vendor: 17,072 bytes, lines 1-579
1/*! sidr - v2.2.1 - 2016-02-17 2 * http://www.berriart.com/sidr/ 3 * Copyright (c) 2013-2016 Alberto Varela; Licensed MIT */ 4 5(function () { 6 'use strict'; 7 8 var babelHelpers = {}; 9 10 babelHelpers.classCallCheck = function (instance, Constructor) { 11 if (!(instance instanceof Constructor)) { 12 throw new TypeError("Cannot call a class as a function"); 13 } 14 }; 15 16 babelHelpers.createClass = function () { 17 function defineProperties(target, props) { 18 for (var i = 0; i < props.length; i++) { 19 var descriptor = props[i]; 20 descriptor.enumerable = descriptor.enumerable || false; 21 descriptor.configurable = true; 22 if ("value" in descriptor) descriptor.writable = true; 23 Object.defineProperty(target, descriptor.key, descriptor); 24 } 25 } 26 27 return function (Constructor, protoProps, staticProps) { 28 if (protoProps) defineProperties(Constructor.prototype, protoProps); 29 if (staticProps) defineProperties(Constructor, staticProps); 30 return Constructor; 31 }; 32 }(); 33 34 babelHelpers; 35 36 var sidrStatus = { 37 moving: false, 38 opened: false 39 }; 40 41 var helper = { 42 // Check for valids urls 43 // From : http://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-an-url 44 45 isUrl: function isUrl(str) { 46 var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol 47 '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name 48 '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address 49 '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path 50 '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string 51 '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator 52 53 if (pattern.test(str)) { 54 return true; 55 } else { 56 return false; 57 } 58 }, 59 60 61 // Add sidr prefixes 62 addPrefixes: function addPrefixes($element) { 63 this.addPrefix($element, 'id'); 64 this.addPrefix($element, 'class'); 65 $element.removeAttr('style'); 66 }, 67 addPrefix: function addPrefix($element, attribute) { 68 var toReplace = $element.attr(attribute); 69 70 if (typeof toReplace === 'string' && toReplace !== '' && toReplace !== 'sidr-inner') { 71 $element.attr(attribute, toReplace.replace(/([A-Za-z0-9_.\-]+)/g, 'sidr-' + attribute + '-$1')); 72 } 73 }, 74 75 76 // Check if transitions is supported 77 transitions: function () { 78 var body = document.body || document.documentElement, 79 style = body.style, 80 supported = false, 81 property = 'transition'; 82 83 if (property in style) { 84 supported = true; 85 } else { 86 (function () { 87 var prefixes = ['moz', 'webkit', 'o', 'ms'], 88 prefix = undefined, 89 i = undefined; 90 91 property = property.charAt(0).toUpperCase() + property.substr(1); 92 supported = function () { 93 for (i = 0; i < prefixes.length; i++) { 94 prefix = prefixes[i]; 95 if (prefix + property in style) { 96 return true; 97 } 98 } 99 100 return false; 101 }(); 102 property = supported ? '-' + prefix.toLowerCase() + '-' + property.toLowerCase() : null; 103 })(); 104 } 105 106 return { 107 supported: supported, 108 property: property 109 }; 110 }() 111 }; 112 113 var $$2 = jQuery; 114 115 var bodyAnimationClass = 'sidr-animating'; 116 var openAction = 'open'; 117 var closeAction = 'close'; 118 var transitionEndEvent = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend'; 119 var Menu = function () { 120 function Menu(name) { 121 babelHelpers.classCallCheck(this, Menu); 122 123 this.name = name; 124 this.item = $$2('#' + name); 125 this.openClass = name === 'sidr' ? 'sidr-open' : 'sidr-open ' + name + '-open'; 126 this.menuWidth = this.item.outerWidth(true); 127 this.speed = this.item.data('speed'); 128 this.side = this.item.data('side'); 129 this.displace = this.item.data('displace'); 130 this.timing = this.item.data('timing'); 131 this.method = this.item.data('method'); 132 this.onOpenCallback = this.item.data('onOpen'); 133 this.onCloseCallback = this.item.data('onClose'); 134 this.onOpenEndCallback = this.item.data('onOpenEnd'); 135 this.onCloseEndCallback = this.item.data('onCloseEnd'); 136 this.body = $$2(this.item.data('body')); 137 } 138 139 babelHelpers.createClass(Menu, [{ 140 key: 'getAnimation', 141 value: function getAnimation(action, element) { 142 var animation = {}, 143 prop = this.side; 144 145 if (action === 'open' && element === 'body') { 146 animation[prop] = this.menuWidth + 'px'; 147 } else if (action === 'close' && element === 'menu') { 148 animation[prop] = '-' + this.menuWidth + 'px'; 149 } else { 150 animation[prop] = 0; 151 } 152 153 return animation; 154 } 155 }, { 156 key: 'prepareBody', 157 value: function prepareBody(action) { 158 var prop = action === 'open' ? 'hidden' : ''; 159 160 // Prepare page if container is body 161 if (this.body.is('body')) { 162 var $html = $$2('html'), 163 scrollTop = $html.scrollTop(); 164 165 $html.css('overflow-x', prop).scrollTop(scrollTop); 166 } 167 } 168 }, { 169 key: 'openBody', 170 value: function openBody() { 171 if (this.displace) { 172 var transitions = helper.transitions, 173 $body = this.body; 174 175 if (transitions.supported) { 176 $body.css(transitions.property, this.side + ' ' + this.speed / 1000 + 's ' + this.timing).css(this.side, 0).css({ 177 width: $body.width(), 178 position: 'absolute' 179 }); 180 $body.css(this.side, this.menuWidth + 'px'); 181 } else { 182 var bodyAnimation = this.getAnimation(openAction, 'body'); 183 184 $body.css({ 185 width: $body.width(), 186 position: 'absolute' 187 }).animate(bodyAnimation, { 188 queue: false, 189 duration: this.speed 190 }); 191 } 192 } 193 } 194 }, { 195 key: 'onCloseBody', 196 value: function onCloseBody() { 197 var transitions = helper.transitions, 198 resetStyles = { 199 width: '', 200 position: '', 201 right: '', 202 left: '' 203 }; 204 205 if (transitions.supported) { 206 resetStyles[transitions.property] = ''; 207 } 208 209 this.body.css(resetStyles).unbind(transitionEndEvent); 210 } 211 }, { 212 key: 'closeBody', 213 value: function closeBody() { 214 var _this = this; 215 216 if (this.displace) { 217 if (helper.transitions.supported) { 218 this.body.css(this.side, 0).one(transitionEndEvent, function () { 219 _this.onCloseBody(); 220 }); 221 } else { 222 var bodyAnimation = this.getAnimation(closeAction, 'body'); 223 224 this.body.animate(bodyAnimation, { 225 queue: false, 226 duration: this.speed, 227 complete: function complete() { 228 _this.onCloseBody(); 229 } 230 }); 231 } 232 } 233 } 234 }, { 235 key: 'moveBody', 236 value: function moveBody(action) { 237 if (action === openAction) { 238 this.openBody(); 239 } else { 240 this.closeBody(); 241 } 242 } 243 }, { 244 key: 'onOpenMenu', 245 value: function onOpenMenu(callback) { 246 var name = this.name; 247 248 sidrStatus.moving = false; 249 sidrStatus.opened = name; 250 251 this.item.unbind(transitionEndEvent); 252 253 this.body.removeClass(bodyAnimationClass).addClass(this.openClass); 254 255 this.onOpenEndCallback(); 256 257 if (typeof callback === 'function') { 258 callback(name); 259 } 260 } 261 }, { 262 key: 'openMenu', 263 value: function openMenu(callback) { 264 var _this2 = this; 265 266 var $item = this.item; 267 268 if (helper.transitions.supported) { 269 $item.css(this.side, 0).one(transitionEndEvent, function () { 270 _this2.onOpenMenu(callback); 271 }); 272 } else { 273 var menuAnimation = this.getAnimation(openAction, 'menu'); 274 275 $item.css('display', 'block').animate(menuAnimation, { 276 queue: false, 277 duration: this.speed, 278 complete: function complete() { 279 _this2.onOpenMenu(callback); 280 } 281 }); 282 } 283 } 284 }, { 285 key: 'onCloseMenu', 286 value: function onCloseMenu(callback) { 287 this.item.css({ 288 left: '', 289 right: '' 290 }).unbind(transitionEndEvent); 291 $$2('html').css('overflow-x', ''); 292 293 sidrStatus.moving = false; 294 sidrStatus.opened = false; 295 296 this.body.removeClass(bodyAnimationClass).removeClass(this.openClass); 297 298 this.onCloseEndCallback(); 299 300 // Callback 301 if (typeof callback === 'function') { 302 callback(name); 303 } 304 } 305 }, { 306 key: 'closeMenu', 307 value: function closeMenu(callback) { 308 var _this3 = this; 309 310 var item = this.item; 311 312 if (helper.transitions.supported) { 313 item.css(this.side, '').one(transitionEndEvent, function () { 314 _this3.onCloseMenu(callback); 315 }); 316 } else { 317 var menuAnimation = this.getAnimation(closeAction, 'menu'); 318 319 item.animate(menuAnimation, { 320 queue: false, 321 duration: this.speed, 322 complete: function complete() { 323 _this3.onCloseMenu(); 324 } 325 }); 326 } 327 } 328 }, { 329 key: 'moveMenu', 330 value: function moveMenu(action, callback) { 331 this.body.addClass(bodyAnimationClass); 332 333 if (action === openAction) { 334 this.openMenu(callback); 335 } else { 336 this.closeMenu(callback); 337 } 338 } 339 }, { 340 key: 'move', 341 value: function move(action, callback) { 342 // Lock sidr 343 sidrStatus.moving = true; 344 345 this.prepareBody(action); 346 this.moveBody(action); 347 this.moveMenu(action, callback); 348 } 349 }, { 350 key: 'open', 351 value: function open(callback) { 352 var _this4 = this; 353 354 // Check if is already opened or moving 355 if (sidrStatus.opened === this.name || sidrStatus.moving) { 356 return; 357 } 358 359 // If another menu opened close first 360 if (sidrStatus.opened !== false) { 361 var alreadyOpenedMenu = new Menu(sidrStatus.opened); 362 363 alreadyOpenedMenu.close(function () { 364 _this4.open(callback); 365 }); 366 367 return; 368 } 369 370 this.move('open', callback); 371 372 // onOpen callback 373 this.onOpenCallback(); 374 } 375 }, { 376 key: 'close', 377 value: function close(callback) { 378 // Check if is already closed or moving 379 if (sidrStatus.opened !== this.name || sidrStatus.moving) { 380 return; 381 } 382 383 this.move('close', callback); 384 385 // onClose callback 386 this.onCloseCallback(); 387 } 388 }, { 389 key: 'toggle', 390 value: function toggle(callback) { 391 if (sidrStatus.opened === this.name) { 392 this.close(callback); 393 } else { 394 this.open(callback); 395 } 396 } 397 }]); 398 return Menu; 399 }(); 400 401 var $$1 = jQuery; 402 403 function execute(action, name, callback) { 404 var sidr = new Menu(name); 405 406 switch (action) { 407 case 'open': 408 sidr.open(callback); 409 break; 410 case 'close': 411 sidr.close(callback); 412 break; 413 case 'toggle': 414 sidr.toggle(callback); 415 break; 416 default: 417 $$1.error('Method ' + action + ' does not exist on jQuery.sidr'); 418 break; 419 } 420 } 421 422 var i; 423 var $ = jQuery; 424 var publicMethods = ['open', 'close', 'toggle']; 425 var methodName; 426 var methods = {}; 427 var getMethod = function getMethod(methodName) { 428 return function (name, callback) { 429 // Check arguments 430 if (typeof name === 'function') { 431 callback = name; 432 name = 'sidr'; 433 } else if (!name) { 434 name = 'sidr'; 435 } 436 437 execute(methodName, name, callback); 438 }; 439 }; 440 for (i = 0; i < publicMethods.length; i++) { 441 methodName = publicMethods[i]; 442 methods[methodName] = getMethod(methodName); 443 } 444 445 function sidr(method) { 446 if (method === 'status') { 447 return sidrStatus; 448 } else if (methods[method]) { 449 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 450 } else if (typeof method === 'function' || typeof method === 'string' || !method) { 451 return methods.toggle.apply(this, arguments); 452 } else { 453 $.error('Method ' + method + ' does not exist on jQuery.sidr'); 454 } 455 } 456 457 var $$3 = jQuery; 458 459 function fillContent($sideMenu, settings) { 460 // The menu content 461 if (typeof settings.source === 'function') { 462 var newContent = settings.source(name); 463 464 $sideMenu.html(newContent); 465 } else if (typeof settings.source === 'string' && helper.isUrl(settings.source)) { 466 $$3.get(settings.source, function (data) { 467 $sideMenu.html(data); 468 }); 469 } else if (typeof settings.source === 'string') { 470 var htmlContent = '', 471 selectors = settings.source.split(','); 472 473 $$3.each(selectors, function (index, element) { 474 htmlContent += '<div class="sidr-inner">' + $$3(element).html() + '</div>'; 475 }); 476 477 // Renaming ids and classes 478 if (settings.renaming) { 479 var $htmlContent = $$3('<div />').html(htmlContent); 480 481 $htmlContent.find('*').each(function (index, element) { 482 var $element = $$3(element); 483 484 helper.addPrefixes($element); 485 }); 486 htmlContent = $htmlContent.html(); 487 } 488 489 $sideMenu.html(htmlContent); 490 } else if (settings.source !== null) { 491 $$3.error('Invalid Sidr Source'); 492 } 493 494 return $sideMenu; 495 } 496 497 function fnSidr(options) { 498 var transitions = helper.transitions, 499 settings = $$3.extend({ 500 name: 'sidr', // Name for the 'sidr' 501 speed: 200, // Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds) 502 side: 'left', // Accepts 'left' or 'right' 503 source: null, // Override the source of the content. 504 renaming: true, // The ids and classes will be prepended with a prefix when loading existent content 505 body: 'body', // Page container selector, 506 displace: true, // Displace the body content or not 507 timing: 'ease', // Timing function for CSS transitions 508 method: 'toggle', // The method to call when element is clicked 509 bind: 'touchstart click', // The event(s) to trigger the menu 510 onOpen: function onOpen() {}, 511 // Callback when sidr start opening 512 onClose: function onClose() {}, 513 // Callback when sidr start closing 514 onOpenEnd: function onOpenEnd() {}, 515 // Callback when sidr end opening 516 onCloseEnd: function onCloseEnd() {} // Callback when sidr end closing 517 518 }, options), 519 name = settings.name, 520 $sideMenu = $$3('#' + name); 521 522 // If the side menu do not exist create it 523 if ($sideMenu.length === 0) { 524 $sideMenu = $$3('<div />').attr('id', name).appendTo($$3('body')); 525 } 526 527 // Add transition to menu if are supported 528 if (transitions.supported) { 529 $sideMenu.css(transitions.property, settings.side + ' ' + settings.speed / 1000 + 's ' + settings.timing); 530 } 531 532 // Adding styles and options 533 $sideMenu.addClass('sidr').addClass(settings.side).data({ 534 speed: settings.speed, 535 side: settings.side, 536 body: settings.body, 537 displace: settings.displace, 538 timing: settings.timing, 539 method: settings.method, 540 onOpen: settings.onOpen, 541 onClose: settings.onClose, 542 onOpenEnd: settings.onOpenEnd, 543 onCloseEnd: settings.onCloseEnd 544 }); 545 546 $sideMenu = fillContent($sideMenu, settings); 547 548 return this.each(function () { 549 var $this = $$3(this), 550 data = $this.data('sidr'), 551 flag = false; 552 553 // If the plugin hasn't been initialized yet 554 if (!data) { 555 sidrStatus.moving = false; 556 sidrStatus.opened = false; 557 558 $this.data('sidr', name); 559 560 $this.bind(settings.bind, function (event) { 561 event.preventDefault(); 562 563 if (!flag) { 564 flag = true; 565 sidr(settings.method, name); 566 567 setTimeout(function () { 568 flag = false; 569 }, 100); 570 } 571 }); 572 } 573 }); 574 } 575 576 jQuery.sidr = sidr; 577 jQuery.fn.sidr = fnSidr; 578 579}());
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.