1// Copyright (c) %%year%% by Code Computerlove (http://www.codecomputerlove.com) 2// Licensed under the MIT license 3// version: %%version%% 4 5(function(window, klass, Util){ 6 7 8 Util.registerNamespace('Code.PhotoSwipe.Toolbar'); 9 var PhotoSwipe = window.Code.PhotoSwipe; 10 11 12 PhotoSwipe.Toolbar.ToolbarClass = klass({ 13 14 15 16 toolbarEl: null, 17 closeEl: null, 18 playEl: null, 19 previousEl: null, 20 nextEl: null, 21 captionEl: null, 22 captionContentEl: null, 23 currentCaption: null, 24 settings: null, 25 cache: null, 26 timeout: null, 27 isVisible: null, 28 fadeOutHandler: null, 29 touchStartHandler: null, 30 touchMoveHandler: null, 31 clickHandler: null, 32 33 34 35 /* 36 * Function: dispose 37 */ 38 dispose: function(){ 39 40 var prop; 41 42 this.clearTimeout(); 43 44 this.removeEventHandlers(); 45 46 Util.Animation.stop(this.toolbarEl); 47 Util.Animation.stop(this.captionEl); 48 49 Util.DOM.removeChild(this.toolbarEl, this.toolbarEl.parentNode); 50 Util.DOM.removeChild(this.captionEl, this.captionEl.parentNode); 51 52 for (prop in this) { 53 if (Util.objectHasProperty(this, prop)) { 54 this[prop] = null; 55 } 56 } 57 58 }, 59 60 61 62 /* 63 * Function: initialize 64 */ 65 initialize: function(cache, options){ 66 67 var cssClass; 68 69 this.settings = options; 70 this.cache = cache; 71 this.isVisible = false; 72 73 this.fadeOutHandler = this.onFadeOut.bind(this); 74 this.touchStartHandler = this.onTouchStart.bind(this); 75 this.touchMoveHandler = this.onTouchMove.bind(this); 76 this.clickHandler = this.onClick.bind(this); 77 78 79 cssClass = PhotoSwipe.Toolbar.CssClasses.toolbar; 80 if (this.settings.captionAndToolbarFlipPosition){ 81 cssClass = cssClass + ' ' + PhotoSwipe.Toolbar.CssClasses.toolbarTop; 82 } 83 84 85 // Toolbar 86 this.toolbarEl = Util.DOM.createElement( 87 'div', 88 { 89 'class': cssClass 90 }, 91 this.settings.getToolbar() 92 ); 93 94 95 Util.DOM.setStyle(this.toolbarEl, { 96 left: 0, 97 position: 'absolute', 98 overflow: 'hidden', 99 zIndex: this.settings.zIndex 100 }); 101 102 if (this.settings.target === window){ 103 Util.DOM.appendToBody(this.toolbarEl); 104 } 105 else{ 106 Util.DOM.appendChild(this.toolbarEl, this.settings.target); 107 } 108 Util.DOM.hide(this.toolbarEl); 109 110 this.closeEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.close, this.toolbarEl)[0]; 111 if (this.settings.preventHide && !Util.isNothing(this.closeEl)){ 112 Util.DOM.hide(this.closeEl); 113 } 114 115 this.playEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.play, this.toolbarEl)[0]; 116 if (this.settings.preventSlideshow && !Util.isNothing(this.playEl)){ 117 Util.DOM.hide(this.playEl); 118 } 119 120 this.nextEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.next, this.toolbarEl)[0]; 121 this.previousEl = Util.DOM.find('.' + PhotoSwipe.Toolbar.CssClasses.previous, this.toolbarEl)[0]; 122 123 124 // Caption 125 cssClass = PhotoSwipe.Toolbar.CssClasses.caption; 126 if (this.settings.captionAndToolbarFlipPosition){ 127 cssClass = cssClass + ' ' + PhotoSwipe.Toolbar.CssClasses.captionBottom; 128 } 129 130 this.captionEl = Util.DOM.createElement( 131 'div', 132 { 133 'class': cssClass 134 }, 135 '' 136 ); 137 Util.DOM.setStyle(this.captionEl, { 138 left: 0, 139 position: 'absolute', 140 overflow: 'hidden', 141 zIndex: this.settings.zIndex 142 }); 143 144 if (this.settings.target === window){ 145 Util.DOM.appendToBody(this.captionEl); 146 } 147 else{ 148 Util.DOM.appendChild(this.captionEl, this.settings.target); 149 } 150 Util.DOM.hide(this.captionEl); 151 152 this.captionContentEl = Util.DOM.createElement( 153 'div', 154 { 155 'class': PhotoSwipe.Toolbar.CssClasses.captionContent 156 }, 157 '' 158 ); 159 Util.DOM.appendChild(this.captionContentEl, this.captionEl); 160 161 this.addEventHandlers(); 162 163 }, 164 165 166 167 /* 168 * Function: resetPosition 169 */ 170 resetPosition: function(){ 171 172 var width, toolbarTop, captionTop; 173 174 if (this.settings.target === window){ 175 if (this.settings.captionAndToolbarFlipPosition){ 176 toolbarTop = Util.DOM.windowScrollTop(); 177 captionTop = (Util.DOM.windowScrollTop() + Util.DOM.windowHeight()) -
177Util.DOM.height(this.captionEl); 178 } 179 else { 180 toolbarTop = (Util.DOM.windowScrollTop() + Util.DOM.windowHeight()) - Util.DOM.height(this.toolbarEl); 181 captionTop = Util.DOM.windowScrollTop(); 182 } 183 width = Util.DOM.windowWidth(); 184 } 185 else{ 186 if (this.settings.captionAndToolbarFlipPosition){ 187 toolbarTop = '0'; 188 captionTop = Util.DOM.height(this.settings.target) - Util.DOM.height(this.captionEl); 189 } 190 else{ 191 toolbarTop = Util.DOM.height(this.settings.target) - Util.DOM.height(this.toolbarEl); 192 captionTop = 0; 193 } 194 width = Util.DOM.width(this.settings.target); 195 } 196 197 Util.DOM.setStyle(this.toolbarEl, { 198 top: toolbarTop + 'px', 199 width: width 200 }); 201 202 Util.DOM.setStyle(this.captionEl, { 203 top: captionTop + 'px', 204 width: width 205 }); 206 }, 207 208 209 210 /* 211 * Function: toggleVisibility 212 */ 213 toggleVisibility: function(index){ 214 215 if (this.isVisible){ 216 this.fadeOut(); 217 } 218 else{ 219 this.show(index); 220 } 221 222 }, 223 224 225 226 /* 227 * Function: show 228 */ 229 show: function(index){ 230 231 Util.Animation.stop(this.toolbarEl); 232 Util.Animation.stop(this.captionEl); 233 234 this.resetPosition(); 235 this.setToolbarStatus(index); 236 237 Util.Events.fire(this, { 238 type: PhotoSwipe.Toolbar.EventTypes.onBeforeShow, 239 target: this 240 }); 241 242 this.showToolbar(); 243 this.setCaption(index); 244 this.showCaption(); 245 246 this.isVisible = true; 247 248 this.setTimeout(); 249 250 Util.Events.fire(this, { 251 type: PhotoSwipe.Toolbar.EventTypes.onShow, 252 target: this 253 }); 254 255 }, 256 257 258 259 /* 260 * Function: setTimeout 261 */ 262 setTimeout: function(){ 263 264 if (this.settings.captionAndToolbarAutoHideDelay > 0){ 265 // Set a timeout to hide the toolbar 266 this.clearTimeout(); 267 this.timeout = window.setTimeout(this.fadeOut.bind(this), this.settings.captionAndToolbarAutoHideDelay); 268 } 269 270 }, 271 272 273 274 /* 275 * Function: clearTimeout 276 */ 277 clearTimeout: function(){ 278 279 if (!Util.isNothing(this.timeout)){ 280 window.clearTimeout(this.timeout); 281 this.timeout = null; 282 } 283 284 }, 285 286 287 288 /* 289 * Function: fadeOut 290 */ 291 fadeOut: function(){ 292 293 this.clearTimeout(); 294 295 Util.Events.fire(this, { 296 type: PhotoSwipe.Toolbar.EventTypes.onBeforeHide, 297 target: this 298 }); 299 300 Util.Animation.fadeOut(this.toolbarEl, this.settings.fadeOutSpeed); 301 Util.Animation.fadeOut(this.captionEl, this.settings.fadeOutSpeed, this.fadeOutHandler); 302 303 this.isVisible = false; 304 305 }, 306 307 308 309 /* 310 * Function: addEventHandlers 311 */ 312 addEventHandlers: function(){ 313 314 if (Util.Browser.isTouchSupported){ 315 if (!Util.Browser.blackberry){ 316 // Had an issue with touchstart, animation and Blackberry. BB will default to click 317 Util.Events.add(this.toolbarEl, 'touchstart', this.touchStartHandler); 318 } 319 Util.Events.add(this.toolbarEl, 'touchmove', this.touchMoveHandler); 320 Util.Events.add(this.captionEl, 'touchmove', this.touchMoveHandler); 321 } 322 Util.Events.add(this.toolbarEl, 'click', this.clickHandler); 323 324 }, 325 326 327 328 /* 329 * Function: removeEventHandlers 330 */ 331 removeEventHandlers: function(){ 332 333 if (Util.Browser.isTouchSupported){ 334 if (!Util.Browser.blackberry){ 335 // Had an issue with touchstart, animation and Blackberry. BB will default to click 336 Util.Events.remove(this.toolbarEl, 'touchstart', this.touchStartHandler); 337 } 338 Util.Events.remove(this.toolbarEl, 'touchmove', this.touchMoveHandler); 339 Util.Events.remove(this.captionEl, 'touchmove', this.touchMoveHandler); 340 } 341 Util.Events.remove(this.toolbarEl, 'click', this.clickHandler); 342 343 }, 344 345 346 347 /* 348 * Function: handleTap 349 */ 350 handleTap: function(e){ 351 352 this.clearTimeout(); 353 354 var action; 355 356 if (e.target === this.nextEl || Util.DOM.isChildOf(e.target, this.nextEl)){ 357 action = PhotoSwipe.Toolbar.ToolbarAction.next; 358 } 359 else if (e.target === this.previousEl || Util.DOM.isChildOf(e.target, this.previousEl)){ 360 action = PhotoSwipe.Toolbar.ToolbarAction.previous; 361 } 362 else if (e.target === this.closeEl || Util.DOM.isChildOf(e.target, this.closeEl)){ 363 action = PhotoSwipe.Toolbar.ToolbarAction.close; 364 } 365 else if (e.target === this.playEl || Util.DOM.isChildOf(e.target, this.playEl)){ 366 action = PhotoSwipe.Toolbar.ToolbarAction.play; 367 } 368 369 this.setTimeout(); 370 371 if (Util.isNothing(action)){ 372 action = PhotoSwipe.Toolbar.ToolbarAction.none; 373 } 374 375 Util.Events.fire(this, { 376 type: PhotoSwipe.Toolbar.EventTypes.onTap, 377 target: this, 378 action: action, 379 tapTarget: e.target 380 }); 381 382 }, 383 384 385 386 /* 387 * Function: setCaption 388 */ 389 setCaption: function(index){ 390 391 Util.DOM.removeChildren(this.captionContentEl); 392 393 this.currentCaption = Util.coalesce(this.cache.images[index].caption, '\u00A0'); 394 395 if (Util.isObject(this.currentCaption)){ 396 Util.DOM.appendChild(this.currentCaption, this.captionContentEl); 397 } 398 else{ 399 if (this.currentCaption === ''){ 400 this.currentCaption = '\u00A0'; 401 } 402 Util.DOM.appendText(this.currentCaption, this.captionContentEl); 403 } 404 405 this.currentCaption = (this.currentCaption === '\u00A0') ? '' : this.currentCaption; 406 this.resetPosition(); 407 408 }, 409 410 411 412 /* 413 * Function: showToolbar 414 */ 415 showToolbar: function(){ 416 417 Util.DOM.setStyle(this.toolbarEl, { 418 opacity: this.settings.captionAndToolbarOpacity 419 }); 420 Util.DOM.show(this.toolbarEl); 421 422 }, 423 424 425 426 /* 427 * Function: showCaption 428 */ 429 showCaption: function(){ 430 431 if (this.currentCaption === '' || this.captionContentEl.childNodes.length < 1){ 432 // Empty caption 433 if (!this.settings.captionAndToolbarShowEmptyCaptions){ 434 Util.DOM.hide(this.captionEl); 435 return; 436 } 437 } 438 Util.DOM.setStyle(this.captionEl, { 439 opacity: this.settings.captionAndToolbarOpacity 440 }); 441 Util.DOM.show(this.captionEl); 442
443 }, 444 445 446 447 /* 448 * Function: setToolbarStatus 449 */ 450 setToolbarStatus: function(index){ 451 452 if (this.settings.loop){ 453 return; 454 } 455 456 Util.DOM.removeClass(this.previousEl, PhotoSwipe.Toolbar.CssClasses.previousDisabled); 457 Util.DOM.removeClass(this.nextEl, PhotoSwipe.Toolbar.CssClasses.nextDisabled); 458 Util.DOM.removeClass(this.playEl, PhotoSwipe.Toolbar.CssClasses.playDisabled); 459 460 if (index > 0 && index < this.cache.images.length-1){ 461 return; 462 } 463 464 if (index === 0 && index === this.cache.images.length-1){ 465 if (!Util.isNothing(this.playEl)){ 466 Util.DOM.addClass(this.playEl, PhotoSwipe.Toolbar.CssClasses.playDisabled); 467 } 468 } 469 470 if (index === 0){ 471 if (!Util.isNothing(this.previousEl)){ 472 Util.DOM.addClass(this.previousEl, PhotoSwipe.Toolbar.CssClasses.previousDisabled); 473 } 474 } 475 476 if (index === this.cache.images.length-1){ 477 if (!Util.isNothing(this.nextEl)){ 478 Util.DOM.addClass(this.nextEl, PhotoSwipe.Toolbar.CssClasses.nextDisabled); 479 } 480 } 481 482 }, 483 484 485 486 /* 487 * Function: onFadeOut 488 */ 489 onFadeOut: function(){ 490 491 Util.DOM.hide(this.toolbarEl); 492 Util.DOM.hide(this.captionEl); 493 494 Util.Events.fire(this, { 495 type: PhotoSwipe.Toolbar.EventTypes.onHide, 496 target: this 497 }); 498 499 }, 500 501 502 503 /* 504 * Function: onTouchStart 505 */ 506 onTouchStart: function(e){ 507 508 e.preventDefault(); 509 Util.Events.remove(this.toolbarEl, 'click', this.clickHandler); 510 this.handleTap(e); 511 512 }, 513 514 515 516 /* 517 * Function: onTouchMove 518 */ 519 onTouchMove: function(e){ 520 521 e.preventDefault(); 522 523 }, 524 525 526 527 /* 528 * Function: onClick 529 */ 530 onClick: function(e){ 531 532 e.preventDefault(); 533 this.handleTap(e); 534 535 } 536 537 538 }); 539 540 541 542} 543( 544 window, 545 window.klass, 546 window.Code.Util 547));
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.