1// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2// Licensed under the MIT license 3// version: 3.0.5 4 5(function (window) { 6 7 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind 8 if (!Function.prototype.bind ) { 9 10 Function.prototype.bind = function( obj ) { 11 var slice = [].slice, 12 args = slice.call(arguments, 1), 13 self = this, 14 nop = function () {}, 15 bound = function () { 16 return self.apply( this instanceof nop ? this : ( obj || {} ), 17 args.concat( slice.call(arguments) ) ); 18 }; 19 20 nop.prototype = self.prototype; 21 22 bound.prototype = new nop(); 23 24 return bound; 25 }; 26 } 27 28 29 30 if (typeof window.Code === "undefined") { 31 window.Code = {}; 32 } 33 34 35 36 window.Code.Util = { 37 38 39 /* 40 * Function: registerNamespace 41 */ 42 registerNamespace: function () { 43 var 44 args = arguments, obj = null, i, j, ns, nsParts, root, argsLen, nsPartsLens; 45 for (i=0, argsLen=args.length; i<argsLen; i++) { 46 ns = args[i]; 47 nsParts = ns.split("."); 48 root = nsParts[0]; 49 if (typeof window[root] === "undefined"){ 50 window[root] = {}; 51 } 52 obj = window[root]; 53 //eval('if (typeof ' + root + ' == "undefined"){' + root + ' = {};} obj = ' + root + ';'); 54 for (j=1, nsPartsLens=nsParts.length; j<nsPartsLens; ++j) { 55 obj[nsParts[j]] = obj[nsParts[j]] || {}; 56 obj = obj[nsParts[j]]; 57 } 58 } 59 }, 60 61 62 63 /* 64 * Function: coalesce 65 * Takes any number of arguments and returns the first non Null / Undefined argument. 66 */ 67 coalesce: function () { 68 var i, j; 69 for (i=0, j=arguments.length; i<j; i++) { 70 if (!this.isNothing(arguments[i])) { 71 return arguments[i]; 72 } 73 } 74 return null; 75 }, 76 77 78 79 /* 80 * Function: extend 81 */ 82 extend: function(destination, source, overwriteProperties){ 83 var prop; 84 if (this.isNothing(overwriteProperties)){ 85 overwriteProperties = true; 86 } 87 if (destination && source && this.isObject(source)){ 88 for(prop in source){ 89 if (this.objectHasProperty(source, prop)) { 90 if (overwriteProperties){ 91 destination[prop] = source[prop]; 92 } 93 else{ 94 if(typeof destination[prop] === "undefined"){ 95 destination[prop] = source[prop]; 96 } 97 } 98 } 99 } 100 } 101 }, 102 103 104 105 /* 106 * Function: clone 107 */ 108 clone: function(obj) { 109 var retval = {}; 110 this.extend(retval, obj); 111 return retval; 112 }, 113 114 115 116 /* 117 * Function: isObject 118 */ 119 isObject: function(obj){ 120 return obj instanceof Object; 121 }, 122 123 124 125 /* 126 * Function: isFunction 127 */ 128 isFunction: function(obj){ 129 return ({}).toString.call(obj) === "[object Function]"; 130 }, 131 132 133 134 /* 135 * Function: isArray 136 */ 137 isArray: function(obj){ 138 return obj instanceof Array; 139 }, 140 141 142 /* 143 * Function: isLikeArray 144 */ 145 isLikeArray: function(obj) { 146 return typeof obj.length === 'number'; 147 }, 148 149 150 151 /* 152 * Function: isNumber 153 */ 154 isNumber: function(obj){ 155 return typeof obj === "number"; 156 }, 157 158 159 160 /* 161 * Function: isString 162 */ 163 isString: function(obj){ 164 return typeof obj === "string"; 165 }, 166 167 168 /* 169 * Function: isNothing 170 */ 171 isNothing: function (obj) { 172 173 if (typeof obj === "undefined" || obj === null) { 174 return true; 175 } 176 return false; 177 178 }, 179 180 181 182 /* 183 * Function: swapArrayElements 184 */ 185 swapArrayElements: function(arr, i, j){ 186 187 var temp = arr[i]; 188 arr[i] = arr[j]; 189 arr[j] = temp; 190 191 }, 192 193 194 195 /* 196 * Function: trim 197 */ 198 trim: function(val) { 199 return val.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); 200 }, 201 202 203 204 /* 205 * Function: toCamelCase 206 */ 207 toCamelCase: function(val){ 208 return val.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');}); 209 }, 210 211 212 213 /* 214 * Function: toDashedCase 215 */ 216 toDashedCase: function(val){ 217 return val.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();}); 218 }, 219 220 221 222 /* 223 * Function: indexOf 224 */ 225 arrayIndexOf: function(obj, array, prop){ 226 227 var i, j, retval, arrayItem; 228 229 retval = -1; 230 231 for (i=0, j=array.length; i<j; i++){ 232 233 arrayItem = array[i]; 234 235 if (!this.isNothing(prop)){ 236 if (this.objectHasProperty(arrayItem, prop)) { 237 if (arrayItem[prop] === obj){ 238 retval = i; 239 break; 240 } 241 } 242 } 243 else{ 244 if (arrayItem === obj){ 245 retval = i; 246 break; 247 } 248 } 249 250 } 251 252 return retval; 253 254 }, 255 256 257 258 /* 259 * Function: objectHasProperty 260 */ 261 objectHasProperty: function(obj, propName){ 262 263 if (obj.hasOwnProperty){ 264 return obj.hasOwnProperty(propName); 265 } 266 else{ 267 return ('undefined' !== typeof obj[propName]); 268 } 269 270 } 271 272 273 }; 274 275}(window)); 276// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 277// Licensed under the MIT license 278// version: 3.0.5 279 280(function(window, Util) { 281 282 Util.Browser = { 283 284 ua: null, 285 version: null, 286 safari: null, 287 webkit: null, 288 opera: null, 289 msie: null, 290 chrome: null, 291 mozilla: null, 292 293 android: null, 294 blackberry: null, 295 iPad: null, 296 iPhone: null, 297 iPod: null, 298 iOS: null, 299 300 is3dSupported: null, 301 isCSSTransformSupported: null, 302 isTouchSupported: null, 303 isGestureSupported: null, 304 305 306 _detect: function(){ 307 308 this.ua = window.navigator.userAgent; 309 this.version = (this.ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || []); 310 this.safari = (/Safari/gi).test(window.navigator.appVersion); 311 this.webkit = /webkit/i.test(this.ua); 312 this.opera = /opera/i.test(this.ua); 313 this.msie = /msie/i.test(this.ua) && !this.opera; 314 this.chrome = /Chrome/i.test(this.ua); 315 this.firefox = /Firefox/i.test(this.ua); 316 this.fennec = /Fennec/i.test(this.ua); 317 this.mozilla = /mozilla/i.test(this.ua) && !/(compatible|webkit)/.test(this.ua); 318 this.android = /android/i.test(this.ua); 319 this.blackberry = /blackberry/i.test(this.ua); 320 this.iOS = (/iphone|ipod|ipad/gi).test(window.navigator.platform); 321 this.iPad = (/ipad/gi).test(window.navigator.platform); 322 this.iPhone = (/iphone/gi).test(window.navigator.platform); 323 this.iPod = (/ipod/gi).test(window.navigator.platform); 324 325 var testEl = document.createElement('div'); 326 this.is3dSupported = !Util.isNothing(testEl.style.WebkitPerspective); 327 this.isCSSTransformSupported = ( !Util.isNothing(testEl.style.WebkitTransform) || !Util.isNothing(testEl.style.MozTransform) || !Util.isNothing(testEl.style.transformProperty) ); 328 this.isTouchSupported = this.isEventSupported('touchstart'); 329 this.isGestureSupported = this.isEventSupported('gesturestart') || this.iOS; //fixes iOS 7 bug 330 //https://github.com/thorstein5/PhotoSwipe/commit/1f51896d3cef4248a972048852bb8bd8832f206b 331 332 }, 333 334 335 _eventTagNames: { 336 'select':'input', 337 'change':'input', 338 'submit':'form', 339 'reset':'form', 340 'error':'img', 341 'load':'img', 342 'abort':'img' 343 }, 344 345 346 /* 347 * Function: isEventSupported 348 * http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ 349 */ 350 isEventSupported: function(eventName) { 351 var 352 el = document.createElement(this._eventTagNames[eventName] || 'div'), 353 isSupported; 354 eventName = 'on' + eventName; 355 isSupported = Util.objectHasProperty(el, eventName); 356 if (!isSupported) { 357 el.setAttribute(eventName, 'return;'); 358 isSupported = typeof el[eventName] === 'function'; 359 } 360 el = null; 361 return isSupported; 362 }, 363 364 365 isLandscape: function(){ 366 return (Util.DOM.windowWidth() > Util.DOM.windowHeight()); 367 } 368 }; 369 370 Util.Browser._detect(); 371 372} 373( 374 window, 375 window.Code.Util 376)) 377; 378// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 379// Licensed under the MIT license 380// version: 3.0.5 381 382(function (window, $, Util) { 383 384 Util.extend(Util, { 385 386 Events: { 387 388 389 /* 390 * Function: add 391 * Add an event handler 392 */ 393 add: function(obj, type, handler){ 394 395 $(obj).bind(type, handler); 396 397 }, 398 399 400 401 /* 402 * Function: remove 403 * Removes a handler or all handlers associated with a type 404 */ 405 remove: function(obj, type, handler){ 406 407 $(obj).unbind(type, handler); 408 409 }, 410 411 412 /* 413 * Function: fire 414 * Fire an event 415 */ 416 fire: function(obj, type){ 417 418 var 419 event, 420 args = Array.prototype.slice.call(arguments).splice(2); 421 422 if (typeof type === "string"){ 423 event = { type: type }; 424 } 425 else{ 426 event = type; 427 } 428 429 $(obj).trigger( $.Event(event.type, event), args); 430 431 }, 432 433 434 /* 435 * Function: getMousePosition 436 */ 437 getMousePosition: function(event){ 438 439 var retval = { 440 x: event.pageX, 441 y: event.pageY 442 }; 443 444 return retval; 445 446 }, 447 448 449 /* 450 * Function: getTouchEvent 451 */ 452 getTouchEvent: function(event){ 453 454 return event.originalEvent; 455 456 }, 457 458 459 460 /* 461 * Function: getWheelDelta 462 */ 463 getWheelDelta: function(event){ 464 465 var delta = 0; 466 467 if (!Util.isNothing(event.wheelDelta)){ 468 delta = event.wheelDelta / 120; 469 } 470 else if (!Util.isNothing(event.detail)){ 471 delta = -event.detail / 3; 472 } 473 474 return delta; 475 476 }, 477 478 479 /* 480 * Function: domReady 481 */ 482 domReady: function(handler){ 483 484 $(document).ready(handler); 485 486 } 487 488 489 } 490 491 492 }); 493 494 495} 496( 497 window, 498 window.jQuery, 499 window.Code.Util 500));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 501// Licensed under the MIT license 502// version: 3.0.5 503 504(function (window, $, Util) { 505 506 Util.extend(Util, { 507 508 DOM: { 509 510 511 512 /* 513 * Function: setData 514 */ 515 setData: function(el, key, value){ 516 517 if (Util.isLikeArray(el)){ 518 var i, len; 519 for (i=0, len=el.length; i<len; i++){ 520 Util.DOM._setData(el[i], key, value); 521 } 522 } 523 else{ 524 Util.DOM._setData(el, key, value); 525 } 526 527 }, 528 _setData: function(el, key, value){ 529 530 Util.DOM.setAttribute(el, 'data-' + key, value); 531 532 }, 533 534 535 536 /* 537 * Function: getData 538 */ 539 getData: function(el, key, defaultValue){ 540 541 return Util.DOM.getAttribute(el, 'data-' + key, defaultValue); 542 543 }, 544 545 546 547 /* 548 * Function: removeData 549 */ 550 removeData: function(el, key){ 551 552 if (Util.isLikeArray(el)){ 553 var i, len; 554 for (i=0, len=el.length; i<len; i++){ 555 Util.DOM._removeData(el[i], key); 556 } 557 } 558 else{ 559 Util.DOM._removeData(el, key); 560 } 561 562 }, 563 _removeData: function(el, key){ 564 565 Util.DOM.removeAttribute(el, 'data-' + key); 566 567 }, 568 569 570 571 /* 572 * Function: isChildOf 573 */ 574 isChildOf: function(childEl, parentEl) 575 { 576 if (parentEl === childEl){ 577 return false; 578 } 579 while (childEl && childEl !== parentEl) 580 { 581 childEl = childEl.parentNode; 582 } 583 584 return childEl === parentEl; 585 }, 586 587 588 589 /* 590 * Function: find 591 */ 592 find: function(selectors, contextEl){ 593 if (Util.isNothing(contextEl)){ 594 contextEl = window.document; 595 } 596 var 597 els = $(selectors, contextEl), 598 retval = [], 599 i, j; 600 601 for (i=0, j=els.length; i<j; i++){ 602 retval.push(els[i]); 603 } 604 return retval; 605 }, 606 607 608 609 /* 610 * Function: createElement 611 */ 612 createElement: function(type, attributes, content){ 613 614 var retval = $('<' + type +'></' + type + '>'); 615 retval.attr(attributes); 616 retval.append(content); 617 618 return retval[0]; 619 620 }, 621 622 623 624 /* 625 * Function: appendChild 626 */ 627 appendChild: function(childEl, parentEl){ 628 629 $(parentEl).append(childEl); 630 631 }, 632 633 634 635 /* 636 * Function: insertBefore 637 */ 638 insertBefore: function(newEl, refEl, parentEl){ 639 640 $(newEl).insertBefore(refEl); 641 642 }, 643 644 645 646 /* 647 * Function: appendText 648 */ 649 appendText: function(text, parentEl){ 650 651 $(parentEl).text(text); 652 653 }, 654 655 656 657 /* 658 * Function: appendToBody 659 */ 660 appendToBody: function(childEl){ 661 662 $('body').append(childEl); 663 664 }, 665 666 667 668 /* 669 * Function: removeChild 670 */ 671 removeChild: function(childEl, parentEl){ 672 673 $(childEl).empty().remove(); 674 675 }, 676 677 678 679 /* 680 * Function: removeChildren 681 */ 682 removeChildren: function(parentEl){ 683 684 $(parentEl).empty(); 685 686 }, 687 688 689 690 /* 691 * Function: hasAttribute 692 */ 693 hasAttribute: function(el, attributeName){ 694 695 return !Util.isNothing( $(el).attr(attributeName) ); 696 697 }, 698 699 700 701 /* 702 * Function: getAttribute 703 */ 704 getAttribute: function(el, attributeName, defaultValue){ 705 706 var retval = $(el).attr(attributeName); 707 if (Util.isNothing(retval) && !Util.isNothing(defaultValue)){ 708 retval = defaultValue; 709 } 710 return retval; 711 712 }, 713 714 715 716 /* 717 * Function: el, attributeName 718 */ 719 setAttribute: function(el, attributeName, value){ 720 721 if (Util.isLikeArray(el)){ 722 var i, len; 723 for (i=0, len=el.length; i<len; i++){ 724 Util.DOM._setAttribute(el[i], attributeName, value); 725 } 726 } 727 else{ 728 Util.DOM._setAttribute(el, attributeName, value); 729 } 730 731 }, 732 _setAttribute: function(el, attributeName, value){ 733 734 $(el).attr(attributeName, value); 735 736 }, 737 738 739 740 /* 741 * Function: removeAttribute 742 */ 743 removeAttribute: function(el, attributeName){ 744 745 if (Util.isLikeArray(el)){ 746 var i, len; 747 for (i=0, len=el.length; i<len; i++){ 748 Util.DOM._removeAttribute(el[i], attributeName); 749 } 750 } 751 else{ 752 Util.DOM._removeAttribute(el, attributeName); 753 } 754 755 }, 756 _removeAttribute: function(el, attributeName){ 757 758 $(el).removeAttr(attributeName); 759 760 }, 761 762 763 764 /* 765 * Function: addClass 766 */ 767 addClass: function(el, className){ 768 769 if (Util.isLikeArray(el)){ 770 var i, len; 771 for (i=0, len=el.length; i<len; i++){ 772 Util.DOM._addClass(el[i], className); 773 } 774 } 775 else{ 776 Util.DOM._addClass(el, className); 777 } 778 779 }, 780 _addClass: function(el, className){ 781 782 $(el).addClass(className); 783 784 }, 785 786 787 788 /* 789 * Function: removeClass 790 */ 791 removeClass: function(el, className){ 792 793 if (Util.isLikeArray(el)){ 794 var i, len; 795 for (i=0, len=el.length; i<len; i++){ 796 Util.DOM._removeClass(el[i], className); 797 } 798 } 799 else{ 800 Util.DOM._removeClass(el, className); 801 } 802 803 }, 804 _removeClass: function(el, className){ 805 806 $(el).removeClass(className); 807 808 }, 809 810 811 812 /* 813 * Function: hasClass 814 */ 815 hasClass: function(el, className){ 816 817 $(el).hasClass(className); 818 819 }, 820 821 822 823 /* 824 * Function: setStyle 825 */ 826 setStyle: function(el, style, value){ 827 828 if (Util.isLikeArray(el)){ 829 var i, len; 830 for (i=0, len=el.length; i<len; i++){ 831 Util.DOM._setStyle(el[i], style, value); 832 } 833 } 834 else{ 835 Util.DOM._setStyle(el, style, value); 836 } 837 838 }, 839 _setStyle: function(el, style, value){ 840 841 var prop; 842 843 if (Util.isObject(style)) { 844 for(prop in style) { 845 if(Util.objectHasProperty(style, prop)){ 846 if (prop === 'width'){ 847 Util.DOM.width(el, style[prop]); 848 } 849 else if (prop === 'height'){ 850 Util.DOM.height(el, style[prop]); 851 } 852 else{ 853 $(el).css(prop, style[prop]); 854 } 855 } 856 } 857 } 858 else { 859 $(el).css(style, value); 860 } 861 862 }, 863 864 865 866 /* 867 * Function: getStyle 868 */ 869 getStyle: function(el, styleName
869){ 870 871 return $(el).css(styleName); 872 873 }, 874 875 876 877 /* 878 * Function: hide 879 */ 880 hide: function(el){ 881 if (Util.isLikeArray(el)){ 882 var i, len; 883 for (i=0, len=el.length; i<len; i++){ 884 Util.DOM._hide(el[i]); 885 } 886 } 887 else{ 888 Util.DOM._hide(el); 889 } 890 }, 891 _hide: function(el){ 892 893 $(el).hide(); 894 895 }, 896 897 898 899 /* 900 * Function: show 901 */ 902 show: function(el){ 903 904 if (Util.isLikeArray(el)){ 905 var i, len; 906 for (i=0, len=el.length; i<len; i++){ 907 Util.DOM._show(el[i]); 908 } 909 } 910 else{ 911 Util.DOM._show(el); 912 } 913 914 }, 915 _show: function(el){ 916 917 $(el).show(); 918 919 }, 920 921 922 923 /* 924 * Function: width 925 * Content width, exludes padding 926 */ 927 width: function(el, value){ 928 929 if (!Util.isNothing(value)){ 930 $(el).width(value); 931 } 932 933 return $(el).width(); 934 935 }, 936 937 938 939 /* 940 * Function: outerWidth 941 */ 942 outerWidth: function(el){ 943 944 return $(el).outerWidth(); 945 946 }, 947 948 949 950 /* 951 * Function: height 952 * Content height, excludes padding 953 */ 954 height: function(el, value){ 955 956 if (!Util.isNothing(value)){ 957 $(el).height(value); 958 } 959 960 return $(el).height(); 961 962 }, 963 964 965 966 /* 967 * Function: outerHeight 968 */ 969 outerHeight: function(el){ 970 971 return $(el).outerHeight(); 972 973 }, 974 975 976 977 /* 978 * Function: documentWidth 979 */ 980 documentWidth: function(){ 981 982 return $(document.documentElement).width(); 983 984 }, 985 986 987 988 /* 989 * Function: documentHeight 990 */ 991 documentHeight: function(){ 992 993 return $(document.documentElement).height(); 994 995 }, 996 997 998 999 /* 1000 * Function: documentOuterWidth 1001 */ 1002 documentOuterWidth: function(){ 1003 1004 return Util.DOM.width(document.documentElement); 1005 1006 }, 1007 1008 1009 1010 /* 1011 * Function: documentOuterHeight 1012 */ 1013 documentOuterHeight: function(){ 1014 1015 return Util.DOM.outerHeight(document.documentElement); 1016 1017 }, 1018 1019 1020 1021 /* 1022 * Function: bodyWidth 1023 */ 1024 bodyWidth: function(){ 1025 1026 return $(document.body).width(); 1027 1028 }, 1029 1030 1031 1032 /* 1033 * Function: bodyHeight 1034 */ 1035 bodyHeight: function(){ 1036 1037 return $(document.body).height(); 1038 1039 }, 1040 1041 1042 1043 /* 1044 * Function: bodyOuterWidth 1045 */ 1046 bodyOuterWidth: function(){ 1047 1048 return Util.DOM.outerWidth(document.body); 1049 1050 }, 1051 1052 1053 1054 /* 1055 * Function: bodyOuterHeight 1056 */ 1057 bodyOuterHeight: function(){ 1058 1059 return Util.DOM.outerHeight(document.body); 1060 1061 }, 1062 1063 1064 1065 /* 1066 * Function: windowWidth 1067 */ 1068 windowWidth: function(){ 1069 //IE 1070 if(!window.innerWidth) { 1071 return $(window).width(); 1072 } 1073 //w3c 1074 return window.innerWidth; 1075 }, 1076 1077 1078 1079 /* 1080 * Function: windowHeight 1081 */ 1082 windowHeight: function(){ 1083 //IE 1084 if(!window.innerHeight) { 1085 return $(window).height(); 1086 } 1087 //w3c 1088 return window.innerHeight; 1089 }, 1090 1091 1092 1093 /* 1094 * Function: windowScrollLeft 1095 */ 1096 windowScrollLeft: function(){ 1097 //IE 1098 if(!window.pageXOffset) { 1099 return $(window).scrollLeft(); 1100 } 1101 //w3c 1102 return window.pageXOffset; 1103 }, 1104 1105 1106 1107 /* 1108 * Function: windowScrollTop 1109 */ 1110 windowScrollTop: function(){ 1111 //IE 1112 if(!window.pageYOffset) { 1113 return $(window).scrollTop(); 1114 } 1115 //w3c 1116 return window.pageYOffset; 1117 } 1118 1119 } 1120 1121 1122 }); 1123 1124 1125} 1126( 1127 window, 1128 window.jQuery, 1129 window.Code.Util 1130)); 1131// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 1132// Licensed under the MIT license 1133// version: 3.0.5 1134 1135(function (window, Util) { 1136 1137 Util.extend(Util, { 1138 1139 Animation: { 1140 1141 _applyTransitionDelay: 50, 1142 1143 _transitionEndLabel: (window.document.documentElement.style.webkitTransition !== undefined) ? "webkitTransitionEnd" : "transitionend", 1144 1145 _transitionEndHandler: null, 1146 1147 _transitionPrefix: (window.document.documentElement.style.webkitTransition !== undefined) ? "webkitTransition" : (window.document.documentElement.style.MozTransition !== undefined) ? "MozTransition" : "transition", 1148 1149 _transformLabel: (window.document.documentElement.style.webkitTransform !== undefined) ? "webkitTransform" : (window.document.documentElement.style.MozTransition !== undefined) ? "MozTransform" : "transform", 1150 1151 1152 /* 1153 * Function: _getTransitionEndHandler 1154 */ 1155 _getTransitionEndHandler: function(){ 1156 1157 if (Util.isNothing(this._transitionEndHandler)){ 1158 this._transitionEndHandler = this._onTransitionEnd.bind(this); 1159 } 1160 1161 return this._transitionEndHandler; 1162 1163 }, 1164 1165 1166 1167 /* 1168 * Function: stop 1169 */ 1170 stop: function(el){ 1171 1172 if (Util.Browser.isCSSTransformSupported){ 1173 var 1174 property = el.style[this._transitionPrefix + 'Property'], 1175 callbackLabel = (property !== '') ? 'ccl' + property + 'callback' : 'cclallcallback', 1176 style = {}; 1177 1178 Util.Events.remove(el, this._transitionEndLabel, this._getTransitionEndHandler()); 1179 if (Util.isNothing(el.callbackLabel)){ 1180 delete el.callbackLabel; 1181 } 1182 1183 style[this._transitionPrefix + 'Property'] = ''; 1184 style[this._transitionPrefix + 'Duration'] = ''; 1185 style[this._transitionPrefix + 'TimingFunction'] = ''; 1186 style[this._transitionPrefix + 'Delay'] = ''; 1187 style[this._transformLabel] = ''; 1188 1189 Util.DOM.setStyle(el, style); 1190 } 1191 else if (!Util.isNothing(window.jQuery)){ 1192 1193 window.jQuery(el).stop(true, true); 1194 1195 } 1196 1197 1198 }, 1199 1200 1201 1202 /* 1203 * Function: fadeIn 1204 */ 1205 fadeIn: function(el, speed, callback, timingFunction, opacity){ 1206 1207 opacity = Util.coalesce(opacity, 1); 1208 if (opacity <= 0){ 1209 opacity = 1; 1210 } 1211 1212 if (speed <= 0){ 1213 Util.DOM.setStyle(el, 'opacity', opacity); 1214 if (!Util.isNothing(callback)){ 1215 callback(el); 1216 return; 1217 } 1218 } 1219 1220 var currentOpacity = Util.DOM.getStyle(el, 'opacity'); 1221 1222 if (currentOpacity >= 1){ 1223 Util.DOM.setStyle(el, 'opacity', 0); 1224 } 1225 1226 if (Util.Browser.isCSSTransformSupported){ 1227 this._applyTransition(el, 'opacity', opacity, speed, callback, timingFunction); 1228 } 1229 else if (!Util.isNothing(window.jQuery)){ 1230 window.jQuery(el).fadeTo(speed, opacity, callback); 1231 } 1232 1233 }, 1234 1235 1236 1237 /* 1238 * Function: fadeTo 1239 */ 1240 fadeTo: function(el, opacity, speed, callback, timingFunction){ 1241 this.fadeIn(el, speed, callback, timingFunction, opacity); 1242 }, 1243 1244 1245 1246 /* 1247 * Function: fadeOut 1248 */ 1249 fadeOut: function(el, speed, callback, timingFunction){ 1250 1251 if (speed <= 0){ 1252 Util.DOM.setStyle(el, 'opacity', 0); 1253 if (!Util.isNothing(callback)){ 1254 callback(el); 1255 return; 1256 } 1257 } 1258 1259 if (Util.Browser.isCSSTransformSupported){ 1260 1261 this._applyTransition(el, 'opacity', 0, speed, callback, timingFunction); 1262 1263 } 1264 else{ 1265 1266 window.jQuery(el).fadeTo(speed, 0, callback); 1267 1268 } 1269 1270 }, 1271 1272 1273 1274 /* 1275 * Function: slideBy 1276 */ 1277 slideBy: function(el, x, y, speed, callback, timingFunction){ 1278 1279 var style = {}; 1280 1281 x = Util.coalesce(x, 0); 1282 y = Util.coalesce(y, 0); 1283 timingFunction = Util.coalesce(timingFunction, 'ease-out'); 1284 1285 style[this._transitionPrefix + 'Property'] = 'all'; 1286 style[this._transitionPrefix + 'Delay'] = '0'; 1287 1288 if (speed === 0){ 1289 style[this._transitionPrefix + 'Duration'] = ''; 1290 style[this._transitionPrefix + 'TimingFunction'] = ''; 1291 } 1292 else{ 1293 style[this._transitionPrefix + 'Duration'] = speed + 'ms'; 1294 style[this._transitionPrefix + 'TimingFunction'] = Util.coalesce(timingFunction, 'ease-out'); 1295 1296 Util.Events.add(el, this._transitionEndLabel, this._getTransitionEndHandler()); 1297 1298 } 1299 1300 style[this._transformLabel] = (Util.Browser.is3dSupported) ? 'translate3d(' + x + 'px, ' + y + 'px, 0px)' : 'translate(' + x + 'px, ' + y + 'px)'; 1301 1302 if (!Util.isNothing(callback)){ 1303 el.cclallcallback = callback; 1304 } 1305 1306 Util.DOM.setStyle(el, style); 1307 1308 if (speed === 0){ 1309 window.setTimeout(function(){ 1310 this._leaveTransforms(el); 1311 }.bind(this), this._applyTransitionDelay); 1312 } 1313 1314 }, 1315 1316 1317 1318 /* 1319 * Function: 1320 */ 1321 resetTranslate: function(el){ 1322 1323 var style = {}; 1324 style[this._transformLabel] = style[this._transformLabel] = (Util.Browser.is3dSupported) ? 'translate3d(0px, 0px, 0px)' : 'translate(0px, 0px)'; 1325 Util.DOM.setStyle(el, style); 1326 1327 }, 1328 1329 1330 1331 /* 1332 * Function: _applyTransition 1333 */ 1334 _applyTransition: function(el, property, val, speed, callback, timingFunction){ 1335 1336 var style = {}; 1337 1338 timingFunction = Util.coalesce(timingFunction, 'ease-in'); 1339 1340 style[this._transitionPrefix + 'Property'] = property; 1341 style[this._transitionPrefix + 'Duration'] = speed + 'ms'; 1342 style[this._transitionPrefix + 'TimingFunction'] = timingFunction; 1343 style[this._transitionPrefix + 'Delay'] = '0'; 1344 1345 Util.Events.add(el, this._transitionEndLabel, this._getTransitionEndHandler()); 1346 1347 Util.DOM.setStyle(el, style); 1348 1349 if (!Util.isNothing(callback)){ 1350 el['ccl' + property + 'callback'] = callback; 1351 } 1352 1353 window.setTimeout(function(){ 1354 Util.DOM.setStyle(el, property, val); 1355 }, this._applyTransitionDelay); 1356 1357 }, 1358 1359 1360 1361 /* 1362 * Function: _onTransitionEnd 1363 */ 1364 _onTransitionEnd: function(e){
1365 1366 Util.Events.remove(e.currentTarget, this._transitionEndLabel, this._getTransitionEndHandler()); 1367 this._leaveTransforms(e.currentTarget); 1368 1369 }, 1370 1371 1372 1373 /* 1374 * Function: _leaveTransforms 1375 */ 1376 _leaveTransforms: function(el){ 1377 1378 var 1379 property = el.style[this._transitionPrefix + 'Property'], 1380 callbackLabel = (property !== '') ? 'ccl' + property + 'callback' : 'cclallcallback', 1381 callback, 1382 transform = Util.coalesce(el.style.webkitTransform, el.style.MozTransform, el.style.transform), 1383 transformMatch, 1384 transformExploded, 1385 domX = window.parseInt(Util.DOM.getStyle(el, 'left'), 0), 1386 domY = window.parseInt(Util.DOM.getStyle(el, 'top'), 0), 1387 transformedX, 1388 transformedY, 1389 style = {}; 1390 1391 if (transform !== ''){ 1392 if (Util.Browser.is3dSupported){ 1393 transformMatch = transform.match( /translate3d\((.*?)\)/ ); 1394 } 1395 else{ 1396 transformMatch = transform.match( /translate\((.*?)\)/ ); 1397 } 1398 if (!Util.isNothing(transformMatch)){ 1399 transformExploded = transformMatch[1].split(', '); 1400 transformedX = window.parseInt(transformExploded[0], 0); 1401 transformedY = window.parseInt(transformExploded[1], 0); 1402 } 1403 } 1404 1405 style[this._transitionPrefix + 'Property'] = ''; 1406 style[this._transitionPrefix + 'Duration'] = ''; 1407 style[this._transitionPrefix + 'TimingFunction'] = ''; 1408 style[this._transitionPrefix + 'Delay'] = ''; 1409 1410 Util.DOM.setStyle(el, style); 1411 1412 window.setTimeout(function(){ 1413 1414 if(!Util.isNothing(transformExploded)){ 1415 1416 style = {}; 1417 style[this._transformLabel] = ''; 1418 style.left = (domX + transformedX) + 'px'; 1419 style.top = (domY + transformedY) + 'px'; 1420 1421 Util.DOM.setStyle(el, style); 1422 1423 } 1424 1425 if (!Util.isNothing(el[callbackLabel])){ 1426 callback = el[callbackLabel]; 1427 delete el[callbackLabel]; 1428 callback(el); 1429 } 1430 1431 }.bind(this), this._applyTransitionDelay); 1432 1433 } 1434 1435 1436 } 1437 1438 1439 }); 1440 1441 1442} 1443( 1444 window, 1445 window.Code.Util 1446)); 1447// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 1448// Licensed under the MIT license 1449// version: 3.0.5 1450 1451(function(window, klass, Util){ 1452 1453 1454 Util.registerNamespace('Code.Util.TouchElement'); 1455 1456 1457 Util.TouchElement.EventTypes = { 1458 1459 onTouch: 'CodeUtilTouchElementOnTouch' 1460 1461 }; 1462 1463 1464 Util.TouchElement.ActionTypes = { 1465 1466 touchStart: 'touchStart', 1467 touchMove: 'touchMove', 1468 touchEnd: 'touchEnd', 1469 touchMoveEnd: 'touchMoveEnd', 1470 tap: 'tap', 1471 doubleTap: 'doubleTap', 1472 swipeLeft: 'swipeLeft', 1473 swipeRight: 'swipeRight', 1474 swipeUp: 'swipeUp', 1475 swipeDown: 'swipeDown', 1476 gestureStart: 'gestureStart', 1477 gestureChange: 'gestureChange', 1478 gestureEnd: 'gestureEnd' 1479 1480 }; 1481 1482 1483} 1484( 1485 window, 1486 window.klass, 1487 window.Code.Util 1488));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 1489// Licensed under the MIT license 1490// version: 3.0.5 1491 1492(function(window, klass, Util){ 1493 1494 1495 Util.registerNamespace('Code.Util.TouchElement'); 1496 1497 1498 Util.TouchElement.TouchElementClass = klass({ 1499 1500 el: null, 1501 1502 captureSettings: null, 1503 1504 touchStartPoint: null, 1505 touchEndPoint: null, 1506 touchStartTime: null, 1507 doubleTapTimeout: null, 1508 1509 touchStartHandler: null, 1510 touchMoveHandler: null, 1511 touchEndHandler: null, 1512 1513 mouseDownHandler: null, 1514 mouseMoveHandler: null, 1515 mouseUpHandler: null, 1516 mouseOutHandler: null, 1517 1518 gestureStartHandler: null, 1519 gestureChangeHandler: null, 1520 gestureEndHandler: null, 1521 1522 swipeThreshold: null, 1523 swipeTimeThreshold: null, 1524 doubleTapSpeed: null, 1525 1526 1527 1528 /* 1529 * Function: dispose 1530 */ 1531 dispose: function(){ 1532 1533 var prop; 1534 1535 this.removeEventHandlers(); 1536 1537 for (prop in this) { 1538 if (Util.objectHasProperty(this, prop)) { 1539 this[prop] = null; 1540 } 1541 } 1542 1543 }, 1544 1545 1546 1547 /* 1548 * Function: initialize 1549 */ 1550 initialize: function(el, captureSettings){ 1551 1552 this.el = el; 1553 1554 this.captureSettings = { 1555 swipe: false, 1556 move: false, 1557 gesture: false, 1558 doubleTap: false, 1559 preventDefaultTouchEvents: true 1560 }; 1561
1562 Util.extend(this.captureSettings, captureSettings); 1563 1564 this.swipeThreshold = 50; 1565 this.swipeTimeThreshold = 250; 1566 this.doubleTapSpeed = 250; 1567 1568 this.touchStartPoint = { x: 0, y: 0 }; 1569 this.touchEndPoint = { x: 0, y: 0 }; 1570 1571 }, 1572 1573 1574 1575 /* 1576 * Function: addEventHandlers 1577 */ 1578 addEventHandlers: function(){ 1579 1580 if (Util.isNothing(this.touchStartHandler)){ 1581 this.touchStartHandler = this.onTouchStart.bind(this); 1582 this.touchMoveHandler = this.onTouchMove.bind(this); 1583 this.touchEndHandler = this.onTouchEnd.bind(this); 1584 this.mouseDownHandler = this.onMouseDown.bind(this); 1585 this.mouseMoveHandler = this.onMouseMove.bind(this); 1586 this.mouseUpHandler = this.onMouseUp.bind(this); 1587 this.mouseOutHandler = this.onMouseOut.bind(this); 1588 this.gestureStartHandler = this.onGestureStart.bind(this); 1589 this.gestureChangeHandler = this.onGestureChange.bind(this); 1590 this.gestureEndHandler = this.onGestureEnd.bind(this); 1591 } 1592 1593 Util.Events.add(this.el, 'touchstart', this.touchStartHandler); 1594 if (this.captureSettings.move){ 1595 Util.Events.add(this.el, 'touchmove', this.touchMoveHandler); 1596 } 1597 Util.Events.add(this.el, 'touchend', this.touchEndHandler); 1598 1599 Util.Events.add(this.el, 'mousedown', this.mouseDownHandler); 1600 1601 if (Util.Browser.isGestureSupported && this.captureSettings.gesture){ 1602 Util.Events.add(this.el, 'gesturestart', this.gestureStartHandler); 1603 Util.Events.add(this.el, 'gesturechange', this.gestureChangeHandler); 1604 Util.Events.add(this.el, 'gestureend', this.gestureEndHandler); 1605 } 1606 1607 }, 1608 1609 1610 1611 /* 1612 * Function: removeEventHandlers 1613 */ 1614 removeEventHandlers: function(){ 1615 1616 Util.Events.remove(this.el, 'touchstart', this.touchStartHandler); 1617 if (this.captureSettings.move){ 1618 Util.Events.remove(this.el, 'touchmove', this.touchMoveHandler); 1619 } 1620 Util.Events.remove(this.el, 'touchend', this.touchEndHandler); 1621 Util.Events.remove(this.el, 'mousedown', this.mouseDownHandler); 1622 1623 if (Util.Browser.isGestureSupported && this.captureSettings.gesture){ 1624 Util.Events.remove(this.el, 'gesturestart', this.gestureStartHandler); 1625 Util.Events.remove(this.el, 'gesturechange', this.gestureChangeHandler); 1626 Util.Events.remove(this.el, 'gestureend', this.gestureEndHandler); 1627 } 1628 1629 }, 1630 1631 1632 1633 /* 1634 * Function: getTouchPoint 1635 */ 1636 getTouchPoint: function(touches){ 1637 1638 return { 1639 x: touches[0].pageX, 1640 y: touches[0].pageY 1641 }; 1642 1643 }, 1644 1645 1646 1647 /* 1648 * Function: fireTouchEvent 1649 */ 1650 fireTouchEvent: function(e){ 1651 1652 var 1653 action, 1654 distX = 0, 1655 distY = 0, 1656 dist = 0, 1657 self, 1658 endTime, 1659 diffTime; 1660 1661 distX = this.touchEndPoint.x - this.touchStartPoint.x; 1662 distY = this.touchEndPoint.y - this.touchStartPoint.y; 1663 dist = Math.sqrt( (distX * distX) + (distY * distY) ); 1664 1665 if (this.captureSettings.swipe){ 1666 endTime = new Date(); 1667 diffTime = endTime - this.touchStartTime; 1668 1669 // See if there was a swipe gesture 1670 if (diffTime <= this.swipeTimeThreshold){ 1671 1672 if (window.Math.abs(distX) >= this.swipeThreshold){ 1673 1674 Util.Events.fire(this, { 1675 type: Util.TouchElement.EventTypes.onTouch, 1676 target: this, 1677 point: this.touchEndPoint, 1678 action: (distX < 0) ? Util.TouchElement.ActionTypes.swipeLeft : Util.TouchElement.ActionTypes.swipeRight, 1679 targetEl: e.target, 1680 currentTargetEl: e.currentTarget 1681 }); 1682 return; 1683 1684 } 1685 1686 1687 if (window.Math.abs(distY) >= this.swipeThreshold){ 1688 1689 Util.Events.fire(this, { 1690 type: Util.TouchElement.EventTypes.onTouch, 1691 target: this, 1692 point: this.touchEndPoint, 1693 action: (distY < 0) ? Util.TouchElement.ActionTypes.swipeUp : Util.TouchElement.ActionTypes.swipeDown, 1694 targetEl: e.target, 1695 currentTargetEl: e.currentTarget 1696 }); 1697 return; 1698 1699 } 1700 1701 } 1702 } 1703 1704 1705 if (dist > 1){ 1706 1707 Util.Events.fire(this, { 1708 type: Util.TouchElement.EventTypes.onTouch, 1709 target: this, 1710 action: Util.TouchElement.ActionTypes.touchMoveEnd, 1711 point: this.touchEndPoint, 1712 targetEl: e.target, 1713 currentTargetEl: e.currentTarget 1714 }); 1715 return; 1716 } 1717 1718 1719 if (!this.captureSettings.doubleTap){ 1720 1721 Util.Events.fire(this, { 1722 type: Util.TouchElement.EventTypes.onTouch, 1723 target: this, 1724 point: this.touchEndPoint, 1725 action: Util.TouchElement.ActionTypes.tap, 1726 targetEl: e.target, 1727 currentTargetEl: e.currentTarget 1728 }); 1729 return; 1730 1731 } 1732 1733 if (Util.isNothing(this.doubleTapTimeout)){ 1734 1735 this.doubleTapTimeout = window.setTimeout(function(){ 1736 1737 this.doubleTapTimeout = null; 1738 1739 Util.Events.fire(this, { 1740 type: Util.TouchElement.EventTypes.onTouch, 1741 target: this, 1742 point: this.touchEndPoint, 1743 action: Util.TouchElement.ActionTypes.tap, 1744 targetEl: e.target, 1745 currentTargetEl: e.currentTarget 1746 });
1747 1748 }.bind(this), this.doubleTapSpeed); 1749 1750 return; 1751 1752 } 1753 else{ 1754 1755 window.clearTimeout(this.doubleTapTimeout); 1756 this.doubleTapTimeout = null; 1757 1758 Util.Events.fire(this, { 1759 type: Util.TouchElement.EventTypes.onTouch, 1760 target: this, 1761 point: this.touchEndPoint, 1762 action: Util.TouchElement.ActionTypes.doubleTap, 1763 targetEl: e.target, 1764 currentTargetEl: e.currentTarget 1765 }); 1766 1767 } 1768 1769 }, 1770 1771 1772 1773 /* 1774 * Function: onTouchStart 1775 */ 1776 onTouchStart: function(e){ 1777 1778 if (this.captureSettings.preventDefaultTouchEvents){ 1779 e.preventDefault(); 1780 } 1781 1782 // No longer need mouse events 1783 Util.Events.remove(this.el, 'mousedown', this.mouseDownHandler); 1784 1785 var 1786 touchEvent = Util.Events.getTouchEvent(e), 1787 touches = touchEvent.touches; 1788 1789 if (touches.length > 1 && this.captureSettings.gesture){ 1790 this.isGesture = true; 1791 return; 1792 } 1793 1794 this.touchStartTime = new Date(); 1795 this.isGesture = false; 1796 this.touchStartPoint = this.getTouchPoint(touches); 1797 1798 Util.Events.fire(this, { 1799 type: Util.TouchElement.EventTypes.onTouch, 1800 target: this, 1801 action: Util.TouchElement.ActionTypes.touchStart, 1802 point: this.touchStartPoint, 1803 targetEl: e.target, 1804 currentTargetEl: e.currentTarget 1805 }); 1806 1807 1808 }, 1809 1810 1811 1812 /* 1813 * Function: onTouchMove 1814 */ 1815 onTouchMove: function(e){ 1816 1817 if (this.captureSettings.preventDefaultTouchEvents){ 1818 e.preventDefault(); 1819 } 1820 1821 if (this.isGesture && this.captureSettings.gesture){ 1822 return; 1823 } 1824 1825 var 1826 touchEvent = Util.Events.getTouchEvent(e), 1827 touches = touchEvent.touches; 1828 1829 Util.Events.fire(this, { 1830 type: Util.TouchElement.EventTypes.onTouch, 1831 target: this, 1832 action: Util.TouchElement.ActionTypes.touchMove, 1833 point: this.getTouchPoint(touches), 1834 targetEl: e.target, 1835 currentTargetEl: e.currentTarget 1836 }); 1837 1838 }, 1839 1840 1841 1842 /* 1843 * Function: onTouchEnd 1844 */ 1845 onTouchEnd: function(e){ 1846 1847 if (this.isGesture && this.captureSettings.gesture){ 1848 return; 1849 } 1850 1851 if (this.captureSettings.preventDefaultTouchEvents){ 1852 e.preventDefault(); 1853 } 1854 1855 // http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html 1856 // iOS removed the current touch from e.touches on "touchend" 1857 // Need to look into e.changedTouches 1858 1859 var 1860 touchEvent = Util.Events.getTouchEvent(e), 1861 touches = (!Util.isNothing(touchEvent.changedTouches)) ? touchEvent.changedTouches : touchEvent.touches; 1862 1863 this.touchEndPoint = this.getTouchPoint(touches); 1864 1865 Util.Events.fire(this, { 1866 type: Util.TouchElement.EventTypes.onTouch, 1867 target: this, 1868 action: Util.TouchElement.ActionTypes.touchEnd, 1869 point: this.touchEndPoint, 1870 targetEl: e.target, 1871 currentTargetEl: e.currentTarget 1872 }); 1873 1874 this.fireTouchEvent(e); 1875 1876 }, 1877 1878 1879 1880 /* 1881 * Function: onMouseDown 1882 */ 1883 onMouseDown: function(e){ 1884 1885 e.preventDefault(); 1886 1887 // No longer need touch events 1888 Util.Events.remove(this.el, 'touchstart', this.mouseDownHandler); 1889 Util.Events.remove(this.el, 'touchmove', this.touchMoveHandler); 1890 Util.Events.remove(this.el, 'touchend', this.touchEndHandler); 1891 1892 // Add move/up/out 1893 if (this.captureSettings.move){ 1894 Util.Events.add(this.el, 'mousemove', this.mouseMoveHandler); 1895 } 1896 Util.Events.add(this.el, 'mouseup', this.mouseUpHandler); 1897 Util.Events.add(this.el, 'mouseout', this.mouseOutHandler); 1898 1899 this.touchStartTime = new Date(); 1900 this.isGesture = false; 1901 this.touchStartPoint = Util.Events.getMousePosition(e); 1902 1903 Util.Events.fire(this, { 1904 type: Util.TouchElement.EventTypes.onTouch, 1905 target: this, 1906 action: Util.TouchElement.ActionTypes.touchStart, 1907 point: this.touchStartPoint, 1908 targetEl: e.target, 1909 currentTargetEl: e.currentTarget 1910 }); 1911 1912 }, 1913 1914 1915 1916 /* 1917 * Function: onMouseMove 1918 */ 1919 onMouseMove: function(e){
1920 1921 e.preventDefault(); 1922 1923 Util.Events.fire(this, { 1924 type: Util.TouchElement.EventTypes.onTouch, 1925 target: this, 1926 action: Util.TouchElement.ActionTypes.touchMove, 1927 point: Util.Events.getMousePosition(e), 1928 targetEl: e.target, 1929 currentTargetEl: e.currentTarget 1930 }); 1931 1932 }, 1933 1934 1935 1936 /* 1937 * Function: onMouseUp 1938 */ 1939 onMouseUp: function(e){ 1940 1941 e.preventDefault(); 1942 1943 if (this.captureSettings.move){ 1944 Util.Events.remove(this.el, 'mousemove', this.mouseMoveHandler); 1945 } 1946 Util.Events.remove(this.el, 'mouseup', this.mouseUpHandler); 1947 Util.Events.remove(this.el, 'mouseout', this.mouseOutHandler); 1948 1949 this.touchEndPoint = Util.Events.getMousePosition(e); 1950 1951 Util.Events.fire(this, { 1952 type: Util.TouchElement.EventTypes.onTouch, 1953 target: this, 1954 action: Util.TouchElement.ActionTypes.touchEnd, 1955 point: this.touchEndPoint, 1956 targetEl: e.target, 1957 currentTargetEl: e.currentTarget 1958 }); 1959 1960 this.fireTouchEvent(e); 1961 1962 }, 1963 1964 1965 1966 /* 1967 * Function: onMouseOut 1968 */ 1969 onMouseOut: function(e){ 1970 1971 /* 1972 * http://blog.stchur.com/2007/03/15/mouseenter-and-mouseleave-events-for-firefox-and-other-non-ie-browsers/ 1973 */ 1974 var relTarget = e.relatedTarget; 1975 if (this.el === relTarget || Util.DOM.isChildOf(relTarget, this.el)){ 1976 return; 1977 } 1978 1979 e.preventDefault(); 1980 1981 if (this.captureSettings.move){ 1982 Util.Events.remove(this.el, 'mousemove', this.mouseMoveHandler); 1983 } 1984 Util.Events.remove(this.el, 'mouseup', this.mouseUpHandler); 1985 Util.Events.remove(this.el, 'mouseout', this.mouseOutHandler); 1986 1987 this.touchEndPoint = Util.Events.getMousePosition(e); 1988 1989 Util.Events.fire(this, { 1990 type: Util.TouchElement.EventTypes.onTouch, 1991 target: this, 1992 action: Util.TouchElement.ActionTypes.touchEnd, 1993 point: this.touchEndPoint, 1994 targetEl: e.target, 1995 currentTargetEl: e.currentTarget 1996 }); 1997 1998 this.fireTouchEvent(e); 1999 2000 }, 2001 2002 2003 2004 /* 2005 * Function: onGestureStart 2006 */ 2007 onGestureStart: function(e){ 2008 2009 e.preventDefault(); 2010 2011 var touchEvent = Util.Events.getTouchEvent(e); 2012 2013 Util.Events.fire(this, { 2014 type: Util.TouchElement.EventTypes.onTouch, 2015 target: this, 2016 action: Util.TouchElement.ActionTypes.gestureStart, 2017 scale: touchEvent.scale, 2018 rotation: touchEvent.rotation, 2019 targetEl: e.target, 2020 currentTargetEl: e.currentTarget 2021 }); 2022 2023 }, 2024 2025 2026 2027 /* 2028 * Function: onGestureChange 2029 */ 2030 onGestureChange: function(e){ 2031 2032 e.preventDefault(); 2033 2034 var touchEvent = Util.Events.getTouchEvent(e); 2035 2036 Util.Events.fire(this, { 2037 type: Util.TouchElement.EventTypes.onTouch, 2038 target: this, 2039 action: Util.TouchElement.ActionTypes.gestureChange, 2040 scale: touchEvent.scale, 2041 rotation: touchEvent.rotation, 2042 targetEl: e.target, 2043 currentTargetEl: e.currentTarget 2044 }); 2045 2046 }, 2047 2048 2049 2050 /* 2051 * Function: onGestureEnd 2052 */ 2053 onGestureEnd: function(e){ 2054 2055 e.preventDefault(); 2056 2057 var touchEvent = Util.Events.getTouchEvent(e); 2058 2059 Util.Events.fire(this, { 2060 type: Util.TouchElement.EventTypes.onTouch, 2061 target: this, 2062 action: Util.TouchElement.ActionTypes.gestureEnd, 2063 scale: touchEvent.scale, 2064 rotation: touchEvent.rotation, 2065 targetEl: e.target, 2066 currentTargetEl: e.currentTarget 2067 }); 2068 2069 } 2070 2071 2072 2073 }); 2074 2075 2076 2077} 2078( 2079 window, 2080 window.klass, 2081 window.Code.Util 2082));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2083// Licensed under the MIT license 2084// version: 3.0.5 2085 2086(function(window, klass, Util){ 2087 2088 2089 Util.registerNamespace('Code.PhotoSwipe.Image'); 2090 var PhotoSwipe = window.Code.PhotoSwipe; 2091 2092 2093 2094 PhotoSwipe.Image.EventTypes = { 2095 2096 onLoad: 'onLoad', 2097 onError: 'onError' 2098 2099 }; 2100 2101 2102 2103} 2104( 2105 window, 2106 window.klass, 2107 window.Code.Util 2108));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2109// Licensed under the MIT license 2110// version: 3.0.5 2111 2112(function(window, klass, Util){ 2113 2114 2115 Util.registerNamespace('Code.PhotoSwipe.Image'); 2116 var PhotoSwipe = window.Code.PhotoSwipe; 2117 2118 2119 2120 PhotoSwipe.Image.ImageClass = klass({ 2121 2122 2123 2124 refObj: null, 2125 imageEl: null, 2126 src: null, 2127 caption: null, 2128 metaData: null, 2129 imageLoadHandler: null, 2130 imageErrorHandler: null, 2131 2132 2133 2134 /* 2135 * Function: dispose 2136 */ 2137 dispose: function(){ 2138 2139 var prop, i; 2140 2141 this.shrinkImage(); 2142 2143 for (prop in this) { 2144 if (Util.objectHasProperty(this, prop)) { 2145 this[prop] = null; 2146 } 2147 } 2148 2149 }, 2150 2151 2152 2153 /* 2154 * Function: initialize 2155 */ 2156 initialize: function(refObj, src, caption, metaData){ 2157 2158 this.refObj = refObj; 2159 // This is needed. Webkit resolves the src 2160 // value which means we can't compare against it in the load function 2161 this.originalSrc = src; 2162 this.src = src; 2163 this.caption = caption; 2164 this.metaData = metaData; 2165 2166 this.imageEl = new window.Image(); 2167 2168 this.imageLoadHandler = this.onImageLoad.bind(this); 2169 this.imageErrorHandler = this.onImageError.bind(this); 2170 2171 }, 2172 2173 2174 2175 /* 2176 * Function: load 2177 */ 2178 load: function(){ 2179 2180 this.imageEl.originalSrc = Util.coalesce(this.imageEl.originalSrc, ''); 2181
2182 if (this.imageEl.originalSrc === this.src){ 2183 2184 if (this.imageEl.isError){ 2185 Util.Events.fire(this, { 2186 type: PhotoSwipe.Image.EventTypes.onError, 2187 target: this 2188 }); 2189 } 2190 else{ 2191 Util.Events.fire(this, { 2192 type: PhotoSwipe.Image.EventTypes.onLoad, 2193 target: this 2194 }); 2195 } 2196 return; 2197 } 2198 2199 this.imageEl.isError = false; 2200 this.imageEl.isLoading = true; 2201 this.imageEl.naturalWidth = null; 2202 this.imageEl.naturalHeight = null; 2203 this.imageEl.isLandscape = false; 2204 this.imageEl.onload = this.imageLoadHandler; 2205 this.imageEl.onerror = this.imageErrorHandler; 2206 this.imageEl.onabort = this.imageErrorHandler; 2207 this.imageEl.originalSrc = this.src; 2208 this.imageEl.src = this.src; 2209 2210 }, 2211 2212 2213 2214 /* 2215 * Function: shrinkImage 2216 */ 2217 shrinkImage: function(){ 2218 2219 if (Util.isNothing(this.imageEl)){ 2220 return; 2221 } 2222 2223 if (this.imageEl.src.indexOf(this.src) > -1){ 2224 this.imageEl.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='; 2225 if (!Util.isNothing(this.imageEl.parentNode)){ 2226 Util.DOM.removeChild(this.imageEl, this.imageEl.parentNode); 2227 } 2228 } 2229 2230 }, 2231 2232 2233 2234 /* 2235 * Function: onImageLoad 2236 */ 2237 onImageLoad: function(e){ 2238 2239 this.imageEl.onload = null; 2240 this.imageEl.naturalWidth = Util.coalesce(this.imageEl.naturalWidth, this.imageEl.width); 2241 this.imageEl.naturalHeight = Util.coalesce(this.imageEl.naturalHeight, this.imageEl.height); 2242 this.imageEl.isLandscape = (this.imageEl.naturalWidth > this.imageEl.naturalHeight); 2243 this.imageEl.isLoading = false; 2244 2245 Util.Events.fire(this, { 2246 type: PhotoSwipe.Image.EventTypes.onLoad, 2247 target: this 2248 }); 2249 2250 }, 2251 2252 2253 2254 /* 2255 * Function: onImageError 2256 */ 2257 onImageError: function(e){ 2258 2259 this.imageEl.onload = null; 2260 this.imageEl.onerror = null; 2261 this.imageEl.onabort = null; 2262 this.imageEl.isLoading = false; 2263 this.imageEl.isError = true; 2264 2265 Util.Events.fire(this, { 2266 type: PhotoSwipe.Image.EventTypes.onError, 2267 target: this 2268 }); 2269 2270 } 2271 2272 2273 2274 }); 2275 2276 2277 2278} 2279( 2280 window, 2281 window.klass, 2282 window.Code.Util 2283));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2284// Licensed under the MIT license 2285// version: 3.0.5 2286 2287(function(window, klass, Util){ 2288 2289 2290 Util.registerNamespace('Code.PhotoSwipe.Cache'); 2291 var PhotoSwipe = window.Code.PhotoSwipe; 2292 2293 2294 2295 PhotoSwipe.Cache.Mode = { 2296 2297 normal: 'normal', 2298 aggressive: 'aggressive' 2299 2300 }; 2301 2302 2303 2304 PhotoSwipe.Cache.Functions = { 2305 2306 /* 2307 * Function: getImageSource 2308 * Default method for returning an image's source 2309 */ 2310 getImageSource: function(el){ 2311 return el.href; 2312 }, 2313 2314 2315 2316 /* 2317 * Function: getImageCaption 2318 * Default method for returning an image's caption 2319 * Assumes the el is an anchor and the first child is the 2320 * image. The returned value is the "alt" attribute of the 2321 * image. 2322 */ 2323 getImageCaption: function(el){ 2324 2325 if (el.nodeName === "IMG"){ 2326 return Util.DOM.getAttribute(el, 'alt'); 2327 } 2328 var i, j, childEl; 2329 for (i=0, j=el.childNodes.length; i<j; i++){ 2330 childEl = el.childNodes[i]; 2331 if (el.childNodes[i].nodeName === 'IMG'){ 2332 return Util.DOM.getAttribute(childEl, 'alt'); 2333 } 2334 } 2335 2336 }, 2337 2338 2339 2340 /* 2341 * Function: getImageMetaData 2342 * Can be used if you wish to store additional meta 2343 * data against the full size image 2344 */ 2345 getImageMetaData: function(el){ 2346 2347 return {}; 2348 2349 } 2350 2351 }; 2352 2353 2354 2355 2356} 2357( 2358 window, 2359 window.klass, 2360 window.Code.Util 2361));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2362// Licensed under the MIT license 2363// version: 3.0.5 2364 2365(function(window, klass, Util){ 2366 2367 2368 Util.registerNamespace('Code.PhotoSwipe.Cache'); 2369 var PhotoSwipe = window.Code.PhotoSwipe; 2370 2371 2372 2373 PhotoSwipe.Cache.CacheClass = klass({ 2374 2375 2376 2377 images: null, 2378 settings: null, 2379 2380 2381 2382 /* 2383 * Function: dispose 2384 */ 2385 dispose: function(){ 2386 2387 var prop, i, j; 2388 2389 if (!Util.isNothing(this.images)){ 2390 for (i=0, j=this.images.length; i<j; i++){ 2391 this.images[i].dispose(); 2392 } 2393 this.images.length = 0; 2394 } 2395 2396 for (prop in this) { 2397 if (Util.objectHasProperty(this, prop)) { 2398 this[prop] = null; 2399 } 2400 } 2401 2402 }, 2403 2404 2405 2406 /* 2407 * Function: initialize 2408 */ 2409 initialize: function(images, options){ 2410 2411 var i, j, cacheImage, image, src, caption, metaData; 2412 2413 this.settings = options; 2414 2415 this.images = []; 2416 2417 for (i=0, j=images.length; i<j; i++){ 2418 2419 image = images[i]; 2420 src = this.settings.getImageSource(image); 2421 caption = this.settings.getImageCaption(image); 2422 metaData = this.settings.getImageMetaData(image); 2423 2424 this.images.push(new PhotoSwipe.Image.ImageClass(image, src, caption, metaData)); 2425 2426 } 2427 2428 2429 }, 2430 2431 2432 2433 /* 2434 * Function: getImages 2435 */
2436 getImages: function(indexes){ 2437 2438 var i, j, retval = [], cacheImage; 2439 2440 for (i=0, j=indexes.length; i<j; i++){ 2441 cacheImage = this.images[indexes[i]]; 2442 if (this.settings.cacheMode === PhotoSwipe.Cache.Mode.aggressive){ 2443 cacheImage.cacheDoNotShrink = true; 2444 } 2445 retval.push(cacheImage); 2446 } 2447 2448 if (this.settings.cacheMode === PhotoSwipe.Cache.Mode.aggressive){ 2449 for (i=0, j=this.images.length; i<j; i++){ 2450 cacheImage = this.images[i]; 2451 if (!Util.objectHasProperty(cacheImage, 'cacheDoNotShrink')){ 2452 cacheImage.shrinkImage(); 2453 } 2454 else{ 2455 delete cacheImage.cacheDoNotShrink; 2456 } 2457 } 2458 } 2459 2460 return retval; 2461 2462 } 2463 2464 2465 }); 2466 2467 2468 2469} 2470( 2471 window, 2472 window.klass, 2473 window.Code.Util, 2474 window.Code.PhotoSwipe.Image 2475));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2476// Licensed under the MIT license 2477// version: 3.0.5 2478 2479(function(window, klass, Util){ 2480 2481 2482 Util.registerNamespace('Code.PhotoSwipe.DocumentOverlay'); 2483 var PhotoSwipe = window.Code.PhotoSwipe; 2484 2485 2486 2487 PhotoSwipe.DocumentOverlay.CssClasses = { 2488 documentOverlay: 'ps-document-overlay' 2489 }; 2490 2491 2492 2493} 2494( 2495 window, 2496 window.klass, 2497 window.Code.Util 2498));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2499// Licensed under the MIT license 2500// version: 3.0.5 2501 2502(function(window, klass, Util){ 2503 2504 2505 Util.registerNamespace('Code.PhotoSwipe.DocumentOverlay'); 2506 var PhotoSwipe = window.Code.PhotoSwipe; 2507 2508 2509 2510 PhotoSwipe.DocumentOverlay.DocumentOverlayClass = klass({ 2511 2512 2513 2514 el: null, 2515 settings: null, 2516 initialBodyHeight: null, 2517 2518 2519 2520 /* 2521 * Function: dispose 2522 */ 2523 dispose: function(){ 2524 2525 var prop; 2526 2527 Util.Animation.stop(this.el); 2528 Util.DOM.removeChild(this.el, this.el.parentNode); 2529 2530 for (prop in this) { 2531 if (Util.objectHasProperty(this, prop)) { 2532 this[prop] = null; 2533 } 2534 } 2535 2536 }, 2537 2538 2539 2540 /* 2541 * Function: initialize 2542 */ 2543 initialize: function(options){ 2544 2545 this.settings = options; 2546 2547 this.el = Util.DOM.createElement( 2548 'div', 2549 { 2550 'class': PhotoSwipe.DocumentOverlay.CssClasses.documentOverlay 2551 }, 2552 '' 2553 ); 2554 Util.DOM.setStyle(this.el, { 2555 display: 'block', 2556 position: 'absolute', 2557 left: 0, 2558 top: 0, 2559 zIndex: this.settings.zIndex 2560 }); 2561 2562 Util.DOM.hide(this.el); 2563 if (this.settings.target === window){ 2564 Util.DOM.appendToBody(this.el); 2565 } 2566 else{ 2567 Util.DOM.appendChild(this.el, this.settings.target); 2568 } 2569 2570 Util.Animation.resetTranslate(this.el); 2571 2572 // Store this value incase the body dimensions change to zero! 2573 // I've seen it happen! :D 2574 this.initialBodyHeight = Util.DOM.bodyOuterHeight(); 2575 2576 2577 }, 2578 2579 2580 2581 /* 2582 * Function: resetPosition 2583 */ 2584 resetPosition: function(){ 2585 2586 var width, height, top; 2587 2588 if (this.settings.target === window){ 2589 2590 width = Util.DOM.windowWidth(); 2591 height = Util.DOM.bodyOuterHeight() * 2; // This covers extra height added by photoswipe 2592 top = (this.settings.jQueryMobile) ? Util.DOM.windowScrollTop() + 'px' : '0px'; 2593 2594 if (height < 1){ 2595 height = this.initialBodyHeight; 2596 } 2597 2598 if (Util.DOM.windowHeight() > height){ 2599 height = Util.DOM.windowHeight(); 2600 } 2601 2602 } 2603 else{ 2604 2605 width = Util.DOM.width(this.settings.target); 2606 height = Util.DOM.height(this.settings.target); 2607 top = '0px'; 2608 2609 } 2610 2611 Util.DOM.setStyle(this.el, { 2612 width: width, 2613 height: height, 2614 top: top 2615 }); 2616 2617 }, 2618 2619 2620 2621 /* 2622 * Function: fadeIn 2623 */ 2624 fadeIn: function(speed, callback){ 2625 2626 this.resetPosition(); 2627 2628 Util.DOM.setStyle(this.el, 'opacity', 0); 2629 Util.DOM.show(this.el); 2630 2631 Util.Animation.fadeIn(this.el, speed, callback); 2632 2633 } 2634 2635 2636 }); 2637 2638 2639 2640} 2641( 2642 window, 2643 window.klass, 2644 window.Code.Util 2645));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2646// Licensed under the MIT license 2647// version: 3.0.5 2648 2649(function(window, klass, Util){ 2650 2651 2652 Util.registerNamespace('Code.PhotoSwipe.Carousel'); 2653 var PhotoSwipe = window.Code.PhotoSwipe; 2654 2655 2656 2657 PhotoSwipe.Carousel.EventTypes = { 2658 2659 onSlideByEnd: 'PhotoSwipeCarouselOnSlideByEnd', 2660 onSlideshowStart: 'PhotoSwipeCarouselOnSlideshowStart', 2661 onSlideshowStop: 'PhotoSwipeCarouselOnSlideshowStop' 2662 2663 }; 2664 2665 2666
2667 PhotoSwipe.Carousel.CssClasses = { 2668 carousel: 'ps-carousel', 2669 content: 'ps-carousel-content', 2670 item: 'ps-carousel-item', 2671 itemLoading: 'ps-carousel-item-loading', 2672 itemError: 'ps-carousel-item-error' 2673 }; 2674 2675 2676 2677 PhotoSwipe.Carousel.SlideByAction = { 2678 previous: 'previous', 2679 current: 'current', 2680 next: 'next' 2681 }; 2682 2683 2684} 2685( 2686 window, 2687 window.klass, 2688 window.Code.Util 2689));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 2690// Licensed under the MIT license 2691// version: 3.0.5 2692 2693(function(window, klass, Util){ 2694 2695 2696 Util.registerNamespace('Code.PhotoSwipe.Carousel'); 2697 var PhotoSwipe = window.Code.PhotoSwipe; 2698 2699 2700 PhotoSwipe.Carousel.CarouselClass = klass({ 2701 2702 2703 2704 el: null, 2705 contentEl: null, 2706 settings: null, 2707 cache: null, 2708 slideByEndHandler: null, 2709 currentCacheIndex: null, 2710 isSliding: null, 2711 isSlideshowActive: null, 2712 lastSlideByAction: null, 2713 touchStartPoint: null, 2714 touchStartPosition: null, 2715 imageLoadHandler: null, 2716 imageErrorHandler: null, 2717 slideshowTimeout: null, 2718 2719 2720 2721 /* 2722 * Function: dispose 2723 */ 2724 dispose: function(){ 2725 2726 var prop, i, j; 2727 2728 for (i=0, j=this.cache.images.length; i<j; i++){ 2729 Util.Events.remove(this.cache.images[i], PhotoSwipe.Image.EventTypes.onLoad, this.imageLoadHandler); 2730 Util.Events.remove(this.cache.images[i], PhotoSwipe.Image.EventTypes.onError, this.imageErrorHandler); 2731 } 2732 2733 this.stopSlideshow(); 2734 Util.Animation.stop(this.el); 2735 Util.DOM.removeChild(this.el, this.el.parentNode); 2736 2737 for (prop in this) { 2738 if (Util.objectHasProperty(this, prop)) { 2739 this[prop] = null; 2740 } 2741 } 2742 2743 }, 2744 2745 2746 2747 /* 2748 * Function: initialize 2749 */ 2750 initialize: function(cache, options){ 2751 2752 //this.supr(true); 2753 2754 var i, totalItems, itemEl; 2755 2756 this.cache = cache; 2757 this.settings = options; 2758 this.slideByEndHandler = this.onSlideByEnd.bind(this); 2759 this.imageLoadHandler = this.onImageLoad.bind(this); 2760 this.imageErrorHandler = this.onImageError.bind(this); 2761 this.currentCacheIndex = 0; 2762 this.isSliding = false; 2763 this.isSlideshowActive = false; 2764 2765 // No looping if < 3 images 2766 if (this.cache.images.length < 3){ 2767 this.settings.loop = false; 2768 } 2769 2770 // Main container 2771 this.el = Util.DOM.createElement( 2772 'div', 2773 { 2774 'class': PhotoSwipe.Carousel.CssClasses.carousel 2775 }, 2776 '' 2777 ); 2778 Util.DOM.setStyle(this.el, { 2779 display: 'block', 2780 position: 'absolute', 2781 left: 0, 2782 top: 0, 2783 overflow: 'hidden', 2784 zIndex: this.settings.zIndex 2785 }); 2786 Util.DOM.hide(this.el); 2787 2788 2789 // Content 2790 this.contentEl = Util.DOM.createElement( 2791 'div', 2792 { 2793 'class': PhotoSwipe.Carousel.CssClasses.content 2794 }, 2795 '' 2796 ); 2797 Util.DOM.setStyle(this.contentEl, { 2798 display: 'block', 2799 position: 'absolute', 2800 left: 0, 2801 top: 0 2802 }); 2803 2804 Util.DOM.appendChild(this.contentEl, this.el); 2805 2806 2807 // Items 2808 totalItems = (cache.images.length < 3) ? cache.images.length : 3; 2809 2810 for (i=0; i<totalItems; i++){ 2811 2812 itemEl = Util.DOM.createElement( 2813 'div', 2814 { 2815 'class': PhotoSwipe.Carousel.CssClasses.item + 2816 ' ' + PhotoSwipe.Carousel.CssClasses.item + '-'+ i 2817 }, 2818 '' 2819 ); 2820 Util.DOM.setAttribute(itemEl, 'style', 'float: left;'); 2821 Util.DOM.setStyle(itemEl, { 2822 display: 'block', 2823 position: 'relative', 2824 left: 0, 2825 top: 0, 2826 overflow: 'hidden' 2827 }); 2828 2829 if (this.settings.margin > 0){ 2830 Util.DOM.setStyle(itemEl, { 2831 marginRight: this.settings.margin + 'px' 2832 }); 2833 } 2834 2835 Util.DOM.appendChild(itemEl, this.contentEl); 2836 2837 } 2838 2839 2840 if (this.settings.target === window){ 2841 Util.DOM.appendToBody(this.el); 2842 } 2843 else{ 2844 Util.DOM.appendChild(this.el, this.settings.target); 2845 } 2846 2847 }, 2848 2849 2850 2851 2852 /* 2853 * Function: resetPosition 2854 */ 2855 resetPosition: function(){ 2856 2857 var width, height, top, itemWidth, itemEls, contentWidth, i, j, itemEl, imageEl; 2858 2859 if (this.settings.target === window){
2860 width = Util.DOM.windowWidth(); 2861 height = Util.DOM.windowHeight(); 2862 top = Util.DOM.windowScrollTop() + 'px'; 2863 } 2864 else{ 2865 width = Util.DOM.width(this.settings.target); 2866 height = Util.DOM.height(this.settings.target); 2867 top = '0px'; 2868 } 2869 2870 itemWidth = (this.settings.margin > 0) ? width + this.settings.margin : width; 2871 itemEls = Util.DOM.find('.' + PhotoSwipe.Carousel.CssClasses.item, this.contentEl); 2872 contentWidth = itemWidth * itemEls.length; 2873 2874 2875 // Set the height and width to fill the document 2876 Util.DOM.setStyle(this.el, { 2877 top: top, 2878 width: width, 2879 height: height 2880 }); 2881 2882 2883 // Set the height and width of the content el 2884 Util.DOM.setStyle(this.contentEl, { 2885 width: contentWidth, 2886 height: height 2887 }); 2888 2889 2890 // Set the height and width of item elements 2891 for (i=0, j=itemEls.length; i<j; i++){ 2892 2893 itemEl = itemEls[i]; 2894 Util.DOM.setStyle(itemEl, { 2895 width: width, 2896 height: height 2897 }); 2898 2899 // If an item has an image then resize that 2900 imageEl = Util.DOM.find('img', itemEl)[0]; 2901 if (!Util.isNothing(imageEl)){ 2902 this.resetImagePosition(imageEl); 2903 } 2904 2905 } 2906 2907 this.setContentLeftPosition(); 2908 2909 2910 }, 2911 2912 2913 2914 /* 2915 * Function: resetImagePosition 2916 */ 2917 resetImagePosition: function(imageEl){ 2918 2919 if (Util.isNothing(imageEl)){ 2920 return; 2921 } 2922 2923 var 2924 src = Util.DOM.getAttribute(imageEl, 'src'), 2925 scale, 2926 newWidth, 2927 newHeight, 2928 newTop, 2929 newLeft, 2930 maxWidth = Util.DOM.width(this.el), 2931 maxHeight = Util.DOM.height(this.el); 2932 2933 if (this.settings.imageScaleMethod === 'fitNoUpscale'){ 2934 2935 newWidth = imageEl.naturalWidth; 2936 newHeight =imageEl.naturalHeight; 2937 2938 if (newWidth > maxWidth){ 2939 scale = maxWidth / newWidth; 2940 newWidth = Math.round(newWidth * scale); 2941 newHeight = Math.round(newHeight * scale); 2942 } 2943 2944 if (newHeight > maxHeight){ 2945 scale = maxHeight / newHeight; 2946 newHeight = Math.round(newHeight * scale); 2947 newWidth = Math.round(newWidth * scale); 2948 } 2949 2950 } 2951 else{ 2952 2953 if (imageEl.isLandscape) { 2954 // Ensure the width fits the screen 2955 scale = maxWidth / imageEl.naturalWidth; 2956 } 2957 else { 2958 // Ensure the height fits the screen 2959 scale = maxHeight / imageEl.naturalHeight; 2960 } 2961 2962 newWidth = Math.round(imageEl.naturalWidth * scale); 2963 newHeight = Math.round(imageEl.naturalHeight * scale); 2964 2965 if (this.settings.imageScaleMethod === 'zoom'){ 2966 2967 scale = 1; 2968 if (newHeight < maxHeight){ 2969 scale = maxHeight /newHeight; 2970 } 2971 else if (newWidth < maxWidth){ 2972 scale = maxWidth /newWidth; 2973 } 2974 2975 if (scale !== 1) { 2976 newWidth = Math.round(newWidth * scale); 2977 newHeight = Math.round(newHeight * scale); 2978 } 2979 2980 } 2981 else if (this.settings.imageScaleMethod === 'fit') { 2982 // Rescale again to ensure full image fits into the viewport 2983 scale = 1; 2984 if (newWidth > maxWidth) { 2985 scale = maxWidth / newWidth; 2986 } 2987 else if (newHeight > maxHeight) { 2988 scale = maxHeight / newHeight; 2989 } 2990 if (scale !== 1) { 2991 newWidth = Math.round(newWidth * scale); 2992 newHeight = Math.round(newHeight * scale); 2993 } 2994 } 2995 2996 } 2997 2998 newTop = Math.round( ((maxHeight - newHeight) / 2) ) + 'px'; 2999 newLeft = Math.round( ((maxWidth - newWidth) / 2) ) + 'px'; 3000 3001 Util.DOM.setStyle(imageEl, { 3002 position: 'absolute', 3003 width: newWidth, 3004 height: newHeight, 3005 top: newTop, 3006 left: newLeft, 3007 display: 'block' 3008 }); 3009 3010 }, 3011 3012 3013 3014 /* 3015 * Function: setContentLeftPosition 3016 */ 3017 setContentLeftPosition: function(){ 3018 3019 var width, itemEls, left; 3020 if (this.settings.target === window){ 3021 width = Util.DOM.windowWidth(); 3022 } 3023 else{ 3024 width = Util.DOM.width(this.settings.target); 3025 } 3026 3027 itemEls = this.getItemEls(); 3028 left = 0; 3029 3030 if (this.settings.loop){ 3031 left = (width + this.settings.margin) * -1; 3032 } 3033 else{ 3034 3035 if (this.currentCacheIndex === this.cache.images.length-1){ 3036 left = ((itemEls.length-1) * (width + this.settings.margin)) * -1; 3037 } 3038 else if (this.currentCacheIndex > 0){ 3039 left = (width + this.settings.margin) * -1; 3040 } 3041 3042 } 3043 3044 Util.DOM.setStyle(this.contentEl, { 3045 left: left + 'px' 3046 }); 3047 3048 }, 3049 3050 3051 3052 /* 3053 * Function: 3054 */ 3055 show: function(index){ 3056 3057 this.currentCacheIndex = index; 3058 this.resetPosition(); 3059 this.setImages(false); 3060 Util.DOM.show(this.el); 3061 3062 Util.Animation.resetTranslate(this.contentEl); 3063 var 3064 itemEls = this.getItemEls(), 3065 i, j; 3066 for (i=0, j=itemEls.length; i<j; i++){ 3067 Util.Animation.resetTranslate(itemEls[i]); 3068 } 3069 3070 Util.Events.fire(this, { 3071 type: PhotoSwipe.Carousel.EventTypes.onSlideByEnd, 3072 target: this, 3073 action: PhotoSwipe.Carousel.SlideByAction.current, 3074 cacheIndex: this.currentCacheIndex 3075 }); 3076 3077 }, 3078 3079 3080 3081 /* 3082 * Function: setImages 3083 */ 3084 setImages: function(ignoreCurrent){ 3085 3086 var 3087 cacheImages, 3088 itemEls = this.getItemEls(), 3089 nextCacheIndex = this.currentCacheIndex + 1, 3090 previousCacheIndex = this.currentCacheIndex - 1; 3091 3092 if (this.settings.loop){ 3093 3094 if (nextCacheIndex > this.cache.images.length-1){ 3095 nextCacheIndex = 0; 3096 } 3097 if (previousCacheIndex < 0){ 3098 previousCacheIndex = this.cache.images.length-1; 3099 } 3100 3101 cacheImages = this.cache.getImages([ 3102 previousCacheIndex, 3103 this.currentCacheIndex, 3104 nextCacheIndex 3105 ]); 3106 3107 if (!ignoreCurrent){ 3108 // Current 3109 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3110 } 3111 // Next 3112 this.addCacheImageToItemEl(cacheImages[2], itemEls[2]); 3113 // Previous 3114 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3115 3116 } 3117 else{ 3118 3119 if (itemEls.length === 1){ 3120 if (!ignoreCurrent){ 3121 // Current 3122 cacheImages = this.cache.getImages([ 3123 this.currentCacheIndex 3124 ]); 3125 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3126 } 3127 } 3128 else if (itemEls.length === 2){ 3129 3130 if (this.currentCacheIndex === 0){ 3131 cacheImages = this.cache.getImages([ 3132 this.currentCacheIndex, 3133 this.currentCacheIndex + 1 3134 ]); 3135 if (!ignoreCurrent){ 3136 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3137 } 3138 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3139 } 3140 else{ 3141 cacheImages = this.cache.getImages([ 3142 this.currentCacheIndex - 1, 3143 this.currentCacheIndex 3144 ]); 3145 if (!ignoreCurrent){ 3146 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3147 } 3148 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3149 } 3150 3151 } 3152 else{ 3153 3154 if (this.currentCacheIndex === 0){ 3155 cacheImages = this.cache.getImages([ 3156 this.currentCacheIndex, 3157 this.currentCacheIndex + 1, 3158 this.currentCacheIndex + 2 3159 ]); 3160 if (!ignoreCurrent){ 3161 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3162 } 3163 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3164 this.addCacheImageToItemEl(cacheImages[2], itemEls[2]); 3165 } 3166 else if (this.currentCacheIndex === this.cache.images.length-1){ 3167 cacheImages = this.cache.getImages([ 3168 this.currentCacheIndex - 2, 3169 this.currentCacheIndex - 1, 3170 this.currentCacheIndex 3171 ]); 3172 if (!ignoreCurrent){ 3173 // Current 3174 this.addCacheImageToItemEl(cacheImages[2], itemEls[2]); 3175 } 3176 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3177 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3178 } 3179 else{ 3180 cacheImages = this.cache.getImages([ 3181 this.currentCacheIndex - 1, 3182 this.currentCacheIndex, 3183 this.currentCacheIndex + 1 3184 ]); 3185 3186 if (!ignoreCurrent){ 3187 // Current 3188 this.addCacheImageToItemEl(cacheImages[1], itemEls[1]); 3189 } 3190 // Next 3191 this.addCacheImageToItemEl(cacheImages[2], itemEls[2]); 3192 // Previous 3193 this.addCacheImageToItemEl(cacheImages[0], itemEls[0]); 3194 } 3195 3196 } 3197 3198 } 3199 3200 }, 3201 3202 3203 3204 /* 3205 * Function: addCacheImageToItemEl 3206 */ 3207 addCacheImageToItemEl: function(cacheImage, itemEl){ 3208
3209 Util.DOM.removeClass(itemEl, PhotoSwipe.Carousel.CssClasses.itemError); 3210 Util.DOM.addClass(itemEl, PhotoSwipe.Carousel.CssClasses.itemLoading); 3211 3212 Util.DOM.removeChildren(itemEl); 3213 3214 Util.DOM.setStyle(cacheImage.imageEl, { 3215 display: 'none' 3216 }); 3217 Util.DOM.appendChild(cacheImage.imageEl, itemEl); 3218 3219 Util.Animation.resetTranslate(cacheImage.imageEl); 3220 3221 Util.Events.add(cacheImage, PhotoSwipe.Image.EventTypes.onLoad, this.imageLoadHandler); 3222 Util.Events.add(cacheImage, PhotoSwipe.Image.EventTypes.onError, this.imageErrorHandler); 3223 3224 cacheImage.load(); 3225 3226 }, 3227 3228 3229 3230 /* 3231 * Function: slideCarousel 3232 */ 3233 slideCarousel: function(point, action, speed){ 3234 3235 if (this.isSliding){ 3236 return; 3237 } 3238 3239 var width, diffX, slideBy; 3240 3241 if (this.settings.target === window){ 3242 width = Util.DOM.windowWidth() + this.settings.margin; 3243 } 3244 else{ 3245 width = Util.DOM.width(this.settings.target) + this.settings.margin; 3246 } 3247 3248 speed = Util.coalesce(speed, this.settings.slideSpeed); 3249 3250 if (window.Math.abs(diffX) < 1){ 3251 return; 3252 } 3253 3254 3255 switch (action){ 3256 3257 case Util.TouchElement.ActionTypes.swipeLeft: 3258 3259 slideBy = width * -1; 3260 break; 3261 3262 case Util.TouchElement.ActionTypes.swipeRight: 3263 3264 slideBy = width; 3265 break; 3266 3267 default: 3268 3269 diffX = point.x - this.touchStartPoint.x; 3270 3271 if (window.Math.abs(diffX) > width / 2){ 3272 slideBy = (diffX > 0) ? width : width * -1; 3273 } 3274 else{ 3275 slideBy = 0; 3276 } 3277 break; 3278 3279 } 3280 3281 if (slideBy < 0){ 3282 this.lastSlideByAction = PhotoSwipe.Carousel.SlideByAction.next; 3283 } 3284 else if (slideBy > 0){ 3285 this.lastSlideByAction = PhotoSwipe.Carousel.SlideByAction.previous; 3286 } 3287 else{ 3288 this.lastSlideByAction = PhotoSwipe.Carousel.SlideByAction.current; 3289 } 3290 3291 // Check for non-looping carousels 3292 // If we are at the start or end, spring back to the current item element 3293 if (!this.settings.loop){ 3294 if ( (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.previous && this.currentCacheIndex === 0 ) || (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.next && this.currentCacheIndex === this.cache.images.length-1) ){ 3295 slideBy = 0; 3296 this.lastSlideByAction = PhotoSwipe.Carousel.SlideByAction.current; 3297 } 3298 } 3299 3300 this.isSliding = true; 3301 this.doSlideCarousel(slideBy, speed); 3302 3303 }, 3304 3305 3306 3307 /* 3308 * Function: 3309 */ 3310 moveCarousel: function(point){ 3311 3312 if (this.isSliding){ 3313 return; 3314 } 3315 3316 if (!this.settings.enableDrag){ 3317 return; 3318 } 3319 3320 this.doMoveCarousel(point.x - this.touchStartPoint.x); 3321 3322 }, 3323 3324 3325 3326 /* 3327 * Function: getItemEls 3328 */ 3329 getItemEls: function(){ 3330 3331 return Util.DOM.find('.' + PhotoSwipe.Carousel.CssClasses.item, this.contentEl); 3332 3333 }, 3334 3335 3336 3337 /* 3338 * Function: previous 3339 */ 3340 previous: function(){ 3341 3342 this.stopSlideshow(); 3343 this.slideCarousel({x:0, y:0}, Util.TouchElement.ActionTypes.swipeRight, this.settings.nextPreviousSlideSpeed); 3344 3345 }, 3346 3347 3348 3349 /* 3350 * Function: next 3351 */ 3352 next: function(){ 3353 3354 this.stopSlideshow(); 3355 this.slideCarousel({x:0, y:0}, Util.TouchElement.ActionTypes.swipeLeft, this.settings.nextPreviousSlideSpeed); 3356 3357 }, 3358 3359 3360 3361 /* 3362 * Function: slideshowNext 3363 */ 3364 slideshowNext: function(){ 3365 3366 this.slideCarousel({x:0, y:0}, Util.TouchElement.ActionTypes.swipeLeft); 3367 3368 }, 3369 3370 3371 3372 3373 /* 3374 * Function: startSlideshow 3375 */ 3376 startSlideshow: function(){ 3377 3378 this.stopSlideshow(); 3379 3380 this.isSlideshowActive = true; 3381 3382 this.slideshowTimeout = window.setTimeout(this.slideshowNext.bind(this), this.settings.slideshowDelay); 3383 3384 Util.Events.fire(this, { 3385 type: PhotoSwipe.Carousel.EventTypes.onSlideshowStart, 3386 target: this 3387 }); 3388 3389 }, 3390 3391 3392 3393 /* 3394 * Function: stopSlideshow 3395 */ 3396 stopSlideshow: function(){ 3397 3398 if (!Util.isNothing(this.slideshowTimeout)){ 3399 3400 window.clearTimeout(this.slideshowTimeout); 3401 this.slideshowTimeout = null; 3402 this.isSlideshowActive = false; 3403 3404 Util.Events.fire(this, { 3405 type: PhotoSwipe.Carousel.EventTypes.onSlideshowStop, 3406 target: this 3407 }); 3408 3409 } 3410 3411 }, 3412 3413 3414 3415 /* 3416 * Function: onSlideByEnd 3417 */ 3418 onSlideByEnd: function(e){
3419 3420 if (Util.isNothing(this.isSliding)){ 3421 return; 3422 } 3423 3424 var itemEls = this.getItemEls(); 3425 3426 this.isSliding = false; 3427 3428 if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.next){ 3429 this.currentCacheIndex = this.currentCacheIndex + 1; 3430 } 3431 else if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.previous){ 3432 this.currentCacheIndex = this.currentCacheIndex - 1; 3433 } 3434 3435 if (this.settings.loop){ 3436 3437 if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.next){ 3438 // Move first to the last 3439 Util.DOM.appendChild(itemEls[0], this.contentEl); 3440 } 3441 else if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.previous){ 3442 // Move the last to the first 3443 Util.DOM.insertBefore(itemEls[itemEls.length-1], itemEls[0], this.contentEl); 3444 } 3445 3446 if (this.currentCacheIndex < 0){ 3447 this.currentCacheIndex = this.cache.images.length - 1; 3448 } 3449 else if (this.currentCacheIndex === this.cache.images.length){ 3450 this.currentCacheIndex = 0; 3451 } 3452 3453 } 3454 else{ 3455 3456 if (this.cache.images.length > 3){ 3457 3458 if (this.currentCacheIndex > 1 && this.currentCacheIndex < this.cache.images.length-2){ 3459 if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.next){ 3460 // Move first to the last 3461 Util.DOM.appendChild(itemEls[0], this.contentEl); 3462 } 3463 else if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.previous){ 3464 // Move the last to the first 3465 Util.DOM.insertBefore(itemEls[itemEls.length-1], itemEls[0], this.contentEl); 3466 } 3467 } 3468 else if (this.currentCacheIndex === 1){ 3469 if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.previous){ 3470 // Move the last to the first 3471 Util.DOM.insertBefore(itemEls[itemEls.length-1], itemEls[0], this.contentEl); 3472 } 3473 } 3474 else if (this.currentCacheIndex === this.cache.images.length-2){ 3475 if (this.lastSlideByAction === PhotoSwipe.Carousel.SlideByAction.next){ 3476 // Move first to the last 3477 Util.DOM.appendChild(itemEls[0], this.contentEl); 3478 } 3479 } 3480 3481 } 3482 3483 3484 } 3485 3486 if (this.lastSlideByAction !== PhotoSwipe.Carousel.SlideByAction.current){ 3487 this.setContentLeftPosition(); 3488 this.setImages(true); 3489 } 3490 3491 3492 Util.Events.fire(this, { 3493 type: PhotoSwipe.Carousel.EventTypes.onSlideByEnd, 3494 target: this, 3495 action: this.lastSlideByAction, 3496 cacheIndex: this.currentCacheIndex 3497 }); 3498 3499 3500 if (this.isSlideshowActive){ 3501 3502 if (this.lastSlideByAction !== PhotoSwipe.Carousel.SlideByAction.current){ 3503 this.startSlideshow(); 3504 } 3505 else{ 3506 this.stopSlideshow(); 3507 } 3508 3509 } 3510 3511 3512 }, 3513 3514 3515 3516 /* 3517 * Function: onTouch 3518 */ 3519 onTouch: function(action, point){ 3520 3521 this.stopSlideshow(); 3522 3523 switch(action){ 3524 3525 case Util.TouchElement.ActionTypes.touchStart: 3526 this.touchStartPoint = point; 3527 this.touchStartPosition = { 3528 x: window.parseInt(Util.DOM.getStyle(this.contentEl, 'left'), 0), 3529 y: window.parseInt(Util.DOM.getStyle(this.contentEl, 'top'), 0) 3530 }; 3531 break; 3532 3533 case Util.TouchElement.ActionTypes.touchMove: 3534 this.moveCarousel(point); 3535 break; 3536 3537 case Util.TouchElement.ActionTypes.touchMoveEnd: 3538 case Util.TouchElement.ActionTypes.swipeLeft: 3539 case Util.TouchElement.ActionTypes.swipeRight: 3540 this.slideCarousel(point, action); 3541 break; 3542 3543 case Util.TouchElement.ActionTypes.tap: 3544 break; 3545 3546 case Util.TouchElement.ActionTypes.doubleTap: 3547 break; 3548 3549 3550 } 3551 3552 }, 3553 3554 3555 3556 /* 3557 * Function: onImageLoad 3558 */ 3559 onImageLoad: function(e){ 3560 3561 var cacheImage = e.target; 3562 3563 if (!Util.isNothing(cacheImage.imageEl.parentNode)){ 3564 Util.DOM.removeClass(cacheImage.imageEl.parentNode, PhotoSwipe.Carousel.CssClasses.itemLoading); 3565 this.resetImagePosition(cacheImage.imageEl); 3566 } 3567 3568 Util.Events.remove(cacheImage, PhotoSwipe.Image.EventTypes.onLoad, this.imageLoadHandler); 3569 Util.Events.remove(cacheImage, PhotoSwipe.Image.EventTypes.onError, this.imageErrorHandler); 3570 3571 }, 3572 3573 3574 3575 /* 3576 * Function: onImageError 3577 */ 3578 onImageError: function(e){
3579 3580 var cacheImage = e.target; 3581 3582 if (!Util.isNothing(cacheImage.imageEl.parentNode)){ 3583 Util.DOM.removeClass(cacheImage.imageEl.parentNode, PhotoSwipe.Carousel.CssClasses.itemLoading); 3584 Util.DOM.addClass(cacheImage.imageEl.parentNode, PhotoSwipe.Carousel.CssClasses.itemError); 3585 } 3586 3587 Util.Events.remove(cacheImage, PhotoSwipe.Image.EventTypes.onLoad, this.imageLoadHandler); 3588 Util.Events.remove(cacheImage, PhotoSwipe.Image.EventTypes.onError, this.imageErrorHandler); 3589 3590 } 3591 3592 3593 3594 }); 3595 3596 3597 3598} 3599( 3600 window, 3601 window.klass, 3602 window.Code.Util 3603));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 3604// Licensed under the MIT license 3605// version: 3.0.5 3606 3607(function(window, klass, Util, TouchElement){ 3608 3609 3610 Util.registerNamespace('Code.PhotoSwipe.Carousel'); 3611 var PhotoSwipe = window.Code.PhotoSwipe; 3612 3613 3614 PhotoSwipe.Carousel.CarouselClass = PhotoSwipe.Carousel.CarouselClass.extend({ 3615 3616 3617 /* 3618 * Function: getStartingPos 3619 */ 3620 getStartingPos: function(){ 3621 3622 var startingPos = this.touchStartPosition; 3623 3624 if (Util.isNothing(startingPos)){ 3625 startingPos = { 3626 x: window.parseInt(Util.DOM.getStyle(this.contentEl, 'left'), 0), 3627 y: window.parseInt(Util.DOM.getStyle(this.contentEl, 'top'), 0) 3628 }; 3629 } 3630 3631 return startingPos; 3632 3633 }, 3634 3635 3636 3637 /* 3638 * Function: doMoveCarousel 3639 */ 3640 doMoveCarousel: function(xVal){ 3641 3642 var style; 3643 3644 if (Util.Browser.isCSSTransformSupported){ 3645 3646 style = {}; 3647 3648 style[Util.Animation._transitionPrefix + 'Property'] = 'all'; 3649 style[Util.Animation._transitionPrefix + 'Duration'] = ''; 3650 style[Util.Animation._transitionPrefix + 'TimingFunction'] = ''; 3651 style[Util.Animation._transitionPrefix + 'Delay'] = '0'; 3652 style[Util.Animation._transformLabel] = (Util.Browser.is3dSupported) ? 'translate3d(' + xVal + 'px, 0px, 0px)' : 'translate(' + xVal + 'px, 0px)'; 3653 3654 Util.DOM.setStyle(this.contentEl, style); 3655 3656 } 3657 else if (!Util.isNothing(window.jQuery)){ 3658 3659 3660 window.jQuery(this.contentEl).stop().css('left', this.getStartingPos().x + xVal + 'px'); 3661 3662 } 3663 3664 }, 3665 3666 3667 3668 /* 3669 * Function: doSlideCarousel 3670 */ 3671 doSlideCarousel: function(xVal, speed){ 3672 3673 var animateProps, transform; 3674 3675 if (speed <= 0){ 3676 3677 this.slideByEndHandler(); 3678 return; 3679 3680 } 3681 3682 3683 if (Util.Browser.isCSSTransformSupported){ 3684 3685 transform = Util.coalesce(this.contentEl.style.webkitTransform, this.contentEl.style.MozTransform, this.contentEl.style.transform, ''); 3686 if (transform.indexOf('translate3d(' + xVal) === 0){ 3687 this.slideByEndHandler(); 3688 return; 3689 } 3690 else if (transform.indexOf('translate(' + xVal) === 0){ 3691 this.slideByEndHandler(); 3692 return; 3693 } 3694 3695 Util.Animation.slideBy(this.contentEl, xVal, 0, speed, this.slideByEndHandler, this.settings.slideTimingFunction); 3696 3697 } 3698 else if (!Util.isNothing(window.jQuery)){ 3699 3700 animateProps = { 3701 left: this.getStartingPos().x + xVal + 'px' 3702 }; 3703 3704 if (this.settings.animationTimingFunction === 'ease-out'){ 3705 this.settings.animationTimingFunction = 'easeOutQuad'; 3706 } 3707 3708 if ( Util.isNothing(window.jQuery.easing[this.settings.animationTimingFunction]) ){ 3709 this.settings.animationTimingFunction = 'linear'; 3710 } 3711 3712 window.jQuery(this.contentEl).animate( 3713 animateProps, 3714 this.settings.slideSpeed, 3715 this.settings.animationTimingFunction, 3716 this.slideByEndHandler 3717 ); 3718 3719 } 3720 3721 3722 } 3723 3724 }); 3725 3726 3727 3728} 3729( 3730 window, 3731 window.klass, 3732 window.Code.Util, 3733 window.Code.PhotoSwipe.TouchElement 3734));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 3735// Licensed under the MIT license 3736// version: 3.0.5 3737 3738(function(window, klass, Util){ 3739 3740 3741 Util.registerNamespace('Code.PhotoSwipe.Toolbar'); 3742 var PhotoSwipe = window.Code.PhotoSwipe; 3743 3744 3745 PhotoSwipe.Toolbar.CssClasses = { 3746 toolbar: 'ps-toolbar', 3747 toolbarContent: 'ps-toolbar-content', 3748 toolbarTop: 'ps-toolbar-top', 3749 caption: 'ps-caption', 3750 captionBottom: 'ps-caption-bottom', 3751 captionContent: 'ps-caption-content', 3752 close: 'ps-toolbar-close', 3753 play: 'ps-toolbar-play', 3754 previous: 'ps-toolbar-previous', 3755 previousDisabled: 'ps-toolbar-previous-disabled', 3756 next: 'ps-toolbar-next', 3757 nextDisabled: 'ps-toolbar-next-disabled' 3758 }; 3759 3760 3761 3762 PhotoSwipe.Toolbar.ToolbarAction = { 3763 close: 'close', 3764 play: 'play', 3765 next: 'next', 3766 previous: 'previous', 3767 none: 'none' 3768 }; 3769 3770 3771 3772 PhotoSwipe.Toolbar.EventTypes = { 3773 onTap: 'PhotoSwipeToolbarOnClick', 3774 onBeforeShow: 'PhotoSwipeToolbarOnBeforeShow', 3775 onShow: 'PhotoSwipeToolbarOnShow', 3776 onBeforeHide: 'PhotoSwipeToolbarOnBeforeHide', 3777 onHide: 'PhotoSwipeToolbarOnHide' 3778 }; 3779 3780 3781 3782 PhotoSwipe.Toolbar.getToolbar = function(){ 3783
3784 return '<div class="' + PhotoSwipe.Toolbar.CssClasses.close + '"><div class="' + PhotoSwipe.Toolbar.CssClasses.toolbarContent + '"></div></div><div class="' + PhotoSwipe.Toolbar.CssClasses.play + '"><div class="' + PhotoSwipe.Toolbar.CssClasses.toolbarContent + '"></div></div><div class="' + PhotoSwipe.Toolbar.CssClasses.previous + '"><div class="' + PhotoSwipe.Toolbar.CssClasses.toolbarContent + '"></div></div><div class="' + PhotoSwipe.Toolbar.CssClasses.next + '"><div class="' + PhotoSwipe.Toolbar.CssClasses.toolbarContent + '"></div></div>'; 3785 3786 }; 3787 3788} 3789( 3790 window, 3791 window.klass, 3792 window.Code.Util 3793));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 3794// Licensed under the MIT license 3795// version: 3.0.5 3796 3797(function(window, klass, Util){ 3798 3799 3800 Util.registerNamespace('Code.PhotoSwipe.Toolbar'); 3801 var PhotoSwipe = window.Code.PhotoSwipe; 3802 3803 3804 PhotoSwipe.Toolbar.ToolbarClass = klass({ 3805 3806 3807 3808 toolbarEl: null, 3809 closeEl: null, 3810 playEl: null, 3811 previousEl: null, 3812 nextEl: null, 3813 captionEl: null, 3814 captionContentEl: null, 3815 currentCaption: null, 3816 settings: null, 3817 cache: null, 3818 timeout: null, 3819 isVisible: null, 3820 fadeOutHandler: null, 3821 touchStartHandler: null, 3822 touchMoveHandler: null, 3823 clickHandler: null, 3824 3825 3826 3827 /* 3828 * Function: dispose 3829 */ 3830 dispose: function(){ 3831 3832 var prop; 3833 3834 this.clearTimeout(); 3835 3836 this.removeEventHandlers(); 3837 3838 Util.Animation.stop(this.toolbarEl); 3839 Util.Animation.stop(this.captionEl); 3840 3841 Util.DOM.removeChild(this.toolbarEl, this.toolbarEl.parentNode); 3842 Util.DOM.removeChild(this.captionEl, this.captionEl.parentNode); 3843 3844 for (prop in this) { 3845 if (Util.objectHasProperty(this, prop)) { 3846 this[prop] = null; 3847 } 3848 } 3849 3850 }, 3851 3852 3853 3854 /* 3855 * Function: initialize 3856 */ 3857 initialize: function(cache, options){ 3858 3859 var cssClass; 3860 3861 this.settings = options; 3862 this.cache = cache; 3863 this.isVisible = false; 3864 3865 this.fadeOutHandler = this.onFadeOut.bind(this); 3866 this.touchStartHandler = this.onTouchStart.bind(this); 3867 this.touchMoveHandler = this.onTouchMove.bind(this); 3868 this.clickHandler = this.onClick.bind(this); 3869 3870 3871 cssClass = PhotoSwipe.Toolbar.CssClasses.toolbar; 3872 if (this.settings.captionAndToolbarFlipPosition){ 3873 cssClass = cssClass + ' ' + PhotoSwipe.Toolbar.CssClasses.toolbarTop; 3874 } 3875 3876 3877 // Toolbar 3878 this.toolbarEl = Util.DOM.createElement( 3879 'div', 3880 { 3881 'class': cssClass 3882 }, 3883 this.settings.getToolbar() 3884 ); 3885 3886 3887 Util.DOM.setStyle(this.toolbarEl, { 3888 left: 0, 3889 position: 'absolute', 3890 overflow: 'hidden', 3891 zIndex: this.settings.zIndex 3892 }); 3893 3894 if (this.settings.target === window){ 3895 Util.DOM.appendToBody(this.toolbarEl); 3896 } 3897 else{ 3898 Util.DOM.appendChild(this.toolbarEl, this.settings.target); 3899 } 3900 Util.DOM.hide(this.toolbarEl); 3901 3902 this.closeEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.close, this.toolbarEl)[0]; 3903 if (this.settings.preventHide && !Util.isNothing(this.closeEl)){ 3904 Util.DOM.hide(this.closeEl); 3905 } 3906 3907 this.playEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.play, this.toolbarEl)[0]; 3908 if (this.settings.preventSlideshow && !Util.isNothing(this.playEl)){ 3909 Util.DOM.hide(this.playEl); 3910 } 3911 3912 this.nextEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.next, this.toolbarEl)[0]; 3913 this.previousEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.previous, this.toolbarEl)[0]; 3914 3915 3916 // Caption 3917 cssClass = PhotoSwipe.Toolbar.CssClasses.caption; 3918 if (this.settings.captionAndToolbarFlipPosition){ 3919 cssClass = cssClass + ' ' + PhotoSwipe.Toolbar.CssClasses.captionBottom; 3920 } 3921 3922 this.captionEl = Util.DOM.createElement( 3923 'div', 3924 { 3925 'class': cssClass 3926 }, 3927 '' 3928 ); 3929 Util.DOM.setStyle(this.captionEl, { 3930 left: 0, 3931 position: 'absolute', 3932 overflow: 'hidden', 3933 zIndex: this.settings.zIndex 3934 }); 3935 3936 if (this.settings.target === window){ 3937 Util.DOM.appendToBody(this.captionEl); 3938 } 3939 else{ 3940 Util.DOM.appendChild(this.captionEl, this.settings.target); 3941 } 3942 Util.DOM.hide(this.captionEl); 3943 3944 this.captionContentEl = Util.DOM.createElement( 3945 'div', 3946 {
3947 'class': PhotoSwipe.Toolbar.CssClasses.captionContent 3948 }, 3949 '' 3950 ); 3951 Util.DOM.appendChild(this.captionContentEl, this.captionEl); 3952 3953 this.addEventHandlers(); 3954 3955 }, 3956 3957 3958 3959 /* 3960 * Function: resetPosition 3961 */ 3962 resetPosition: function(){ 3963 3964 var width, toolbarTop, captionTop; 3965 3966 if (this.settings.target === window){ 3967 if (this.settings.captionAndToolbarFlipPosition){ 3968 toolbarTop = Util.DOM.windowScrollTop(); 3969 captionTop = (Util.DOM.windowScrollTop() + Util.DOM.windowHeight()) - Util.DOM.height(this.captionEl); 3970 } 3971 else { 3972 toolbarTop = (Util.DOM.windowScrollTop() + Util.DOM.windowHeight()) - Util.DOM.height(this.toolbarEl); 3973 captionTop = Util.DOM.windowScrollTop(); 3974 } 3975 width = Util.DOM.windowWidth(); 3976 } 3977 else{ 3978 if (this.settings.captionAndToolbarFlipPosition){ 3979 toolbarTop = '0'; 3980 captionTop = Util.DOM.height(this.settings.target) - Util.DOM.height(this.captionEl); 3981 } 3982 else{ 3983 toolbarTop = Util.DOM.height(this.settings.target) - Util.DOM.height(this.toolbarEl); 3984 captionTop = 0; 3985 } 3986 width = Util.DOM.width(this.settings.target); 3987 } 3988 3989 Util.DOM.setStyle(this.toolbarEl, { 3990 top: toolbarTop + 'px', 3991 width: width 3992 }); 3993 3994 Util.DOM.setStyle(this.captionEl, { 3995 top: captionTop + 'px', 3996 width: width 3997 }); 3998 }, 3999 4000 4001 4002 /* 4003 * Function: toggleVisibility 4004 */ 4005 toggleVisibility: function(index){ 4006 4007 if (this.isVisible){ 4008 this.fadeOut(); 4009 } 4010 else{ 4011 this.show(index); 4012 } 4013 4014 }, 4015 4016 4017 4018 /* 4019 * Function: show 4020 */ 4021 show: function(index){ 4022 4023 Util.Animation.stop(this.toolbarEl); 4024 Util.Animation.stop(this.captionEl); 4025 4026 this.resetPosition(); 4027 this.setToolbarStatus(index); 4028 4029 Util.Events.fire(this, { 4030 type: PhotoSwipe.Toolbar.EventTypes.onBeforeShow, 4031 target: this 4032 }); 4033 4034 this.showToolbar(); 4035 this.setCaption(index); 4036 this.showCaption(); 4037 4038 this.isVisible = true; 4039 4040 this.setTimeout(); 4041 4042 Util.Events.fire(this, { 4043 type: PhotoSwipe.Toolbar.EventTypes.onShow, 4044 target: this 4045 }); 4046 4047 }, 4048 4049 4050 4051 /* 4052 * Function: setTimeout 4053 */ 4054 setTimeout: function(){ 4055 4056 if (this.settings.captionAndToolbarAutoHideDelay > 0){ 4057 // Set a timeout to hide the toolbar 4058 this.clearTimeout(); 4059 this.timeout = window.setTimeout(this.fadeOut.bind(this), this.settings.captionAndToolbarAutoHideDelay); 4060 } 4061 4062 }, 4063 4064 4065 4066 /* 4067 * Function: clearTimeout 4068 */ 4069 clearTimeout: function(){ 4070 4071 if (!Util.isNothing(this.timeout)){ 4072 window.clearTimeout(this.timeout); 4073 this.timeout = null; 4074 } 4075 4076 }, 4077 4078 4079 4080 /* 4081 * Function: fadeOut 4082 */ 4083 fadeOut: function(){ 4084 4085 this.clearTimeout(); 4086 4087 Util.Events.fire(this, { 4088 type: PhotoSwipe.Toolbar.EventTypes.onBeforeHide, 4089 target: this 4090 }); 4091 4092 Util.Animation.fadeOut(this.toolbarEl, this.settings.fadeOutSpeed); 4093 Util.Animation.fadeOut(this.captionEl, this.settings.fadeOutSpeed, this.fadeOutHandler); 4094 4095 this.isVisible = false; 4096 4097 }, 4098 4099 4100 4101 /* 4102 * Function: addEventHandlers 4103 */ 4104 addEventHandlers: function(){ 4105 4106 if (Util.Browser.isTouchSupported){ 4107 if (!Util.Browser.blackberry){ 4108 // Had an issue with touchstart, animation and Blackberry. BB will default to click 4109 Util.Events.add(this.toolbarEl, 'touchstart', this.touchStartHandler); 4110 } 4111 Util.Events.add(this.toolbarEl, 'touchmove', this.touchMoveHandler); 4112 Util.Events.add(this.captionEl, 'touchmove', this.touchMoveHandler); 4113 } 4114 Util.Events.add(this.toolbarEl, 'click', this.clickHandler); 4115 4116 }, 4117 4118 4119 4120 /* 4121 * Function: removeEventHandlers 4122 */ 4123 removeEventHandlers: function(){ 4124 4125 if (Util.Browser.isTouchSupported){ 4126 if (!Util.Browser.blackberry){ 4127 // Had an issue with touchstart, animation and Blackberry. BB will default to click 4128 Util.Events.remove(this.toolbarEl, 'touchstart', this.touchStartHandler); 4129 } 4130 Util.Events.remove(this.toolbarEl, 'touchmove', this.touchMoveHandler); 4131 Util.Events.remove(this.captionEl, 'touchmove', this.touchMoveHandler); 4132 } 4133 Util.Events.remove(this.toolbarEl, 'click', this.clickHandler); 4134 4135 }, 4136 4137 4138 4139 /* 4140 * Function: handleTap 4141 */ 4142 handleTap: function(e){
4143 4144 this.clearTimeout(); 4145 4146 var action; 4147 4148 if (e.target === this.nextEl || Util.DOM.isChildOf(e.target, this.nextEl)){ 4149 action = PhotoSwipe.Toolbar.ToolbarAction.next; 4150 } 4151 else if (e.target === this.previousEl || Util.DOM.isChildOf(e.target, this.previousEl)){ 4152 action = PhotoSwipe.Toolbar.ToolbarAction.previous; 4153 } 4154 else if (e.target === this.closeEl || Util.DOM.isChildOf(e.target, this.closeEl)){ 4155 action = PhotoSwipe.Toolbar.ToolbarAction.close; 4156 } 4157 else if (e.target === this.playEl || Util.DOM.isChildOf(e.target, this.playEl)){ 4158 action = PhotoSwipe.Toolbar.ToolbarAction.play; 4159 } 4160 4161 this.setTimeout(); 4162 4163 if (Util.isNothing(action)){ 4164 action = PhotoSwipe.Toolbar.ToolbarAction.none; 4165 } 4166 4167 Util.Events.fire(this, { 4168 type: PhotoSwipe.Toolbar.EventTypes.onTap, 4169 target: this, 4170 action: action, 4171 tapTarget: e.target 4172 }); 4173 4174 }, 4175 4176 4177 4178 /* 4179 * Function: setCaption 4180 */ 4181 setCaption: function(index){ 4182 4183 Util.DOM.removeChildren(this.captionContentEl); 4184 4185 this.currentCaption = Util.coalesce(this.cache.images[index].caption, '\u00A0'); 4186 4187 if (Util.isObject(this.currentCaption)){ 4188 Util.DOM.appendChild(this.currentCaption, this.captionContentEl); 4189 } 4190 else{ 4191 if (this.currentCaption === ''){ 4192 this.currentCaption = '\u00A0'; 4193 } 4194 Util.DOM.appendText(this.currentCaption, this.captionContentEl); 4195 } 4196 4197 this.currentCaption = (this.currentCaption === '\u00A0') ? '' : this.currentCaption; 4198 this.resetPosition(); 4199 4200 }, 4201 4202 4203 4204 /* 4205 * Function: showToolbar 4206 */ 4207 showToolbar: function(){ 4208 4209 Util.DOM.setStyle(this.toolbarEl, { 4210 opacity: this.settings.captionAndToolbarOpacity 4211 }); 4212 Util.DOM.show(this.toolbarEl); 4213 4214 }, 4215 4216 4217 4218 /* 4219 * Function: showCaption 4220 */ 4221 showCaption: function(){ 4222 4223 if (this.currentCaption === '' || this.captionContentEl.childNodes.length < 1){ 4224 // Empty caption 4225 if (!this.settings.captionAndToolbarShowEmptyCaptions){ 4226 Util.DOM.hide(this.captionEl); 4227 return; 4228 } 4229 } 4230 Util.DOM.setStyle(this.captionEl, { 4231 opacity: this.settings.captionAndToolbarOpacity 4232 }); 4233 Util.DOM.show(this.captionEl); 4234 4235 }, 4236 4237 4238 4239 /* 4240 * Function: setToolbarStatus 4241 */ 4242 setToolbarStatus: function(index){ 4243 4244 if (this.settings.loop){ 4245 return; 4246 } 4247 4248 Util.DOM.removeClass(this.previousEl, PhotoSwipe.Toolbar.CssClasses.previousDisabled); 4249 Util.DOM.removeClass(this.nextEl, PhotoSwipe.Toolbar.CssClasses.nextDisabled); 4250 4251 if (index > 0 && index < this.cache.images.length-1){ 4252 return; 4253 } 4254 4255 if (index === 0){ 4256 if (!Util.isNothing(this.previousEl)){ 4257 Util.DOM.addClass(this.previousEl, PhotoSwipe.Toolbar.CssClasses.previousDisabled); 4258 } 4259 } 4260 4261 if (index === this.cache.images.length-1){ 4262 if (!Util.isNothing(this.nextEl)){ 4263 Util.DOM.addClass(this.nextEl, PhotoSwipe.Toolbar.CssClasses.nextDisabled); 4264 } 4265 } 4266 4267 }, 4268 4269 4270 4271 /* 4272 * Function: onFadeOut 4273 */ 4274 onFadeOut: function(){ 4275 4276 Util.DOM.hide(this.toolbarEl); 4277 Util.DOM.hide(this.captionEl); 4278 4279 Util.Events.fire(this, { 4280 type: PhotoSwipe.Toolbar.EventTypes.onHide, 4281 target: this 4282 }); 4283 4284 }, 4285 4286 4287 4288 /* 4289 * Function: onTouchStart 4290 */ 4291 onTouchStart: function(e){ 4292 4293 e.preventDefault(); 4294 Util.Events.remove(this.toolbarEl, 'click', this.clickHandler); 4295 this.handleTap(e); 4296 4297 }, 4298 4299 4300 4301 /* 4302 * Function: onTouchMove 4303 */ 4304 onTouchMove: function(e){ 4305 4306 e.preventDefault(); 4307 4308 }, 4309 4310 4311 4312 /* 4313 * Function: onClick 4314 */ 4315 onClick: function(e){ 4316 4317 e.preventDefault(); 4318 this.handleTap(e); 4319 4320 } 4321 4322 4323 }); 4324 4325 4326 4327} 4328( 4329 window, 4330 window.klass, 4331 window.Code.Util 4332));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 4333// Licensed under the MIT license 4334// version: 3.0.5 4335 4336(function(window, klass, Util){ 4337 4338 4339 Util.registerNamespace('Code.PhotoSwipe.UILayer'); 4340 var PhotoSwipe = window.Code.PhotoSwipe; 4341
4342 PhotoSwipe.UILayer.CssClasses = { 4343 uiLayer: 'ps-uilayer' 4344 }; 4345 4346} 4347( 4348 window, 4349 window.klass, 4350 window.Code.Util 4351));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 4352// Licensed under the MIT license 4353// version: 3.0.5 4354 4355(function(window, klass, Util){ 4356 4357 4358 Util.registerNamespace('Code.PhotoSwipe.UILayer'); 4359 var PhotoSwipe = window.Code.PhotoSwipe; 4360 4361 4362 PhotoSwipe.UILayer.UILayerClass = Util.TouchElement.TouchElementClass.extend({ 4363 4364 4365 4366 el: null, 4367 settings: null, 4368 4369 4370 4371 /* 4372 * Function: dispose 4373 */ 4374 dispose: function(){ 4375 4376 var prop; 4377 4378 this.removeEventHandlers(); 4379 4380 Util.DOM.removeChild(this.el, this.el.parentNode); 4381 4382 for (prop in this) { 4383 if (Util.objectHasProperty(this, prop)) { 4384 this[prop] = null; 4385 } 4386 } 4387 4388 }, 4389 4390 4391 4392 /* 4393 * Function: initialize 4394 */ 4395 initialize: function(options){ 4396 4397 this.settings = options; 4398 4399 // Main container 4400 this.el = Util.DOM.createElement( 4401 'div', 4402 { 4403 'class': PhotoSwipe.UILayer.CssClasses.uiLayer 4404 }, 4405 '' 4406 ); 4407 Util.DOM.setStyle(this.el, { 4408 display: 'block', 4409 position: 'absolute', 4410 left: 0, 4411 top: 0, 4412 overflow: 'hidden', 4413 zIndex: this.settings.zIndex, 4414 opacity: 0 4415 }); 4416 Util.DOM.hide(this.el); 4417 4418 if (this.settings.target === window){ 4419 Util.DOM.appendToBody(this.el); 4420 } 4421 else{ 4422 Util.DOM.appendChild(this.el, this.settings.target); 4423 } 4424 4425 this.supr(this.el, { 4426 swipe: true, 4427 move: true, 4428 gesture: Util.Browser.iOS, 4429 doubleTap: true, 4430 preventDefaultTouchEvents: this.settings.preventDefaultTouchEvents 4431 }); 4432 4433 }, 4434 4435 4436 4437 /* 4438 * Function: resetPosition 4439 */ 4440 resetPosition: function(){ 4441 4442 // Set the height and width to fill the document 4443 if (this.settings.target === window){ 4444 Util.DOM.setStyle(this.el, { 4445 top: Util.DOM.windowScrollTop() + 'px', 4446 width: Util.DOM.windowWidth(), 4447 height: Util.DOM.windowHeight() 4448 }); 4449 } 4450 else{ 4451 Util.DOM.setStyle(this.el, { 4452 top: '0px', 4453 width: Util.DOM.width(this.settings.target), 4454 height: Util.DOM.height(this.settings.target) 4455 }); 4456 } 4457 4458 }, 4459 4460 4461 4462 /* 4463 * Function: show 4464 */ 4465 show: function(){ 4466 4467 this.resetPosition(); 4468 Util.DOM.show(this.el); 4469 this.addEventHandlers(); 4470 4471 }, 4472 4473 4474 4475 /* 4476 * Function: addEventHandlers 4477 */ 4478 addEventHandlers: function(){ 4479 4480 this.supr(); 4481 4482 }, 4483 4484 4485 4486 /* 4487 * Function: removeEventHandlers 4488 */ 4489 removeEventHandlers: function(){ 4490 4491 this.supr(); 4492 4493 } 4494 4495 4496 }); 4497 4498 4499 4500} 4501( 4502 window, 4503 window.klass, 4504 window.Code.Util 4505));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 4506// Licensed under the MIT license 4507// version: 3.0.5 4508 4509(function(window, klass, Util){ 4510 4511 4512 Util.registerNamespace('Code.PhotoSwipe.ZoomPanRotate'); 4513 var PhotoSwipe = window.Code.PhotoSwipe; 4514 4515 PhotoSwipe.ZoomPanRotate.CssClasses = { 4516 zoomPanRotate: 'ps-zoom-pan-rotate' 4517 }; 4518 4519 4520 PhotoSwipe.ZoomPanRotate.EventTypes = { 4521 4522 onTransform: 'PhotoSwipeZoomPanRotateOnTransform' 4523 4524 }; 4525 4526} 4527( 4528 window, 4529 window.klass, 4530 window.Code.Util 4531));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 4532// Licensed under the MIT license 4533// version: 3.0.5 4534 4535(function(window, klass, Util){ 4536 4537 4538 Util.registerNamespace('Code.PhotoSwipe.ZoomPanRotate'); 4539 var PhotoSwipe = window.Code.PhotoSwipe; 4540 4541 4542 PhotoSwipe.ZoomPanRotate.ZoomPanRotateClass = klass({ 4543 4544 el: null, 4545 settings: null, 4546 containerEl: null, 4547 imageEl: null, 4548 transformSettings: null, 4549 panStartingPoint: null, 4550 transformEl: null, 4551 4552 4553 4554 /* 4555 * Function: dispose 4556 */ 4557 dispose: function(){ 4558 4559 var prop; 4560 4561 Util.DOM.removeChild(this.el, this.el.parentNode); 4562 4563 for (prop in this) { 4564 if (Util.objectHasProperty(this, prop)) { 4565 this[prop] = null; 4566 } 4567 } 4568 4569 }, 4570 4571 4572 4573 /* 4574 * Function: initialize 4575 */ 4576 initialize: function(options, cacheImage, uiLayer){ 4577 4578 var parentEl, width, height, top; 4579 4580 this.settings = options; 4581 4582 if (this.settings.target === window){ 4583 parentEl = document.body;
4584 width = Util.DOM.windowWidth(); 4585 height = Util.DOM.windowHeight(); 4586 top = Util.DOM.windowScrollTop() + 'px'; 4587 } 4588 else{ 4589 parentEl = this.settings.target; 4590 width = Util.DOM.width(parentEl); 4591 height = Util.DOM.height(parentEl); 4592 top = '0px'; 4593 } 4594 4595 this.imageEl = cacheImage.imageEl.cloneNode(false); 4596 Util.DOM.setStyle(this.imageEl, { 4597 4598 zIndex: 1 4599 4600 }); 4601 4602 this.transformSettings = { 4603 4604 startingScale: 1.0, 4605 scale: 1.0, 4606 startingRotation: 0, 4607 rotation: 0, 4608 startingTranslateX: 0, 4609 startingTranslateY: 0, 4610 translateX: 0, 4611 translateY: 0 4612 4613 }; 4614 4615 4616 this.el = Util.DOM.createElement( 4617 'div', 4618 { 4619 'class': PhotoSwipe.ZoomPanRotate.CssClasses.zoomPanRotate 4620 }, 4621 '' 4622 ); 4623 Util.DOM.setStyle(this.el, { 4624 left: 0, 4625 top: top, 4626 position: 'absolute', 4627 width: width, 4628 height: height, 4629 zIndex: this.settings.zIndex, 4630 display: 'block' 4631 }); 4632 4633 Util.DOM.insertBefore(this.el, uiLayer.el, parentEl); 4634 4635 if (Util.Browser.iOS){ 4636 this.containerEl = Util.DOM.createElement('div','',''); 4637 Util.DOM.setStyle(this.containerEl, { 4638 left: 0, 4639 top: 0, 4640 width: width, 4641 height: height, 4642 position: 'absolute', 4643 zIndex: 1 4644 }); 4645 Util.DOM.appendChild(this.imageEl, this.containerEl); 4646 Util.DOM.appendChild(this.containerEl, this.el); 4647 Util.Animation.resetTranslate(this.containerEl); 4648 Util.Animation.resetTranslate(this.imageEl); 4649 this.transformEl = this.containerEl; 4650 } 4651 else{ 4652 Util.DOM.appendChild(this.imageEl, this.el); 4653 this.transformEl = this.imageEl; 4654 } 4655 4656 }, 4657 4658 4659 4660 /* 4661 * Function: setStartingTranslateFromCurrentTransform 4662 */ 4663 setStartingTranslateFromCurrentTransform: function(){ 4664 4665 var 4666 transformValue = Util.coalesce(this.transformEl.style.webkitTransform, this.transformEl.style.MozTransform, this.transformEl.style.transform), 4667 transformExploded; 4668 4669 if (!Util.isNothing(transformValue)){ 4670 4671 transformExploded = transformValue.match( /translate\((.*?)\)/ ); 4672 4673 if (!Util.isNothing(transformExploded)){ 4674 4675 transformExploded = transformExploded[1].split(', '); 4676 this.transformSettings.startingTranslateX = window.parseInt(transformExploded[0], 10); 4677 this.transformSettings.startingTranslateY = window.parseInt(transformExploded[1], 10); 4678 4679 } 4680 4681 } 4682 4683 }, 4684 4685 4686 4687 /* 4688 * Function: getScale 4689 */ 4690 getScale: function(scaleValue){ 4691 4692 var scale = this.transformSettings.startingScale * scaleValue; 4693 4694 if (this.settings.minUserZoom !== 0 && scale < this.settings.minUserZoom){ 4695 scale = this.settings.minUserZoom; 4696 } 4697 else if (this.settings.maxUserZoom !== 0 && scale > this.settings.maxUserZoom){ 4698 scale = this.settings.maxUserZoom; 4699 } 4700 4701 return scale; 4702 4703 }, 4704 4705 4706 4707 /* 4708 * Function: setStartingScaleAndRotation 4709 */ 4710 setStartingScaleAndRotation: function(scaleValue, rotationValue){ 4711 4712 this.transformSettings.startingScale = this.getScale(scaleValue); 4713 4714 this.transformSettings.startingRotation = 4715 (this.transformSettings.startingRotation + rotationValue) % 360; 4716 4717 }, 4718 4719 4720 4721 /* 4722 * Function: zoomRotate 4723 */ 4724 zoomRotate: function(scaleValue, rotationValue){ 4725 4726 this.transformSettings.scale = this.getScale(scaleValue); 4727 4728 this.transformSettings.rotation = 4729 this.transformSettings.startingRotation + rotationValue; 4730 4731 this.applyTransform(); 4732 4733 }, 4734 4735 4736 4737 /* 4738 * Function: panStart 4739 */ 4740 panStart: function(point){ 4741 4742 this.setStartingTranslateFromCurrentTransform(); 4743 4744 this.panStartingPoint = { 4745 x: point.x, 4746 y: point.y 4747 }; 4748 4749 }, 4750 4751 4752 4753 /* 4754 * Function: pan 4755 */ 4756 pan: function(point){ 4757 4758 var 4759 dx = point.x - this.panStartingPoint.x, 4760 dy = point.y - this.panStartingPoint.y, 4761 dxScaleAdjust = dx / this.transformSettings.scale , 4762 dyScaleAdjust = dy / this.transformSettings.scale; 4763 4764 this.transformSettings.translateX = 4765 this.transformSettings.startingTranslateX + dxScaleAdjust; 4766 4767 this.transformSettings.translateY = 4768 this.transformSettings.startingTranslateY + dyScaleAdjust; 4769 4770 this.applyTransform(); 4771 4772 }, 4773 4774 4775 4776 /* 4777 * Function: zoomAndPanToPoint 4778 */ 4779 zoomAndPanToPoint: function(scaleValue, point){ 4780 4781 4782 if (this.settings.target === window){ 4783 4784 this.panStart({ 4785 x: Util.DOM.windowWidth() / 2, 4786 y: Util.DOM.windowHeight() / 2 4787 }); 4788 4789 var 4790 dx = point.x - this.panStartingPoint.x, 4791 dy = point.y - this.panStartingPoint.y, 4792 dxScaleAdjust = dx / this.transformSettings.scale, 4793 dyScaleAdjust = dy / this.transformSettings.scale; 4794 4795 this.transformSettings.translateX = 4796 (this.transformSettings.startingTranslateX + dxScaleAdjust) * -1; 4797 4798 this.transformSettings.translateY = 4799 (this.transformSettings.startingTranslateY + dyScaleAdjust) * -1; 4800 4801 } 4802 4803 4804 this.setStartingScaleAndRotation(scaleValue, 0); 4805 this.transformSettings.scale = this.transformSettings.startingScale; 4806 4807 this.transformSettings.rotation = 0; 4808 4809 this.applyTransform(); 4810 4811 }, 4812 4813 4814 4815 /* 4816 * Function: applyTransform 4817 */ 4818 applyTransform: function(){ 4819 4820 var 4821 rotationDegs = this.transformSettings.rotation % 360, 4822 translateX = window.parseInt(this.transformSettings.translateX, 10), 4823 translateY = window.parseInt(this.transformSettings.translateY, 10), 4824 transform = 'scale(' + this.transformSettings.scale + ') rotate(' + rotationDegs + 'deg) translate(' + translateX + 'px, ' + translateY + 'px)'; 4825 4826 Util.DOM.setStyle(this.transformEl, { 4827 webkitTransform: transform, 4828 MozTransform: transform, 4829 msTransform: transform, 4830 transform: transform 4831 }); 4832 4833 Util.Events.fire(this, { 4834 target: this, 4835 type: PhotoSwipe.ZoomPanRotate.EventTypes.onTransform, 4836 scale: this.transformSettings.scale, 4837 rotation: this.transformSettings.rotation, 4838 rotationDegs: rotationDegs, 4839 translateX: translateX, 4840 translateY: translateY 4841 }); 4842 4843 } 4844 4845 }); 4846 4847 4848 4849} 4850( 4851 window, 4852 window.klass, 4853 window.Code.Util 4854));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 4855// Licensed under the MIT license 4856// version: 3.0.5 4857 4858(function(window, Util){ 4859 4860 4861 Util.registerNamespace('Code.PhotoSwipe'); 4862 var PhotoSwipe = window.Code.PhotoSwipe; 4863 4864 4865
4866 PhotoSwipe.CssClasses = { 4867 buildingBody: 'ps-building', 4868 activeBody: 'ps-active' 4869 }; 4870 4871 4872 4873 PhotoSwipe.EventTypes = { 4874 4875 onBeforeShow: 'PhotoSwipeOnBeforeShow', 4876 onShow: 'PhotoSwipeOnShow', 4877 onBeforeHide: 'PhotoSwipeOnBeforeHide', 4878 onHide: 'PhotoSwipeOnHide', 4879 onDisplayImage: 'PhotoSwipeOnDisplayImage', 4880 onResetPosition: 'PhotoSwipeOnResetPosition', 4881 onSlideshowStart: 'PhotoSwipeOnSlideshowStart', 4882 onSlideshowStop: 'PhotoSwipeOnSlideshowStop', 4883 onTouch: 'PhotoSwipeOnTouch', 4884 onBeforeCaptionAndToolbarShow: 'PhotoSwipeOnBeforeCaptionAndToolbarShow', 4885 onCaptionAndToolbarShow: 'PhotoSwipeOnCaptionAndToolbarShow', 4886 onBeforeCaptionAndToolbarHide: 'PhotoSwipeOnBeforeCaptionAndToolbarHide', 4887 onCaptionAndToolbarHide: 'PhotoSwipeOnCaptionAndToolbarHide', 4888 onToolbarTap: 'PhotoSwipeOnToolbarTap', 4889 onBeforeZoomPanRotateShow: 'PhotoSwipeOnBeforeZoomPanRotateShow', 4890 onZoomPanRotateShow: 'PhotoSwipeOnZoomPanRotateShow', 4891 onBeforeZoomPanRotateHide: 'PhotoSwipeOnBeforeZoomPanRotateHide', 4892 onZoomPanRotateHide: 'PhotoSwipeOnZoomPanRotateHide', 4893 onZoomPanRotateTransform: 'PhotoSwipeOnZoomPanRotateTransform' 4894 4895 }; 4896 4897 4898 4899 PhotoSwipe.instances = []; 4900 PhotoSwipe.activeInstances = []; 4901 4902 4903 4904 /* 4905 * Function: Code.PhotoSwipe.setActivateInstance 4906 */ 4907 PhotoSwipe.setActivateInstance = function(instance){ 4908 4909 // Can only have one instance per target (i.e. window or div) 4910 var index = Util.arrayIndexOf(instance.settings.target, PhotoSwipe.activeInstances, 'target'); 4911 if (index > -1){ 4912 throw 'Code.PhotoSwipe.activateInstance: Unable to active instance as another instance is already active for this target'; 4913 } 4914 PhotoSwipe.activeInstances.push({ 4915 target: instance.settings.target, 4916 instance: instance 4917 }); 4918 4919 }; 4920 4921 4922 4923 /* 4924 * Function: Code.PhotoSwipe.unsetActivateInstance 4925 */ 4926 PhotoSwipe.unsetActivateInstance = function(instance){ 4927 4928 var index = Util.arrayIndexOf(instance, PhotoSwipe.activeInstances, 'instance'); 4929 PhotoSwipe.activeInstances.splice(index, 1); 4930 4931 }; 4932 4933 4934 4935 /* 4936 * Function: Code.PhotoSwipe.attach 4937 */ 4938 PhotoSwipe.attach = function(images, options, id){ 4939 4940 var i, j, instance, image; 4941 4942 instance = PhotoSwipe.createInstance(images, options, id); 4943 4944 // Add click event handlers if applicable 4945 for (i=0, j=images.length; i<j; i++){ 4946 4947 image = images[i]; 4948 if (!Util.isNothing(image.nodeType)){ 4949 if (image.nodeType === 1){ 4950 // DOM element 4951 image.__photoSwipeClickHandler = PhotoSwipe.onTriggerElementClick.bind(instance); 4952 Util.Events.remove(image, 'click', image.__photoSwipeClickHandler); 4953 Util.Events.add(image, 'click', image.__photoSwipeClickHandler); 4954 } 4955 } 4956 4957 } 4958 4959 return instance; 4960 4961 }; 4962 4963 4964 4965 /* 4966 * jQuery plugin 4967 */ 4968 if (window.jQuery){ 4969 4970 window.jQuery.fn.photoSwipe = function(options, id){ 4971 4972 return PhotoSwipe.attach(this, options, id); 4973 4974 }; 4975 4976 4977 } 4978 4979 4980 4981 /* 4982 * Function: Code.PhotoSwipe.detatch 4983 */ 4984 PhotoSwipe.detatch = function(instance){ 4985 4986 var i, j, image; 4987 4988 // Remove click event handlers if applicable 4989 for (i=0, j=instance.originalImages.length; i<j; i++){ 4990 4991 image = instance.originalImages[i]; 4992 if (!Util.isNothing(image.nodeType)){ 4993 if (image.nodeType === 1){ 4994 // DOM element 4995 Util.Events.remove(image, 'click', image.__photoSwipeClickHandler); 4996 delete image.__photoSwipeClickHandler; 4997 } 4998 } 4999 5000 } 5001 5002 PhotoSwipe.disposeInstance(instance); 5003 5004 }; 5005 5006 5007 5008 /* 5009 * Function: Code.PhotoSwipe.createInstance 5010 */ 5011 PhotoSwipe.createInstance = function(images, options, id){ 5012 5013 var i, instance, image; 5014 5015 if (Util.isNothing(images)){ 5016 throw 'Code.PhotoSwipe.attach: No images passed.'; 5017 } 5018 5019 if (!Util.isLikeArray(images)){ 5020 throw 'Code.PhotoSwipe.createInstance: Images must be an array of elements or image urls.'; 5021 } 5022 5023 if (images.length < 1){ 5024 throw 'Code.PhotoSwipe.createInstance: No images to passed.'; 5025 } 5026 5027 options = Util.coalesce(options, { }); 5028 5029 instance = PhotoSwipe.getInstance(id); 5030 5031 if (Util.isNothing(instance)){ 5032 instance = new PhotoSwipe.PhotoSwipeClass(images, options, id); 5033 PhotoSwipe.instances.push(instance); 5034 } 5035 else{
5036 throw 'Code.PhotoSwipe.createInstance: Instance with id "' + id +' already exists."'; 5037 } 5038 5039 return instance; 5040 5041 }; 5042 5043 5044 5045 /* 5046 * Function: Code.PhotoSwipe.disposeInstance 5047 */ 5048 PhotoSwipe.disposeInstance = function(instance){ 5049 5050 var instanceIndex = PhotoSwipe.getInstanceIndex(instance); 5051 5052 if (instanceIndex < 0){ 5053 throw 'Code.PhotoSwipe.disposeInstance: Unable to find instance to dispose.'; 5054 } 5055 5056 instance.dispose(); 5057 PhotoSwipe.instances.splice(instanceIndex, 1); 5058 instance = null; 5059 5060 }; 5061 5062 5063 5064 /* 5065 * Function: onTriggerElementClick 5066 */ 5067 PhotoSwipe.onTriggerElementClick = function(e){ 5068 5069 e.preventDefault(); 5070 5071 var instance = this; 5072 instance.show(e.currentTarget); 5073 5074 }; 5075 5076 5077 5078 /* 5079 * Function: Code.PhotoSwipe.getInstance 5080 */ 5081 PhotoSwipe.getInstance = function(id){ 5082 5083 var i, j, instance; 5084 5085 for (i=0, j=PhotoSwipe.instances.length; i<j; i++){ 5086 5087 instance = PhotoSwipe.instances[i]; 5088 if (instance.id === id){ 5089 return instance; 5090 } 5091 5092 } 5093 5094 return null; 5095 5096 }; 5097 5098 5099 5100 /* 5101 * Function: Code.PhotoSwipe.getInstanceIndex 5102 */ 5103 PhotoSwipe.getInstanceIndex = function(instance){ 5104 5105 var i, j, instanceIndex = -1; 5106 5107 for (i=0, j=PhotoSwipe.instances.length; i<j; i++){ 5108 5109 if (PhotoSwipe.instances[i] === instance){ 5110 instanceIndex = i; 5111 break; 5112 } 5113 5114 } 5115 5116 return instanceIndex; 5117 5118 }; 5119 5120 5121 5122} 5123( 5124 window, 5125 window.Code.Util 5126));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com) 5127// Licensed under the MIT license 5128// version: 3.0.5 5129 5130(function(window, klass, Util, Cache, DocumentOverlay, Carousel, Toolbar, UILayer, ZoomPanRotate){ 5131 5132 5133 Util.registerNamespace('Code.PhotoSwipe'); 5134 var PhotoSwipe = window.Code.PhotoSwipe; 5135 5136 5137 PhotoSwipe.PhotoSwipeClass = klass({ 5138 5139 5140 5141 id: null, 5142 settings: null, 5143 isBackEventSupported: null, 5144 backButtonClicked: null, 5145 currentIndex: null, 5146 originalImages: null, 5147 mouseWheelStartTime: null, 5148 windowDimensions: null, 5149 5150 5151 5152 // Components 5153 cache: null, 5154 documentOverlay: null, 5155 carousel: null, 5156 uiLayer: null, 5157 toolbar: null, 5158 zoomPanRotate: null, 5159 5160 5161 5162 // Handlers 5163 windowOrientationChangeHandler: null, 5164 windowScrollHandler: null, 5165 windowHashChangeHandler: null, 5166 keyDownHandler: null, 5167 windowOrientationEventName: null, 5168 uiLayerTouchHandler: null, 5169 carouselSlideByEndHandler: null, 5170 carouselSlideshowStartHandler: null, 5171 carouselSlideshowStopHandler: null, 5172 toolbarTapHandler: null, 5173 toolbarBeforeShowHandler: null, 5174 toolbarShowHandler: null, 5175 toolbarBeforeHideHandler: null, 5176 toolbarHideHandler: null, 5177 mouseWheelHandler: null, 5178 zoomPanRotateTransformHandler: null, 5179 5180 5181 _isResettingPosition: null, 5182 _uiWebViewResetPositionTimeout: null, 5183 5184 5185 /* 5186 * Function: dispose 5187 */ 5188 dispose: function(){ 5189 5190 var prop; 5191 5192 Util.Events.remove(this, PhotoSwipe.EventTypes.onBeforeShow); 5193 Util.Events.remove(this, PhotoSwipe.EventTypes.onShow); 5194 Util.Events.remove(this, PhotoSwipe.EventTypes.onBeforeHide); 5195 Util.Events.remove(this, PhotoSwipe.EventTypes.onHide); 5196 Util.Events.remove(this, PhotoSwipe.EventTypes.onDisplayImage); 5197 Util.Events.remove(this, PhotoSwipe.EventTypes.onResetPosition); 5198 Util.Events.remove(this, PhotoSwipe.EventTypes.onSlideshowStart); 5199 Util.Events.remove(this, PhotoSwipe.EventTypes.onSlideshowStop); 5200 Util.Events.remove(this, PhotoSwipe.EventTypes.onTouch); 5201 Util.Events.remove(this, PhotoSwipe.EventTypes.onBeforeCaptionAndToolbarShow); 5202 Util.Events.remove(this, PhotoSwipe.EventTypes.onCaptionAndToolbarShow); 5203 Util.Events.remove(this, PhotoSwipe.EventTypes.onBeforeCaptionAndToolbarHide); 5204 Util.Events.remove(this, PhotoSwipe.EventTypes.onCaptionAndToolbarHide); 5205 Util.Events.remove(this, PhotoSwipe.EventTypes.onZoomPanRotateTransform); 5206 5207 5208 this.removeEventHandlers(); 5209 5210 if (!Util.isNothing(this.documentOverlay)){ 5211 this.documentOverlay.dispose(); 5212 } 5213 5214 if (!Util.isNothing(this.carousel)){ 5215 this.carousel.dispose(); 5216 } 5217 5218 if (!Util.isNothing(this.uiLayer)){ 5219 this.uiLayer.dispose(); 5220 } 5221 5222 if (!Util.isNothing(this.toolbar)){ 5223 this.toolbar.dispose(); 5224 } 5225 5226 this.destroyZoomPanRotate(); 5227 5228 if (!Util.isNothing(this.cache)){ 5229 this.cache.dispose(); 5230 } 5231 5232 for (prop in this) { 5233 if (Util.objectHasProperty(this, prop)) { 5234 this[prop] = null; 5235 } 5236 } 5237 5238 }, 5239 5240 5241 5242 /* 5243 * Function: initialize 5244 */ 5245 initialize: function(images, options, id){ 5246 5247 var targetPosition; 5248 5249 if (Util.isNothing(id)){ 5250 this.id = 'PhotoSwipe' + new Date().getTime().toString(); 5251 } 5252 else{ 5253 this.id = id; 5254 } 5255 5256 this.originalImages = images; 5257 5258 if (Util.Browser.android && !Util.Browser.firefox){ 5259 if (window.navigator.userAgent.match(/Android (\d+.\d+)/).toString().replace(/^.*\,/, '') >= 2.1){ 5260 this.isBackEventSupported = true; 5261 } 5262 } 5263 5264 if (!this.isBackEventSupported){ 5265 this.isBackEventSupported = Util.objectHasProperty(window, 'onhashchange'); 5266 } 5267 5268 this.settings = { 5269 5270 // General 5271 fadeInSpeed: 250, 5272 fadeOutSpeed: 250, 5273 preventHide: false, 5274 preventSlideshow: false, 5275 zIndex: 1000, 5276 backButtonHideEnabled: true, 5277 enableKeyboard: true, 5278 enableMouseWheel: true, 5279 mouseWheelSpeed: 350,
5280 autoStartSlideshow: false, 5281 jQueryMobile: ( !Util.isNothing(window.jQuery) && !Util.isNothing(window.jQuery.mobile) ), 5282 jQueryMobileDialogHash: '&ui-state=dialog', 5283 enableUIWebViewRepositionTimeout: false, 5284 uiWebViewResetPositionDelay: 500, 5285 target: window, 5286 preventDefaultTouchEvents: true, 5287 5288 5289 // Carousel 5290 loop: true, 5291 slideSpeed: 250, 5292 nextPreviousSlideSpeed: 0, 5293 enableDrag: true, 5294 swipeThreshold: 50, 5295 swipeTimeThreshold: 250, 5296 slideTimingFunction: 'ease-out', 5297 slideshowDelay: 3000, 5298 doubleTapSpeed: 250, 5299 margin: 20, 5300 imageScaleMethod: 'fit', // Either "fit", "fitNoUpscale" or "zoom", 5301 5302 5303 // Toolbar 5304 captionAndToolbarHide: false, 5305 captionAndToolbarFlipPosition: false, 5306 captionAndToolbarAutoHideDelay: 5000, 5307 captionAndToolbarOpacity: 0.8, 5308 captionAndToolbarShowEmptyCaptions: true, 5309 getToolbar: PhotoSwipe.Toolbar.getToolbar, 5310 5311 5312 // ZoomPanRotate 5313 allowUserZoom: true, 5314 allowRotationOnUserZoom: false, 5315 maxUserZoom: 5.0, 5316 minUserZoom: 0.5, 5317 doubleTapZoomLevel: 2.5, 5318 5319 5320 // Cache 5321 getImageSource: PhotoSwipe.Cache.Functions.getImageSource, 5322 getImageCaption: PhotoSwipe.Cache.Functions.getImageCaption, 5323 getImageMetaData: PhotoSwipe.Cache.Functions.getImageMetaData, 5324 cacheMode: PhotoSwipe.Cache.Mode.normal 5325 5326 }; 5327 5328 Util.extend(this.settings, options); 5329 5330 if (this.settings.target !== window){ 5331 targetPosition = Util.DOM.getStyle(this.settings.target, 'position'); 5332 if (targetPosition !== 'relative' || targetPosition !== 'absolute'){ 5333 Util.DOM.setStyle(this.settings.target, 'position', 'relative'); 5334 } 5335 } 5336 5337 if (this.settings.target !== window){ 5338 this.isBackEventSupported = false; 5339 this.settings.backButtonHideEnabled = false; 5340 } 5341 else{ 5342 if (this.settings.preventHide){ 5343 this.settings.backButtonHideEnabled = false; 5344 } 5345 } 5346 5347 this.cache = new Cache.CacheClass(images, this.settings); 5348 5349 }, 5350 5351 5352 5353 /* 5354 * Function: show 5355 */ 5356 show: function(obj){ 5357 5358 var i, j; 5359 5360 this._isResettingPosition = false; 5361 this.backButtonClicked = false; 5362 5363 // Work out what the starting index is 5364 if (Util.isNumber(obj)){ 5365 this.currentIndex = obj; 5366 } 5367 else{ 5368 5369 this.currentIndex = -1; 5370 for (i=0, j=this.originalImages.length; i<j; i++){ 5371 if (this.originalImages[i] === obj){ 5372 this.currentIndex = i; 5373 break; 5374 } 5375 } 5376 5377 } 5378 5379 if (this.currentIndex < 0 || this.currentIndex > this.originalImages.length-1){ 5380 throw "Code.PhotoSwipe.PhotoSwipeClass.show: Starting index out of range"; 5381 } 5382 5383 // Store a reference to the current window dimensions 5384 // Use this later to double check that a window has actually 5385 // been resized. 5386 this.isAlreadyGettingPage = this.getWindowDimensions(); 5387 5388 // Set this instance to be the active instance 5389 PhotoSwipe.setActivateInstance(this); 5390 5391 this.windowDimensions = this.getWindowDimensions(); 5392 5393 // Create components 5394 if (this.settings.target === window){ 5395 Util.DOM.addClass(window.document.body, PhotoSwipe.CssClasses.buildingBody); 5396 } 5397 else{ 5398 Util.DOM.addClass(this.settings.target, PhotoSwipe.CssClasses.buildingBody); 5399 } 5400 this.createComponents(); 5401 5402 Util.Events.fire(this, { 5403 type: PhotoSwipe.EventTypes.onBeforeShow, 5404 target: this 5405 }); 5406 5407 // Fade in the document overlay 5408 this.documentOverlay.fadeIn(this.settings.fadeInSpeed, this.onDocumentOverlayFadeIn.bind(this)); 5409 5410 }, 5411 5412 5413 5414 /* 5415 * Function: getWindowDimensions 5416 */ 5417 getWindowDimensions: function(){ 5418 5419 return { 5420 width: Util.DOM.windowWidth(), 5421 height: Util.DOM.windowHeight() 5422 }; 5423 5424 }, 5425 5426 5427 5428 /* 5429 * Function: createComponents 5430 */ 5431 createComponents: function(){ 5432 5433 this.documentOverlay = new DocumentOverlay.DocumentOverlayClass(this.settings); 5434 this.carousel = new Carousel.CarouselClass(this.cache, this.settings); 5435 this.uiLayer = new UILayer.UILayerClass(this.settings); 5436 if (!this.settings.captionAndToolbarHide){ 5437 this.toolbar = new Toolbar.ToolbarClass(this.cache, this.settings); 5438 } 5439 5440 }, 5441 5442 5443 5444 /* 5445 * Function: resetPosition 5446 */ 5447 resetPosition: function(){ 5448 5449 if (this._isResettingPosition){ 5450 return; 5451 } 5452 5453 var newWindowDimensions = this.getWindowDimensions(); 5454 if (!Util.isNothing(this.windowDimensions)){ 5455 if (newWindowDimensions.width === this.windowDimensions.width && newWindowDimensions.height === this.windowDimensions.height){ 5456 // This was added as a fudge for iOS 5457 return; 5458 } 5459 } 5460 5461 this._isResettingPosition = true; 5462 5463 this.windowDimensions = newWindowDimensions; 5464 5465 this.destroyZoomPanRotate(); 5466 5467 this.documentOverlay.resetPosition(); 5468 this.carousel.resetPosition(); 5469 5470 if (!Util.isNothing(this.toolbar)){ 5471 this.toolbar.resetPosition(); 5472 } 5473 5474 this.uiLayer.resetPosition(); 5475 5476 this._isResettingPosition = false; 5477 5478 Util.Events.fire(this, { 5479 type: PhotoSwipe.EventTypes.onResetPosition, 5480 target: this 5481 }); 5482 5483 }, 5484 5485 5486 5487 /* 5488 * Function: addEventHandler 5489 */ 5490 addEventHandler: function(type, handler){ 5491 5492 Util.Events.add(this, type, handler); 5493 5494 }, 5495 5496 5497 5498 /* 5499 * Function: addEventHandlers 5500 */ 5501 addEventHandlers: function(){ 5502 5503 if (Util.isNothing(this.windowOrientationChangeHandler)){ 5504 5505 this.windowOrientationChangeHandler = this.onWindowOrientationChange.bind(this); 5506 this.windowScrollHandler = this.onWindowScroll.bind(this); 5507 this.keyDownHandler = this.onKeyDown.bind(this); 5508 this.windowHashChangeHandler = this.onWindowHashChange.bind(this); 5509 this.uiLayerTouchHandler = this.onUILayerTouch.bind(this); 5510 this.carouselSlideByEndHandler = this.onCarouselSlideByEnd.bind(this); 5511 this.carouselSlideshowStartHandler = this.onCarouselSlideshowStart.bind(this); 5512 this.carouselSlideshowStopHandler = this.onCarouselSlideshowStop.bind(this); 5513 this.toolbarTapHandler = this.onToolbarTap.bind(this); 5514 this.toolbarBeforeShowHandler = this.onToolbarBeforeShow.bind(this); 5515 this.toolbarShowHandler = this.onToolbarShow.bind(this); 5516 this.toolbarBeforeHideHandler = this.onToolbarBeforeHide.bind(this); 5517 this.toolbarHideHandler = this.onToolbarHide.bind(this); 5518 this.mouseWheelHandler = this.onMouseWheel.bind(this); 5519 this.zoomPanRotateTransformHandler = this.onZoomPanRotateTransform.bind(this); 5520 5521 } 5522 5523 // Set window handlers 5524 if (Util.Browser.android){ 5525 // For some reason, resize was more stable than orientationchange in Android 5526 this.orientationEventName = 'resize'; 5527 } 5528 else if (Util.Browser.iOS && (!Util.Browser.safari)){ 5529 Util.Events.add(window.document.body, 'orientationchange', this.windowOrientationChangeHandler); 5530 } 5531 else{ 5532 var supportsOrientationChange = !Util.isNothing(window.onorientationchange); 5533 this.orientationEventName = supportsOrientationChange ? 'orientationchange' : 'resize'; 5534 } 5535 5536 if (!Util.isNothing(this.orientationEventName)){ 5537 Util.Events.add(window, this.orientationEventName, this.windowOrientationChangeHandler); 5538 } 5539 if (this.settings.target === window){ 5540 Util.Events.add(window, 'scroll', this.windowScrollHandler); 5541 } 5542 5543 if (this.settings.enableKeyboard){ 5544 Util.Events.add(window.document, 'keydown', this.keyDownHandler); 5545 } 5546 5547 5548 if (this.isBackEventSupported && this.settings.backButtonHideEnabled){ 5549 5550 this.windowHashChangeHandler = this.onWindowHashChange.bind(this); 5551 5552 if (this.settings.jQueryMobile){ 5553 window.location.hash = this.settings.jQueryMobileDialogHash; 5554 } 5555 else{ 5556 this.currentHistoryHashValue = 'PhotoSwipe' + new Date().getTime().toString(); 5557 window.location.hash = this.currentHistoryHashValue; 5558 } 5559 5560 Util.Events.add(window, 'hashchange', this.windowHashChangeHandler); 5561 5562 } 5563 5564 if (this.settings.enableMouseWheel){ 5565 Util.Events.add(window, 'mousewheel', this.mouseWheelHandler); 5566 } 5567 5568 Util.Events.add(this.uiLayer, Util.TouchElement.EventTypes.onTouch, this.uiLayerTouchHandler); 5569 Util.Events.add(this.carousel, Carousel.EventTypes.onSlideByEnd, this.carouselSlideByEndHandler); 5570 Util.Events.add(this.carousel, Carousel.EventTypes.onSlideshowStart, this.carouselSlideshowStartHandler); 5571 Util.Events.add(this.carousel, Carousel.EventTypes.onSlideshowStop, this.carouselSlideshowStopHandler); 5572 5573 if (!Util.isNothing(this.toolbar)){ 5574 Util.Events.add(this.toolbar, Toolbar.EventTypes.onTap, this.toolbarTapHandler); 5575 Util.Events.add(this.toolbar, Toolbar.EventTypes.onBeforeShow, this.toolbarBeforeShowHandler); 5576 Util.Events.add(this.toolbar, Toolbar.EventTypes.onShow, this.toolbarShowHandler); 5577 Util.Events.add(this.toolbar, Toolbar.EventTypes.onBeforeHide, this.toolbarBeforeHideHandler); 5578 Util.Events.add(this.toolbar, Toolbar.EventTypes.onHide, this.toolbarHideHandler); 5579 } 5580 5581 }, 5582 5583 5584 5585 /* 5586 * Function: removeEventHandlers 5587 */ 5588 removeEventHandlers: function(){ 5589 5590 if (Util.Browser.iOS && (!Util.Browser.safari)){ 5591 Util.Events.remove(window.document.body, 'orientationchange', this.windowOrientationChangeHandler); 5592 } 5593 5594 if (!Util.isNothing(this.orientationEventName)){ 5595 Util.Events.remove(window, this.orientationEventName, this.windowOrientationChangeHandler); 5596 } 5597 5598 Util.Events.remove(window, 'scroll', this.windowScrollHandler); 5599 5600 if (this.settings.enableKeyboard){ 5601 Util.Events.remove(window.document, 'keydown', this.keyDownHandler); 5602 } 5603 5604 if (this.isBackEventSupported && this.settings.backButtonHideEnabled){ 5605 Util.Events.remove(window, 'hashchange', this.windowHashChangeHandler); 5606 } 5607 5608 if (this.settings.enableMouseWheel){ 5609 Util.Events.remove(window, 'mousewheel', this.mouseWheelHandler); 5610 } 5611 5612 if (!Util.isNothing(this.uiLayer)){ 5613 Util.Events.remove(this.uiLayer, Util.TouchElement.EventTypes.onTouch, this.uiLayerTouchHandler); 5614 } 5615 5616 if (!Util.isNothing(this.toolbar)){ 5617 Util.Events.remove(this.carousel, Carousel.EventTypes.onSlideByEnd, this.carouselSlideByEndHandler); 5618 Util.Events.remove(this.carousel, Carousel.EventTypes.onSlideshowStart, this.carouselSlideshowStartHandler); 5619 Util.Events.remove(this.carousel, Carousel.EventTypes.onSlideshowStop, this.carouselSlideshowStopHandler); 5620 } 5621 5622 if (!Util.isNothing(this.toolbar)){ 5623 Util.Events.remove(this.toolbar, Toolbar.EventTypes.onTap, this.toolbarTapHandler); 5624 Util.Events.remove(this.toolbar, Toolbar.EventTypes.onBeforeShow, this.toolbarBeforeShowHandler); 5625 Util.Events.remove(this.toolbar, Toolbar.EventTypes.onShow, this.toolbarShowHandler); 5626 Util.Events.remove(this.toolbar, Toolbar.EventTypes.onBeforeHide, this.toolbarBeforeHideHandler); 5627 Util.Events.remove(this.toolbar, Toolbar.EventTypes.onHide, this.toolbarHideHandler); 5628 } 5629 5630 }, 5631 5632 5633 5634 5635 /* 5636 * Function: hide 5637 */ 5638 hide: function(){ 5639 5640 if (this.settings.preventHide){ 5641 return; 5642 } 5643 5644 if (Util.isNothing(this.documentOverlay)){ 5645 throw "Code.PhotoSwipe.PhotoSwipeClass.hide: PhotoSwipe instance is already hidden"; 5646 } 5647 5648 if (!Util.isNothing(this.hiding)){ 5649 return; 5650 } 5651 5652 this.clearUIWebViewResetPositionTimeout(); 5653 5654 this.destroyZoomPanRotate(); 5655 5656 this.removeEventHandlers(); 5657 5658 Util.Events.fire(this, { 5659 type: PhotoSwipe.EventTypes.onBeforeHide, 5660 target: this 5661 }); 5662 5663 this.uiLayer.dispose(); 5664 this.uiLayer = null; 5665 5666 if (!Util.isNothing(this.toolbar)){ 5667 this.toolbar.dispose(); 5668 this.toolbar = null; 5669 } 5670 5671 this.carousel.dispose(); 5672 this.carousel = null; 5673 5674 Util.DOM.removeClass(window.document.body, PhotoSwipe.CssClasse
5674s.activeBody); 5675 5676 this.documentOverlay.dispose(); 5677 this.documentOverlay = null; 5678 5679 this._isResettingPosition = false; 5680 5681 // Deactive this instance 5682 PhotoSwipe.unsetActivateInstance(this); 5683 5684 Util.Events.fire(this, { 5685 type: PhotoSwipe.EventTypes.onHide, 5686 target: this 5687 }); 5688 5689 this.goBackInHistory(); 5690 5691 }, 5692 5693 5694 5695 /* 5696 * Function: goBackInHistory 5697 */ 5698 goBackInHistory: function(){ 5699 5700 if (this.isBackEventSupported && this.settings.backButtonHideEnabled){ 5701 if ( !this.backButtonClicked ){ 5702 window.history.back(); 5703 } 5704 } 5705 5706 }, 5707 5708 5709 5710 /* 5711 * Function: play 5712 */ 5713 play: function(){ 5714 5715 if (this.isZoomActive()){ 5716 return; 5717 } 5718 5719 if (!this.settings.preventSlideshow){ 5720 if (!Util.isNothing(this.carousel)){ 5721 if (!Util.isNothing(this.toolbar) && this.toolbar.isVisible){ 5722 this.toolbar.fadeOut(); 5723 } 5724 this.carousel.startSlideshow(); 5725 } 5726 } 5727 5728 }, 5729 5730 5731 5732 /* 5733 * Function: stop 5734 */ 5735 stop: function(){ 5736 5737 if (this.isZoomActive()){ 5738 return; 5739 } 5740 5741 if (!Util.isNothing(this.carousel)){ 5742 this.carousel.stopSlideshow(); 5743 } 5744 5745 }, 5746 5747 5748 5749 /* 5750 * Function: previous 5751 */ 5752 previous: function(){ 5753 5754 if (this.isZoomActive()){ 5755 return; 5756 } 5757 5758 if (!Util.isNothing(this.carousel)){ 5759 this.carousel.previous(); 5760 } 5761 5762 }, 5763 5764 5765 5766 /* 5767 * Function: next 5768 */ 5769 next: function(){ 5770 5771 if (this.isZoomActive()){ 5772 return; 5773 } 5774 5775 if (!Util.isNothing(this.carousel)){ 5776 this.carousel.next(); 5777 } 5778 5779 }, 5780 5781 5782 5783 /* 5784 * Function: toggleToolbar 5785 */ 5786 toggleToolbar: function(){ 5787 5788 if (this.isZoomActive()){ 5789 return; 5790 } 5791 5792 if (!Util.isNothing(this.toolbar)){ 5793 this.toolbar.toggleVisibility(this.currentIndex); 5794 } 5795 5796 }, 5797 5798 5799 5800 /* 5801 * Function: fadeOutToolbarIfVisible 5802 */ 5803 fadeOutToolbarIfVisible: function(){ 5804 5805 if (!Util.isNothing(this.toolbar) && this.toolbar.isVisible && this.settings.captionAndToolbarAutoHideDelay > 0){ 5806 this.toolbar.fadeOut(); 5807 } 5808 5809 }, 5810 5811 5812 5813 /* 5814 * Function: createZoomPanRotate 5815 */ 5816 createZoomPanRotate: function(){ 5817 5818 this.stop(); 5819 5820 if (this.canUserZoom() && !this.isZoomActive()){ 5821 5822 Util.Events.fire(this, PhotoSwipe.EventTypes.onBeforeZoomPanRotateShow); 5823 5824 this.zoomPanRotate = new ZoomPanRotate.ZoomPanRotateClass( 5825 this.settings, 5826 this.cache.images[this.currentIndex], 5827 this.uiLayer 5828 ); 5829 5830 // If we don't override this in the event of false 5831 // you will be unable to pan around a zoomed image effectively 5832 this.uiLayer.captureSettings.preventDefaultTouchEvents = true; 5833 5834 Util.Events.add(this.zoomPanRotate, PhotoSwipe.ZoomPanRotate.EventTypes.onTransform, this.zoomPanRotateTransformHandler); 5835 5836 Util.Events.fire(this, PhotoSwipe.EventTypes.onZoomPanRotateShow); 5837 5838 if (!Util.isNothing(this.toolbar) && this.toolbar.isVisible){ 5839 this.toolbar.fadeOut(); 5840 } 5841 5842 } 5843 5844 }, 5845 5846 5847 5848 /* 5849 * Function: destroyZoomPanRotate 5850 */ 5851 destroyZoomPanRotate: function(){ 5852 5853 if (!Util.isNothing(this.zoomPanRotate)){ 5854 5855 Util.Events.fire(this, PhotoSwipe.EventTypes.onBeforeZoomPanRotateHide); 5856 5857 Util.Events.remove(this.zoomPanRotate, PhotoSwipe.ZoomPanRotate.EventTypes.onTransform, this.zoomPanRotateTransformHandler); 5858 this.zoomPanRotate.dispose(); 5859 this.zoomPanRotate = null; 5860 5861 // Set the preventDefaultTouchEvents back to it was 5862 this.uiLayer.captureSettings.preventDefaultTouchEvents = this.settings.preventDefaultTouchEvents; 5863 5864 Util.Events.fire(this, PhotoSwipe.EventTypes.onZoomPanRotateHide); 5865 5866 } 5867 5868 }, 5869 5870 5871 5872 /* 5873 * Function: canUserZoom 5874 */ 5875 canUserZoom: function(){ 5876 5877 var testEl, cacheImage; 5878 5879 if (Util.Browser.msie){ 5880 testEl = document.createElement('div'); 5881 if (Util.isNothing(testEl.style.msTransform)){ 5882 return false; 5883 } 5884 } 5885 else if (!Util.Browser.isCSSTransformSupported){ 5886 return false; 5887 } 5888 5889 if (!this.settings.allowUserZoom){ 5890 return false; 5891 } 5892 5893 5894 if (this.carousel.isSliding){ 5895 return false; 5896 } 5897 5898 cacheImage = this.cache.images[this.currentIndex]; 5899 5900 if (Util.isNothing(cacheImage)){ 5901 return false; 5902 } 5903 5904 if (cacheImage.isLoading){ 5905 return false; 5906 } 5907 5908 return true; 5909 5910 }, 5911 5912 5913 5914 /* 5915 * Function: isZoomActive 5916 */ 5917 isZoomActive: function(){ 5918 5919 return (!Util.isNothing(this.zoomPanRotate)); 5920 5921 }, 5922 5923 5924 5925 /* 5926 * Function: getCurrentImage 5927 */ 5928 getCurrentImage: function(){ 5929 5930 return this.cache.images[this.currentIndex]; 5931 5932 }, 5933 5934 5935 5936 /* 5937 * Function: onDocumentOverlayFadeIn 5938 */ 5939 onDocumentOverlayFadeIn: function(e){
5940 5941 window.setTimeout(function(){ 5942 5943 var el = (this.settings.target === window) ? window.document.body : this.settings.target; 5944 5945 Util.DOM.removeClass(el, PhotoSwipe.CssClasses.buildingBody); 5946 Util.DOM.addClass(el, PhotoSwipe.CssClasses.activeBody); 5947 5948 this.addEventHandlers(); 5949 5950 this.carousel.show(this.currentIndex); 5951 5952 this.uiLayer.show(); 5953 5954 if (this.settings.autoStartSlideshow){ 5955 this.play(); 5956 } 5957 else if (!Util.isNothing(this.toolbar)){ 5958 this.toolbar.show(this.currentIndex); 5959 } 5960 5961 Util.Events.fire(this, { 5962 type: PhotoSwipe.EventTypes.onShow, 5963 target: this 5964 }); 5965 5966 this.setUIWebViewResetPositionTimeout(); 5967 5968 }.bind(this), 250); 5969 5970 5971 }, 5972 5973 5974 5975 /* 5976 * Function: setUIWebViewResetPositionTimeout 5977 */ 5978 setUIWebViewResetPositionTimeout: function(){ 5979 5980 if (!this.settings.enableUIWebViewRepositionTimeout){ 5981 return; 5982 } 5983 5984 if (!(Util.Browser.iOS && (!Util.Browser.safari))){ 5985 return; 5986 } 5987 5988 if (!Util.isNothing(this._uiWebViewResetPositionTimeout)){ 5989 window.clearTimeout(this._uiWebViewResetPositionTimeout); 5990 } 5991 this._uiWebViewResetPositionTimeout = window.setTimeout(function(){ 5992 5993 this.resetPosition(); 5994 5995 this.setUIWebViewResetPositionTimeout(); 5996 5997 }.bind(this), this.settings.uiWebViewResetPositionDelay); 5998 5999 }, 6000 6001 6002 6003 /* 6004 * Function: clearUIWebViewResetPositionTimeout 6005 */ 6006 clearUIWebViewResetPositionTimeout: function(){ 6007 if (!Util.isNothing(this._uiWebViewResetPositionTimeout)){ 6008 window.clearTimeout(this._uiWebViewResetPositionTimeout); 6009 } 6010 }, 6011 6012 6013 6014 /* 6015 * Function: onWindowScroll 6016 */ 6017 onWindowScroll: function(e){ 6018 6019 this.resetPosition(); 6020 6021 }, 6022 6023 6024 6025 /* 6026 * Function: onWindowOrientationChange 6027 */ 6028 onWindowOrientationChange: function(e){ 6029 6030 this.resetPosition(); 6031 6032 }, 6033 6034 6035 6036 /* 6037 * Function: onWindowHashChange 6038 */ 6039 onWindowHashChange: function(e){ 6040 6041 var compareHash = '#' + 6042 ((this.settings.jQueryMobile) ? this.settings.jQueryMobileDialogHash : this.currentHistoryHashValue); 6043 6044 if (window.location.hash !== compareHash){ 6045 this.backButtonClicked = true; 6046 this.hide(); 6047 } 6048 6049 }, 6050 6051 6052 6053 /* 6054 * Function: onKeyDown 6055 */ 6056 onKeyDown: function(e){ 6057 6058 if (e.keyCode === 37) { // Left 6059 e.preventDefault(); 6060 this.previous(); 6061 } 6062 else if (e.keyCode === 39) { // Right 6063 e.preventDefault(); 6064 this.next(); 6065 } 6066 else if (e.keyCode === 38 || e.keyCode === 40) { // Up and down 6067 e.preventDefault(); 6068 } 6069 else if (e.keyCode === 27) { // Escape 6070 e.preventDefault(); 6071 this.hide(); 6072 } 6073 else if (e.keyCode === 32) { // Spacebar 6074 if (!this.settings.hideToolbar){ 6075 this.toggleToolbar(); 6076 } 6077 else{ 6078 this.hide(); 6079 } 6080 e.preventDefault(); 6081 } 6082 else if (e.keyCode === 13) { // Enter 6083 e.preventDefault(); 6084 this.play(); 6085 } 6086 6087 }, 6088 6089 6090 6091 /* 6092 * Function: onUILayerTouch 6093 */ 6094 onUILayerTouch: function(e){ 6095 6096 if (this.isZoomActive()){ 6097 6098 switch (e.action){ 6099 6100 case Util.TouchElement.ActionTypes.gestureChange: 6101 this.zoomPanRotate.zoomRotate(e.scale, (this.settings.allowRotationOnUserZoom) ? e.rotation : 0); 6102 break; 6103 6104 case Util.TouchElement.ActionTypes.gestureEnd: 6105 this.zoomPanRotate.setStartingScaleAndRotation(e.scale, (this.settings.allowRotationOnUserZoom) ? e.rotation : 0); 6106 break; 6107 6108 case Util.TouchElement.ActionTypes.touchStart: 6109 this.zoomPanRotate.panStart(e.point); 6110 break; 6111 6112 case Util.TouchElement.ActionTypes.touchMove: 6113 this.zoomPanRotate.pan(e.point); 6114 break; 6115 6116 case Util.TouchElement.ActionTypes.doubleTap: 6117 this.destroyZoomPanRotate(); 6118 this.toggleToolbar(); 6119 break; 6120 6121 case Util.TouchElement.ActionTypes.swipeLeft: 6122 this.destroyZoomPanRotate(); 6123 this.next(); 6124 this.toggleToolbar(); 6125 break; 6126 6127 case Util.TouchElement.ActionTypes.swipeRight: 6128 this.destroyZoomPanRotate(); 6129 this.previous(); 6130 this.toggleToolbar(); 6131 break; 6132 } 6133 6134 } 6135 else{ 6136 6137 switch (e.action){ 6138 6139 case Util.TouchElement.ActionTypes.touchMove: 6140 case Util.TouchElement.ActionTypes.swipeLeft: 6141 case Util.TouchElement.ActionTypes.swipeRight: 6142 6143 // Hide the toolbar if need be 6144 this.fadeOutToolbarIfVisible(); 6145 6146 // Pass the touch onto the carousel 6147 this.carousel.onTouch(e.action, e.point); 6148 break; 6149 6150 case Util.TouchElement.ActionTypes.touchStart: 6151 case Util.TouchElement.ActionTypes.touchMoveEnd: 6152 6153 // Pass the touch onto the carousel 6154 this.carousel.onTouch(e.action, e.point); 6155 break; 6156 6157 case Util.TouchElement.ActionTypes.tap: 6158 this.toggleToolbar(); 6159 break; 6160 6161 case Util.TouchElement.ActionTypes.doubleTap: 6162 6163 // Take into consideration the window scroll 6164 if (this.settings.target === window){ 6165 e.point.x -= Util.DOM.windowScrollLeft(); 6166 e.point.y -= Util.DOM.windowScrollTop(); 6167 } 6168 6169 // Just make sure that if the user clicks out of the image 6170 // that the image does not pan out of view! 6171 var 6172 cacheImageEl = this.cache.images[this.currentIndex].imageEl, 6173 6174 imageTop = window.parseInt(Util.DOM.getStyle(cacheImageEl, 'top'), 10), 6175 imageLeft = window.parseInt(Util.DOM.getStyle(cacheImageEl, 'left'), 10), 6176 imageRight = imageLeft + Util.DOM.width(cacheImageEl), 6177 imageBottom = imageTop + Util.DOM.height(cacheImageEl); 6178 6179 if (e.point.x < imageLeft){ 6180 e.point.x = imageLeft; 6181 } 6182 else if (e.point.x > imageRight){ 6183 e.point.x = imageRight; 6184 } 6185 6186 if (e.point.y < imageTop){ 6187 e.point.y = imageTop; 6188 } 6189 else if (e.point.y > imageBottom){ 6190 e.point.y = imageBottom; 6191 } 6192 6193 this.createZoomPanRotate(); 6194 if (this.isZoomActive()){ 6195 this.zoomPanRotate.zoomAndPanToPoint(this.settings.doubleTapZoomLevel, e.point); 6196 } 6197 6198 break; 6199 6200 case Util.TouchElement.ActionTypes.gestureStart: 6201 this.createZoomPanRotate(); 6202 break; 6203 } 6204 6205 6206 } 6207 6208 Util.Events.fire(this, { 6209 type: PhotoSwipe.EventTypes.onTouch, 6210 target: this, 6211 point: e.point, 6212 action: e.action 6213 }); 6214 6215 }, 6216 6217 6218 6219 /* 6220 * Function: onCarouselSlideByEnd 6221 */ 6222 onCarouselSlideByEnd: function(e){
6223 6224 this.currentIndex = e.cacheIndex; 6225 6226 if (!Util.isNothing(this.toolbar)){ 6227 this.toolbar.setCaption(this.currentIndex); 6228 this.toolbar.setToolbarStatus(this.currentIndex); 6229 } 6230 6231 Util.Events.fire(this, { 6232 type: PhotoSwipe.EventTypes.onDisplayImage, 6233 target: this, 6234 action: e.action, 6235 index: e.cacheIndex 6236 }); 6237 6238 }, 6239 6240 6241 6242 /* 6243 * Function: onToolbarTap 6244 */ 6245 onToolbarTap: function(e){ 6246 6247 switch(e.action){ 6248 6249 case Toolbar.ToolbarAction.next: 6250 this.next(); 6251 break; 6252 6253 case Toolbar.ToolbarAction.previous: 6254 this.previous(); 6255 break; 6256 6257 case Toolbar.ToolbarAction.close: 6258 this.hide(); 6259 break; 6260 6261 case Toolbar.ToolbarAction.play: 6262 this.play(); 6263 break; 6264 6265 } 6266 6267 Util.Events.fire(this, { 6268 type: PhotoSwipe.EventTypes.onToolbarTap, 6269 target: this, 6270 toolbarAction: e.action, 6271 tapTarget: e.tapTarget 6272 }); 6273 6274 }, 6275 6276 6277 6278 /* 6279 * Function: onMouseWheel 6280 */ 6281 onMouseWheel: function(e){ 6282 6283 var 6284 delta = Util.Events.getWheelDelta(e), 6285 dt = e.timeStamp - (this.mouseWheelStartTime || 0); 6286 6287 if (dt < this.settings.mouseWheelSpeed) { 6288 return; 6289 } 6290 6291 this.mouseWheelStartTime = e.timeStamp; 6292 6293 if (this.settings.invertMouseWheel){ 6294 delta = delta * -1; 6295 } 6296 6297 if (delta < 0){ 6298 this.next(); 6299 } 6300 else if (delta > 0){ 6301 this.previous(); 6302 } 6303 6304 }, 6305 6306 6307 6308 /* 6309 * Function: onCarouselSlideshowStart 6310 */ 6311 onCarouselSlideshowStart: function(e){ 6312 6313 Util.Events.fire(this, { 6314 type: PhotoSwipe.EventTypes.onSlideshowStart, 6315 target: this 6316 }); 6317 6318 }, 6319 6320 6321 6322 /* 6323 * Function: onCarouselSlideshowStop 6324 */ 6325 onCarouselSlideshowStop: function(e){ 6326 6327 Util.Events.fire(this, { 6328 type: PhotoSwipe.EventTypes.onSlideshowStop, 6329 target: this 6330 }); 6331 6332 }, 6333 6334 6335 6336 /* 6337 * Function: onToolbarBeforeShow 6338 */ 6339 onToolbarBeforeShow: function(e){ 6340 6341 Util.Events.fire(this, { 6342 type: PhotoSwipe.EventTypes.onBeforeCaptionAndToolbarShow, 6343 target: this 6344 }); 6345 6346 }, 6347 6348 6349 6350 /* 6351 * Function: onToolbarShow 6352 */ 6353 onToolbarShow: function(e){ 6354 6355 Util.Events.fire(this, { 6356 type: PhotoSwipe.EventTypes.onCaptionAndToolbarShow, 6357 target: this 6358 }); 6359 6360 }, 6361 6362 6363 6364 /* 6365 * Function: onToolbarBeforeHide 6366 */ 6367 onToolbarBeforeHide: function(e){ 6368 6369 Util.Events.fire(this, { 6370 type: PhotoSwipe.EventTypes.onBeforeCaptionAndToolbarHide, 6371 target: this 6372 }); 6373 6374 }, 6375 6376 6377 6378 /* 6379 * Function: onToolbarHide 6380 */ 6381 onToolbarHide: function(e){ 6382 6383 Util.Events.fire(this, { 6384 type: PhotoSwipe.EventTypes.onCaptionAndToolbarHide, 6385 target: this 6386 }); 6387 6388 }, 6389 6390 6391 6392 /* 6393 * Function: onZoomPanRotateTransform 6394 */ 6395 onZoomPanRotateTransform: function(e){ 6396 6397 Util.Events.fire(this, { 6398 target: this, 6399 type: PhotoSwipe.EventTypes.onZoomPanRotateTransform, 6400 scale: e.scale, 6401 rotation: e.rotation, 6402 rotationDegs: e.rotationDegs, 6403 translateX: e.translateX, 6404 translateY: e.translateY 6405 }); 6406 6407 } 6408 6409 6410 }); 6411 6412 6413 6414} 6415( 6416 window, 6417 window.klass, 6418 window.Code.Util, 6419 window.Code.PhotoSwipe.Cache, 6420 window.Code.PhotoSwipe.DocumentOverlay, 6421 window.Code.PhotoSwipe.Carousel, 6422 window.Code.PhotoSwipe.Toolbar, 6423 window.Code.PhotoSwipe.UILayer, 6424 window.Code.PhotoSwipe.ZoomPanRotate 6425));
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.