My static website generator using poole https://www.xythobuz.de
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

yox.js 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. Yox = {
  2. // Adds a stylesheet link reference in the specified document's HEAD
  3. addStylesheet: function(_document, cssUrl)
  4. {
  5. var cssLink = _document.createElement("link");
  6. cssLink.setAttribute("rel", "Stylesheet");
  7. cssLink.setAttribute("type", "text/css");
  8. cssLink.setAttribute("href", cssUrl);
  9. _document.getElementsByTagName("head")[0].appendChild(cssLink);
  10. },
  11. compare: function(obj1, obj2)
  12. {
  13. if (typeof(obj1) != typeof(obj2))
  14. return false;
  15. else if (typeof(obj1) == "function")
  16. return obj1 == obj2;
  17. // deep-compare objects:
  18. function size(obj)
  19. {
  20. var size = 0;
  21. for (var keyName in obj)
  22. {
  23. if (keyName != null)
  24. size++;
  25. }
  26. return size;
  27. }
  28. if (size(obj1) != size(obj2))
  29. return false;
  30. for(var keyName in obj1)
  31. {
  32. var value1 = obj1[keyName];
  33. var value2 = obj2[keyName];
  34. if (typeof value1 != typeof value2)
  35. return false;
  36. if (value1 && value1.length && (value1[0] !== undefined && value1[0].tagName))
  37. {
  38. if(!value2 || value2.length != value1.length || !value2[0].tagName || value2[0].tagName != value1[0].tagName)
  39. return false;
  40. }
  41. else if (typeof value1 == 'function' || typeof value1 == 'object') {
  42. var equal = Yox.compare(value1, value2);
  43. if (!equal)
  44. return equal;
  45. }
  46. else if (value1 != value2)
  47. return false;
  48. }
  49. return true;
  50. },
  51. hasProperties: function(obj){
  52. var hasProperties = false;
  53. for(pName in obj)
  54. {
  55. hasProperties = true;
  56. break;
  57. }
  58. return hasProperties;
  59. },
  60. dataSources: [],
  61. fitImageSize: function(imageSize, targetSize, enlarge, isFill)
  62. {
  63. var resultSize = { width: imageSize.width, height: imageSize.height};
  64. if ((imageSize.width > targetSize.width) ||
  65. (enlarge && imageSize.width < targetSize.width) )
  66. {
  67. resultSize.height = Math.round((targetSize.width / imageSize.width) * imageSize.height);
  68. resultSize.width = targetSize.width;
  69. }
  70. if (!isFill && resultSize.height > targetSize.height)
  71. {
  72. resultSize.width = Math.round((targetSize.height / resultSize.height) * resultSize.width);
  73. resultSize.height = targetSize.height;
  74. }
  75. else if (isFill && resultSize.height < targetSize.height && (targetSize.height <= imageSize.height || enlarge))
  76. {
  77. resultSize.height = targetSize.height;
  78. resultSize.width = Math.round((targetSize.height / imageSize.height) * imageSize.width);
  79. }
  80. return resultSize;
  81. },
  82. flashVideoPlayers: {
  83. jwplayer: function(swfUrl, videoUrl, imageUrl, title, flashVars){
  84. var returnData = {
  85. swf: swfUrl || "/jwplayer/player.swf",
  86. flashVars: {
  87. file: videoUrl,
  88. image: imageUrl,
  89. stretching: "fill",
  90. title: title,
  91. backcolor: "000000",
  92. frontcolor: "FFFFFF"
  93. }
  94. }
  95. $.extend(returnData.flashVars, flashVars);
  96. return returnData;
  97. }
  98. },
  99. getDataSourceName: function(url)
  100. {
  101. for(dataSourceIndex in Yox.Regex.data)
  102. {
  103. if(url.match(Yox.Regex.data[dataSourceIndex]))
  104. return dataSourceIndex;
  105. }
  106. return null;
  107. },
  108. getPath: function(pathRegex)
  109. {
  110. var scripts = document.getElementsByTagName("script");
  111. for(var i=0; i<scripts.length; i++)
  112. {
  113. var currentScriptSrc = scripts[i].src;
  114. var matchPath = currentScriptSrc.match(pathRegex);
  115. if (matchPath)
  116. return matchPath[1];
  117. }
  118. return null;
  119. },
  120. getTopWindow: function()
  121. {
  122. var topWindow = window;
  123. if (window.top)
  124. topWindow = window.top;
  125. else
  126. {
  127. while(topWindow.parent)
  128. topWindow = topWindow.parent;
  129. }
  130. return topWindow;
  131. },
  132. getUrlData: function(url)
  133. {
  134. var urlMatch = url.match(Yox.Regex.url);
  135. if (!urlMatch)
  136. return null;
  137. var urlData = {
  138. path: urlMatch[1],
  139. anchor: urlMatch[3]
  140. }
  141. if (urlMatch[2])
  142. urlData.queryFields = this.queryToJson(urlMatch[2]);
  143. return urlData;
  144. },
  145. hex2rgba: function(hex, alpha)
  146. {
  147. hex = parseInt(hex.replace("#", "0x"), 16);
  148. var r = (hex & 0xff0000) >> 16;
  149. var g = (hex & 0x00ff00) >> 8;
  150. var b = hex & 0x0000ff;
  151. return "rgba(" + r + ", " + g + ", " + b + ", " + (typeof(alpha) != 'undefined' ? alpha : "1") + ")";
  152. },
  153. queryToJson: function(query)
  154. {
  155. if (!query)
  156. return null;
  157. var queryParams = query.split("&");
  158. var json = {};
  159. for(var i=0; i < queryParams.length; i++)
  160. {
  161. var paramData = queryParams[i].split('=');
  162. if (paramData.length == 2)
  163. json[paramData[0]] = paramData[1];
  164. }
  165. return json;
  166. },
  167. loadDataSource: function(options, callback)
  168. {
  169. var dataSourceName;
  170. if (options.dataUrl)
  171. {
  172. dataSourceName = Yox.getDataSourceName(options.dataUrl);
  173. if (dataSourceName)
  174. $.extend(options, { dataSource: dataSourceIndex });
  175. }
  176. if (options.dataSource && !Yox.dataSources[dataSourceName])
  177. {
  178. $.ajax({
  179. url : options.dataFolder + options.dataSource + ".js",
  180. async : false,
  181. dataType : "script",
  182. success: function(data){
  183. eval(data);
  184. eval ("Yox.dataSources['" + options.dataSource + "'] = new yox_" + options.dataSource + "();");
  185. callback(Yox.dataSources[options.dataSource]);
  186. },
  187. error : function(XMLHttpRequest, textStatus, errorThrown)
  188. {
  189. console.log(XMLHttpRequest, textStatus, errorThrown);
  190. }
  191. });
  192. }
  193. else if (callback)
  194. callback();
  195. },
  196. Regex: {
  197. data: {
  198. picasa: /http:\/\/(?:www\.)?picasaweb\.google\..*/i,
  199. flickr: /http:\/\/(?:www\.)?flickr.com/i,
  200. smugmug: /http:\/\/.*\.smugmug.com/i,
  201. youtube: /^http:\/\/(?:www\.)?youtube.com\//
  202. },
  203. flash: /^(.*\.(swf))(\?[^\?]+)?/i,
  204. flashvideo: /^(.*\.(flv|f4v|f4p|f4a|f4b|aac))(\?[^\?]+)?/i,
  205. image: /^[^\?#]+\.(?:jpg|jpeg|gif|png)$/i,
  206. url: /^([^#\?]*)?(?:\?([^\?#]*))?(?:#([A-Za-z]{1}[A-Za-z\d-_\:\.]+))?$/, // [0] - whole url, [1] - path, [2] - query (sans '?'), [3] - anchor
  207. video: {
  208. youtube: /.*youtube.com\/watch.*(?:v=[^&]+).*/i,
  209. vimeo: /vimeo.com\/\d+/i,
  210. hulu: /hulu.com\/watch\//i,
  211. viddler: /viddler.com\//i,
  212. flickr: /.*flickr.com\/.*/i,
  213. myspace: /.*vids.myspace.com\/.*/i,
  214. qik: /qik.com/i,
  215. revision3: /revision3.com/i,
  216. dailymotion: /dailymotion.com/i,
  217. "5min": /.*5min\.com\/Video/i
  218. }
  219. },
  220. Sprites: function(sprites, spritesImage, srcImage)
  221. {
  222. var cacheImg = new Image();
  223. cacheImg.src = spritesImage;
  224. this.spritesImage = spritesImage;
  225. var currentTop = 0;
  226. jQuery.each(sprites, function(i, spriteGroup){
  227. spriteGroup.top = currentTop;
  228. currentTop += spriteGroup.height;
  229. });
  230. this.getSprite = function(spriteGroup, spriteName, title)
  231. {
  232. return jQuery("<img/>", {
  233. src: srcImage,
  234. alt: spriteName,
  235. title: title,
  236. css: {
  237. width: sprites[spriteGroup].width,
  238. height: sprites[spriteGroup].height,
  239. "background-image": "url(" + spritesImage + ")",
  240. "background-repeat": "no-repeat",
  241. "background-position": this.getBackgroundPosition(spriteGroup, spriteName)
  242. }
  243. });
  244. }
  245. this.getBackgroundPosition = function(spriteGroup, spriteName)
  246. {
  247. var backgroundLeft = jQuery.inArray(spriteName, sprites[spriteGroup].sprites) * (sprites[spriteGroup].width || 0);
  248. return "-" + backgroundLeft + "px -" + sprites[spriteGroup].top + "px";
  249. }
  250. },
  251. Support: {
  252. rgba: function()
  253. {
  254. // From http://leaverou.me/2009/03/check-whether-the-browser-supports-rgba-and-other-css3-values/
  255. if(!('result' in arguments.callee))
  256. {
  257. var element = document.createElement('div');
  258. var testColor = 'rgba(0, 0, 0, 0.5)';
  259. var result = false;
  260. try {
  261. element.style.color = testColor;
  262. result = /^rgba/.test(element.style.color);
  263. } catch(e) {}
  264. element = null;
  265. arguments.callee.result = result;
  266. }
  267. return arguments.callee.result;
  268. }
  269. },
  270. urlDataToPath: function(urlData)
  271. {
  272. var path = urlData.path ||"";
  273. if (urlData.queryFields && this.hasProperties(urlData.queryFields))
  274. {
  275. path += "?";
  276. for(field in urlData.queryFields)
  277. {
  278. path += field + "=" + urlData.queryFields[field] + "&";
  279. }
  280. path = path.substring(0, path.length-1);
  281. }
  282. if (urlData.anchor)
  283. path += "#" + urlData.anchor;
  284. return path;
  285. }
  286. }