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