1 2var Smoothbox = { 3 4 instance : false, 5 6 bind : function(selector) 7 { 8 // All children of element 9 var elements; 10 if( $type(selector) == 'element' ){ 11 elements = selector.getElements('a.smoothbox'); 12 } else if( $type(selector) == 'string' ){ 13 elements = $$(selector); 14 } else { 15 elements = $$("a.smoothbox"); 16 } 17 18 elements.each(function(el) 19 { 20 if( el.get('tag') != 'a' || el.retrieve('smoothboxed', false) ) 21 { 22 return; 23 } 24 25 var params = Function.attempt(function(){ 26 var ret = JSON.decode(el.title); 27 if( $type(ret.title) ) 28 { 29 el.title = ret.title; 30 } 31 else 32 { 33 el.title = ''; 34 } 35 return ret; 36 }, function(){ 37 return {}; 38 }); 39 40 params.url = el.href; 41 el.store('smoothbox', params); 42 el.store('smoothboxed', true); 43 44 //el.href = 'javascript:void(0);'; 45 el.addEvent('click', function(event) 46 { 47 event.stop(); // Maybe move this to after next line when done debugging 48 Smoothbox.open(el); 49 }); 50 }); 51 }, 52 53 close : function() 54 { 55 if( this.instance ) 56 { 57 this.instance.close(); 58 } 59 }, 60 61 open : function(spec, options) 62 { 63 if( this.instance ) 64 { 65 var bind = this; 66 this.instance.addEvent('closeafter', function() 67 { 68 bind.open(spec); 69 }); 70 this.instance.close(); 71 return; 72 } 73 74 // Check the options array 75 if( $type(options) == 'object' ) { 76 options = new Hash(options); 77 } else if( $type(options) != 'hash' ) { 78 options = new Hash(); 79 } 80 81 // Check the arguments 82 83 // Spec as element 84 if( $type(spec) == 'element' ) { 85 // This is a link 86 if( spec.get('tag').toLowerCase() == 'a' ) { 87 spec = new Hash({ 88 'mode' : 'Iframe', 89 'link' : spec, 90 'element' : spec, 91 'url' : spec.get('href'), 92 'title' : spec.get('title') 93 }); 94 } 95 // This is some other element 96 else { 97 spec = new Hash({ 98 'mode' : 'Inline', 99 'title' : spec.get('title'), 100 'element' : spec 101 }); 102 } 103 } 104 105 // Spec as string 106 else if( $type(spec) == 'string' ) { 107 // Spec is url 108 if( spec.length < 4000 && (spec.substring(0, 1) == '/' || 109 spec.substring(0, 1) == '.' || 110 spec.substring(0, 4) == 'http' || 111 !spec.match(/[ <>"'{}|^~\[\]`]/) 112 ) 113 ) { 114 spec = new Hash({ 115 'mode' : 'Iframe', 116 'url' : spec 117 }); 118 } 119 // Spec is a string 120 else { 121 spec = new Hash({ 122 'mode' : 'String', 123 'bodyText' : spec 124 }); 125 } 126 } 127 128 // Spec as object or hash 129 else if( $type(spec) == 'object' || $type(spec) == 'hash' ) { 130 // Don't do anything? 131 } 132 133 // Unknown spec 134 else { 135 spec = new Hash(); 136 } 137 138 139 140 141 // Now lets start the fun stuff 142 spec.extend(options); 143 144 var mode = spec.get('mode'); 145 spec.erase('mode'); 146 147 if( !mode ) { 148 if( spec.has('url') ) { 149 //if( spec.get('url').match(/\.(jpe?g|png|gif|bmp)/gi) ) { 150 //mode = 'Image'; 151 //} else { 152 mode = 'Iframe'; 153 //} 154 } 155 else if( spec.has('element') ) { 156 mode = 'Inline'; 157 } 158 else if( spec.has('bodyText') ) { 159 mode = 'String'; 160 } 161 else { 162 return; 163 } 164 } 165 166 if( !$type(Smoothbox.Modal[mode]) ) 167 { 168 //mode = 'Iframe'; 169 return; 170 } 171 172 this.instance = new Smoothbox.Modal[mode](spec.getClean()); 173 } 174 175}; 176 177Smoothbox.Modal = new Class({ 178 179 Implements : [Events, Options], 180 181 options : { 182 url : null, 183 width : 480, 184 height : 320, 185 186 // Do or do not 187 transitions : false, 188 overlay : true, 189 loading : true, 190 191 noOverlayClose : false, 192 193 autoResize : true, 194 autoFormat : 'smoothbox' 195 196// useFixed : false 197 }, 198 199 eventProto : {}, 200 201 overlay : false, 202 203 window : false, 204 205 content : false, 206 207 loading : false, 208 209 initialize : function(options) 210 { 211 this.setOptions(options); 212 213 /* 214 if( Browser.Engine.gecko ) 215 { 216 // @todo figure out which browsers exactly use fixed 217 this.options.useFixed = true; 218 } 219 */ 220 221 this.onOpen(); 222 223 this.load(); 224 }, 225
226 close : function() 227 { 228 this.onClose(); 229 230 window.removeEvent('scroll', this.eventProto.scroll); 231 window.removeEvent('resize', this.eventProto.resize); 232 233 if( this.options.transitions ) { 234 this.addEvent('closeafter', function() { 235 if( this.window ) this.window.destroy(); 236 if( this.overlay ) this.overlay.destroy(); 237 if( this.loading ) this.loading.destroy(); 238 }.bind(this)); 239 this.hide(); 240 } else { 241 if( this.window ) this.window.destroy(); 242 if( this.overlay ) this.overlay.destroy(); 243 if( this.loading ) this.loading.destroy(); 244 } 245 246 Smoothbox.instance = false; 247 }, 248 249 load : function() 250 { 251 this.create(); 252 253 // Add Events 254 var bind = this; 255 this.eventProto.resize = function() { 256 bind.positionOverlay(); 257 bind.positionWindow(); 258 } 259 260 this.eventProto.scroll = function() 261 { 262 bind.positionOverlay(); 263 bind.positionWindow(); 264 }; 265 266 // window.addEvent('resize', this.eventProto.resize); 267// window.addEvent('scroll', this.eventProto.scroll); 268 269 270 this.position(); 271 this.showOverlay(); 272 this.showLoading(); 273 }, 274 275 create : function() 276 { 277 this.createOverlay(); 278 this.createLoading(); 279 this.createWindow(); 280 }, 281 282 createLoading : function() 283 { 284 if( this.loading || !this.options.loading ) { 285 return; 286 } 287 288 var bind = this; 289 290 this.loading = new Element('div', { 291 id : 'TB_load' 292 }); 293 this.loading.inject(document.body); 294 295 var loadingImg = new Element('img', { 296 src : '/externals/smoothbox/loading.gif' // @todo Move to CSS 297 }); 298 loadingImg.inject(this.loading); 299 }, 300 301 createOverlay : function() 302 { 303 if( this.overlay || !this.options.overlay ) { 304 return; 305 } 306 307 this.overlay = new Element('div', { 308 'id' : 'TB_overlay', 309 'styles' : { 310 'position' : 'absolute', 311 'top' : '0px', 312 'left' : '0px', 313 'visibility' : 'visible' 314 }, 315 'opacity' : 0 316 }); 317 this.overlay.inject(document.body); 318 319 if( !this.options.noOverlayClose ) { 320 this.overlay.addEvent('click', function() { 321 this.close(); 322 }.bind(this)); 323 } 324 }, 325 326 createWindow : function() 327 { 328 if( this.window ) { 329 return; 330 } 331 332 var bind = this; 333 334 this.window = new Element('div', { 335 'id' : 'TB_window', 336 'opacity' : 0 337 }); 338 this.window.inject(document.body); 339 340 var title = new Element('div', { 341 class: 'relative height_0', 342 style: 'height: 0;' 343 }); 344 title.inject(this.window); 345 346 var titleClose = new Element('div', { 347 class: 'absolute close_popup padding_0 right_0 margin_right_8 top_0 margin_top_6', 348 events : { 349 click : function() { 350 bind.close(); 351 } 352 } 353 }); 354 titleClose.inject(title); 355 356 var titleCloseLink = new Element('a', { 357 id : 'TB_title', 358 href : 'javascript:void(0);', 359 title : '', 360 html : '', 361 events : { 362 click : function() { 363 bind.close(); 364 } 365 } 366 }) 367 titleCloseLink.inject(titleClose); 368 }, 369 370 position : function() 371 { 372 this.positionOverlay(); 373 this.positionWindow(); 374 this.positionLoading(); 375 }, 376 377 positionLoading : function() 378 { 379 if( !this.loading ) 380 { 381 return; 382 } 383 384 if( Browser.Engine.trident /*&& this.loading.style.display == 'none'*/ ){ 385 //this.loading.style.visibility = 'hidden'; 386 //this.loading.style.display = ''; 387 this.loading.style.display = ''; 388 } 389 390 this.loading.setStyles({ 391 left: (window.getScroll().x + (window.getSize().x - 56) / 2) + 'px', 392 top: (window.getScroll().y + ((window.getSize().y - 20) / 2)) + 'px', 393 display: "block" 394 }); 395 }, 396 397 positionOverlay : function() 398 { 399 if( !this.overlay ) 400 { 401 return; 402 } 403 404 if( Browser.Engine.trident /*&& this.overlay.style.display == 'none'*/ ){ 405 //this.overlay.style.visibility = 'hidden'; 406 //this.overlay.style.display = ''; 407 this.overlay.style.display = ''; 408 } 409 410 this.overlay.setStyles({ 411 "height" : '0px', 412 "width" : '0px' 413 }); 414 415 if( !this.options.noOverlay ) 416 { 417 this.overlay.setStyles({ 418 "height" : window.getScrollHeight() + 'px', 419 "width" : window.getScrollWidth() + 'px' 420 }); 421 } 422 }, 423 424 positionWindow : function() 425 { 426 if( !this.window ) { 427 return; 428 } 429 430 if( Browser.ie ) { 431 //this.window.style.visibility = 'hidden'; 432 //this.window.style.display = ''; 433 this.window.style.display = ''; 434 } 435 436 this.window.setStyles({ 437 "width" : this.options.width + 'px', 438 "left" : (window.getScroll().x + (window.getSize().x - this.options.width) / 2) + 'px', 439 "top" : (window.getScroll().y + (window.getSize().y - this.options.height) / 2) + 'px' 440 }); 441 }, 442 443 show : function() 444 { 445 this.showOverlay(); 446 this.showLoading(); 447 this.showWindow(); 448 }, 449 450 showLoading : function() 451 { 452 if( !this.loading ) 453 { 454 return; 455 } 456 457 if( Browser.Engine.trident /*&& this.loading.style.visibility == 'hidden'*/ ){ 458 //this.loading.style.visibility = 'visible'; 459 this.loading.style.display = ''; 460 } 461 462 if( this.options.transitions ) 463 { 464 this.loading.tween('opacity', [0, 1]); 465 } 466 else 467 { 468 this.loading.setStyle('opacity', 1); 469 this.loading.setStyle('visibility', 'visible'); 470 } 471 }, 472 473 showOverlay : function() 474 { 475 if( !this.overlay ) { 476 return; 477 } 478 479 if( Browser.Engine.trident /*&& this.overlay.style.visibility == 'hidden'*/ ){ 480 //this.overlay.style.visibility = 'visible'; 481 this.overlay.style.display = ''; 482 } 483 484 if( this.options.transitions ) 485 { 486 this.overlay.tween('opacity', [0, 0.6]); 487 } 488 else 489 { 490 this.overlay.setStyle('opacity', 0.6); 491 this.overlay.setStyle('visibility', 'visible'); 492 } 493 }, 494 495 showWindow : function() 496 { 497 if( !this.window ) 498 { 499 return; 500 } 501 502 if( Browser.Engine.trident /* && this.window.style.visibility == 'hidden'*/ ){ 503 //this.window.style.visibility = 'visible'; 504 this.window.style.display = ''; 505 } 506 507 // Try to autoresize the window 508 if( typeof(this.doAutoResize) == 'function' ) 509 { 510 this.doAutoResize(); 511 } 512 513 if( this.options.transitions ) { 514 this.window.tween('opacity', [0, 1]); 515 } else { 516 this.window.setStyle('opacity', 1); 517 this.window.setStyle('visibility', 'visible'); 518 } 519 }, 520 521 hide : function() 522 { 523 this.hideLoading(); 524 this.hideOverlay(); 525 this.hideWindow(); 526 }, 527 528 hideLoading : function() 529 { 530 if( !this.loading ) { 531 return; 532 } 533 534 if( this.options.transitions ) { 535 this.loading.tween('opacity', [1, 0]); 536 } else { 537 this.loading.setStyle('opacity', 0); 538 } 539 }, 540 541 hideOverlay : function() 542 { 543 if( !this.overlay ) 544 { 545 return; 546 } 547 548 if( this.options.transitions ) { 549 this.overlay.tween('opacity', [0.6, 0]); 550 } else { 551 this.overlay.setStyle('opacity', 0); 552 } 553 }, 554 555 hideWindow : function() 556 { 557 /* 558 if( !this.window ) 559 { 560 return; 561 } 562 */ 563 564 if( this.options.transitions ) { 565 var bind = this; 566 this.window.tween('opacity', [1, 0]); 567 this.window.get('tween').addEvent('complete', function() { 568 bind.fireEvent('closeafter'); 569 }); 570 } 571 else 572 { 573 this.window.setStyle('opacity', 0); 574 } 575 }, 576 577 578 doAutoResize : function(element) 579 { 580 if( !element || !this.options.autoResize ) 581 { 582 return; 583 } 584 585 var size = Function.attempt(function(){ 586 return element.getScrollSize(); 587 }, function(){ 588 return element.getSize(); 589 }, function(){ 590 return { 591 x : element.scrollWidth, 592 y : element.scrollHeight 593 } 594 }); 595 596 var winSize = window.getSize(); 597 if( size.x - 70 > winSize.x ) size.x = winSize.x - 70; 598 if( size.y - 70 >
598 winSize.y ) size.y = winSize.y - 70; 599 600 601 this.content.setStyles({ 602 'width' : (size.x + 20) + 'px', 603 'height' : (size.y + 20) + 'px' 604 }); 605 606 this.options.width = (size.x + 20); 607 this.options.height = (size.y + 20); 608 609 this.positionWindow(); 610 }, 611 612 613 // events 614 onLoad : function() 615 { 616 this.fireEvent('load', this); 617 }, 618 619 onOpen : function() 620 { 621 this.fireEvent('open', this); 622 }, 623 624 onClose : function() 625 { 626 this.fireEvent('close', this); 627 }, 628 629 onCloseAfter : function() 630 { 631 this.fireEvent('closeafter', this); 632 } 633 634}); 635 636Smoothbox.Modal.Iframe = new Class({ 637 638 Extends : Smoothbox.Modal, 639 640 load : function() 641 { 642 if( this.content ) { 643 return; 644 } 645 646 this.parent(); 647 648 var bind = this; 649 var loadIsOkay = true; 650 651 var uriSrc = new URI(this.options.url); 652 if( this.options.autoFormat ) { 653 uriSrc.setData({'format' : this.options.autoFormat}, true, 'query'); 654 } 655 656 this.content = new IFrame({ 657 src : uriSrc, 658 id : 'TB_iframeContent', 659 name : 'TB_iframeContent', 660 frameborder : '0', 661 width : this.options.width, 662 height : this.options.height, 663 events : { 664 load : function() { 665 if( loadIsOkay ) { 666 loadIsOkay = false; 667 this.hideLoading(); 668 this.showWindow(); 669 this.onLoad(); 670 } else { 671 this.doAutoResize(); 672 } 673 }.bind(this) 674 } 675 }); 676 677 this.content.inject(this.window); 678 }, 679 680 doAutoResize : function() 681 { 682 if( !this.options.autoResize ) { 683 return; 684 } 685 686 // Check if from same host 687 var iframe = this.content; 688 var host = Function.attempt(function(){ 689 return iframe.contentWindow.location.host; 690 }); 691 692 if( !host || host != window.location.host ) { 693 return; 694 } 695 696 // Try to get element 697 if( this.options.autoResize == true ) { 698 var self = this; 699 var element = Function.attempt(function(){ 700 return iframe.contentWindow.document.body.getChildren()[0]; 701 }, function(){ 702 return iframe.contentWindow.document.body; 703 }, function(){ 704 return iframe.contentWindow.document.documentElement; 705 }); 706 707 return this.parent( element ); 708 } 709 710 else if( $type(this.options.autoResize) == 'element' ) 711 { 712 return this.parent( iframe.contentWindow.$(this.options.autoResize) ); 713 } 714 } 715 716}); 717 718Smoothbox.Modal.Request = new Class({ 719 720 Extends : Smoothbox.Modal, 721 722 load : function() 723 { 724 if( this.content ) 725 { 726 return; 727 } 728 729 this.parent(); 730 731 var bind = this; 732 var data = (this.options.requestData || {}); 733 734 if( this.autoFormat ) { 735 data.format = this.autoFormat; 736 } 737 738 (new Request.HTML({ 739 url : this.options.url, 740 method : (this.options.requestMethod || 'get'), 741 data : data, 742 onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) 743 { 744 bind.content = new Element('div', { 745 id : 'TB_ajaxContent', 746 width : bind.options.width, 747 height : bind.options.height, 748 html : responseHTML 749 }); 750 bind.content.inject(bind.window); 751 //responseTree.inject(bind.content); 752 753 bind.hideLoading(); 754 bind.showWindow(); 755 bind.onLoad(); 756 } 757 })).send(); 758 759 } 760 761}); 762 763Smoothbox.Modal.Inline = new Class({ 764 765 Extends : Smoothbox.Modal, 766 767 element : false, 768 769 load : function() 770 { 771 if( this.content ) 772 { 773 return; 774 } 775 776 this.parent(); 777 778 this.content = new Element('div', { 779 id : 'TB_ajaxContent', 780 width : this.options.width, 781 height : this.options.height 782 }); 783 this.content.inject(this.window); 784 785 this.element.clone().inject(this.content); 786 787 this.hideLoading(); 788 this.showWindow(); 789 this.onLoad(); 790 }, 791 792 setOptions : function(options) 793 { 794 this.element = $(options.element); 795 this.parent(options); 796 } 797 798}); 799 800Smoothbox.Modal.String = new Class({ 801 802 Extends : Smoothbox.Modal, 803 804 load : function() 805 { 806 if( this.content ) 807 { 808 return; 809 } 810 811 this.parent(); 812 813 this.content = new Element('div', { 814 id : 'TB_ajaxContent', 815 width : this.options.width, 816 height : this.options.height, 817 html : '<div>
817' + this.options.bodyText + '</div>' 818 }); 819 this.content.inject(this.window); 820 821 this.hideLoading(); 822 this.showWindow(); 823 this.onLoad(); 824 }, 825 826 doAutoResize : function() 827 { 828 if( !this.options.autoResize ) 829 { 830 return; 831 } 832 833 var bind = this; 834 var element = Function.attempt(function(){ 835 return bind.content.getChildren()[0]; 836 }); 837 838 return this.parent( element ); 839 } 840 841}); 842 843Smoothbox.Modal.Image = new Class({ 844 845 Extends : Smoothbox.Modal 846 847}); 848 849window.addEvent('domready', function() 850{ 851 Smoothbox.bind(); 852}) 853 854window.addEvent('load', function() 855{ 856 Smoothbox.bind(); 857})
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.