vendor: 10,095 bytes, lines 1-254
1/*! ======================================================= 2 VERSION 9.8.1 3 ========================================================= */ 4"use strict"; 5 6var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { 7 return typeof obj; 8} : function (obj) { 9 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 10}; 11 12/*! ========================================================= 13 * bootstrap-slider.js 14 * 15 * Maintainers: 16 * Kyle Kemp 17 * - Twitter: @seiyria 18 * - Github: seiyria 19 * Rohit Kalkur 20 * - Twitter: @Rovolutionary 21 * - Github: rovolution 22 * 23 * ========================================================= 24 * 25 * bootstrap-slider is released under the MIT License 26 * Copyright (c) 2017 Kyle Kemp, Rohit Kalkur, and contributors 27 * 28 * Permission is hereby granted, free of charge, to any person 29 * obtaining a copy of this software and associated documentation 30 * files (the "Software"), to deal in the Software without 31 * restriction, including without limitation the rights to use, 32 * copy, modify, merge, publish, distribute, sublicense, and/or sell 33 * copies of the Software, and to permit persons to whom the 34 * Software is furnished to do so, subject to the following 35 * conditions: 36 * 37 * The above copyright notice and this permission notice shall be 38 * included in all copies or substantial portions of the Software. 39 * 40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 41 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 42 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 43 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 44 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 45 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 46 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 47 * OTHER DEALINGS IN THE SOFTWARE. 48 * 49 * ========================================================= */ 50 51/** 52 * Bridget makes jQuery widgets 53 * v1.0.1 54 * MIT license 55 */ 56var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object"; 57 58(function (factory) { 59 if (typeof define === "function" && define.amd) { 60 define(["jquery"], factory); 61 } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" && module.exports) { 62 var jQuery; 63 try { 64 jQuery = require("jquery"); 65 } catch (err) { 66 jQuery = null; 67 } 68 module.exports = factory(jQuery); 69 } else if (window) { 70 window.Slider = factory(window.jQuery); 71 } 72})(function ($) { 73 // Constants 74 var NAMESPACE_MAIN = 'slider'; 75 var NAMESPACE_ALTERNATE = 'bootstrapSlider'; 76 77 // Polyfill console methods 78 if (windowIsDefined && !window.console) { 79 window.console = {}; 80 } 81 if (windowIsDefined && !window.console.log) { 82 window.console.log = function () {}; 83 } 84 if (windowIsDefined && !window.console.warn) { 85 window.console.warn = function () {}; 86 } 87 88 // Reference to Slider constructor 89 var Slider; 90 91 (function ($) { 92 93 'use strict'; 94 95 // -------------------------- utils -------------------------- // 96 97 var slice = Array.prototype.slice; 98 99 function noop() {} 100 101 // -------------------------- definition -------------------------- // 102 103 function defineBridget($) { 104 105 // bail if no jQuery 106 if (!$) { 107 return; 108 } 109 110 // -------------------------- addOptionMethod -------------------------- // 111 112 /** 113 * adds option method -> $().plugin('option', {...}) 114 * @param {Function} PluginClass - constructor class 115 */ 116 function addOptionMethod(PluginClass) { 117 // don't overwrite original option method 118 if (PluginClass.prototype.option) { 119 return; 120 } 121 122 // option setter 123 PluginClass.prototype.option = function (opts) { 124 // bail out if not an object 125 if (!$.isPlainObject(opts)) { 126 return; 127 } 128 this.options = $.extend(true, this.options, opts); 129 }; 130 } 131 132 // -------------------------- plugin bridge -------------------------- // 133 134 // helper function for logging errors 135 // $.error breaks jQuery chaining 136 var logError = typeof console === 'undefined' ? noop : function (message) { 137 console.error(message); 138 }; 139 140 /** 141 * jQuery plugin bridge, access methods like $elem.plugin('method') 142 * @param {String} namespace - plugin name 143 * @param {Function} PluginClass - constructor class 144 */ 145 function bridge(namespace, PluginClass) { 146 // add to jQuery fn namespace 147 $.fn[namespace] = function (options) { 148 if (typeof options === 'string') { 149 // call plugin method when first argument is a string 150 // get arguments for method 151 var args = slice.call(arguments, 1); 152 153 for (var i = 0, len = this.length; i < len; i++) { 154 var elem = this[i]; 155 var instance = $.data(elem, namespace); 156 if (!instance) { 157 logError("cannot call methods on " + namespace + " prior to initialization; " + "attempted to call '" + options + "'"); 158 continue; 159 } 160 if (!$.isFunction(instance[options]) || options.charAt(0) === '_') { 161 logError("no such method '" + options + "' for " + namespace + " instance"); 162 continue; 163 } 164 165 // trigger method with arguments 166 var returnValue = instance[options].apply(instance, args); 167 168 // break look and return first value if provided 169 if (returnValue !== undefined && returnValue !== instance) { 170 return returnValue; 171 } 172 } 173 // return this if no return value 174 return this; 175 } else { 176 var objects = this.map(function () { 177 var instance = $.data(this, namespace); 178 if (instance) { 179 // apply options & init 180 instance.option(options); 181 instance._init(); 182 } else { 183 // initialize new instance 184 instance = new PluginClass(this, options); 185 $.data(this, namespace, instance); 186 } 187 return $(this); 188 }); 189 190 if (!objects || objects.length > 1) { 191 return objects; 192 } else { 193 return objects[0]; 194 } 195 } 196 }; 197 } 198 199 // -------------------------- bridget -------------------------- // 200 201 /** 202 * converts a Prototypical class into a proper jQuery plugin 203 * the class must have a ._init method 204 * @param {String} namespace - plugin name, used in $().pluginName 205 * @param {Function} PluginClass - constructor class 206 */ 207 $.bridget = function (namespace, PluginClass) { 208 addOptionMethod(PluginClass); 209 bridge(namespace, PluginClass); 210 }; 211 212 return $.bridget; 213 } 214 215 // get jquery from browser global 216 defineBridget($); 217 })($); 218 219 /************************************************* 220 BOOTSTRAP-SLIDER SOURCE CODE 221 **************************************************/ 222 223 (function ($) { 224 225 var ErrorMsgs = { 226 formatInvalidInputErrorMsg: function formatInvalidInputErrorMsg(input) { 227 return "Invalid input value '" + input + "' passed in"; 228 }, 229 callingContextNotSliderInstance: "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method" 230 }; 231 232 var SliderScale = { 233 linear: { 234 toValue: function toValue(percentage) { 235 var rawValue = percentage / 100 * (this.options.max - this.options.min); 236 var shouldAdjustWithBase = true; 237 if (this.options.ticks_positions.length > 0) { 238 var minv, 239 maxv, 240 minp, 241 maxp = 0; 242 for (var i = 1; i < this.options.ticks_positions.length; i++) { 243 if (percentage <= this.options.ticks_positions[i]) { 244 minv = this.options.ticks[i - 1]; 245 minp = this.options.ticks_positions[i - 1]; 246 maxv = this.options.ticks[i]; 247 maxp = this.options.ticks_positions[i]; 248 249 break; 250 } 251 } 252 var partialPercentage = (percentage - minp) / (maxp - minp); 253 rawValue = minv + partialPercentage * (maxv - minv); 254 shouldAdjustWithBase = false;
255 } 256 257 var adjustment = shouldAdjustWithBase ? this.options.min : 0; 258 var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step; 259 if (value < this.options.min) { 260 return this.options.min; 261 } else if (value > this.options.max) { 262 return this.options.max; 263 } else { 264 return value; 265 } 266 }, 267 toPercentage: function toPercentage(value) { 268 if (this.options.max === this.options.min) { 269 return 0; 270 } 271 272 if (this.options.ticks_positions.length > 0) { 273 var minv, 274 maxv, 275 minp, 276 maxp = 0; 277 for (var i = 0; i < this.options.ticks.length; i++) { 278 if (value <= this.options.ticks[i]) { 279 minv = i > 0 ? this.options.ticks[i - 1] : 0; 280 minp = i > 0 ? this.options.ticks_positions[i - 1] : 0; 281 maxv = this.options.ticks[i]; 282 maxp = this.options.ticks_positions[i]; 283 284 break; 285 } 286 } 287 if (i > 0) { 288 var partialPercentage = (value - minv) / (maxv - minv); 289 return minp + partialPercentage * (maxp - minp); 290 } 291 } 292 293 return 100 * (value - this.options.min) / (this.options.max - this.options.min); 294 } 295 }, 296 297 logarithmic: { 298 /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */ 299 toValue: function toValue(percentage) { 300 var min = this.options.min === 0 ? 0 : Math.log(this.options.min); 301 var max = Math.log(this.options.max); 302 var value = Math.exp(min + (max - min) * percentage / 100); 303 if (Math.round(value) === this.options.max) { 304 return this.options.max; 305 } 306 value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step; 307 /* Rounding to the nearest step could exceed the min or 308 * max, so clip to those values. */ 309 if (value < this.options.min) { 310 return this.options.min; 311 } else if (value > this.options.max) { 312 return this.options.max; 313 } else { 314 return value; 315 } 316 }, 317 toPercentage: function toPercentage(value) { 318 if (this.options.max === this.options.min) { 319 return 0; 320 } else { 321 var max = Math.log(this.options.max); 322 var min = this.options.min === 0 ? 0 : Math.log(this.options.min); 323 var v = value === 0 ? 0 : Math.log(value); 324 return 100 * (v - min) / (max - min); 325 } 326 } 327 } 328 }; 329 330 /************************************************* 331 CONSTRUCTOR 332 **************************************************/ 333 Slider = function Slider(element, options) { 334 createNewSlider.call(this, element, options); 335 return this; 336 }; 337 338 function createNewSlider(element, options) { 339 340 /* 341 The internal state object is used to store data about the current 'state' of slider. 342 This includes values such as the `value`, `enabled`, etc... 343 */ 344 this._state = { 345 value: null, 346 enabled: null, 347 offset: null, 348 size: null, 349 percentage: null, 350 inDrag: false, 351 over: false 352 }; 353 354 // The objects used to store the reference to the tick methods if ticks_tooltip is on 355 this.ticksCallbackMap = {}; 356 this.handleCallbackMap = {}; 357 358 if (typeof element === "string") { 359 this.element = document.querySelector(element); 360 } else if (element instanceof HTMLElement) { 361 this.element = element; 362 } 363 364 /************************************************* 365 Process Options 366 **************************************************/ 367 options = options ? options : {}; 368 var optionTypes = Object.keys(this.defaultOptions); 369 370 for (var i = 0; i < optionTypes.length; i++) { 371 var optName = optionTypes[i]; 372 373 // First check if an option was passed in via the constructor 374 var val = options[optName]; 375 // If no data attrib, then check data atrributes 376 val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName); 377 // Finally, if nothing was specified, use the defaults 378 val = val !== null ? val : this.defaultOptions[optName]; 379 380 // Set all options on the instance of the Slider 381 if (!this.options) { 382 this.options = {}; 383 } 384 this.options[optName] = val; 385 } 386 387 // Check options.rtl 388 if (this.options.rtl === 'auto') { 389 this.options.rtl = window.getComputedStyle(this.element).direction === 'rtl'; 390 } 391 392 /* 393 Validate `tooltip_position` against 'orientation` 394 - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation` 395 -- default for "vertical" -> "right", "left" if rtl 396 -- default for "horizontal" -> "top" 397 */ 398 if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) { 399 if (this.options.rtl) { 400 this.options.tooltip_position = "left"; 401 } else { 402 this.options.tooltip_position = "right"; 403 } 404 } else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) { 405 406 this.options.tooltip_position = "top"; 407 } 408 409 function getDataAttrib(element, optName) {
vendor: 15,714 bytes, lines 410-738
410 var dataName = "data-slider-" + optName.replace(/_/g, '-'); 411 var dataValString = element.getAttribute(dataName); 412 413 try { 414 return JSON.parse(dataValString); 415 } catch (err) { 416 return dataValString; 417 } 418 } 419 420 /************************************************* 421 Create Markup 422 **************************************************/ 423 424 var origWidth = this.element.style.width; 425 var updateSlider = false; 426 var parent = this.element.parentNode; 427 var sliderTrackSelection; 428 var sliderTrackLow, sliderTrackHigh; 429 var sliderMinHandle; 430 var sliderMaxHandle; 431 432 if (this.sliderElem) { 433 updateSlider = true; 434 } else { 435 /* Create elements needed for slider */ 436 this.sliderElem = document.createElement("div"); 437 this.sliderElem.className = "slider"; 438 439 /* Create slider track elements */ 440 var sliderTrack = document.createElement("div"); 441 sliderTrack.className = "slider-track"; 442 443 sliderTrackLow = document.createElement("div"); 444 sliderTrackLow.className = "slider-track-low"; 445 446 sliderTrackSelection = document.createElement("div"); 447 sliderTrackSelection.className = "slider-selection"; 448 449 sliderTrackHigh = document.createElement("div"); 450 sliderTrackHigh.className = "slider-track-high"; 451 452 sliderMinHandle = document.createElement("div"); 453 sliderMinHandle.className = "slider-handle min-slider-handle"; 454 sliderMinHandle.setAttribute('role', 'slider'); 455 sliderMinHandle.setAttribute('aria-valuemin', this.options.min); 456 sliderMinHandle.setAttribute('aria-valuemax', this.options.max); 457 458 sliderMaxHandle = document.createElement("div"); 459 sliderMaxHandle.className = "slider-handle max-slider-handle"; 460 sliderMaxHandle.setAttribute('role', 'slider'); 461 sliderMaxHandle.setAttribute('aria-valuemin', this.options.min); 462 sliderMaxHandle.setAttribute('aria-valuemax', this.options.max); 463 464 sliderTrack.appendChild(sliderTrackLow); 465 sliderTrack.appendChild(sliderTrackSelection); 466 sliderTrack.appendChild(sliderTrackHigh); 467 468 /* Create highlight range elements */ 469 this.rangeHighlightElements = []; 470 var rangeHighlightsOpts = this.options.rangeHighlights; 471 if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) { 472 for (var j = 0; j < rangeHighlightsOpts.length; j++) { 473 var rangeHighlightElement = document.createElement("div"); 474 var customClassString = rangeHighlightsOpts[j].class || ""; 475 rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + customClassString; 476 this.rangeHighlightElements.push(rangeHighlightElement); 477 sliderTrack.appendChild(rangeHighlightElement); 478 } 479 } 480 481 /* Add aria-labelledby to handle's */ 482 var isLabelledbyArray = Array.isArray(this.options.labelledby); 483 if (isLabelledbyArray && this.options.labelledby[0]) { 484 sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]); 485 } 486 if (isLabelledbyArray && this.options.labelledby[1]) { 487 sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]); 488 } 489 if (!isLabelledbyArray && this.options.labelledby) { 490 sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby); 491 sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby); 492 } 493 494 /* Create ticks */ 495 this.ticks = []; 496 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { 497 this.ticksContainer = document.createElement('div'); 498 this.ticksContainer.className = 'slider-tick-container'; 499 500 for (i = 0; i < this.options.ticks.length; i++) { 501 var tick = document.createElement('div'); 502 tick.className = 'slider-tick'; 503 if (this.options.ticks_tooltip) { 504 var tickListenerReference = this._addTickListener(); 505 var enterCallback = tickListenerReference.addMouseEnter(this, tick, i); 506 var leaveCallback = tickListenerReference.addMouseLeave(this, tick); 507 508 this.ticksCallbackMap[i] = { 509 mouseEnter: enterCallback, 510 mouseLeave: leaveCallback 511 }; 512 } 513 this.ticks.push(tick); 514 this.ticksContainer.appendChild(tick); 515 } 516 517 sliderTrackSelection.className += " tick-slider-selection"; 518 } 519 520 this.tickLabels = []; 521 if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) { 522 this.tickLabelContainer = document.createElement('div'); 523 this.tickLabelContainer.className = 'slider-tick-label-container'; 524 525 for (i = 0; i < this.options.ticks_labels.length; i++) { 526 var label = document.createElement('div'); 527 var noTickPositionsSpecified = this.options.ticks_positions.length === 0; 528 var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i; 529 label.className = 'slider-tick-label'; 530 label.innerHTML = this.options.ticks_labels[tickLabelsIndex]; 531 532 this.tickLabels.push(label); 533 this.tickLabelContainer.appendChild(label); 534 } 535 } 536 537 var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) { 538 var arrow = document.createElement("div"); 539 arrow.className = "tooltip-arrow"; 540 541 var inner = document.createElement("div"); 542 inner.className = "tooltip-inner"; 543 544 tooltipElem.appendChild(arrow); 545 tooltipElem.appendChild(inner); 546 }; 547 548 /* Create tooltip elements */ 549 var sliderTooltip = document.createElement("div"); 550 sliderTooltip.className = "tooltip tooltip-main"; 551 sliderTooltip.setAttribute('role', 'presentation'); 552 createAndAppendTooltipSubElements(sliderTooltip); 553 554 var sliderTooltipMin = document.createElement("div"); 555 sliderTooltipMin.className = "tooltip tooltip-min"; 556 sliderTooltipMin.setAttribute('role', 'presentation'); 557 createAndAppendTooltipSubElements(sliderTooltipMin); 558 559 var sliderTooltipMax = document.createElement("div"); 560 sliderTooltipMax.className = "tooltip tooltip-max"; 561 sliderTooltipMax.setAttribute('role', 'presentation'); 562 createAndAppendTooltipSubElements(sliderTooltipMax); 563 564 /* Append components to sliderElem */ 565 this.sliderElem.appendChild(sliderTrack); 566 this.sliderElem.appendChild(sliderTooltip); 567 this.sliderElem.appendChild(sliderTooltipMin); 568 this.sliderElem.appendChild(sliderTooltipMax); 569 570 if (this.tickLabelContainer) { 571 this.sliderElem.appendChild(this.tickLabelContainer); 572 } 573 if (this.ticksContainer) { 574 this.sliderElem.appendChild(this.ticksContainer); 575 } 576 577 this.sliderElem.appendChild(sliderMinHandle); 578 this.sliderElem.appendChild(sliderMaxHandle); 579 580 /* Append slider element to parent container, right before the original <input> element */ 581 parent.insertBefore(this.sliderElem, this.element); 582 583 /* Hide original <input> element */ 584 this.element.style.display = "none"; 585 } 586 /* If JQuery exists, cache JQ references */ 587 if ($) { 588 this.$element = $(this.element); 589 this.$sliderElem = $(this.sliderElem); 590 } 591 592 /************************************************* 593 Setup 594 **************************************************/ 595 this.eventToCallbackMap = {}; 596 this.sliderElem.id = this.options.id; 597 598 this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch; 599 600 this.touchX = 0; 601 this.touchY = 0; 602 603 this.tooltip = this.sliderElem.querySelector('.tooltip-main'); 604 this.tooltipInner = this.tooltip.querySelector('.tooltip-inner'); 605 606 this.tooltip_min = this.sliderElem.querySelector('.tooltip-min'); 607 this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner'); 608 609 this.tooltip_max = this.sliderElem.querySelector('.tooltip-max'); 610 this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner'); 611 612 if (SliderScale[this.options.scale]) { 613 this.options.scale = SliderScale[this.options.scale]; 614 } 615 616 if (updateSlider === true) { 617 // Reset classes 618 this._removeClass(this.sliderElem, 'slider-horizontal'); 619 this._removeClass(this.sliderElem, 'slider-vertical'); 620 this._removeClass(this.sliderElem, 'slider-rtl'); 621 this._removeClass(this.tooltip, 'hide'); 622 this._removeClass(this.tooltip_min, 'hide'); 623 this._removeClass(this.tooltip_max, 'hide'); 624 625 // Undo existing inline styles for track 626 ["left", "right", "top", "width", "height"].forEach(function (prop) { 627 this._removeProperty(this.trackLow, prop); 628 this._removeProperty(this.trackSelection, prop); 629 this._removeProperty(this.trackHigh, prop); 630 }, this); 631 632 // Undo inline styles on handles 633 [this.handle1, this.handle2].forEach(function (handle) { 634 this._removeProperty(handle, 'left'); 635 this._removeProperty(handle, 'right'); 636 this._removeProperty(handle, 'top'); 637 }, this); 638 639 // Undo inline styles and classes on tooltips 640 [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) { 641 this._removeProperty(tooltip, 'left'); 642 this._removeProperty(tooltip, 'right'); 643 this._removeProperty(tooltip, 'top'); 644 this._removeProperty(tooltip, 'margin-left'); 645 this._removeProperty(tooltip, 'margin-right'); 646 this._removeProperty(tooltip, 'margin-top'); 647 648 this._removeClass(tooltip, 'right'); 649 this._removeClass(tooltip, 'left'); 650 this._removeClass(tooltip, 'top'); 651 }, this); 652 } 653 654 if (this.options.orientation === 'vertical') { 655 this._addClass(this.sliderElem, 'slider-vertical'); 656 this.stylePos = 'top'; 657 this.mousePos = 'pageY'; 658 this.sizePos = 'offsetHeight'; 659 } else { 660 this._addClass(this.sliderElem, 'slider-horizontal'); 661 this.sliderElem.style.width = origWidth; 662 this.options.orientation = 'horizontal'; 663 if (this.options.rtl) { 664 this.stylePos = 'right'; 665 } else { 666 this.stylePos = 'left'; 667 } 668 this.mousePos = 'pageX'; 669 this.sizePos = 'offsetWidth'; 670 } 671 // specific rtl class 672 if (this.options.rtl) { 673 this._addClass(this.sliderElem, 'slider-rtl'); 674 } 675 this._setTooltipPosition(); 676 /* In case ticks are specified, overwrite the min and max bounds */ 677 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { 678 this.options.max = Math.max.apply(Math, this.options.ticks); 679 this.options.min = Math.min.apply(Math, this.options.ticks); 680 } 681 682 if (Array.isArray(this.options.value)) { 683 this.options.range = true; 684 this._state.value = this.options.value; 685 } else if (this.options.range) { 686 // User wants a range, but value is not an array 687 this._state.value = [this.options.value, this.options.max]; 688 } else { 689 this._state.value = this.options.value; 690 } 691 692 this.trackLow = sliderTrackLow || this.trackLow; 693 this.trackSelection = sliderTrackSelection || this.trackSelection; 694 this.trackHigh = sliderTrackHigh || this.trackHigh; 695 696 if (this.options.selection === 'none') { 697 this._addClass(this.trackLow, 'hide'); 698 this._addClass(this.trackSelection, 'hide'); 699 this._addClass(this.trackHigh, 'hide'); 700 } else if (this.options.selection === 'after' || this.options.selection === 'before') { 701 this._removeClass(this.trackLow, 'hide'); 702 this._removeClass(this.trackSelection, 'hide'); 703 this._removeClass(this.trackHigh, 'hide'); 704 } 705 706 this.handle1 = sliderMinHandle || this.handle1; 707 this.handle2 = sliderMaxHandle || this.handle2; 708 709 if (updateSlider === true) { 710 // Reset classes 711 this._removeClass(this.handle1, 'round triangle'); 712 this._removeClass(this.handle2, 'round triangle hide'); 713 714 for (i = 0; i < this.ticks.length; i++) { 715 this._removeClass(this.ticks[i], 'round triangle hide'); 716 } 717 } 718 719 var availableHandleModifiers = ['round', 'triangle', 'custom']; 720 var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1; 721 if (isValidHandleType) { 722 this._addClass(this.handle1, this.options.handle); 723 this._addClass(this.handle2, this.options.handle); 724 725 for (i = 0; i < this.ticks.length; i++) { 726 this._addClass(this.ticks[i], this.options.handle); 727 } 728 } 729 730 this._state.offset = this._offset(this.sliderElem); 731 this._state.size = this.sliderElem[this.sizePos]; 732 this.setValue(this._state.value); 733 734 /****************************************** 735 Bind Event Listeners 736 ******************************************/ 737 738 // Bind keyboard handlers
739 this.handle1Keydown = this._keydown.bind(this, 0); 740 this.handle1.addEventListener("keydown", this.handle1Keydown, false); 741 742 this.handle2Keydown = this._keydown.bind(this, 1); 743 this.handle2.addEventListener("keydown", this.handle2Keydown, false); 744 745 this.mousedown = this._mousedown.bind(this); 746 this.touchstart = this._touchstart.bind(this); 747 this.touchmove = this._touchmove.bind(this); 748 749 if (this.touchCapable) { 750 // Test for passive event support 751 var supportsPassive = false; 752 try { 753 var opts = Object.defineProperty({}, 'passive', { 754 get: function get() { 755 supportsPassive = true; 756 } 757 }); 758 window.addEventListener("test", null, opts); 759 } catch (e) { 760 } 761 // Use our detect's results. passive applied if supported, capture will be false either way. 762 var eventOptions = supportsPassive ? {passive: true} : false; 763 // Bind touch handlers 764 this.sliderElem.addEventListener("touchstart", this.touchstart, eventOptions); 765 this.sliderElem.addEventListener("touchmove", this.touchmove, eventOptions); 766 } 767 this.sliderElem.addEventListener("mousedown", this.mousedown, false); 768 769 // Bind window handlers 770 this.resize = this._resize.bind(this); 771 window.addEventListener("resize", this.resize, false); 772 773 // Bind tooltip-related handlers 774 if (this.options.tooltip === 'hide') { 775 this._addClass(this.tooltip, 'hide'); 776 this._addClass(this.tooltip_min, 'hide'); 777 this._addClass(this.tooltip_max, 'hide'); 778 } else if (this.options.tooltip === 'always') { 779 this._showTooltip(); 780 this._alwaysShowTooltip = true; 781 } else { 782 this.showTooltip = this._showTooltip.bind(this); 783 this.hideTooltip = this._hideTooltip.bind(this); 784 785 if (this.options.ticks_tooltip) { 786 var callbackHandle = this._addTickListener(); 787 //create handle1 listeners and store references in map 788 var mouseEnter = callbackHandle.addMouseEnter(this, this.handle1); 789 var mouseLeave = callbackHandle.addMouseLeave(this, this.handle1); 790 this.handleCallbackMap.handle1 = { 791 mouseEnter: mouseEnter, 792 mouseLeave: mouseLeave 793 }; 794 //create handle2 listeners and store references in map 795 mouseEnter = callbackHandle.addMouseEnter(this, this.handle2); 796 mouseLeave = callbackHandle.addMouseLeave(this, this.handle2); 797 this.handleCallbackMap.handle2 = { 798 mouseEnter: mouseEnter, 799 mouseLeave: mouseLeave 800 }; 801 } else { 802 this.sliderElem.addEventListener("mouseenter", this.showTooltip, false); 803 this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false); 804 } 805 806 this.handle1.addEventListener("focus", this.showTooltip, false); 807 this.handle1.addEventListener("blur", this.hideTooltip, false); 808 809 this.handle2.addEventListener("focus", this.showTooltip, false); 810 this.handle2.addEventListener("blur", this.hideTooltip, false); 811 } 812 813 if (this.options.enabled) { 814 this.enable(); 815 } else { 816 this.disable(); 817 } 818 } 819 820 /************************************************* 821 INSTANCE PROPERTIES/METHODS 822 - Any methods bound to the prototype are considered 823 part of the plugin's `public` interface 824 **************************************************/ 825 Slider.prototype = { 826 _init: function _init() {}
vendor: 32,727 bytes, lines 826-1507
826, // NOTE: Must exist to support bridget 827 828 constructor: Slider, 829 830 defaultOptions: { 831 id: "", 832 min: 0, 833 max: 10, 834 step: 1, 835 precision: 0, 836 orientation: 'horizontal', 837 value: 5, 838 range: false, 839 selection: 'before', 840 tooltip: 'show', 841 tooltip_split: false, 842 handle: 'round', 843 reversed: false, 844 rtl: 'auto', 845 enabled: true, 846 formatter: function formatter(val) { 847 if (Array.isArray(val)) { 848 return val[0] + " : " + val[1]; 849 } else { 850 return val; 851 } 852 }, 853 natural_arrow_keys: false, 854 ticks: [], 855 ticks_positions: [], 856 ticks_labels: [], 857 ticks_snap_bounds: 0, 858 ticks_tooltip: false, 859 scale: 'linear', 860 focus: false, 861 tooltip_position: null, 862 labelledby: null, 863 rangeHighlights: [] 864 }, 865 866 getElement: function getElement() { 867 return this.sliderElem; 868 }, 869 870 getValue: function getValue() { 871 if (this.options.range) { 872 return this._state.value; 873 } else { 874 return this._state.value[0]; 875 } 876 }, 877 878 setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) { 879 if (!val) { 880 val = 0; 881 } 882 var oldValue = this.getValue(); 883 this._state.value = this._validateInputValue(val); 884 var applyPrecision = this._applyPrecision.bind(this); 885 886 if (this.options.range) { 887 this._state.value[0] = applyPrecision(this._state.value[0]); 888 this._state.value[1] = applyPrecision(this._state.value[1]); 889 890 this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0])); 891 this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1])); 892 } else { 893 this._state.value = applyPrecision(this._state.value); 894 this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))]; 895 this._addClass(this.handle2, 'hide'); 896 if (this.options.selection === 'after') { 897 this._state.value[1] = this.options.max; 898 } else { 899 this._state.value[1] = this.options.min; 900 } 901 } 902 903 if (this.options.max > this.options.min) { 904 this._state.percentage = [this._toPercentage(this._state.value[0]), this._toPercentage(this._state.value[1]), this.options.step * 100 / (this.options.max - this.options.min)]; 905 } else { 906 this._state.percentage = [0, 0, 100]; 907 } 908 909 this._layout(); 910 var newValue = this.options.range ? this._state.value : this._state.value[0]; 911 912 this._setDataVal(newValue); 913 if (triggerSlideEvent === true) { 914 this._trigger('slide', newValue); 915 } 916 if (oldValue !== newValue && triggerChangeEvent === true) { 917 this._trigger('change', { 918 oldValue: oldValue, 919 newValue: newValue 920 }); 921 } 922 923 return this; 924 }, 925 926 destroy: function destroy() { 927 // Remove event handlers on slider elements 928 this._removeSliderEventHandlers(); 929 930 // Remove the slider from the DOM 931 this.sliderElem.parentNode.removeChild(this.sliderElem); 932 /* Show original <input> element */ 933 this.element.style.display = ""; 934 935 // Clear out custom event bindings 936 this._cleanUpEventCallbacksMap(); 937 938 // Remove data values 939 this.element.removeAttribute("data"); 940 941 // Remove JQuery handlers/data 942 if ($) { 943 this._unbindJQueryEventHandlers(); 944 this.$element.removeData('slider'); 945 } 946 }, 947 948 disable: function disable() { 949 this._state.enabled = false; 950 this.handle1.removeAttribute("tabindex"); 951 this.handle2.removeAttribute("tabindex"); 952 this._addClass(this.sliderElem, 'slider-disabled'); 953 this._trigger('slideDisabled'); 954 955 return this; 956 }, 957 958 enable: function enable() { 959 this._state.enabled = true; 960 this.handle1.setAttribute("tabindex", 0); 961 this.handle2.setAttribute("tabindex", 0); 962 this._removeClass(this.sliderElem, 'slider-disabled'); 963 this._trigger('slideEnabled'); 964 965 return this; 966 }, 967 968 toggle: function toggle() { 969 if (this._state.enabled) { 970 this.disable(); 971 } else { 972 this.enable(); 973 } 974 return this; 975 }, 976 977 isEnabled: function isEnabled() { 978 return this._state.enabled; 979 }, 980 981 on: function on(evt, callback) { 982 this._bindNonQueryEventHandler(evt, callback); 983 return this; 984 }, 985 986 off: function off(evt, callback) { 987 if ($) { 988 this.$element.off(evt, callback); 989 this.$sliderElem.off(evt, callback); 990 } else { 991 this._unbindNonQueryEventHandler(evt, callback); 992 } 993 }, 994 995 getAttribute: function getAttribute(attribute) { 996 if (attribute) { 997 return this.options[attribute]; 998 } else { 999 return this.options; 1000 } 1001 }, 1002 1003 setAttribute: function setAttribute(attribute, value) { 1004 this.options[attribute] = value; 1005 return this; 1006 }, 1007 1008 refresh: function refresh() { 1009 this._removeSliderEventHandlers(); 1010 createNewSlider.call(this, this.element, this.options); 1011 if ($) { 1012 // Bind new instance of slider to the element 1013 $.data(this.element, 'slider', this); 1014 } 1015 return this; 1016 }, 1017 1018 relayout: function relayout() { 1019 this._resize(); 1020 this._layout(); 1021 return this; 1022 }, 1023 1024 /******************************+ 1025 HELPERS 1026 - Any method that is not part of the public interface. 1027 - Place it underneath this comment block and write its signature like so: 1028 _fnName : function() {...} 1029 ********************************/ 1030 _removeSliderEventHandlers: function _removeSliderEventHandlers() { 1031 // Remove keydown event listeners 1032 this.handle1.removeEventListener("keydown", this.handle1Keydown, false); 1033 this.handle2.removeEventListener("keydown", this.handle2Keydown, false); 1034 1035 //remove the listeners from the ticks and handles if they had their own listeners 1036 if (this.options.ticks_tooltip) { 1037 var ticks = this.ticksContainer.getElementsByClassName('slider-tick'); 1038 for (var i = 0; i < ticks.length; i++) { 1039 ticks[i].removeEventListener('mouseenter', this.ticksCallbackMap[i].mouseEnter, false); 1040 ticks[i].removeEventListener('mouseleave', this.ticksCallbackMap[i].mouseLeave, false); 1041 } 1042 this.handle1.removeEventListener('mouseenter', this.handleCallbackMap.handle1.mouseEnter, false); 1043 this.handle2.removeEventListener('mouseenter', this.handleCallbackMap.handle2.mouseEnter, false); 1044 this.handle1.removeEventListener('mouseleave', this.handleCallbackMap.handle1.mouseLeave, false); 1045 this.handle2.removeEventListener('mouseleave', this.handleCallbackMap.handle2.mouseLeave, false); 1046 } 1047 1048 this.handleCallbackMap = null; 1049 this.ticksCallbackMap = null; 1050 1051 if (this.showTooltip) { 1052 this.handle1.removeEventListener("focus", this.showTooltip, false); 1053 this.handle2.removeEventListener("focus", this.showTooltip, false); 1054 } 1055 if (this.hideTooltip) { 1056 this.handle1.removeEventListener("blur", this.hideTooltip, false); 1057 this.handle2.removeEventListener("blur", this.hideTooltip, false); 1058 } 1059 1060 // Remove event listeners from sliderElem 1061 if (this.showTooltip) { 1062 this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false); 1063 } 1064 if (this.hideTooltip) { 1065 this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false); 1066 } 1067 this.sliderElem.removeEventListener("touchstart", this.touchstart, false); 1068 this.sliderElem.removeEventListener("touchmove", this.touchmove, false); 1069 this.sliderElem.removeEventListener("mousedown", this.mousedown, false); 1070 1071 // Remove window event listener 1072 window.removeEventListener("resize", this.resize, false); 1073 }, 1074 _bindNonQueryEventHandler: function _bindNonQueryEventHandler(evt, callback) { 1075 if (this.eventToCallbackMap[evt] === undefined) { 1076 this.eventToCallbackMap[evt] = []; 1077 } 1078 this.eventToCallbackMap[evt].push(callback); 1079 }, 1080 _unbindNonQueryEventHandler: function _unbindNonQueryEventHandler(evt, callback) { 1081 var callbacks = this.eventToCallbackMap[evt]; 1082 if (callbacks !== undefined) { 1083 for (var i = 0; i < callbacks.length; i++) { 1084 if (callbacks[i] === callback) { 1085 callbacks.splice(i, 1); 1086 break; 1087 } 1088 } 1089 } 1090 }, 1091 _cleanUpEventCallbacksMap: function _cleanUpEventCallbacksMap() { 1092 var eventNames = Object.keys(this.eventToCallbackMap); 1093 for (var i = 0; i < eventNames.length; i++) { 1094 var eventName = eventNames[i]; 1095 delete this.eventToCallbackMap[eventName]; 1096 } 1097 }, 1098 _showTooltip: function _showTooltip() { 1099 if (this.options.tooltip_split === false) { 1100 this._addClass(this.tooltip, 'in'); 1101 this.tooltip_min.style.display = 'none'; 1102 this.tooltip_max.style.display = 'none'; 1103 } else { 1104 this._addClass(this.tooltip_min, 'in'); 1105 this._addClass(this.tooltip_max, 'in'); 1106 this.tooltip.style.display = 'none'; 1107 } 1108 this._state.over = true; 1109 }, 1110 _hideTooltip: function _hideTooltip() { 1111 if (this._state.inDrag === false && this.alwaysShowTooltip !== true) { 1112 this._removeClass(this.tooltip, 'in'); 1113 this._removeClass(this.tooltip_min, 'in'); 1114 this._removeClass(this.tooltip_max, 'in'); 1115 } 1116 this._state.over = false; 1117 }, 1118 _setToolTipOnMouseOver: function _setToolTipOnMouseOver(tempState) { 1119 var formattedTooltipVal = this.options.formatter(!tempState ? this._state.value[0] : tempState.value[0]); 1120 var positionPercentages = !tempState ? getPositionPercentages(this._state, this.options.reversed) : getPositionPercentages(tempState, this.options.reversed); 1121 this._setText(this.tooltipInner, formattedTooltipVal); 1122 1123 this.tooltip.style[this.stylePos] = positionPercentages[0] + "%"; 1124 if (this.options.orientation === 'vertical') { 1125 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetHeight / 2 + "px"); 1126 } else { 1127 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetWidth / 2 + "px"); 1128 } 1129 1130 function getPositionPercentages(state, reversed) { 1131 if (reversed) { 1132 return [100 - state.percentage[0], this.options.range ? 100 - state.percentage[1] : state.percentage[1]]; 1133 } 1134 return [state.percentage[0], state.percentage[1]]; 1135 } 1136 }, 1137 _addTickListener: function _addTickListener() { 1138 return { 1139 addMouseEnter: function addMouseEnter(reference, tick, index) { 1140 var enter = function enter() { 1141 var tempState = reference._state; 1142 var idString = index >= 0 ? index : this.attributes['aria-valuenow'].value; 1143 var hoverIndex = parseInt(idString, 10); 1144 tempState.value[0] = hoverIndex; 1145 tempState.percentage[0] = reference.options.ticks_positions[hoverIndex]; 1146 reference._setToolTipOnMouseOver(tempState); 1147 reference._showTooltip(); 1148 }; 1149 tick.addEventListener("mouseenter", enter, false); 1150 return enter; 1151 }, 1152 addMouseLeave: function addMouseLeave(reference, tick) { 1153 var leave = function leave() { 1154 reference._hideTooltip(); 1155 }; 1156 tick.addEventListener("mouseleave", leave, false); 1157 return leave; 1158 } 1159 }; 1160 }, 1161 _layout: function _layout() { 1162 var positionPercentages; 1163 1164 if (this.options.reversed) { 1165 positionPercentages = [100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]]; 1166 } else { 1167 positionPercentages = [this._state.percentage[0], this._state.percentage[1]]; 1168 } 1169 1170 this.handle1.style[this.stylePos] = positionPercentages[0] + "%"; 1171 this.handle1.setAttribute('aria-valuenow', this._state.value[0]); 1172 if (isNaN(this.options.formatter(this._state.value[0]))) { 1173 this.handle1.setAttribute('aria-valuetext', this.options.formatter(this._state.value[0])); 1174 } 1175 1176 this.handle2.style[this.stylePos] = positionPercentages[1] + "%"; 1177 this.handle2.setAttribute('aria-valuenow', this._state.value[1]); 1178 if (isNaN(this.options.formatter(this._state.value[1]))) { 1179 this.handle2.setAttribute('aria-valuetext', this.options.formatter(this._state.value[1])); 1180 } 1181 1182 /* Position highlight range elements */ 1183 if (this.rangeHighlightElements.length > 0 && Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) { 1184 for (var _i = 0; _i < this.options.rangeHighlights.length; _i++) { 1185 var startPercent = this._toPercentage(this.options.rangeHighlights[_i].start); 1186 var endPercent = this._toPercentage(this.options.rangeHighlights[_i].end); 1187 1188 if (this.options.reversed) { 1189 var sp = 100 - endPercent; 1190 endPercent = 100 - startPercent; 1191 startPercent = sp; 1192 } 1193 1194 var currentRange = this._createHighlightRange(startPercent, endPercent); 1195 1196 if (currentRange) { 1197 if (this.options.orientation === 'vertical') { 1198 this.rangeHighlightElements[_i].style.top = currentRange.start + "%"; 1199 this.rangeHighlightElements[_i].style.height = currentRange.size + "%"; 1200 } else { 1201 if (this.options.rtl) { 1202 this.rangeHighlightElements[_i].style.right = currentRange.start + "%"; 1203 } else { 1204 this.rangeHighlightElements[_i].style.left = currentRange.start + "%"; 1205 } 1206 this.rangeHighlightElements[_i].style.width = currentRange.size + "%"; 1207 } 1208 } else { 1209 this.rangeHighlightElements[_i].style.display = "none"; 1210 } 1211 } 1212 } 1213 1214 /* Position ticks and labels */ 1215 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { 1216 1217 var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width'; 1218 var styleMargin; 1219 if (this.options.orientation === 'vertical') { 1220 styleMargin = 'marginTop'; 1221 } else { 1222 if (this.options.rtl) { 1223 styleMargin = 'marginRight'; 1224 } else { 1225 styleMargin = 'marginLeft'; 1226 } 1227 } 1228 var labelSize = this._state.size / (this.options.ticks.length - 1); 1229 1230 if (this.tickLabelContainer) { 1231 var extraMargin = 0; 1232 if (this.options.ticks_positions.length === 0) { 1233 if (this.options.orientation !== 'vertical') { 1234 this.tickLabelContainer.style[styleMargin] = -labelSize / 2 + "px"; 1235 } 1236 1237 extraMargin = this.tickLabelContainer.offsetHeight; 1238 } else { 1239 /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */ 1240 for (i = 0; i < this.tickLabelContainer.childNodes.length; i++) { 1241 if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) { 1242 extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight; 1243 } 1244 } 1245 } 1246 if (this.options.orientation === 'horizontal') { 1247 this.sliderElem.style.marginBottom = extraMargin + "px"; 1248 } 1249 } 1250 for (var i = 0; i < this.options.ticks.length; i++) { 1251 1252 var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]); 1253 1254 if (this.options.reversed) { 1255 percentage = 100 - percentage; 1256 } 1257 1258 this.ticks[i].style[this.stylePos] = percentage + "%"; 1259 1260 /* Set class labels to denote whether ticks are in the selection */ 1261 this._removeClass(this.ticks[i], 'in-selection'); 1262 if (!this.options.range) { 1263 if (this.options.selection === 'after' && percentage >= positionPercentages[0]) { 1264 this._addClass(this.ticks[i], 'in-selection'); 1265 } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) { 1266 this._addClass(this.ticks[i], 'in-selection'); 1267 } 1268 } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) { 1269 this._addClass(this.ticks[i], 'in-selection'); 1270 } 1271 1272 if (this.tickLabels[i]) { 1273 this.tickLabels[i].style[styleSize] = labelSize + "px"; 1274 1275 if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) { 1276 this.tickLabels[i].style.position = 'absolute'; 1277 this.tickLabels[i].style[this.stylePos] = percentage + "%"; 1278 this.tickLabels[i].style[styleMargin] = -labelSize / 2 + 'px'; 1279 } else if (this.options.orientation === 'vertical') { 1280 if (this.options.rtl) { 1281 this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + "px"; 1282 } else { 1283 this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + "px"; 1284 } 1285 this.tickLabelContainer.style[styleMargin] = this.sliderElem.offsetWidth / 2 * -1 + 'px'; 1286 } 1287 } 1288 } 1289 } 1290 1291 var formattedTooltipVal; 1292 1293 if (this.options.range) { 1294 formattedTooltipVal = this.options.formatter(this._state.value); 1295 this._setText(this.tooltipInner, formattedTooltipVal); 1296 this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0]) / 2 + "%"; 1297 1298 if (this.options.orientation === 'vertical') { 1299 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetHeight / 2 + "px"); 1300 } else { 1301 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetWidth / 2 + "px"); 1302 } 1303 1304 var innerTooltipMinText = this.options.formatter(this._state.value[0]); 1305 this._setText(this.tooltipInner_min, innerTooltipMinText); 1306 1307 var innerTooltipMaxText = this.options.formatter(this._state.value[1]); 1308 this._setText(this.tooltipInner_max, innerTooltipMaxText); 1309 1310 this.tooltip_min.style[this.stylePos] = positionPercentages[0] + "%"; 1311 1312 if (this.options.orientation === 'vertical') { 1313 this._css(this.tooltip_min, "margin-" + this.stylePos, -this.tooltip_min.offsetHeight / 2 + "px"); 1314 } else { 1315 this._css(this.tooltip_min, "margin-" + this.stylePos, -this.tooltip_min.offsetWidth / 2 + "px"); 1316 } 1317 1318 this.tooltip_max.style[this.stylePos] = positionPercentages[1] + "%"; 1319 1320 if (this.options.orientation === 'vertical') { 1321 this._css(this.tooltip_max, "margin-" + this.stylePos, -this.tooltip_max.offsetHeight / 2 + "px"); 1322 } else { 1323 this._css(this.tooltip_max, "margin-" + this.stylePos, -this.tooltip_max.offsetWidth / 2 + "px"); 1324 } 1325 } else { 1326 formattedTooltipVal = this.options.formatter(this._state.value[0]); 1327 this._setText(this.tooltipInner, formattedTooltipVal); 1328 1329 this.tooltip.style[this.stylePos] = positionPercentages[0] + "%"; 1330 if (this.options.orientation === 'vertical') { 1331 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetHeight / 2 + "px"); 1332 } else { 1333 this._css(this.tooltip, "margin-" + this.stylePos, -this.tooltip.offsetWidth / 2 + "px"); 1334 } 1335 } 1336 1337 if (this.options.orientation === 'vertical') { 1338 this.trackLow.style.top = '0'; 1339 this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) + '%'; 1340 1341 this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) + '%'; 1342 this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%'; 1343 1344 this.trackHigh.style.bottom = '0'; 1345 this.trackHigh.style.height = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%'; 1346 } else { 1347 if (this.stylePos === 'right') { 1348 this.trackLow.style.right = '0'; 1349 } else { 1350 this.trackLow.style.left = '0'; 1351 } 1352 this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) + '%'; 1353 1354 if (this.stylePos === 'right') { 1355 this.trackSelection.style.right = Math.min(positionPercentages[0], positionPercentages[1]) + '%'; 1356 } else { 1357 this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) + '%'; 1358 } 1359 this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%'; 1360 1361 if (this.stylePos === 'right') { 1362 this.trackHigh.style.left = '0'; 1363 } else { 1364 this.trackHigh.style.right = '0'; 1365 } 1366 this.trackHigh.style.width = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%'; 1367 1368 var offset_min = this.tooltip_min.getBoundingClientRect(); 1369 var offset_max = this.tooltip_max.getBoundingClientRect(); 1370 1371 if (this.options.tooltip_position === 'bottom') { 1372 if (offset_min.right > offset_max.left) { 1373 this._removeClass(this.tooltip_max, 'bottom'); 1374 this._addClass(this.tooltip_max, 'top'); 1375 this.tooltip_max.style.top = ''; 1376 this.tooltip_max.style.bottom = 22 + 'px'; 1377 } else { 1378 this._removeClass(this.tooltip_max, 'top'); 1379 this._addClass(this.tooltip_max, 'bottom'); 1380 this.tooltip_max.style.top = this.tooltip_min.style.top; 1381 this.tooltip_max.style.bottom = ''; 1382 } 1383 } else { 1384 if (offset_min.right > offset_max.left) { 1385 this._removeClass(this.tooltip_max, 'top'); 1386 this._addClass(this.tooltip_max, 'bottom'); 1387 this.tooltip_max.style.top = 18 + 'px'; 1388 } else { 1389 this._removeClass(this.tooltip_max, 'bottom'); 1390 this._addClass(this.tooltip_max, 'top'); 1391 this.tooltip_max.style.top = this.tooltip_min.style.top; 1392 } 1393 } 1394 } 1395 }, 1396 _createHighlightRange: function _createHighlightRange(start, end) { 1397 if (this._isHighlightRange(start, end)) { 1398 if (start > end) { 1399 return {'start': end, 'size': start - end}; 1400 } 1401 return {'start': start, 'size': end - start}; 1402 } 1403 return null; 1404 }, 1405 _isHighlightRange: function _isHighlightRange(start, end) { 1406 if (0 <= start && start <= 100 && 0 <= end && end <= 100) { 1407 return true; 1408 } else { 1409 return false; 1410 } 1411 }, 1412 _resize: function _resize(ev) { 1413 /*jshint unused:false*/ 1414 this._state.offset = this._offset(this.sliderElem); 1415 this._state.size = this.sliderElem[this.sizePos]; 1416 this._layout(); 1417 }, 1418 _removeProperty: function _removeProperty(element, prop) { 1419 if (element.style.removeProperty) { 1420 element.style.removeProperty(prop); 1421 } else { 1422 element.style.removeAttribute(prop); 1423 } 1424 }, 1425 _mousedown: function _mousedown(ev) { 1426 if (!this._state.enabled) { 1427 return false; 1428 } 1429 1430 this._state.offset = this._offset(this.sliderElem); 1431 this._state.size = this.sliderElem[this.sizePos]; 1432 1433 var percentage = this._getPercentage(ev); 1434 1435 if (this.options.range) { 1436 var diff1 = Math.abs(this._state.percentage[0] - percentage); 1437 var diff2 = Math.abs(this._state.percentage[1] - percentage); 1438 this._state.dragged = diff1 < diff2 ? 0 : 1; 1439 this._adjustPercentageForRangeSliders(percentage); 1440 } else { 1441 this._state.dragged = 0; 1442 } 1443 1444 this._state.percentage[this._state.dragged] = percentage; 1445 this._layout(); 1446 1447 if (this.touchCapable) { 1448 document.removeEventListener("touchmove", this.mousemove, false); 1449 document.removeEventListener("touchend", this.mouseup, false); 1450 } 1451 1452 if (this.mousemove) { 1453 document.removeEventListener("mousemove", this.mousemove, false); 1454 } 1455 if (this.mouseup) { 1456 document.removeEventListener("mouseup", this.mouseup, false); 1457 } 1458 1459 this.mousemove = this._mousemove.bind(this); 1460 this.mouseup = this._mouseup.bind(this); 1461 1462 if (this.touchCapable) { 1463 // Touch: Bind touch events: 1464 document.addEventListener("touchmove", this.mousemove, false); 1465 document.addEventListener("touchend", this.mouseup, false); 1466 } 1467 // Bind mouse events: 1468 document.addEventListener("mousemove", this.mousemove, false); 1469 document.addEventListener("mouseup", this.mouseup, false); 1470 1471 this._state.inDrag = true; 1472 var newValue = this._calculateValue(); 1473 1474 this._trigger('slideStart', newValue); 1475 1476 this._setDataVal(newValue); 1477 this.setValue(newValue, false, true); 1478 1479 ev.returnValue = false; 1480 1481 if (this.options.focus) { 1482 this._triggerFocusOnHandle(this._state.dragged); 1483 } 1484 1485 return true; 1486 }, 1487 _touchstart: function _touchstart(ev) { 1488 if (ev.changedTouches === undefined) { 1489 this._mousedown(ev); 1490 return; 1491 } 1492 1493 var touch = ev.changedTouches[0]; 1494 this.touchX = touch.pageX; 1495 this.touchY = touch.pageY; 1496 }, 1497 _triggerFocusOnHandle: function _triggerFocusOnHandle(handleIdx) { 1498 if (handleIdx === 0) { 1499 this.handle1.focus(); 1500 } 1501 if (handleIdx === 1) { 1502 this.handle2.focus(); 1503 } 1504 }, 1505 _keydown: function _keydown(handleIdx, ev) { 1506 if (!this._state.enabled) { 1507 return false;
1508 } 1509 1510 var dir; 1511 switch (ev.keyCode) { 1512 case 37: // left 1513 case 40: 1514 // down 1515 dir = -1; 1516 break; 1517 case 39: // right 1518 case 38: 1519 // up 1520 dir = 1; 1521 break; 1522 } 1523 if (!dir) { 1524 return; 1525 } 1526 1527 // use natural arrow keys instead of from min to max 1528 if (this.options.natural_arrow_keys) { 1529 var ifVerticalAndNotReversed = this.options.orientation === 'vertical' && !this.options.reversed; 1530 var ifHorizontalAndReversed = this.options.orientation === 'horizontal' && this.options.reversed; // @todo control with rtl 1531 1532 if (ifVerticalAndNotReversed || ifHorizontalAndReversed) { 1533 dir = -dir; 1534 } 1535 } 1536 1537 var val = this._state.value[handleIdx] + dir * this.options.step; 1538 var percentage = val / this.options.max * 100; 1539 this._state.keyCtrl = handleIdx; 1540 if (this.options.range) { 1541 this._adjustPercentageForRangeSliders(percentage); 1542 var val1 = !this._state.keyCtrl ? val : this._state.value[0]; 1543 var val2 = this._state.keyCtrl ? val : this._state.value[1]; 1544 val = [val1, val2]; 1545 } 1546 1547 this._trigger('slideStart', val); 1548 this._setDataVal(val); 1549 this.setValue(val, true, true); 1550 1551 this._setDataVal(val); 1552 this._trigger('slideStop', val); 1553 this._layout(); 1554 1555 this._pauseEvent(ev); 1556 delete this._state.keyCtrl; 1557 1558 return false; 1559 }, 1560 _pauseEvent: function _pauseEvent(ev) { 1561 if (ev.stopPropagation) { 1562 ev.stopPropagation(); 1563 } 1564 if (ev.preventDefault) { 1565 ev.preventDefault(); 1566 } 1567 ev.cancelBubble = true; 1568 ev.returnValue = false; 1569 }, 1570 _mousemove: function _mousemove(ev) { 1571 if (!this._state.enabled) { 1572 return false; 1573 } 1574 1575 var percentage = this._getPercentage(ev); 1576 this._adjustPercentageForRangeSliders(percentage); 1577 this._state.percentage[this._state.dragged] = percentage; 1578 this._layout(); 1579 1580 var val = this._calculateValue(true); 1581 this.setValue(val, true, true); 1582 1583 return false; 1584 }, 1585 _touchmove: function _touchmove(ev) { 1586 if (ev.changedTouches === undefined) { 1587 return; 1588 } 1589 1590 var touch = ev.changedTouches[0]; 1591 1592 var xDiff = touch.pageX - this.touchX; 1593 var yDiff = touch.pageY - this.touchY; 1594 1595 if (!this._state.inDrag) { 1596 // Vertical Slider 1597 if (this.options.orientation === 'vertical' && xDiff <= 5 && xDiff >= -5 && (yDiff >= 15 || yDiff <= -15)) { 1598 this._mousedown(ev); 1599 } 1600 // Horizontal slider. 1601 else if (yDiff <= 5 && yDiff >= -5 && (xDiff >= 15 || xDiff <= -15)) { 1602 this._mousedown(ev); 1603 } 1604 } 1605 }, 1606 _adjustPercentageForRangeSliders: function _adjustPercentageForRangeSliders(percentage) { 1607 if (this.options.range) { 1608 var precision = this._getNumDigitsAfterDecimalPlace(percentage); 1609 precision = precision ? precision - 1 : 0; 1610 var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision); 1611 if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) { 1612 this._state.percentage[0] = this._state.percentage[1]; 1613 this._state.dragged = 1; 1614 } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) { 1615 this._state.percentage[1] = this._state.percentage[0]; 1616 this._state.dragged = 0; 1617 } else if (this._state.keyCtrl === 0 && this._state.value[1] / this.options.max * 100 < percentage) { 1618 this._state.percentage[0] = this._state.percentage[1]; 1619 this._state.keyCtrl = 1;
1620 this.handle2.focus(); 1621 } else if (this._state.keyCtrl === 1 && this._state.value[0] / this.options.max * 100 > percentage) { 1622 this._state.percentage[1] = this._state.percentage[0]; 1623 this._state.keyCtrl = 0; 1624 this.handle1.focus(); 1625 } 1626 } 1627 }, 1628 _mouseup: function _mouseup() { 1629 if (!this._state.enabled) { 1630 return false; 1631 } 1632 if (this.touchCapable) { 1633 // Touch: Unbind touch event handlers: 1634 document.removeEventListener("touchmove", this.mousemove, false); 1635 document.removeEventListener("touchend", this.mouseup, false); 1636 } 1637 // Unbind mouse event handlers: 1638 document.removeEventListener("mousemove", this.mousemove, false); 1639 document.removeEventListener("mouseup", this.mouseup, false); 1640 1641 this._state.inDrag = false; 1642 if (this._state.over === false) { 1643 this._hideTooltip(); 1644 } 1645 var val = this._calculateValue(true); 1646 1647 this._layout(); 1648 this._setDataVal(val); 1649 this._trigger('slideStop', val); 1650 1651 return false; 1652 }, 1653 _calculateValue: function _calculateValue(snapToClosestTick) { 1654 var val; 1655 if (this.options.range) { 1656 val = [this.options.min, this.options.max]; 1657 if (this._state.percentage[0] !== 0) { 1658 val[0] = this._toValue(this._state.percentage[0]); 1659 val[0] = this._applyPrecision(val[0]); 1660 } 1661 if (this._state.percentage[1] !== 100) { 1662 val[1] = this._toValue(this._state.percentage[1]); 1663 val[1] = this._applyPrecision(val[1]); 1664 } 1665 } else { 1666 val = this._toValue(this._state.percentage[0]); 1667 val = parseFloat(val); 1668 val = this._applyPrecision(val); 1669 } 1670 1671 if (snapToClosestTick) { 1672 var min = [val, Infinity]; 1673 for (var i = 0; i < this.options.ticks.length; i++) { 1674 var diff = Math.abs(this.options.ticks[i] - val); 1675 if (diff <= min[1]) { 1676 min = [this.options.ticks[i], diff]; 1677 } 1678 } 1679 if (min[1] <= this.options.ticks_snap_bounds) { 1680 return min[0]; 1681 } 1682 } 1683 1684 return val; 1685 }, 1686 _applyPrecision: function _applyPrecision(val) { 1687 var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step); 1688 return this._applyToFixedAndParseFloat(val, precision); 1689 }, 1690 _getNumDigitsAfterDecimalPlace: function _getNumDigitsAfterDecimalPlace(num) { 1691 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 1692 if (!match) { 1693 return 0; 1694 } 1695 return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)); 1696 }, 1697 _applyToFixedAndParseFloat: function _applyToFixedAndParseFloat(num, toFixedInput) { 1698 var truncatedNum = num.toFixed(toFixedInput); 1699 return parseFloat(truncatedNum); 1700 }, 1701 /* 1702 Credits to Mike Samuel for the following method! 1703 Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number 1704 */ 1705 _getPercentage: function _getPercentage(ev) { 1706 if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) { 1707 ev = ev.touches[0]; 1708 } 1709 1710 var eventPosition = ev[this.mousePos]; 1711 var sliderOffset = this._state.offset[this.stylePos]; 1712 var distanceToSlide = eventPosition - sliderOffset; 1713 if (this.stylePos === 'right') { 1714 distanceToSlide = -distanceToSlide; 1715 } 1716 // Calculate what percent of the length the slider handle has slid 1717 var percentage = distanceToSlide / this._state.size * 100; 1718 percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2]; 1719 if (this.options.reversed) { 1720 percentage = 100 - percentage; 1721 } 1722 1723 // Make sure the percent is within the bounds of the slider. 1724 // 0% corresponds to the 'min' value of the slide 1725 // 100% corresponds to the 'max' value of the slide 1726 return Math.max(0, Math.min(100, percentage)); 1727 }, 1728 _validateInputValue: function _validateInputValue(val) { 1729 if (!isNaN(+val)) { 1730 return +val; 1731 } else if (Array.isArray(val)) {
vendor: 7,085 bytes, lines 1732-1896
1732 this._validateArray(val); 1733 return val; 1734 } else { 1735 throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(val)); 1736 } 1737 }, 1738 _validateArray: function _validateArray(val) { 1739 for (var i = 0; i < val.length; i++) { 1740 var input = val[i]; 1741 if (typeof input !== 'number') { 1742 throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(input)); 1743 } 1744 } 1745 }, 1746 _setDataVal: function _setDataVal(val) { 1747 this.element.setAttribute('data-value', val); 1748 this.element.setAttribute('value', val); 1749 this.element.value = val; 1750 }, 1751 _trigger: function _trigger(evt, val) { 1752 val = val || val === 0 ? val : undefined; 1753 1754 var callbackFnArray = this.eventToCallbackMap[evt]; 1755 if (callbackFnArray && callbackFnArray.length) { 1756 for (var i = 0; i < callbackFnArray.length; i++) { 1757 var callbackFn = callbackFnArray[i]; 1758 callbackFn(val); 1759 } 1760 } 1761 1762 /* If JQuery exists, trigger JQuery events */ 1763 if ($) { 1764 this._triggerJQueryEvent(evt, val); 1765 } 1766 }, 1767 _triggerJQueryEvent: function _triggerJQueryEvent(evt, val) { 1768 var eventData = { 1769 type: evt, 1770 value: val 1771 }; 1772 this.$element.trigger(eventData); 1773 this.$sliderElem.trigger(eventData); 1774 }, 1775 _unbindJQueryEventHandlers: function _unbindJQueryEventHandlers() { 1776 this.$element.off(); 1777 this.$sliderElem.off(); 1778 }, 1779 _setText: function _setText(element, text) { 1780 if (typeof element.textContent !== "undefined") { 1781 element.textContent = text; 1782 } else if (typeof element.innerText !== "undefined") { 1783 element.innerText = text; 1784 } 1785 }, 1786 _removeClass: function _removeClass(element, classString) { 1787 var classes = classString.split(" "); 1788 var newClasses = element.className; 1789 1790 for (var i = 0; i < classes.length; i++) { 1791 var classTag = classes[i]; 1792 var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)"); 1793 newClasses = newClasses.replace(regex, " "); 1794 } 1795 1796 element.className = newClasses.trim(); 1797 }, 1798 _addClass: function _addClass(element, classString) { 1799 var classes = classString.split(" "); 1800 var newClasses = element.className; 1801 1802 for (var i = 0; i < classes.length; i++) { 1803 var classTag = classes[i]; 1804 var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)"); 1805 var ifClassExists = regex.test(newClasses); 1806 1807 if (!ifClassExists) { 1808 newClasses += " " + classTag; 1809 } 1810 } 1811 1812 element.className = newClasses.trim(); 1813 }, 1814 _offsetLeft: function _offsetLeft(obj) { 1815 return obj.getBoundingClientRect().left; 1816 }, 1817 _offsetRight: function _offsetRight(obj) { 1818 return obj.getBoundingClientRect().right; 1819 }, 1820 _offsetTop: function _offsetTop(obj) { 1821 var offsetTop = obj.offsetTop; 1822 while ((obj = obj.offsetParent) && !isNaN(obj.offsetTop)) { 1823 offsetTop += obj.offsetTop; 1824 if (obj.tagName !== 'BODY') { 1825 offsetTop -= obj.scrollTop; 1826 } 1827 } 1828 return offsetTop; 1829 }, 1830 _offset: function _offset(obj) { 1831 return { 1832 left: this._offsetLeft(obj), 1833 right: this._offsetRight(obj), 1834 top: this._offsetTop(obj) 1835 }; 1836 }, 1837 _css: function _css(elementRef, styleName, value) { 1838 if ($) { 1839 $.style(elementRef, styleName, value); 1840 } else { 1841 var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) { 1842 return letter.toUpperCase(); 1843 }); 1844 elementRef.style[style] = value; 1845 } 1846 }, 1847 _toValue: function _toValue(percentage) { 1848 return this.options.scale.toValue.apply(this, [percentage]); 1849 }, 1850 _toPercentage: function _toPercentage(value) { 1851 return this.options.scale.toPercentage.apply(this, [value]); 1852 }, 1853 _setTooltipPosition: function _setTooltipPosition() { 1854 var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max]; 1855 if (this.options.orientation === 'vertical') { 1856 var tooltipPos; 1857 if (this.options.tooltip_position) { 1858 tooltipPos = this.options.tooltip_position; 1859 } else { 1860 if (this.options.rtl) { 1861 tooltipPos = 'left'; 1862 } else { 1863 tooltipPos = 'right'; 1864 } 1865 } 1866 var oppositeSide = tooltipPos === 'left' ? 'right' : 'left'; 1867 tooltips.forEach(function (tooltip) { 1868 this._addClass(tooltip, tooltipPos); 1869 tooltip.style[oppositeSide] = '100%'; 1870 }.bind(this)); 1871 } else if (this.options.tooltip_position === 'bottom') { 1872 tooltips.forEach(function (tooltip) { 1873 this._addClass(tooltip, 'bottom'); 1874 tooltip.style.top = 22 + 'px'; 1875 }.bind(this)); 1876 } else { 1877 tooltips.forEach(function (tooltip) { 1878 this._addClass(tooltip, 'top'); 1879 tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px'; 1880 }.bind(this)); 1881 } 1882 } 1883 }; 1884 1885 /********************************* 1886 Attach to global namespace 1887 *********************************/ 1888 if ($ && $.fn) { 1889 var autoRegisterNamespace = void 0; 1890 1891 if (!$.fn.slider) { 1892 $.bridget(NAMESPACE_MAIN, Slider); 1893 autoRegisterNamespace = NAMESPACE_MAIN; 1894 } else { 1895 if (windowIsDefined) { 1896 window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSl
1896ider namespace instead."); 1897 } 1898 autoRegisterNamespace = NAMESPACE_ALTERNATE; 1899 } 1900 $.bridget(NAMESPACE_ALTERNATE, Slider); 1901 1902 // Auto-Register data-provide="slider" Elements 1903 $(function () { 1904 $("input[data-provide=slider]")[autoRegisterNamespace](); 1905 }); 1906 } 1907 })($); 1908 1909 return Slider; 1910});
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.