You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5383 lines
209 KiB

8 years ago
  1. (function(root, factory) {
  2. // if(typeof exports === 'object' && typeof module === 'object')
  3. // factory(require("Bokeh"));
  4. // else if(typeof define === 'function' && define.amd)
  5. // define(["Bokeh"], factory);
  6. // else if(typeof exports === 'object')
  7. // factory(require("Bokeh"));
  8. // else
  9. factory(root["Bokeh"]);
  10. })(this, function(Bokeh) {
  11. var define;
  12. return (function(modules, aliases, entry) {
  13. if (Bokeh != null) {
  14. return Bokeh.register_plugin(modules, aliases, entry);
  15. } else {
  16. throw new Error("Cannot find Bokeh. You have to load it prior to loading plugins.");
  17. }
  18. })
  19. ({
  20. 365: /* models/widgets/abstract_button */ function(require, module, exports) {
  21. 'use strict';
  22. Object.defineProperty(exports, '__esModule', { value: true });
  23. var extend = function (child, parent) {
  24. for (var key in parent) {
  25. if (hasProp.call(parent, key))
  26. child[key] = parent[key];
  27. }
  28. function ctor() {
  29. this.constructor = child;
  30. }
  31. ctor.prototype = parent.prototype;
  32. child.prototype = new ctor();
  33. child.__super__ = parent.prototype;
  34. return child;
  35. }, hasProp = {}.hasOwnProperty, slice = [].slice;
  36. var p = require(13 /* core/properties */);
  37. var dom_1 = require(4 /* core/dom */);
  38. var build_views_1 = require(3 /* core/build_views */);
  39. var widget_1 = require(405 /* ./widget */);
  40. exports.AbstractButtonView = function (superClass) {
  41. extend(AbstractButtonView, superClass);
  42. function AbstractButtonView() {
  43. return AbstractButtonView.__super__.constructor.apply(this, arguments);
  44. }
  45. AbstractButtonView.prototype.initialize = function (options) {
  46. AbstractButtonView.__super__.initialize.call(this, options);
  47. this.icon_views = {};
  48. return this.render();
  49. };
  50. AbstractButtonView.prototype.connect_signals = function () {
  51. AbstractButtonView.__super__.connect_signals.call(this);
  52. return this.connect(this.model.change, function () {
  53. return this.render();
  54. });
  55. };
  56. AbstractButtonView.prototype.remove = function () {
  57. build_views_1.remove_views(this.icon_views);
  58. return AbstractButtonView.__super__.remove.call(this);
  59. };
  60. AbstractButtonView.prototype._render_button = function () {
  61. var children;
  62. children = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  63. return dom_1.button.apply(null, [{
  64. type: 'button',
  65. disabled: this.model.disabled,
  66. 'class': [
  67. 'bk-bs-btn',
  68. 'bk-bs-btn-' + this.model.button_type
  69. ]
  70. }].concat(slice.call(children)));
  71. };
  72. AbstractButtonView.prototype.render = function () {
  73. var icon;
  74. AbstractButtonView.__super__.render.call(this);
  75. dom_1.empty(this.el);
  76. this.buttonEl = this._render_button(this.model.label);
  77. this.buttonEl.addEventListener('click', function (_this) {
  78. return function (event) {
  79. return _this._button_click(event);
  80. };
  81. }(this));
  82. this.el.appendChild(this.buttonEl);
  83. icon = this.model.icon;
  84. if (icon != null) {
  85. build_views_1.build_views(this.icon_views, [icon], { parent: this });
  86. dom_1.prepend(this.buttonEl, this.icon_views[icon.id].el, dom_1.nbsp);
  87. }
  88. return this;
  89. };
  90. AbstractButtonView.prototype._button_click = function (event) {
  91. event.preventDefault();
  92. return this.change_input();
  93. };
  94. AbstractButtonView.prototype.change_input = function () {
  95. var ref;
  96. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  97. };
  98. return AbstractButtonView;
  99. }(widget_1.WidgetView);
  100. exports.AbstractButton = function (superClass) {
  101. extend(AbstractButton, superClass);
  102. function AbstractButton() {
  103. return AbstractButton.__super__.constructor.apply(this, arguments);
  104. }
  105. AbstractButton.prototype.type = 'AbstractButton';
  106. AbstractButton.prototype.default_view = exports.AbstractButtonView;
  107. AbstractButton.define({
  108. callback: [p.Instance],
  109. label: [
  110. p.String,
  111. 'Button'
  112. ],
  113. icon: [p.Instance],
  114. button_type: [
  115. p.String,
  116. 'default'
  117. ]
  118. });
  119. return AbstractButton;
  120. }(widget_1.Widget);
  121. },
  122. 366: /* models/widgets/abstract_icon */ function(require, module, exports) {
  123. 'use strict';
  124. Object.defineProperty(exports, '__esModule', { value: true });
  125. var extend = function (child, parent) {
  126. for (var key in parent) {
  127. if (hasProp.call(parent, key))
  128. child[key] = parent[key];
  129. }
  130. function ctor() {
  131. this.constructor = child;
  132. }
  133. ctor.prototype = parent.prototype;
  134. child.prototype = new ctor();
  135. child.__super__ = parent.prototype;
  136. return child;
  137. }, hasProp = {}.hasOwnProperty;
  138. var widget_1 = require(405 /* ./widget */);
  139. exports.AbstractIcon = function (superClass) {
  140. extend(AbstractIcon, superClass);
  141. function AbstractIcon() {
  142. return AbstractIcon.__super__.constructor.apply(this, arguments);
  143. }
  144. AbstractIcon.prototype.type = 'AbstractIcon';
  145. return AbstractIcon;
  146. }(widget_1.Widget);
  147. },
  148. 367: /* models/widgets/abstract_slider */ function(require, module, exports) {
  149. 'use strict';
  150. Object.defineProperty(exports, '__esModule', { value: true });
  151. var extend = function (child, parent) {
  152. for (var key in parent) {
  153. if (hasProp.call(parent, key))
  154. child[key] = parent[key];
  155. }
  156. function ctor() {
  157. this.constructor = child;
  158. }
  159. ctor.prototype = parent.prototype;
  160. child.prototype = new ctor();
  161. child.__super__ = parent.prototype;
  162. return child;
  163. }, hasProp = {}.hasOwnProperty;
  164. var noUiSlider = require(396 /* nouislider */);
  165. var p = require(13 /* core/properties */);
  166. var dom_1 = require(4 /* core/dom */);
  167. var logging_1 = require(12 /* core/logging */);
  168. var callback_1 = require(22 /* core/util/callback */);
  169. var widget_1 = require(405 /* ./widget */);
  170. exports.AbstractSliderView = function (superClass) {
  171. extend(AbstractSliderView, superClass);
  172. function AbstractSliderView() {
  173. return AbstractSliderView.__super__.constructor.apply(this, arguments);
  174. }
  175. AbstractSliderView.prototype.initialize = function (options) {
  176. AbstractSliderView.__super__.initialize.call(this, options);
  177. return this.render();
  178. };
  179. AbstractSliderView.prototype.connect_signals = function () {
  180. return this.connect(this.model.change, function (_this) {
  181. return function () {
  182. return _this.render();
  183. };
  184. }(this));
  185. };
  186. AbstractSliderView.prototype._calc_to = function () {
  187. };
  188. AbstractSliderView.prototype._calc_from = function (values) {
  189. };
  190. AbstractSliderView.prototype.render = function () {
  191. var callback, end, formatter, i, prefix, pretty, ref, start, step, toggleTooltip, tooltips, v, value;
  192. if (this.sliderEl == null) {
  193. AbstractSliderView.__super__.render.call(this);
  194. }
  195. if (this.model.callback != null) {
  196. callback = function (_this) {
  197. return function () {
  198. return _this.model.callback.execute(_this.model);
  199. };
  200. }(this);
  201. switch (this.model.callback_policy) {
  202. case 'continuous':
  203. this.callback_wrapper = callback;
  204. break;
  205. case 'throttle':
  206. this.callback_wrapper = callback_1.throttle(callback, this.model.callback_throttle);
  207. }
  208. }
  209. prefix = 'bk-noUi-';
  210. ref = this._calc_to(), start = ref.start, end = ref.end, value = ref.value, step = ref.step;
  211. if (this.model.tooltips) {
  212. formatter = {
  213. to: function (_this) {
  214. return function (value) {
  215. return _this.model.pretty(value);
  216. };
  217. }(this)
  218. };
  219. tooltips = function () {
  220. var j, ref1, results;
  221. results = [];
  222. for (i = j = 0, ref1 = value.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
  223. results.push(formatter);
  224. }
  225. return results;
  226. }();
  227. } else {
  228. tooltips = false;
  229. }
  230. this.el.classList.add('bk-slider');
  231. if (this.sliderEl == null) {
  232. this.sliderEl = dom_1.div();
  233. this.el.appendChild(this.sliderEl);
  234. noUiSlider.create(this.sliderEl, {
  235. cssPrefix: prefix,
  236. range: {
  237. min: start,
  238. max: end
  239. },
  240. start: value,
  241. step: step,
  242. behaviour: this.model.behaviour,
  243. connect: this.model.connected,
  244. tooltips: tooltips,
  245. orientation: this.model.orientation,
  246. direction: this.model.direction
  247. });
  248. this.sliderEl.noUiSlider.on('slide', function (_this) {
  249. return function (_, __, values) {
  250. return _this._slide(values);
  251. };
  252. }(this));
  253. this.sliderEl.noUiSlider.on('change', function (_this) {
  254. return function (_, __, values) {
  255. return _this._change(values);
  256. };
  257. }(this));
  258. toggleTooltip = function (_this) {
  259. return function (i, show) {
  260. var handle, tooltip;
  261. handle = _this.sliderEl.querySelectorAll('.' + prefix + 'handle')[i];
  262. tooltip = handle.querySelector('.' + prefix + 'tooltip');
  263. return tooltip.style.display = show ? 'block' : '';
  264. };
  265. }(this);
  266. this.sliderEl.noUiSlider.on('start', function (_this) {
  267. return function (_, i) {
  268. return toggleTooltip(i, true);
  269. };
  270. }(this));
  271. this.sliderEl.noUiSlider.on('end', function (_this) {
  272. return function (_, i) {
  273. return toggleTooltip(i, false);
  274. };
  275. }(this));
  276. } else {
  277. this.sliderEl.noUiSlider.updateOptions({
  278. range: {
  279. min: start,
  280. max: end
  281. },
  282. start: value,
  283. step: step
  284. });
  285. }
  286. if (this.titleEl != null) {
  287. this.el.removeChild(this.titleEl);
  288. }
  289. if (this.valueEl != null) {
  290. this.el.removeChild(this.valueEl);
  291. }
  292. if (this.model.title != null) {
  293. if (this.model.title.length !== 0) {
  294. this.titleEl = dom_1.label({}, this.model.title + ':');
  295. this.el.insertBefore(this.titleEl, this.sliderEl);
  296. }
  297. if (this.model.show_value) {
  298. pretty = function () {
  299. var j, len, results;
  300. results = [];
  301. for (j = 0, len = value.length; j < len; j++) {
  302. v = value[j];
  303. results.push(this.model.pretty(v));
  304. }
  305. return results;
  306. }.call(this).join(' .. ');
  307. this.valueEl = dom_1.div({ 'class': 'bk-slider-value' }, pretty);
  308. this.el.insertBefore(this.valueEl, this.sliderEl);
  309. }
  310. }
  311. if (!this.model.disabled) {
  312. this.sliderEl.querySelector('.' + prefix + 'connect').style.backgroundColor = this.model.bar_color;
  313. }
  314. if (this.model.disabled) {
  315. this.sliderEl.setAttribute('disabled', true);
  316. } else {
  317. this.sliderEl.removeAttribute('disabled');
  318. }
  319. return this;
  320. };
  321. AbstractSliderView.prototype._slide = function (values) {
  322. var pretty, v, value;
  323. value = this._calc_from(values);
  324. pretty = function () {
  325. var j, len, results;
  326. results = [];
  327. for (j = 0, len = values.length; j < len; j++) {
  328. v = values[j];
  329. results.push(this.model.pretty(v));
  330. }
  331. return results;
  332. }.call(this).join(' .. ');
  333. logging_1.logger.debug('[slider slide] value = ' + pretty);
  334. if (this.valueEl != null) {
  335. this.valueEl.textContent = pretty;
  336. }
  337. this.model.value = value;
  338. return typeof this.callback_wrapper === 'function' ? this.callback_wrapper() : void 0;
  339. };
  340. AbstractSliderView.prototype._change = function (values) {
  341. var pretty, ref, v, value;
  342. value = this._calc_from(values);
  343. pretty = function () {
  344. var j, len, results;
  345. results = [];
  346. for (j = 0, len = values.length; j < len; j++) {
  347. v = values[j];
  348. results.push(this.model.pretty(v));
  349. }
  350. return results;
  351. }.call(this).join(' .. ');
  352. logging_1.logger.debug('[slider change] value = ' + pretty);
  353. if (this.valueEl != null) {
  354. this.valueEl.value = pretty;
  355. }
  356. this.model.value = value;
  357. switch (this.model.callback_policy) {
  358. case 'mouseup':
  359. case 'throttle':
  360. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  361. }
  362. };
  363. return AbstractSliderView;
  364. }(widget_1.WidgetView);
  365. exports.AbstractSlider = function (superClass) {
  366. extend(AbstractSlider, superClass);
  367. function AbstractSlider() {
  368. return AbstractSlider.__super__.constructor.apply(this, arguments);
  369. }
  370. AbstractSlider.prototype.type = 'AbstractSlider';
  371. AbstractSlider.prototype.default_view = exports.AbstractSliderView;
  372. AbstractSlider.define({
  373. title: [
  374. p.String,
  375. ''
  376. ],
  377. show_value: [
  378. p.Bool,
  379. true
  380. ],
  381. start: [p.Any],
  382. end: [p.Any],
  383. value: [p.Any],
  384. step: [
  385. p.Number,
  386. 1
  387. ],
  388. format: [p.String],
  389. orientation: [
  390. p.Orientation,
  391. 'horizontal'
  392. ],
  393. direction: [
  394. p.Any,
  395. 'ltr'
  396. ],
  397. tooltips: [
  398. p.Boolean,
  399. true
  400. ],
  401. callback: [p.Instance],
  402. callback_throttle: [
  403. p.Number,
  404. 200
  405. ],
  406. callback_policy: [
  407. p.String,
  408. 'throttle'
  409. ],
  410. bar_color: [
  411. p.Color,
  412. '#e6e6e6'
  413. ]
  414. });
  415. AbstractSlider.prototype.behaviour = null;
  416. AbstractSlider.prototype.connected = false;
  417. AbstractSlider.prototype._formatter = function (value, format) {
  418. return '' + value;
  419. };
  420. AbstractSlider.prototype.pretty = function (value) {
  421. return this._formatter(value, this.format);
  422. };
  423. return AbstractSlider;
  424. }(widget_1.Widget);
  425. },
  426. 368: /* models/widgets/autocomplete_input */ function(require, module, exports) {
  427. 'use strict';
  428. Object.defineProperty(exports, '__esModule', { value: true });
  429. var extend = function (child, parent) {
  430. for (var key in parent) {
  431. if (hasProp.call(parent, key))
  432. child[key] = parent[key];
  433. }
  434. function ctor() {
  435. this.constructor = child;
  436. }
  437. ctor.prototype = parent.prototype;
  438. child.prototype = new ctor();
  439. child.__super__ = parent.prototype;
  440. return child;
  441. }, hasProp = {}.hasOwnProperty;
  442. var text_input_1 = require(393 /* ./text_input */);
  443. var common_1 = require(372 /* ./common */);
  444. var dom_1 = require(4 /* core/dom */);
  445. var p = require(13 /* core/properties */);
  446. exports.AutocompleteInputView = function (superClass) {
  447. extend(AutocompleteInputView, superClass);
  448. function AutocompleteInputView() {
  449. return AutocompleteInputView.__super__.constructor.apply(this, arguments);
  450. }
  451. AutocompleteInputView.prototype.connect_signals = function () {
  452. AutocompleteInputView.__super__.connect_signals.call(this);
  453. return common_1.clear_menus.connect(function (_this) {
  454. return function () {
  455. return _this._clear_menu();
  456. };
  457. }(this));
  458. };
  459. AutocompleteInputView.prototype.render = function () {
  460. AutocompleteInputView.__super__.render.call(this);
  461. this.inputEl.classList.add('bk-autocomplete-input');
  462. this.inputEl.addEventListener('keydown', function (_this) {
  463. return function (event) {
  464. return _this._keydown(event);
  465. };
  466. }(this));
  467. this.inputEl.addEventListener('keyup', function (_this) {
  468. return function (event) {
  469. return _this._keyup(event);
  470. };
  471. }(this));
  472. this.menuEl = dom_1.ul({ 'class': 'bk-bs-dropdown-menu' });
  473. this.menuEl.addEventListener('click', function (_this) {
  474. return function (event) {
  475. return _this._item_click(event);
  476. };
  477. }(this));
  478. this.el.appendChild(this.menuEl);
  479. return this;
  480. };
  481. AutocompleteInputView.prototype._render_items = function (completions) {
  482. var i, itemEl, len, results, text;
  483. dom_1.empty(this.menuEl);
  484. results = [];
  485. for (i = 0, len = completions.length; i < len; i++) {
  486. text = completions[i];
  487. itemEl = dom_1.li({}, dom_1.a({ data: { text: text } }, text));
  488. results.push(this.menuEl.appendChild(itemEl));
  489. }
  490. return results;
  491. };
  492. AutocompleteInputView.prototype._open_menu = function () {
  493. return this.el.classList.add('bk-bs-open');
  494. };
  495. AutocompleteInputView.prototype._clear_menu = function () {
  496. return this.el.classList.remove('bk-bs-open');
  497. };
  498. AutocompleteInputView.prototype._item_click = function (event) {
  499. var el, text;
  500. event.preventDefault();
  501. if (event.target !== event.currentTarget) {
  502. el = event.target;
  503. text = el.dataset.text;
  504. return this.model.value = text;
  505. }
  506. };
  507. AutocompleteInputView.prototype._keydown = function (event) {
  508. };
  509. AutocompleteInputView.prototype._keyup = function (event) {
  510. var completions, i, len, ref, text, value;
  511. switch (event.keyCode) {
  512. case dom_1.Keys.Enter:
  513. return console.log('enter');
  514. case dom_1.Keys.Esc:
  515. return this._clear_menu();
  516. case dom_1.Keys.Up:
  517. case dom_1.Keys.Down:
  518. return console.log('up/down');
  519. default:
  520. value = this.inputEl.value;
  521. if (value.length <= 1) {
  522. this._clear_menu();
  523. return;
  524. }
  525. completions = [];
  526. ref = this.model.completions;
  527. for (i = 0, len = ref.length; i < len; i++) {
  528. text = ref[i];
  529. if (text.indexOf(value) !== -1) {
  530. completions.push(text);
  531. }
  532. }
  533. if (completions.length === 0) {
  534. return this._clear_menu();
  535. } else {
  536. this._render_items(completions);
  537. return this._open_menu();
  538. }
  539. }
  540. };
  541. return AutocompleteInputView;
  542. }(text_input_1.TextInputView);
  543. exports.AutocompleteInput = function (superClass) {
  544. extend(AutocompleteInput, superClass);
  545. function AutocompleteInput() {
  546. return AutocompleteInput.__super__.constructor.apply(this, arguments);
  547. }
  548. AutocompleteInput.prototype.type = 'AutocompleteInput';
  549. AutocompleteInput.prototype.default_view = exports.AutocompleteInputView;
  550. AutocompleteInput.define({
  551. completions: [
  552. p.Array,
  553. []
  554. ]
  555. });
  556. AutocompleteInput.internal({
  557. active: [
  558. p.Boolean,
  559. true
  560. ]
  561. });
  562. return AutocompleteInput;
  563. }(text_input_1.TextInput);
  564. },
  565. 369: /* models/widgets/button */ function(require, module, exports) {
  566. 'use strict';
  567. Object.defineProperty(exports, '__esModule', { value: true });
  568. var extend = function (child, parent) {
  569. for (var key in parent) {
  570. if (hasProp.call(parent, key))
  571. child[key] = parent[key];
  572. }
  573. function ctor() {
  574. this.constructor = child;
  575. }
  576. ctor.prototype = parent.prototype;
  577. child.prototype = new ctor();
  578. child.__super__ = parent.prototype;
  579. return child;
  580. }, hasProp = {}.hasOwnProperty;
  581. var p = require(13 /* core/properties */);
  582. var bokeh_events_1 = require(2 /* core/bokeh_events */);
  583. var abstract_button_1 = require(365 /* ./abstract_button */);
  584. exports.ButtonView = function (superClass) {
  585. extend(ButtonView, superClass);
  586. function ButtonView() {
  587. return ButtonView.__super__.constructor.apply(this, arguments);
  588. }
  589. ButtonView.prototype.change_input = function () {
  590. this.model.trigger_event(new bokeh_events_1.ButtonClick({}));
  591. this.model.clicks = this.model.clicks + 1;
  592. return ButtonView.__super__.change_input.call(this);
  593. };
  594. return ButtonView;
  595. }(abstract_button_1.AbstractButtonView);
  596. exports.Button = function (superClass) {
  597. extend(Button, superClass);
  598. function Button() {
  599. return Button.__super__.constructor.apply(this, arguments);
  600. }
  601. Button.prototype.type = 'Button';
  602. Button.prototype.default_view = exports.ButtonView;
  603. Button.define({
  604. clicks: [
  605. p.Number,
  606. 0
  607. ]
  608. });
  609. return Button;
  610. }(abstract_button_1.AbstractButton);
  611. bokeh_events_1.register_with_event(bokeh_events_1.ButtonClick, exports.Button);
  612. },
  613. 370: /* models/widgets/checkbox_button_group */ function(require, module, exports) {
  614. 'use strict';
  615. Object.defineProperty(exports, '__esModule', { value: true });
  616. var extend = function (child, parent) {
  617. for (var key in parent) {
  618. if (hasProp.call(parent, key))
  619. child[key] = parent[key];
  620. }
  621. function ctor() {
  622. this.constructor = child;
  623. }
  624. ctor.prototype = parent.prototype;
  625. child.prototype = new ctor();
  626. child.__super__ = parent.prototype;
  627. return child;
  628. }, hasProp = {}.hasOwnProperty, indexOf = [].indexOf || function (item) {
  629. for (var i = 0, l = this.length; i < l; i++) {
  630. if (i in this && this[i] === item)
  631. return i;
  632. }
  633. return -1;
  634. };
  635. var dom_1 = require(4 /* core/dom */);
  636. var p = require(13 /* core/properties */);
  637. var widget_1 = require(405 /* ./widget */);
  638. exports.CheckboxButtonGroupView = function (superClass) {
  639. extend(CheckboxButtonGroupView, superClass);
  640. function CheckboxButtonGroupView() {
  641. return CheckboxButtonGroupView.__super__.constructor.apply(this, arguments);
  642. }
  643. CheckboxButtonGroupView.prototype.initialize = function (options) {
  644. CheckboxButtonGroupView.__super__.initialize.call(this, options);
  645. return this.render();
  646. };
  647. CheckboxButtonGroupView.prototype.connect_signals = function () {
  648. CheckboxButtonGroupView.__super__.connect_signals.call(this);
  649. return this.connect(this.model.change, function () {
  650. return this.render();
  651. });
  652. };
  653. CheckboxButtonGroupView.prototype.render = function () {
  654. var active, divEl, i, inputEl, j, labelEl, len, ref, text;
  655. CheckboxButtonGroupView.__super__.render.call(this);
  656. dom_1.empty(this.el);
  657. divEl = dom_1.div({ 'class': 'bk-bs-btn-group' });
  658. this.el.appendChild(divEl);
  659. active = this.model.active;
  660. ref = this.model.labels;
  661. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  662. text = ref[i];
  663. inputEl = dom_1.input({
  664. type: 'checkbox',
  665. value: '' + i,
  666. checked: indexOf.call(active, i) >= 0
  667. });
  668. inputEl.addEventListener('change', function (_this) {
  669. return function () {
  670. return _this.change_input();
  671. };
  672. }(this));
  673. labelEl = dom_1.label({
  674. 'class': [
  675. 'bk-bs-btn',
  676. 'bk-bs-btn-' + this.model.button_type
  677. ]
  678. }, inputEl, text);
  679. if (indexOf.call(active, i) >= 0) {
  680. labelEl.classList.add('bk-bs-active');
  681. }
  682. divEl.appendChild(labelEl);
  683. }
  684. return this;
  685. };
  686. CheckboxButtonGroupView.prototype.change_input = function () {
  687. var active, checkbox, i, ref;
  688. active = function () {
  689. var j, len, ref, results;
  690. ref = this.el.querySelectorAll('input');
  691. results = [];
  692. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  693. checkbox = ref[i];
  694. if (checkbox.checked) {
  695. results.push(i);
  696. }
  697. }
  698. return results;
  699. }.call(this);
  700. this.model.active = active;
  701. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  702. };
  703. return CheckboxButtonGroupView;
  704. }(widget_1.WidgetView);
  705. exports.CheckboxButtonGroup = function (superClass) {
  706. extend(CheckboxButtonGroup, superClass);
  707. function CheckboxButtonGroup() {
  708. return CheckboxButtonGroup.__super__.constructor.apply(this, arguments);
  709. }
  710. CheckboxButtonGroup.prototype.type = 'CheckboxButtonGroup';
  711. CheckboxButtonGroup.prototype.default_view = exports.CheckboxButtonGroupView;
  712. CheckboxButtonGroup.define({
  713. active: [
  714. p.Array,
  715. []
  716. ],
  717. labels: [
  718. p.Array,
  719. []
  720. ],
  721. button_type: [
  722. p.String,
  723. 'default'
  724. ],
  725. callback: [p.Instance]
  726. });
  727. return CheckboxButtonGroup;
  728. }(widget_1.Widget);
  729. },
  730. 371: /* models/widgets/checkbox_group */ function(require, module, exports) {
  731. 'use strict';
  732. Object.defineProperty(exports, '__esModule', { value: true });
  733. var extend = function (child, parent) {
  734. for (var key in parent) {
  735. if (hasProp.call(parent, key))
  736. child[key] = parent[key];
  737. }
  738. function ctor() {
  739. this.constructor = child;
  740. }
  741. ctor.prototype = parent.prototype;
  742. child.prototype = new ctor();
  743. child.__super__ = parent.prototype;
  744. return child;
  745. }, hasProp = {}.hasOwnProperty, indexOf = [].indexOf || function (item) {
  746. for (var i = 0, l = this.length; i < l; i++) {
  747. if (i in this && this[i] === item)
  748. return i;
  749. }
  750. return -1;
  751. };
  752. var dom_1 = require(4 /* core/dom */);
  753. var p = require(13 /* core/properties */);
  754. var widget_1 = require(405 /* ./widget */);
  755. exports.CheckboxGroupView = function (superClass) {
  756. extend(CheckboxGroupView, superClass);
  757. function CheckboxGroupView() {
  758. return CheckboxGroupView.__super__.constructor.apply(this, arguments);
  759. }
  760. CheckboxGroupView.prototype.initialize = function (options) {
  761. CheckboxGroupView.__super__.initialize.call(this, options);
  762. return this.render();
  763. };
  764. CheckboxGroupView.prototype.connect_signals = function () {
  765. CheckboxGroupView.__super__.connect_signals.call(this);
  766. return this.connect(this.model.change, function () {
  767. return this.render();
  768. });
  769. };
  770. CheckboxGroupView.prototype.render = function () {
  771. var active, divEl, i, inputEl, j, labelEl, len, ref, text;
  772. CheckboxGroupView.__super__.render.call(this);
  773. dom_1.empty(this.el);
  774. active = this.model.active;
  775. ref = this.model.labels;
  776. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  777. text = ref[i];
  778. inputEl = dom_1.input({
  779. type: 'checkbox',
  780. value: '' + i
  781. });
  782. inputEl.addEventListener('change', function (_this) {
  783. return function () {
  784. return _this.change_input();
  785. };
  786. }(this));
  787. if (this.model.disabled) {
  788. inputEl.disabled = true;
  789. }
  790. if (indexOf.call(active, i) >= 0) {
  791. inputEl.checked = true;
  792. }
  793. labelEl = dom_1.label({}, inputEl, text);
  794. if (this.model.inline) {
  795. labelEl.classList.add('bk-bs-checkbox-inline');
  796. this.el.appendChild(labelEl);
  797. } else {
  798. divEl = dom_1.div({ 'class': 'bk-bs-checkbox' }, labelEl);
  799. this.el.appendChild(divEl);
  800. }
  801. }
  802. return this;
  803. };
  804. CheckboxGroupView.prototype.change_input = function () {
  805. var active, checkbox, i, ref;
  806. active = function () {
  807. var j, len, ref, results;
  808. ref = this.el.querySelectorAll('input');
  809. results = [];
  810. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  811. checkbox = ref[i];
  812. if (checkbox.checked) {
  813. results.push(i);
  814. }
  815. }
  816. return results;
  817. }.call(this);
  818. this.model.active = active;
  819. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  820. };
  821. return CheckboxGroupView;
  822. }(widget_1.WidgetView);
  823. exports.CheckboxGroup = function (superClass) {
  824. extend(CheckboxGroup, superClass);
  825. function CheckboxGroup() {
  826. return CheckboxGroup.__super__.constructor.apply(this, arguments);
  827. }
  828. CheckboxGroup.prototype.type = 'CheckboxGroup';
  829. CheckboxGroup.prototype.default_view = exports.CheckboxGroupView;
  830. CheckboxGroup.define({
  831. active: [
  832. p.Array,
  833. []
  834. ],
  835. labels: [
  836. p.Array,
  837. []
  838. ],
  839. inline: [
  840. p.Bool,
  841. false
  842. ],
  843. callback: [p.Instance]
  844. });
  845. return CheckboxGroup;
  846. }(widget_1.Widget);
  847. },
  848. 372: /* models/widgets/common */ function(require, module, exports) {
  849. 'use strict';
  850. Object.defineProperty(exports, '__esModule', { value: true });
  851. var signaling_1 = require(18 /* core/signaling */);
  852. exports.clear_menus = new signaling_1.Signal({}, 'clear_menus');
  853. document.addEventListener('click', function () {
  854. return exports.clear_menus.emit(undefined);
  855. });
  856. },
  857. 373: /* models/widgets/date_picker */ function(require, module, exports) {
  858. 'use strict';
  859. Object.defineProperty(exports, '__esModule', { value: true });
  860. var bind = function (fn, me) {
  861. return function () {
  862. return fn.apply(me, arguments);
  863. };
  864. }, extend = function (child, parent) {
  865. for (var key in parent) {
  866. if (hasProp.call(parent, key))
  867. child[key] = parent[key];
  868. }
  869. function ctor() {
  870. this.constructor = child;
  871. }
  872. ctor.prototype = parent.prototype;
  873. child.prototype = new ctor();
  874. child.__super__ = parent.prototype;
  875. return child;
  876. }, hasProp = {}.hasOwnProperty;
  877. var input_widget_1 = require(379 /* ./input_widget */);
  878. var dom_1 = require(4 /* core/dom */);
  879. var p = require(13 /* core/properties */);
  880. var Pikaday = require(397 /* pikaday */);
  881. Pikaday.prototype.adjustPosition = function () {
  882. var clientRect, field, height, left, scrollTop, top, viewportHeight, viewportWidth, width;
  883. if (this._o.container) {
  884. return;
  885. }
  886. this.el.style.position = 'absolute';
  887. field = this._o.trigger;
  888. width = this.el.offsetWidth;
  889. height = this.el.offsetHeight;
  890. viewportWidth = window.innerWidth || document.documentElement.clientWidth;
  891. viewportHeight = window.innerHeight || document.documentElement.clientHeight;
  892. scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
  893. clientRect = field.getBoundingClientRect();
  894. left = clientRect.left + window.pageXOffset;
  895. top = clientRect.bottom + window.pageYOffset;
  896. left -= this.el.parentElement.offsetLeft;
  897. top -= this.el.parentElement.offsetTop;
  898. if (this._o.reposition && left + width > viewportWidth || this._o.position.indexOf('right') > -1 && left - width + field.offsetWidth > 0) {
  899. left = left - width + field.offsetWidth;
  900. }
  901. if (this._o.reposition && top + height > viewportHeight + scrollTop || this._o.position.indexOf('top') > -1 && top - height - field.offsetHeight > 0) {
  902. top = top - height - field.offsetHeight;
  903. }
  904. this.el.style.left = left + 'px';
  905. return this.el.style.top = top + 'px';
  906. };
  907. exports.DatePickerView = function (superClass) {
  908. extend(DatePickerView, superClass);
  909. function DatePickerView() {
  910. this._on_select = bind(this._on_select, this);
  911. return DatePickerView.__super__.constructor.apply(this, arguments);
  912. }
  913. DatePickerView.prototype.className = 'bk-widget-form-group';
  914. DatePickerView.prototype.render = function () {
  915. DatePickerView.__super__.render.call(this);
  916. if (this._picker != null) {
  917. this._picker.destroy();
  918. }
  919. dom_1.empty(this.el);
  920. this.labelEl = dom_1.label({}, this.model.title);
  921. this.el.appendChild(this.labelEl);
  922. this.inputEl = dom_1.input({
  923. type: 'text',
  924. 'class': 'bk-widget-form-input',
  925. disabled: this.model.disabled
  926. });
  927. this.el.appendChild(this.inputEl);
  928. this._picker = new Pikaday({
  929. field: this.inputEl,
  930. defaultDate: new Date(this.model.value),
  931. setDefaultDate: true,
  932. minDate: this.model.min_date != null ? new Date(this.model.min_date) : null,
  933. maxDate: this.model.max_date != null ? new Date(this.model.max_date) : null,
  934. onSelect: this._on_select
  935. });
  936. this._root_element.appendChild(this._picker.el);
  937. return this;
  938. };
  939. DatePickerView.prototype._on_select = function (date) {
  940. this.model.value = date.toString();
  941. return this.change_input();
  942. };
  943. return DatePickerView;
  944. }(input_widget_1.InputWidgetView);
  945. exports.DatePicker = function (superClass) {
  946. extend(DatePicker, superClass);
  947. function DatePicker() {
  948. return DatePicker.__super__.constructor.apply(this, arguments);
  949. }
  950. DatePicker.prototype.type = 'DatePicker';
  951. DatePicker.prototype.default_view = exports.DatePickerView;
  952. DatePicker.define({
  953. value: [
  954. p.Any,
  955. Date.now()
  956. ],
  957. min_date: [p.Any],
  958. max_date: [p.Any]
  959. });
  960. return DatePicker;
  961. }(input_widget_1.InputWidget);
  962. },
  963. 374: /* models/widgets/date_range_slider */ function(require, module, exports) {
  964. 'use strict';
  965. Object.defineProperty(exports, '__esModule', { value: true });
  966. var extend = function (child, parent) {
  967. for (var key in parent) {
  968. if (hasProp.call(parent, key))
  969. child[key] = parent[key];
  970. }
  971. function ctor() {
  972. this.constructor = child;
  973. }
  974. ctor.prototype = parent.prototype;
  975. child.prototype = new ctor();
  976. child.__super__ = parent.prototype;
  977. return child;
  978. }, hasProp = {}.hasOwnProperty;
  979. var tz = require(356 /* timezone */);
  980. var abstract_slider_1 = require(367 /* ./abstract_slider */);
  981. exports.DateRangeSliderView = function (superClass) {
  982. extend(DateRangeSliderView, superClass);
  983. function DateRangeSliderView() {
  984. return DateRangeSliderView.__super__.constructor.apply(this, arguments);
  985. }
  986. DateRangeSliderView.prototype._calc_to = function () {
  987. return {
  988. start: this.model.start,
  989. end: this.model.end,
  990. value: this.model.value,
  991. step: this.model.step
  992. };
  993. };
  994. DateRangeSliderView.prototype._calc_from = function (values) {
  995. return values;
  996. };
  997. return DateRangeSliderView;
  998. }(abstract_slider_1.AbstractSliderView);
  999. exports.DateRangeSlider = function (superClass) {
  1000. extend(DateRangeSlider, superClass);
  1001. function DateRangeSlider() {
  1002. return DateRangeSlider.__super__.constructor.apply(this, arguments);
  1003. }
  1004. DateRangeSlider.prototype.type = 'DateRangeSlider';
  1005. DateRangeSlider.prototype.default_view = exports.DateRangeSliderView;
  1006. DateRangeSlider.prototype.behaviour = 'drag';
  1007. DateRangeSlider.prototype.connected = [
  1008. false,
  1009. true,
  1010. false
  1011. ];
  1012. DateRangeSlider.prototype._formatter = tz;
  1013. DateRangeSlider.override({ format: '%d %b %G' });
  1014. return DateRangeSlider;
  1015. }(abstract_slider_1.AbstractSlider);
  1016. },
  1017. 375: /* models/widgets/date_slider */ function(require, module, exports) {
  1018. 'use strict';
  1019. Object.defineProperty(exports, '__esModule', { value: true });
  1020. var extend = function (child, parent) {
  1021. for (var key in parent) {
  1022. if (hasProp.call(parent, key))
  1023. child[key] = parent[key];
  1024. }
  1025. function ctor() {
  1026. this.constructor = child;
  1027. }
  1028. ctor.prototype = parent.prototype;
  1029. child.prototype = new ctor();
  1030. child.__super__ = parent.prototype;
  1031. return child;
  1032. }, hasProp = {}.hasOwnProperty;
  1033. var tz = require(356 /* timezone */);
  1034. var abstract_slider_1 = require(367 /* ./abstract_slider */);
  1035. exports.DateSliderView = function (superClass) {
  1036. extend(DateSliderView, superClass);
  1037. function DateSliderView() {
  1038. return DateSliderView.__super__.constructor.apply(this, arguments);
  1039. }
  1040. DateSliderView.prototype._calc_to = function () {
  1041. return {
  1042. start: this.model.start,
  1043. end: this.model.end,
  1044. value: [this.model.value],
  1045. step: this.model.step
  1046. };
  1047. };
  1048. DateSliderView.prototype._calc_from = function (arg) {
  1049. var value;
  1050. value = arg[0];
  1051. return value;
  1052. };
  1053. return DateSliderView;
  1054. }(abstract_slider_1.AbstractSliderView);
  1055. exports.DateSlider = function (superClass) {
  1056. extend(DateSlider, superClass);
  1057. function DateSlider() {
  1058. return DateSlider.__super__.constructor.apply(this, arguments);
  1059. }
  1060. DateSlider.prototype.type = 'DateSlider';
  1061. DateSlider.prototype.default_view = exports.DateSliderView;
  1062. DateSlider.prototype.behaviour = 'tap';
  1063. DateSlider.prototype.connected = [
  1064. true,
  1065. false
  1066. ];
  1067. DateSlider.prototype._formatter = tz;
  1068. DateSlider.override({ format: '%d %b %G' });
  1069. return DateSlider;
  1070. }(abstract_slider_1.AbstractSlider);
  1071. },
  1072. 376: /* models/widgets/div */ function(require, module, exports) {
  1073. 'use strict';
  1074. Object.defineProperty(exports, '__esModule', { value: true });
  1075. var extend = function (child, parent) {
  1076. for (var key in parent) {
  1077. if (hasProp.call(parent, key))
  1078. child[key] = parent[key];
  1079. }
  1080. function ctor() {
  1081. this.constructor = child;
  1082. }
  1083. ctor.prototype = parent.prototype;
  1084. child.prototype = new ctor();
  1085. child.__super__ = parent.prototype;
  1086. return child;
  1087. }, hasProp = {}.hasOwnProperty;
  1088. var markup_1 = require(381 /* ./markup */);
  1089. var dom_1 = require(4 /* core/dom */);
  1090. var p = require(13 /* core/properties */);
  1091. exports.DivView = function (superClass) {
  1092. extend(DivView, superClass);
  1093. function DivView() {
  1094. return DivView.__super__.constructor.apply(this, arguments);
  1095. }
  1096. DivView.prototype.render = function () {
  1097. var content;
  1098. DivView.__super__.render.call(this);
  1099. content = dom_1.div();
  1100. if (this.model.render_as_text) {
  1101. content.textContent = this.model.text;
  1102. } else {
  1103. content.innerHTML = this.model.text;
  1104. }
  1105. this.markupEl.appendChild(content);
  1106. return this;
  1107. };
  1108. return DivView;
  1109. }(markup_1.MarkupView);
  1110. exports.Div = function (superClass) {
  1111. extend(Div, superClass);
  1112. function Div() {
  1113. return Div.__super__.constructor.apply(this, arguments);
  1114. }
  1115. Div.prototype.type = 'Div';
  1116. Div.prototype.default_view = exports.DivView;
  1117. Div.define({
  1118. render_as_text: [
  1119. p.Bool,
  1120. false
  1121. ]
  1122. });
  1123. return Div;
  1124. }(markup_1.Markup);
  1125. },
  1126. 377: /* models/widgets/dropdown */ function(require, module, exports) {
  1127. 'use strict';
  1128. Object.defineProperty(exports, '__esModule', { value: true });
  1129. var extend = function (child, parent) {
  1130. for (var key in parent) {
  1131. if (hasProp.call(parent, key))
  1132. child[key] = parent[key];
  1133. }
  1134. function ctor() {
  1135. this.constructor = child;
  1136. }
  1137. ctor.prototype = parent.prototype;
  1138. child.prototype = new ctor();
  1139. child.__super__ = parent.prototype;
  1140. return child;
  1141. }, hasProp = {}.hasOwnProperty;
  1142. var dom_1 = require(4 /* core/dom */);
  1143. var p = require(13 /* core/properties */);
  1144. var abstract_button_1 = require(365 /* ./abstract_button */);
  1145. var common_1 = require(372 /* ./common */);
  1146. exports.DropdownView = function (superClass) {
  1147. extend(DropdownView, superClass);
  1148. function DropdownView() {
  1149. return DropdownView.__super__.constructor.apply(this, arguments);
  1150. }
  1151. DropdownView.prototype.connect_signals = function () {
  1152. DropdownView.__super__.connect_signals.call(this);
  1153. return common_1.clear_menus.connect(function (_this) {
  1154. return function () {
  1155. return _this._clear_menu();
  1156. };
  1157. }(this));
  1158. };
  1159. DropdownView.prototype.render = function () {
  1160. var caretEl, i, item, itemEl, items, label, len, link, menuEl, ref, value;
  1161. DropdownView.__super__.render.call(this);
  1162. if (!this.model.is_split_button) {
  1163. this.el.classList.add('bk-bs-dropdown');
  1164. this.buttonEl.classList.add('bk-bs-dropdown-toggle');
  1165. this.buttonEl.appendChild(dom_1.span({ 'class': 'bk-bs-caret' }));
  1166. } else {
  1167. this.el.classList.add('bk-bs-btn-group');
  1168. caretEl = this._render_button(dom_1.span({ 'class': 'bk-bs-caret' }));
  1169. caretEl.classList.add('bk-bs-dropdown-toggle');
  1170. caretEl.addEventListener('click', function (_this) {
  1171. return function (event) {
  1172. return _this._caret_click(event);
  1173. };
  1174. }(this));
  1175. this.el.appendChild(caretEl);
  1176. }
  1177. if (this.model.active) {
  1178. this.el.classList.add('bk-bs-open');
  1179. }
  1180. items = [];
  1181. ref = this.model.menu;
  1182. for (i = 0, len = ref.length; i < len; i++) {
  1183. item = ref[i];
  1184. if (item != null) {
  1185. label = item[0], value = item[1];
  1186. link = dom_1.a({}, label);
  1187. link.dataset.value = value;
  1188. link.addEventListener('click', function (_this) {
  1189. return function (event) {
  1190. return _this._item_click(event);
  1191. };
  1192. }(this));
  1193. itemEl = dom_1.li({}, link);
  1194. } else {
  1195. itemEl = dom_1.li({ 'class': 'bk-bs-divider' });
  1196. }
  1197. items.push(itemEl);
  1198. }
  1199. menuEl = dom_1.ul({ 'class': 'bk-bs-dropdown-menu' }, items);
  1200. this.el.appendChild(menuEl);
  1201. return this;
  1202. };
  1203. DropdownView.prototype._clear_menu = function () {
  1204. return this.model.active = false;
  1205. };
  1206. DropdownView.prototype._toggle_menu = function () {
  1207. var active;
  1208. active = this.model.active;
  1209. common_1.clear_menus.emit();
  1210. if (!active) {
  1211. return this.model.active = true;
  1212. }
  1213. };
  1214. DropdownView.prototype._button_click = function (event) {
  1215. event.preventDefault();
  1216. event.stopPropagation();
  1217. if (!this.model.is_split_button) {
  1218. return this._toggle_menu();
  1219. } else {
  1220. this._clear_menu();
  1221. return this.set_value(this.model.default_value);
  1222. }
  1223. };
  1224. DropdownView.prototype._caret_click = function (event) {
  1225. event.preventDefault();
  1226. event.stopPropagation();
  1227. return this._toggle_menu();
  1228. };
  1229. DropdownView.prototype._item_click = function (event) {
  1230. event.preventDefault();
  1231. this._clear_menu();
  1232. return this.set_value(event.currentTarget.dataset.value);
  1233. };
  1234. DropdownView.prototype.set_value = function (value) {
  1235. this.buttonEl.value = this.model.value = value;
  1236. return this.change_input();
  1237. };
  1238. return DropdownView;
  1239. }(abstract_button_1.AbstractButtonView);
  1240. exports.Dropdown = function (superClass) {
  1241. extend(Dropdown, superClass);
  1242. function Dropdown() {
  1243. return Dropdown.__super__.constructor.apply(this, arguments);
  1244. }
  1245. Dropdown.prototype.type = 'Dropdown';
  1246. Dropdown.prototype.default_view = exports.DropdownView;
  1247. Dropdown.define({
  1248. value: [p.String],
  1249. default_value: [p.String],
  1250. menu: [
  1251. p.Array,
  1252. []
  1253. ]
  1254. });
  1255. Dropdown.override({ label: 'Dropdown' });
  1256. Dropdown.internal({
  1257. active: [
  1258. p.Boolean,
  1259. false
  1260. ]
  1261. });
  1262. Dropdown.getters({
  1263. is_split_button: function () {
  1264. return this.default_value != null;
  1265. }
  1266. });
  1267. return Dropdown;
  1268. }(abstract_button_1.AbstractButton);
  1269. },
  1270. 378: /* models/widgets/index */ function(require, module, exports) {
  1271. 'use strict';
  1272. Object.defineProperty(exports, '__esModule', { value: true });
  1273. var abstract_button_1 = require(365 /* ./abstract_button */);
  1274. exports.AbstractButton = abstract_button_1.AbstractButton;
  1275. var abstract_icon_1 = require(366 /* ./abstract_icon */);
  1276. exports.AbstractIcon = abstract_icon_1.AbstractIcon;
  1277. var autocomplete_input_1 = require(368 /* ./autocomplete_input */);
  1278. exports.AutocompleteInput = autocomplete_input_1.AutocompleteInput;
  1279. var button_1 = require(369 /* ./button */);
  1280. exports.Button = button_1.Button;
  1281. var checkbox_button_group_1 = require(370 /* ./checkbox_button_group */);
  1282. exports.CheckboxButtonGroup = checkbox_button_group_1.CheckboxButtonGroup;
  1283. var checkbox_group_1 = require(371 /* ./checkbox_group */);
  1284. exports.CheckboxGroup = checkbox_group_1.CheckboxGroup;
  1285. var date_picker_1 = require(373 /* ./date_picker */);
  1286. exports.DatePicker = date_picker_1.DatePicker;
  1287. var date_range_slider_1 = require(374 /* ./date_range_slider */);
  1288. exports.DateRangeSlider = date_range_slider_1.DateRangeSlider;
  1289. var date_slider_1 = require(375 /* ./date_slider */);
  1290. exports.DateSlider = date_slider_1.DateSlider;
  1291. var div_1 = require(376 /* ./div */);
  1292. exports.Div = div_1.Div;
  1293. var dropdown_1 = require(377 /* ./dropdown */);
  1294. exports.Dropdown = dropdown_1.Dropdown;
  1295. var input_widget_1 = require(379 /* ./input_widget */);
  1296. exports.InputWidget = input_widget_1.InputWidget;
  1297. var markup_1 = require(381 /* ./markup */);
  1298. exports.Markup = markup_1.Markup;
  1299. var multiselect_1 = require(382 /* ./multiselect */);
  1300. exports.MultiSelect = multiselect_1.MultiSelect;
  1301. var panel_1 = require(383 /* ./panel */);
  1302. exports.Panel = panel_1.Panel;
  1303. var paragraph_1 = require(384 /* ./paragraph */);
  1304. exports.Paragraph = paragraph_1.Paragraph;
  1305. var password_input_1 = require(385 /* ./password_input */);
  1306. exports.PasswordInput = password_input_1.PasswordInput;
  1307. var pretext_1 = require(386 /* ./pretext */);
  1308. exports.PreText = pretext_1.PreText;
  1309. var radio_button_group_1 = require(387 /* ./radio_button_group */);
  1310. exports.RadioButtonGroup = radio_button_group_1.RadioButtonGroup;
  1311. var radio_group_1 = require(388 /* ./radio_group */);
  1312. exports.RadioGroup = radio_group_1.RadioGroup;
  1313. var range_slider_1 = require(389 /* ./range_slider */);
  1314. exports.RangeSlider = range_slider_1.RangeSlider;
  1315. var selectbox_1 = require(390 /* ./selectbox */);
  1316. exports.Select = selectbox_1.Select;
  1317. var slider_1 = require(391 /* ./slider */);
  1318. exports.Slider = slider_1.Slider;
  1319. var tabs_1 = require(392 /* ./tabs */);
  1320. exports.Tabs = tabs_1.Tabs;
  1321. var text_input_1 = require(393 /* ./text_input */);
  1322. exports.TextInput = text_input_1.TextInput;
  1323. var toggle_1 = require(394 /* ./toggle */);
  1324. exports.Toggle = toggle_1.Toggle;
  1325. var widget_1 = require(405 /* ./widget */);
  1326. exports.Widget = widget_1.Widget;
  1327. },
  1328. 379: /* models/widgets/input_widget */ function(require, module, exports) {
  1329. 'use strict';
  1330. Object.defineProperty(exports, '__esModule', { value: true });
  1331. var extend = function (child, parent) {
  1332. for (var key in parent) {
  1333. if (hasProp.call(parent, key))
  1334. child[key] = parent[key];
  1335. }
  1336. function ctor() {
  1337. this.constructor = child;
  1338. }
  1339. ctor.prototype = parent.prototype;
  1340. child.prototype = new ctor();
  1341. child.__super__ = parent.prototype;
  1342. return child;
  1343. }, hasProp = {}.hasOwnProperty;
  1344. var widget_1 = require(405 /* ./widget */);
  1345. var p = require(13 /* core/properties */);
  1346. exports.InputWidgetView = function (superClass) {
  1347. extend(InputWidgetView, superClass);
  1348. function InputWidgetView() {
  1349. return InputWidgetView.__super__.constructor.apply(this, arguments);
  1350. }
  1351. InputWidgetView.prototype.change_input = function () {
  1352. var ref;
  1353. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  1354. };
  1355. return InputWidgetView;
  1356. }(widget_1.WidgetView);
  1357. exports.InputWidget = function (superClass) {
  1358. extend(InputWidget, superClass);
  1359. function InputWidget() {
  1360. return InputWidget.__super__.constructor.apply(this, arguments);
  1361. }
  1362. InputWidget.prototype.type = 'InputWidget';
  1363. InputWidget.prototype.default_view = exports.InputWidgetView;
  1364. InputWidget.define({
  1365. callback: [p.Instance],
  1366. title: [
  1367. p.String,
  1368. ''
  1369. ]
  1370. });
  1371. return InputWidget;
  1372. }(widget_1.Widget);
  1373. },
  1374. 380: /* models/widgets/main */ function(require, module, exports) {
  1375. 'use strict';
  1376. Object.defineProperty(exports, '__esModule', { value: true });
  1377. var Widgets = require(378 /* ./index */);
  1378. exports.Widgets = Widgets;
  1379. var base_1 = require(0 /* ../../base */);
  1380. base_1.register_models(Widgets);
  1381. },
  1382. 381: /* models/widgets/markup */ function(require, module, exports) {
  1383. 'use strict';
  1384. Object.defineProperty(exports, '__esModule', { value: true });
  1385. var extend1 = function (child, parent) {
  1386. for (var key in parent) {
  1387. if (hasProp.call(parent, key))
  1388. child[key] = parent[key];
  1389. }
  1390. function ctor() {
  1391. this.constructor = child;
  1392. }
  1393. ctor.prototype = parent.prototype;
  1394. child.prototype = new ctor();
  1395. child.__super__ = parent.prototype;
  1396. return child;
  1397. }, hasProp = {}.hasOwnProperty;
  1398. var p = require(13 /* core/properties */);
  1399. var dom_1 = require(4 /* core/dom */);
  1400. var object_1 = require(28 /* core/util/object */);
  1401. var widget_1 = require(405 /* ./widget */);
  1402. exports.MarkupView = function (superClass) {
  1403. extend1(MarkupView, superClass);
  1404. function MarkupView() {
  1405. return MarkupView.__super__.constructor.apply(this, arguments);
  1406. }
  1407. MarkupView.prototype.initialize = function (options) {
  1408. MarkupView.__super__.initialize.call(this, options);
  1409. return this.render();
  1410. };
  1411. MarkupView.prototype.connect_signals = function () {
  1412. MarkupView.__super__.connect_signals.call(this);
  1413. return this.connect(this.model.change, function () {
  1414. return this.render();
  1415. });
  1416. };
  1417. MarkupView.prototype.render = function () {
  1418. var style;
  1419. MarkupView.__super__.render.call(this);
  1420. dom_1.empty(this.el);
  1421. style = object_1.extend({
  1422. width: this.model.width + 'px',
  1423. height: this.model.height + 'px'
  1424. }, this.model.style);
  1425. this.markupEl = dom_1.div({ style: style });
  1426. return this.el.appendChild(this.markupEl);
  1427. };
  1428. return MarkupView;
  1429. }(widget_1.WidgetView);
  1430. exports.Markup = function (superClass) {
  1431. extend1(Markup, superClass);
  1432. function Markup() {
  1433. return Markup.__super__.constructor.apply(this, arguments);
  1434. }
  1435. Markup.prototype.type = 'Markup';
  1436. Markup.prototype.initialize = function (options) {
  1437. return Markup.__super__.initialize.call(this, options);
  1438. };
  1439. Markup.define({
  1440. text: [
  1441. p.String,
  1442. ''
  1443. ],
  1444. style: [
  1445. p.Any,
  1446. {}
  1447. ]
  1448. });
  1449. return Markup;
  1450. }(widget_1.Widget);
  1451. },
  1452. 382: /* models/widgets/multiselect */ function(require, module, exports) {
  1453. 'use strict';
  1454. Object.defineProperty(exports, '__esModule', { value: true });
  1455. var bind = function (fn, me) {
  1456. return function () {
  1457. return fn.apply(me, arguments);
  1458. };
  1459. }, extend = function (child, parent) {
  1460. for (var key in parent) {
  1461. if (hasProp.call(parent, key))
  1462. child[key] = parent[key];
  1463. }
  1464. function ctor() {
  1465. this.constructor = child;
  1466. }
  1467. ctor.prototype = parent.prototype;
  1468. child.prototype = new ctor();
  1469. child.__super__ = parent.prototype;
  1470. return child;
  1471. }, hasProp = {}.hasOwnProperty, indexOf = [].indexOf || function (item) {
  1472. for (var i = 0, l = this.length; i < l; i++) {
  1473. if (i in this && this[i] === item)
  1474. return i;
  1475. }
  1476. return -1;
  1477. };
  1478. var dom_1 = require(4 /* core/dom */);
  1479. var types_1 = require(40 /* core/util/types */);
  1480. var p = require(13 /* core/properties */);
  1481. var input_widget_1 = require(379 /* ./input_widget */);
  1482. exports.MultiSelectView = function (superClass) {
  1483. extend(MultiSelectView, superClass);
  1484. function MultiSelectView() {
  1485. this.render_selection = bind(this.render_selection, this);
  1486. return MultiSelectView.__super__.constructor.apply(this, arguments);
  1487. }
  1488. MultiSelectView.prototype.initialize = function (options) {
  1489. MultiSelectView.__super__.initialize.call(this, options);
  1490. return this.render();
  1491. };
  1492. MultiSelectView.prototype.connect_signals = function () {
  1493. MultiSelectView.__super__.connect_signals.call(this);
  1494. this.connect(this.model.properties.value.change, function () {
  1495. return this.render_selection();
  1496. });
  1497. this.connect(this.model.properties.options.change, function () {
  1498. return this.render();
  1499. });
  1500. this.connect(this.model.properties.name.change, function () {
  1501. return this.render();
  1502. });
  1503. this.connect(this.model.properties.title.change, function () {
  1504. return this.render();
  1505. });
  1506. return this.connect(this.model.properties.size.change, function () {
  1507. return this.render();
  1508. });
  1509. };
  1510. MultiSelectView.prototype.render = function () {
  1511. var labelEl, options;
  1512. MultiSelectView.__super__.render.call(this);
  1513. dom_1.empty(this.el);
  1514. labelEl = dom_1.label({ 'for': this.model.id }, this.model.title);
  1515. this.el.appendChild(labelEl);
  1516. options = this.model.options.map(function (_this) {
  1517. return function (opt) {
  1518. var _label, selected, value;
  1519. if (types_1.isString(opt)) {
  1520. value = _label = opt;
  1521. } else {
  1522. value = opt[0], _label = opt[1];
  1523. }
  1524. selected = indexOf.call(_this.model.value, value) >= 0;
  1525. return dom_1.option({
  1526. selected: selected,
  1527. value: value
  1528. }, _label);
  1529. };
  1530. }(this));
  1531. this.selectEl = dom_1.select({
  1532. multiple: true,
  1533. 'class': 'bk-widget-form-input',
  1534. id: this.model.id,
  1535. name: this.model.name,
  1536. size: this.model.size
  1537. }, options);
  1538. this.selectEl.addEventListener('change', function (_this) {
  1539. return function () {
  1540. return _this.change_input();
  1541. };
  1542. }(this));
  1543. this.el.appendChild(this.selectEl);
  1544. return this;
  1545. };
  1546. MultiSelectView.prototype.render_selection = function () {
  1547. var el, i, j, len, len1, ref, ref1, values, x;
  1548. values = {};
  1549. ref = this.model.value;
  1550. for (i = 0, len = ref.length; i < len; i++) {
  1551. x = ref[i];
  1552. values[x] = true;
  1553. }
  1554. ref1 = this.el.querySelectorAll('option');
  1555. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1556. el = ref1[j];
  1557. if (values[el.value]) {
  1558. el.selected = 'selected';
  1559. }
  1560. }
  1561. return this.selectEl.size = this.model.size;
  1562. };
  1563. MultiSelectView.prototype.change_input = function () {
  1564. var el, i, is_focused, len, ref, values;
  1565. is_focused = this.el.querySelector('select:focus') !== null;
  1566. values = [];
  1567. ref = this.el.querySelectorAll('option');
  1568. for (i = 0, len = ref.length; i < len; i++) {
  1569. el = ref[i];
  1570. if (el.selected) {
  1571. values.push(el.value);
  1572. }
  1573. }
  1574. this.model.value = values;
  1575. MultiSelectView.__super__.change_input.call(this);
  1576. if (is_focused) {
  1577. return this.selectEl.focus();
  1578. }
  1579. };
  1580. return MultiSelectView;
  1581. }(input_widget_1.InputWidgetView);
  1582. exports.MultiSelect = function (superClass) {
  1583. extend(MultiSelect, superClass);
  1584. function MultiSelect() {
  1585. return MultiSelect.__super__.constructor.apply(this, arguments);
  1586. }
  1587. MultiSelect.prototype.type = 'MultiSelect';
  1588. MultiSelect.prototype.default_view = exports.MultiSelectView;
  1589. MultiSelect.define({
  1590. value: [
  1591. p.Array,
  1592. []
  1593. ],
  1594. options: [
  1595. p.Array,
  1596. []
  1597. ],
  1598. size: [
  1599. p.Number,
  1600. 4
  1601. ]
  1602. });
  1603. return MultiSelect;
  1604. }(input_widget_1.InputWidget);
  1605. },
  1606. 383: /* models/widgets/panel */ function(require, module, exports) {
  1607. 'use strict';
  1608. Object.defineProperty(exports, '__esModule', { value: true });
  1609. var extend = function (child, parent) {
  1610. for (var key in parent) {
  1611. if (hasProp.call(parent, key))
  1612. child[key] = parent[key];
  1613. }
  1614. function ctor() {
  1615. this.constructor = child;
  1616. }
  1617. ctor.prototype = parent.prototype;
  1618. child.prototype = new ctor();
  1619. child.__super__ = parent.prototype;
  1620. return child;
  1621. }, hasProp = {}.hasOwnProperty;
  1622. var widget_1 = require(405 /* ./widget */);
  1623. var p = require(13 /* core/properties */);
  1624. var dom_1 = require(4 /* core/dom */);
  1625. exports.PanelView = function (superClass) {
  1626. extend(PanelView, superClass);
  1627. function PanelView() {
  1628. return PanelView.__super__.constructor.apply(this, arguments);
  1629. }
  1630. PanelView.prototype.render = function () {
  1631. PanelView.__super__.render.call(this);
  1632. dom_1.empty(this.el);
  1633. return this;
  1634. };
  1635. return PanelView;
  1636. }(widget_1.WidgetView);
  1637. exports.Panel = function (superClass) {
  1638. extend(Panel, superClass);
  1639. function Panel() {
  1640. return Panel.__super__.constructor.apply(this, arguments);
  1641. }
  1642. Panel.prototype.type = 'Panel';
  1643. Panel.prototype.default_view = exports.PanelView;
  1644. Panel.define({
  1645. title: [
  1646. p.String,
  1647. ''
  1648. ],
  1649. child: [p.Instance],
  1650. closable: [
  1651. p.Bool,
  1652. false
  1653. ]
  1654. });
  1655. return Panel;
  1656. }(widget_1.Widget);
  1657. },
  1658. 384: /* models/widgets/paragraph */ function(require, module, exports) {
  1659. 'use strict';
  1660. Object.defineProperty(exports, '__esModule', { value: true });
  1661. var extend = function (child, parent) {
  1662. for (var key in parent) {
  1663. if (hasProp.call(parent, key))
  1664. child[key] = parent[key];
  1665. }
  1666. function ctor() {
  1667. this.constructor = child;
  1668. }
  1669. ctor.prototype = parent.prototype;
  1670. child.prototype = new ctor();
  1671. child.__super__ = parent.prototype;
  1672. return child;
  1673. }, hasProp = {}.hasOwnProperty;
  1674. var markup_1 = require(381 /* ./markup */);
  1675. var dom_1 = require(4 /* core/dom */);
  1676. exports.ParagraphView = function (superClass) {
  1677. extend(ParagraphView, superClass);
  1678. function ParagraphView() {
  1679. return ParagraphView.__super__.constructor.apply(this, arguments);
  1680. }
  1681. ParagraphView.prototype.render = function () {
  1682. var content;
  1683. ParagraphView.__super__.render.call(this);
  1684. content = dom_1.p({ style: { margin: 0 } }, this.model.text);
  1685. return this.markupEl.appendChild(content);
  1686. };
  1687. return ParagraphView;
  1688. }(markup_1.MarkupView);
  1689. exports.Paragraph = function (superClass) {
  1690. extend(Paragraph, superClass);
  1691. function Paragraph() {
  1692. return Paragraph.__super__.constructor.apply(this, arguments);
  1693. }
  1694. Paragraph.prototype.type = 'Paragraph';
  1695. Paragraph.prototype.default_view = exports.ParagraphView;
  1696. return Paragraph;
  1697. }(markup_1.Markup);
  1698. },
  1699. 385: /* models/widgets/password_input */ function(require, module, exports) {
  1700. 'use strict';
  1701. Object.defineProperty(exports, '__esModule', { value: true });
  1702. var extend = function (child, parent) {
  1703. for (var key in parent) {
  1704. if (hasProp.call(parent, key))
  1705. child[key] = parent[key];
  1706. }
  1707. function ctor() {
  1708. this.constructor = child;
  1709. }
  1710. ctor.prototype = parent.prototype;
  1711. child.prototype = new ctor();
  1712. child.__super__ = parent.prototype;
  1713. return child;
  1714. }, hasProp = {}.hasOwnProperty;
  1715. var text_input_1 = require(393 /* ./text_input */);
  1716. exports.PasswordInputView = function (superClass) {
  1717. extend(PasswordInputView, superClass);
  1718. function PasswordInputView() {
  1719. return PasswordInputView.__super__.constructor.apply(this, arguments);
  1720. }
  1721. PasswordInputView.prototype.render = function () {
  1722. PasswordInputView.__super__.render.call(this);
  1723. return this.inputEl.type = 'password';
  1724. };
  1725. return PasswordInputView;
  1726. }(text_input_1.TextInputView);
  1727. exports.PasswordInput = function (superClass) {
  1728. extend(PasswordInput, superClass);
  1729. function PasswordInput() {
  1730. return PasswordInput.__super__.constructor.apply(this, arguments);
  1731. }
  1732. PasswordInput.prototype.type = 'PasswordInput';
  1733. PasswordInput.prototype.default_view = exports.PasswordInputView;
  1734. return PasswordInput;
  1735. }(text_input_1.TextInput);
  1736. },
  1737. 386: /* models/widgets/pretext */ function(require, module, exports) {
  1738. 'use strict';
  1739. Object.defineProperty(exports, '__esModule', { value: true });
  1740. var extend = function (child, parent) {
  1741. for (var key in parent) {
  1742. if (hasProp.call(parent, key))
  1743. child[key] = parent[key];
  1744. }
  1745. function ctor() {
  1746. this.constructor = child;
  1747. }
  1748. ctor.prototype = parent.prototype;
  1749. child.prototype = new ctor();
  1750. child.__super__ = parent.prototype;
  1751. return child;
  1752. }, hasProp = {}.hasOwnProperty;
  1753. var markup_1 = require(381 /* ./markup */);
  1754. var dom_1 = require(4 /* core/dom */);
  1755. exports.PreTextView = function (superClass) {
  1756. extend(PreTextView, superClass);
  1757. function PreTextView() {
  1758. return PreTextView.__super__.constructor.apply(this, arguments);
  1759. }
  1760. PreTextView.prototype.render = function () {
  1761. var content;
  1762. PreTextView.__super__.render.call(this);
  1763. content = dom_1.pre({ style: { overflow: 'auto' } }, this.model.text);
  1764. return this.markupEl.appendChild(content);
  1765. };
  1766. return PreTextView;
  1767. }(markup_1.MarkupView);
  1768. exports.PreText = function (superClass) {
  1769. extend(PreText, superClass);
  1770. function PreText() {
  1771. return PreText.__super__.constructor.apply(this, arguments);
  1772. }
  1773. PreText.prototype.type = 'PreText';
  1774. PreText.prototype.default_view = exports.PreTextView;
  1775. return PreText;
  1776. }(markup_1.Markup);
  1777. },
  1778. 387: /* models/widgets/radio_button_group */ function(require, module, exports) {
  1779. 'use strict';
  1780. Object.defineProperty(exports, '__esModule', { value: true });
  1781. var extend = function (child, parent) {
  1782. for (var key in parent) {
  1783. if (hasProp.call(parent, key))
  1784. child[key] = parent[key];
  1785. }
  1786. function ctor() {
  1787. this.constructor = child;
  1788. }
  1789. ctor.prototype = parent.prototype;
  1790. child.prototype = new ctor();
  1791. child.__super__ = parent.prototype;
  1792. return child;
  1793. }, hasProp = {}.hasOwnProperty;
  1794. var dom_1 = require(4 /* core/dom */);
  1795. var string_1 = require(35 /* core/util/string */);
  1796. var p = require(13 /* core/properties */);
  1797. var widget_1 = require(405 /* ./widget */);
  1798. exports.RadioButtonGroupView = function (superClass) {
  1799. extend(RadioButtonGroupView, superClass);
  1800. function RadioButtonGroupView() {
  1801. return RadioButtonGroupView.__super__.constructor.apply(this, arguments);
  1802. }
  1803. RadioButtonGroupView.prototype.initialize = function (options) {
  1804. RadioButtonGroupView.__super__.initialize.call(this, options);
  1805. return this.render();
  1806. };
  1807. RadioButtonGroupView.prototype.connect_signals = function () {
  1808. RadioButtonGroupView.__super__.connect_signals.call(this);
  1809. return this.connect(this.model.change, function () {
  1810. return this.render();
  1811. });
  1812. };
  1813. RadioButtonGroupView.prototype.render = function () {
  1814. var active, divEl, i, inputEl, j, labelEl, len, name, ref, text;
  1815. RadioButtonGroupView.__super__.render.call(this);
  1816. dom_1.empty(this.el);
  1817. divEl = dom_1.div({ 'class': 'bk-bs-btn-group' });
  1818. this.el.appendChild(divEl);
  1819. name = string_1.uniqueId();
  1820. active = this.model.active;
  1821. ref = this.model.labels;
  1822. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  1823. text = ref[i];
  1824. inputEl = dom_1.input({
  1825. type: 'radio',
  1826. name: name,
  1827. value: '' + i,
  1828. checked: i === active
  1829. });
  1830. inputEl.addEventListener('change', function (_this) {
  1831. return function () {
  1832. return _this.change_input();
  1833. };
  1834. }(this));
  1835. labelEl = dom_1.label({
  1836. 'class': [
  1837. 'bk-bs-btn',
  1838. 'bk-bs-btn-' + this.model.button_type
  1839. ]
  1840. }, inputEl, text);
  1841. if (i === active) {
  1842. labelEl.classList.add('bk-bs-active');
  1843. }
  1844. divEl.appendChild(labelEl);
  1845. }
  1846. return this;
  1847. };
  1848. RadioButtonGroupView.prototype.change_input = function () {
  1849. var active, i, radio, ref;
  1850. active = function () {
  1851. var j, len, ref, results;
  1852. ref = this.el.querySelectorAll('input');
  1853. results = [];
  1854. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  1855. radio = ref[i];
  1856. if (radio.checked) {
  1857. results.push(i);
  1858. }
  1859. }
  1860. return results;
  1861. }.call(this);
  1862. this.model.active = active[0];
  1863. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  1864. };
  1865. return RadioButtonGroupView;
  1866. }(widget_1.WidgetView);
  1867. exports.RadioButtonGroup = function (superClass) {
  1868. extend(RadioButtonGroup, superClass);
  1869. function RadioButtonGroup() {
  1870. return RadioButtonGroup.__super__.constructor.apply(this, arguments);
  1871. }
  1872. RadioButtonGroup.prototype.type = 'RadioButtonGroup';
  1873. RadioButtonGroup.prototype.default_view = exports.RadioButtonGroupView;
  1874. RadioButtonGroup.define({
  1875. active: [
  1876. p.Any,
  1877. null
  1878. ],
  1879. labels: [
  1880. p.Array,
  1881. []
  1882. ],
  1883. button_type: [
  1884. p.String,
  1885. 'default'
  1886. ],
  1887. callback: [p.Instance]
  1888. });
  1889. return RadioButtonGroup;
  1890. }(widget_1.Widget);
  1891. },
  1892. 388: /* models/widgets/radio_group */ function(require, module, exports) {
  1893. 'use strict';
  1894. Object.defineProperty(exports, '__esModule', { value: true });
  1895. var extend = function (child, parent) {
  1896. for (var key in parent) {
  1897. if (hasProp.call(parent, key))
  1898. child[key] = parent[key];
  1899. }
  1900. function ctor() {
  1901. this.constructor = child;
  1902. }
  1903. ctor.prototype = parent.prototype;
  1904. child.prototype = new ctor();
  1905. child.__super__ = parent.prototype;
  1906. return child;
  1907. }, hasProp = {}.hasOwnProperty;
  1908. var dom_1 = require(4 /* core/dom */);
  1909. var string_1 = require(35 /* core/util/string */);
  1910. var p = require(13 /* core/properties */);
  1911. var widget_1 = require(405 /* ./widget */);
  1912. exports.RadioGroupView = function (superClass) {
  1913. extend(RadioGroupView, superClass);
  1914. function RadioGroupView() {
  1915. return RadioGroupView.__super__.constructor.apply(this, arguments);
  1916. }
  1917. RadioGroupView.prototype.initialize = function (options) {
  1918. RadioGroupView.__super__.initialize.call(this, options);
  1919. return this.render();
  1920. };
  1921. RadioGroupView.prototype.connect_signals = function () {
  1922. RadioGroupView.__super__.connect_signals.call(this);
  1923. return this.connect(this.model.change, function () {
  1924. return this.render();
  1925. });
  1926. };
  1927. RadioGroupView.prototype.render = function () {
  1928. var active, divEl, i, inputEl, j, labelEl, len, name, ref, text;
  1929. RadioGroupView.__super__.render.call(this);
  1930. dom_1.empty(this.el);
  1931. name = string_1.uniqueId();
  1932. active = this.model.active;
  1933. ref = this.model.labels;
  1934. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  1935. text = ref[i];
  1936. inputEl = dom_1.input({
  1937. type: 'radio',
  1938. name: name,
  1939. value: '' + i
  1940. });
  1941. inputEl.addEventListener('change', function (_this) {
  1942. return function () {
  1943. return _this.change_input();
  1944. };
  1945. }(this));
  1946. if (this.model.disabled) {
  1947. inputEl.disabled = true;
  1948. }
  1949. if (i === active) {
  1950. inputEl.checked = true;
  1951. }
  1952. labelEl = dom_1.label({}, inputEl, text);
  1953. if (this.model.inline) {
  1954. labelEl.classList.add('bk-bs-radio-inline');
  1955. this.el.appendChild(labelEl);
  1956. } else {
  1957. divEl = dom_1.div({ 'class': 'bk-bs-radio' }, labelEl);
  1958. this.el.appendChild(divEl);
  1959. }
  1960. }
  1961. return this;
  1962. };
  1963. RadioGroupView.prototype.change_input = function () {
  1964. var active, i, radio, ref;
  1965. active = function () {
  1966. var j, len, ref, results;
  1967. ref = this.el.querySelectorAll('input');
  1968. results = [];
  1969. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  1970. radio = ref[i];
  1971. if (radio.checked) {
  1972. results.push(i);
  1973. }
  1974. }
  1975. return results;
  1976. }.call(this);
  1977. this.model.active = active[0];
  1978. return (ref = this.model.callback) != null ? ref.execute(this.model) : void 0;
  1979. };
  1980. return RadioGroupView;
  1981. }(widget_1.WidgetView);
  1982. exports.RadioGroup = function (superClass) {
  1983. extend(RadioGroup, superClass);
  1984. function RadioGroup() {
  1985. return RadioGroup.__super__.constructor.apply(this, arguments);
  1986. }
  1987. RadioGroup.prototype.type = 'RadioGroup';
  1988. RadioGroup.prototype.default_view = exports.RadioGroupView;
  1989. RadioGroup.define({
  1990. active: [
  1991. p.Any,
  1992. null
  1993. ],
  1994. labels: [
  1995. p.Array,
  1996. []
  1997. ],
  1998. inline: [
  1999. p.Bool,
  2000. false
  2001. ],
  2002. callback: [p.Instance]
  2003. });
  2004. return RadioGroup;
  2005. }(widget_1.Widget);
  2006. },
  2007. 389: /* models/widgets/range_slider */ function(require, module, exports) {
  2008. 'use strict';
  2009. Object.defineProperty(exports, '__esModule', { value: true });
  2010. var extend = function (child, parent) {
  2011. for (var key in parent) {
  2012. if (hasProp.call(parent, key))
  2013. child[key] = parent[key];
  2014. }
  2015. function ctor() {
  2016. this.constructor = child;
  2017. }
  2018. ctor.prototype = parent.prototype;
  2019. child.prototype = new ctor();
  2020. child.__super__ = parent.prototype;
  2021. return child;
  2022. }, hasProp = {}.hasOwnProperty;
  2023. var numbro_1 = require(325 /* numbro */);
  2024. var abstract_slider_1 = require(367 /* ./abstract_slider */);
  2025. exports.RangeSliderView = function (superClass) {
  2026. extend(RangeSliderView, superClass);
  2027. function RangeSliderView() {
  2028. return RangeSliderView.__super__.constructor.apply(this, arguments);
  2029. }
  2030. RangeSliderView.prototype._calc_to = function () {
  2031. return {
  2032. start: this.model.start,
  2033. end: this.model.end,
  2034. value: this.model.value,
  2035. step: this.model.step
  2036. };
  2037. };
  2038. RangeSliderView.prototype._calc_from = function (values) {
  2039. return values;
  2040. };
  2041. return RangeSliderView;
  2042. }(abstract_slider_1.AbstractSliderView);
  2043. exports.RangeSlider = function (superClass) {
  2044. extend(RangeSlider, superClass);
  2045. function RangeSlider() {
  2046. return RangeSlider.__super__.constructor.apply(this, arguments);
  2047. }
  2048. RangeSlider.prototype.type = 'RangeSlider';
  2049. RangeSlider.prototype.default_view = exports.RangeSliderView;
  2050. RangeSlider.prototype.behaviour = 'drag';
  2051. RangeSlider.prototype.connected = [
  2052. false,
  2053. true,
  2054. false
  2055. ];
  2056. RangeSlider.prototype._formatter = numbro_1.format;
  2057. RangeSlider.override({ format: '0[.]00' });
  2058. return RangeSlider;
  2059. }(abstract_slider_1.AbstractSlider);
  2060. },
  2061. 390: /* models/widgets/selectbox */ function(require, module, exports) {
  2062. 'use strict';
  2063. Object.defineProperty(exports, '__esModule', { value: true });
  2064. var extend = function (child, parent) {
  2065. for (var key in parent) {
  2066. if (hasProp.call(parent, key))
  2067. child[key] = parent[key];
  2068. }
  2069. function ctor() {
  2070. this.constructor = child;
  2071. }
  2072. ctor.prototype = parent.prototype;
  2073. child.prototype = new ctor();
  2074. child.__super__ = parent.prototype;
  2075. return child;
  2076. }, hasProp = {}.hasOwnProperty;
  2077. var dom_1 = require(4 /* core/dom */);
  2078. var types_1 = require(40 /* core/util/types */);
  2079. var logging_1 = require(12 /* core/logging */);
  2080. var p = require(13 /* core/properties */);
  2081. var input_widget_1 = require(379 /* ./input_widget */);
  2082. exports.SelectView = function (superClass) {
  2083. extend(SelectView, superClass);
  2084. function SelectView() {
  2085. return SelectView.__super__.constructor.apply(this, arguments);
  2086. }
  2087. SelectView.prototype.initialize = function (options) {
  2088. SelectView.__super__.initialize.call(this, options);
  2089. return this.render();
  2090. };
  2091. SelectView.prototype.connect_signals = function () {
  2092. SelectView.__super__.connect_signals.call(this);
  2093. return this.connect(this.model.change, function () {
  2094. return this.render();
  2095. });
  2096. };
  2097. SelectView.prototype.render = function () {
  2098. var labelEl, options;
  2099. SelectView.__super__.render.call(this);
  2100. dom_1.empty(this.el);
  2101. labelEl = dom_1.label({ 'for': this.model.id }, this.model.title);
  2102. this.el.appendChild(labelEl);
  2103. options = this.model.options.map(function (_this) {
  2104. return function (opt) {
  2105. var _label, selected, value;
  2106. if (types_1.isString(opt)) {
  2107. value = _label = opt;
  2108. } else {
  2109. value = opt[0], _label = opt[1];
  2110. }
  2111. selected = _this.model.value === value;
  2112. return dom_1.option({
  2113. selected: selected,
  2114. value: value
  2115. }, _label);
  2116. };
  2117. }(this));
  2118. this.selectEl = dom_1.select({
  2119. 'class': 'bk-widget-form-input',
  2120. id: this.model.id,
  2121. name: this.model.name
  2122. }, options);
  2123. this.selectEl.addEventListener('change', function (_this) {
  2124. return function () {
  2125. return _this.change_input();
  2126. };
  2127. }(this));
  2128. this.el.appendChild(this.selectEl);
  2129. return this;
  2130. };
  2131. SelectView.prototype.change_input = function () {
  2132. var value;
  2133. value = this.selectEl.value;
  2134. logging_1.logger.debug('selectbox: value = ' + value);
  2135. this.model.value = value;
  2136. return SelectView.__super__.change_input.call(this);
  2137. };
  2138. return SelectView;
  2139. }(input_widget_1.InputWidgetView);
  2140. exports.Select = function (superClass) {
  2141. extend(Select, superClass);
  2142. function Select() {
  2143. return Select.__super__.constructor.apply(this, arguments);
  2144. }
  2145. Select.prototype.type = 'Select';
  2146. Select.prototype.default_view = exports.SelectView;
  2147. Select.define({
  2148. value: [
  2149. p.String,
  2150. ''
  2151. ],
  2152. options: [
  2153. p.Any,
  2154. []
  2155. ]
  2156. });
  2157. return Select;
  2158. }(input_widget_1.InputWidget);
  2159. },
  2160. 391: /* models/widgets/slider */ function(require, module, exports) {
  2161. 'use strict';
  2162. Object.defineProperty(exports, '__esModule', { value: true });
  2163. var extend = function (child, parent) {
  2164. for (var key in parent) {
  2165. if (hasProp.call(parent, key))
  2166. child[key] = parent[key];
  2167. }
  2168. function ctor() {
  2169. this.constructor = child;
  2170. }
  2171. ctor.prototype = parent.prototype;
  2172. child.prototype = new ctor();
  2173. child.__super__ = parent.prototype;
  2174. return child;
  2175. }, hasProp = {}.hasOwnProperty;
  2176. var numbro_1 = require(325 /* numbro */);
  2177. var abstract_slider_1 = require(367 /* ./abstract_slider */);
  2178. exports.SliderView = function (superClass) {
  2179. extend(SliderView, superClass);
  2180. function SliderView() {
  2181. return SliderView.__super__.constructor.apply(this, arguments);
  2182. }
  2183. SliderView.prototype._calc_to = function () {
  2184. return {
  2185. start: this.model.start,
  2186. end: this.model.end,
  2187. value: [this.model.value],
  2188. step: this.model.step
  2189. };
  2190. };
  2191. SliderView.prototype._calc_from = function (arg) {
  2192. var value;
  2193. value = arg[0];
  2194. return value;
  2195. };
  2196. return SliderView;
  2197. }(abstract_slider_1.AbstractSliderView);
  2198. exports.Slider = function (superClass) {
  2199. extend(Slider, superClass);
  2200. function Slider() {
  2201. return Slider.__super__.constructor.apply(this, arguments);
  2202. }
  2203. Slider.prototype.type = 'Slider';
  2204. Slider.prototype.default_view = exports.SliderView;
  2205. Slider.prototype.behaviour = 'tap';
  2206. Slider.prototype.connected = [
  2207. true,
  2208. false
  2209. ];
  2210. Slider.prototype._formatter = numbro_1.format;
  2211. Slider.override({ format: '0[.]00' });
  2212. return Slider;
  2213. }(abstract_slider_1.AbstractSlider);
  2214. },
  2215. 392: /* models/widgets/tabs */ function(require, module, exports) {
  2216. 'use strict';
  2217. Object.defineProperty(exports, '__esModule', { value: true });
  2218. var extend = function (child, parent) {
  2219. for (var key in parent) {
  2220. if (hasProp.call(parent, key))
  2221. child[key] = parent[key];
  2222. }
  2223. function ctor() {
  2224. this.constructor = child;
  2225. }
  2226. ctor.prototype = parent.prototype;
  2227. child.prototype = new ctor();
  2228. child.__super__ = parent.prototype;
  2229. return child;
  2230. }, hasProp = {}.hasOwnProperty;
  2231. var dom_1 = require(4 /* core/dom */);
  2232. var array_1 = require(20 /* core/util/array */);
  2233. var p = require(13 /* core/properties */);
  2234. var widget_1 = require(405 /* ./widget */);
  2235. exports.TabsView = function (superClass) {
  2236. extend(TabsView, superClass);
  2237. function TabsView() {
  2238. return TabsView.__super__.constructor.apply(this, arguments);
  2239. }
  2240. TabsView.prototype.connect_signals = function () {
  2241. TabsView.__super__.connect_signals.call(this);
  2242. return this.connect(this.model.properties.tabs.change, function (_this) {
  2243. return function () {
  2244. return _this.rebuild_child_views();
  2245. };
  2246. }(this));
  2247. };
  2248. TabsView.prototype.render = function () {
  2249. var child, j, len, len1, panelEl, panels, panelsEl, ref, ref1, tabs, tabsEl;
  2250. TabsView.__super__.render.call(this);
  2251. dom_1.empty(this.el);
  2252. len = this.model.tabs.length;
  2253. if (len === 0) {
  2254. return;
  2255. } else if (this.model.active >= len) {
  2256. this.model.active = len - 1;
  2257. }
  2258. tabs = this.model.tabs.map(function (tab, i) {
  2259. return dom_1.li({}, dom_1.span({ data: { index: i } }, tab.title));
  2260. });
  2261. tabs[this.model.active].classList.add('bk-bs-active');
  2262. tabsEl = dom_1.ul({
  2263. 'class': [
  2264. 'bk-bs-nav',
  2265. 'bk-bs-nav-tabs'
  2266. ]
  2267. }, tabs);
  2268. this.el.appendChild(tabsEl);
  2269. panels = this.model.tabs.map(function (tab) {
  2270. return dom_1.div({ 'class': 'bk-bs-tab-pane' });
  2271. });
  2272. panels[this.model.active].classList.add('bk-bs-active');
  2273. panelsEl = dom_1.div({ 'class': 'bk-bs-tab-content' }, panels);
  2274. this.el.appendChild(panelsEl);
  2275. tabsEl.addEventListener('click', function (_this) {
  2276. return function (event) {
  2277. var el, new_active, old_active, ref;
  2278. event.preventDefault();
  2279. if (event.target !== event.currentTarget) {
  2280. el = event.target;
  2281. old_active = _this.model.active;
  2282. new_active = parseInt(el.dataset.index);
  2283. if (old_active !== new_active) {
  2284. tabs[old_active].classList.remove('bk-bs-active');
  2285. panels[old_active].classList.remove('bk-bs-active');
  2286. tabs[new_active].classList.add('bk-bs-active');
  2287. panels[new_active].classList.add('bk-bs-active');
  2288. _this.model.active = new_active;
  2289. return (ref = _this.model.callback) != null ? ref.execute(_this.model) : void 0;
  2290. }
  2291. }
  2292. };
  2293. }(this));
  2294. ref = array_1.zip(this.model.children, panels);
  2295. for (j = 0, len1 = ref.length; j < len1; j++) {
  2296. ref1 = ref[j], child = ref1[0], panelEl = ref1[1];
  2297. panelEl.appendChild(this.child_views[child.id].el);
  2298. }
  2299. return this;
  2300. };
  2301. return TabsView;
  2302. }(widget_1.WidgetView);
  2303. exports.Tabs = function (superClass) {
  2304. extend(Tabs, superClass);
  2305. function Tabs() {
  2306. return Tabs.__super__.constructor.apply(this, arguments);
  2307. }
  2308. Tabs.prototype.type = 'Tabs';
  2309. Tabs.prototype.default_view = exports.TabsView;
  2310. Tabs.define({
  2311. tabs: [
  2312. p.Array,
  2313. []
  2314. ],
  2315. active: [
  2316. p.Number,
  2317. 0
  2318. ],
  2319. callback: [p.Instance]
  2320. });
  2321. Tabs.getters({
  2322. children: function () {
  2323. var j, len1, ref, results, tab;
  2324. ref = this.tabs;
  2325. results = [];
  2326. for (j = 0, len1 = ref.length; j < len1; j++) {
  2327. tab = ref[j];
  2328. results.push(tab.child);
  2329. }
  2330. return results;
  2331. }
  2332. });
  2333. Tabs.prototype.get_layoutable_children = function () {
  2334. return this.children;
  2335. };
  2336. return Tabs;
  2337. }(widget_1.Widget);
  2338. },
  2339. 393: /* models/widgets/text_input */ function(require, module, exports) {
  2340. 'use strict';
  2341. Object.defineProperty(exports, '__esModule', { value: true });
  2342. var extend = function (child, parent) {
  2343. for (var key in parent) {
  2344. if (hasProp.call(parent, key))
  2345. child[key] = parent[key];
  2346. }
  2347. function ctor() {
  2348. this.constructor = child;
  2349. }
  2350. ctor.prototype = parent.prototype;
  2351. child.prototype = new ctor();
  2352. child.__super__ = parent.prototype;
  2353. return child;
  2354. }, hasProp = {}.hasOwnProperty;
  2355. var logging_1 = require(12 /* core/logging */);
  2356. var p = require(13 /* core/properties */);
  2357. var dom_1 = require(4 /* core/dom */);
  2358. var input_widget_1 = require(379 /* ./input_widget */);
  2359. exports.TextInputView = function (superClass) {
  2360. extend(TextInputView, superClass);
  2361. function TextInputView() {
  2362. return TextInputView.__super__.constructor.apply(this, arguments);
  2363. }
  2364. TextInputView.prototype.className = 'bk-widget-form-group';
  2365. TextInputView.prototype.initialize = function (options) {
  2366. TextInputView.__super__.initialize.call(this, options);
  2367. return this.render();
  2368. };
  2369. TextInputView.prototype.connect_signals = function () {
  2370. TextInputView.__super__.connect_signals.call(this);
  2371. return this.connect(this.model.change, function () {
  2372. return this.render();
  2373. });
  2374. };
  2375. TextInputView.prototype.render = function () {
  2376. var labelEl;
  2377. TextInputView.__super__.render.call(this);
  2378. dom_1.empty(this.el);
  2379. labelEl = dom_1.label({ 'for': this.model.id }, this.model.title);
  2380. this.el.appendChild(labelEl);
  2381. this.inputEl = dom_1.input({
  2382. type: 'text',
  2383. 'class': 'bk-widget-form-input',
  2384. id: this.model.id,
  2385. name: this.model.name,
  2386. value: this.model.value,
  2387. disabled: this.model.disabled,
  2388. placeholder: this.model.placeholder
  2389. });
  2390. this.inputEl.addEventListener('change', function (_this) {
  2391. return function () {
  2392. return _this.change_input();
  2393. };
  2394. }(this));
  2395. this.el.appendChild(this.inputEl);
  2396. if (this.model.height) {
  2397. this.inputEl.style.height = this.model.height - 35 + 'px';
  2398. }
  2399. return this;
  2400. };
  2401. TextInputView.prototype.change_input = function () {
  2402. var value;
  2403. value = this.inputEl.value;
  2404. logging_1.logger.debug('widget/text_input: value = ' + value);
  2405. this.model.value = value;
  2406. return TextInputView.__super__.change_input.call(this);
  2407. };
  2408. return TextInputView;
  2409. }(input_widget_1.InputWidgetView);
  2410. exports.TextInput = function (superClass) {
  2411. extend(TextInput, superClass);
  2412. function TextInput() {
  2413. return TextInput.__super__.constructor.apply(this, arguments);
  2414. }
  2415. TextInput.prototype.type = 'TextInput';
  2416. TextInput.prototype.default_view = exports.TextInputView;
  2417. TextInput.define({
  2418. value: [
  2419. p.String,
  2420. ''
  2421. ],
  2422. placeholder: [
  2423. p.String,
  2424. ''
  2425. ]
  2426. });
  2427. return TextInput;
  2428. }(input_widget_1.InputWidget);
  2429. },
  2430. 394: /* models/widgets/toggle */ function(require, module, exports) {
  2431. 'use strict';
  2432. Object.defineProperty(exports, '__esModule', { value: true });
  2433. var extend = function (child, parent) {
  2434. for (var key in parent) {
  2435. if (hasProp.call(parent, key))
  2436. child[key] = parent[key];
  2437. }
  2438. function ctor() {
  2439. this.constructor = child;
  2440. }
  2441. ctor.prototype = parent.prototype;
  2442. child.prototype = new ctor();
  2443. child.__super__ = parent.prototype;
  2444. return child;
  2445. }, hasProp = {}.hasOwnProperty;
  2446. var p = require(13 /* core/properties */);
  2447. var abstract_button_1 = require(365 /* ./abstract_button */);
  2448. exports.ToggleView = function (superClass) {
  2449. extend(ToggleView, superClass);
  2450. function ToggleView() {
  2451. return ToggleView.__super__.constructor.apply(this, arguments);
  2452. }
  2453. ToggleView.prototype.render = function () {
  2454. ToggleView.__super__.render.call(this);
  2455. if (this.model.active) {
  2456. this.buttonEl.classList.add('bk-bs-active');
  2457. }
  2458. return this;
  2459. };
  2460. ToggleView.prototype.change_input = function () {
  2461. this.model.active = !this.model.active;
  2462. return ToggleView.__super__.change_input.call(this);
  2463. };
  2464. return ToggleView;
  2465. }(abstract_button_1.AbstractButtonView);
  2466. exports.Toggle = function (superClass) {
  2467. extend(Toggle, superClass);
  2468. function Toggle() {
  2469. return Toggle.__super__.constructor.apply(this, arguments);
  2470. }
  2471. Toggle.prototype.type = 'Toggle';
  2472. Toggle.prototype.default_view = exports.ToggleView;
  2473. Toggle.define({
  2474. active: [
  2475. p.Bool,
  2476. false
  2477. ]
  2478. });
  2479. Toggle.override({ label: 'Toggle' });
  2480. return Toggle;
  2481. }(abstract_button_1.AbstractButton);
  2482. },
  2483. 405: /* models/widgets/widget */ function(require, module, exports) {
  2484. 'use strict';
  2485. Object.defineProperty(exports, '__esModule', { value: true });
  2486. var extend = function (child, parent) {
  2487. for (var key in parent) {
  2488. if (hasProp.call(parent, key))
  2489. child[key] = parent[key];
  2490. }
  2491. function ctor() {
  2492. this.constructor = child;
  2493. }
  2494. ctor.prototype = parent.prototype;
  2495. child.prototype = new ctor();
  2496. child.__super__ = parent.prototype;
  2497. return child;
  2498. }, hasProp = {}.hasOwnProperty;
  2499. var layout_dom_1 = require(134 /* ../layouts/layout_dom */);
  2500. exports.WidgetView = function (superClass) {
  2501. extend(WidgetView, superClass);
  2502. function WidgetView() {
  2503. return WidgetView.__super__.constructor.apply(this, arguments);
  2504. }
  2505. WidgetView.prototype.className = 'bk-widget';
  2506. WidgetView.prototype.render = function () {
  2507. this._render_classes();
  2508. if (this.model.height != null) {
  2509. this.el.style.height = this.model.height + 'px';
  2510. }
  2511. if (this.model.width != null) {
  2512. return this.el.style.width = this.model.width + 'px';
  2513. }
  2514. };
  2515. return WidgetView;
  2516. }(layout_dom_1.LayoutDOMView);
  2517. exports.Widget = function (superClass) {
  2518. extend(Widget, superClass);
  2519. function Widget() {
  2520. return Widget.__super__.constructor.apply(this, arguments);
  2521. }
  2522. Widget.prototype.type = 'Widget';
  2523. Widget.prototype.default_view = exports.WidgetView;
  2524. return Widget;
  2525. }(layout_dom_1.LayoutDOM);
  2526. },
  2527. 396: /* nouislider/distribute/nouislider */ function(require, module, exports) {
  2528. /*! nouislider - 10.1.0 - 2017-07-28 17:11:18 */
  2529. (function (factory) {
  2530. if (typeof define === 'function' && define.amd) {
  2531. // AMD. Register as an anonymous module.
  2532. define([], factory);
  2533. } else if (typeof exports === 'object') {
  2534. // Node/CommonJS
  2535. module.exports = factory();
  2536. } else {
  2537. // Browser globals
  2538. window.noUiSlider = factory();
  2539. }
  2540. }(function () {
  2541. 'use strict';
  2542. var VERSION = '10.1.0';
  2543. function isValidFormatter(entry) {
  2544. return typeof entry === 'object' && typeof entry.to === 'function' && typeof entry.from === 'function';
  2545. }
  2546. function removeElement(el) {
  2547. el.parentElement.removeChild(el);
  2548. }
  2549. // Bindable version
  2550. function preventDefault(e) {
  2551. e.preventDefault();
  2552. }
  2553. // Removes duplicates from an array.
  2554. function unique(array) {
  2555. return array.filter(function (a) {
  2556. return !this[a] ? this[a] = true : false;
  2557. }, {});
  2558. }
  2559. // Round a value to the closest 'to'.
  2560. function closest(value, to) {
  2561. return Math.round(value / to) * to;
  2562. }
  2563. // Current position of an element relative to the document.
  2564. function offset(elem, orientation) {
  2565. var rect = elem.getBoundingClientRect();
  2566. var doc = elem.ownerDocument;
  2567. var docElem = doc.documentElement;
  2568. var pageOffset = getPageOffset(doc);
  2569. // getBoundingClientRect contains left scroll in Chrome on Android.
  2570. // I haven't found a feature detection that proves this. Worst case
  2571. // scenario on mis-match: the 'tap' feature on horizontal sliders breaks.
  2572. if (/webkit.*Chrome.*Mobile/i.test(navigator.userAgent)) {
  2573. pageOffset.x = 0;
  2574. }
  2575. return orientation ? rect.top + pageOffset.y - docElem.clientTop : rect.left + pageOffset.x - docElem.clientLeft;
  2576. }
  2577. // Checks whether a value is numerical.
  2578. function isNumeric(a) {
  2579. return typeof a === 'number' && !isNaN(a) && isFinite(a);
  2580. }
  2581. // Sets a class and removes it after [duration] ms.
  2582. function addClassFor(element, className, duration) {
  2583. if (duration > 0) {
  2584. addClass(element, className);
  2585. setTimeout(function () {
  2586. removeClass(element, className);
  2587. }, duration);
  2588. }
  2589. }
  2590. // Limits a value to 0 - 100
  2591. function limit(a) {
  2592. return Math.max(Math.min(a, 100), 0);
  2593. }
  2594. // Wraps a variable as an array, if it isn't one yet.
  2595. // Note that an input array is returned by reference!
  2596. function asArray(a) {
  2597. return Array.isArray(a) ? a : [a];
  2598. }
  2599. // Counts decimals
  2600. function countDecimals(numStr) {
  2601. numStr = String(numStr);
  2602. var pieces = numStr.split('.');
  2603. return pieces.length > 1 ? pieces[1].length : 0;
  2604. }
  2605. // http://youmightnotneedjquery.com/#add_class
  2606. function addClass(el, className) {
  2607. if (el.classList) {
  2608. el.classList.add(className);
  2609. } else {
  2610. el.className += ' ' + className;
  2611. }
  2612. }
  2613. // http://youmightnotneedjquery.com/#remove_class
  2614. function removeClass(el, className) {
  2615. if (el.classList) {
  2616. el.classList.remove(className);
  2617. } else {
  2618. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
  2619. }
  2620. }
  2621. // https://plainjs.com/javascript/attributes/adding-removing-and-testing-for-classes-9/
  2622. function hasClass(el, className) {
  2623. return el.classList ? el.classList.contains(className) : new RegExp('\\b' + className + '\\b').test(el.className);
  2624. }
  2625. // https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY#Notes
  2626. function getPageOffset(doc) {
  2627. var supportPageOffset = window.pageXOffset !== undefined;
  2628. var isCSS1Compat = (doc.compatMode || '') === 'CSS1Compat';
  2629. var x = supportPageOffset ? window.pageXOffset : isCSS1Compat ? doc.documentElement.scrollLeft : doc.body.scrollLeft;
  2630. var y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? doc.documentElement.scrollTop : doc.body.scrollTop;
  2631. return {
  2632. x: x,
  2633. y: y
  2634. };
  2635. }
  2636. // we provide a function to compute constants instead
  2637. // of accessing window.* as soon as the module needs it
  2638. // so that we do not compute anything if not needed
  2639. function getActions() {
  2640. // Determine the events to bind. IE11 implements pointerEvents without
  2641. // a prefix, which breaks compatibility with the IE10 implementation.
  2642. return window.navigator.pointerEnabled ? {
  2643. start: 'pointerdown',
  2644. move: 'pointermove',
  2645. end: 'pointerup'
  2646. } : window.navigator.msPointerEnabled ? {
  2647. start: 'MSPointerDown',
  2648. move: 'MSPointerMove',
  2649. end: 'MSPointerUp'
  2650. } : {
  2651. start: 'mousedown touchstart',
  2652. move: 'mousemove touchmove',
  2653. end: 'mouseup touchend'
  2654. };
  2655. }
  2656. // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  2657. // Issue #785
  2658. function getSupportsPassive() {
  2659. var supportsPassive = false;
  2660. try {
  2661. var opts = Object.defineProperty({}, 'passive', {
  2662. get: function () {
  2663. supportsPassive = true;
  2664. }
  2665. });
  2666. window.addEventListener('test', null, opts);
  2667. } catch (e) {
  2668. }
  2669. return supportsPassive;
  2670. }
  2671. function getSupportsTouchActionNone() {
  2672. return window.CSS && CSS.supports && CSS.supports('touch-action', 'none');
  2673. }
  2674. // Value calculation
  2675. // Determine the size of a sub-range in relation to a full range.
  2676. function subRangeRatio(pa, pb) {
  2677. return 100 / (pb - pa);
  2678. }
  2679. // (percentage) How many percent is this value of this range?
  2680. function fromPercentage(range, value) {
  2681. return value * 100 / (range[1] - range[0]);
  2682. }
  2683. // (percentage) Where is this value on this range?
  2684. function toPercentage(range, value) {
  2685. return fromPercentage(range, range[0] < 0 ? value + Math.abs(range[0]) : value - range[0]);
  2686. }
  2687. // (value) How much is this percentage on this range?
  2688. function isPercentage(range, value) {
  2689. return value * (range[1] - range[0]) / 100 + range[0];
  2690. }
  2691. // Range conversion
  2692. function getJ(value, arr) {
  2693. var j = 1;
  2694. while (value >= arr[j]) {
  2695. j += 1;
  2696. }
  2697. return j;
  2698. }
  2699. // (percentage) Input a value, find where, on a scale of 0-100, it applies.
  2700. function toStepping(xVal, xPct, value) {
  2701. if (value >= xVal.slice(-1)[0]) {
  2702. return 100;
  2703. }
  2704. var j = getJ(value, xVal), va, vb, pa, pb;
  2705. va = xVal[j - 1];
  2706. vb = xVal[j];
  2707. pa = xPct[j - 1];
  2708. pb = xPct[j];
  2709. return pa + toPercentage([
  2710. va,
  2711. vb
  2712. ], value) / subRangeRatio(pa, pb);
  2713. }
  2714. // (value) Input a percentage, find where it is on the specified range.
  2715. function fromStepping(xVal, xPct, value) {
  2716. // There is no range group that fits 100
  2717. if (value >= 100) {
  2718. return xVal.slice(-1)[0];
  2719. }
  2720. var j = getJ(value, xPct), va, vb, pa, pb;
  2721. va = xVal[j - 1];
  2722. vb = xVal[j];
  2723. pa = xPct[j - 1];
  2724. pb = xPct[j];
  2725. return isPercentage([
  2726. va,
  2727. vb
  2728. ], (value - pa) * subRangeRatio(pa, pb));
  2729. }
  2730. // (percentage) Get the step that applies at a certain value.
  2731. function getStep(xPct, xSteps, snap, value) {
  2732. if (value === 100) {
  2733. return value;
  2734. }
  2735. var j = getJ(value, xPct), a, b;
  2736. // If 'snap' is set, steps are used as fixed points on the slider.
  2737. if (snap) {
  2738. a = xPct[j - 1];
  2739. b = xPct[j];
  2740. // Find the closest position, a or b.
  2741. if (value - a > (b - a) / 2) {
  2742. return b;
  2743. }
  2744. return a;
  2745. }
  2746. if (!xSteps[j - 1]) {
  2747. return value;
  2748. }
  2749. return xPct[j - 1] + closest(value - xPct[j - 1], xSteps[j - 1]);
  2750. }
  2751. // Entry parsing
  2752. function handleEntryPoint(index, value, that) {
  2753. var percentage;
  2754. // Wrap numerical input in an array.
  2755. if (typeof value === 'number') {
  2756. value = [value];
  2757. }
  2758. // Reject any invalid input, by testing whether value is an array.
  2759. if (Object.prototype.toString.call(value) !== '[object Array]') {
  2760. throw new Error('noUiSlider (' + VERSION + '): \'range\' contains invalid value.');
  2761. }
  2762. // Covert min/max syntax to 0 and 100.
  2763. if (index === 'min') {
  2764. percentage = 0;
  2765. } else if (index === 'max') {
  2766. percentage = 100;
  2767. } else {
  2768. percentage = parseFloat(index);
  2769. }
  2770. // Check for correct input.
  2771. if (!isNumeric(percentage) || !isNumeric(value[0])) {
  2772. throw new Error('noUiSlider (' + VERSION + '): \'range\' value isn\'t numeric.');
  2773. }
  2774. // Store values.
  2775. that.xPct.push(percentage);
  2776. that.xVal.push(value[0]);
  2777. // NaN will evaluate to false too, but to keep
  2778. // logging clear, set step explicitly. Make sure
  2779. // not to override the 'step' setting with false.
  2780. if (!percentage) {
  2781. if (!isNaN(value[1])) {
  2782. that.xSteps[0] = value[1];
  2783. }
  2784. } else {
  2785. that.xSteps.push(isNaN(value[1]) ? false : value[1]);
  2786. }
  2787. that.xHighestCompleteStep.push(0);
  2788. }
  2789. function handleStepPoint(i, n, that) {
  2790. // Ignore 'false' stepping.
  2791. if (!n) {
  2792. return true;
  2793. }
  2794. // Factor to range ratio
  2795. that.xSteps[i] = fromPercentage([
  2796. that.xVal[i],
  2797. that.xVal[i + 1]
  2798. ], n) / subRangeRatio(that.xPct[i], that.xPct[i + 1]);
  2799. var totalSteps = (that.xVal[i + 1] - that.xVal[i]) / that.xNumSteps[i];
  2800. var highestStep = Math.ceil(Number(totalSteps.toFixed(3)) - 1);
  2801. var step = that.xVal[i] + that.xNumSteps[i] * highestStep;
  2802. that.xHighestCompleteStep[i] = step;
  2803. }
  2804. // Interface
  2805. function Spectrum(entry, snap, singleStep) {
  2806. this.xPct = [];
  2807. this.xVal = [];
  2808. this.xSteps = [singleStep || false];
  2809. this.xNumSteps = [false];
  2810. this.xHighestCompleteStep = [];
  2811. this.snap = snap;
  2812. var index, ordered = [];
  2813. // Map the object keys to an array.
  2814. for (index in entry) {
  2815. if (entry.hasOwnProperty(index)) {
  2816. ordered.push([
  2817. entry[index],
  2818. index
  2819. ]);
  2820. }
  2821. }
  2822. // Sort all entries by value (numeric sort).
  2823. if (ordered.length && typeof ordered[0][0] === 'object') {
  2824. ordered.sort(function (a, b) {
  2825. return a[0][0] - b[0][0];
  2826. });
  2827. } else {
  2828. ordered.sort(function (a, b) {
  2829. return a[0] - b[0];
  2830. });
  2831. }
  2832. // Convert all entries to subranges.
  2833. for (index = 0; index < ordered.length; index++) {
  2834. handleEntryPoint(ordered[index][1], ordered[index][0], this);
  2835. }
  2836. // Store the actual step values.
  2837. // xSteps is sorted in the same order as xPct and xVal.
  2838. this.xNumSteps = this.xSteps.slice(0);
  2839. // Convert all numeric steps to the percentage of the subrange they represent.
  2840. for (index = 0; index < this.xNumSteps.length; index++) {
  2841. handleStepPoint(index, this.xNumSteps[index], this);
  2842. }
  2843. }
  2844. Spectrum.prototype.getMargin = function (value) {
  2845. var step = this.xNumSteps[0];
  2846. if (step && value / step % 1 !== 0) {
  2847. throw new Error('noUiSlider (' + VERSION + '): \'limit\', \'margin\' and \'padding\' must be divisible by step.');
  2848. }
  2849. return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false;
  2850. };
  2851. Spectrum.prototype.toStepping = function (value) {
  2852. value = toStepping(this.xVal, this.xPct, value);
  2853. return value;
  2854. };
  2855. Spectrum.prototype.fromStepping = function (value) {
  2856. return fromStepping(this.xVal, this.xPct, value);
  2857. };
  2858. Spectrum.prototype.getStep = function (value) {
  2859. value = getStep(this.xPct, this.xSteps, this.snap, value);
  2860. return value;
  2861. };
  2862. Spectrum.prototype.getNearbySteps = function (value) {
  2863. var j = getJ(value, this.xPct);
  2864. return {
  2865. stepBefore: {
  2866. startValue: this.xVal[j - 2],
  2867. step: this.xNumSteps[j - 2],
  2868. highestStep: this.xHighestCompleteStep[j - 2]
  2869. },
  2870. thisStep: {
  2871. startValue: this.xVal[j - 1],
  2872. step: this.xNumSteps[j - 1],
  2873. highestStep: this.xHighestCompleteStep[j - 1]
  2874. },
  2875. stepAfter: {
  2876. startValue: this.xVal[j - 0],
  2877. step: this.xNumSteps[j - 0],
  2878. highestStep: this.xHighestCompleteStep[j - 0]
  2879. }
  2880. };
  2881. };
  2882. Spectrum.prototype.countStepDecimals = function () {
  2883. var stepDecimals = this.xNumSteps.map(countDecimals);
  2884. return Math.max.apply(null, stepDecimals);
  2885. };
  2886. // Outside testing
  2887. Spectrum.prototype.convert = function (value) {
  2888. return this.getStep(this.toStepping(value));
  2889. };
  2890. /* Every input option is tested and parsed. This'll prevent
  2891. endless validation in internal methods. These tests are
  2892. structured with an item for every option available. An
  2893. option can be marked as required by setting the 'r' flag.
  2894. The testing function is provided with three arguments:
  2895. - The provided value for the option;
  2896. - A reference to the options object;
  2897. - The name for the option;
  2898. The testing function returns false when an error is detected,
  2899. or true when everything is OK. It can also modify the option
  2900. object, to make sure all values can be correctly looped elsewhere. */
  2901. var defaultFormatter = {
  2902. 'to': function (value) {
  2903. return value !== undefined && value.toFixed(2);
  2904. },
  2905. 'from': Number
  2906. };
  2907. function validateFormat(entry) {
  2908. // Any object with a to and from method is supported.
  2909. if (isValidFormatter(entry)) {
  2910. return true;
  2911. }
  2912. throw new Error('noUiSlider (' + VERSION + '): \'format\' requires \'to\' and \'from\' methods.');
  2913. }
  2914. function testStep(parsed, entry) {
  2915. if (!isNumeric(entry)) {
  2916. throw new Error('noUiSlider (' + VERSION + '): \'step\' is not numeric.');
  2917. }
  2918. // The step option can still be used to set stepping
  2919. // for linear sliders. Overwritten if set in 'range'.
  2920. parsed.singleStep = entry;
  2921. }
  2922. function testRange(parsed, entry) {
  2923. // Filter incorrect input.
  2924. if (typeof entry !== 'object' || Array.isArray(entry)) {
  2925. throw new Error('noUiSlider (' + VERSION + '): \'range\' is not an object.');
  2926. }
  2927. // Catch missing start or end.
  2928. if (entry.min === undefined || entry.max === undefined) {
  2929. throw new Error('noUiSlider (' + VERSION + '): Missing \'min\' or \'max\' in \'range\'.');
  2930. }
  2931. // Catch equal start or end.
  2932. if (entry.min === entry.max) {
  2933. throw new Error('noUiSlider (' + VERSION + '): \'range\' \'min\' and \'max\' cannot be equal.');
  2934. }
  2935. parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.singleStep);
  2936. }
  2937. function testStart(parsed, entry) {
  2938. entry = asArray(entry);
  2939. // Validate input. Values aren't tested, as the public .val method
  2940. // will always provide a valid location.
  2941. if (!Array.isArray(entry) || !entry.length) {
  2942. throw new Error('noUiSlider (' + VERSION + '): \'start\' option is incorrect.');
  2943. }
  2944. // Store the number of handles.
  2945. parsed.handles = entry.length;
  2946. // When the slider is initialized, the .val method will
  2947. // be called with the start options.
  2948. parsed.start = entry;
  2949. }
  2950. function testSnap(parsed, entry) {
  2951. // Enforce 100% stepping within subranges.
  2952. parsed.snap = entry;
  2953. if (typeof entry !== 'boolean') {
  2954. throw new Error('noUiSlider (' + VERSION + '): \'snap\' option must be a boolean.');
  2955. }
  2956. }
  2957. function testAnimate(parsed, entry) {
  2958. // Enforce 100% stepping within subranges.
  2959. parsed.animate = entry;
  2960. if (typeof entry !== 'boolean') {
  2961. throw new Error('noUiSlider (' + VERSION + '): \'animate\' option must be a boolean.');
  2962. }
  2963. }
  2964. function testAnimationDuration(parsed, entry) {
  2965. parsed.animationDuration = entry;
  2966. if (typeof entry !== 'number') {
  2967. throw new Error('noUiSlider (' + VERSION + '): \'animationDuration\' option must be a number.');
  2968. }
  2969. }
  2970. function testConnect(parsed, entry) {
  2971. var connect = [false];
  2972. var i;
  2973. // Map legacy options
  2974. if (entry === 'lower') {
  2975. entry = [
  2976. true,
  2977. false
  2978. ];
  2979. } else if (entry === 'upper') {
  2980. entry = [
  2981. false,
  2982. true
  2983. ];
  2984. }
  2985. // Handle boolean options
  2986. if (entry === true || entry === false) {
  2987. for (i = 1; i < parsed.handles; i++) {
  2988. connect.push(entry);
  2989. }
  2990. connect.push(false);
  2991. } // Reject invalid input
  2992. else if (!Array.isArray(entry) || !entry.length || entry.length !== parsed.handles + 1) {
  2993. throw new Error('noUiSlider (' + VERSION + '): \'connect\' option doesn\'t match handle count.');
  2994. } else {
  2995. connect = entry;
  2996. }
  2997. parsed.connect = connect;
  2998. }
  2999. function testOrientation(parsed, entry) {
  3000. // Set orientation to an a numerical value for easy
  3001. // array selection.
  3002. switch (entry) {
  3003. case 'horizontal':
  3004. parsed.ort = 0;
  3005. break;
  3006. case 'vertical':
  3007. parsed.ort = 1;
  3008. break;
  3009. default:
  3010. throw new Error('noUiSlider (' + VERSION + '): \'orientation\' option is invalid.');
  3011. }
  3012. }
  3013. function testMargin(parsed, entry) {
  3014. if (!isNumeric(entry)) {
  3015. throw new Error('noUiSlider (' + VERSION + '): \'margin\' option must be numeric.');
  3016. }
  3017. // Issue #582
  3018. if (entry === 0) {
  3019. return;
  3020. }
  3021. parsed.margin = parsed.spectrum.getMargin(entry);
  3022. if (!parsed.margin) {
  3023. throw new Error('noUiSlider (' + VERSION + '): \'margin\' option is only supported on linear sliders.');
  3024. }
  3025. }
  3026. function testLimit(parsed, entry) {
  3027. if (!isNumeric(entry)) {
  3028. throw new Error('noUiSlider (' + VERSION + '): \'limit\' option must be numeric.');
  3029. }
  3030. parsed.limit = parsed.spectrum.getMargin(entry);
  3031. if (!parsed.limit || parsed.handles < 2) {
  3032. throw new Error('noUiSlider (' + VERSION + '): \'limit\' option is only supported on linear sliders with 2 or more handles.');
  3033. }
  3034. }
  3035. function testPadding(parsed, entry) {
  3036. if (!isNumeric(entry)) {
  3037. throw new Error('noUiSlider (' + VERSION + '): \'padding\' option must be numeric.');
  3038. }
  3039. if (entry === 0) {
  3040. return;
  3041. }
  3042. parsed.padding = parsed.spectrum.getMargin(entry);
  3043. if (!parsed.padding) {
  3044. throw new Error('noUiSlider (' + VERSION + '): \'padding\' option is only supported on linear sliders.');
  3045. }
  3046. if (parsed.padding < 0) {
  3047. throw new Error('noUiSlider (' + VERSION + '): \'padding\' option must be a positive number.');
  3048. }
  3049. if (parsed.padding >= 50) {
  3050. throw new Error('noUiSlider (' + VERSION + '): \'padding\' option must be less than half the range.');
  3051. }
  3052. }
  3053. function testDirection(parsed, entry) {
  3054. // Set direction as a numerical value for easy parsing.
  3055. // Invert connection for RTL sliders, so that the proper
  3056. // handles get the connect/background classes.
  3057. switch (entry) {
  3058. case 'ltr':
  3059. parsed.dir = 0;
  3060. break;
  3061. case 'rtl':
  3062. parsed.dir = 1;
  3063. break;
  3064. default:
  3065. throw new Error('noUiSlider (' + VERSION + '): \'direction\' option was not recognized.');
  3066. }
  3067. }
  3068. function testBehaviour(parsed, entry) {
  3069. // Make sure the input is a string.
  3070. if (typeof entry !== 'string') {
  3071. throw new Error('noUiSlider (' + VERSION + '): \'behaviour\' must be a string containing options.');
  3072. }
  3073. // Check if the string contains any keywords.
  3074. // None are required.
  3075. var tap = entry.indexOf('tap') >= 0;
  3076. var drag = entry.indexOf('drag') >= 0;
  3077. var fixed = entry.indexOf('fixed') >= 0;
  3078. var snap = entry.indexOf('snap') >= 0;
  3079. var hover = entry.indexOf('hover') >= 0;
  3080. if (fixed) {
  3081. if (parsed.handles !== 2) {
  3082. throw new Error('noUiSlider (' + VERSION + '): \'fixed\' behaviour must be used with 2 handles');
  3083. }
  3084. // Use margin to enforce fixed state
  3085. testMargin(parsed, parsed.start[1] - parsed.start[0]);
  3086. }
  3087. parsed.events = {
  3088. tap: tap || snap,
  3089. drag: drag,
  3090. fixed: fixed,
  3091. snap: snap,
  3092. hover: hover
  3093. };
  3094. }
  3095. function testMultitouch(parsed, entry) {
  3096. parsed.multitouch = entry;
  3097. if (typeof entry !== 'boolean') {
  3098. throw new Error('noUiSlider (' + VERSION + '): \'multitouch\' option must be a boolean.');
  3099. }
  3100. }
  3101. function testTooltips(parsed, entry) {
  3102. if (entry === false) {
  3103. return;
  3104. } else if (entry === true) {
  3105. parsed.tooltips = [];
  3106. for (var i = 0; i < parsed.handles; i++) {
  3107. parsed.tooltips.push(true);
  3108. }
  3109. } else {
  3110. parsed.tooltips = asArray(entry);
  3111. if (parsed.tooltips.length !== parsed.handles) {
  3112. throw new Error('noUiSlider (' + VERSION + '): must pass a formatter for all handles.');
  3113. }
  3114. parsed.tooltips.forEach(function (formatter) {
  3115. if (typeof formatter !== 'boolean' && (typeof formatter !== 'object' || typeof formatter.to !== 'function')) {
  3116. throw new Error('noUiSlider (' + VERSION + '): \'tooltips\' must be passed a formatter or \'false\'.');
  3117. }
  3118. });
  3119. }
  3120. }
  3121. function testAriaFormat(parsed, entry) {
  3122. parsed.ariaFormat = entry;
  3123. validateFormat(entry);
  3124. }
  3125. function testFormat(parsed, entry) {
  3126. parsed.format = entry;
  3127. validateFormat(entry);
  3128. }
  3129. function testCssPrefix(parsed, entry) {
  3130. if (entry !== undefined && typeof entry !== 'string' && entry !== false) {
  3131. throw new Error('noUiSlider (' + VERSION + '): \'cssPrefix\' must be a string or `false`.');
  3132. }
  3133. parsed.cssPrefix = entry;
  3134. }
  3135. function testCssClasses(parsed, entry) {
  3136. if (entry !== undefined && typeof entry !== 'object') {
  3137. throw new Error('noUiSlider (' + VERSION + '): \'cssClasses\' must be an object.');
  3138. }
  3139. if (typeof parsed.cssPrefix === 'string') {
  3140. parsed.cssClasses = {};
  3141. for (var key in entry) {
  3142. if (!entry.hasOwnProperty(key)) {
  3143. continue;
  3144. }
  3145. parsed.cssClasses[key] = parsed.cssPrefix + entry[key];
  3146. }
  3147. } else {
  3148. parsed.cssClasses = entry;
  3149. }
  3150. }
  3151. function testUseRaf(parsed, entry) {
  3152. if (entry === true || entry === false) {
  3153. parsed.useRequestAnimationFrame = entry;
  3154. } else {
  3155. throw new Error('noUiSlider (' + VERSION + '): \'useRequestAnimationFrame\' option should be true (default) or false.');
  3156. }
  3157. }
  3158. // Test all developer settings and parse to assumption-safe values.
  3159. function testOptions(options) {
  3160. // To prove a fix for #537, freeze options here.
  3161. // If the object is modified, an error will be thrown.
  3162. // Object.freeze(options);
  3163. var parsed = {
  3164. margin: 0,
  3165. limit: 0,
  3166. padding: 0,
  3167. animate: true,
  3168. animationDuration: 300,
  3169. ariaFormat: defaultFormatter,
  3170. format: defaultFormatter
  3171. };
  3172. // Tests are executed in the order they are presented here.
  3173. var tests = {
  3174. 'step': {
  3175. r: false,
  3176. t: testStep
  3177. },
  3178. 'start': {
  3179. r: true,
  3180. t: testStart
  3181. },
  3182. 'connect': {
  3183. r: true,
  3184. t: testConnect
  3185. },
  3186. 'direction': {
  3187. r: true,
  3188. t: testDirection
  3189. },
  3190. 'snap': {
  3191. r: false,
  3192. t: testSnap
  3193. },
  3194. 'animate': {
  3195. r: false,
  3196. t: testAnimate
  3197. },
  3198. 'animationDuration': {
  3199. r: false,
  3200. t: testAnimationDuration
  3201. },
  3202. 'range': {
  3203. r: true,
  3204. t: testRange
  3205. },
  3206. 'orientation': {
  3207. r: false,
  3208. t: testOrientation
  3209. },
  3210. 'margin': {
  3211. r: false,
  3212. t: testMargin
  3213. },
  3214. 'limit': {
  3215. r: false,
  3216. t: testLimit
  3217. },
  3218. 'padding': {
  3219. r: false,
  3220. t: testPadding
  3221. },
  3222. 'behaviour': {
  3223. r: true,
  3224. t: testBehaviour
  3225. },
  3226. 'multitouch': {
  3227. r: true,
  3228. t: testMultitouch
  3229. },
  3230. 'ariaFormat': {
  3231. r: false,
  3232. t: testAriaFormat
  3233. },
  3234. 'format': {
  3235. r: false,
  3236. t: testFormat
  3237. },
  3238. 'tooltips': {
  3239. r: false,
  3240. t: testTooltips
  3241. },
  3242. 'cssPrefix': {
  3243. r: false,
  3244. t: testCssPrefix
  3245. },
  3246. 'cssClasses': {
  3247. r: false,
  3248. t: testCssClasses
  3249. },
  3250. 'useRequestAnimationFrame': {
  3251. r: false,
  3252. t: testUseRaf
  3253. }
  3254. };
  3255. var defaults = {
  3256. 'connect': false,
  3257. 'direction': 'ltr',
  3258. 'behaviour': 'tap',
  3259. 'multitouch': false,
  3260. 'orientation': 'horizontal',
  3261. 'cssPrefix': 'noUi-',
  3262. 'cssClasses': {
  3263. target: 'target',
  3264. base: 'base',
  3265. origin: 'origin',
  3266. handle: 'handle',
  3267. handleLower: 'handle-lower',
  3268. handleUpper: 'handle-upper',
  3269. horizontal: 'horizontal',
  3270. vertical: 'vertical',
  3271. background: 'background',
  3272. connect: 'connect',
  3273. ltr: 'ltr',
  3274. rtl: 'rtl',
  3275. draggable: 'draggable',
  3276. drag: 'state-drag',
  3277. tap: 'state-tap',
  3278. active: 'active',
  3279. tooltip: 'tooltip',
  3280. pips: 'pips',
  3281. pipsHorizontal: 'pips-horizontal',
  3282. pipsVertical: 'pips-vertical',
  3283. marker: 'marker',
  3284. markerHorizontal: 'marker-horizontal',
  3285. markerVertical: 'marker-vertical',
  3286. markerNormal: 'marker-normal',
  3287. markerLarge: 'marker-large',
  3288. markerSub: 'marker-sub',
  3289. value: 'value',
  3290. valueHorizontal: 'value-horizontal',
  3291. valueVertical: 'value-vertical',
  3292. valueNormal: 'value-normal',
  3293. valueLarge: 'value-large',
  3294. valueSub: 'value-sub'
  3295. },
  3296. 'useRequestAnimationFrame': true
  3297. };
  3298. // AriaFormat defaults to regular format, if any.
  3299. if (options.format && !options.ariaFormat) {
  3300. options.ariaFormat = options.format;
  3301. }
  3302. // Run all options through a testing mechanism to ensure correct
  3303. // input. It should be noted that options might get modified to
  3304. // be handled properly. E.g. wrapping integers in arrays.
  3305. Object.keys(tests).forEach(function (name) {
  3306. // If the option isn't set, but it is required, throw an error.
  3307. if (options[name] === undefined && defaults[name] === undefined) {
  3308. if (tests[name].r) {
  3309. throw new Error('noUiSlider (' + VERSION + '): \'' + name + '\' is required.');
  3310. }
  3311. return true;
  3312. }
  3313. tests[name].t(parsed, options[name] === undefined ? defaults[name] : options[name]);
  3314. });
  3315. // Forward pips options
  3316. parsed.pips = options.pips;
  3317. var styles = [
  3318. [
  3319. 'left',
  3320. 'top'
  3321. ],
  3322. [
  3323. 'right',
  3324. 'bottom'
  3325. ]
  3326. ];
  3327. // Pre-define the styles.
  3328. parsed.style = styles[parsed.dir][parsed.ort];
  3329. parsed.styleOposite = styles[parsed.dir ? 0 : 1][parsed.ort];
  3330. return parsed;
  3331. }
  3332. function closure(target, options, originalOptions) {
  3333. var actions = getActions();
  3334. var supportsTouchActionNone = getSupportsTouchActionNone();
  3335. var supportsPassive = supportsTouchActionNone && getSupportsPassive();
  3336. // All variables local to 'closure' are prefixed with 'scope_'
  3337. var scope_Target = target;
  3338. var scope_Locations = [];
  3339. var scope_Base;
  3340. var scope_Handles;
  3341. var scope_HandleNumbers = [];
  3342. var scope_ActiveHandlesCount = 0;
  3343. var scope_Connects;
  3344. var scope_Spectrum = options.spectrum;
  3345. var scope_Values = [];
  3346. var scope_Events = {};
  3347. var scope_Self;
  3348. var scope_Pips;
  3349. var scope_Document = target.ownerDocument;
  3350. var scope_DocumentElement = scope_Document.documentElement;
  3351. var scope_Body = scope_Document.body;
  3352. // Creates a node, adds it to target, returns the new node.
  3353. function addNodeTo(target, className) {
  3354. var div = scope_Document.createElement('div');
  3355. if (className) {
  3356. addClass(div, className);
  3357. }
  3358. target.appendChild(div);
  3359. return div;
  3360. }
  3361. // Append a origin to the base
  3362. function addOrigin(base, handleNumber) {
  3363. var origin = addNodeTo(base, options.cssClasses.origin);
  3364. var handle = addNodeTo(origin, options.cssClasses.handle);
  3365. handle.setAttribute('data-handle', handleNumber);
  3366. // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
  3367. // 0 = focusable and reachable
  3368. handle.setAttribute('tabindex', '0');
  3369. handle.setAttribute('role', 'slider');
  3370. handle.setAttribute('aria-orientation', options.ort ? 'vertical' : 'horizontal');
  3371. if (handleNumber === 0) {
  3372. addClass(handle, options.cssClasses.handleLower);
  3373. } else if (handleNumber === options.handles - 1) {
  3374. addClass(handle, options.cssClasses.handleUpper);
  3375. }
  3376. return origin;
  3377. }
  3378. // Insert nodes for connect elements
  3379. function addConnect(base, add) {
  3380. if (!add) {
  3381. return false;
  3382. }
  3383. return addNodeTo(base, options.cssClasses.connect);
  3384. }
  3385. // Add handles to the slider base.
  3386. function addElements(connectOptions, base) {
  3387. scope_Handles = [];
  3388. scope_Connects = [];
  3389. scope_Connects.push(addConnect(base, connectOptions[0]));
  3390. // [::::O====O====O====]
  3391. // connectOptions = [0, 1, 1, 1]
  3392. for (var i = 0; i < options.handles; i++) {
  3393. // Keep a list of all added handles.
  3394. scope_Handles.push(addOrigin(base, i));
  3395. scope_HandleNumbers[i] = i;
  3396. scope_Connects.push(addConnect(base, connectOptions[i + 1]));
  3397. }
  3398. }
  3399. // Initialize a single slider.
  3400. function addSlider(target) {
  3401. // Apply classes and data to the target.
  3402. addClass(target, options.cssClasses.target);
  3403. if (options.dir === 0) {
  3404. addClass(target, options.cssClasses.ltr);
  3405. } else {
  3406. addClass(target, options.cssClasses.rtl);
  3407. }
  3408. if (options.ort === 0) {
  3409. addClass(target, options.cssClasses.horizontal);
  3410. } else {
  3411. addClass(target, options.cssClasses.vertical);
  3412. }
  3413. scope_Base = addNodeTo(target, options.cssClasses.base);
  3414. }
  3415. function addTooltip(handle, handleNumber) {
  3416. if (!options.tooltips[handleNumber]) {
  3417. return false;
  3418. }
  3419. return addNodeTo(handle.firstChild, options.cssClasses.tooltip);
  3420. }
  3421. // The tooltips option is a shorthand for using the 'update' event.
  3422. function tooltips() {
  3423. // Tooltips are added with options.tooltips in original order.
  3424. var tips = scope_Handles.map(addTooltip);
  3425. bindEvent('update', function (values, handleNumber, unencoded) {
  3426. if (!tips[handleNumber]) {
  3427. return;
  3428. }
  3429. var formattedValue = values[handleNumber];
  3430. if (options.tooltips[handleNumber] !== true) {
  3431. formattedValue = options.tooltips[handleNumber].to(unencoded[handleNumber]);
  3432. }
  3433. tips[handleNumber].innerHTML = formattedValue;
  3434. });
  3435. }
  3436. function aria() {
  3437. bindEvent('update', function (values, handleNumber, unencoded, tap, positions) {
  3438. // Update Aria Values for all handles, as a change in one changes min and max values for the next.
  3439. scope_HandleNumbers.forEach(function (handleNumber) {
  3440. var handle = scope_Handles[handleNumber];
  3441. var min = checkHandlePosition(scope_Locations, handleNumber, 0, true, true, true);
  3442. var max = checkHandlePosition(scope_Locations, handleNumber, 100, true, true, true);
  3443. var now = positions[handleNumber];
  3444. var text = options.ariaFormat.to(unencoded[handleNumber]);
  3445. handle.children[0].setAttribute('aria-valuemin', min.toFixed(1));
  3446. handle.children[0].setAttribute('aria-valuemax', max.toFixed(1));
  3447. handle.children[0].setAttribute('aria-valuenow', now.toFixed(1));
  3448. handle.children[0].setAttribute('aria-valuetext', text);
  3449. });
  3450. });
  3451. }
  3452. function getGroup(mode, values, stepped) {
  3453. // Use the range.
  3454. if (mode === 'range' || mode === 'steps') {
  3455. return scope_Spectrum.xVal;
  3456. }
  3457. if (mode === 'count') {
  3458. if (!values) {
  3459. throw new Error('noUiSlider (' + VERSION + '): \'values\' required for mode \'count\'.');
  3460. }
  3461. // Divide 0 - 100 in 'count' parts.
  3462. var spread = 100 / (values - 1);
  3463. var v;
  3464. var i = 0;
  3465. values = [];
  3466. // List these parts and have them handled as 'positions'.
  3467. while ((v = i++ * spread) <= 100) {
  3468. values.push(v);
  3469. }
  3470. mode = 'positions';
  3471. }
  3472. if (mode === 'positions') {
  3473. // Map all percentages to on-range values.
  3474. return values.map(function (value) {
  3475. return scope_Spectrum.fromStepping(stepped ? scope_Spectrum.getStep(value) : value);
  3476. });
  3477. }
  3478. if (mode === 'values') {
  3479. // If the value must be stepped, it needs to be converted to a percentage first.
  3480. if (stepped) {
  3481. return values.map(function (value) {
  3482. // Convert to percentage, apply step, return to value.
  3483. return scope_Spectrum.fromStepping(scope_Spectrum.getStep(scope_Spectrum.toStepping(value)));
  3484. });
  3485. }
  3486. // Otherwise, we can simply use the values.
  3487. return values;
  3488. }
  3489. }
  3490. function generateSpread(density, mode, group) {
  3491. function safeIncrement(value, increment) {
  3492. // Avoid floating point variance by dropping the smallest decimal places.
  3493. return (value + increment).toFixed(7) / 1;
  3494. }
  3495. var indexes = {};
  3496. var firstInRange = scope_Spectrum.xVal[0];
  3497. var lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length - 1];
  3498. var ignoreFirst = false;
  3499. var ignoreLast = false;
  3500. var prevPct = 0;
  3501. // Create a copy of the group, sort it and filter away all duplicates.
  3502. group = unique(group.slice().sort(function (a, b) {
  3503. return a - b;
  3504. }));
  3505. // Make sure the range starts with the first element.
  3506. if (group[0] !== firstInRange) {
  3507. group.unshift(firstInRange);
  3508. ignoreFirst = true;
  3509. }
  3510. // Likewise for the last one.
  3511. if (group[group.length - 1] !== lastInRange) {
  3512. group.push(lastInRange);
  3513. ignoreLast = true;
  3514. }
  3515. group.forEach(function (current, index) {
  3516. // Get the current step and the lower + upper positions.
  3517. var step;
  3518. var i;
  3519. var q;
  3520. var low = current;
  3521. var high = group[index + 1];
  3522. var newPct;
  3523. var pctDifference;
  3524. var pctPos;
  3525. var type;
  3526. var steps;
  3527. var realSteps;
  3528. var stepsize;
  3529. // When using 'steps' mode, use the provided steps.
  3530. // Otherwise, we'll step on to the next subrange.
  3531. if (mode === 'steps') {
  3532. step = scope_Spectrum.xNumSteps[index];
  3533. }
  3534. // Default to a 'full' step.
  3535. if (!step) {
  3536. step = high - low;
  3537. }
  3538. // Low can be 0, so test for false. If high is undefined,
  3539. // we are at the last subrange. Index 0 is already handled.
  3540. if (low === false || high === undefined) {
  3541. return;
  3542. }
  3543. // Make sure step isn't 0, which would cause an infinite loop (#654)
  3544. step = Math.max(step, 1e-7);
  3545. // Find all steps in the subrange.
  3546. for (i = low; i <= high; i = safeIncrement(i, step)) {
  3547. // Get the percentage value for the current step,
  3548. // calculate the size for the subrange.
  3549. newPct = scope_Spectrum.toStepping(i);
  3550. pctDifference = newPct - prevPct;
  3551. steps = pctDifference / density;
  3552. realSteps = Math.round(steps);
  3553. // This ratio represents the ammount of percentage-space a point indicates.
  3554. // For a density 1 the points/percentage = 1. For density 2, that percentage needs to be re-devided.
  3555. // Round the percentage offset to an even number, then divide by two
  3556. // to spread the offset on both sides of the range.
  3557. stepsize = pctDifference / realSteps;
  3558. // Divide all points evenly, adding the correct number to this subrange.
  3559. // Run up to <= so that 100% gets a point, event if ignoreLast is set.
  3560. for (q = 1; q <= realSteps; q += 1) {
  3561. // The ratio between the rounded value and the actual size might be ~1% off.
  3562. // Correct the percentage offset by the number of points
  3563. // per subrange. density = 1 will result in 100 points on the
  3564. // full range, 2 for 50, 4 for 25, etc.
  3565. pctPos = prevPct + q * stepsize;
  3566. indexes[pctPos.toFixed(5)] = [
  3567. 'x',
  3568. 0
  3569. ];
  3570. }
  3571. // Determine the point type.
  3572. type = group.indexOf(i) > -1 ? 1 : mode === 'steps' ? 2 : 0;
  3573. // Enforce the 'ignoreFirst' option by overwriting the type for 0.
  3574. if (!index && ignoreFirst) {
  3575. type = 0;
  3576. }
  3577. if (!(i === high && ignoreLast)) {
  3578. // Mark the 'type' of this point. 0 = plain, 1 = real value, 2 = step value.
  3579. indexes[newPct.toFixed(5)] = [
  3580. i,
  3581. type
  3582. ];
  3583. }
  3584. // Update the percentage count.
  3585. prevPct = newPct;
  3586. }
  3587. });
  3588. return indexes;
  3589. }
  3590. function addMarking(spread, filterFunc, formatter) {
  3591. var element = scope_Document.createElement('div');
  3592. var valueSizeClasses = [
  3593. options.cssClasses.valueNormal,
  3594. options.cssClasses.valueLarge,
  3595. options.cssClasses.valueSub
  3596. ];
  3597. var markerSizeClasses = [
  3598. options.cssClasses.markerNormal,
  3599. options.cssClasses.markerLarge,
  3600. options.cssClasses.markerSub
  3601. ];
  3602. var valueOrientationClasses = [
  3603. options.cssClasses.valueHorizontal,
  3604. options.cssClasses.valueVertical
  3605. ];
  3606. var markerOrientationClasses = [
  3607. options.cssClasses.markerHorizontal,
  3608. options.cssClasses.markerVertical
  3609. ];
  3610. addClass(element, options.cssClasses.pips);
  3611. addClass(element, options.ort === 0 ? options.cssClasses.pipsHorizontal : options.cssClasses.pipsVertical);
  3612. function getClasses(type, source) {
  3613. var a = source === options.cssClasses.value;
  3614. var orientationClasses = a ? valueOrientationClasses : markerOrientationClasses;
  3615. var sizeClasses = a ? valueSizeClasses : markerSizeClasses;
  3616. return source + ' ' + orientationClasses[options.ort] + ' ' + sizeClasses[type];
  3617. }
  3618. function addSpread(offset, values) {
  3619. // Apply the filter function, if it is set.
  3620. values[1] = values[1] && filterFunc ? filterFunc(values[0], values[1]) : values[1];
  3621. // Add a marker for every point
  3622. var node = addNodeTo(element, false);
  3623. node.className = getClasses(values[1], options.cssClasses.marker);
  3624. node.style[options.style] = offset + '%';
  3625. // Values are only appended for points marked '1' or '2'.
  3626. if (values[1]) {
  3627. node = addNodeTo(element, false);
  3628. node.className = getClasses(values[1], options.cssClasses.value);
  3629. node.style[options.style] = offset + '%';
  3630. node.innerText = formatter.to(values[0]);
  3631. }
  3632. }
  3633. // Append all points.
  3634. Object.keys(spread).forEach(function (a) {
  3635. addSpread(a, spread[a]);
  3636. });
  3637. return element;
  3638. }
  3639. function removePips() {
  3640. if (scope_Pips) {
  3641. removeElement(scope_Pips);
  3642. scope_Pips = null;
  3643. }
  3644. }
  3645. function pips(grid) {
  3646. // Fix #669
  3647. removePips();
  3648. var mode = grid.mode;
  3649. var density = grid.density || 1;
  3650. var filter = grid.filter || false;
  3651. var values = grid.values || false;
  3652. var stepped = grid.stepped || false;
  3653. var group = getGroup(mode, values, stepped);
  3654. var spread = generateSpread(density, mode, group);
  3655. var format = grid.format || { to: Math.round };
  3656. scope_Pips = scope_Target.appendChild(addMarking(spread, filter, format));
  3657. return scope_Pips;
  3658. }
  3659. // Shorthand for base dimensions.
  3660. function baseSize() {
  3661. var rect = scope_Base.getBoundingClientRect(), alt = 'offset' + [
  3662. 'Width',
  3663. 'Height'
  3664. ][options.ort];
  3665. return options.ort === 0 ? rect.width || scope_Base[alt] : rect.height || scope_Base[alt];
  3666. }
  3667. // Handler for attaching events trough a proxy.
  3668. function attachEvent(events, element, callback, data) {
  3669. // This function can be used to 'filter' events to the slider.
  3670. // element is a node, not a nodeList
  3671. var method = function (e) {
  3672. if (scope_Target.hasAttribute('disabled')) {
  3673. return false;
  3674. }
  3675. // Stop if an active 'tap' transition is taking place.
  3676. if (hasClass(scope_Target, options.cssClasses.tap)) {
  3677. return false;
  3678. }
  3679. e = fixEvent(e, data.pageOffset, data.target || element);
  3680. // Handle reject of multitouch
  3681. if (!e) {
  3682. return false;
  3683. }
  3684. // Ignore right or middle clicks on start #454
  3685. if (events === actions.start && e.buttons !== undefined && e.buttons > 1) {
  3686. return false;
  3687. }
  3688. // Ignore right or middle clicks on start #454
  3689. if (data.hover && e.buttons) {
  3690. return false;
  3691. }
  3692. // 'supportsPassive' is only true if a browser also supports touch-action: none in CSS.
  3693. // iOS safari does not, so it doesn't get to benefit from passive scrolling. iOS does support
  3694. // touch-action: manipulation, but that allows panning, which breaks
  3695. // sliders after zooming/on non-responsive pages.
  3696. // See: https://bugs.webkit.org/show_bug.cgi?id=133112
  3697. if (!supportsPassive) {
  3698. e.preventDefault();
  3699. }
  3700. e.calcPoint = e.points[options.ort];
  3701. // Call the event handler with the event [ and additional data ].
  3702. callback(e, data);
  3703. };
  3704. var methods = [];
  3705. // Bind a closure on the target for every event type.
  3706. events.split(' ').forEach(function (eventName) {
  3707. element.addEventListener(eventName, method, supportsPassive ? { passive: true } : false);
  3708. methods.push([
  3709. eventName,
  3710. method
  3711. ]);
  3712. });
  3713. return methods;
  3714. }
  3715. // Provide a clean event with standardized offset values.
  3716. function fixEvent(e, pageOffset, target) {
  3717. // Filter the event to register the type, which can be
  3718. // touch, mouse or pointer. Offset changes need to be
  3719. // made on an event specific basis.
  3720. var touch = e.type.indexOf('touch') === 0;
  3721. var mouse = e.type.indexOf('mouse') === 0;
  3722. var pointer = e.type.indexOf('pointer') === 0;
  3723. var x;
  3724. var y;
  3725. // IE10 implemented pointer events with a prefix;
  3726. if (e.type.indexOf('MSPointer') === 0) {
  3727. pointer = true;
  3728. }
  3729. // In the event that multitouch is activated, the only thing one handle should be concerned
  3730. // about is the touches that originated on top of it.
  3731. if (touch && options.multitouch) {
  3732. // Returns true if a touch originated on the target.
  3733. var isTouchOnTarget = function (touch) {
  3734. return touch.target === target || target.contains(touch.target);
  3735. };
  3736. // In the case of touchstart events, we need to make sure there is still no more than one
  3737. // touch on the target so we look amongst all touches.
  3738. if (e.type === 'touchstart') {
  3739. var targetTouches = Array.prototype.filter.call(e.touches, isTouchOnTarget);
  3740. // Do not support more than one touch per handle.
  3741. if (targetTouches.length > 1) {
  3742. return false;
  3743. }
  3744. x = targetTouches[0].pageX;
  3745. y = targetTouches[0].pageY;
  3746. } else {
  3747. // In the other cases, find on changedTouches is enough.
  3748. var targetTouch = Array.prototype.find.call(e.changedTouches, isTouchOnTarget);
  3749. // Cancel if the target touch has not moved.
  3750. if (!targetTouch) {
  3751. return false;
  3752. }
  3753. x = targetTouch.pageX;
  3754. y = targetTouch.pageY;
  3755. }
  3756. } else if (touch) {
  3757. // Fix bug when user touches with two or more fingers on mobile devices.
  3758. // It's useful when you have two or more sliders on one page,
  3759. // that can be touched simultaneously.
  3760. // #649, #663, #668
  3761. if (e.touches.length > 1) {
  3762. return false;
  3763. }
  3764. // noUiSlider supports one movement at a time,
  3765. // so we can select the first 'changedTouch'.
  3766. x = e.changedTouches[0].pageX;
  3767. y = e.changedTouches[0].pageY;
  3768. }
  3769. pageOffset = pageOffset || getPageOffset(scope_Document);
  3770. if (mouse || pointer) {
  3771. x = e.clientX + pageOffset.x;
  3772. y = e.clientY + pageOffset.y;
  3773. }
  3774. e.pageOffset = pageOffset;
  3775. e.points = [
  3776. x,
  3777. y
  3778. ];
  3779. e.cursor = mouse || pointer;
  3780. // Fix #435
  3781. return e;
  3782. }
  3783. // Translate a coordinate in the document to a percentage on the slider
  3784. function calcPointToPercentage(calcPoint) {
  3785. var location = calcPoint - offset(scope_Base, options.ort);
  3786. var proposal = location * 100 / baseSize();
  3787. return options.dir ? 100 - proposal : proposal;
  3788. }
  3789. // Find handle closest to a certain percentage on the slider
  3790. function getClosestHandle(proposal) {
  3791. var closest = 100;
  3792. var handleNumber = false;
  3793. scope_Handles.forEach(function (handle, index) {
  3794. // Disabled handles are ignored
  3795. if (handle.hasAttribute('disabled')) {
  3796. return;
  3797. }
  3798. var pos = Math.abs(scope_Locations[index] - proposal);
  3799. if (pos < closest) {
  3800. handleNumber = index;
  3801. closest = pos;
  3802. }
  3803. });
  3804. return handleNumber;
  3805. }
  3806. // Moves handle(s) by a percentage
  3807. // (bool, % to move, [% where handle started, ...], [index in scope_Handles, ...])
  3808. function moveHandles(upward, proposal, locations, handleNumbers) {
  3809. var proposals = locations.slice();
  3810. var b = [
  3811. !upward,
  3812. upward
  3813. ];
  3814. var f = [
  3815. upward,
  3816. !upward
  3817. ];
  3818. // Copy handleNumbers so we don't change the dataset
  3819. handleNumbers = handleNumbers.slice();
  3820. // Check to see which handle is 'leading'.
  3821. // If that one can't move the second can't either.
  3822. if (upward) {
  3823. handleNumbers.reverse();
  3824. }
  3825. // Step 1: get the maximum percentage that any of the handles can move
  3826. if (handleNumbers.length > 1) {
  3827. handleNumbers.forEach(function (handleNumber, o) {
  3828. var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false);
  3829. // Stop if one of the handles can't move.
  3830. if (to === false) {
  3831. proposal = 0;
  3832. } else {
  3833. proposal = to - proposals[handleNumber];
  3834. proposals[handleNumber] = to;
  3835. }
  3836. });
  3837. } // If using one handle, check backward AND forward
  3838. else {
  3839. b = f = [true];
  3840. }
  3841. var state = false;
  3842. // Step 2: Try to set the handles with the found percentage
  3843. handleNumbers.forEach(function (handleNumber, o) {
  3844. state = setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o]) || state;
  3845. });
  3846. // Step 3: If a handle moved, fire events
  3847. if (state) {
  3848. handleNumbers.forEach(function (handleNumber) {
  3849. fireEvent('update', handleNumber);
  3850. fireEvent('slide', handleNumber);
  3851. });
  3852. }
  3853. }
  3854. // External event handling
  3855. function fireEvent(eventName, handleNumber, tap) {
  3856. Object.keys(scope_Events).forEach(function (targetEvent) {
  3857. var eventType = targetEvent.split('.')[0];
  3858. if (eventName === eventType) {
  3859. scope_Events[targetEvent].forEach(function (callback) {
  3860. callback.call(// Use the slider public API as the scope ('this')
  3861. scope_Self, // Return values as array, so arg_1[arg_2] is always valid.
  3862. scope_Values.map(options.format.to), // Handle index, 0 or 1
  3863. handleNumber, // Unformatted slider values
  3864. scope_Values.slice(), // Event is fired by tap, true or false
  3865. tap || false, // Left offset of the handle, in relation to the slider
  3866. scope_Locations.slice());
  3867. });
  3868. }
  3869. });
  3870. }
  3871. // Fire 'end' when a mouse or pen leaves the document.
  3872. function documentLeave(event, data) {
  3873. if (event.type === 'mouseout' && event.target.nodeName === 'HTML' && event.relatedTarget === null) {
  3874. eventEnd(event, data);
  3875. }
  3876. }
  3877. // Handle movement on document for handle and range drag.
  3878. function eventMove(event, data) {
  3879. // Fix #498
  3880. // Check value of .buttons in 'start' to work around a bug in IE10 mobile (data.buttonsProperty).
  3881. // https://connect.microsoft.com/IE/feedback/details/927005/mobile-ie10-windows-phone-buttons-property-of-pointermove-event-always-zero
  3882. // IE9 has .buttons and .which zero on mousemove.
  3883. // Firefox breaks the spec MDN defines.
  3884. if (navigator.appVersion.indexOf('MSIE 9') === -1 && event.buttons === 0 && data.buttonsProperty !== 0) {
  3885. return eventEnd(event, data);
  3886. }
  3887. // Check if we are moving up or down
  3888. var movement = (options.dir ? -1 : 1) * (event.calcPoint - data.startCalcPoint);
  3889. // Convert the movement into a percentage of the slider width/height
  3890. var proposal = movement * 100 / data.baseSize;
  3891. moveHandles(movement > 0, proposal, data.locations, data.handleNumbers);
  3892. }
  3893. // Unbind move events on document, call callbacks.
  3894. function eventEnd(event, data) {
  3895. // The handle is no longer active, so remove the class.
  3896. if (data.handle) {
  3897. removeClass(data.handle, options.cssClasses.active);
  3898. scope_ActiveHandlesCount -= 1;
  3899. }
  3900. // Unbind the move and end events, which are added on 'start'.
  3901. data.listeners.forEach(function (c) {
  3902. scope_DocumentElement.removeEventListener(c[0], c[1]);
  3903. });
  3904. if (scope_ActiveHandlesCount === 0) {
  3905. // Remove dragging class.
  3906. removeClass(scope_Target, options.cssClasses.drag);
  3907. setZindex();
  3908. // Remove cursor styles and text-selection events bound to the body.
  3909. if (event.cursor) {
  3910. scope_Body.style.cursor = '';
  3911. scope_Body.removeEventListener('selectstart', preventDefault);
  3912. }
  3913. }
  3914. data.handleNumbers.forEach(function (handleNumber) {
  3915. fireEvent('change', handleNumber);
  3916. fireEvent('set', handleNumber);
  3917. fireEvent('end', handleNumber);
  3918. });
  3919. }
  3920. // Bind move events on document.
  3921. function eventStart(event, data) {
  3922. var handle;
  3923. if (data.handleNumbers.length === 1) {
  3924. var handleOrigin = scope_Handles[data.handleNumbers[0]];
  3925. // Ignore 'disabled' handles
  3926. if (handleOrigin.hasAttribute('disabled')) {
  3927. return false;
  3928. }
  3929. handle = handleOrigin.children[0];
  3930. scope_ActiveHandlesCount += 1;
  3931. // Mark the handle as 'active' so it can be styled.
  3932. addClass(handle, options.cssClasses.active);
  3933. }
  3934. // A drag should never propagate up to the 'tap' event.
  3935. event.stopPropagation();
  3936. // Record the event listeners.
  3937. var listeners = [];
  3938. // Attach the move and end events.
  3939. var moveEvent = attachEvent(actions.move, scope_DocumentElement, eventMove, {
  3940. // The event target has changed so we need to propagate the original one so that we keep
  3941. // relying on it to extract target touches.
  3942. target: event.target,
  3943. handle: handle,
  3944. listeners: listeners,
  3945. startCalcPoint: event.calcPoint,
  3946. baseSize: baseSize(),
  3947. pageOffset: event.pageOffset,
  3948. handleNumbers: data.handleNumbers,
  3949. buttonsProperty: event.buttons,
  3950. locations: scope_Locations.slice()
  3951. });
  3952. var endEvent = attachEvent(actions.end, scope_DocumentElement, eventEnd, {
  3953. target: event.target,
  3954. handle: handle,
  3955. listeners: listeners,
  3956. handleNumbers: data.handleNumbers
  3957. });
  3958. var outEvent = attachEvent('mouseout', scope_DocumentElement, documentLeave, {
  3959. target: event.target,
  3960. handle: handle,
  3961. listeners: listeners,
  3962. handleNumbers: data.handleNumbers
  3963. });
  3964. // We want to make sure we pushed the listeners in the listener list rather than creating
  3965. // a new one as it has already been passed to the event handlers.
  3966. listeners.push.apply(listeners, moveEvent.concat(endEvent, outEvent));
  3967. // Text selection isn't an issue on touch devices,
  3968. // so adding cursor styles can be skipped.
  3969. if (event.cursor) {
  3970. // Prevent the 'I' cursor and extend the range-drag cursor.
  3971. scope_Body.style.cursor = getComputedStyle(event.target).cursor;
  3972. // Mark the target with a dragging state.
  3973. if (scope_Handles.length > 1) {
  3974. addClass(scope_Target, options.cssClasses.drag);
  3975. }
  3976. // Prevent text selection when dragging the handles.
  3977. // In noUiSlider <= 9.2.0, this was handled by calling preventDefault on mouse/touch start/move,
  3978. // which is scroll blocking. The selectstart event is supported by FireFox starting from version 52,
  3979. // meaning the only holdout is iOS Safari. This doesn't matter: text selection isn't triggered there.
  3980. // The 'cursor' flag is false.
  3981. // See: http://caniuse.com/#search=selectstart
  3982. scope_Body.addEventListener('selectstart', preventDefault, false);
  3983. }
  3984. data.handleNumbers.forEach(function (handleNumber) {
  3985. fireEvent('start', handleNumber);
  3986. });
  3987. }
  3988. // Move closest handle to tapped location.
  3989. function eventTap(event) {
  3990. // The tap event shouldn't propagate up
  3991. event.stopPropagation();
  3992. var proposal = calcPointToPercentage(event.calcPoint);
  3993. var handleNumber = getClosestHandle(proposal);
  3994. // Tackle the case that all handles are 'disabled'.
  3995. if (handleNumber === false) {
  3996. return false;
  3997. }
  3998. // Flag the slider as it is now in a transitional state.
  3999. // Transition takes a configurable amount of ms (default 300). Re-enable the slider after that.
  4000. if (!options.events.snap) {
  4001. addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
  4002. }
  4003. setHandle(handleNumber, proposal, true, true);
  4004. setZindex();
  4005. fireEvent('slide', handleNumber, true);
  4006. fireEvent('update', handleNumber, true);
  4007. fireEvent('change', handleNumber, true);
  4008. fireEvent('set', handleNumber, true);
  4009. if (options.events.snap) {
  4010. eventStart(event, { handleNumbers: [handleNumber] });
  4011. }
  4012. }
  4013. // Fires a 'hover' event for a hovered mouse/pen position.
  4014. function eventHover(event) {
  4015. var proposal = calcPointToPercentage(event.calcPoint);
  4016. var to = scope_Spectrum.getStep(proposal);
  4017. var value = scope_Spectrum.fromStepping(to);
  4018. Object.keys(scope_Events).forEach(function (targetEvent) {
  4019. if ('hover' === targetEvent.split('.')[0]) {
  4020. scope_Events[targetEvent].forEach(function (callback) {
  4021. callback.call(scope_Self, value);
  4022. });
  4023. }
  4024. });
  4025. }
  4026. // Attach events to several slider parts.
  4027. function bindSliderEvents(behaviour) {
  4028. // Attach the standard drag event to the handles.
  4029. if (!behaviour.fixed) {
  4030. scope_Handles.forEach(function (handle, index) {
  4031. // These events are only bound to the visual handle
  4032. // element, not the 'real' origin element.
  4033. attachEvent(actions.start, handle.children[0], eventStart, { handleNumbers: [index] });
  4034. });
  4035. }
  4036. // Attach the tap event to the slider base.
  4037. if (behaviour.tap) {
  4038. attachEvent(actions.start, scope_Base, eventTap, {});
  4039. }
  4040. // Fire hover events
  4041. if (behaviour.hover) {
  4042. attachEvent(actions.move, scope_Base, eventHover, { hover: true });
  4043. }
  4044. // Make the range draggable.
  4045. if (behaviour.drag) {
  4046. scope_Connects.forEach(function (connect, index) {
  4047. if (connect === false || index === 0 || index === scope_Connects.length - 1) {
  4048. return;
  4049. }
  4050. var handleBefore = scope_Handles[index - 1];
  4051. var handleAfter = scope_Handles[index];
  4052. var eventHolders = [connect];
  4053. addClass(connect, options.cssClasses.draggable);
  4054. // When the range is fixed, the entire range can
  4055. // be dragged by the handles. The handle in the first
  4056. // origin will propagate the start event upward,
  4057. // but it needs to be bound manually on the other.
  4058. if (behaviour.fixed) {
  4059. eventHolders.push(handleBefore.children[0]);
  4060. eventHolders.push(handleAfter.children[0]);
  4061. }
  4062. eventHolders.forEach(function (eventHolder) {
  4063. attachEvent(actions.start, eventHolder, eventStart, {
  4064. handles: [
  4065. handleBefore,
  4066. handleAfter
  4067. ],
  4068. handleNumbers: [
  4069. index - 1,
  4070. index
  4071. ]
  4072. });
  4073. });
  4074. });
  4075. }
  4076. }
  4077. // Split out the handle positioning logic so the Move event can use it, too
  4078. function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue) {
  4079. // For sliders with multiple handles, limit movement to the other handle.
  4080. // Apply the margin option by adding it to the handle positions.
  4081. if (scope_Handles.length > 1) {
  4082. if (lookBackward && handleNumber > 0) {
  4083. to = Math.max(to, reference[handleNumber - 1] + options.margin);
  4084. }
  4085. if (lookForward && handleNumber < scope_Handles.length - 1) {
  4086. to = Math.min(to, reference[handleNumber + 1] - options.margin);
  4087. }
  4088. }
  4089. // The limit option has the opposite effect, limiting handles to a
  4090. // maximum distance from another. Limit must be > 0, as otherwise
  4091. // handles would be unmoveable.
  4092. if (scope_Handles.length > 1 && options.limit) {
  4093. if (lookBackward && handleNumber > 0) {
  4094. to = Math.min(to, reference[handleNumber - 1] + options.limit);
  4095. }
  4096. if (lookForward && handleNumber < scope_Handles.length - 1) {
  4097. to = Math.max(to, reference[handleNumber + 1] - options.limit);
  4098. }
  4099. }
  4100. // The padding option keeps the handles a certain distance from the
  4101. // edges of the slider. Padding must be > 0.
  4102. if (options.padding) {
  4103. if (handleNumber === 0) {
  4104. to = Math.max(to, options.padding);
  4105. }
  4106. if (handleNumber === scope_Handles.length - 1) {
  4107. to = Math.min(to, 100 - options.padding);
  4108. }
  4109. }
  4110. to = scope_Spectrum.getStep(to);
  4111. // Limit percentage to the 0 - 100 range
  4112. to = limit(to);
  4113. // Return false if handle can't move
  4114. if (to === reference[handleNumber] && !getValue) {
  4115. return false;
  4116. }
  4117. return to;
  4118. }
  4119. function toPct(pct) {
  4120. return pct + '%';
  4121. }
  4122. // Updates scope_Locations and scope_Values, updates visual state
  4123. function updateHandlePosition(handleNumber, to) {
  4124. // Update locations.
  4125. scope_Locations[handleNumber] = to;
  4126. // Convert the value to the slider stepping/range.
  4127. scope_Values[handleNumber] = scope_Spectrum.fromStepping(to);
  4128. // Called synchronously or on the next animationFrame
  4129. var stateUpdate = function () {
  4130. scope_Handles[handleNumber].style[options.style] = toPct(to);
  4131. updateConnect(handleNumber);
  4132. updateConnect(handleNumber + 1);
  4133. };
  4134. // Set the handle to the new position.
  4135. // Use requestAnimationFrame for efficient painting.
  4136. // No significant effect in Chrome, Edge sees dramatic performace improvements.
  4137. // Option to disable is useful for unit tests, and single-step debugging.
  4138. if (window.requestAnimationFrame && options.useRequestAnimationFrame) {
  4139. window.requestAnimationFrame(stateUpdate);
  4140. } else {
  4141. stateUpdate();
  4142. }
  4143. }
  4144. function setZindex() {
  4145. scope_HandleNumbers.forEach(function (handleNumber) {
  4146. // Handles before the slider middle are stacked later = higher,
  4147. // Handles after the middle later is lower
  4148. // [[7] [8] .......... | .......... [5] [4]
  4149. var dir = scope_Locations[handleNumber] > 50 ? -1 : 1;
  4150. var zIndex = 3 + (scope_Handles.length + dir * handleNumber);
  4151. scope_Handles[handleNumber].childNodes[0].style.zIndex = zIndex;
  4152. });
  4153. }
  4154. // Test suggested values and apply margin, step.
  4155. function setHandle(handleNumber, to, lookBackward, lookForward) {
  4156. to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false);
  4157. if (to === false) {
  4158. return false;
  4159. }
  4160. updateHandlePosition(handleNumber, to);
  4161. return true;
  4162. }
  4163. // Updates style attribute for connect nodes
  4164. function updateConnect(index) {
  4165. // Skip connects set to false
  4166. if (!scope_Connects[index]) {
  4167. return;
  4168. }
  4169. var l = 0;
  4170. var h = 100;
  4171. if (index !== 0) {
  4172. l = scope_Locations[index - 1];
  4173. }
  4174. if (index !== scope_Connects.length - 1) {
  4175. h = scope_Locations[index];
  4176. }
  4177. scope_Connects[index].style[options.style] = toPct(l);
  4178. scope_Connects[index].style[options.styleOposite] = toPct(100 - h);
  4179. }
  4180. // ...
  4181. function setValue(to, handleNumber) {
  4182. // Setting with null indicates an 'ignore'.
  4183. // Inputting 'false' is invalid.
  4184. if (to === null || to === false) {
  4185. return;
  4186. }
  4187. // If a formatted number was passed, attemt to decode it.
  4188. if (typeof to === 'number') {
  4189. to = String(to);
  4190. }
  4191. to = options.format.from(to);
  4192. // Request an update for all links if the value was invalid.
  4193. // Do so too if setting the handle fails.
  4194. if (to !== false && !isNaN(to)) {
  4195. setHandle(handleNumber, scope_Spectrum.toStepping(to), false, false);
  4196. }
  4197. }
  4198. // Set the slider value.
  4199. function valueSet(input, fireSetEvent) {
  4200. var values = asArray(input);
  4201. var isInit = scope_Locations[0] === undefined;
  4202. // Event fires by default
  4203. fireSetEvent = fireSetEvent === undefined ? true : !!fireSetEvent;
  4204. values.forEach(setValue);
  4205. // Animation is optional.
  4206. // Make sure the initial values were set before using animated placement.
  4207. if (options.animate && !isInit) {
  4208. addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
  4209. }
  4210. // Now that all base values are set, apply constraints
  4211. scope_HandleNumbers.forEach(function (handleNumber) {
  4212. setHandle(handleNumber, scope_Locations[handleNumber], true, false);
  4213. });
  4214. setZindex();
  4215. scope_HandleNumbers.forEach(function (handleNumber) {
  4216. fireEvent('update', handleNumber);
  4217. // Fire the event only for handles that received a new value, as per #579
  4218. if (values[handleNumber] !== null && fireSetEvent) {
  4219. fireEvent('set', handleNumber);
  4220. }
  4221. });
  4222. }
  4223. // Reset slider to initial values
  4224. function valueReset(fireSetEvent) {
  4225. valueSet(options.start, fireSetEvent);
  4226. }
  4227. // Get the slider value.
  4228. function valueGet() {
  4229. var values = scope_Values.map(options.format.to);
  4230. // If only one handle is used, return a single value.
  4231. if (values.length === 1) {
  4232. return values[0];
  4233. }
  4234. return values;
  4235. }
  4236. // Removes classes from the root and empties it.
  4237. function destroy() {
  4238. for (var key in options.cssClasses) {
  4239. if (!options.cssClasses.hasOwnProperty(key)) {
  4240. continue;
  4241. }
  4242. removeClass(scope_Target, options.cssClasses[key]);
  4243. }
  4244. while (scope_Target.firstChild) {
  4245. scope_Target.removeChild(scope_Target.firstChild);
  4246. }
  4247. delete scope_Target.noUiSlider;
  4248. }
  4249. // Get the current step size for the slider.
  4250. function getCurrentStep() {
  4251. // Check all locations, map them to their stepping point.
  4252. // Get the step point, then find it in the input list.
  4253. return scope_Locations.map(function (location, index) {
  4254. var nearbySteps = scope_Spectrum.getNearbySteps(location);
  4255. var value = scope_Values[index];
  4256. var increment = nearbySteps.thisStep.step;
  4257. var decrement = null;
  4258. // If the next value in this step moves into the next step,
  4259. // the increment is the start of the next step - the current value
  4260. if (increment !== false) {
  4261. if (value + increment > nearbySteps.stepAfter.startValue) {
  4262. increment = nearbySteps.stepAfter.startValue - value;
  4263. }
  4264. }
  4265. // If the value is beyond the starting point
  4266. if (value > nearbySteps.thisStep.startValue) {
  4267. decrement = nearbySteps.thisStep.step;
  4268. } else if (nearbySteps.stepBefore.step === false) {
  4269. decrement = false;
  4270. } // If a handle is at the start of a step, it always steps back into the previous step first
  4271. else {
  4272. decrement = value - nearbySteps.stepBefore.highestStep;
  4273. }
  4274. // Now, if at the slider edges, there is not in/decrement
  4275. if (location === 100) {
  4276. increment = null;
  4277. } else if (location === 0) {
  4278. decrement = null;
  4279. }
  4280. // As per #391, the comparison for the decrement step can have some rounding issues.
  4281. var stepDecimals = scope_Spectrum.countStepDecimals();
  4282. // Round per #391
  4283. if (increment !== null && increment !== false) {
  4284. increment = Number(increment.toFixed(stepDecimals));
  4285. }
  4286. if (decrement !== null && decrement !== false) {
  4287. decrement = Number(decrement.toFixed(stepDecimals));
  4288. }
  4289. return [
  4290. decrement,
  4291. increment
  4292. ];
  4293. });
  4294. }
  4295. // Attach an event to this slider, possibly including a namespace
  4296. function bindEvent(namespacedEvent, callback) {
  4297. scope_Events[namespacedEvent] = scope_Events[namespacedEvent] || [];
  4298. scope_Events[namespacedEvent].push(callback);
  4299. // If the event bound is 'update,' fire it immediately for all handles.
  4300. if (namespacedEvent.split('.')[0] === 'update') {
  4301. scope_Handles.forEach(function (a, index) {
  4302. fireEvent('update', index);
  4303. });
  4304. }
  4305. }
  4306. // Undo attachment of event
  4307. function removeEvent(namespacedEvent) {
  4308. var event = namespacedEvent && namespacedEvent.split('.')[0];
  4309. var namespace = event && namespacedEvent.substring(event.length);
  4310. Object.keys(scope_Events).forEach(function (bind) {
  4311. var tEvent = bind.split('.')[0], tNamespace = bind.substring(tEvent.length);
  4312. if ((!event || event === tEvent) && (!namespace || namespace === tNamespace)) {
  4313. delete scope_Events[bind];
  4314. }
  4315. });
  4316. }
  4317. // Updateable: margin, limit, padding, step, range, animate, snap
  4318. function updateOptions(optionsToUpdate, fireSetEvent) {
  4319. // Spectrum is created using the range, snap, direction and step options.
  4320. // 'snap' and 'step' can be updated.
  4321. // If 'snap' and 'step' are not passed, they should remain unchanged.
  4322. var v = valueGet();
  4323. var updateAble = [
  4324. 'margin',
  4325. 'limit',
  4326. 'padding',
  4327. 'range',
  4328. 'animate',
  4329. 'snap',
  4330. 'step',
  4331. 'format'
  4332. ];
  4333. // Only change options that we're actually passed to update.
  4334. updateAble.forEach(function (name) {
  4335. if (optionsToUpdate[name] !== undefined) {
  4336. originalOptions[name] = optionsToUpdate[name];
  4337. }
  4338. });
  4339. var newOptions = testOptions(originalOptions);
  4340. // Load new options into the slider state
  4341. updateAble.forEach(function (name) {
  4342. if (optionsToUpdate[name] !== undefined) {
  4343. options[name] = newOptions[name];
  4344. }
  4345. });
  4346. scope_Spectrum = newOptions.spectrum;
  4347. // Limit, margin and padding depend on the spectrum but are stored outside of it. (#677)
  4348. options.margin = newOptions.margin;
  4349. options.limit = newOptions.limit;
  4350. options.padding = newOptions.padding;
  4351. // Update pips, removes existing.
  4352. if (options.pips) {
  4353. pips(options.pips);
  4354. }
  4355. // Invalidate the current positioning so valueSet forces an update.
  4356. scope_Locations = [];
  4357. valueSet(optionsToUpdate.start || v, fireSetEvent);
  4358. }
  4359. // Throw an error if the slider was already initialized.
  4360. if (scope_Target.noUiSlider) {
  4361. throw new Error('noUiSlider (' + VERSION + '): Slider was already initialized.');
  4362. }
  4363. // Create the base element, initialise HTML and set classes.
  4364. // Add handles and connect elements.
  4365. addSlider(scope_Target);
  4366. addElements(options.connect, scope_Base);
  4367. scope_Self = {
  4368. destroy: destroy,
  4369. steps: getCurrentStep,
  4370. on: bindEvent,
  4371. off: removeEvent,
  4372. get: valueGet,
  4373. set: valueSet,
  4374. reset: valueReset,
  4375. // Exposed for unit testing, don't use this in your application.
  4376. __moveHandles: function (a, b, c) {
  4377. moveHandles(a, b, scope_Locations, c);
  4378. },
  4379. options: originalOptions,
  4380. // Issue #600, #678
  4381. updateOptions: updateOptions,
  4382. target: scope_Target,
  4383. // Issue #597
  4384. removePips: removePips,
  4385. pips: pips // Issue #594
  4386. };
  4387. // Attach user events.
  4388. bindSliderEvents(options.events);
  4389. // Use the public value method to set the start values.
  4390. valueSet(options.start);
  4391. if (options.pips) {
  4392. pips(options.pips);
  4393. }
  4394. if (options.tooltips) {
  4395. tooltips();
  4396. }
  4397. aria();
  4398. return scope_Self;
  4399. }
  4400. // Run the standard initializer
  4401. function initialize(target, originalOptions) {
  4402. if (!target || !target.nodeName) {
  4403. throw new Error('noUiSlider (' + VERSION + '): create requires a single element, got: ' + target);
  4404. }
  4405. // Test the options and create the slider environment;
  4406. var options = testOptions(originalOptions, target);
  4407. var api = closure(target, options, originalOptions);
  4408. target.noUiSlider = api;
  4409. return api;
  4410. }
  4411. // Use an object instead of a function for future expansibility;
  4412. return {
  4413. version: VERSION,
  4414. create: initialize
  4415. };
  4416. }));},
  4417. 397: /* pikaday/pikaday */ function(require, module, exports) {
  4418. /*!
  4419. * Pikaday
  4420. *
  4421. * Copyright © 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
  4422. */
  4423. (function (root, factory) {
  4424. 'use strict';
  4425. var moment;
  4426. if (typeof exports === 'object') {
  4427. // CommonJS module
  4428. // Load moment.js as an optional dependency
  4429. try {
  4430. moment = require('moment' /* moment */);
  4431. } catch (e) {
  4432. }
  4433. module.exports = factory(moment);
  4434. } else if (typeof define === 'function' && define.amd) {
  4435. // AMD. Register as an anonymous module.
  4436. define(function (req) {
  4437. // Load moment.js as an optional dependency
  4438. var id = 'moment';
  4439. try {
  4440. moment = req(id);
  4441. } catch (e) {
  4442. }
  4443. return factory(moment);
  4444. });
  4445. } else {
  4446. root.Pikaday = factory(root.moment);
  4447. }
  4448. }(this, function (moment) {
  4449. 'use strict';
  4450. /**
  4451. * feature detection and helper functions
  4452. */
  4453. var hasMoment = typeof moment === 'function', hasEventListeners = !!window.addEventListener, document = window.document, sto = window.setTimeout, addEvent = function (el, e, callback, capture) {
  4454. if (hasEventListeners) {
  4455. el.addEventListener(e, callback, !!capture);
  4456. } else {
  4457. el.attachEvent('on' + e, callback);
  4458. }
  4459. }, removeEvent = function (el, e, callback, capture) {
  4460. if (hasEventListeners) {
  4461. el.removeEventListener(e, callback, !!capture);
  4462. } else {
  4463. el.detachEvent('on' + e, callback);
  4464. }
  4465. }, trim = function (str) {
  4466. return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
  4467. }, hasClass = function (el, cn) {
  4468. return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
  4469. }, addClass = function (el, cn) {
  4470. if (!hasClass(el, cn)) {
  4471. el.className = el.className === '' ? cn : el.className + ' ' + cn;
  4472. }
  4473. }, removeClass = function (el, cn) {
  4474. el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
  4475. }, isArray = function (obj) {
  4476. return /Array/.test(Object.prototype.toString.call(obj));
  4477. }, isDate = function (obj) {
  4478. return /Date/.test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
  4479. }, isWeekend = function (date) {
  4480. var day = date.getDay();
  4481. return day === 0 || day === 6;
  4482. }, isLeapYear = function (year) {
  4483. // solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
  4484. return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
  4485. }, getDaysInMonth = function (year, month) {
  4486. return [
  4487. 31,
  4488. isLeapYear(year) ? 29 : 28,
  4489. 31,
  4490. 30,
  4491. 31,
  4492. 30,
  4493. 31,
  4494. 31,
  4495. 30,
  4496. 31,
  4497. 30,
  4498. 31
  4499. ][month];
  4500. }, setToStartOfDay = function (date) {
  4501. if (isDate(date))
  4502. date.setHours(0, 0, 0, 0);
  4503. }, compareDates = function (a, b) {
  4504. // weak date comparison (use setToStartOfDay(date) to ensure correct result)
  4505. return a.getTime() === b.getTime();
  4506. }, extend = function (to, from, overwrite) {
  4507. var prop, hasProp;
  4508. for (prop in from) {
  4509. hasProp = to[prop] !== undefined;
  4510. if (hasProp && typeof from[prop] === 'object' && from[prop] !== null && from[prop].nodeName === undefined) {
  4511. if (isDate(from[prop])) {
  4512. if (overwrite) {
  4513. to[prop] = new Date(from[prop].getTime());
  4514. }
  4515. } else if (isArray(from[prop])) {
  4516. if (overwrite) {
  4517. to[prop] = from[prop].slice(0);
  4518. }
  4519. } else {
  4520. to[prop] = extend({}, from[prop], overwrite);
  4521. }
  4522. } else if (overwrite || !hasProp) {
  4523. to[prop] = from[prop];
  4524. }
  4525. }
  4526. return to;
  4527. }, fireEvent = function (el, eventName, data) {
  4528. var ev;
  4529. if (document.createEvent) {
  4530. ev = document.createEvent('HTMLEvents');
  4531. ev.initEvent(eventName, true, false);
  4532. ev = extend(ev, data);
  4533. el.dispatchEvent(ev);
  4534. } else if (document.createEventObject) {
  4535. ev = document.createEventObject();
  4536. ev = extend(ev, data);
  4537. el.fireEvent('on' + eventName, ev);
  4538. }
  4539. }, adjustCalendar = function (calendar) {
  4540. if (calendar.month < 0) {
  4541. calendar.year -= Math.ceil(Math.abs(calendar.month) / 12);
  4542. calendar.month += 12;
  4543. }
  4544. if (calendar.month > 11) {
  4545. calendar.year += Math.floor(Math.abs(calendar.month) / 12);
  4546. calendar.month -= 12;
  4547. }
  4548. return calendar;
  4549. },
  4550. /**
  4551. * defaults and localisation
  4552. */
  4553. defaults = {
  4554. // bind the picker to a form field
  4555. field: null,
  4556. // automatically show/hide the picker on `field` focus (default `true` if `field` is set)
  4557. bound: undefined,
  4558. // position of the datepicker, relative to the field (default to bottom & left)
  4559. // ('bottom' & 'left' keywords are not used, 'top' & 'right' are modifier on the bottom/left position)
  4560. position: 'bottom left',
  4561. // automatically fit in the viewport even if it means repositioning from the position option
  4562. reposition: true,
  4563. // the default output format for `.toString()` and `field` value
  4564. format: 'YYYY-MM-DD',
  4565. // the toString function which gets passed a current date object and format
  4566. // and returns a string
  4567. toString: null,
  4568. // used to create date object from current input string
  4569. parse: null,
  4570. // the initial date to view when first opened
  4571. defaultDate: null,
  4572. // make the `defaultDate` the initial selected value
  4573. setDefaultDate: false,
  4574. // first day of week (0: Sunday, 1: Monday etc)
  4575. firstDay: 0,
  4576. // the default flag for moment's strict date parsing
  4577. formatStrict: false,
  4578. // the minimum/earliest date that can be selected
  4579. minDate: null,
  4580. // the maximum/latest date that can be selected
  4581. maxDate: null,
  4582. // number of years either side, or array of upper/lower range
  4583. yearRange: 10,
  4584. // show week numbers at head of row
  4585. showWeekNumber: false,
  4586. // Week picker mode
  4587. pickWholeWeek: false,
  4588. // used internally (don't config outside)
  4589. minYear: 0,
  4590. maxYear: 9999,
  4591. minMonth: undefined,
  4592. maxMonth: undefined,
  4593. startRange: null,
  4594. endRange: null,
  4595. isRTL: false,
  4596. // Additional text to append to the year in the calendar title
  4597. yearSuffix: '',
  4598. // Render the month after year in the calendar title
  4599. showMonthAfterYear: false,
  4600. // Render days of the calendar grid that fall in the next or previous month
  4601. showDaysInNextAndPreviousMonths: false,
  4602. // Allows user to select days that fall in the next or previous month
  4603. enableSelectionDaysInNextAndPreviousMonths: false,
  4604. // how many months are visible
  4605. numberOfMonths: 1,
  4606. // when numberOfMonths is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`)
  4607. // only used for the first display or when a selected date is not visible
  4608. mainCalendar: 'left',
  4609. // Specify a DOM element to render the calendar in
  4610. container: undefined,
  4611. // Blur field when date is selected
  4612. blurFieldOnSelect: true,
  4613. // internationalization
  4614. i18n: {
  4615. previousMonth: 'Previous Month',
  4616. nextMonth: 'Next Month',
  4617. months: [
  4618. 'January',
  4619. 'February',
  4620. 'March',
  4621. 'April',
  4622. 'May',
  4623. 'June',
  4624. 'July',
  4625. 'August',
  4626. 'September',
  4627. 'October',
  4628. 'November',
  4629. 'December'
  4630. ],
  4631. weekdays: [
  4632. 'Sunday',
  4633. 'Monday',
  4634. 'Tuesday',
  4635. 'Wednesday',
  4636. 'Thursday',
  4637. 'Friday',
  4638. 'Saturday'
  4639. ],
  4640. weekdaysShort: [
  4641. 'Sun',
  4642. 'Mon',
  4643. 'Tue',
  4644. 'Wed',
  4645. 'Thu',
  4646. 'Fri',
  4647. 'Sat'
  4648. ]
  4649. },
  4650. // Theme Classname
  4651. theme: null,
  4652. // events array
  4653. events: [],
  4654. // callback function
  4655. onSelect: null,
  4656. onOpen: null,
  4657. onClose: null,
  4658. onDraw: null
  4659. },
  4660. /**
  4661. * templating functions to abstract HTML rendering
  4662. */
  4663. renderDayName = function (opts, day, abbr) {
  4664. day += opts.firstDay;
  4665. while (day >= 7) {
  4666. day -= 7;
  4667. }
  4668. return abbr ? opts.i18n.weekdaysShort[day] : opts.i18n.weekdays[day];
  4669. }, renderDay = function (opts) {
  4670. var arr = [];
  4671. var ariaSelected = 'false';
  4672. if (opts.isEmpty) {
  4673. if (opts.showDaysInNextAndPreviousMonths) {
  4674. arr.push('is-outside-current-month');
  4675. if (!opts.enableSelectionDaysInNextAndPreviousMonths) {
  4676. arr.push('is-selection-disabled');
  4677. }
  4678. } else {
  4679. return '<td class="is-empty"></td>';
  4680. }
  4681. }
  4682. if (opts.isDisabled) {
  4683. arr.push('is-disabled');
  4684. }
  4685. if (opts.isToday) {
  4686. arr.push('is-today');
  4687. }
  4688. if (opts.isSelected) {
  4689. arr.push('is-selected');
  4690. ariaSelected = 'true';
  4691. }
  4692. if (opts.hasEvent) {
  4693. arr.push('has-event');
  4694. }
  4695. if (opts.isInRange) {
  4696. arr.push('is-inrange');
  4697. }
  4698. if (opts.isStartRange) {
  4699. arr.push('is-startrange');
  4700. }
  4701. if (opts.isEndRange) {
  4702. arr.push('is-endrange');
  4703. }
  4704. return '<td data-day="' + opts.day + '" class="' + arr.join(' ') + '" aria-selected="' + ariaSelected + '">' + '<button class="pika-button pika-day" type="button" ' + 'data-pika-year="' + opts.year + '" data-pika-month="' + opts.month + '" data-pika-day="' + opts.day + '">' + opts.day + '</button>' + '</td>';
  4705. }, renderWeek = function (d, m, y) {
  4706. // Lifted from http://javascript.about.com/library/blweekyear.htm, lightly modified.
  4707. var onejan = new Date(y, 0, 1), weekNum = Math.ceil(((new Date(y, m, d) - onejan) / 86400000 + onejan.getDay() + 1) / 7);
  4708. return '<td class="pika-week">' + weekNum + '</td>';
  4709. }, renderRow = function (days, isRTL, pickWholeWeek, isRowSelected) {
  4710. return '<tr class="pika-row' + (pickWholeWeek ? ' pick-whole-week' : '') + (isRowSelected ? ' is-selected' : '') + '">' + (isRTL ? days.reverse() : days).join('') + '</tr>';
  4711. }, renderBody = function (rows) {
  4712. return '<tbody>' + rows.join('') + '</tbody>';
  4713. }, renderHead = function (opts) {
  4714. var i, arr = [];
  4715. if (opts.showWeekNumber) {
  4716. arr.push('<th></th>');
  4717. }
  4718. for (i = 0; i < 7; i++) {
  4719. arr.push('<th scope="col"><abbr title="' + renderDayName(opts, i) + '">' + renderDayName(opts, i, true) + '</abbr></th>');
  4720. }
  4721. return '<thead><tr>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</tr></thead>';
  4722. }, renderTitle = function (instance, c, year, month, refYear, randId) {
  4723. var i, j, arr, opts = instance._o, isMinYear = year === opts.minYear, isMaxYear = year === opts.maxYear, html = '<div id="' + randId + '" class="pika-title" role="heading" aria-live="assertive">', monthHtml, yearHtml, prev = true, next = true;
  4724. for (arr = [], i = 0; i < 12; i++) {
  4725. arr.push('<option value="' + (year === refYear ? i - c : 12 + i - c) + '"' + (i === month ? ' selected="selected"' : '') + (isMinYear && i < opts.minMonth || isMaxYear && i > opts.maxMonth ? 'disabled="disabled"' : '') + '>' + opts.i18n.months[i] + '</option>');
  4726. }
  4727. monthHtml = '<div class="pika-label">' + opts.i18n.months[month] + '<select class="pika-select pika-select-month" tabindex="-1">' + arr.join('') + '</select></div>';
  4728. if (isArray(opts.yearRange)) {
  4729. i = opts.yearRange[0];
  4730. j = opts.yearRange[1] + 1;
  4731. } else {
  4732. i = year - opts.yearRange;
  4733. j = 1 + year + opts.yearRange;
  4734. }
  4735. for (arr = []; i < j && i <= opts.maxYear; i++) {
  4736. if (i >= opts.minYear) {
  4737. arr.push('<option value="' + i + '"' + (i === year ? ' selected="selected"' : '') + '>' + i + '</option>');
  4738. }
  4739. }
  4740. yearHtml = '<div class="pika-label">' + year + opts.yearSuffix + '<select class="pika-select pika-select-year" tabindex="-1">' + arr.join('') + '</select></div>';
  4741. if (opts.showMonthAfterYear) {
  4742. html += yearHtml + monthHtml;
  4743. } else {
  4744. html += monthHtml + yearHtml;
  4745. }
  4746. if (isMinYear && (month === 0 || opts.minMonth >= month)) {
  4747. prev = false;
  4748. }
  4749. if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
  4750. next = false;
  4751. }
  4752. if (c === 0) {
  4753. html += '<button class="pika-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + opts.i18n.previousMonth + '</button>';
  4754. }
  4755. if (c === instance._o.numberOfMonths - 1) {
  4756. html += '<button class="pika-next' + (next ? '' : ' is-disabled') + '" type="button">' + opts.i18n.nextMonth + '</button>';
  4757. }
  4758. return html += '</div>';
  4759. }, renderTable = function (opts, data, randId) {
  4760. return '<table cellpadding="0" cellspacing="0" class="pika-table" role="grid" aria-labelledby="' + randId + '">' + renderHead(opts) + renderBody(data) + '</table>';
  4761. },
  4762. /**
  4763. * Pikaday constructor
  4764. */
  4765. Pikaday = function (options) {
  4766. var self = this, opts = self.config(options);
  4767. self._onMouseDown = function (e) {
  4768. if (!self._v) {
  4769. return;
  4770. }
  4771. e = e || window.event;
  4772. var target = e.target || e.srcElement;
  4773. if (!target) {
  4774. return;
  4775. }
  4776. if (!hasClass(target, 'is-disabled')) {
  4777. if (hasClass(target, 'pika-button') && !hasClass(target, 'is-empty') && !hasClass(target.parentNode, 'is-disabled')) {
  4778. self.setDate(new Date(target.getAttribute('data-pika-year'), target.getAttribute('data-pika-month'), target.getAttribute('data-pika-day')));
  4779. if (opts.bound) {
  4780. sto(function () {
  4781. self.hide();
  4782. if (opts.blurFieldOnSelect && opts.field) {
  4783. opts.field.blur();
  4784. }
  4785. }, 100);
  4786. }
  4787. } else if (hasClass(target, 'pika-prev')) {
  4788. self.prevMonth();
  4789. } else if (hasClass(target, 'pika-next')) {
  4790. self.nextMonth();
  4791. }
  4792. }
  4793. if (!hasClass(target, 'pika-select')) {
  4794. // if this is touch event prevent mouse events emulation
  4795. if (e.preventDefault) {
  4796. e.preventDefault();
  4797. } else {
  4798. e.returnValue = false;
  4799. return false;
  4800. }
  4801. } else {
  4802. self._c = true;
  4803. }
  4804. };
  4805. self._onChange = function (e) {
  4806. e = e || window.event;
  4807. var target = e.target || e.srcElement;
  4808. if (!target) {
  4809. return;
  4810. }
  4811. if (hasClass(target, 'pika-select-month')) {
  4812. self.gotoMonth(target.value);
  4813. } else if (hasClass(target, 'pika-select-year')) {
  4814. self.gotoYear(target.value);
  4815. }
  4816. };
  4817. self._onKeyChange = function (e) {
  4818. e = e || window.event;
  4819. if (self.isVisible()) {
  4820. switch (e.keyCode) {
  4821. case 13:
  4822. case 27:
  4823. if (opts.field) {
  4824. opts.field.blur();
  4825. }
  4826. break;
  4827. case 37:
  4828. e.preventDefault();
  4829. self.adjustDate('subtract', 1);
  4830. break;
  4831. case 38:
  4832. self.adjustDate('subtract', 7);
  4833. break;
  4834. case 39:
  4835. self.adjustDate('add', 1);
  4836. break;
  4837. case 40:
  4838. self.adjustDate('add', 7);
  4839. break;
  4840. }
  4841. }
  4842. };
  4843. self._onInputChange = function (e) {
  4844. var date;
  4845. if (e.firedBy === self) {
  4846. return;
  4847. }
  4848. if (opts.parse) {
  4849. date = opts.parse(opts.field.value, opts.format);
  4850. } else if (hasMoment) {
  4851. date = moment(opts.field.value, opts.format, opts.formatStrict);
  4852. date = date && date.isValid() ? date.toDate() : null;
  4853. } else {
  4854. date = new Date(Date.parse(opts.field.value));
  4855. }
  4856. if (isDate(date)) {
  4857. self.setDate(date);
  4858. }
  4859. if (!self._v) {
  4860. self.show();
  4861. }
  4862. };
  4863. self._onInputFocus = function () {
  4864. self.show();
  4865. };
  4866. self._onInputClick = function () {
  4867. self.show();
  4868. };
  4869. self._onInputBlur = function () {
  4870. // IE allows pika div to gain focus; catch blur the input field
  4871. var pEl = document.activeElement;
  4872. do {
  4873. if (hasClass(pEl, 'pika-single')) {
  4874. return;
  4875. }
  4876. } while (pEl = pEl.parentNode);
  4877. if (!self._c) {
  4878. self._b = sto(function () {
  4879. self.hide();
  4880. }, 50);
  4881. }
  4882. self._c = false;
  4883. };
  4884. self._onClick = function (e) {
  4885. e = e || window.event;
  4886. var target = e.target || e.srcElement, pEl = target;
  4887. if (!target) {
  4888. return;
  4889. }
  4890. if (!hasEventListeners && hasClass(target, 'pika-select')) {
  4891. if (!target.onchange) {
  4892. target.setAttribute('onchange', 'return;');
  4893. addEvent(target, 'change', self._onChange);
  4894. }
  4895. }
  4896. do {
  4897. if (hasClass(pEl, 'pika-single') || pEl === opts.trigger) {
  4898. return;
  4899. }
  4900. } while (pEl = pEl.parentNode);
  4901. if (self._v && target !== opts.trigger && pEl !== opts.trigger) {
  4902. self.hide();
  4903. }
  4904. };
  4905. self.el = document.createElement('div');
  4906. self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '') + (opts.theme ? ' ' + opts.theme : '');
  4907. addEvent(self.el, 'mousedown', self._onMouseDown, true);
  4908. addEvent(self.el, 'touchend', self._onMouseDown, true);
  4909. addEvent(self.el, 'change', self._onChange);
  4910. addEvent(document, 'keydown', self._onKeyChange);
  4911. if (opts.field) {
  4912. if (opts.container) {
  4913. opts.container.appendChild(self.el);
  4914. } else if (opts.bound) {
  4915. document.body.appendChild(self.el);
  4916. } else {
  4917. opts.field.parentNode.insertBefore(self.el, opts.field.nextSibling);
  4918. }
  4919. addEvent(opts.field, 'change', self._onInputChange);
  4920. if (!opts.defaultDate) {
  4921. if (hasMoment && opts.field.value) {
  4922. opts.defaultDate = moment(opts.field.value, opts.format).toDate();
  4923. } else {
  4924. opts.defaultDate = new Date(Date.parse(opts.field.value));
  4925. }
  4926. opts.setDefaultDate = true;
  4927. }
  4928. }
  4929. var defDate = opts.defaultDate;
  4930. if (isDate(defDate)) {
  4931. if (opts.setDefaultDate) {
  4932. self.setDate(defDate, true);
  4933. } else {
  4934. self.gotoDate(defDate);
  4935. }
  4936. } else {
  4937. self.gotoDate(new Date());
  4938. }
  4939. if (opts.bound) {
  4940. this.hide();
  4941. self.el.className += ' is-bound';
  4942. addEvent(opts.trigger, 'click', self._onInputClick);
  4943. addEvent(opts.trigger, 'focus', self._onInputFocus);
  4944. addEvent(opts.trigger, 'blur', self._onInputBlur);
  4945. } else {
  4946. this.show();
  4947. }
  4948. };
  4949. /**
  4950. * public Pikaday API
  4951. */
  4952. Pikaday.prototype = {
  4953. /**
  4954. * configure functionality
  4955. */
  4956. config: function (options) {
  4957. if (!this._o) {
  4958. this._o = extend({}, defaults, true);
  4959. }
  4960. var opts = extend(this._o, options, true);
  4961. opts.isRTL = !!opts.isRTL;
  4962. opts.field = opts.field && opts.field.nodeName ? opts.field : null;
  4963. opts.theme = typeof opts.theme === 'string' && opts.theme ? opts.theme : null;
  4964. opts.bound = !!(opts.bound !== undefined ? opts.field && opts.bound : opts.field);
  4965. opts.trigger = opts.trigger && opts.trigger.nodeName ? opts.trigger : opts.field;
  4966. opts.disableWeekends = !!opts.disableWeekends;
  4967. opts.disableDayFn = typeof opts.disableDayFn === 'function' ? opts.disableDayFn : null;
  4968. var nom = parseInt(opts.numberOfMonths, 10) || 1;
  4969. opts.numberOfMonths = nom > 4 ? 4 : nom;
  4970. if (!isDate(opts.minDate)) {
  4971. opts.minDate = false;
  4972. }
  4973. if (!isDate(opts.maxDate)) {
  4974. opts.maxDate = false;
  4975. }
  4976. if (opts.minDate && opts.maxDate && opts.maxDate < opts.minDate) {
  4977. opts.maxDate = opts.minDate = false;
  4978. }
  4979. if (opts.minDate) {
  4980. this.setMinDate(opts.minDate);
  4981. }
  4982. if (opts.maxDate) {
  4983. this.setMaxDate(opts.maxDate);
  4984. }
  4985. if (isArray(opts.yearRange)) {
  4986. var fallback = new Date().getFullYear() - 10;
  4987. opts.yearRange[0] = parseInt(opts.yearRange[0], 10) || fallback;
  4988. opts.yearRange[1] = parseInt(opts.yearRange[1], 10) || fallback;
  4989. } else {
  4990. opts.yearRange = Math.abs(parseInt(opts.yearRange, 10)) || defaults.yearRange;
  4991. if (opts.yearRange > 100) {
  4992. opts.yearRange = 100;
  4993. }
  4994. }
  4995. return opts;
  4996. },
  4997. /**
  4998. * return a formatted string of the current selection (using Moment.js if available)
  4999. */
  5000. toString: function (format) {
  5001. format = format || this._o.format;
  5002. if (!isDate(this._d)) {
  5003. return '';
  5004. }
  5005. if (this._o.toString) {
  5006. return this._o.toString(this._d, format);
  5007. }
  5008. if (hasMoment) {
  5009. return moment(this._d).format(format);
  5010. }
  5011. return this._d.toDateString();
  5012. },
  5013. /**
  5014. * return a Moment.js object of the current selection (if available)
  5015. */
  5016. getMoment: function () {
  5017. return hasMoment ? moment(this._d) : null;
  5018. },
  5019. /**
  5020. * set the current selection from a Moment.js object (if available)
  5021. */
  5022. setMoment: function (date, preventOnSelect) {
  5023. if (hasMoment && moment.isMoment(date)) {
  5024. this.setDate(date.toDate(), preventOnSelect);
  5025. }
  5026. },
  5027. /**
  5028. * return a Date object of the current selection
  5029. */
  5030. getDate: function () {
  5031. return isDate(this._d) ? new Date(this._d.getTime()) : null;
  5032. },
  5033. /**
  5034. * set the current selection
  5035. */
  5036. setDate: function (date, preventOnSelect) {
  5037. if (!date) {
  5038. this._d = null;
  5039. if (this._o.field) {
  5040. this._o.field.value = '';
  5041. fireEvent(this._o.field, 'change', { firedBy: this });
  5042. }
  5043. return this.draw();
  5044. }
  5045. if (typeof date === 'string') {
  5046. date = new Date(Date.parse(date));
  5047. }
  5048. if (!isDate(date)) {
  5049. return;
  5050. }
  5051. var min = this._o.minDate, max = this._o.maxDate;
  5052. if (isDate(min) && date < min) {
  5053. date = min;
  5054. } else if (isDate(max) && date > max) {
  5055. date = max;
  5056. }
  5057. this._d = new Date(date.getTime());
  5058. setToStartOfDay(this._d);
  5059. this.gotoDate(this._d);
  5060. if (this._o.field) {
  5061. this._o.field.value = this.toString();
  5062. fireEvent(this._o.field, 'change', { firedBy: this });
  5063. }
  5064. if (!preventOnSelect && typeof this._o.onSelect === 'function') {
  5065. this._o.onSelect.call(this, this.getDate());
  5066. }
  5067. },
  5068. /**
  5069. * change view to a specific date
  5070. */
  5071. gotoDate: function (date) {
  5072. var newCalendar = true;
  5073. if (!isDate(date)) {
  5074. return;
  5075. }
  5076. if (this.calendars) {
  5077. var firstVisibleDate = new Date(this.calendars[0].year, this.calendars[0].month, 1), lastVisibleDate = new Date(this.calendars[this.calendars.length - 1].year, this.calendars[this.calendars.length - 1].month, 1), visibleDate = date.getTime();
  5078. // get the end of the month
  5079. lastVisibleDate.setMonth(lastVisibleDate.getMonth() + 1);
  5080. lastVisibleDate.setDate(lastVisibleDate.getDate() - 1);
  5081. newCalendar = visibleDate < firstVisibleDate.getTime() || lastVisibleDate.getTime() < visibleDate;
  5082. }
  5083. if (newCalendar) {
  5084. this.calendars = [{
  5085. month: date.getMonth(),
  5086. year: date.getFullYear()
  5087. }];
  5088. if (this._o.mainCalendar === 'right') {
  5089. this.calendars[0].month += 1 - this._o.numberOfMonths;
  5090. }
  5091. }
  5092. this.adjustCalendars();
  5093. },
  5094. adjustDate: function (sign, days) {
  5095. var day = this.getDate() || new Date();
  5096. var difference = parseInt(days) * 24 * 60 * 60 * 1000;
  5097. var newDay;
  5098. if (sign === 'add') {
  5099. newDay = new Date(day.valueOf() + difference);
  5100. } else if (sign === 'subtract') {
  5101. newDay = new Date(day.valueOf() - difference);
  5102. }
  5103. this.setDate(newDay);
  5104. },
  5105. adjustCalendars: function () {
  5106. this.calendars[0] = adjustCalendar(this.calendars[0]);
  5107. for (var c = 1; c < this._o.numberOfMonths; c++) {
  5108. this.calendars[c] = adjustCalendar({
  5109. month: this.calendars[0].month + c,
  5110. year: this.calendars[0].year
  5111. });
  5112. }
  5113. this.draw();
  5114. },
  5115. gotoToday: function () {
  5116. this.gotoDate(new Date());
  5117. },
  5118. /**
  5119. * change view to a specific month (zero-index, e.g. 0: January)
  5120. */
  5121. gotoMonth: function (month) {
  5122. if (!isNaN(month)) {
  5123. this.calendars[0].month = parseInt(month, 10);
  5124. this.adjustCalendars();
  5125. }
  5126. },
  5127. nextMonth: function () {
  5128. this.calendars[0].month++;
  5129. this.adjustCalendars();
  5130. },
  5131. prevMonth: function () {
  5132. this.calendars[0].month--;
  5133. this.adjustCalendars();
  5134. },
  5135. /**
  5136. * change view to a specific full year (e.g. "2012")
  5137. */
  5138. gotoYear: function (year) {
  5139. if (!isNaN(year)) {
  5140. this.calendars[0].year = parseInt(year, 10);
  5141. this.adjustCalendars();
  5142. }
  5143. },
  5144. /**
  5145. * change the minDate
  5146. */
  5147. setMinDate: function (value) {
  5148. if (value instanceof Date) {
  5149. setToStartOfDay(value);
  5150. this._o.minDate = value;
  5151. this._o.minYear = value.getFullYear();
  5152. this._o.minMonth = value.getMonth();
  5153. } else {
  5154. this._o.minDate = defaults.minDate;
  5155. this._o.minYear = defaults.minYear;
  5156. this._o.minMonth = defaults.minMonth;
  5157. this._o.startRange = defaults.startRange;
  5158. }
  5159. this.draw();
  5160. },
  5161. /**
  5162. * change the maxDate
  5163. */
  5164. setMaxDate: function (value) {
  5165. if (value instanceof Date) {
  5166. setToStartOfDay(value);
  5167. this._o.maxDate = value;
  5168. this._o.maxYear = value.getFullYear();
  5169. this._o.maxMonth = value.getMonth();
  5170. } else {
  5171. this._o.maxDate = defaults.maxDate;
  5172. this._o.maxYear = defaults.maxYear;
  5173. this._o.maxMonth = defaults.maxMonth;
  5174. this._o.endRange = defaults.endRange;
  5175. }
  5176. this.draw();
  5177. },
  5178. setStartRange: function (value) {
  5179. this._o.startRange = value;
  5180. },
  5181. setEndRange: function (value) {
  5182. this._o.endRange = value;
  5183. },
  5184. /**
  5185. * refresh the HTML
  5186. */
  5187. draw: function (force) {
  5188. if (!this._v && !force) {
  5189. return;
  5190. }
  5191. var opts = this._o, minYear = opts.minYear, maxYear = opts.maxYear, minMonth = opts.minMonth, maxMonth = opts.maxMonth, html = '', randId;
  5192. if (this._y <= minYear) {
  5193. this._y = minYear;
  5194. if (!isNaN(minMonth) && this._m < minMonth) {
  5195. this._m = minMonth;
  5196. }
  5197. }
  5198. if (this._y >= maxYear) {
  5199. this._y = maxYear;
  5200. if (!isNaN(maxMonth) && this._m > maxMonth) {
  5201. this._m = maxMonth;
  5202. }
  5203. }
  5204. randId = 'pika-title-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 2);
  5205. for (var c = 0; c < opts.numberOfMonths; c++) {
  5206. html += '<div class="pika-lendar">' + renderTitle(this, c, this.calendars[c].year, this.calendars[c].month, this.calendars[0].year, randId) + this.render(this.calendars[c].year, this.calendars[c].month, randId) + '</div>';
  5207. }
  5208. this.el.innerHTML = html;
  5209. if (opts.bound) {
  5210. if (opts.field.type !== 'hidden') {
  5211. sto(function () {
  5212. opts.trigger.focus();
  5213. }, 1);
  5214. }
  5215. }
  5216. if (typeof this._o.onDraw === 'function') {
  5217. this._o.onDraw(this);
  5218. }
  5219. if (opts.bound) {
  5220. // let the screen reader user know to use arrow keys
  5221. opts.field.setAttribute('aria-label', 'Use the arrow keys to pick a date');
  5222. }
  5223. },
  5224. adjustPosition: function () {
  5225. var field, pEl, width, height, viewportWidth, viewportHeight, scrollTop, left, top, clientRect;
  5226. if (this._o.container)
  5227. return;
  5228. this.el.style.position = 'absolute';
  5229. field = this._o.trigger;
  5230. pEl = field;
  5231. width = this.el.offsetWidth;
  5232. height = this.el.offsetHeight;
  5233. viewportWidth = window.innerWidth || document.documentElement.clientWidth;
  5234. viewportHeight = window.innerHeight || document.documentElement.clientHeight;
  5235. scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
  5236. if (typeof field.getBoundingClientRect === 'function') {
  5237. clientRect = field.getBoundingClientRect();
  5238. left = clientRect.left + window.pageXOffset;
  5239. top = clientRect.bottom + window.pageYOffset;
  5240. } else {
  5241. left = pEl.offsetLeft;
  5242. top = pEl.offsetTop + pEl.offsetHeight;
  5243. while (pEl = pEl.offsetParent) {
  5244. left += pEl.offsetLeft;
  5245. top += pEl.offsetTop;
  5246. }
  5247. }
  5248. // default position is bottom & left
  5249. if (this._o.reposition && left + width > viewportWidth || this._o.position.indexOf('right') > -1 && left - width + field.offsetWidth > 0) {
  5250. left = left - width + field.offsetWidth;
  5251. }
  5252. if (this._o.reposition && top + height > viewportHeight + scrollTop || this._o.position.indexOf('top') > -1 && top - height - field.offsetHeight > 0) {
  5253. top = top - height - field.offsetHeight;
  5254. }
  5255. this.el.style.left = left + 'px';
  5256. this.el.style.top = top + 'px';
  5257. },
  5258. /**
  5259. * render HTML for a particular month
  5260. */
  5261. render: function (year, month, randId) {
  5262. var opts = this._o, now = new Date(), days = getDaysInMonth(year, month), before = new Date(year, month, 1).getDay(), data = [], row = [];
  5263. setToStartOfDay(now);
  5264. if (opts.firstDay > 0) {
  5265. before -= opts.firstDay;
  5266. if (before < 0) {
  5267. before += 7;
  5268. }
  5269. }
  5270. var previousMonth = month === 0 ? 11 : month - 1, nextMonth = month === 11 ? 0 : month + 1, yearOfPreviousMonth = month === 0 ? year - 1 : year, yearOfNextMonth = month === 11 ? year + 1 : year, daysInPreviousMonth = getDaysInMonth(yearOfPreviousMonth, previousMonth);
  5271. var cells = days + before, after = cells;
  5272. while (after > 7) {
  5273. after -= 7;
  5274. }
  5275. cells += 7 - after;
  5276. var isWeekSelected = false;
  5277. for (var i = 0, r = 0; i < cells; i++) {
  5278. var day = new Date(year, month, 1 + (i - before)), isSelected = isDate(this._d) ? compareDates(day, this._d) : false, isToday = compareDates(day, now), hasEvent = opts.events.indexOf(day.toDateString()) !== -1 ? true : false, isEmpty = i < before || i >= days + before, dayNumber = 1 + (i - before), monthNumber = month, yearNumber = year, isStartRange = opts.startRange && compareDates(opts.startRange, day), isEndRange = opts.endRange && compareDates(opts.endRange, day), isInRange = opts.startRange && opts.endRange && opts.startRange < day && day < opts.endRange, isDisabled = opts.minDate && day < opts.minDate || opts.maxDate && day > opts.maxDate || opts.disableWeekends && isWeekend(day) || opts.disableDayFn && opts.disableDayFn(day);
  5279. if (isEmpty) {
  5280. if (i < before) {
  5281. dayNumber = daysInPreviousMonth + dayNumber;
  5282. monthNumber = previousMonth;
  5283. yearNumber = yearOfPreviousMonth;
  5284. } else {
  5285. dayNumber = dayNumber - days;
  5286. monthNumber = nextMonth;
  5287. yearNumber = yearOfNextMonth;
  5288. }
  5289. }
  5290. var dayConfig = {
  5291. day: dayNumber,
  5292. month: monthNumber,
  5293. year: yearNumber,
  5294. hasEvent: hasEvent,
  5295. isSelected: isSelected,
  5296. isToday: isToday,
  5297. isDisabled: isDisabled,
  5298. isEmpty: isEmpty,
  5299. isStartRange: isStartRange,
  5300. isEndRange: isEndRange,
  5301. isInRange: isInRange,
  5302. showDaysInNextAndPreviousMonths: opts.showDaysInNextAndPreviousMonths,
  5303. enableSelectionDaysInNextAndPreviousMonths: opts.enableSelectionDaysInNextAndPreviousMonths
  5304. };
  5305. if (opts.pickWholeWeek && isSelected) {
  5306. isWeekSelected = true;
  5307. }
  5308. row.push(renderDay(dayConfig));
  5309. if (++r === 7) {
  5310. if (opts.showWeekNumber) {
  5311. row.unshift(renderWeek(i - before, month, year));
  5312. }
  5313. data.push(renderRow(row, opts.isRTL, opts.pickWholeWeek, isWeekSelected));
  5314. row = [];
  5315. r = 0;
  5316. isWeekSelected = false;
  5317. }
  5318. }
  5319. return renderTable(opts, data, randId);
  5320. },
  5321. isVisible: function () {
  5322. return this._v;
  5323. },
  5324. show: function () {
  5325. if (!this.isVisible()) {
  5326. this._v = true;
  5327. this.draw();
  5328. removeClass(this.el, 'is-hidden');
  5329. if (this._o.bound) {
  5330. addEvent(document, 'click', this._onClick);
  5331. this.adjustPosition();
  5332. }
  5333. if (typeof this._o.onOpen === 'function') {
  5334. this._o.onOpen.call(this);
  5335. }
  5336. }
  5337. },
  5338. hide: function () {
  5339. var v = this._v;
  5340. if (v !== false) {
  5341. if (this._o.bound) {
  5342. removeEvent(document, 'click', this._onClick);
  5343. }
  5344. this.el.style.position = 'static';
  5345. // reset
  5346. this.el.style.left = 'auto';
  5347. this.el.style.top = 'auto';
  5348. addClass(this.el, 'is-hidden');
  5349. this._v = false;
  5350. if (v !== undefined && typeof this._o.onClose === 'function') {
  5351. this._o.onClose.call(this);
  5352. }
  5353. }
  5354. },
  5355. /**
  5356. * GAME OVER
  5357. */
  5358. destroy: function () {
  5359. this.hide();
  5360. removeEvent(this.el, 'mousedown', this._onMouseDown, true);
  5361. removeEvent(this.el, 'touchend', this._onMouseDown, true);
  5362. removeEvent(this.el, 'change', this._onChange);
  5363. removeEvent(document, 'keydown', this._onKeyChange);
  5364. if (this._o.field) {
  5365. removeEvent(this._o.field, 'change', this._onInputChange);
  5366. if (this._o.bound) {
  5367. removeEvent(this._o.trigger, 'click', this._onInputClick);
  5368. removeEvent(this._o.trigger, 'focus', this._onInputFocus);
  5369. removeEvent(this._o.trigger, 'blur', this._onInputBlur);
  5370. }
  5371. }
  5372. if (this.el.parentNode) {
  5373. this.el.parentNode.removeChild(this.el);
  5374. }
  5375. }
  5376. };
  5377. return Pikaday;
  5378. }));}
  5379. }, {"models/widgets/abstract_button":365,"models/widgets/abstract_icon":366,"models/widgets/abstract_slider":367,"models/widgets/autocomplete_input":368,"models/widgets/button":369,"models/widgets/checkbox_button_group":370,"models/widgets/checkbox_group":371,"models/widgets/common":372,"models/widgets/date_picker":373,"models/widgets/date_range_slider":374,"models/widgets/date_slider":375,"models/widgets/div":376,"models/widgets/dropdown":377,"models/widgets/index":378,"models/widgets/input_widget":379,"models/widgets/main":380,"models/widgets/markup":381,"models/widgets/multiselect":382,"models/widgets/panel":383,"models/widgets/paragraph":384,"models/widgets/password_input":385,"models/widgets/pretext":386,"models/widgets/radio_button_group":387,"models/widgets/radio_group":388,"models/widgets/range_slider":389,"models/widgets/selectbox":390,"models/widgets/slider":391,"models/widgets/tabs":392,"models/widgets/text_input":393,"models/widgets/toggle":394,"models/widgets/widget":405}, 380);
  5380. })
  5381. //# sourceMappingURL=bokeh-widgets.js.map