powerange.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940
  1. ;
  2. (function () {
  3. /**
  4. * Require the given path.
  5. *
  6. * @param {String} path
  7. * @return {Object} exports
  8. * @api public
  9. */
  10. function require(path, parent, orig) {
  11. var resolved = require.resolve(path);
  12. // lookup failed
  13. if (null == resolved) {
  14. orig = orig || path;
  15. parent = parent || 'root';
  16. var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
  17. err.path = orig;
  18. err.parent = parent;
  19. err.require = true;
  20. throw err;
  21. }
  22. var module = require.modules[resolved];
  23. // perform real require()
  24. // by invoking the module's
  25. // registered function
  26. if (!module._resolving && !module.exports) {
  27. var mod = {};
  28. mod.exports = {};
  29. mod.client = mod.component = true;
  30. module._resolving = true;
  31. module.call(this, mod.exports, require.relative(resolved), mod);
  32. delete module._resolving;
  33. module.exports = mod.exports;
  34. }
  35. return module.exports;
  36. }
  37. /**
  38. * Registered modules.
  39. */
  40. require.modules = {};
  41. /**
  42. * Registered aliases.
  43. */
  44. require.aliases = {};
  45. /**
  46. * Resolve `path`.
  47. *
  48. * Lookup:
  49. *
  50. * - PATH/index.js
  51. * - PATH.js
  52. * - PATH
  53. *
  54. * @param {String} path
  55. * @return {String} path or null
  56. * @api private
  57. */
  58. require.resolve = function (path) {
  59. if (path.charAt(0) === '/') path = path.slice(1);
  60. var paths = [
  61. path,
  62. path + '.js',
  63. path + '.json',
  64. path + '/index.js',
  65. path + '/index.json'
  66. ];
  67. for (var i = 0; i < paths.length; i++) {
  68. var path = paths[i];
  69. if (require.modules.hasOwnProperty(path)) return path;
  70. if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
  71. }
  72. };
  73. /**
  74. * Normalize `path` relative to the current path.
  75. *
  76. * @param {String} curr
  77. * @param {String} path
  78. * @return {String}
  79. * @api private
  80. */
  81. require.normalize = function (curr, path) {
  82. var segs = [];
  83. if ('.' != path.charAt(0)) return path;
  84. curr = curr.split('/');
  85. path = path.split('/');
  86. for (var i = 0; i < path.length; ++i) {
  87. if ('..' == path[i]) {
  88. curr.pop();
  89. } else if ('.' != path[i] && '' != path[i]) {
  90. segs.push(path[i]);
  91. }
  92. }
  93. return curr.concat(segs).join('/');
  94. };
  95. /**
  96. * Register module at `path` with callback `definition`.
  97. *
  98. * @param {String} path
  99. * @param {Function} definition
  100. * @api private
  101. */
  102. require.register = function (path, definition) {
  103. require.modules[path] = definition;
  104. };
  105. /**
  106. * Alias a module definition.
  107. *
  108. * @param {String} from
  109. * @param {String} to
  110. * @api private
  111. */
  112. require.alias = function (from, to) {
  113. if (!require.modules.hasOwnProperty(from)) {
  114. throw new Error('Failed to alias "' + from + '", it does not exist');
  115. }
  116. require.aliases[to] = from;
  117. };
  118. /**
  119. * Return a require function relative to the `parent` path.
  120. *
  121. * @param {String} parent
  122. * @return {Function}
  123. * @api private
  124. */
  125. require.relative = function (parent) {
  126. var p = require.normalize(parent, '..');
  127. /**
  128. * lastIndexOf helper.
  129. */
  130. function lastIndexOf(arr, obj) {
  131. var i = arr.length;
  132. while (i--) {
  133. if (arr[i] === obj) return i;
  134. }
  135. return -1;
  136. }
  137. /**
  138. * The relative require() itself.
  139. */
  140. function localRequire(path) {
  141. var resolved = localRequire.resolve(path);
  142. return require(resolved, parent, path);
  143. }
  144. /**
  145. * Resolve relative to the parent.
  146. */
  147. localRequire.resolve = function (path) {
  148. var c = path.charAt(0);
  149. if ('/' == c) return path.slice(1);
  150. if ('.' == c) return require.normalize(p, path);
  151. // resolve deps by returning
  152. // the dep in the nearest "deps"
  153. // directory
  154. var segs = parent.split('/');
  155. var i = lastIndexOf(segs, 'deps') + 1;
  156. if (!i) i = 0;
  157. path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
  158. return path;
  159. };
  160. /**
  161. * Check if module is defined at `path`.
  162. */
  163. localRequire.exists = function (path) {
  164. return require.modules.hasOwnProperty(localRequire.resolve(path));
  165. };
  166. return localRequire;
  167. };
  168. require.register("component-event/index.js", function (exports, require, module) {
  169. var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
  170. unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
  171. prefix = bind !== 'addEventListener' ? 'on' : '';
  172. /**
  173. * Bind `el` event `type` to `fn`.
  174. *
  175. * @param {Element} el
  176. * @param {String} type
  177. * @param {Function} fn
  178. * @param {Boolean} capture
  179. * @return {Function}
  180. * @api public
  181. */
  182. exports.bind = function (el, type, fn, capture) {
  183. el[bind](prefix + type, fn, capture || false);
  184. return fn;
  185. };
  186. /**
  187. * Unbind `el` event `type`'s callback `fn`.
  188. *
  189. * @param {Element} el
  190. * @param {String} type
  191. * @param {Function} fn
  192. * @param {Boolean} capture
  193. * @return {Function}
  194. * @api public
  195. */
  196. exports.unbind = function (el, type, fn, capture) {
  197. el[unbind](prefix + type, fn, capture || false);
  198. return fn;
  199. };
  200. });
  201. require.register("component-query/index.js", function (exports, require, module) {
  202. function one(selector, el) {
  203. return el.querySelector(selector);
  204. }
  205. exports = module.exports = function (selector, el) {
  206. el = el || document;
  207. return one(selector, el);
  208. };
  209. exports.all = function (selector, el) {
  210. el = el || document;
  211. return el.querySelectorAll(selector);
  212. };
  213. exports.engine = function (obj) {
  214. if (!obj.one) throw new Error('.one callback required');
  215. if (!obj.all) throw new Error('.all callback required');
  216. one = obj.one;
  217. exports.all = obj.all;
  218. return exports;
  219. };
  220. });
  221. require.register("component-matches-selector/index.js", function (exports, require, module) {
  222. /**
  223. * Module dependencies.
  224. */
  225. var query = require('query');
  226. /**
  227. * Element prototype.
  228. */
  229. var proto = Element.prototype;
  230. /**
  231. * Vendor function.
  232. */
  233. var vendor = proto.matches || proto.webkitMatchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector;
  234. /**
  235. * Expose `match()`.
  236. */
  237. module.exports = match;
  238. /**
  239. * Match `el` to `selector`.
  240. *
  241. * @param {Element} el
  242. * @param {String} selector
  243. * @return {Boolean}
  244. * @api public
  245. */
  246. function match(el, selector) {
  247. if (vendor) return vendor.call(el, selector);
  248. var nodes = query.all(selector, el.parentNode);
  249. for (var i = 0; i < nodes.length; ++i) {
  250. if (nodes[i] == el) return true;
  251. }
  252. return false;
  253. }
  254. });
  255. require.register("discore-closest/index.js", function (exports, require, module) {
  256. var matches = require('matches-selector')
  257. module.exports = function (element, selector, checkYoSelf, root) {
  258. element = checkYoSelf ? {
  259. parentNode: element
  260. } : element
  261. root = root || document
  262. // Make sure `element !== document` and `element != null`
  263. // otherwise we get an illegal invocation
  264. while ((element = element.parentNode) && element !== document) {
  265. if (matches(element, selector))
  266. return element
  267. // After `matches` on the edge case that
  268. // the selector matches the root
  269. // (when the root is not the document)
  270. if (element === root)
  271. return
  272. }
  273. }
  274. });
  275. require.register("component-delegate/index.js", function (exports, require, module) {
  276. /**
  277. * Module dependencies.
  278. */
  279. var closest = require('closest'),
  280. event = require('event');
  281. /**
  282. * Delegate event `type` to `selector`
  283. * and invoke `fn(e)`. A callback function
  284. * is returned which may be passed to `.unbind()`.
  285. *
  286. * @param {Element} el
  287. * @param {String} selector
  288. * @param {String} type
  289. * @param {Function} fn
  290. * @param {Boolean} capture
  291. * @return {Function}
  292. * @api public
  293. */
  294. exports.bind = function (el, selector, type, fn, capture) {
  295. return event.bind(el, type, function (e) {
  296. var target = e.target || e.srcElement;
  297. e.delegateTarget = closest(target, selector, true, el);
  298. if (e.delegateTarget) fn.call(el, e);
  299. }, capture);
  300. };
  301. /**
  302. * Unbind event `type`'s callback `fn`.
  303. *
  304. * @param {Element} el
  305. * @param {String} type
  306. * @param {Function} fn
  307. * @param {Boolean} capture
  308. * @api public
  309. */
  310. exports.unbind = function (el, type, fn, capture) {
  311. event.unbind(el, type, fn, capture);
  312. };
  313. });
  314. require.register("component-events/index.js", function (exports, require, module) {
  315. /**
  316. * Module dependencies.
  317. */
  318. var events = require('event');
  319. var delegate = require('delegate');
  320. /**
  321. * Expose `Events`.
  322. */
  323. module.exports = Events;
  324. /**
  325. * Initialize an `Events` with the given
  326. * `el` object which events will be bound to,
  327. * and the `obj` which will receive method calls.
  328. *
  329. * @param {Object} el
  330. * @param {Object} obj
  331. * @api public
  332. */
  333. function Events(el, obj) {
  334. if (!(this instanceof Events)) return new Events(el, obj);
  335. if (!el) throw new Error('element required');
  336. if (!obj) throw new Error('object required');
  337. this.el = el;
  338. this.obj = obj;
  339. this._events = {};
  340. }
  341. /**
  342. * Subscription helper.
  343. */
  344. Events.prototype.sub = function (event, method, cb) {
  345. this._events[event] = this._events[event] || {};
  346. this._events[event][method] = cb;
  347. };
  348. /**
  349. * Bind to `event` with optional `method` name.
  350. * When `method` is undefined it becomes `event`
  351. * with the "on" prefix.
  352. *
  353. * Examples:
  354. *
  355. * Direct event handling:
  356. *
  357. * events.bind('click') // implies "onclick"
  358. * events.bind('click', 'remove')
  359. * events.bind('click', 'sort', 'asc')
  360. *
  361. * Delegated event handling:
  362. *
  363. * events.bind('click li > a')
  364. * events.bind('click li > a', 'remove')
  365. * events.bind('click a.sort-ascending', 'sort', 'asc')
  366. * events.bind('click a.sort-descending', 'sort', 'desc')
  367. *
  368. * @param {String} event
  369. * @param {String|function} [method]
  370. * @return {Function} callback
  371. * @api public
  372. */
  373. Events.prototype.bind = function (event, method) {
  374. var e = parse(event);
  375. var el = this.el;
  376. var obj = this.obj;
  377. var name = e.name;
  378. var method = method || 'on' + name;
  379. var args = [].slice.call(arguments, 2);
  380. // callback
  381. function cb() {
  382. var a = [].slice.call(arguments).concat(args);
  383. obj[method].apply(obj, a);
  384. }
  385. // bind
  386. if (e.selector) {
  387. cb = delegate.bind(el, e.selector, name, cb);
  388. } else {
  389. events.bind(el, name, cb);
  390. }
  391. // subscription for unbinding
  392. this.sub(name, method, cb);
  393. return cb;
  394. };
  395. /**
  396. * Unbind a single binding, all bindings for `event`,
  397. * or all bindings within the manager.
  398. *
  399. * Examples:
  400. *
  401. * Unbind direct handlers:
  402. *
  403. * events.unbind('click', 'remove')
  404. * events.unbind('click')
  405. * events.unbind()
  406. *
  407. * Unbind delegate handlers:
  408. *
  409. * events.unbind('click', 'remove')
  410. * events.unbind('click')
  411. * events.unbind()
  412. *
  413. * @param {String|Function} [event]
  414. * @param {String|Function} [method]
  415. * @api public
  416. */
  417. Events.prototype.unbind = function (event, method) {
  418. if (0 == arguments.length) return this.unbindAll();
  419. if (1 == arguments.length) return this.unbindAllOf(event);
  420. // no bindings for this event
  421. var bindings = this._events[event];
  422. if (!bindings) return;
  423. // no bindings for this method
  424. var cb = bindings[method];
  425. if (!cb) return;
  426. events.unbind(this.el, event, cb);
  427. };
  428. /**
  429. * Unbind all events.
  430. *
  431. * @api private
  432. */
  433. Events.prototype.unbindAll = function () {
  434. for (var event in this._events) {
  435. this.unbindAllOf(event);
  436. }
  437. };
  438. /**
  439. * Unbind all events for `event`.
  440. *
  441. * @param {String} event
  442. * @api private
  443. */
  444. Events.prototype.unbindAllOf = function (event) {
  445. var bindings = this._events[event];
  446. if (!bindings) return;
  447. for (var method in bindings) {
  448. this.unbind(event, method);
  449. }
  450. };
  451. /**
  452. * Parse `event`.
  453. *
  454. * @param {String} event
  455. * @return {Object}
  456. * @api private
  457. */
  458. function parse(event) {
  459. var parts = event.split(/ +/);
  460. return {
  461. name: parts.shift(),
  462. selector: parts.join(' ')
  463. }
  464. }
  465. });
  466. require.register("component-indexof/index.js", function (exports, require, module) {
  467. module.exports = function (arr, obj) {
  468. if (arr.indexOf) return arr.indexOf(obj);
  469. for (var i = 0; i < arr.length; ++i) {
  470. if (arr[i] === obj) return i;
  471. }
  472. return -1;
  473. };
  474. });
  475. require.register("component-classes/index.js", function (exports, require, module) {
  476. /**
  477. * Module dependencies.
  478. */
  479. var index = require('indexof');
  480. /**
  481. * Whitespace regexp.
  482. */
  483. var re = /\s+/;
  484. /**
  485. * toString reference.
  486. */
  487. var toString = Object.prototype.toString;
  488. /**
  489. * Wrap `el` in a `ClassList`.
  490. *
  491. * @param {Element} el
  492. * @return {ClassList}
  493. * @api public
  494. */
  495. module.exports = function (el) {
  496. return new ClassList(el);
  497. };
  498. /**
  499. * Initialize a new ClassList for `el`.
  500. *
  501. * @param {Element} el
  502. * @api private
  503. */
  504. function ClassList(el) {
  505. if (!el) throw new Error('A DOM element reference is required');
  506. this.el = el;
  507. this.list = el.classList;
  508. }
  509. /**
  510. * Add class `name` if not already present.
  511. *
  512. * @param {String} name
  513. * @return {ClassList}
  514. * @api public
  515. */
  516. ClassList.prototype.add = function (name) {
  517. // classList
  518. if (this.list) {
  519. this.list.add(name);
  520. return this;
  521. }
  522. // fallback
  523. var arr = this.array();
  524. var i = index(arr, name);
  525. if (!~i) arr.push(name);
  526. this.el.className = arr.join(' ');
  527. return this;
  528. };
  529. /**
  530. * Remove class `name` when present, or
  531. * pass a regular expression to remove
  532. * any which match.
  533. *
  534. * @param {String|RegExp} name
  535. * @return {ClassList}
  536. * @api public
  537. */
  538. ClassList.prototype.remove = function (name) {
  539. if ('[object RegExp]' == toString.call(name)) {
  540. return this.removeMatching(name);
  541. }
  542. // classList
  543. if (this.list) {
  544. this.list.remove(name);
  545. return this;
  546. }
  547. // fallback
  548. var arr = this.array();
  549. var i = index(arr, name);
  550. if (~i) arr.splice(i, 1);
  551. this.el.className = arr.join(' ');
  552. return this;
  553. };
  554. /**
  555. * Remove all classes matching `re`.
  556. *
  557. * @param {RegExp} re
  558. * @return {ClassList}
  559. * @api private
  560. */
  561. ClassList.prototype.removeMatching = function (re) {
  562. var arr = this.array();
  563. for (var i = 0; i < arr.length; i++) {
  564. if (re.test(arr[i])) {
  565. this.remove(arr[i]);
  566. }
  567. }
  568. return this;
  569. };
  570. /**
  571. * Toggle class `name`, can force state via `force`.
  572. *
  573. * For browsers that support classList, but do not support `force` yet,
  574. * the mistake will be detected and corrected.
  575. *
  576. * @param {String} name
  577. * @param {Boolean} force
  578. * @return {ClassList}
  579. * @api public
  580. */
  581. ClassList.prototype.toggle = function (name, force) {
  582. // classList
  583. if (this.list) {
  584. if ("undefined" !== typeof force) {
  585. if (force !== this.list.toggle(name, force)) {
  586. this.list.toggle(name); // toggle again to correct
  587. }
  588. } else {
  589. this.list.toggle(name);
  590. }
  591. return this;
  592. }
  593. // fallback
  594. if ("undefined" !== typeof force) {
  595. if (!force) {
  596. this.remove(name);
  597. } else {
  598. this.add(name);
  599. }
  600. } else {
  601. if (this.has(name)) {
  602. this.remove(name);
  603. } else {
  604. this.add(name);
  605. }
  606. }
  607. return this;
  608. };
  609. /**
  610. * Return an array of classes.
  611. *
  612. * @return {Array}
  613. * @api public
  614. */
  615. ClassList.prototype.array = function () {
  616. var str = this.el.className.replace(/^\s+|\s+$/g, '');
  617. var arr = str.split(re);
  618. if ('' === arr[0]) arr.shift();
  619. return arr;
  620. };
  621. /**
  622. * Check if class `name` is present.
  623. *
  624. * @param {String} name
  625. * @return {ClassList}
  626. * @api public
  627. */
  628. ClassList.prototype.has =
  629. ClassList.prototype.contains = function (name) {
  630. return this.list ? this.list.contains(name) : !!~index(this.array(), name);
  631. };
  632. });
  633. require.register("component-emitter/index.js", function (exports, require, module) {
  634. /**
  635. * Expose `Emitter`.
  636. */
  637. module.exports = Emitter;
  638. /**
  639. * Initialize a new `Emitter`.
  640. *
  641. * @api public
  642. */
  643. function Emitter(obj) {
  644. if (obj) return mixin(obj);
  645. };
  646. /**
  647. * Mixin the emitter properties.
  648. *
  649. * @param {Object} obj
  650. * @return {Object}
  651. * @api private
  652. */
  653. function mixin(obj) {
  654. for (var key in Emitter.prototype) {
  655. obj[key] = Emitter.prototype[key];
  656. }
  657. return obj;
  658. }
  659. /**
  660. * Listen on the given `event` with `fn`.
  661. *
  662. * @param {String} event
  663. * @param {Function} fn
  664. * @return {Emitter}
  665. * @api public
  666. */
  667. Emitter.prototype.on =
  668. Emitter.prototype.addEventListener = function (event, fn) {
  669. this._callbacks = this._callbacks || {};
  670. (this._callbacks[event] = this._callbacks[event] || [])
  671. .push(fn);
  672. return this;
  673. };
  674. /**
  675. * Adds an `event` listener that will be invoked a single
  676. * time then automatically removed.
  677. *
  678. * @param {String} event
  679. * @param {Function} fn
  680. * @return {Emitter}
  681. * @api public
  682. */
  683. Emitter.prototype.once = function (event, fn) {
  684. var self = this;
  685. this._callbacks = this._callbacks || {};
  686. function on() {
  687. self.off(event, on);
  688. fn.apply(this, arguments);
  689. }
  690. on.fn = fn;
  691. this.on(event, on);
  692. return this;
  693. };
  694. /**
  695. * Remove the given callback for `event` or all
  696. * registered callbacks.
  697. *
  698. * @param {String} event
  699. * @param {Function} fn
  700. * @return {Emitter}
  701. * @api public
  702. */
  703. Emitter.prototype.off =
  704. Emitter.prototype.removeListener =
  705. Emitter.prototype.removeAllListeners =
  706. Emitter.prototype.removeEventListener = function (event, fn) {
  707. this._callbacks = this._callbacks || {};
  708. // all
  709. if (0 == arguments.length) {
  710. this._callbacks = {};
  711. return this;
  712. }
  713. // specific event
  714. var callbacks = this._callbacks[event];
  715. if (!callbacks) return this;
  716. // remove all handlers
  717. if (1 == arguments.length) {
  718. delete this._callbacks[event];
  719. return this;
  720. }
  721. // remove specific handler
  722. var cb;
  723. for (var i = 0; i < callbacks.length; i++) {
  724. cb = callbacks[i];
  725. if (cb === fn || cb.fn === fn) {
  726. callbacks.splice(i, 1);
  727. break;
  728. }
  729. }
  730. return this;
  731. };
  732. /**
  733. * Emit `event` with the given args.
  734. *
  735. * @param {String} event
  736. * @param {Mixed} ...
  737. * @return {Emitter}
  738. */
  739. Emitter.prototype.emit = function (event) {
  740. this._callbacks = this._callbacks || {};
  741. var args = [].slice.call(arguments, 1),
  742. callbacks = this._callbacks[event];
  743. if (callbacks) {
  744. callbacks = callbacks.slice(0);
  745. for (var i = 0, len = callbacks.length; i < len; ++i) {
  746. callbacks[i].apply(this, args);
  747. }
  748. }
  749. return this;
  750. };
  751. /**
  752. * Return array of callbacks for `event`.
  753. *
  754. * @param {String} event
  755. * @return {Array}
  756. * @api public
  757. */
  758. Emitter.prototype.listeners = function (event) {
  759. this._callbacks = this._callbacks || {};
  760. return this._callbacks[event] || [];
  761. };
  762. /**
  763. * Check if this emitter has `event` handlers.
  764. *
  765. * @param {String} event
  766. * @return {Boolean}
  767. * @api public
  768. */
  769. Emitter.prototype.hasListeners = function (event) {
  770. return !!this.listeners(event).length;
  771. };
  772. });
  773. require.register("ui-component-mouse/index.js", function (exports, require, module) {
  774. /**
  775. * dependencies.
  776. */
  777. var emitter = require('emitter'),
  778. event = require('event');
  779. /**
  780. * export `Mouse`
  781. */
  782. module.exports = function (el, obj) {
  783. return new Mouse(el, obj);
  784. };
  785. /**
  786. * initialize new `Mouse`.
  787. *
  788. * @param {Element} el
  789. * @param {Object} obj
  790. */
  791. function Mouse(el, obj) {
  792. this.obj = obj || {};
  793. this.el = el;
  794. }
  795. /**
  796. * mixin emitter.
  797. */
  798. emitter(Mouse.prototype);
  799. /**
  800. * bind mouse.
  801. *
  802. * @return {Mouse}
  803. */
  804. Mouse.prototype.bind = function () {
  805. var obj = this.obj,
  806. self = this;
  807. // up
  808. function up(e) {
  809. obj.onmouseup && obj.onmouseup(e);
  810. event.unbind(document, 'mousemove', move);
  811. event.unbind(document, 'mouseup', up);
  812. self.emit('up', e);
  813. }
  814. // move
  815. function move(e) {
  816. obj.onmousemove && obj.onmousemove(e);
  817. self.emit('move', e);
  818. }
  819. // down
  820. self.down = function (e) {
  821. obj.onmousedown && obj.onmousedown(e);
  822. event.bind(document, 'mouseup', up);
  823. event.bind(document, 'mousemove', move);
  824. self.emit('down', e);
  825. };
  826. // bind all.
  827. event.bind(this.el, 'mousedown', self.down);
  828. return this;
  829. };
  830. /**
  831. * unbind mouse.
  832. *
  833. * @return {Mouse}
  834. */
  835. Mouse.prototype.unbind = function () {
  836. event.unbind(this.el, 'mousedown', this.down);
  837. this.down = null;
  838. };
  839. });
  840. require.register("abpetkov-percentage-calc/percentage-calc.js", function (exports, require, module) {
  841. /**
  842. * Percentage-Calc 0.0.1
  843. * https://github.com/abpetkov/percentage-calc
  844. *
  845. * Authored by Alexander Petkov
  846. * https://github.com/abpetkov
  847. *
  848. * Copyright 2014, Alexander Petkov
  849. * License: The MIT License (MIT)
  850. * http://opensource.org/licenses/MIT
  851. *
  852. */
  853. /**
  854. * Check if number.
  855. *
  856. * @param {Number} num
  857. * @returns {Boolean}
  858. * @api public
  859. */
  860. exports.isNumber = function (num) {
  861. return (typeof num === 'number') ? true : false;
  862. };
  863. /**
  864. * Calculate percentage of a number.
  865. *
  866. * @param {Number} perc
  867. * @param {Number} num
  868. * @returns {Number} result
  869. * @api public
  870. */
  871. exports.of = function (perc, num) {
  872. if (exports.isNumber(perc) && exports.isNumber(num)) return (perc / 100) * num;
  873. };
  874. /**
  875. * Calculate percentage of a number out ot another number.
  876. *
  877. * @param {Number} part
  878. * @param {Number} target
  879. * @returns {Number} result
  880. * @api public
  881. */
  882. exports.from = function (part, target) {
  883. if (exports.isNumber(part) && exports.isNumber(target)) return (part / target) * 100;
  884. };
  885. });
  886. require.register("abpetkov-closest-num/closest-num.js", function (exports, require, module) {
  887. /**
  888. * Closest-num 0.0.1
  889. * https://github.com/abpetkov/closest-num
  890. *
  891. * Author: Alexander Petkov
  892. * https://github.com/abpetkov
  893. *
  894. * Copyright 2014, Alexander Petkov
  895. * License: The MIT License (MIT)
  896. * http://opensource.org/licenses/MIT
  897. *
  898. */
  899. /**
  900. * Get closest number in array.
  901. *
  902. * @param {Number} target
  903. * @param {Array} points
  904. * @returns {Number} closest
  905. * @api private
  906. */
  907. exports.find = function (target, points) {
  908. var diff = null,
  909. current = null,
  910. closest = points[0];
  911. for (i = 0; i < points.length; i++) {
  912. diff = Math.abs(target - closest);
  913. current = Math.abs(target - points[i]);
  914. if (current < diff) closest = points[i];
  915. }
  916. return closest;
  917. };
  918. });
  919. require.register("vesln-super/lib/super.js", function (exports, require, module) {
  920. /**
  921. * slice
  922. */
  923. var slice = Array.prototype.slice;
  924. /**
  925. * Primary export
  926. */
  927. var exports = module.exports = super_;
  928. /**
  929. * ### _super (dest, orig)
  930. *
  931. * Inherits the prototype methods or merges objects.
  932. * This is the primary export and it is recommended
  933. * that it be imported as `inherits` in node to match
  934. * the auto imported browser interface.
  935. *
  936. * var inherits = require('super');
  937. *
  938. * @param {Object|Function} destination object
  939. * @param {Object|Function} source object
  940. * @name _super
  941. * @api public
  942. */
  943. function super_() {
  944. var args = slice.call(arguments);
  945. if (!args.length) return;
  946. if (typeof args[0] !== 'function') return exports.merge(args);
  947. exports.inherits.apply(null, args);
  948. };
  949. /**
  950. * ### extend (proto[, klass])
  951. *
  952. * Provide `.extend` mechanism to allow extenion without
  953. * needing to use dependancy.
  954. *
  955. * function Bar () {
  956. * this._konstructed = true;
  957. * }
  958. *
  959. * Bar.extend = inherits.extend;
  960. *
  961. * var Fu = Bar.extend({
  962. * initialize: function () {
  963. * this._initialized = true;
  964. * }
  965. * });
  966. *
  967. * var fu = new Fu();
  968. * fu.should.be.instanceof(Fu); // true
  969. * fu.should.be.instanceof(Bar); // true
  970. *
  971. * @param {Object} properties/methods to add to new prototype
  972. * @param {Object} properties/methods to add to new class
  973. * @returns {Object} new constructor
  974. * @name extend
  975. * @api public
  976. */
  977. exports.extend = function (proto, klass) {
  978. var self = this,
  979. child = function () {
  980. return self.apply(this, arguments);
  981. };
  982. exports.merge([child, this]);
  983. exports.inherits(child, this);
  984. if (proto) exports.merge([child.prototype, proto]);
  985. if (klass) exports.merge([child, klass]);
  986. child.extend = this.extend; // prevent overwrite
  987. return child;
  988. };
  989. /**
  990. * ### inherits (ctor, superCtor)
  991. *
  992. * Inherit the prototype methods from on contructor
  993. * to another.
  994. *
  995. * @param {Function} destination
  996. * @param {Function} source
  997. * @api private
  998. */
  999. exports.inherits = function (ctor, superCtor) {
  1000. ctor.super_ = superCtor;
  1001. if (Object.create) {
  1002. ctor.prototype = Object.create(superCtor.prototype, {
  1003. constructor: {
  1004. value: ctor,
  1005. enumerable: false,
  1006. writable: true,
  1007. configurable: true
  1008. }
  1009. });
  1010. } else {
  1011. ctor.prototype = new superCtor();
  1012. ctor.prototype.constructor = ctor;
  1013. }
  1014. }
  1015. /**
  1016. * Extends multiple objects.
  1017. *
  1018. * @param {Array} array of objects
  1019. * @api private
  1020. */
  1021. exports.merge = function (arr) {
  1022. var main = arr.length === 2 ? arr.shift() : {};
  1023. var obj = null;
  1024. for (var i = 0, len = arr.length; i < len; i++) {
  1025. obj = arr[i];
  1026. for (var p in obj) {
  1027. if (!obj.hasOwnProperty(p)) continue;
  1028. main[p] = obj[p];
  1029. }
  1030. }
  1031. return main;
  1032. };
  1033. });
  1034. require.register("powerange/lib/powerange.js", function (exports, require, module) {
  1035. /**
  1036. * Require classes.
  1037. */
  1038. var Main = require('./main'),
  1039. Horizontal = require('./horizontal'),
  1040. Vertical = require('./vertical');
  1041. /**
  1042. * Set default values.
  1043. *
  1044. * @api public
  1045. */
  1046. var defaults = {
  1047. callback: function () {},
  1048. decimal: false,
  1049. disable: false,
  1050. disableOpacity: 0.5,
  1051. hideRange: false,
  1052. klass: '',
  1053. min: 0,
  1054. max: 100,
  1055. handleDiameter: 20,
  1056. touchDiameter: 42,
  1057. start: null,
  1058. step: null,
  1059. vertical: false
  1060. };
  1061. /**
  1062. * Expose proper type of `Powerange`.
  1063. */
  1064. module.exports = function (element, options) {
  1065. options = options || {};
  1066. for (var i in defaults) {
  1067. if (options[i] == null) {
  1068. options[i] = defaults[i];
  1069. }
  1070. }
  1071. if (options.vertical) {
  1072. return new Vertical(element, options);
  1073. } else {
  1074. return new Horizontal(element, options);
  1075. }
  1076. };
  1077. });
  1078. require.register("powerange/lib/main.js", function (exports, require, module) {
  1079. /**
  1080. * External dependencies.
  1081. *
  1082. */
  1083. var mouse = require('mouse'),
  1084. events = require('events'),
  1085. classes = require('classes'),
  1086. percentage = require('percentage-calc');
  1087. /**
  1088. * Expose `Powerange`.
  1089. */
  1090. module.exports = Powerange;
  1091. /**
  1092. * Create Powerange object.
  1093. *
  1094. * @constructor
  1095. * @param {Object} element
  1096. * @param {Object} options
  1097. * @api public
  1098. */
  1099. function Powerange(element, options) {
  1100. if (!(this instanceof Powerange)) return new Powerange(element, options);
  1101. this.element = element;
  1102. this.options = options || {};
  1103. //this.slider = this.create('span', 'range-bar');
  1104. this.slider = this.create('div', 'range-container');
  1105. if (this.element !== null && this.element.type === 'text') this.init();
  1106. }
  1107. /**
  1108. * Bind events on handle element.
  1109. *
  1110. * @api private
  1111. */
  1112. Powerange.prototype.bindEvents = function () {
  1113. this.handle = this.slider.querySelector('.range-handle');
  1114. this.touch = events(this.slider, this);
  1115. this.touch.bind('touchstart', 'onmousedown');
  1116. this.touch.bind('touchmove', 'onmousemove');
  1117. this.touch.bind('touchend', 'onmouseup');
  1118. this.mouse = mouse(this.slider, this);
  1119. this.mouse.bind();
  1120. };
  1121. /**
  1122. * Hide the target element.
  1123. *
  1124. * @api private
  1125. */
  1126. Powerange.prototype.hide = function () {
  1127. this.element.style.display = 'none';
  1128. };
  1129. /**
  1130. * Append the target after the element.
  1131. *
  1132. * @api private
  1133. */
  1134. Powerange.prototype.append = function () {
  1135. var slider = this.generate();
  1136. this.insertAfter(this.element, slider);
  1137. };
  1138. /**
  1139. * Generate the appropriate type of slider.
  1140. *
  1141. * @returns {Object} this.slider
  1142. * @api private
  1143. */
  1144. Powerange.prototype.generate = function () {
  1145. var elems = {
  1146. 'handle': {
  1147. 'type': 'span',
  1148. 'selector': 'range-handle'
  1149. },
  1150. 'min': {
  1151. 'type': 'span',
  1152. 'selector': 'range-min'
  1153. },
  1154. 'max': {
  1155. 'type': 'span',
  1156. 'selector': 'range-max'
  1157. },
  1158. 'quantity': {
  1159. 'type': 'span',
  1160. 'selector': 'range-quantity'
  1161. }
  1162. };
  1163. var bar = this.create('span', 'range-bar');
  1164. this.slider.appendChild(bar);
  1165. for (var key in elems) {
  1166. if (elems.hasOwnProperty(key)) {
  1167. var temp = this.create(elems[key].type, elems[key].selector);
  1168. bar.appendChild(temp);
  1169. }
  1170. }
  1171. return this.slider;
  1172. };
  1173. /**
  1174. * Create HTML element.
  1175. *
  1176. * @param {String} type
  1177. * @param {String} name
  1178. * @returns {Object} elem
  1179. * @api private
  1180. */
  1181. Powerange.prototype.create = function (type, name) {
  1182. var elem = document.createElement(type);
  1183. elem.className = name;
  1184. return elem;
  1185. };
  1186. /**
  1187. * Insert element after another element.
  1188. *
  1189. * @param {Object} reference
  1190. * @param {Object} target
  1191. * @api private
  1192. */
  1193. Powerange.prototype.insertAfter = function (reference, target) {
  1194. reference.parentNode.insertBefore(target, reference.nextSibling);
  1195. };
  1196. /**
  1197. * Add an additional class for extra customization.
  1198. *
  1199. * @param {String} klass
  1200. * @api private
  1201. */
  1202. Powerange.prototype.extraClass = function (klass) {
  1203. if (this.options.klass) classes(this.slider).add(klass);
  1204. };
  1205. /**
  1206. * Set min and max values.
  1207. *
  1208. * @param {Number} min
  1209. * @param {Number} max
  1210. * @api private
  1211. */
  1212. Powerange.prototype.setRange = function (min, max) {
  1213. if (typeof min === 'number' && typeof max === 'number' && !this.options.hideRange) {
  1214. this.slider.querySelector('.range-min').innerHTML = min;
  1215. this.slider.querySelector('.range-max').innerHTML = max;
  1216. }
  1217. };
  1218. /**
  1219. * Set slider current value.
  1220. *
  1221. * @param {Number} offset
  1222. * @param {Number} size
  1223. * @api private
  1224. */
  1225. Powerange.prototype.setValue = function (offset, size) {
  1226. var part = percentage.from(parseFloat(offset), size),
  1227. value = percentage.of(part, this.options.max - this.options.min) + this.options.min,
  1228. changed = false;
  1229. value = (this.options.decimal) ? (Math.round(value * 100) / 100) : Math.round(value);
  1230. changed = (this.element.value != value) ? true : false;
  1231. this.element.value = value;
  1232. this.options.callback();
  1233. if (changed) this.changeEvent();
  1234. };
  1235. /**
  1236. * Set step.
  1237. *
  1238. * @param {Number} sliderSize
  1239. * @param {Number} handleSize
  1240. * @returns {Array} this.steps
  1241. * @api private
  1242. */
  1243. Powerange.prototype.step = function (sliderSize, handleSize) {
  1244. var dimension = sliderSize - handleSize,
  1245. part = percentage.from(this.checkStep(this.options.step), this.options.max - this.options.min),
  1246. interval = percentage.of(part, dimension),
  1247. steps = [];
  1248. if (interval == 0) interval = 1;
  1249. for (i = 0; i <= dimension; i += interval) {
  1250. steps.push(i);
  1251. }
  1252. this.steps = steps;
  1253. return this.steps;
  1254. };
  1255. /**
  1256. * Check values.
  1257. *
  1258. * @param {Number} start
  1259. * @api private
  1260. */
  1261. Powerange.prototype.checkValues = function (start) {
  1262. if (start < this.options.min) this.options.start = this.options.min;
  1263. if (start > this.options.max) this.options.start = this.options.max;
  1264. if (this.options.min >= this.options.max) this.options.min = this.options.max;
  1265. };
  1266. /**
  1267. * Make sure `step` is positive.
  1268. *
  1269. * @param {Number} value
  1270. * @returns {Number} this.options.step
  1271. * @api private
  1272. */
  1273. Powerange.prototype.checkStep = function (value) {
  1274. if (value < 0) value = Math.abs(value);
  1275. this.options.step = value;
  1276. return this.options.step;
  1277. };
  1278. /**
  1279. * Disable range slider.
  1280. *
  1281. * @api private
  1282. */
  1283. Powerange.prototype.disable = function () {
  1284. if (this.options.min == this.options.max || this.options.min > this.options.max || this.options.disable) {
  1285. this.mouse.unbind();
  1286. this.touch.unbind();
  1287. this.slider.style.opacity = this.options.disableOpacity;
  1288. classes(this.handle).add('range-disabled');
  1289. }
  1290. };
  1291. /**
  1292. * Make element unselectable.
  1293. *
  1294. * @param {Object} element
  1295. * @param {Boolean} set
  1296. * @api private
  1297. */
  1298. Powerange.prototype.unselectable = function (element, set) {
  1299. if (!classes(this.slider).has('unselectable') && set === true) {
  1300. classes(this.slider).add('unselectable');
  1301. } else {
  1302. classes(this.slider).remove('unselectable');
  1303. }
  1304. };
  1305. /**
  1306. * Handle the onchange event.
  1307. *
  1308. * @param {Boolean} state
  1309. * @api private
  1310. */
  1311. Powerange.prototype.changeEvent = function (state) {
  1312. if (typeof Event === 'function' || !document.fireEvent) {
  1313. var event = document.createEvent('HTMLEvents');
  1314. event.initEvent('change', false, true);
  1315. this.element.dispatchEvent(event);
  1316. } else {
  1317. this.element.fireEvent('onchange');
  1318. }
  1319. };
  1320. /**
  1321. * Initialize main class.
  1322. *
  1323. * @api private
  1324. */
  1325. Powerange.prototype.init = function () {
  1326. this.hide();
  1327. this.append();
  1328. this.bindEvents();
  1329. this.extraClass(this.options.klass);
  1330. this.checkValues(this.options.start);
  1331. this.setRange(this.options.min, this.options.max);
  1332. this.disable();
  1333. };
  1334. });
  1335. require.register("powerange/lib/horizontal.js", function (exports, require, module) {
  1336. /**
  1337. * External dependencies.
  1338. *
  1339. */
  1340. var inherits = require('super'),
  1341. closest = require('closest-num'),
  1342. percentage = require('percentage-calc');
  1343. /**
  1344. * Require main class.
  1345. */
  1346. var Powerange = require('./main');
  1347. /**
  1348. * Expose `Horizontal`.
  1349. */
  1350. module.exports = Horizontal;
  1351. /**
  1352. * Create horizontal slider object.
  1353. *
  1354. * @api public
  1355. */
  1356. function Horizontal() {
  1357. Powerange.apply(this, arguments);
  1358. this.handle.style.width = this.options.handleDiameter + "px";
  1359. this.handle.style.height = this.options.handleDiameter + "px";
  1360. this.handle.style.top = - (this.options.handleDiameter)/2 + 2 + "px";
  1361. if (this.options.step) this.step($(this.slider).width(), $(this.handle).width());
  1362. this.setStart(this.options.start);
  1363. }
  1364. /**
  1365. * Inherit the main class.
  1366. */
  1367. inherits(Horizontal, Powerange);
  1368. /**
  1369. * Set horizontal slider position.
  1370. *
  1371. * @param {Number} start
  1372. * @api private
  1373. */
  1374. Horizontal.prototype.setStart = function (start) {
  1375. var begin = (start === null) ? this.options.min : start,
  1376. part = percentage.from(begin - this.options.min, this.options.max - this.options.min) || 0,
  1377. offset = percentage.of(part, $(this.slider).width() - $(this.handle).width()),
  1378. position = (this.options.step) ? closest.find(offset, this.steps) : offset;
  1379. this.setPosition(position);
  1380. this.setValue(this.handle.style.left, $(this.slider).width() - $(this.handle).width());
  1381. if (this.options.step) this.step($(this.slider).width(), $(this.handle).width());
  1382. };
  1383. /**
  1384. * Set horizontal slider current position.
  1385. *
  1386. * @param {Number} val
  1387. * @api private
  1388. */
  1389. Horizontal.prototype.setPosition = function (val) {
  1390. this.handle.style.left = val + 'px';
  1391. this.slider.querySelector('.range-quantity').style.width = val + 'px';
  1392. };
  1393. /**
  1394. * On slider mouse down.
  1395. *
  1396. * @param {Object} e
  1397. * @api private
  1398. */
  1399. Horizontal.prototype.onmousedown = function (e) {
  1400. if (e.touches) e = e.touches[0];
  1401. // snap to the touched position
  1402. if (e.target.className !== 'range-handle') {
  1403. if (!this.options.tap)
  1404. return;
  1405. var offset = 0;
  1406. var elm = this.handle;
  1407. while (elm !== null) {
  1408. offset += elm.offsetLeft;
  1409. elm = elm.offsetParent;
  1410. }
  1411. this.startX = offset - window.scrollX + this.handle.clientWidth / 2;
  1412. } else {
  1413. this.startX = e.clientX;
  1414. this.ht = $(this.handle).css("top");
  1415. this.handle.style.marginLeft = - (this.options.touchDiameter-this.options.handleDiameter)/4 + "px";
  1416. this.handle.style.width = this.options.touchDiameter + "px";
  1417. this.handle.style.height = this.options.touchDiameter + "px";
  1418. this.handle.style.top = parseInt(this.handle.style.top) - (this.options.touchDiameter-this.options.handleDiameter)/2 +'px';
  1419. }
  1420. this.handleOffsetX = this.handle.offsetLeft;
  1421. this.restrictHandleX = $(this.slider).width() - $(this.handle).width();
  1422. this.unselectable(this.slider, true);
  1423. this.onmousemove(e);
  1424. };
  1425. /**
  1426. * On slider mouse move.
  1427. *
  1428. * @param {Object} e
  1429. * @api private
  1430. */
  1431. Horizontal.prototype.onmousemove = function (e) {
  1432. if (e.target.className !== 'range-handle' && !this.options.tap)
  1433. return;
  1434. if (typeof e.preventDefault == 'function') {
  1435. e.preventDefault()
  1436. }
  1437. if (e.touches) e = e.touches[0];
  1438. var leftOffset = this.handleOffsetX + e.clientX - this.startX,
  1439. position = (this.steps) ? closest.find(leftOffset, this.steps) : leftOffset;
  1440. if (leftOffset <= 0) {
  1441. this.setPosition(0);
  1442. } else if (leftOffset >= this.restrictHandleX) {
  1443. this.setPosition(this.restrictHandleX);
  1444. } else {
  1445. this.setPosition(position);
  1446. }
  1447. this.setValue(this.handle.style.left, $(this.slider).width() - this.options.handleDiameter);
  1448. };
  1449. /**
  1450. * On mouse up.
  1451. *
  1452. * @param {Object} e
  1453. * @api private
  1454. */
  1455. Horizontal.prototype.onmouseup = function (e) {
  1456. this.unselectable(this.slider, false);
  1457. this.handle.style.marginLeft = "0px";
  1458. this.handle.style.width = this.options.handleDiameter + "px";
  1459. this.handle.style.height = this.options.handleDiameter + "px";
  1460. this.handle.style.top = this.ht;
  1461. this.setValue(this.handle.style.left, $(this.slider).width() - $(this.handle).width());
  1462. };
  1463. });
  1464. require.register("powerange/lib/vertical.js", function (exports, require, module) {
  1465. /**
  1466. * External dependencies.
  1467. *
  1468. */
  1469. var inherits = require('super'),
  1470. classes = require('classes'),
  1471. closest = require('closest-num'),
  1472. percentage = require('percentage-calc');
  1473. /**
  1474. * Require main class.
  1475. */
  1476. var Powerange = require('./main');
  1477. /**
  1478. * Expose `Vertical`.
  1479. */
  1480. module.exports = Vertical;
  1481. /**
  1482. * Create vertical slider object.
  1483. *
  1484. * @api public
  1485. */
  1486. function Vertical() {
  1487. Powerange.apply(this, arguments);
  1488. this.handle.style.width = this.options.handleDiameter + "px";
  1489. this.handle.style.height = this.options.handleDiameter + "px";
  1490. classes(this.slider).add('vertical');
  1491. if (this.options.step) this.step($(this.slider).height(), $(this.handle).height());
  1492. this.setStart(this.options.start);
  1493. }
  1494. /**
  1495. * Inherit the main class.
  1496. */
  1497. inherits(Vertical, Powerange);
  1498. /**
  1499. * Set vertical slider position.
  1500. *
  1501. * @param {Number} start
  1502. * @api private
  1503. */
  1504. Vertical.prototype.setStart = function (start) {
  1505. var begin = (start === null) ? this.options.min : start,
  1506. part = percentage.from(begin - this.options.min, this.options.max - this.options.min) || 0,
  1507. offset = percentage.of(part, $(this.slider).height() - $(this.handle).height()),
  1508. position = (this.options.step) ? closest.find(offset, this.steps) : offset;
  1509. this.setPosition(position);
  1510. this.setValue(this.handle.style.bottom, $(this.slider).height() - $(this.handle).height());
  1511. if (this.options.step) this.step($(this.slider).height(), $(this.handle).height());
  1512. };
  1513. /**
  1514. * Set vertical slider current position.
  1515. *
  1516. * @param {Number} val
  1517. * @api private
  1518. */
  1519. Vertical.prototype.setPosition = function (val) {
  1520. this.handle.style.bottom = val + 'px';
  1521. this.slider.querySelector('.range-quantity').style.height = val + 'px';
  1522. };
  1523. /**
  1524. * On mouse down.
  1525. *
  1526. * @param {Object} e
  1527. * @api private
  1528. */
  1529. Vertical.prototype.onmousedown = function (e) {
  1530. if (e.touches) e = e.touches[0];
  1531. // snap to the touched position
  1532. if (e.target.className !== 'range-handle') {
  1533. if (!this.options.tap)
  1534. return;
  1535. var offset = 0;
  1536. var elm = this.handle;
  1537. while (elm !== null) {
  1538. offset += elm.offsetTop;
  1539. elm = elm.offsetParent;
  1540. }
  1541. this.startY = offset - window.scrollY + this.handle.clientHeight / 2;
  1542. } else {
  1543. this.startY = e.clientY;
  1544. this.handle.style.marginLeft = - (this.options.touchDiameter-this.options.handleDiameter)/2 + "px";
  1545. this.handle.style.width = this.options.touchDiameter + "px";
  1546. this.handle.style.height = this.options.touchDiameter + "px";
  1547. }
  1548. this.handleOffsetY = $(this.slider).height() - $(this.handle).height() - this.handle.offsetTop;
  1549. this.restrictHandleY = $(this.slider).height() - $(this.handle).height();
  1550. this.unselectable(this.slider, true);
  1551. this.onmousemove(e);
  1552. };
  1553. /**
  1554. * On vertical slider mouse move.
  1555. *
  1556. * @param {Object} e
  1557. * @api private
  1558. */
  1559. Vertical.prototype.onmousemove = function (e) {
  1560. if (e.target.className !== 'range-handle' && !this.options.tap)
  1561. return;
  1562. if (typeof e.preventDefault == 'function') {
  1563. e.preventDefault()
  1564. }
  1565. if (e.touches) e = e.touches[0];
  1566. var bottomOffset = this.handleOffsetY + this.startY - e.clientY,
  1567. position = (this.steps) ? closest.find(bottomOffset, this.steps) : bottomOffset;
  1568. if (bottomOffset <= 0) {
  1569. this.setPosition(0);
  1570. } else if (bottomOffset >= this.restrictHandleY) {
  1571. this.setPosition(this.restrictHandleY);
  1572. } else {
  1573. this.setPosition(position);
  1574. }
  1575. this.setValue(this.handle.style.bottom, $(this.slider).height() - $(this.handle).height());
  1576. };
  1577. /**
  1578. * On mouse up.
  1579. *
  1580. * @param {Object} e
  1581. * @api private
  1582. */
  1583. Vertical.prototype.onmouseup = function (e) {
  1584. this.unselectable(this.slider, false);
  1585. this.handle.style.marginLeft = "0px";
  1586. this.handle.style.width = this.options.handleDiameter + "px";
  1587. this.handle.style.height = this.options.handleDiameter + "px";
  1588. //this.handle.style.top = this.ht;
  1589. this.setValue(this.handle.style.bottom, $(this.slider).height() - $(this.handle).height());
  1590. };
  1591. });
  1592. require.alias("component-events/index.js", "powerange/deps/events/index.js");
  1593. require.alias("component-events/index.js", "events/index.js");
  1594. require.alias("component-event/index.js", "component-events/deps/event/index.js");
  1595. require.alias("component-delegate/index.js", "component-events/deps/delegate/index.js");
  1596. require.alias("discore-closest/index.js", "component-delegate/deps/closest/index.js");
  1597. require.alias("discore-closest/index.js", "component-delegate/deps/closest/index.js");
  1598. require.alias("component-matches-selector/index.js", "discore-closest/deps/matches-selector/index.js");
  1599. require.alias("component-query/index.js", "component-matches-selector/deps/query/index.js");
  1600. require.alias("discore-closest/index.js", "discore-closest/index.js");
  1601. require.alias("component-event/index.js", "component-delegate/deps/event/index.js");
  1602. require.alias("component-classes/index.js", "powerange/deps/classes/index.js");
  1603. require.alias("component-classes/index.js", "classes/index.js");
  1604. require.alias("component-indexof/index.js", "component-classes/deps/indexof/index.js");
  1605. require.alias("ui-component-mouse/index.js", "powerange/deps/mouse/index.js");
  1606. require.alias("ui-component-mouse/index.js", "mouse/index.js");
  1607. require.alias("component-emitter/index.js", "ui-component-mouse/deps/emitter/index.js");
  1608. require.alias("component-event/index.js", "ui-component-mouse/deps/event/index.js");
  1609. require.alias("abpetkov-percentage-calc/percentage-calc.js", "powerange/deps/percentage-calc/percentage-calc.js");
  1610. require.alias("abpetkov-percentage-calc/percentage-calc.js", "powerange/deps/percentage-calc/index.js");
  1611. require.alias("abpetkov-percentage-calc/percentage-calc.js", "percentage-calc/index.js");
  1612. require.alias("abpetkov-percentage-calc/percentage-calc.js", "abpetkov-percentage-calc/index.js");
  1613. require.alias("abpetkov-closest-num/closest-num.js", "powerange/deps/closest-num/closest-num.js");
  1614. require.alias("abpetkov-closest-num/closest-num.js", "powerange/deps/closest-num/index.js");
  1615. require.alias("abpetkov-closest-num/closest-num.js", "closest-num/index.js");
  1616. require.alias("abpetkov-closest-num/closest-num.js", "abpetkov-closest-num/index.js");
  1617. require.alias("vesln-super/lib/super.js", "powerange/deps/super/lib/super.js");
  1618. require.alias("vesln-super/lib/super.js", "powerange/deps/super/index.js");
  1619. require.alias("vesln-super/lib/super.js", "super/index.js");
  1620. require.alias("vesln-super/lib/super.js", "vesln-super/index.js");
  1621. require.alias("powerange/lib/powerange.js", "powerange/index.js");
  1622. if (typeof exports == "object") {
  1623. module.exports = require("powerange");
  1624. } else if (typeof define == "function" && define.amd) {
  1625. define([], function () {
  1626. return require("powerange");
  1627. });
  1628. } else {
  1629. this["Powerange"] = require("powerange");
  1630. }
  1631. })();