1/* 2 * nyroModal v2.0.0 3 * Core 4 * 5 * Commit 61895b6ee8cb543cfdaa17d703ec6bcd338fec5f (01/16/2013) * 6 * 7 * Included parts: 8 * - anims.fade 9 * - filters.title 10 * - filters.gallery 11 * - filters.link 12 * - filters.dom 13 * - filters.data 14 * - filters.image 15 * - filters.swf 16 * - filters.form 17 * - filters.formFile 18 * - filters.iframe 19 * - filters.iframeForm 20 * - filters.embedly 21 */ 22/* 23 * nyroModal v2.0.0 24 * Core 25 * 26 */ 27jQuery(function($, undefined) { 28 29 var uaMatch = function(ua) { 30 ua = ua.toLowerCase(); 31 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || 32 /(webkit)[ \/]([\w.]+)/.exec( ua ) || 33 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || 34 /(msie) ([\w.]+)/.exec( ua ) || 35 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || 36 []; 37 38 return { 39 browser: match[ 1 ] || "", 40 version: match[ 2 ] || "0" 41 }; 42 }, 43 matched = uaMatch(navigator.userAgent), 44 browser = {}; 45 46 if (matched.browser) { 47 browser[matched.browser] = true; 48 browser.version = matched.version; 49 } 50 51 // Chrome is Webkit, but Webkit is also Safari. 52 if (browser.chrome) { 53 browser.webkit = true; 54 } else if (browser.webkit) { 55 browser.safari = true; 56 } 57 58 var $w = $(window), 59 $d = $(document), 60 $b = $('body'), 61 baseHref = $('base').attr('href'), 62 // nyroModal Object 63 _nmObj = { 64 filters: [], // List of filters used 65 callbacks: {}, // Sepcific callbacks 66 anims: {}, // Sepcific animations functions 67 loadFilter: undefined, // Name of the filter used for loading 68 69 modal: false, // Indicates if it's a modal window or not 70 closeOnEscape: true, // Indicates if the modal should close on Escape key 71 closeOnClick: true, // Indicates if a click on the background should close the modal 72 useKeyHandler: false, // Indicates if the modal has to handle key down event 73 74 showCloseButton: true, // Indicates if the closeButonn should be added 75 closeButton: '<a href="#" class="nyroModalClose nyroModalCloseButton nmReposition" title="close">Close</a>', // Close button HTML 76 77 stack: false, // Indicates if links automatically binded inside the modal should stack or not 78 nonStackable: 'form', // Filter to not stack DOM element 79 80 header: undefined, // header include in every modal 81 footer: undefined, // footer include in every modal 82 83 // Specific confirguation for gallery filter 84 galleryLoop: true, // Indicates if the gallery should loop 85 galleryCounts: true, // Indicates if the gallery counts should be shown 86 ltr: true, // Left to Right by default. Put to false for Hebrew or Right to Left language. Used in gallery filter 87 88 // Specific confirguation for DOM filter 89 domCopy: false, // Indicates if DOM element should be copied or moved 90 91 // Specific confirguation for link and form filters 92 ajax: {}, // Ajax options to be used in link and form filter 93 94 // Specific confirguation for image filter 95 imageRegex: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\\s*$', // Regex used to detect image link 96 97 selIndicator: 'nyroModalSel', // Value added when a form or Ajax is sent with a filter content 98 99 swfObjectId: undefined, // Object id for swf object 100 swf: { // Default SWF attributes 101 allowFullScreen: 'true', 102 allowscriptaccess: 'always', 103 wmode: 'transparent' 104 }, 105 106 store: {}, // Storage object for filters. 107 errorMsg: 'An error occured', // Error message 108 elts: { // HTML elements for the modal 109 all: undefined, 110 bg: undefined, 111 load: undefined, 112 cont: undefined, 113 hidden: undefined 114 }, 115 sizes: { // Size information 116 initW: undefined, // Initial width 117 initH: undefined, // Initial height 118 w: undefined, // width 119 h: undefined, // height 120 minW: undefined, // minimum Width 121 minH: undefined, // minimum height 122 wMargin: undefined, // Horizontal margin 123 hMargin: undefined // Vertical margin 124 }, 125 anim: { // Animation names to use 126 def: undefined, // Default animation set to use if sspecific are not defined or doesn't exist 127 showBg: undefined, // Set to use for showBg animation 128 hideBg: undefined, // Set to use for hideBg animation 129 showLoad: undefined, // Set to use for showLoad animation 130 hideLoad: undefined, // Set to use for hideLoad animation 131 showCont: undefined, // Set to use for showCont animation 132 hideCont: undefined, // Set to use for hideCont animation 133 showTrans: undefined, // Set to use for showTrans animation 134 hideTrans: undefined, // Set to use for hideTrans animation 135 resize: undefined // Set to use for resize animation 136 }, 137 138 _open: false, // Indicates if the modal is open 139 _bgReady: false, // Indicates if the background is ready 140 _opened: false, // Indicates if the modal was opened (useful for stacking) 141 _loading: false, // Indicates if the loading is shown 142 _animated: false, // Indicates if the modal is currently animated 143 _transition: false, // Indicates if the modal is in transition 144 _needClose: false, // Indicates if the modal should close after current animation 145 _nmOpener: undefined, // nmObj of the modal that opened the current one in non stacking mode
146 _nbContentLoading: 0, // Counter for contentLoading call 147 _scripts: '', // Scripts tags to be included 148 _scriptsShown: '', //Scripts tags to be included once the modal is swhon 149 150 // save the object in data 151 saveObj: function() { 152 this.opener.data('nmObj', this); 153 }, 154 // Open the modal 155 open: function() { 156 if (this._nmOpener) 157 this._nmOpener._close(); 158 this.getInternal()._pushStack(this.opener); 159 this._opened = false; 160 this._bgReady = false; 161 this._open = true; 162 this._initElts(); 163 this._load(); 164 this._nbContentLoading = 0; 165 this._callAnim('showBg', $.proxy(function() { 166 this._bgReady = true; 167 if (this._nmOpener) { 168 // fake closing of the opener nyroModal 169 this._nmOpener._bgReady = false; 170 this._nmOpener._loading = false; 171 this._nmOpener._animated = false; 172 this._nmOpener._opened = false; 173 this._nmOpener._open = false; 174 this._nmOpener.elts.cont = this._nmOpener.elts.hidden = this._nmOpener.elts.load = this._nmOpener.elts.bg = this._nmOpener.elts.all = undefined; 175 this._nmOpener.saveObj(); 176 this._nmOpener = undefined; 177 } 178 this._contentLoading(); 179 }, this)); 180 }, 181 182 // Resize the modal according to sizes.initW and sizes.initH 183 // Will call size function 184 // @param recalc boolean: Indicate if the size should be recalaculated (useful when content has changed) 185 resize: function(recalc, w) { 186 if (recalc) { 187 this.elts.hidden.append(this.elts.cont.children().first().clone()); 188 this.sizes.initW = this.sizes.w = this.elts.hidden.width(); 189 this.sizes.initH = this.sizes.h = this.elts.hidden.height(); 190 this.elts.hidden.empty(); 191 } else { 192 this.sizes.w = this.sizes.initW; 193 this.sizes.h = this.sizes.initH; 194 } 195 this._unreposition(); 196 this.size(); 197 this._callAnim('resize', $.proxy(function() { 198 199 this._reposition(); 200 if( $(window).height() < $('.nyroModalLink').height()){ 201 try{ 202 $('.nyroModalCont').width($('.nyroModalCont').width()+17); 203 }catch(e){} 204 }else{ 205 if(w > $('.nyroModalLink').width()){ 206 $('.nyroModalCont').css("overflow","hidden"); 207 } 208 } 209 }, this)); 210 }, 211 212 // Update sizes element to not go outsize the viewport. 213 // Will call 'size' callback filter 214 size: function() { 215 var maxHeight = this.getInternal().fullSize.viewH - this.sizes.hMargin, 216 maxWidth = this.getInternal().fullSize.viewW - this.sizes.wMargin; 217 if (this.sizes.minW && this.sizes.minW > this.sizes.w) 218 this.sizes.w = this.sizes.minW; 219 if (this.sizes.minH && this.sizes.minH > this.sizes.h) 220 this.sizes.h = this.sizes.minH; 221 if (this.sizes.h > maxHeight || this.sizes.w > maxWidth) { 222 // We're gonna resize the modal as it will goes outside the view port 223 this.sizes.h = Math.min(this.sizes.h, maxHeight); 224 this.sizes.w = Math.min(this.sizes.w, maxWidth); 225 } 226 this._callFilters('size'); 227 }, 228 229 // Get the nmObject for a new nyroModal 230 getForNewLinks: function(elt) { 231 var ret; 232 if (this.stack && (!elt || this.isStackable(elt))) { 233 ret = $.extend(true, {}, this); 234 ret._nmOpener = undefined; 235 ret.elts.all = undefined; 236 } else { 237 ret = $.extend({}, this); 238 ret._nmOpener = this; 239 } 240 ret.filters = []; 241 ret.opener = undefined; 242 ret._open = false; 243 return ret; 244 }, 245 246 // Indicate if an element can be stackable or not, regarding the nonStackable setting 247 isStackable: function(elt) { 248 return !elt.is(this.nonStackable); 249 }, 250 251 // key handle function. 252 // Will call 'keyHandle' callback filter 253 keyHandle: function(e) { 254 this.keyEvent = e; 255 this._callFilters('keyHandle'); 256 this.keyEvent = undefined; 257 delete(this.keyEvent); 258 }, 259 260 // Get the internal object 261 getInternal: function() { 262 return _internal; 263 }, 264 265 // Internal function for closing a nyroModal 266 // Will call 'close' callback filter 267 _close: function() { 268 var ret = true; 269 if (!this._animated) { 270 $.each(this._callFilters('close'), function(k, v) { 271 if (v === false) 272 ret = false; 273 });
274 if (ret) { 275 this.getInternal()._removeStack(this.opener); 276 this._opened = false; 277 this._open = false; 278 } 279 } else { 280 this._needClose = true; 281 ret = false; 282 } 283 return ret; 284 }, 285 // Public function for closing a nyroModal 286 close: function() { 287 if (this._close()) { 288 this._needClose = false; 289 this._callFilters('beforeClose'); 290 var self = this; 291 this._unreposition(); 292 self._callAnim('hideCont', function() { 293 self._callAnim('hideLoad', function() { 294 self._callAnim('hideBg', function() { 295 self._callFilters('afterClose'); 296 self.elts.cont.remove(); 297 self.elts.hidden.remove(); 298 self.elts.load.remove(); 299 self.elts.bg.remove(); 300 self.elts.all.remove(); 301 self.elts.cont = self.elts.hidden = self.elts.load = self.elts.bg = self.elts.all = undefined; 302 }); 303 }); 304 }); 305 } 306 }, 307 308 // Public function for destroying a nyroModal instance, only for non open modal 309 destroy: function() { 310 if (this._open) 311 return false; 312 this._callFilters('destroy'); 313 if (this.elts.all) 314 this.elts.all.remove(); 315 return true; 316 }, 317 318 // Init HTML elements 319 _initElts: function() { 320 if (!this.stack && this.getInternal().stack.length > 1) 321 this.elts = this.getInternal().stack[this.getInternal().stack.length-2]['nmObj'].elts; 322 if (!this.elts.all || this.elts.all.closest('body').length == 0) 323 this.elts.all = this.elts.bg = this.elts.cont = this.elts.hidden = this.elts.load = undefined; 324 if (!this.elts.all) 325 this.elts.all = $('<div />').appendTo(this.getInternal()._container); 326 if (!this.elts.bg) 327 this.elts.bg = $('<div />').hide().appendTo(this.elts.all); 328 if (!this.elts.cont) 329 this.elts.cont = $('<div />').hide().appendTo(this.elts.all); 330 if (!this.elts.hidden) 331 this.elts.hidden = $('<div />').hide().appendTo(this.elts.all); 332 this.elts.hidden.empty(); 333 if (!this.elts.load) 334 this.elts.load = $('<div />').hide().appendTo(this.elts.all); 335 this._callFilters('initElts'); 336 }, 337 338 // Trigger the error 339 // Will call 'error' callback filter 340 _error: function(jqXHR) { 341 this._callFilters('error', jqXHR); 342 }, 343 344 // Set the HTML content to show. 345 // - html: HTML content 346 // - selector: selector to filter the content 347 // Will init the size and call the 'size' function. 348 // Will call 'filledContent' callback filter 349 _setCont: function(html, selector) { 350 if (selector) { 351 var tmp = [], 352 i = 0; 353 // Looking for script to store them 354 html = html 355 .replace(/\r\n/gi, 'nyroModalLN') 356 .replace(/<script(.|\s)*?\/script>/gi, function(x) { 357 tmp[i] = x; 358 return '<pre class=nyroModalScript rel="'+(i++)+'"></pre>'; 359 }); 360 var cur = $('<div>'+html+'</div>').find(selector); 361 if (cur.length) { 362 html = cur.html() 363 .replace(/<pre class="?nyroModalScript"? rel="?([0-9]*)"?><\/pre>/gi, function(x, y, z) { return tmp[y]; }) 364 .replace(/nyroModalLN/gi, "\r\n"); 365 } else { 366 // selector not found 367 this._error(); 368 return; 369 } 370 } 371 this.elts.hidden 372 .append(this._filterScripts(html)) 373 .prepend(this.header) 374 .append(this.footer) 375 .wrapInner($('<div />', {'class': 'nyroModal'+ucfirst(this.loadFilter)})); 376 377 // Store the size of the element 378 this.sizes.initW = this.sizes.w = this.elts.hidden.width(); 379 this.sizes.initH = this.sizes.h = this.elts.hidden.height(); 380 var outer = this.getInternal()._getOuter(this.elts.cont); 381 this.sizes.hMargin = outer.h.total; 382 this.sizes.wMargin = outer.w.total; 383 384 this.size(); 385 386 this.loading = false; 387 this._callFilters('filledContent'); 388 this._contentLoading(); 389 }, 390 391 // Filter an html content to remove the script[src] and store them appropriately if needed 392 // - data: Data to filter 393 _filterScripts: function(data) { 394 if (typeof data != 'string') 395 return data; 396 397 this._scripts = []; 398 this._scriptsShown = []; 399 var start = 0, 400 stStart = '<script', 401 stEnd = '</script>', 402 endLn = stEnd.length, 403 pos, 404 pos2, 405 tmp; 406 while ((pos = data.indexOf(stStart, start)) > -1) { 407 pos2 = data.indexOf(stEnd)+endLn; 408 tmp = $(data.substring(pos, pos2)); 409 if (!tmp.attr('src') || tmp.attr('rel') == 'forceLoad') { 410 if (tmp.attr('rev') == 'shown') 411 this._scriptsShown.push(tmp.get(0)); 412 else 413 this._scripts.push(tmp.get(0)); 414 } 415 data = data.substring(0, pos)+data.substr(pos2); 416 start = pos; 417 } 418 return data; 419 }, 420 421 // Check if the nmObject has a specific filter 422 // - filter: Filter name 423 _hasFilter: function(filter) { 424 var ret = false; 425 $.each(this.filters, function(i, f) { 426 ret = ret || f == filter; 427 }); 428 return ret; 429 }, 430 431 // Remove a specific filter 432 // - filter: Filter name 433 _delFilter: function(filter) { 434 this.filters = $.map(this.filters, function(v) { 435 if (v != filter) 436 return v; 437 }); 438 }, 439 440 // Call a function against all active filters 441 // - fct: Function name 442 // - prm: Parameter to be used in callback
443 // return an array of all return of callbacks; keys are filters name 444 _callFilters: function(fct, prm) { 445 this.getInternal()._debug(fct, prm); 446 if (this.opener && this.opener.length) { 447 this.opener.trigger(fct+'.nyroModal', [this, prm]); 448 } else { 449 $b.trigger(fct+'.nyroModal', [this, prm]); 450 } 451 var ret = {}, 452 self = this; 453 $.each(this.filters, function(i, f) { 454 ret[f] = self._callFilter(f, fct, prm); 455 }); 456 if (this.callbacks[fct] && $.isFunction(this.callbacks[fct])) 457 ret['callbacks'] = this.callbacks[fct](this, prm); 458 return ret; 459 }, 460 461 // Call a filter function for a specific filter 462 // - f: Filter name 463 // - fct: Function name 464 // - prm: Parameter to be used in callback 465 // return the return of the callback 466 _callFilter: function(f, fct, prm) { 467 if (_filters[f] && _filters[f][fct] && $.isFunction(_filters[f][fct])) 468 return _filters[f][fct](this, prm); 469 return undefined; 470 }, 471 472 // Call animation callback. 473 // Will also call beforeNNN and afterNNN filter callbacks 474 // - fct: Animation function name 475 // - clb: Callback once the animation is done 476 _callAnim: function(fct, clb) { 477 this.getInternal()._debug(fct, clb); 478 this._callFilters('before'+ucfirst(fct)); 479 if (!this._animated) { 480 this._animated = true; 481 if (!$.isFunction(clb)) clb = $.noop; 482 if (this.anims[fct] && $.isFunction(this.anims[fct])) { 483 curFct = this.anims[fct]; 484 } else { 485 var set = this.anim[fct] || this.anim.def || 'basic'; 486 if (!_animations[set] || !_animations[set][fct] || !$.isFunction(_animations[set][fct])) 487 set = 'basic'; 488 curFct = _animations[set][fct]; 489 } 490 curFct(this, $.proxy(function() { 491 this._animated = false; 492 this._callFilters('after'+ucfirst(fct)); 493 clb(); 494 if (this._needClose) 495 setTimeout($.proxy(function() {this.close();}, this), 50); 496 }, this)); 497 } 498 }, 499 500 // Load the content 501 // Will call the 'load' function of the filter specified in the loadFilter parameter 502 _load: function() { 503 this.getInternal()._debug('_load'); 504 if (!this.loading && this.loadFilter) { 505 this.loading = true; 506 this._callFilter(this.loadFilter, 'load'); 507 } 508 }, 509 510 // Show the content or the loading according to the current state of the modal 511 _contentLoading: function() { 512 if (!this._animated && this._bgReady) { 513 if (!this._transition && this.elts.cont.html().length > 0) 514 this._transition = true; 515 this._nbContentLoading++; 516 if (!this.loading) { 517 if (!this._opened) { 518 this._opened = true; 519 if (this._transition) { 520 var fct = $.proxy(function() { 521 this._writeContent(); 522 this._callFilters('beforeShowCont'); 523 this._callAnim('hideTrans', $.proxy(function() { 524 this._transition = false; 525 this._callFilters('afterShowCont'); 526 this.elts.cont.append(this._scriptsShown); 527 this._reposition(); 528 this.elts.cont.scrollTop(0); 529 }, this)); 530 }, this); 531 if (this._nbContentLoading == 1) { 532 this._unreposition(); 533 this._callAnim('showTrans', fct); 534 } else { 535 fct(); 536 } 537 } else { 538 this._callAnim('hideLoad', $.proxy(function() { 539 this._writeContent(); 540 this._callAnim('showCont', $.proxy(function() { 541 this.elts.cont.append(this._scriptsShown); 542 this._reposition(); 543 this.elts.cont.scrollTop(0); 544 }, this)); 545 }, this)); 546 } 547 } 548 } else if (this._nbContentLoading == 1) { 549 var outer = this.getInternal()._getOuter(this.elts.load); 550 this.elts.load 551 .css({ 552 position: 'fixed', 553 top: (this.getInternal().fullSize.viewH - this.elts.load.height() - outer.h.margin)/2, 554 left: (this.getInternal().fullSize.viewW - this.elts.load.width() - outer.w.margin)/2 555 }); 556 if (this._transition) { 557 this._unreposition(); 558 this._callAnim('showTrans', $.proxy(function() { 559 this._contentLoading(); 560 }, this)); 561 } else { 562 this._callAnim('showLoad', $.proxy(function() { 563 this._contentLoading(); 564 }, this)); 565 } 566 } 567 } 568 }, 569 570 // Write the content in the modal. 571 // Content comes from the hidden div, scripts and eventually close button. 572 _writeContent: function() { 573 this.elts.cont 574 .empty() 575 .append(this.elts.hidden.contents()) 576 .append(this._scripts) 577 .append(this.showCloseButton ? this.closeButton : '') 578 .css({ 579 position: 'fixed', 580 width: this.sizes.w, 581 height: this.sizes.h, 582 top: (this.getInternal().fullSize.viewH - this.sizes.h - this.sizes.hMargin)/2, 583 left: (this.getInternal().fullSize.viewW - this.sizes.w - this.sizes.wMargin)/2 584 });
585 }, 586 587 // Reposition elements with a class nmReposition 588 _reposition: function() { 589 var elts = this.elts.cont.find('.nmReposition'); 590 if (elts.length) { 591 var space = this.getInternal()._getSpaceReposition(); 592 elts.each(function() { 593 var me = $(this), 594 offset = me.offset(); 595 me.css({ 596 position: 'fixed', 597 top: offset.top - space.top, 598 left: offset.left - space.left 599 }); 600 }); 601 this.elts.cont.after(elts); 602 } 603 this.elts.cont.css('overflow', 'auto'); 604 this._callFilters('afterReposition'); 605 }, 606 607 // Unreposition elements with a class nmReposition 608 // Exaclty the reverse of the _reposition function 609 _unreposition: function() { 610 this.elts.cont.css('overflow', ''); 611 var elts = this.elts.all.find('.nmReposition'); 612 if (elts.length) 613 this.elts.cont.append(elts.removeAttr('style')); 614 this._callFilters('afterUnreposition'); 615 } 616 }, 617 _internal = { 618 firstInit: true, 619 debug: false, 620 stack: [], 621 fullSize: { 622 w: 0, 623 h: 0, 624 wW: 0, 625 wH: 0, 626 viewW: 0, 627 viewH: 0 628 }, 629 nyroModal: function(opts, fullObj) { 630 if (_internal.firstInit) {
631 _internal._container = $('<div />').appendTo($b); 632 $w.smartresize($.proxy(_internal._resize, _internal)); 633 $d.on('keydown.nyroModal', $.proxy(_internal._keyHandler, _internal)); 634 _internal._calculateFullSize(); 635 _internal.firstInit = false; 636 } 637 return this.nmInit(opts, fullObj).each(function() { 638 _internal._init($(this).data('nmObj')); 639 }); 640 }, 641 nmInit: function(opts, fullObj) { 642 return this.each(function() { 643 var me = $(this); 644 if (fullObj) 645 me.data('nmObj', $.extend(true, {opener: me}, opts)); 646 else 647 me.data('nmObj', 648 me.data('nmObj') 649 ? $.extend(true, me.data('nmObj'), opts) 650 : $.extend(true, {opener: me}, _nmObj, opts)); 651 }); 652 }, 653 nmDestroy: function() { 654 return this.each(function() { 655 var me = $(this); 656 if (me.data('nmObj')) { 657 if (me.data('nmObj').destroy()) 658 me.removeData('nmObj'); 659 } 660 }); 661 }, 662 nmCall: function() { 663 return this.trigger('nyroModal'); 664 }, 665 666 nmManual: function(url, opts) { 667 $('<a />', {href: url}).nyroModal(opts).trigger('nyroModal'); 668 }, 669 nmData: function(data, opts) { 670 this.nmManual('#', $.extend({data: data}, opts)); 671 }, 672 nmObj: function(opts) { 673 $.extend(true, _nmObj, opts); 674 }, 675 nmInternal: function(opts) { 676 $.extend(true, _internal, opts); 677 }, 678 nmAnims: function(opts) { 679 $.extend(true, _animations, opts); 680 }, 681 nmFilters: function(opts) { 682 $.extend(true, _filters, opts); 683 }, 684 nmTop: function() { 685 if (_internal.stack.length) 686 return _internal.stack[_internal.stack.length-1]['nmObj']; 687 return undefined; 688 }, 689 690 _debug: function() { 691 if (this.debug && window.console && window.console.log) 692 window.console.log.apply(window.console, arguments); 693 }, 694 695 _container: undefined, 696 697 _init: function(nm) { 698 nm.filters = []; 699 $.each(_filters, function(f, obj) { 700 if (obj.is && $.isFunction(obj.is) && obj.is(nm)) { 701 nm.filters.push(f); 702 } 703 }); 704 nm._callFilters('initFilters'); 705 nm._callFilters('init'); 706 nm.opener 707 .off('nyroModal.nyroModal nmClose.nyroModal nmResize.nyroModal') 708 .on({ 709 'nyroModal.nyroModal': function() { nm.open(); return false;}, 710 'nmClose.nyroModal': function() { nm.close(); return false;}, 711 'nmResize.nyroModal': function() { nm.resize(); return false;} 712 }); 713 }, 714 715 _selNyroModal: function(obj) { 716 return $(obj).data('nmObj') ? true : false; 717 }, 718 719 _selNyroModalOpen: function(obj) { 720 var me = $(obj); 721 return me.data('nmObj') ? me.data('nmObj')._open : false; 722 }, 723 724 _keyHandler: function(e) { 725 var nmTop = $.nmTop(); 726 if (nmTop && nmTop.useKeyHandler) { 727 return nmTop.keyHandle(e); 728 } 729 }, 730 _pushStack: function(obj) { 731 this.stack = $.map(this.stack, function(elA) { 732 if (elA['nmOpener'] != obj.get(0)) 733 return elA; 734 }); 735 this.stack.push({ 736 nmOpener: obj.get(0), 737 nmObj: $(obj).data('nmObj') 738 }); 739 }, 740 _removeStack: function(obj) { 741 this.stack = $.map(this.stack, function(elA) { 742 if (elA['nmOpener'] != obj.get(0)) 743 return elA; 744 }); 745 }, 746 _resize: function() { 747 $.each(this.stack, function(k, v) { 748 v.nmObj._unreposition(); 749 }); 750 this._calculateFullSize(); 751 $.each(this.stack, function(k, v) { 752 v.nmObj.resize(); 753 }); 754 }, 755 _calculateFullSize: function() { 756 this.fullSize = { 757 w: $d.width(), 758 h: $d.height(), 759 wW: $w.width(), 760 wH: $w.height() 761 }; 762 this.fullSize.viewW = Math.min(this.fullSize.w, this.fullSize.wW); 763 this.fullSize.viewH = Math.min(this.fullSize.h, this.fullSize.wH); 764 }, 765 _getCurCSS: function(elm, name) { 766 var ret = parseInt($.css(elm, name, true)); 767 return isNaN(ret) ? 0 : ret; 768 }, 769 _getOuter: function(elm) { 770 elm = elm.get(0); 771 var ret = { 772 h: { 773 margin: this._getCurCSS(elm, 'marginTop') + this._getCurCSS(elm, 'marginBottom'), 774 border: this._getCurCSS(elm, 'borderTopWidth') + this._getCurCSS(elm, 'borderBottomWidth'), 775 padding: this._getCurCSS(elm, 'paddingTop') + this._getCurCSS(elm, 'paddingBottom') 776 }, 777 w: { 778 margin: this._getCurCSS(elm, 'marginLeft') + this._getCurCSS(elm, 'marginRight'), 779 border: this._getCurCSS(elm, 'borderLeftWidth') + this._getCurCSS(elm, 'borderRightWidth'), 780 padding: this._getCurCSS(elm, 'paddingLeft') + this._getCurCSS(elm, 'paddingRight') 781 } 782 }; 783 784 ret.h.outer = ret.h.margin + ret.h.border; 785 ret.w.outer = ret.w.margin + ret.w.border; 786 787 ret.h.inner = ret.h.padding + ret.h.border; 788 ret.w.inner = ret.w.padding + ret.w.border; 789 790 ret.h.total = ret.h.outer + ret.h.padding; 791 ret.w.total = ret.w.outer + ret.w.padding; 792 793 return ret; 794 }, 795 _getSpaceReposition: function() { 796 var outer = this._getOuter($b), 797 ie7 = browser.msie && browser.version < 8 && !(screen.height <= $
797w.height()+23); 798 return { 799 top: $w.scrollTop() - (!ie7 ? outer.h.border / 2 : 0), 800 left: $w.scrollLeft() - (!ie7 ? outer.w.border / 2 : 0) 801 }; 802 }, 803 804 _getHash: function(url) { 805 if (typeof url == 'string') { 806 var hashPos = url.indexOf('#'); 807 if (hashPos > -1) 808 return url.substring(hashPos); 809 } 810 return ''; 811 }, 812 _extractUrl: function(url) { 813 var ret = { 814 url: undefined, 815 sel: undefined 816 }; 817 818 if (url) { 819 var hash = this._getHash(url), 820 hashLoc = this._getHash(window.location.href), 821 curLoc = window.location.href.substring(0, window.location.href.length - hashLoc.length), 822 req = url.substring(0, url.length - hash.length); 823 ret.sel = hash; 824 if (req != curLoc && req != baseHref) 825 ret.url = req; 826 } 827 return ret; 828 } 829 }, 830 _animations = { 831 basic: { 832 showBg: function(nm, clb) { 833 nm.elts.bg.css({opacity: 0.7}).show(); 834 clb(); 835 }, 836 hideBg: function(nm, clb) { 837 nm.elts.bg.hide(); 838 clb(); 839 }, 840 showLoad: function(nm, clb) { 841 nm.elts.load.show(); 842 clb(); 843 }, 844 hideLoad: function(nm, clb) { 845 nm.elts.load.hide(); 846 clb(); 847 }, 848 showCont: function(nm, clb) { 849 nm.elts.cont.show(); 850 clb(); 851 }, 852 hideCont: function(nm, clb) { 853 nm.elts.cont.hide(); 854 clb(); 855 }, 856 showTrans: function(nm, clb) { 857 nm.elts.cont.hide(); 858 nm.elts.load.show(); 859 clb(); 860 }, 861 hideTrans: function(nm, clb) { 862 nm.elts.cont.show(); 863 nm.elts.load.hide(); 864 clb(); 865 }, 866 resize: function(nm, clb) { 867 nm.elts.cont.css({ 868 width: nm.sizes.w, 869 height: nm.sizes.h, 870 top: (nm.getInternal().fullSize.viewH - nm.sizes.h - nm.sizes.hMargin)/2, 871 left: (nm.getInternal().fullSize.viewW - nm.sizes.w - nm.sizes.wMargin)/2 872 }); 873 clb(); 874 } 875 } 876 }, 877 _filters = { 878 basic: { 879 is: function(nm) { 880 return true; 881 }, 882 init: function(nm) { 883 if (nm.opener.attr('rev') == 'modal') 884 nm.modal = true; 885 if (nm.modal) 886 nm.closeOnEscape = nm.closeOnClick = nm.showCloseButton = false; 887 if (nm.closeOnEscape) 888 nm.useKeyHandler = true; 889 }, 890 initElts: function(nm) { 891 nm.elts.bg.addClass('nyroModalBg'); 892 nm.elts.cont.addClass('nyroModalCont'); 893 nm.elts.hidden.addClass('nyroModalCont nyroModalHidden'); 894 nm.elts.load.addClass('nyroModalCont nyroModalLoad'); 895 }, 896 error: function(nm) { 897 nm.elts.hidden.addClass('nyroModalError'); 898 nm.elts.cont.addClass('nyroModalError'); 899 nm._setCont(nm.errorMsg); 900 }, 901 beforeShowCont: function(nm) { 902 nm.elts.cont 903 .find('.nyroModal').each(function() { 904 var cur = $(this); 905 cur.nyroModal(nm.getForNewLinks(cur), true); 906 }).end() 907 .find('.nyroModalClose').on('click.nyroModal', function(e) { 908 e.preventDefault(); 909 nm.close(); 910 }); 911 }, 912 afterShowCont: function(nm) { 913 if (nm.closeOnClick) 914 nm.elts.bg.off('click.nyroModal').on('click.nyroModal', function(e) { 915 e.preventDefault(); 916 nm.close(); 917 }); 918 }, 919 keyHandle: function(nm) { 920 // used for escape key 921 if (nm.keyEvent.keyCode == 27 && nm.closeOnEscape) { 922 nm.keyEvent.preventDefault(); 923 nm.close(); 924 } 925 } 926 }, 927 928 custom: { 929 is: function(nm) { 930 return true; 931 } 932 } 933 }; 934 935 // Add jQuery call fucntions 936 $.fn.extend({ 937 nm: _internal.nyroModal, 938 nyroModal: _internal.nyroModal, 939 nmInit: _internal.nmInit, 940 nmDestroy: _internal.nmDestroy, 941 nmCall: _internal.nmCall 942 }); 943 944 // Add global jQuery functions 945 $.extend({ 946 nmManual: _internal.nmManual, 947 nmData: _internal.nmData, 948 nmObj: _internal.nmObj, 949 nmInternal: _internal.nmInternal, 950 nmAnims: _internal.nmAnims, 951 nmFilters: _internal.nmFilters, 952 nmTop: _internal.nmTop 953 }); 954 955 // Add jQuery selectors 956 $.expr[':'].nyroModal = $.expr[':'].nm = _internal._selNyroModal; 957 $.expr[':'].nmOpen = _internal._selNyroModalOpen; 958}); 959 960// Smartresize plugin 961(function($,sr){ 962 963 // debouncing function from John Hann 964 // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ 965 var debounce = function (func, threshold, execAsap) { 966 var timeout; 967 968 return function debounced () { 969 var obj = this, args = arguments; 970 function delayed () { 971 if (!execAsap) 972 func.apply(obj, args); 973 timeout = null; 974 }; 975 976 if (timeout) 977 clearTimeout(timeout); 978 else if (execAsap) 979 func.apply(obj, args); 980 981 timeout = setTimeout(delayed, threshold || 100); 982 }; 983 }; 984 // smartresize 985 jQuery.fn[sr] = function(fn){ return fn ? this.on('resize', debounce(fn)) : this.trigger(sr); }; 986 987})(jQuery,'smartresize'); 988// ucFirst 989function ucfirst(str) { 990 // http://kevin.vanzonneveld.net 991 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 992 // + bugfixed by: Onno Marsman 993 // + improved by: Brett Zamir (http://brett-zamir.me) 994 // * example 1: ucfirst('kevin van zonneveld'); 995 // * returns 1: 'Kevin van zonneveld' 996 str += ''; 997 var f = str.charAt(0).toUpperCase(); 998 return f + str.substr(1); 999} 1000/* 1001 * nyroModal v2.0.0 1002 * 1003 * Fade animations 1004 * 1005 * Depends: 1006 * 1007 */ 1008jQuery(function($, undefined) { 1009 $.nmAnims({
1010 fade: { 1011 showBg: function(nm, clb) { 1012 nm.elts.bg.fadeTo(250, 0.7, clb); 1013 }, 1014 hideBg: function(nm, clb) { 1015 nm.elts.bg.fadeOut(clb); 1016 }, 1017 showLoad: function(nm, clb) { 1018 nm.elts.load.fadeIn(clb); 1019 }, 1020 hideLoad: function(nm, clb) { 1021 nm.elts.load.fadeOut(clb); 1022 }, 1023 showCont: function(nm, clb) { 1024 nm.elts.cont.fadeIn(clb); 1025 }, 1026 hideCont: function(nm, clb) { 1027 nm.elts.cont.css('overflow', 'hidden').fadeOut(clb); 1028 }, 1029 showTrans: function(nm, clb) { 1030 nm.elts.load 1031 .css({ 1032 position: nm.elts.cont.css('position'), 1033 top: nm.elts.cont.css('top'), 1034 left: nm.elts.cont.css('left'), 1035 width: nm.elts.cont.css('width'), 1036 height: nm.elts.cont.css('height'), 1037 marginTop: nm.elts.cont.css('marginTop'), 1038 marginLeft: nm.elts.cont.css('marginLeft') 1039 }) 1040 .fadeIn(function() { 1041 nm.elts.cont.hide(); 1042 clb(); 1043 }); 1044 }, 1045 hideTrans: function(nm, clb) { 1046 nm.elts.cont.css('visibility', 'hidden').show(); 1047 nm.elts.load 1048 .css('position', nm.elts.cont.css('position')) 1049 .animate({ 1050 top: nm.elts.cont.css('top'), 1051 left: nm.elts.cont.css('left'), 1052 width: nm.elts.cont.css('width'), 1053 height: nm.elts.cont.css('height'), 1054 marginTop: nm.elts.cont.css('marginTop'), 1055 marginLeft: nm.elts.cont.css('marginLeft') 1056 }, function() { 1057 nm.elts.cont.css('visibility', ''); 1058 nm.elts.load.fadeOut(clb); 1059 }); 1060 }, 1061 resize: function(nm, clb) { 1062 nm.elts.cont.animate({ 1063 width: nm.sizes.w, 1064 height: nm.sizes.h, 1065 top: (nm.getInternal().fullSize.viewH - nm.sizes.h - nm.sizes.hMargin)/2, 1066 left: (nm.getInternal().fullSize.viewW - nm.sizes.w - nm.sizes.wMargin)/2 1067 }, clb); 1068 } 1069 } 1070 }); 1071 // Define fade aniamtions as default 1072 $.nmObj({anim: {def: 'fade'}}); 1073}); 1074/* 1075 * nyroModal v2.0.0 1076 * 1077 * Title filter 1078 * 1079 * Depends: 1080 * 1081 * Before: 1082 */ 1083jQuery(function($, undefined) { 1084 $.nmFilters({ 1085 title: { 1086 is: function(nm) { 1087 return nm.opener.is('[title]'); 1088 }, 1089 beforeShowCont: function(nm) { 1090 var offset = nm.elts.cont.offset(); 1091 nm.store.title = $('<h1 />', { 1092 text: nm.opener.attr('title') 1093 }).addClass('nyroModalTitle nmReposition'); 1094 nm.elts.cont.prepend(nm.store.title); 1095 }, 1096 close: function(nm) { 1097 if (nm.store.title) { 1098 nm.store.title.remove(); 1099 nm.store.title = undefined; 1100 delete(nm.store.title); 1101 } 1102 } 1103 } 1104 }); 1105}); 1106/* 1107 * nyroModal v2.0.0 1108 * 1109 * Gallery filter 1110 * 1111 * Depends: 1112 * - filters.title 1113 * 1114 * Before: filters.title 1115 */ 1116jQuery(function($, undefined) { 1117 $.nmFilters({ 1118 gallery: { 1119 is: function(nm) { 1120 var ret = nm.opener.is('[rel]:not([rel=external], [rel=nofollow])'); 1121 if (ret) { 1122 var rel = nm.opener.attr('rel'), 1123 indexSpace = rel.indexOf(' '), 1124 gal = indexSpace > 0 ? rel.substr(0, indexSpace) : rel, 1125 links = $('[href][rel="'+gal+'"], [href][rel^="'+gal+' "]'); 1126 if (links.length < 2) 1127 ret = false; 1128 if (ret && nm.galleryCounts && !nm._hasFilter('title')) 1129 nm.filters.push('title'); 1130 } 1131 return ret; 1132 }, 1133 init: function(nm) { 1134 nm.useKeyHandler = true; 1135 }, 1136 keyHandle: function(nm) { 1137 // used for arrows key 1138 if (!nm._animated && nm._opened) { 1139 if (nm.keyEvent.keyCode == 39 || nm.keyEvent.keyCode == 40) { 1140 nm.keyEvent.preventDefault(); 1141 nm._callFilters('galleryNext'); 1142 } else if (nm.keyEvent.keyCode == 37 || nm.keyEvent.keyCode == 38) { 1143 nm.keyEvent.preventDefault(); 1144 nm._callFilters('galleryPrev'); 1145 } 1146 } 1147 }, 1148 initElts: function(nm) { 1149 var rel = nm.opener.attr('rel'), 1150 indexSpace = rel.indexOf(' '); 1151 nm.store.gallery = indexSpace > 0 ? rel.substr(0, indexSpace) : rel; 1152 nm.store.galleryLinks = $('[href][rel="'+nm.store.gallery+'"], [href][rel^="'+nm.store.gallery+' "]'); 1153 nm.store.galleryIndex = nm.store.galleryLinks.index(nm.opener); 1154 }, 1155 beforeShowCont: function(nm) { 1156 if (nm.galleryCounts && nm.store.title && nm.store.galleryLinks && nm.store.galleryLinks.length > 1) { 1157 var curTitle = nm.store.title.html(); 1158 nm.store.title.html((curTitle.length ? curTitle+' - ' : '')+(nm.store.galleryIndex+1)+'/'+nm.store.galleryLinks.length); 1159 } 1160 }, 1161 filledContent: function(nm) { 1162 var link = this._getGalleryLink(nm, -1), 1163 append = nm.elts.hidden.find(' > div'); 1164 if (link) { 1165 $('<a />', { 1166 text: 'previous', 1167 href: '#' 1168 }) 1169 .addClass('nyroModalPrev') 1170 .on('click', function(e) { 1171 e.preventDefault(); 1172 nm._callFilters('galleryPrev'); 1173 }) 1174 .appendTo(append); 1175 } 1176 link = this._getGalleryLink(nm, 1); 1177 if (link) { 1178 $('<a />', { 1179 text: 'next', 1180 href: '#' 1181 }) 1182 .addClass('nyroModalNext') 1183 .on('click', function(e) { 1184 e.preventDefault(); 1185 nm._callFilters('galleryNext'); 1186 }) 1187 .appendTo(append); 1188 } 1189 }, 1190 close: function(nm) { 1191 nm.store.gallery = undefined; 1192 nm.store.galleryLinks = undefined; 1193 nm.store.galleryIndex = undefined; 1194 delete(nm.store.gallery); 1195 delete(nm.store.galleryLinks); 1196 delete(nm.store.galleryIndex); 1197 if (nm.elts.cont)
1198 nm.elts.cont.find('.nyroModalNext, .nyroModalPrev').remove(); 1199 }, 1200 galleryNext: function(nm) { 1201 this._getGalleryLink(nm, 1).nyroModal(nm.getForNewLinks(), true).click(); 1202 }, 1203 galleryPrev: function(nm) { 1204 this._getGalleryLink(nm, -1).nyroModal(nm.getForNewLinks(), true).click(); 1205 }, 1206 _getGalleryLink: function(nm, dir) { 1207 if (nm.store.gallery) { 1208 if (!nm.ltr) 1209 dir *= -1; 1210 var index = nm.store.galleryIndex + dir; 1211 if (nm.store.galleryLinks && index >= 0 && index < nm.store.galleryLinks.length) 1212 return nm.store.galleryLinks.eq(index); 1213 else if (nm.galleryLoop && nm.store.galleryLinks) 1214 return nm.store.galleryLinks.eq(index<0 ? nm.store.galleryLinks.length-1 : 0); 1215 } 1216 return undefined; 1217 } 1218 } 1219 }); 1220}); 1221/* 1222 * nyroModal v2.0.0 1223 * 1224 * Link filter 1225 * 1226 * Depends: 1227 * 1228 * Before: filters.gallery 1229 */ 1230jQuery(function($, undefined) { 1231 $.nmFilters({ 1232 link: { 1233 is: function(nm) { 1234 var ret = nm.opener.is('[href]'); 1235 if (ret) 1236 nm.store.link = nm.getInternal()._extractUrl(nm.opener.attr('href')); 1237 return ret; 1238 }, 1239 init: function(nm) { 1240 nm.loadFilter = 'link'; 1241 nm.opener.off('click.nyroModal').on('click.nyroModal', function(e) { 1242 e.preventDefault(); 1243 nm.opener.trigger('nyroModal'); 1244 }); 1245 }, 1246 load: function(nm) { 1247 $.ajax($.extend(true, {}, nm.ajax || {}, { 1248 url: nm.store.link.url, 1249 data: nm.store.link.sel ? [{name: nm.selIndicator, value: nm.store.link.sel.substring(1)}] : undefined, 1250 success: function(data) { 1251 nm._setCont(data, nm.store.link.sel); 1252 }, 1253 error: function(jqXHR) { 1254 nm._error(jqXHR); 1255 } 1256 })); 1257 }, 1258 destroy: function(nm) { 1259 nm.opener.off('click.nyroModal'); 1260 } 1261 } 1262 }); 1263}); 1264/* 1265 * nyroModal v2.0.0 1266 * 1267 * Dom filter 1268 * 1269 * Depends: 1270 * - filters.link 1271 * 1272 * Before: filters.link 1273 */ 1274jQuery(function($, undefined) { 1275 $.nmFilters({ 1276 dom: { 1277 is: function(nm) { 1278 return nm._hasFilter('link') && !nm.store.link.url && nm.store.link.sel; 1279 }, 1280 init: function(nm) { 1281 nm.loadFilter = 'dom'; 1282 }, 1283 load: function(nm) { 1284 nm.store.domEl = $(nm.store.link.sel); 1285 if (nm.store.domEl.length) 1286 nm._setCont(nm.domCopy ? nm.store.domEl.html() : nm.store.domEl.contents()); 1287 else 1288 nm._error(); 1289 }, 1290 close: function(nm) { 1291 if (!nm.domCopy && nm.store.domEl && nm.elts.cont) 1292 nm.store.domEl.append(nm.elts.cont.find('.nyroModalDom').contents()); 1293 } 1294 } 1295 }); 1296}); 1297/* 1298 * nyroModal v2.0.0 1299 * 1300 * Data filter 1301 * 1302 * Depends: 1303 * - filters.link 1304 * 1305 * Before: filters.dom 1306 */ 1307jQuery(function($, undefined) { 1308 $.nmFilters({ 1309 data: { 1310 is: function(nm) { 1311 var ret = nm.data ? true : false; 1312 if (ret) 1313 nm._delFilter('dom'); 1314 return ret; 1315 }, 1316 init: function(nm) { 1317 nm.loadFilter = 'data'; 1318 }, 1319 load: function(nm) { 1320 nm._setCont(nm.data); 1321 } 1322 } 1323 }); 1324}); 1325/* 1326 * nyroModal v2.0.0 1327 * 1328 * Image filter 1329 * 1330 * Depends: 1331 * - filters.link 1332 * 1333 * Before: filters.data 1334 */ 1335jQuery(function($, undefined) { 1336 $.nmFilters({ 1337 image: { 1338 is: function(nm) { 1339 return (new RegExp(nm.imageRegex, 'i')).test(nm.opener.attr('href')); 1340 }, 1341 init: function(nm) { 1342 nm.loadFilter = 'image'; 1343 }, 1344 load: function(nm) { 1345 var url = nm.opener.attr('href'); 1346 $('<img />') 1347 .load(function() { 1348 nm.elts.cont.addClass('nyroModalImg'); 1349 nm.elts.hidden.addClass('nyroModalImg'); 1350 nm._setCont(this); 1351 }).error(function() { 1352 nm._error(); 1353 }) 1354 .attr('src', url); 1355 }, 1356 size: function(nm) { 1357 if (nm.sizes.w != nm.sizes.initW || nm.sizes.h != nm.sizes.initH) { 1358 var ratio = Math.min(nm.sizes.w/nm.sizes.initW, nm.sizes.h/nm.sizes.initH); 1359 nm.sizes.w = nm.sizes.initW * ratio; 1360 nm.sizes.h = nm.sizes.initH * ratio; 1361 } 1362 var img = nm.loading ? nm.elts.hidden.find('img') : nm.elts.cont.find('img'); 1363 img.attr({ 1364 width: nm.sizes.w, 1365 height: nm.sizes.h 1366 }); 1367 }, 1368 close: function(nm) { 1369 if (nm.elts.cont) { 1370 nm.elts.cont.removeClass('nyroModalImg'); 1371 nm.elts.hidden.removeClass('nyroModalImg'); 1372 } 1373 } 1374 } 1375 }); 1376}); 1377/* 1378 * nyroModal v2.0.0 1379 * 1380 * SWF filter 1381 * 1382 * Depends: 1383 * - filters.link 1384 * 1385 * Before: filters.image 1386 */ 1387jQuery(function($, undefined) { 1388 $.nmFilters({ 1389 swf: { 1390 idCounter: 1, 1391 is: function(nm) { 1392 return nm._hasFilter('link') && nm.opener.is('[href$=".swf"]'); 1393 }, 1394 init: function(nm) { 1395 nm.loadFilter = 'swf'; 1396 }, 1397 load: function(nm) { 1398 if (!nm.swfObjectId) 1399 nm.swfObjectId = 'nyroModalSwf-'+(this.idCounter++); 1400 var url = nm.store.link.url, 1401 cont = '<div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="'+nm.swfObjectId+'" width="'+nm.sizes.w+'" height="'+nm.sizes.h+'"><param name="movie" value="'+url+'"></param>', 1402 tmp = ''; 1403 $.each(nm.swf, function(name, val) { 1404 cont+= '<param name="'+name+'" value="'+val+'"></param>'; 1405 tmp+= ' '+name+'="'+val+'"'; 1406 }); 1407 cont+= '<embed src="'+url+'" type="application/x-shockwave-flash" width="'+nm.sizes.w+'" height="'+nm.sizes.h+'"'+tmp+'></embed></object></div>'; 1408 nm._setCont(cont); 1409 } 1410 } 1411 }); 1412}); 1413/* 1414 * nyroModal v2.0.0 1415 * 1416 * Form filter 1417 * 1418 * Depends: 1419 * 1420 * Before: filters.swf 1421 */ 1422jQuery(function($, undefined) { 1423 $.nmFilters({ 1424 form: { 1425 is: function(nm) { 1426 var ret = nm.opener.is('form'); 1427 if (ret) 1428 nm.store.form = nm.getInternal()._extractUrl(nm.opener.attr('action')); 1429 return ret; 1430 }, 1431 init: function(nm) { 1432 nm.loadFilter = 'form'; 1433 nm.opener.off('submit.nyroModal').on('submit.nyroModal', function(e) { 1434 e.preventDefault(); 1435 nm.opener.trigger('nyroModal'); 1436 }); 1437 }, 1438 load: function(nm) { 1439 var data = {}; 1440 $.map(nm.opener.serializeArray(), function(d) { 1441 data[d.name] = d.value; 1442 }); 1443 if (nm.store.form.sel) 1444 data[nm.selIndicator] = nm.store.form.sel.substring(1); 1445 $.ajax($.extend(true, { type : 'get', dataType : 'text' }, nm.ajax || {}, { 1446 url: nm.store.form.url, 1447 data: data, 1448 type: nm.opener.attr('method') ? nm.opener.attr('method') : undefined, 1449 success: function(data) { 1450 nm._setCont(data, nm.store.form.sel); 1451 }, 1452 error: function(jqXHR) { 1453 nm._error(jqXHR); 1454 } 1455 })); 1456 }, 1457 destroy: function(nm) { 1458 nm.opener.off('submit.nyroModal'); 1459 } 1460 } 1461 }); 1462}); 1463/* 1464 * nyroModal v2.0.0 1465 * 1466 * Form file filter 1467 * 1468 * Depends: 1469 * 1470 * Before: filters.form 1471 */ 1472jQuery(function($, undefined) { 1473 $.nmFilters({ 1474 formFile: { 1475 is: function(nm) { 1476 var ret = nm.opener.is('form[enctype="multipart/form-data"]'); 1477 if (ret) { 1478 nm._delFilter('form'); 1479 if (!nm.store.form) 1480 nm.store.form = nm.getInternal()._extractUrl(nm.opener.attr('action')); 1481 } 1482 return ret; 1483 }, 1484 init: function(nm) { 1485 nm.loadFilter = 'formFile'; 1486 nm.store.formFileLoading = false; 1487 nm.opener.off('submit.nyroModal').on('submit.nyroModal', function(e) { 1488 if (!nm.store.formFileIframe) { 1489 e.preventDefault(); 1490 nm.opener.trigger('nyroModal'); 1491 } else { 1492 nm.store.formFileLoading = true; 1493 } 1494 }); 1495 }, 1496 initElts: function(nm) { 1497 var inputSel; 1498 if (nm.store.form.sel) 1499 inputSel = $('<input type="hidden" />', { 1500 name: nm.selIndicator, 1501 value: nm.store.form.sel.substring(1) 1502 }).appendTo(nm.opener); 1503 function rmFormFileElts() { 1504 if (inputSel) { 1505 inputSel.remove(); 1506 inputSel = undefined; 1507 delete(inputSel); 1508 } 1509 nm.store.formFileIframe.attr('src', 'about:blank').remove(); 1510 nm.store.formFileIframe = undefined; 1511 delete(nm.store.formFileIframe); 1512 } 1513 nm.store.formFileIframe = $('<iframe />') 1514 .attr({ 1515 name: 'nyroModalFormFile', 1516 src: 'javascript:\'\';', 1517 id: 'nyromodal-iframe-'+(new Date().getTime()), 1518 frameborder: '0' 1519 }) 1520 .hide() 1521 .load(function() { 1522 if (nm.store.formFileLoading) { 1523 nm.store.formFileLoading = false; 1524 var content = nm.store.formFileIframe 1525 .off('load error') 1526 .contents().find('body').not('script[src]'); 1527 if (content && content.html() && content.html().length) { 1528 rmFormFileElts(); 1529 nm._setCont(content.html(), nm.store.form.sel); 1530 } else { 1531 // Not totally ready, try it in a few secs 1532 var nbTry = 0, 1533 fct = function() { 1534 nbTry++; 1535 var content = nm.store.formFileIframe 1536 .off('load error') 1537 .contents().find('body').not('script[src]'); 1538 if (content && content.html() && content.html().length) { 1539 nm._setCont(content.html(), nm.store.form.sel); 1540 rmFormFileElts(); 1541 } else if (nbTry < 5) { 1542 setTimeout(fct, 25); 1543 } else { 1544 rmFormFileElts(); 1545 nm._error(); 1546 } 1547 }; 1548 setTimeout(fct, 25); 1549 } 1550 } 1551 }) 1552 .on('error', function() { 1553 rmFormFileElts(); 1554 nm._error(); 1555 });
1556 nm.elts.all.append(nm.store.formFileIframe); 1557 nm.opener 1558 .attr('target', 'nyroModalFormFile') 1559 .submit(); 1560 }, 1561 close: function(nm) { 1562 nm.store.formFileLoading = false; 1563 if (nm.store.formFileIframe) { 1564 nm.store.formFileIframe.remove(); 1565 nm.store.formFileIframe = undefined; 1566 delete(nm.store.formFileIframe); 1567 } 1568 }, 1569 destroy: function(nm) { 1570 nm.opener.off('submit.nyroModal') 1571 } 1572 } 1573 }); 1574}); 1575/* 1576 * nyroModal v2.0.0 1577 * 1578 * Iframe filter 1579 * 1580 * Depends: 1581 * - filters.link 1582 * 1583 * Before: filters.formFile 1584 */ 1585jQuery(function($, undefined) { 1586 $.nmFilters({ 1587 iframe: { 1588 is: function(nm) { 1589 var target = nm.opener.attr('target') || '', 1590 rel = nm.opener.attr('rel') || '', 1591 opener = nm.opener.get(0); 1592 return !nm._hasFilter('image') && (target.toLowerCase() == '_blank' 1593 || rel.toLowerCase().indexOf('external') > -1 1594 || (opener.hostname && opener.hostname.replace(/:\d*$/,'') != window.location.hostname.replace(/:\d*$/,''))); 1595 }, 1596 init: function(nm) { 1597 nm.loadFilter = 'iframe'; 1598 }, 1599 load: function(nm) { 1600 nm.store.iframe = $('<iframe />') 1601 .attr({ 1602 src: 'javascript:\'\';', 1603 id: 'nyromodal-iframe-'+(new Date().getTime()), 1604 frameborder: '0' 1605 }); 1606 nm._setCont(nm.store.iframe); 1607 }, 1608 afterShowCont: function(nm) { 1609 nm.store.iframe.attr('src', nm.opener.attr('href')); 1610 }, 1611 close: function(nm) { 1612 if (nm.store.iframe) { 1613 nm.store.iframe.remove(); 1614 nm.store.iframe = undefined; 1615 delete(nm.store.iframe); 1616 } 1617 } 1618 } 1619 }); 1620}); 1621/* 1622 * nyroModal v2.0.0 1623 * 1624 * Iframe form filter 1625 * 1626 * Depends: 1627 * - filters.iframe 1628 * 1629 * Before: filters.iframe 1630 */ 1631jQuery(function($, undefined) { 1632 $.nmFilters({ 1633 iframeForm: { 1634 is: function(nm) { 1635 var ret = nm._hasFilter('iframe') && nm.opener.is('form'); 1636 if (ret) { 1637 nm._delFilter('iframe'); 1638 nm._delFilter('form'); 1639 } 1640 return ret; 1641 }, 1642 init: function(nm) { 1643 nm.loadFilter = 'iframeForm'; 1644 nm.store.iframeFormLoading = false; 1645 nm.store.iframeFormOrgTarget = nm.opener.attr('target'); 1646 nm.opener.off('submit.nyroModal').on('submit.nyroModal', function(e) { 1647 if (!nm.store.iframeFormIframe) { 1648 e.preventDefault(); 1649 nm.opener.trigger('nyroModal'); 1650 } else { 1651 nm.store.iframeFormLoading = true; 1652 } 1653 }); 1654 }, 1655 load: function(nm) { 1656 nm.store.iframeFormIframe = $('<iframe />') 1657 .attr({ 1658 name: 'nyroModalIframeForm', 1659 src: 'javascript:\'\';', 1660 id: 'nyromodal-iframe-'+(new Date().getTime()), 1661 frameborder: '0' 1662 }); 1663 nm._setCont(nm.store.iframeFormIframe); 1664 }, 1665 afterShowCont: function(nm) { 1666 nm.opener 1667 .attr('target', 'nyroModalIframeForm') 1668 .submit(); 1669 }, 1670 close: function(nm) { 1671 nm.store.iframeFormOrgTarget ? nm.opener.attr('target', nm.store.iframeFormOrgTarget) : nm.opener.removeAttr('target'); 1672 delete(nm.store.formFileLoading); 1673 delete(nm.store.iframeFormOrgTarget); 1674 if (nm.store.iframeFormIframe) { 1675 nm.store.iframeFormIframe.remove(); 1676 nm.store.iframeFormIframe = undefined; 1677 delete(nm.store.iframeFormIframe); 1678 } 1679 }, 1680 destroy: function(nm) { 1681 nm.opener.off('submit.nyroModal') 1682 } 1683 } 1684 }); 1685}); 1686/* 1687 * nyroModal v2.0.0 1688 * 1689 * Embedly filter 1690 * 1691 * Depends: 1692 * - filters.link 1693 * 1694 * Before: filters.iframeForm 1695 */ 1696jQuery(function($, undefined) { 1697 $.nmObj({ 1698 embedlyUrl: 'http://api.embed.ly/1/oembed', 1699 embedly: { 1700 key: undefined, 1701 wmode: 'transparent', 1702 allowscripts: true, 1703 format: 'json' 1704 1705 /* 1706 maxwidth: 400, 1707 maxheight: 400, 1708 width: 400, 1709 nostyle: false, 1710 autoplay: false, 1711 videosrc: false, 1712 words: 50, 1713 chars: 100 1714 */ 1715 } 1716 }); 1717 var cache = []; 1718 $.nmFilters({ 1719 embedly: { 1720 is: function(nm) { 1721 if (nm._hasFilter('link') && nm._hasFilter('iframe') && nm.opener.attr('href') && nm.embedly.key) { 1722 if (cache[nm.opener.attr('href')]) { 1723 nm.store.embedly = cache[nm.opener.attr('href')]; 1724 nm._delFilter('iframe'); 1725 return true; 1726 } 1727 nm.store.embedly = false; 1728 var data = nm.embedly; 1729 data.url = nm.opener.attr('href'); 1730 $.ajax({
1731 url: nm.embedlyUrl, 1732 dataType: 'jsonp', 1733 data: data, 1734 success: function(data) { 1735 if (data.type != 'error' && data.html) { 1736 nm.store.embedly = data; 1737 cache[nm.opener.attr('href')] = data; 1738 nm._delFilter('iframe'); 1739 nm.filters.push('embedly'); 1740 nm._callFilters('initFilters'); 1741 nm._callFilters('init'); 1742 } 1743 } 1744 }); 1745 } 1746 return false; 1747 }, 1748 init: function(nm) { 1749 nm.loadFilter = 'embedly'; 1750 }, 1751 load: function(nm) { 1752 if (nm.store.embedly.type == 'photo') { 1753 nm.filters.push('image'); 1754 $('<img />') 1755 .load(function() { 1756 nm.elts.cont.addClass('nyroModalImg'); 1757 nm.elts.hidden.addClass('nyroModalImg'); 1758 nm._setCont(this); 1759 }).on('error', function() { 1760 nm._error(); 1761 }) 1762 .attr('src', nm.store.embedly.url); 1763 } else { 1764 nm._setCont('<div>'+nm.store.embedly.html+'</div>'); 1765 } 1766 }, 1767 size: function(nm) { 1768 if (nm.store.embedly.width && !nm.sizes.height) { 1769 nm.sizes.w = nm.store.embedly.width; 1770 nm.sizes.h = nm.store.embedly.height; 1771 } 1772 } 1773 } 1774 }); 1775}); 1776 1777/* 1778 * nyroModal v2.0.0 1779 * 1780 * Youtube filter 1781 * 1782 * Depends: 1783 * - filters.link 1784 * 1785 * Before: filters.embedly 1786 */ 1787 /* 1788jQuery(function($, undefined) { 1789 $.nmFilters({ 1790 youtube: { 1791 is: function(nm) { 1792 if (nm._hasFilter('link') && nm._hasFilter('iframe') && nm.opener.attr('href').indexOf('www.youtube.com/watch?v=') > -1) { 1793 nm._delFilter('iframe'); 1794 return true; 1795 } 1796 return false; 1797 }, 1798 init: function(nm) { 1799 nm.loadFilter = 'youtube'; 1800 }, 1801 load: function(nm) { 1802 nm.store.youtubeIframe = $('<iframe />') 1803 .attr({ 1804 src: 'javascript:\'\';', 1805 id: 'nyromodal-iframe-'+(new Date().getTime()), 1806 frameborder: '0' 1807 }); 1808 nm._setCont(nm.store.youtubeIframe); 1809 }, 1810 afterShowCont: function(nm) { 1811 nm.store.youtubeIframe.attr('src', nm.opener.attr('href').replace(/watch\?v=/i, 'embed/')); 1812 }, 1813 close: function(nm) { 1814 if (nm.store.youtubeIframe) { 1815 nm.store.youtubeIframe.remove(); 1816 nm.store.youtubeIframe = undefined; 1817 delete(nm.store.youtubeIframe); 1818 } 1819 } 1820 } 1821 }); 1822}); 1823*/
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.