1/** 2 * iBox 2.2 (Build 1612) 3 * For more info & download: http://www.ibegin.com/labs/ibox/ 4 * Created as a part of the iBegin Labs Project - http://www.ibegin.com/labs/ 5 * For licensing please see readme.html (MIT Open Source License) 6*/ 7var iBox = function() { 8 var _pub = { 9 // label for the close link 10 //close_label: 'Close', 11 close_label: '', 12 13 // show iframed content in the parent window 14 // this *does not* work with #containers 15 inherit_frames: false, 16 17 // how fast to fade in the overlay/ibox (this is each step in ms) 18 fade_in_speed: 100, 19 fade_out_speed: 100, 20 21 // our attribute identifier for our iBox elements 22 attribute_name: 'rel', 23 24 // tags to hide when we show our box 25 tags_to_hide: ['select', 'embed', 'object'], 26 27 // default width of the box (when displaying html only) 28 // height is calculated automatically 29 //default_width: 450, 30 default_width: 800, 31 32 // public version number 33 version_number: '2.2', 34 // internal build number 35 build_number: '1612', 36 37 // browser checks 38 is_opera: navigator.userAgent.indexOf('Opera/9') != -1, 39 is_ie: navigator.userAgent.indexOf("MSIE ") != -1, 40 is_ie6: false /*@cc_on || @_jscript_version < 5.7 @*/, 41 is_firefox: navigator.appName == "Netscape" && navigator.userAgent.indexOf("Gecko") != -1 && navigator.userAgent.indexOf("Netscape") == -1, 42 is_mac: navigator.userAgent.indexOf('Macintosh') != -1, 43 44 // url for including images/external files 45 base_url: '', 46 47 /** 48 * Updates the base_url variable. 49 * @param {String} path Relative or absolute path to this file. 50 */ 51 setPath: function(path) { 52 _pub.base_url = path; 53 }, 54 55 /** 56 * Checks a container for specified tags containing rel="ibox" 57 * @param {Object} container 58 * @param {String} tag_name 59 */ 60 checkTags: function(container, tag_name) { 61 if (!container) var container = document.body; 62 if (!tag_name) var tag_name = 'a'; 63 var els = container.getElementsByTagName(tag_name); 64 for (var i=0; i<els.length; i++) { 65 if (els[i].getAttribute(_pub.attribute_name)) { 66 var t = els[i].getAttribute(_pub.attribute_name); 67 if ((t.indexOf("ibox") != -1) || t.toLowerCase() == "ibox") { // check if this element is an iBox element 68 els[i].onclick = _pub.handleTag; 69 } 70 } 71 } 72 }, 73 74 /** 75 * Binds arguments to a callback function 76 */ 77 bind: function(fn) { 78 var args = []; 79 for (var n=1; n<arguments.length; n++) args.push(arguments[n]); 80 return function(e) { return fn.apply(this, [e].concat(args)); }; 81 }, 82 83 /** 84 * Sets the content of the ibox 85 * @param {String} content HTML content 86 * @param {Object} params 87 */ 88 html: function(content, params) { 89 if (content === undefined) return els.content; 90 if (params === undefined) var params = {}; 91 if (!active.is_loaded) return; 92 _pub.clear(); 93 94 _pub.updateObject(els.wrapper.style, {display: 'block', visibility: 'hidden', left: 0, top: 0, height: '', width: ''}); 95 96 if (typeof(content) == 'string') els.content.innerHTML = content; 97 else els.content.appendChild(content); 98 99 var pagesize = _pub.getPageSize(); 100 101 if (params.can_resize === undefined) params.can_resize = true; 102 if (params.fade_in === undefined) params.use_fade = true; 103 104 if (params.fullscreen) { 105 params.width = '100%'; 106 params.height = '100%'; 107 } 108 109 // reset offsets 110 offset.container = [els.wrapper.offsetLeft*2, els.wrapper.offsetTop*2]; 111 offset.wrapper = [els.wrapper.offsetWidth-els.content.offsetWidth, els.wrapper.offsetHeight-els.content.offsetHeight]; 112 113 // TODO: remove the +4 when issue is solved with calculations 114 offset.wrapper[1] += 4; 115 116 if (params.width) var width = params.width; 117 else var width = _pub.default_width; 118 119 if (params.height) var height = params.height; 120 else { 121 els.content.style.height = '100%'; 122 var height = els.content.offsetHeight + 12; 123 els.content.style.height = ''; 124 } 125 active.dimensions = [width, height]; 126 active.params = params; 127 _pub.reposition(); 128 129 // XXX: Fix for inline containers which had elements that were hidden 130 for (var i=0; i<_pub.tags_to_hide.length; i++) { 131 showTags(_pub.tags_to_hide[i], els.content); 132 } 133 134 els.wrapper.style.visibility = 'visible'; 135 }, 136 137 /** 138 * Empties the content of the iBox (also hides the loading indicator) 139 */ 140 clear: function() { 141 els.loading.style.display = "none"; 142 while (els.content.firstChild) els.content.removeChild(els.content.firstChild); 143 }, 144 145 /** 146 * Loads text into the ibox 147 * @param {String} text 148 * @param {String} title 149 * @param {Object} params 150 */ 151 show: function(text, title, params) { 152 showInit(title, params, function() { 153 _pub.html(text, active.params); 154 }); 155 }, 156 /** 157 * Loads a url into the ibox 158 * @param {String} url 159 * @param {String} title 160 * @param {Object} params 161 */ 162 showURL: function(url, title, params) { 163 showInit(title, params, function() { 164 for (var i=0; i<_pub.plugins.list.length; i++) { 165 var plugin = _pub.plugins.list[i]; 166 if (plugin.match(url)) { 167 active.plugin = plugin; 168 plugin.render(url, active.params); 169 break; 170 } 171 } 172 }); 173 }, 174 175 /** 176 * Hides the iBox 177 */ 178 hide: function() { 179 if (active.plugin) { 180 // call the plugins unload method 181 if (active.plugin.unload) active.plugin.unload(); 182 } 183 active = {} 184 _pub.clear(); 185 // restore elements that were hidden 186 for (var i=0; i<_pub.tags_to_hide.length; i++) showTags(_pub.tags_to_hide[i]); 187 188 els.loading.style.display = 'none'; 189 els.wrapper.style.display = 'none'; 190 _pub.fade(els.overlay, _pub.getOpacity(null, els.overlay), 0, _pub.fade_out_speed, function() { els.overlay.style.display = 'none';}); 191 _pub.fireEvent('hide'); 192 }, 193 194 /** 195 * Repositions the iBox wrapper based on the params set originally. 196 */ 197 reposition: function() { 198 if (!active.is_loaded) return; 199 200 // center loading box 201 if (els.loading.style.display != 'none') _pub.center(els.loading); 202 203 // update ibox width/height/position
204 if (active.dimensions) { 205 var pagesize = _pub.getPageSize(); 206 207 var width = active.dimensions[0]; 208 var height = active.dimensions[1]; 209 210 if (height.toString().indexOf('%') != -1) { 211 els.wrapper.style.height = (Math.max(document.documentElement.clientHeight, document.body.clientHeight, pagesize.height) - offset.container[0])*(parseInt(height)/100) + 'px'; 212 } 213 else if (height) { 214 els.content.style.height = height + 'px'; 215 // TODO: if we dont set wrapper height, it doesnt restrict the height and the box is fine 216 // so offset.wrapper[1] must not be correct 217 els.wrapper.style.height = els.content.offsetHeight + offset.wrapper[1] + 'px'; 218 } 219 else { 220 els.wrapper.style.height = els.content.offsetHeight + offset.wrapper[1] + 'px'; 221 } 222 var container_offset = (els.content.offsetHeight - els.content.firstChild.offsetHeight); 223 if (width.toString().indexOf('%') != -1) { 224 els.wrapper.style.width = (Math.max(document.documentElement.clientWidth, document.body.clientWidth, pagesize.width) - offset.container[1])*(parseInt(width)/100) + 'px'; 225 var container_offset = 0; 226 } 227 else { 228 els.content.style.width = width + 'px'; 229 els.wrapper.style.width = els.content.offsetWidth + offset.wrapper[0] + 'px'; 230 } 231
232 _pub.updateObject(els.content.style, {width: '', height: ''}); 233 234 var width = parseInt(els.wrapper.style.width); 235 var height = parseInt(els.wrapper.style.height); 236 237 // if we can resize this, make sure it fits in our page bounds 238 if (active.params.can_resize) { 239 var x = pagesize.width; 240 var y = pagesize.height; 241 242 x -= offset.container[0]; 243 y -= offset.container[1]; 244 if (width > x) { 245 if (active.params.constrain) height = height * (x/width); 246 width = x; 247 } 248 if (height > y) { 249 if (active.params.constrain) width = width * (y/height); 250 height = y; 251 } 252 _pub.updateObject(els.wrapper.style, {width: width + 'px', height: height + 'px'}); 253 } 254 255 //els.content.style.width = width - offset.wrapper[0] + 'px'; 256 // TODO: this isn't adjusting to the right height for containers that are smaller than the page height 257 // resize the wrappers height based on the content boxes height 258 // this needs to be height - ibox_content[margin+padding+border] 259 els.content.style.height = height - offset.wrapper[1] + 'px'; 260 if (active.dimensions != ['100%', '100%']) _pub.center(els.wrapper); 261 } 262 263 // fix overlay width/height (cant use css fixed on ie6 or fx or any 264 // browser really due to issues) 265 els.overlay.style.height = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) + 'px'; 266 }, 267 268 updateObject: function(obj, params) { 269 for (var i in params) obj[i] = params[i]; 270 }, 271 272 /** 273 * Centers an object 274 * @param {Object} obj 275 */ 276 center: function(obj) { 277 var pageSize = _pub.getPageSize(); 278 var scrollPos = _pub.getScrollPos(); 279 var emSize = _pub.getElementSize(obj); 280 var x = Math.round((pageSize.width - emSize.width) / 2 + scrollPos.scrollX); 281 var y = Math.round((pageSize.height - emSize.height) / 2 + scrollPos.scrollY); 282 if (obj.offsetLeft) x -= obj.offsetLeft; 283 if (obj.offsetTop) y -= obj.offsetTop; 284 if (obj.style.left) x += parseInt(obj.style.left); 285 if (obj.style.top) y += parseInt(obj.style.top); 286 // this nearly centers it due to scrollbars 287 x -= 10; 288 _pub.updateObject(obj.style, {top: y + 'px', left: x + 'px'}); 289 }, 290 291 getStyle: function(obj, styleProp) { 292 if (obj.currentStyle) 293 return obj.currentStyle[styleProp]; 294 else if (window.getComputedStyle) 295 return document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp); 296 }, 297 298 /** 299 * Gets the scroll positions 300 */ 301 getScrollPos: function() { 302 var docElem = document.documentElement; 303 return { 304 scrollX: document.body.scrollLeft || window.pageXOffset || (docElem && docElem.scrollLeft), 305 scrollY: document.body.scrollTop || window.pageYOffset || (docElem && docElem.scrollTop) 306 }; 307 }, 308 309 /** 310 * Gets the page constraints 311 */ 312 getPageSize: function() { 313 return { 314 width: window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth, 315 height: window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight 316 }; 317 }, 318 319 /** 320 * Gets an objects offsets 321 * @param {Object} obj 322 */ 323 getElementSize: function(obj) { 324 return { 325 width: obj.offsetWidth || obj.style.pixelWidth, 326 height: obj.offsetHeight || obj.style.pixelHeight 327 }; 328 }, 329 330 fade: function(obj, start, end, speed, callback) { 331 if (start === undefined || !(start >= 0) || !(start <= 100)) var start = 0; 332 if (end === undefined || !(end >= 0) || !(end <= 100)) var end = 100; 333 if (speed === undefined) var speed = 0; 334 335 if (obj.fader) clearInterval(obj.fader); 336 337 if (!speed) { 338 _pub.setOpacity(null, obj, end); 339 if (callback) callback(); 340 } 341 342 var opacity_difference = end - start; 343 var time_total = speed; // time is speed (jQuery compat) 344 var step_size = 25; // step size in ms 345 var steps = time_total / step_size; // total number of steps 346 var increment = Math.ceil(opacity_difference / steps); // how much to incr per step 347 348 obj.fader = setInterval(_pub.bind(function(e, obj, increment, end, callback) { 349 var opacity = _pub.getOpacity(e, obj) + increment; 350 _pub.setOpacity(e, obj, opacity); 351 if ((increment < 0 && opacity <= end) || (increment > 0 && opacity >= end)) { 352 _pub.setOpacity(e, obj, end); 353 clearInterval(obj.fader); 354 if (callback) callback(); 355 } 356 }, obj, increment, end, callback), step_size); 357 }, 358 359 /** 360 * Sets the opacity of an element 361 * @param {Object} obj 362 * @param {Integer} value 363 */ 364 setOpacity: function(e, obj, value) { 365 value = Math.round(value); 366 obj.style.opacity = value/100; 367 obj.style.filter = 'alpha(opacity=' + value + ')'; 368 }, 369 370 /** 371 * Gets the opacity of an element 372 * @param {Object} obj 373 * @return {Integer} value 374 */ 375 getOpacity: function(e, obj) { 376 return _pub.getStyle(obj, 'opacity')*100; 377 }, 378 379 /** 380 * Creates a new XMLHttpRequest object based on browser 381 */ 382 createXMLHttpRequest: function() { 383 var http; 384 if (window.XMLHttpRequest) { // Mozilla, Safari,... 385 http = new XMLHttpRequest(); 386 if (http.overrideMimeType) { 387 // set type accordingly to anticipated content type 388 http.overrideMimeType('text/html'); 389 } 390 } 391 else if (window.ActiveXObject) { // IE 392 try { 393 http = new ActiveXObject("Msxml2.XMLHTTP"); 394 } catch (e) { 395 try { 396 http = new ActiveXObject("Microsoft.XMLHTTP"); 397 } catch (e) {} 398 } 399 } 400 if (!http) { 401 alert('Cannot create XMLHTTP instance'); 402 return false;
403 } 404 return http; 405 }, 406 407 addEvent: function(obj, evType, fn) { 408 if (obj.addEventListener) { 409 obj.addEventListener(evType, fn, false); 410 return true; 411 } 412 else if (obj.attachEvent) { 413 var r = obj.attachEvent("on"+evType, fn); 414 return r; 415 } 416 else { 417 return false; 418 } 419 }, 420 421 addEventListener: function(name, callback) { 422 if (!events[name]) events[name] = new Array(); 423 events[name].push(callback); 424 }, 425 426 /** 427 * Causes all event listeners attached to `name` event to 428 * execute. 429 * @param {String} name Event name 430 */ 431 fireEvent: function(name) { 432 if (events[name] && events[name].length) { 433 for (var i=0; i<events[name].length; i++) { 434 var args = []; 435 for (var n=1; n<arguments.length; n++) args.push(arguments[n]); 436 // Events returning false stop propagation 437 if (events[name][i](args) === false) break; 438 } 439 } 440 }, 441 442 /** 443 * Parses the arguments in the rel attribute 444 * @param {String} query 445 */ 446 parseQuery: function(query) { 447 var params = new Object(); 448 if (!query) return params; 449 var pairs = query.split(/[;&]/); 450 var end_token; 451 for (var i=0; i<pairs.length; i++) { 452 var keyval = pairs[i].split('='); 453 if (!keyval || keyval.length != 2) continue; 454 var key = unescape(keyval[0]); 455 var val = unescape(keyval[1]); 456 val = val.replace(/\+/g, ' '); 457 if (val[0] == '"') var token = '"'; 458 else if (val[0] == "'") var token = "'"; 459 else var token = null; 460 if (token) { 461 if (val[val.length-1] != token) { 462 do { 463 i += 1; 464 val += '&'+pairs[i]; 465 } 466 while ((end_token = pairs[i][pairs[i].length-1]) != token) 467 } 468 val = val.substr(1, val.length-2); 469 } 470 if (val == 'true') val = true; 471 else if (val == 'false') val = false; 472 else if (val == 'null') val = null; 473 params[key] = val; 474 } 475 return params; 476 }, 477 /** 478 * Handles the onclick event for iBox anchors. 479 * @param {Event} e 480 */ 481 handleTag: function(e) { 482 var t = this.getAttribute('rel'); 483 var params = _pub.parseQuery(t.substr(5,999)); 484 if (params.target) var url = params.target; 485 else if (this.target && !params.ignore_target) var url = this.target; 486 else var url = this.href; 487 var title = this.title; 488 if (_pub.inherit_frames && window.parent) window.parent.iBox.showURL(url, title, params); 489 else _pub.showURL(url, title, params); 490 return false; 491 }, 492 493 plugins: { 494 list: new Array(), 495 register: function(func, last) { 496 if (last === undefined) var last = false; 497 if (!last) { 498 _pub.plugins.list = [func].concat(_pub.plugins.list); 499 } 500 else { 501 _pub.plugins.list.push(func); 502 } 503 } 504 } 505 }; 506 507 // private methods and variables 508 var active = {}; 509 510 // events 511 var events = {}; 512 513 // some containers 514 // we store these in memory instead of finding them each time 515 var els = {}; 516 517 var offset = {}; 518 519 /** 520 * Creates the iBox container and appends it to an element 521 * @param {HTMLObject} elem Container to attach to 522 * @return {HTMLObject} iBox element 523 */ 524 var create = function(elem) { 525 pagesize = _pub.getPageSize(); 526 527 // TODO: why isnt this using DOM tools 528 // a trick on just creating an ibox wrapper then doing an innerHTML on our root ibox element 529 els.container = document.createElement('div'); 530 els.container.id = 'ibox'; 531 532 els.overlay = document.createElement('div'); 533 els.overlay.style.display = 'none'; 534 _pub.setOpacity(null, els.overlay, 0); 535 // firefox mac has issues with opacity and flash 536 if (!_pub.is_firefox) els.overlay.style.background = '#000000'; 537 else els.overlay.style.backgroundImage = "url('" + _pub.base_url + "images/bg.png')"; 538 els.overlay.id = 'ibox_overlay'; 539// params = {position: 'fixed', top: 0, left: 0, width: '100%'}; 540 params = {position: 'absolute', top: 0, left: 0, width: '100%'}; 541 _pub.updateObject(els.overlay.style, params); 542 els.overlay.onclick = _pub.hide; 543 els.container.appendChild(els.overlay); 544 545 els.loading = document.createElement('div'); 546 els.loading.id = 'ibox_loading'; 547 els.loading.innerHTML = 'Loading...'; 548 els.loading.style.display = 'none'; 549 els.loading.onclick = _pub.hide 550 els.container.appendChild(els.loading); 551 552 els.wrapper = document.createElement('div') 553 els.wrapper.id = 'ibox_wrapper'; 554 _pub.updateObject(els.wrapper.style, {position: 'absolute', top: 0, left: 0, display: 'none'}); 555 556 els.content = document.createElement('div'); 557 els.content.id = 'ibox_content';
558 _pub.updateObject(els.content.style, {overflow: 'auto'}) 559 els.wrapper.appendChild(els.content); 560 561 var child = document.createElement('div'); 562 child.id = 'ibox_footer_wrapper'; 563 564 var child2 = document.createElement('a'); 565 child2.innerHTML = '<img src="/gallerma/common_files/js/movieOverlay/images/x.gif" alt="X" title="X">'; 566 //child2.innerHTML = _pub.close_label; 567 child2.href = 'javascript:void(0)'; 568 child2.onclick = _pub.hide; 569 child.appendChild(child2); 570 571 els.footer = document.createElement('div'); 572 els.footer.id = 'ibox_footer'; 573 els.footer.innerHTML = ' '; 574 child.appendChild(els.footer); 575 els.wrapper.appendChild(child); 576 577 els.container.appendChild(els.wrapper); 578 579 elem.appendChild(els.container); 580 581 _pub.updateObject(els.wrapper.style, {right: '', bottom: ''}); 582 583 return els.container; 584 }; 585 586 /** 587 * Hides tags within the container 588 * @param {String} tag The name of the tag (e.g. 'a') 589 * @param {HTMLObject} container The container to restore tags within (defaults to document) 590 */ 591 var hideTags = function(tag, container) { 592 if (container === undefined) var container = document.body; 593 var list = container.getElementsByTagName(tag); 594 for (var i=0; i<list.length; i++) { 595 if (_pub.getStyle(list[i], 'visibility') != 'hidden' && list[i].style.display != 'none') { 596 list[i].style.visibility = 'hidden'; 597 list[i].wasHidden = true; 598 } 599 } 600 }; 601 602 /** 603 * Shows all previously hidden tags in a container. 604 * @param {String} tag The name of the tag (e.g. 'a') 605 * @param {HTMLObject} container The container to restore tags within (defaults to document) 606 */ 607 var showTags = function(tag, container) { 608 if (container === undefined) var container = document.body; 609 var list = container.getElementsByTagName(tag); 610 for (var i=0; i<list.length; i++) { 611 if (list[i].wasHidden) { 612 list[i].style.visibility = 'visible'; 613 list[i].wasHidden = null; 614 } 615 } 616 }; 617 618 var showInit = function(title, params, callback) { 619 if (!_initialized) initialize(); 620 if (params === undefined) var params = {}; 621 if (active.plugin) _pub.hide(); 622 623 active.is_loaded = true; 624 active.params = params; 625 626 els.loading.style.display = "block"; 627 628 _pub.center(els.loading); 629 _pub.reposition(); 630 631 // hide tags 632 for (var i=0; i<_pub.tags_to_hide.length; i++) { 633 hideTags(_pub.tags_to_hide[i]); 634 } 635 636 // set title here 637 els.footer.innerHTML = title || " "; 638 639 // setup background 640 els.overlay.style.display = "block"; 641 642 if (!_pub.is_firefox) var amount = 70; 643 else var amount = 100; 644 _pub.fade(els.overlay, _pub.getOpacity(null, els.overlay), amount, _pub.fade_in_speed, callback); 645 646 _pub.fireEvent('show'); 647 }; 648 649 var drawCSS = function() { 650 // Core CSS (positioning/etc) 651 var core_styles = "#ibox {z-index:1000000;text-align:left;} #ibox_overlay {z-index:1000000;} #ibox_loading {position:absolute;z-index:1000001;} #ibox_wrapper {margin:30px;position:absolute;top:0;left:0;z-index:1000001;} #ibox_content {z-index:1000002;margin:32px 5px 5px 5px;padding:2px;} #ibox_content object {display:block;} #ibox_content .ibox_image {width:100%;height:100%;margin:0;padding:0;border:0;display:block;} #ibox_footer_wrapper a {float:right;display:block;outline:0;margin:0;padding:0;} #ibox_footer_wrapper {text-align:left;position:absolute;top:5px;right:5px;left:5px;white-space:nowrap;overflow:hidden;}"; 652 653 // Default style/theme/skin/whatever 654 var default_skin = "#ibox_footer_wrapper {font-weight:bold;height:23px;line-height:20px;} #ibox_footer_wrapper a {text-decoration:none;/*background:#888;border:1px solid #666;*/line-height:16px;padding:0 5px;color:#333;font-weight:bold;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;} #ibox_footer_wrapper a:hover {background-color:#bbb;color:#111;} #ibox_footer_wrapper {font-size:12px;font-family:Verdana, Arial, Helvetica, sans-serif;color:#111;} #ibox_wrapper {border-top:1px solid #666;border-left:1px solid #666;border-right:1px solid #444;border-bottom:1px solid #444;} #ibox_wrapper {background-color:#222;}#ibox_content {} #ibox_loading {padding:50px; background:#000;color:#fff;font-size:16px;font-weight:bold;}"; 655 656 var head = document.getElementsByTagName("head")[0]; 657 658 // tricky hack for IE 659 // because IE doesn't like when you insert stuff the proper way 660 // and we cant use relative paths to include this as an external 661 // stylesheet 662 var htmDiv = document.createElement('div'); 663 664 htmDiv.innerHTML = '<p>
664x</p><style type="text/css">'+default_skin+'</style>'; 665 head.insertBefore(htmDiv.childNodes[1], head.firstChild); 666 667 htmDiv.innerHTML = '<p>x</p><style type="text/css">'+core_styles+'</style>'; 668 head.insertBefore(htmDiv.childNodes[1], head.firstChild); 669 }; 670 671 var _initialized = false; 672 var initialize = function() { 673 // make sure we haven't already done this 674 if (_initialized) return; 675 _initialized = true; 676 // elements here start the look up from the start non <a> tags 677 drawCSS(); 678 var els = document.getElementsByTagName('script'); 679 var src; 680 for (var i=0, el=null; (el = els[i]); i++) { 681 if (!(src = el.getAttribute('src'))) continue; 682 src = src.split('?')[0]; 683 if (src.substr(src.length-8) == '/ibox.js') { 684 _pub.setPath(src.substr(0, src.length-7)); 685 break; 686 } 687 } 688 create(document.body); 689 _pub.checkTags(document.body, 'a'); 690 _pub.http = _pub.createXMLHttpRequest(); 691 _pub.fireEvent('load'); 692 }; 693 694 _pub.addEvent(window, 'keypress', function(e){ if (e.keyCode == (window.event ? 27 : e.DOM_VK_ESCAPE)) { iBox.hide(); }}); 695 _pub.addEvent(window, 'resize', _pub.reposition); 696 _pub.addEvent(window, 'load', initialize); 697 _pub.addEvent(window, 'scroll', _pub.reposition); 698 699 // DEFAULT PLUGINS 700 701 /** 702 * Handles embedded containers in the page based on url of #container. 703 * This _ONLY_ works with hidden containers. 704 */ 705 var iBoxPlugin_Container = function() { 706 var was_error = false; 707 var original_wrapper = null; 708 return { 709 /** 710 * Matches the url and returns true if it fits this plugin. 711 */ 712 match: function(url) { 713 return url.indexOf('#') != -1; 714 }, 715 /** 716 * Called when this plugin is unloaded. 717 */ 718 unload: function() { 719 if (was_error) return; 720 var elemSrc = _pub.html().firstChild; 721 if (elemSrc) { 722 elemSrc.style.display = 'none'; 723 original_wrapper.appendChild(elemSrc); 724 } 725 }, 726 /** 727 * Handles the output 728 * @param {iBox} ibox 729 * @param {String} url 730 * @return {iBoxContent} an instance or subclass of iBoxContent 731 */ 732 render: function(url, params) { 733 was_error = false; 734 var elemSrcId = url.substr(url.indexOf("#") + 1); 735 var elemSrc = document.getElementById(elemSrcId); 736 // If the element doesnt exist, break the switch 737 if (!elemSrc) { 738 was_error = true; 739 _pub.html(document.createTextNode('There was an error loading the document.'), params); 740 } 741 else { 742 original_wrapper = elemSrc.parentNode; 743 elemSrc.style.display = 'block'; 744 _pub.html(elemSrc, params); 745 } 746 } 747 } 748 }(); 749 _pub.plugins.register(iBoxPlugin_Container, true); 750 751 /** 752 * Handles images 753 */ 754 var iBoxPlugin_Image = function() { 755 // Image types (for auto detection of image display) 756 var image_types = /\.jpg|\.jpeg|\.png|\.gif/gi; 757 758 return { 759 match: function(url) { 760 return url.match(image_types); 761 }, 762 763 render: function(url, params) { 764 var img = document.createElement('img'); 765 img.onclick = _pub.hide; 766 img.className = 'ibox_image' 767 img.style.cursor = 'pointer'; 768 img.onload = function() { 769 _pub.html(img, {width: this.width, height: this.height, constrain: true}) 770 } 771 img.onerror = function() { 772 _pub.html(document.createTextNode('There was an error loading the document.'), params); 773 } 774 img.src = url; 775 } 776 } 777 }(); 778 _pub.plugins.register(iBoxPlugin_Image); 779 780 var iBoxPlugin_YouTube = function() { 781 var youtube_url = /(?:http:\/\/)?(?:www\d*\.)?(youtube\.(?:[a-z]+))\/(?:v\/|(?:watch(?:\.php)?)?\?(?:.+&)?v=)([^&]+).*/; 782 return { 783 match: function(url) { 784 return url.match(youtube_url); 785 }, 786 787 render: function(url, params) { 788 var _match = url.match(youtube_url); 789 var domain = _match[1]; 790 var id = _match[2]; 791 //params.width = 425; 792 params.width = 660; 793 //params.height = 355; 794 params.height = 390; 795 params.constrain = true; 796 var html = '<span><object width="100%" height="390px" style="overflow: hidden; display: block;"><param name="movie" value="http://www.' + domain + '/v/' + id + '"/><param name="wmode" value="transparent"/><embed src="http://www.' + domain + '/v/' + id + '" type="application/x-shockwave-flash" wmode="transparent" width="100%" height="390px"></embed></object></span>'; 797 _pub.html(html, params); 798 } 799 } 800 }(); 801 _pub.plugins.register(iBoxPlugin_YouTube); 802 803 var iBoxPlugin_Document = function() { 804 return { 805 match: function(url) { 806 return true; 807 }, 808 809 render: function(url, params) { 810 _pub.http.open('get', url, true); 811 812 _pub.http.onreadystatechange = function() { 813 if (_pub.http.readyState == 4) { 814 // XXX: why does status return 0? 815 if (_pub.http.status == 200 || _pub.http.status == 0) { 816 _pub.html(_pub.http.responseText, params); 817 } 818 else { 819 _pub.html(document.createTextNode('There was an error loading the document.'), params); 820 } 821 } 822 } 823 _pub.http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
824 try { 825 _pub.http.send(null); 826 } 827 catch (ex) { 828 _pub.html(document.createTextNode('There was an error loading the document.'), params); 829 } 830 } 831 }; 832 }(); 833 _pub.plugins.register(iBoxPlugin_Document, true); 834 835 return _pub; 836}();
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.