1/** 2 * Modules in this bundle 3 * @license 4 * 5 * smartphoto: 6 * license: MIT (http://opensource.org/licenses/MIT) 7 * author: appleple 8 * homepage: http://developer.a-blogcms.jp 9 * version: 1.2.0 10 * 11 * a-template: 12 * license: MIT (http://opensource.org/licenses/MIT) 13 * author: steelydylan 14 * maintainers: appleple <[email protected]>, steelydylan <[email protected]> 15 * version: 0.4.4 16 * 17 * array.prototype.find: 18 * license: MIT (http://opensource.org/licenses/MIT) 19 * author: Paul Miller <http://paulmillr.com> 20 * maintainers: ljharb <[email protected]>, paulmillr <[email protected]> 21 * contributors: Duncan Hall <[email protected]> 22 * homepage: https://github.com/paulmillr/Array.prototype.find#readme 23 * version: 2.0.4 24 * 25 * custom-event-polyfill: 26 * license: MIT (http://opensource.org/licenses/MIT) 27 * maintainers: krambuhl <[email protected]> 28 * contributors: Frank Panetta, Mikhail Reenko <[email protected]>, Joscha Feth <[email protected]> 29 * homepage: https://github.com/krambuhl/custom-event-polyfill#readme 30 * version: 0.3.0 31 * 32 * define-properties: 33 * license: MIT (http://opensource.org/licenses/MIT) 34 * author: Jordan Harband 35 * maintainers: ljharb <[email protected]> 36 * homepage: https://github.com/ljharb/define-properties#readme 37 * version: 1.1.2 38 * 39 * es-abstract: 40 * license: MIT (http://opensource.org/licenses/MIT) 41 * author: Jordan Harband <[email protected]> 42 * maintainers: ljharb <[email protected]> 43 * contributors: Jordan Harband <[email protected]> 44 * homepage: https://github.com/ljharb/es-abstract#readme 45 * version: 1.10.0 46 * 47 * es-to-primitive: 48 * license: MIT (http://opensource.org/licenses/MIT) 49 * author: Jordan Harband 50 * maintainers: ljharb <[email protected]> 51 * homepage: https://github.com/ljharb/es-to-primitive#readme 52 * version: 1.1.1 53 * 54 * es6-promise-polyfill: 55 * license: MIT (http://opensource.org/licenses/MIT) 56 * author: Roman Dvornov <[email protected]> 57 * maintainers: lahmatiy <[email protected]> 58 * homepage: https://github.com/lahmatiy/es6-promise-polyfill#readme 59 * version: 1.2.0 60 * 61 * foreach: 62 * license: MIT (http://opensource.org/licenses/MIT) 63 * author: Manuel Stofer <[email protected]> 64 * maintainers: manuelstofer <[email protected]> 65 * contributors: Manuel Stofer, Jordan Harband 66 * homepage: https://github.com/manuelstofer/foreach 67 * version: 2.0.5 68 * 69 * function-bind: 70 * license: MIT (http://opensource.org/licenses/MIT) 71 * author: Raynos <[email protected]> 72 * maintainers: raynos <[email protected]>, ljharb <[email protected]> 73 * contributors: Raynos, Jordan Harband 74 * homepage: https://github.com/Raynos/function-bind 75 * version: 1.1.1 76 * 77 * has: 78 * licenses: MIT (http://opensource.org/licenses/MIT) 79 * author: Thiago de Arruda <[email protected]> 80 * maintainers: tarruda <[email protected]> 81 * homepage: https://github.com/tarruda/has 82 * version: 1.0.1 83 * 84 * is-callable: 85 * license: MIT (http://opensource.org/licenses/MIT) 86 * author: Jordan Harband <[email protected]> 87 * maintainers: ljharb <[email protected]> 88 * contributors: Jordan Harband <[email protected]> 89 * homepage: https://github.com/ljharb/is-callable#readme 90 * version: 1.1.3 91 * 92 * is-date-object: 93 * license: MIT (http://opensource.org/licenses/MIT) 94 * author: Jordan Harband 95 * maintainers: ljharb <[email protected]> 96 * homepage: https://github.com/ljharb/is-date-object#readme 97 * version: 1.0.1 98 * 99 * is-regex: 100 * license: MIT (http://opensource.org/licenses/MIT) 101 * author: Jordan Harband 102 * maintainers: ljharb <[email protected]> 103 * homepage: https://github.com/ljharb/is-regex 104 * version: 1.0.4 105 * 106 * is-symbol: 107 * license: MIT (http://opensource.org/licenses/MIT) 108 * author: Jordan Harband 109 * maintainers: ljharb <[email protected]> 110 * homepage: https://github.com/ljharb/is-symbol 111 * version: 1.0.1 112 * 113 * morphdom: 114 * license: MIT (http://opensource.org/licenses/MIT) 115 * author: Patrick Steele-Idem <[email protected]> 116 * maintainers: mlrawlings <[email protected]>, pnidem <[email protected]> 117 * homepage: https://github.com/patrick-steele-idem/morphdom#readme 118 * version: 2.3.3 119 * 120 * object-keys: 121 * license: MIT (http://opensource.org/licenses/MIT) 122 * author: Jordan Harband <[email protected]> 123 * maintainers: ljharb <[email protected]> 124 * contributors: Jordan Harband <[email protected]>, Raynos <[email protected]>, Nathan Rajlich <[email protected]>
124, Ivan Starkov <[email protected]>, Gary Katsevman <[email protected]> 125 * homepage: https://github.com/ljharb/object-keys#readme 126 * version: 1.0.11 127 * 128 * This header is generated by licensify (https://github.com/twada/licensify) 129 */ 130(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 131'use strict'; 132 133Object.defineProperty(exports, "__esModule", { 134 value: true 135}); 136 137var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 138 139var _util = require('./util'); 140 141function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } 142 143function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 144 145var morphdom = require('morphdom'); 146var find = require('array.prototype.find'); 147 148var eventType = 'input paste copy click change keydown keyup contextmenu mouseup mousedown mousemove touchstart touchend touchmove compositionstart compositionend focus'; 149var bindType = 'input change click'; 150var dataAction = eventType.replace(/([a-z]+)/g, '[data-action-$1],') + '[data-action]'; 151 152var aTemplate = function () { 153 function aTemplate(opt) { 154 var _this = this; 155 156 _classCallCheck(this, aTemplate); 157 158 this.atemplate = []; 159 if (opt) { 160 Object.keys(opt).forEach(function (key) { 161 _this[key] = opt[key]; 162 }); 163 } 164 if (!this.data) { 165 this.data = {}; 166 } 167 if (!this.templates) { 168 this.templates = []; 169 } 170 var templates = this.templates; 171 var length = templates.length; 172 for (var i = 0, n = length; i < n; i += 1) { 173 var template = this.templates[i]; 174 var html = (0, _util.selector)('#' + template).innerHTML; 175 this.atemplate.push({ id: template, html: html, binded: false }); 176 } 177 } 178 179 _createClass(aTemplate, [{ 180 key: 'addDataBind', 181 value: function addDataBind(ele) { 182 var _this2 = this; 183 184 (0, _util.on)(ele, '[data-bind]', bindType, function (e) { 185 var target = e.delegateTarget; 186 var data = target.getAttribute('data-bind'); 187 var attr = target.getAttribute('href'); 188 var value = target.value; 189 if (attr) { 190 value = value.replace('#', ''); 191 } 192 if (target.getAttribute('type') === 'checkbox') { 193 (function () { 194 var arr = []; 195 var items = document.querySelectorAll('[data-bind="' + data + '"]'); 196 [].forEach.call(items, function (item) { 197 if (item.checked) { 198 arr.push(item.value); 199 } 200 }); 201 })(); 202 } else if (target.getAttribute('type') !== 'radio') { 203 _this2.updateDataByString(data, value); 204 } 205 }); 206 } 207 }, { 208 key: 'addActionBind', 209 value: function addActionBind(ele) { 210 var _this3 = this; 211 212 (0, _util.on)(ele, dataAction, eventType, function (e) { 213 var target = e.delegateTarget; 214 var events = eventType.split(' '); 215 var action = 'action'; 216 events.forEach(function (event) { 217 if (target.getAttribute('data-action-' + event)) { 218 if (e.type === event) { 219 action += '-' + event; 220 } 221 } 222 }); 223 var string = target.getAttribute('data-' + action); 224 if (!string) { 225 return; 226 } 227 var method = string.replace(/\(.*?\);?/, ''); 228 var parameter = string.replace(/(.*?)\((.*?)\);?/, '$2'); 229 var pts = parameter.split(','); // å¼ãæ° 230 _this3.e = e; 231 if (_this3.method && _this3.method[method]) { 232 var _method; 233 234 (_method = _this3.method)[method].apply(_method, _toConsumableArray(pts)); 235 } else if (_this3[method]) { 236 _this3[method].apply(_this3, _toConsumableArray(pts)); 237 } 238 }); 239 } 240 }, { 241 key: 'addTemplate', 242 value: function addTemplate(id, html) { 243 this.atemplate.push({ id: id, html: html, binded: false }); 244 this.templates.push(id); 245 } 246 247 // loadHtml() { 248 // const templates = this.templates; 249 // const promises = [];
250 // templates.forEach((template) => { 251 // const d = new $.Deferred(); 252 // promises.push(d); 253 // const src = selector(`#${template}`).getAttribute('src'); 254 // $.ajax({ 255 // url: src, 256 // type: 'GET', 257 // dataType: 'text' 258 // }).success((data) => { 259 // selector(`#${template}`).innerHTML = data; 260 // d.resolve(); 261 // }); 262 // }); 263 // return $.when(...promises); 264 // } 265 266 }, { 267 key: 'getData', 268 value: function getData() { 269 return JSON.parse(JSON.stringify(this.data)); 270 } 271 }, { 272 key: 'saveData', 273 value: function saveData(key) { 274 var data = JSON.stringify(this.data); 275 localStorage.setItem(key, data); 276 } 277 }, { 278 key: 'setData', 279 value: function setData(opt) { 280 var _this4 = this; 281 282 Object.keys(opt).forEach(function (key) { 283 if (typeof opt[key] !== 'function') { 284 _this4.data[key] = opt[key]; 285 } 286 }); 287 } 288 }, { 289 key: 'loadData', 290 value: function loadData(key) { 291 var data = JSON.parse(localStorage.getItem(key)); 292 if (data) { 293 this.setData(data); 294 } 295 } 296 }, { 297 key: 'getRand', 298 value: function getRand(a, b) { 299 return ~~(Math.random() * (b - a + 1)) + a; 300 } 301 }, { 302 key: 'getRandText', 303 value: function getRandText(limit) { 304 var ret = ''; 305 var strings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 306 var length = strings.length; 307 for (var i = 0; i < limit; i += 1) { 308 ret += strings.charAt(Math.floor(this.getRand(0, length))); 309 } 310 return ret; 311 } 312 }, { 313 key: 'getDataFromObj', 314 value: function getDataFromObj(s, o) { 315 s = s.replace(/\[([\w\-\.ã-ãã¡-ã¶äº-ç]+)\]/g, '.$1'); // convert indexes to properties 316 s = s.replace(/^\./, ''); // strip leading dot 317 var a = s.split('.'); 318 while (a.length) { 319 var n = a.shift(); 320 if (n in o) { 321 o = o[n]; 322 } else { 323 return null; 324 } 325 } 326 return o; 327 } 328 }, { 329 key: 'getDataByString', 330 value: function getDataByString(s) { 331 var o = this.data; 332 return this.getDataFromObj(s, o); 333 } 334 }, { 335 key: 'updateDataByString', 336 value: function updateDataByString(path, newValue) { 337 var object = this.data; 338 var stack = path.split('.'); 339 while (stack.length > 1) { 340 object = object[stack.shift()]; 341 } 342 object[stack.shift()] = newValue; 343 } 344 }, { 345 key: 'removeDataByString', 346 value: function removeDataByString(path) { 347 var object = this.data; 348 var stack = path.split('.'); 349 while (stack.length > 1) { 350 object = object[stack.shift()]; 351 } 352 var shift = stack.shift(); 353 if (shift.match(/^\d+$/)) { 354 object.splice(Number(shift), 1); 355 } else { 356 delete object[shift]; 357 } 358 } 359 }, { 360 key: 'resolveBlock', 361 value: function resolveBlock(html, item, i) { 362 var that = this; 363 var touchs = html.match(/<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+):touch#([\w\-\.ã-ãã¡-ã¶äº-ç]+) -->/g); 364 var touchnots = html.match(/<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+):touchnot#([\w\-\.ã-ãã¡-ã¶äº-ç]+) -->/g); 365 var exists = html.match(/<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+):exist -->/g); 366 var empties = html.match(/<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+):empty -->/g); 367 /* ã¿ãããããã¯è§£æ±º*/ 368 if (touchs) { 369 for (var k = 0, n = touchs.length; k < n; k += 1) { 370 var start = touchs[k]; 371 start = start.replace(/([\w\-\.ã-ãã¡-ã¶äº-ç]+):touch#([\w\-\.ã-ãã¡-ã¶äº-ç]+)/, '($1):touch#($2)'); 372 var end = start.replace(/BEGIN/, 'END'); 373 var reg = new RegExp(start + '(([\\n\\r\\t]|.)*?)' + end, 'g'); 374 html = html.replace(reg, function (m, key2, val, next) { 375 var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); 376 if ('' + itemkey === val) { 377 return next; 378 } 379 return ''; 380 }); 381 } 382 } 383 /* ã¿ããããããããã¯è§£æ±º*/ 384 if (touchnots) { 385 for (var _k = 0, _n = touchnots.length; _k < _n; _k += 1) { 386 var _start = touchnots[_k]; 387 _start = _start.replace(/([\w\-\.ã-ãã¡-ã¶äº-ç]+):touchnot#([\w\-\.ã-ãã¡-ã¶äº-ç]+)/, '($1):touchnot#($2)'); 388 var _end = _start.replace(/BEGIN/, 'END'); 389 var _reg = new RegExp(_start + '(([\\n\\r\\t]|.)*?)' + _end, 'g'); 390 html = html.replace(_reg, function (m, key2, val, next) { 391 var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); 392 if ('' + itemkey !== val) { 393 return next; 394 } 395 return ''; 396 }); 397 } 398 } 399 /* existãããã¯ã解決*/ 400 if (exists) { 401 for (var _k2 = 0, _n2 = exists.length; _k2 < _n2; _k2 += 1) { 402 var _start2 = exists[_k2]; 403 _start2 = _start2.replace(/([\w\-\.ã-ãã¡-ã¶äº-ç]+):exist/, '($1):exist'); 404 var _end2 = _start2.replace(/BEGIN/, 'END'); 405 var _reg2 = new RegExp(_start2 + '(([\\n\\r\\t]|.)*?)' + _end2, 'g'); 406 html = html.replace(_reg2, function (m, key2, next) { 407 var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); 408 if (itemkey || itemkey === 0) { 409 return next; 410 } 411 return ''; 412 }); 413 } 414 } 415 /* emptyãããã¯ã解決*/ 416 if (empties) { 417 for (var _k3 = 0, _n3 = empties.length;
417 _k3 < _n3; _k3 += 1) { 418 var _start3 = empties[_k3]; 419 _start3 = _start3.replace(/([\w\-\.ã-ãã¡-ã¶äº-ç]+):empty/, '($1):empty'); 420 var _end3 = _start3.replace(/BEGIN/, 'END'); 421 var empty = new RegExp(_start3 + '(([\\n\\r\\t]|.)*?)' + _end3, 'g'); 422 html = html.replace(empty, function (m, key2, next) { 423 var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); 424 if (!itemkey && itemkey !== 0) { 425 return next; 426 } 427 return ''; 428 }); 429 } 430 } 431 /* 夿°è§£æ±º*/ 432 html = html.replace(/{([\w\-\.ã-ãã¡-ã¶äº-ç]+)}(\[([\w\-\.ã-ãã¡-ã¶äº-ç]+)\])*/g, function (n, key3, key4, converter) { 433 var data = void 0; 434 if ('' + key3 === 'i') { 435 data = i; 436 } else if (item[key3] || item[key3] === 0) { 437 if (typeof item[key3] === 'function') { 438 data = item[key3].apply(that); 439 } else { 440 data = item[key3]; 441 } 442 } else { 443 if (converter && that.convert && that.convert[converter]) { 444 return that.convert[converter].call(that, ''); 445 } 446 return ''; 447 } 448 if (converter && that.convert && that.convert[converter]) { 449 return that.convert[converter].call(that, data); 450 } 451 return data; 452 }); 453 return html; 454 } 455 /* 絶対ãã¹å½¢å¼ã®å¤æ°ã解決*/ 456 457 }, { 458 key: 'resolveAbsBlock', 459 value: function resolveAbsBlock(html) { 460 var that = this; 461 html = html.replace(/{(.*?)}/g, function (n, key3) { 462 var data = that.getDataByString(key3); 463 if (typeof data !== 'undefined') { 464 if (typeof data === 'function') { 465 return data.apply(that); 466 } 467 return data; 468 } 469 return n; 470 }); 471 return html; 472 } 473 }, { 474 key: 'resolveInclude', 475 value: function resolveInclude(html) { 476 var include = /<!-- #include id="(.*?)" -->/g; 477 html = html.replace(include, function (m, key) { 478 return (0, _util.selector)('#' + key).innerHTML; 479 }); 480 return html; 481 } 482 }, { 483 key: 'resolveWith', 484 value: function resolveWith(html) { 485 var width = /<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+):with -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ã-ãã¡-ã¶äº-ç]+):with -->/g; 486 html = html.replace(width, function (m, key) { 487 m = m.replace(/data\-bind=['"](.*?)['"]/g, 'data-bind=\'' + key + '.$1\''); 488 return m; 489 }); 490 return html; 491 } 492 }, { 493 key: 'resolveLoop', 494 value: function resolveLoop(html) { 495 var loop = /<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ã-ãã¡-ã¶äº-ç]+?):loop -->/g; 496 var that = this; 497 /* ã«ã¼ãæè§£æ±º*/ 498 html = html.replace(loop, function (m, key, val) { 499 var keyItem = that.getDataByString(key); 500 var keys = []; 501 if (typeof keyItem === 'function') { 502 keys = keyItem.apply(that); 503 } else { 504 keys = keyItem; 505 } 506 var ret = ''; 507 if (keys instanceof Array) { 508 for (var i = 0, n = keys.length; i < n; i += 1) { 509 ret += that.resolveBlock(val, keys[i], i); 510 } 511 } 512 /* ã¨ã¹ã±ã¼ãåé¤*/ 513 ret = ret.replace(/\\([^\\])/g, '$1'); 514 return ret; 515 }); 516 return html; 517 } 518 }, { 519 key: 'removeData', 520 value: function removeData(arr) { 521 var data = this.data; 522 Object.keys(data).forEach(function (i) { 523 for (var t = 0, n = arr.length; t < n; t += 1) { 524 if (i === arr[t]) { 525 delete data[i]; 526 } 527 } 528 }); 529 return this; 530 } 531 }, { 532 key: 'hasLoop', 533 value: function hasLoop(txt) { 534 var loop = /<!-- BEGIN ([\w\-\.ã-ãã¡-ã¶äº-ç]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ã-ãã¡-ã¶äº-ç]+?):loop -->/g; 535 if (txt.match(loop)) { 536 return true; 537 } 538 return false; 539 } 540 }, { 541 key: 'getHtml', 542 value: function getHtml(query, row) { 543 var template = find(this.atemplate, function (item) { 544 return item.id === query; 545 }); 546 var html = ''; 547 if (template && template.html) { 548 html = template.html; 549 } 550 if (row) { 551 html = query; 552 } 553 if (!html) { 554 return ''; 555 } 556 var data = this.data; 557 /* ã¤ã³ã¯ã«ã¼ã解決*/ 558 html = this.resolveInclude(html); 559 /* with解決*/ 560 html = this.resolveWith(html); 561 /* ã«ã¼ã解決*/ 562 while (this.hasLoop(html)) { 563 html = this.resolveLoop(html); 564 } 565 /* 夿°è§£æ±º*/ 566 html = this.resolveBlock(html, data); 567 /* ã¨ã¹ã±ã¼ãåé¤*/ 568 html = html.replace(/\\([^\\])/g, '$1'); 569 /* 絶対ãã¹ã§æå®ããã夿°ã解決*/ 570 html = this.resolveAbsBlock(html); 571 /* 空è¡åé¤*/ 572 return html.replace(/^([\t ])*\n/gm, ''); 573 } 574 }, { 575 key: 'update',
576 value: function update() { 577 var _this5 = this; 578 579 var renderWay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'html'; 580 var part = arguments[1]; 581 582 var templates = this.templates; 583 if (this.beforeUpdated) { 584 this.beforeUpdated(); 585 } 586 587 var _loop = function _loop(i, n) { 588 var tem = templates[i]; 589 var query = '#' + tem; 590 var html = _this5.getHtml(tem); 591 var target = (0, _util.selector)('[data-id=\'' + tem + '\']'); 592 if (!target) { 593 (0, _util.selector)(query).insertAdjacentHTML('afterend', '<div data-id="' + tem + '"></div>'); 594 if (renderWay === 'text') { 595 (0, _util.selector)('[data-id=\'' + tem + '\']').innerText = html; 596 } else { 597 (0, _util.selector)('[data-id=\'' + tem + '\']').innerHTML = html; 598 } 599 } else if (renderWay === 'text') { 600 target.innerText = html; 601 } else if (part) { 602 var parser = new DOMParser(); 603 var doc = parser.parseFromString(html, 'text/html'); 604 var partHtml = doc.querySelector(part).outerHTML; 605 morphdom(target.querySelector(part), partHtml); 606 } else { 607 morphdom(target, '<div data-id=\'' + tem + '\'>' + html + '</div>'); 608 } 609 var template = find(_this5.atemplate, function (item) { 610 return item.id === tem; 611 }); 612 if (!template.binded) { 613 template.binded = true; 614 _this5.addDataBind((0, _util.selector)('[data-id=\'' + tem + '\']')); 615 _this5.addActionBind((0, _util.selector)('[data-id=\'' + tem + '\']')); 616 } 617 }; 618 619 for (var i = 0, n = templates.length; i < n; i += 1) { 620 _loop(i, n); 621 } 622 this.updateBindingData(part); 623 if (this.onUpdated) { 624 this.onUpdated(part); 625 } 626 return this; 627 } 628 }, { 629 key: 'updateBindingData', 630 value: function updateBindingData(part) { 631 var _this6 = this; 632 633 var templates = this.templates; 634 for (var i = 0, n = templates.length; i < n; i += 1) { 635 var temp = templates[i]; 636 var _template = (0, _util.selector)('[data-id=\'' + temp + '\']'); 637 if (part) { 638 _template = _template.querySelector(part); 639 } 640 var binds = _template.querySelectorAll('[data-bind]'); 641 [].forEach.call(binds, function (item) { 642 var data = _this6.getDataByString(item.getAttribute('data-bind')); 643 if (item.getAttribute('type') === 'checkbox' || item.getAttribute('type') === 'radio') { 644 if (data === item.value) { 645 item.checked = true; 646 } 647 } else { 648 // if(item !== document.activeElement) { 649 item.value = data; 650 // } 651 } 652 }); 653 } 654 return this; 655 } 656 }, { 657 key: 'applyMethod', 658 value: function applyMethod(method) { 659 var _method2; 660 661 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 662 args[_key - 1] = arguments[_key]; 663 } 664 665 return (_method2 = this.method)[method].apply(_method2, args); 666 } 667 }, { 668 key: 'getComputedProp', 669 value: function getComputedProp(prop) { 670 return this.data[prop].apply(this); 671 } 672 }, { 673 key: 'remove', 674 value: function remove(path) { 675 var object = this.data; 676 var stack = path.split('.'); 677 while (stack.length > 1) { 678 object = object[stack.shift()]; 679 } 680 var shift = stack.shift(); 681 if (shift.match(/^\d+$/)) { 682 object.splice(Number(shift), 1); 683 } else { 684 delete object[shift]; 685 } 686 return this; 687 } 688 }]); 689 690 return aTemplate; 691}(); 692 693exports.default = aTemplate; 694module.exports = exports['default']; 695},{"./util":2,"array.prototype.find":4,"morphdom":30}],2:[function(require,module,exports){ 696'use strict'; 697 698Object.defineProperty(exports, "__esModule", { 699 value: true 700}); 701var matches = exports.matches = function matches(element, query) { 702 var matches = (element.document || element.ownerDocument).querySelectorAll(query); 703 var i = matches.length; 704 while (--i >= 0 && matches.item(i) !== element) {} 705 return i > -1; 706}; 707 708var selector = exports.selector = function selector(_selector) { 709 return document.querySelector(_selector); 710}; 711
712var findAncestor = exports.findAncestor = function findAncestor(element, selector) { 713 if (typeof element.closest === 'function') { 714 return element.closest(selector) || null; 715 } 716 while (element && element !== document) { 717 if (matches(element, selector)) { 718 return element; 719 } 720 element = element.parentElement; 721 } 722 return null; 723}; 724 725var on = exports.on = function on(element, query, eventNames, fn) { 726 var events = eventNames.split(' '); 727 events.forEach(function (event) { 728 element.addEventListener(event, function (e) { 729 var target = e.target; 730 var delegateTarget = findAncestor(e.target, query); 731 if (delegateTarget) { 732 e.delegateTarget = delegateTarget; 733 fn(e); 734 } 735 }); 736 }); 737}; 738},{}],3:[function(require,module,exports){ 739'use strict'; 740 741var ES = require('es-abstract/es6'); 742 743module.exports = function find(predicate) { 744 var list = ES.ToObject(this); 745 var length = ES.ToInteger(ES.ToLength(list.length)); 746 if (!ES.IsCallable(predicate)) { 747 throw new TypeError('Array#find: predicate must be a function'); 748 } 749 if (length === 0) { 750 return undefined; 751 } 752 var thisArg = arguments[1]; 753 for (var i = 0, value; i < length; i++) { 754 value = list[i]; 755 if (ES.Call(predicate, thisArg, [value, i, list])) { 756 return value; 757 } 758 } 759 return undefined; 760}; 761 762},{"es-abstract/es6":11}],4:[function(require,module,exports){ 763'use strict'; 764 765var define = require('define-properties'); 766var ES = require('es-abstract/es6'); 767 768var implementation = require('./implementation'); 769var getPolyfill = require('./polyfill'); 770var shim = require('./shim'); 771 772var slice = Array.prototype.slice; 773 774var polyfill = getPolyfill(); 775 776var boundFindShim = function find(array, predicate) { // eslint-disable-line no-unused-vars 777 ES.RequireObjectCoercible(array); 778 var args = slice.call(arguments, 1); 779 return polyfill.apply(array, args); 780}; 781 782define(boundFindShim, { 783 getPolyfill: getPolyfill, 784 implementation: implementation, 785 shim: shim 786}); 787 788module.exports = boundFindShim; 789 790},{"./implementation":3,"./polyfill":5,"./shim":6,"define-properties":8,"es-abstract/es6":11}],5:[function(require,module,exports){ 791'use strict'; 792 793module.exports = function getPolyfill() { 794 // Detect if an implementation exists 795 // Detect early implementations which skipped holes in sparse arrays 796 // eslint-disable-next-line no-sparse-arrays 797 var implemented = Array.prototype.find && [, 1].find(function () { 798 return true; 799 }) !== 1; 800 801 // eslint-disable-next-line global-require 802 return implemented ? Array.prototype.find : require('./implementation'); 803}; 804 805},{"./implementation":3}],6:[function(require,module,exports){ 806'use strict'; 807 808var define = require('define-properties'); 809var getPolyfill = require('./polyfill'); 810 811module.exports = function shimArrayPrototypeFind() { 812 var polyfill = getPolyfill(); 813 814 define(Array.prototype, { find: polyfill }, { 815 find: function () { 816 return Array.prototype.find !== polyfill; 817 } 818 }); 819 820 return polyfill; 821}; 822 823},{"./polyfill":5,"define-properties":8}],7:[function(require,module,exports){ 824// Polyfill for creating CustomEvents on IE9/10/11 825 826// code pulled from: 827// https://github.com/d4tocchini/customevent-polyfill 828// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill 829 830try { 831 var ce = new window.CustomEvent('test'); 832 ce.preventDefault(); 833 if (ce.defaultPrevented !== true) { 834 // IE has problems with .preventDefault() on custom events 835 // http://stackoverflow.com/questions/23349191 836 throw new Error('Could not prevent default'); 837 } 838} catch(e) { 839 var CustomEvent = function(event, params) { 840 var evt, origPrevent; 841 params = params || { 842 bubbles: false, 843 cancelable: false, 844 detail: undefined 845 }; 846 847 evt = document.createEvent("CustomEvent"); 848 evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); 849 origPrevent = evt.preventDefault; 850 evt.preventDefault = function () { 851 origPrevent.call(this); 852 try { 853 Object.defineProperty(this, 'defaultPrevented', { 854 get: function () { 855 return true; 856 } 857 }); 858 } catch(e) { 859 this.defaultPrevented = true; 860 } 861 }; 862 return evt; 863 }; 864 865 CustomEvent.prototype = window.Event.prototype; 866 window.CustomEvent = CustomEvent; // expose definition to window 867} 868 869},{}],8:[function(require,module,exports){ 870'use strict'; 871 872var keys = require('object-keys'); 873var foreach = require('foreach'); 874var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol'; 875 876var toStr = Object.prototype.toString; 877 878var isFunction = function (fn) { 879 return typeof fn === 'function' && toStr.call(fn) === '[object Function]'; 880}; 881 882var arePropertyDescriptorsSupported = function () { 883 var obj = {}; 884 try { 885 Object.defineProperty(obj, 'x', { enumerable: false, value: obj }); 886 /* eslint-disable no-unused-vars, no-restricted-syntax */ 887 for (var _ in obj) { return false; } 888 /* eslint-enable no-unused-vars, no-restricted-syntax */ 889 return obj.x === obj; 890 } catch (e) { /* this is IE 8. */ 891 return false;
892 } 893}; 894var supportsDescriptors = Object.defineProperty && arePropertyDescriptorsSupported(); 895 896var defineProperty = function (object, name, value, predicate) { 897 if (name in object && (!isFunction(predicate) || !predicate())) { 898 return; 899 } 900 if (supportsDescriptors) { 901 Object.defineProperty(object, name, { 902 configurable: true, 903 enumerable: false, 904 value: value, 905 writable: true 906 }); 907 } else { 908 object[name] = value; 909 } 910}; 911 912var defineProperties = function (object, map) { 913 var predicates = arguments.length > 2 ? arguments[2] : {}; 914 var props = keys(map); 915 if (hasSymbols) { 916 props = props.concat(Object.getOwnPropertySymbols(map)); 917 } 918 foreach(props, function (name) { 919 defineProperty(object, name, map[name], predicates[name]); 920 }); 921}; 922 923defineProperties.supportsDescriptors = !!supportsDescriptors; 924 925module.exports = defineProperties; 926 927},{"foreach":22,"object-keys":31}],9:[function(require,module,exports){ 928'use strict'; 929 930var has = require('has'); 931var toPrimitive = require('es-to-primitive/es6'); 932 933var toStr = Object.prototype.toString; 934var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'; 935 936var $isNaN = require('./helpers/isNaN'); 937var $isFinite = require('./helpers/isFinite'); 938var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; 939 940var assign = require('./helpers/assign'); 941var sign = require('./helpers/sign'); 942var mod = require('./helpers/mod'); 943var isPrimitive = require('./helpers/isPrimitive'); 944var parseInteger = parseInt; 945var bind = require('function-bind'); 946var arraySlice = bind.call(Function.call, Array.prototype.slice); 947var strSlice = bind.call(Function.call, String.prototype.slice); 948var isBinary = bind.call(Function.call, RegExp.prototype.test, /^0b[01]+$/i); 949var isOctal = bind.call(Function.call, RegExp.prototype.test, /^0o[0-7]+$/i); 950var regexExec = bind.call(Function.call, RegExp.prototype.exec); 951var nonWS = ['\u0085', '\u200b', '\ufffe'].join(''); 952var nonWSregex = new RegExp('[' + nonWS + ']', 'g'); 953var hasNonWS = bind.call(Function.call, RegExp.prototype.test, nonWSregex); 954var invalidHexLiteral = /^[-+]0x[0-9a-f]+$/i; 955var isInvalidHexLiteral = bind.call(Function.call, RegExp.prototype.test, invalidHexLiteral); 956 957// whitespace from: http://es5.github.io/#x15.5.4.20 958// implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324 959var ws = [ 960 '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003', 961 '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028', 962 '\u2029\uFEFF' 963].join(''); 964var trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g'); 965var replace = bind.call(Function.call, String.prototype.replace); 966var trim = function (value) { 967 return replace(value, trimRegex, ''); 968}; 969 970var ES5 = require('./es5'); 971 972var hasRegExpMatcher = require('is-regex'); 973 974// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-abstract-operations 975var ES6 = assign(assign({}, ES5), { 976 977 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args 978 Call: function Call(F, V) { 979 var args = arguments.length > 2 ? arguments[2] : []; 980 if (!this.IsCallable(F)) { 981 throw new TypeError(F + ' is not a function'); 982 } 983 return F.apply(V, args); 984 }, 985 986 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toprimitive 987 ToPrimitive: toPrimitive, 988 989 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean 990 // ToBoolean: ES5.ToBoolean, 991 992 // http://www.ecma-international.org/ecma-262/6.0/#sec-tonumber 993 ToNumber: function ToNumber(argument) { 994 var value = isPrimitive(argument) ? argument : toPrimitive(argument, Number); 995 if (typeof value === 'symbol') { 996 throw new TypeError('Cannot convert a Symbol value to a number'); 997 } 998 if (typeof value === 'string') { 999 if (isBinary(value)) { 1000 return this.ToNumber(parseInteger(strSlice(value, 2), 2)); 1001 } else if (isOctal(value)) { 1002 return this.ToNumber(parseInteger(strSlice(value, 2), 8)); 1003 } else if (hasNonWS(value) || isInvalidHexLiteral(value)) { 1004 return NaN; 1005 } else { 1006 var trimmed = trim(value); 1007 if (trimmed !== value) { 1008 return this.ToNumber(trimmed); 1009 } 1010 } 1011 } 1012 return Number(value); 1013 }, 1014 1015 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tointeger 1016 // ToInteger: ES5.ToNumber, 1017 1018 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint32
1019 // ToInt32: ES5.ToInt32, 1020 1021 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint32 1022 // ToUint32: ES5.ToUint32, 1023 1024 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint16 1025 ToInt16: function ToInt16(argument) { 1026 var int16bit = this.ToUint16(argument); 1027 return int16bit >= 0x8000 ? int16bit - 0x10000 : int16bit; 1028 }, 1029 1030 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint16 1031 // ToUint16: ES5.ToUint16, 1032 1033 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint8 1034 ToInt8: function ToInt8(argument) { 1035 var int8bit = this.ToUint8(argument); 1036 return int8bit >= 0x80 ? int8bit - 0x100 : int8bit; 1037 }, 1038 1039 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8 1040 ToUint8: function ToUint8(argument) { 1041 var number = this.ToNumber(argument); 1042 if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; } 1043 var posInt = sign(number) * Math.floor(Math.abs(number)); 1044 return mod(posInt, 0x100); 1045 }, 1046 1047 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8clamp 1048 ToUint8Clamp: function ToUint8Clamp(argument) { 1049 var number = this.ToNumber(argument); 1050 if ($isNaN(number) || number <= 0) { return 0; } 1051 if (number >= 0xFF) { return 0xFF; } 1052 var f = Math.floor(argument); 1053 if (f + 0.5 < number) { return f + 1; } 1054 if (number < f + 0.5) { return f; } 1055 if (f % 2 !== 0) { return f + 1; } 1056 return f; 1057 }, 1058 1059 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tostring 1060 ToString: function ToString(argument) { 1061 if (typeof argument === 'symbol') { 1062 throw new TypeError('Cannot convert a Symbol value to a string'); 1063 } 1064 return String(argument); 1065 }, 1066 1067 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toobject 1068 ToObject: function ToObject(value) { 1069 this.RequireObjectCoercible(value); 1070 return Object(value); 1071 }, 1072 1073 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-topropertykey 1074 ToPropertyKey: function ToPropertyKey(argument) { 1075 var key = this.ToPrimitive(argument, String); 1076 return typeof key === 'symbol' ? key : this.ToString(key); 1077 }, 1078 1079 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength 1080 ToLength: function ToLength(argument) { 1081 var len = this.ToInteger(argument); 1082 if (len <= 0) { return 0; } // includes converting -0 to +0 1083 if (len > MAX_SAFE_INTEGER) { return MAX_SAFE_INTEGER; } 1084 return len; 1085 }, 1086 1087 // http://www.ecma-international.org/ecma-262/6.0/#sec-canonicalnumericindexstring 1088 CanonicalNumericIndexString: function CanonicalNumericIndexString(argument) { 1089 if (toStr.call(argument) !== '[object String]') { 1090 throw new TypeError('must be a string'); 1091 } 1092 if (argument === '-0') { return -0; } 1093 var n = this.ToNumber(argument); 1094 if (this.SameValue(this.ToString(n), argument)) { return n; } 1095 return void 0; 1096 }, 1097 1098 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-requireobjectcoercible 1099 RequireObjectCoercible: ES5.CheckObjectCoercible, 1100 1101 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isarray 1102 IsArray: Array.isArray || function IsArray(argument) { 1103 return toStr.call(argument) === '[object Array]'; 1104 }, 1105 1106 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-iscallable 1107 // IsCallable: ES5.IsCallable, 1108 1109 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isconstructor 1110 IsConstructor: function IsConstructor(argument) { 1111 return typeof argument === 'function' && !!argument.prototype; // unfortunately there's no way to truly check this without try/catch `new argument` 1112 }, 1113 1114 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isextensible-o 1115 IsExtensible: function IsExtensible(obj) { 1116 if (!Object.preventExtensions) { return true; } 1117 if (isPrimitive(obj)) { 1118 return false; 1119 } 1120 return Object.isExtensible(obj); 1121 }, 1122 1123 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isinteger 1124 IsInteger: function IsInteger(argument) { 1125 if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) { 1126 return false; 1127 } 1128 var abs = Math.abs(argument); 1129 return Math.floor(abs) === abs; 1130 }, 1131 1132 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ispropertykey 1133 IsPropertyKey: function IsPropertyKey(argument) { 1134 return typeof argument === 'string' || typeof argument === 'symbol'; 1135 }, 1136 1137 // http://www.ecma-international.org/ecma-262/6.0/#sec-isregexp 1138 IsRegExp: function IsRegExp(argument) { 1139 if (!argument || typeof argument !== 'object') { 1140 return false;
1141 } 1142 if (hasSymbols) { 1143 var isRegExp = argument[Symbol.match]; 1144 if (typeof isRegExp !== 'undefined') { 1145 return ES5.ToBoolean(isRegExp); 1146 } 1147 } 1148 return hasRegExpMatcher(argument); 1149 }, 1150 1151 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevalue 1152 // SameValue: ES5.SameValue, 1153 1154 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero 1155 SameValueZero: function SameValueZero(x, y) { 1156 return (x === y) || ($isNaN(x) && $isNaN(y)); 1157 }, 1158 1159 /** 1160 * 7.3.2 GetV (V, P) 1161 * 1. Assert: IsPropertyKey(P) is true. 1162 * 2. Let O be ToObject(V). 1163 * 3. ReturnIfAbrupt(O). 1164 * 4. Return O.[[Get]](P, V). 1165 */ 1166 GetV: function GetV(V, P) { 1167 // 7.3.2.1 1168 if (!this.IsPropertyKey(P)) { 1169 throw new TypeError('Assertion failed: IsPropertyKey(P) is not true'); 1170 } 1171 1172 // 7.3.2.2-3 1173 var O = this.ToObject(V); 1174 1175 // 7.3.2.4 1176 return O[P]; 1177 }, 1178 1179 /** 1180 * 7.3.9 - http://www.ecma-international.org/ecma-262/6.0/#sec-getmethod 1181 * 1. Assert: IsPropertyKey(P) is true. 1182 * 2. Let func be GetV(O, P). 1183 * 3. ReturnIfAbrupt(func). 1184 * 4. If func is either undefined or null, return undefined. 1185 * 5. If IsCallable(func) is false, throw a TypeError exception. 1186 * 6. Return func. 1187 */ 1188 GetMethod: function GetMethod(O, P) { 1189 // 7.3.9.1 1190 if (!this.IsPropertyKey(P)) { 1191 throw new TypeError('Assertion failed: IsPropertyKey(P) is not true'); 1192 } 1193 1194 // 7.3.9.2 1195 var func = this.GetV(O, P); 1196 1197 // 7.3.9.4 1198 if (func == null) { 1199 return void 0; 1200 } 1201 1202 // 7.3.9.5 1203 if (!this.IsCallable(func)) { 1204 throw new TypeError(P + 'is not a function'); 1205 } 1206 1207 // 7.3.9.6 1208 return func; 1209 }, 1210 1211 /** 1212 * 7.3.1 Get (O, P) - http://www.ecma-international.org/ecma-262/6.0/#sec-get-o-p 1213 * 1. Assert: Type(O) is Object. 1214 * 2. Assert: IsPropertyKey(P) is true. 1215 * 3. Return O.[[Get]](P, O). 1216 */ 1217 Get: function Get(O, P) { 1218 // 7.3.1.1 1219 if (this.Type(O) !== 'Object') { 1220 throw new TypeError('Assertion failed: Type(O) is not Object'); 1221 } 1222 // 7.3.1.2 1223 if (!this.IsPropertyKey(P)) { 1224 throw new TypeError('Assertion failed: IsPropertyKey(P) is not true'); 1225 } 1226 // 7.3.1.3 1227 return O[P]; 1228 }, 1229 1230 Type: function Type(x) { 1231 if (typeof x === 'symbol') { 1232 return 'Symbol'; 1233 } 1234 return ES5.Type(x); 1235 }, 1236 1237 // http://www.ecma-international.org/ecma-262/6.0/#sec-speciesconstructor 1238 SpeciesConstructor: function SpeciesConstructor(O, defaultConstructor) { 1239 if (this.Type(O) !== 'Object') { 1240 throw new TypeError('Assertion failed: Type(O) is not Object'); 1241 } 1242 var C = O.constructor; 1243 if (typeof C === 'undefined') { 1244 return defaultConstructor; 1245 } 1246 if (this.Type(C) !== 'Object') { 1247 throw new TypeError('O.constructor is not an Object'); 1248 } 1249 var S = hasSymbols && Symbol.species ? C[Symbol.species] : void 0; 1250 if (S == null) { 1251 return defaultConstructor; 1252 } 1253 if (this.IsConstructor(S)) { 1254 return S; 1255 } 1256 throw new TypeError('no constructor found'); 1257 }, 1258 1259 // http://ecma-international.org/ecma-262/6.0/#sec-completepropertydescriptor 1260 CompletePropertyDescriptor: function CompletePropertyDescriptor(Desc) { 1261 if (!this.IsPropertyDescriptor(Desc)) { 1262 throw new TypeError('Desc must be a Property Descriptor'); 1263 } 1264 1265 if (this.IsGenericDescriptor(Desc) || this.IsDataDescriptor(Desc)) { 1266 if (!has(Desc, '[[Value]]')) { 1267 Desc['[[Value]]'] = void 0; 1268 } 1269 if (!has(Desc, '[[Writable]]')) { 1270 Desc['[[Writable]]'] = false; 1271 } 1272 } else { 1273 if (!has(Desc, '[[Get]]')) { 1274 Desc['[[Get]]'] = void 0; 1275 } 1276 if (!has(Desc, '[[Set]]')) { 1277 Desc['[[Set]]'] = void 0; 1278 } 1279 } 1280 if (!has(Desc, '[[Enumerable]]')) { 1281 Desc['[[Enumerable]]'] = false; 1282 } 1283 if (!has(Desc, '[[Configurable]]')) { 1284 Desc['[[Configurable]]'] = false; 1285 } 1286 return Desc; 1287 }, 1288 1289 // http://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw 1290 Set: function Set(O, P, V, Throw) { 1291 if (this.Type(O) !== 'Object') { 1292 throw new TypeError('O must be an Object'); 1293 } 1294 if (!this.IsPropertyKey(P)) { 1295 throw new TypeError('P must be a Property Key'); 1296 } 1297 if (this.Type(Throw) !== 'Boolean') { 1298 throw new TypeError('Throw must be a Boolean'); 1299 } 1300 if (Throw) { 1301 O[P] = V; 1302 return true; 1303 } else { 1304 try { 1305 O[P] = V; 1306 } catch (e) { 1307 return false;
1308 } 1309 } 1310 }, 1311 1312 // http://ecma-international.org/ecma-262/6.0/#sec-hasownproperty 1313 HasOwnProperty: function HasOwnProperty(O, P) { 1314 if (this.Type(O) !== 'Object') { 1315 throw new TypeError('O must be an Object'); 1316 } 1317 if (!this.IsPropertyKey(P)) { 1318 throw new TypeError('P must be a Property Key'); 1319 } 1320 return has(O, P); 1321 }, 1322 1323 // http://ecma-international.org/ecma-262/6.0/#sec-hasproperty 1324 HasProperty: function HasProperty(O, P) { 1325 if (this.Type(O) !== 'Object') { 1326 throw new TypeError('O must be an Object'); 1327 } 1328 if (!this.IsPropertyKey(P)) { 1329 throw new TypeError('P must be a Property Key'); 1330 } 1331 return P in O; 1332 }, 1333 1334 // http://ecma-international.org/ecma-262/6.0/#sec-isconcatspreadable 1335 IsConcatSpreadable: function IsConcatSpreadable(O) { 1336 if (this.Type(O) !== 'Object') { 1337 return false; 1338 } 1339 if (hasSymbols && typeof Symbol.isConcatSpreadable === 'symbol') { 1340 var spreadable = this.Get(O, Symbol.isConcatSpreadable); 1341 if (typeof spreadable !== 'undefined') { 1342 return this.ToBoolean(spreadable); 1343 } 1344 } 1345 return this.IsArray(O); 1346 }, 1347 1348 // http://ecma-international.org/ecma-262/6.0/#sec-invoke 1349 Invoke: function Invoke(O, P) { 1350 if (!this.IsPropertyKey(P)) { 1351 throw new TypeError('P must be a Property Key'); 1352 } 1353 var argumentsList = arraySlice(arguments, 2); 1354 var func = this.GetV(O, P); 1355 return this.Call(func, O, argumentsList); 1356 }, 1357 1358 // http://ecma-international.org/ecma-262/6.0/#sec-createiterresultobject 1359 CreateIterResultObject: function CreateIterResultObject(value, done) { 1360 if (this.Type(done) !== 'Boolean') { 1361 throw new TypeError('Assertion failed: Type(done) is not Boolean'); 1362 } 1363 return { 1364 value: value, 1365 done: done 1366 }; 1367 }, 1368 1369 // http://ecma-international.org/ecma-262/6.0/#sec-regexpexec 1370 RegExpExec: function RegExpExec(R, S) { 1371 if (this.Type(R) !== 'Object') { 1372 throw new TypeError('R must be an Object'); 1373 } 1374 if (this.Type(S) !== 'String') { 1375 throw new TypeError('S must be a String'); 1376 } 1377 var exec = this.Get(R, 'exec'); 1378 if (this.IsCallable(exec)) { 1379 var result = this.Call(exec, R, [S]); 1380 if (result === null || this.Type(result) === 'Object') { 1381 return result; 1382 } 1383 throw new TypeError('"exec" method must return `null` or an Object'); 1384 } 1385 return regexExec(R, S); 1386 }, 1387 1388 // http://ecma-international.org/ecma-262/6.0/#sec-arrayspeciescreate 1389 ArraySpeciesCreate: function ArraySpeciesCreate(originalArray, length) { 1390 if (!this.IsInteger(length) || length < 0) { 1391 throw new TypeError('Assertion failed: length must be an integer >= 0'); 1392 } 1393 var len = length === 0 ? 0 : length; 1394 var C; 1395 var isArray = this.IsArray(originalArray); 1396 if (isArray) { 1397 C = this.Get(originalArray, 'constructor');
1398 // TODO: figure out how to make a cross-realm normal Array, a same-realm Array 1399 // if (this.IsConstructor(C)) { 1400 // if C is another realm's Array, C = undefined 1401 // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ? 1402 // } 1403 if (this.Type(C) === 'Object' && hasSymbols && Symbol.species) { 1404 C = this.Get(C, Symbol.species); 1405 if (C === null) { 1406 C = void 0; 1407 } 1408 } 1409 } 1410 if (typeof C === 'undefined') { 1411 return Array(len); 1412 } 1413 if (!this.IsConstructor(C)) { 1414 throw new TypeError('C must be a constructor'); 1415 } 1416 return new C(len); // this.Construct(C, len); 1417 }, 1418 1419 CreateDataProperty: function CreateDataProperty(O, P, V) { 1420 if (this.Type(O) !== 'Object') { 1421 throw new TypeError('Assertion failed: Type(O) is not Object'); 1422 } 1423 if (!this.IsPropertyKey(P)) { 1424 throw new TypeError('Assertion failed: IsPropertyKey(P) is not true'); 1425 } 1426 var oldDesc = Object.getOwnPropertyDescriptor(O, P); 1427 var extensible = oldDesc || (typeof Object.isExtensible !== 'function' || Object.isExtensible(O)); 1428 var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable); 1429 if (immutable || !extensible) { 1430 return false; 1431 } 1432 var newDesc = { 1433 configurable: true, 1434 enumerable: true, 1435 value: V, 1436 writable: true 1437 }; 1438 Object.defineProperty(O, P, newDesc); 1439 return true; 1440 }, 1441 1442 // http://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow 1443 CreateDataPropertyOrThrow: function CreateDataPropertyOrThrow(O, P, V) { 1444 if (this.Type(O) !== 'Object') { 1445 throw new TypeError('Assertion failed: Type(O) is not Object'); 1446 } 1447 if (!this.IsPropertyKey(P)) { 1448 throw new TypeError('Assertion failed: IsPropertyKey(P) is not true'); 1449 } 1450 var success = this.CreateDataProperty(O, P, V); 1451 if (!success) { 1452 throw new TypeError('unable to create data property'); 1453 } 1454 return success; 1455 }, 1456 1457 // http://ecma-international.org/ecma-262/6.0/#sec-advancestringindex 1458 AdvanceStringIndex: function AdvanceStringIndex(S, index, unicode) { 1459 if (this.Type(S) !== 'String') { 1460 throw new TypeError('Assertion failed: Type(S) is not String'); 1461 } 1462 if (!this.IsInteger(index)) { 1463 throw new TypeError('Assertion failed: length must be an integer >= 0 and <= (2**53 - 1)'); 1464 } 1465 if (index < 0 || index > MAX_SAFE_INTEGER) { 1466 throw new RangeError('Assertion failed: length must be an integer >= 0 and <= (2**53 - 1)'); 1467 } 1468 if (this.Type(unicode) !== 'Boolean') { 1469 throw new TypeError('Assertion failed: Type(unicode) is not Boolean'); 1470 } 1471 if (!unicode) { 1472 return index + 1; 1473 } 1474 var length = S.length; 1475 if ((index + 1) >= length) { 1476 return index + 1; 1477 } 1478 var first = S.charCodeAt(index); 1479 if (first < 0xD800 || first > 0xDBFF) { 1480 return index + 1; 1481 } 1482 var second = S.charCodeAt(index + 1); 1483 if (second < 0xDC00 || second > 0xDFFF) { 1484 return index + 1; 1485 } 1486 return index + 2; 1487 } 1488}); 1489 1490delete ES6.CheckObjectCoercible; // renamed in ES6 to RequireObjectCoercible 1491 1492module.exports = ES6; 1493 1494},{"./es5":10,"./helpers/assign":12,"./helpers/isFinite":13,"./helpers/isNaN":14,"./helpers/isPrimitive":15,"./helpers/mod":16,"./helpers/sign":17,"es-to-primitive/es6":19,"function-bind":24,"has":25,"is-regex":28}],10:[function(require,module,exports){ 1495'use strict'; 1496 1497var $isNaN = require('./helpers/isNaN'); 1498var $isFinite = require('./helpers/isFinite'); 1499 1500var sign = require('./helpers/sign'); 1501var mod = require('./helpers/mod'); 1502 1503var IsCallable = require('is-callable'); 1504var toPrimitive = require('es-to-primitive/es5'); 1505 1506var has = require('has'); 1507 1508// https://es5.github.io/#x9 1509var ES5 = { 1510 ToPrimitive: toPrimitive, 1511 1512 ToBoolean: function ToBoolean(value) { 1513 return !!value; 1514 }, 1515 ToNumber: function ToNumber(value) { 1516 return Number(value); 1517 }, 1518 ToInteger: function ToInteger(value) { 1519 var number = this.ToNumber(value); 1520 if ($isNaN(number)) { return 0; } 1521 if (number === 0 || !$isFinite(number)) { return number; } 1522 return sign(number) * Math.floor(Math.abs(number)); 1523 }, 1524 ToInt32: function ToInt32(x) { 1525 return this.ToNumber(x) >> 0; 1526 }, 1527 ToUint32: function ToUint32(x) { 1528 return this.ToNumber(x) >>> 0; 1529 }, 1530 ToUint16: function ToUint16(value) { 1531 var number = this.ToNumber(value); 1532 if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; } 1533 var posInt = sign(number) * Math.floor(Math.abs(number)); 1534 return mod(posInt, 0x10000); 1535 }, 1536 ToString: function ToString(value) { 1537 return String(value); 1538 }, 1539 ToObject: function ToObject(value) { 1540 this.CheckObjectCoercible(value); 1541 return Object(value); 1542 }, 1543 CheckObjectCoercible: function CheckObjectCoercible(value, optMessage) { 1544 /* jshint eqnull:true */ 1545 if (value == null) { 1546 throw new TypeError(optMessage || 'Cannot call method on ' + value); 1547 } 1548 return value; 1549 }, 1550 IsCallable: IsCallable, 1551 SameValue: function SameValue(x, y) { 1552 if (x === y) { // 0 === -0, but they are not identical. 1553 if (x === 0) { return 1 / x === 1 / y; } 1554 return true; 1555 } 1556 return $isNaN(x) && $isNaN(y); 1557 }, 1558 1559 // http://www.ecma-international.org/ecma-262/5.1/#sec-8 1560 Type: function Type(x) { 1561 if (x === null) { 1562 return 'Null'; 1563 } 1564 if (typeof x === 'undefined') { 1565 return 'Undefined'; 1566 } 1567 if (typeof x === 'function' || typeof x === 'object') { 1568 return 'Object'; 1569 } 1570 if (typeof x === 'number') { 1571 return 'Number'; 1572 } 1573 if (typeof x === 'boolean') { 1574 return 'Boolean'; 1575 } 1576 if (typeof x === 'string') { 1577 return 'String'; 1578 } 1579 }, 1580 1581 // http://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type 1582 IsPropertyDescriptor: function IsPropertyDescriptor(Desc) { 1583 if (this.Type(Desc) !== 'Object') { 1584 return false;
1585 } 1586 var allowed = { 1587 '[[Configurable]]': true, 1588 '[[Enumerable]]': true, 1589 '[[Get]]': true, 1590 '[[Set]]': true, 1591 '[[Value]]': true, 1592 '[[Writable]]': true 1593 }; 1594 // jscs:disable 1595 for (var key in Desc) { // eslint-disable-line 1596 if (has(Desc, key) && !allowed[key]) { 1597 return false; 1598 } 1599 } 1600 // jscs:enable 1601 var isData = has(Desc, '[[Value]]'); 1602 var IsAccessor = has(Desc, '[[Get]]') || has(Desc, '[[Set]]'); 1603 if (isData && IsAccessor) { 1604 throw new TypeError('Property Descriptors may not be both accessor and data descriptors'); 1605 } 1606 return true; 1607 }, 1608 1609 // http://ecma-international.org/ecma-262/5.1/#sec-8.10.1 1610 IsAccessorDescriptor: function IsAccessorDescriptor(Desc) { 1611 if (typeof Desc === 'undefined') { 1612 return false; 1613 } 1614 1615 if (!this.IsPropertyDescriptor(Desc)) { 1616 throw new TypeError('Desc must be a Property Descriptor'); 1617 } 1618 1619 if (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) { 1620 return false; 1621 } 1622 1623 return true; 1624 }, 1625 1626 // http://ecma-international.org/ecma-262/5.1/#sec-8.10.2 1627 IsDataDescriptor: function IsDataDescriptor(Desc) { 1628 if (typeof Desc === 'undefined') { 1629 return false; 1630 } 1631 1632 if (!this.IsPropertyDescriptor(Desc)) { 1633 throw new TypeError('Desc must be a Property Descriptor'); 1634 } 1635 1636 if (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) { 1637 return false; 1638 } 1639 1640 return true; 1641 }, 1642 1643 // http://ecma-international.org/ecma-262/5.1/#sec-8.10.3 1644 IsGenericDescriptor: function IsGenericDescriptor(Desc) { 1645 if (typeof Desc === 'undefined') { 1646 return false; 1647 } 1648 1649 if (!this.IsPropertyDescriptor(Desc)) { 1650 throw new TypeError('Desc must be a Property Descriptor'); 1651 } 1652 1653 if (!this.IsAccessorDescriptor(Desc) && !this.IsDataDescriptor(Desc)) { 1654 return true; 1655 } 1656 1657 return false; 1658 }, 1659 1660 // http://ecma-international.org/ecma-262/5.1/#sec-8.10.4 1661 FromPropertyDescriptor: function FromPropertyDescriptor(Desc) { 1662 if (typeof Desc === 'undefined') { 1663 return Desc; 1664 } 1665 1666 if (!this.IsPropertyDescriptor(Desc)) { 1667 throw new TypeError('Desc must be a Property Descriptor'); 1668 } 1669 1670 if (this.IsDataDescriptor(Desc)) { 1671 return { 1672 value: Desc['[[Value]]'], 1673 writable: !!Desc['[[Writable]]'], 1674 enumerable: !!Desc['[[Enumerable]]'], 1675 configurable: !!Desc['[[Configurable]]'] 1676 }; 1677 } else if (this.IsAccessorDescriptor(Desc)) { 1678 return { 1679 get: Desc['[[Get]]'], 1680 set: Desc['[[Set]]'], 1681 enumerable: !!Desc['[[Enumerable]]'], 1682 configurable: !!Desc['[[Configurable]]'] 1683 }; 1684 } else { 1685 throw new TypeError('FromPropertyDescriptor must be called with a fully populated Property Descriptor'); 1686 } 1687 }, 1688 1689 // http://ecma-international.org/ecma-262/5.1/#sec-8.10.5 1690 ToPropertyDescriptor: function ToPropertyDescriptor(Obj) { 1691 if (this.Type(Obj) !== 'Object') { 1692 throw new TypeError('ToPropertyDescriptor requires an object'); 1693 } 1694 1695 var desc = {}; 1696 if (has(Obj, 'enumerable')) { 1697 desc['[[Enumerable]]'] = this.ToBoolean(Obj.enumerable); 1698 } 1699 if (has(Obj, 'configurable')) { 1700 desc['[[Configurable]]'] = this.ToBoolean(Obj.configurable); 1701 } 1702 if (has(Obj, 'value')) { 1703 desc['[[Value]]'] = Obj.value; 1704 } 1705 if (has(Obj, 'writable')) { 1706 desc['[[Writable]]'] = this.ToBoolean(Obj.writable); 1707 } 1708 if (has(Obj, 'get')) { 1709 var getter = Obj.get; 1710 if (typeof getter !== 'undefined' && !this.IsCallable(getter)) { 1711 throw new TypeError('getter must be a function'); 1712 } 1713 desc['[[Get]]'] = getter; 1714 } 1715 if (has(Obj, 'set')) { 1716 var setter = Obj.set; 1717 if (typeof setter !== 'undefined' && !this.IsCallable(setter)) { 1718 throw new TypeError('setter must be a function'); 1719 } 1720 desc['[[Set]]'] = setter; 1721 } 1722 1723 if ((has(desc, '[[Get]]') || has(desc, '[[Set]]')) && (has(desc, '[[Value]]') || has(desc, '[[Writable]]'))) { 1724 throw new TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute'); 1725 } 1726 return desc; 1727 } 1728}; 1729
1730module.exports = ES5; 1731 1732},{"./helpers/isFinite":13,"./helpers/isNaN":14,"./helpers/mod":16,"./helpers/sign":17,"es-to-primitive/es5":18,"has":25,"is-callable":26}],11:[function(require,module,exports){ 1733'use strict'; 1734 1735module.exports = require('./es2015'); 1736 1737},{"./es2015":9}],12:[function(require,module,exports){ 1738var has = Object.prototype.hasOwnProperty; 1739module.exports = function assign(target, source) { 1740 if (Object.assign) { 1741 return Object.assign(target, source); 1742 } 1743 for (var key in source) { 1744 if (has.call(source, key)) { 1745 target[key] = source[key]; 1746 } 1747 } 1748 return target; 1749}; 1750 1751},{}],13:[function(require,module,exports){ 1752var $isNaN = Number.isNaN || function (a) { return a !== a; }; 1753 1754module.exports = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity; }; 1755 1756},{}],14:[function(require,module,exports){ 1757module.exports = Number.isNaN || function isNaN(a) { 1758 return a !== a; 1759}; 1760 1761},{}],15:[function(require,module,exports){ 1762module.exports = function isPrimitive(value) { 1763 return value === null || (typeof value !== 'function' && typeof value !== 'object'); 1764}; 1765 1766},{}],16:[function(require,module,exports){ 1767module.exports = function mod(number, modulo) { 1768 var remain = number % modulo; 1769 return Math.floor(remain >= 0 ? remain : remain + modulo); 1770}; 1771 1772},{}],17:[function(require,module,exports){ 1773module.exports = function sign(number) { 1774 return number >= 0 ? 1 : -1; 1775}; 1776 1777},{}],18:[function(require,module,exports){ 1778'use strict'; 1779 1780var toStr = Object.prototype.toString; 1781 1782var isPrimitive = require('./helpers/isPrimitive'); 1783 1784var isCallable = require('is-callable'); 1785 1786// https://es5.github.io/#x8.12 1787var ES5internalSlots = { 1788 '[[DefaultValue]]': function (O, hint) { 1789 var actualHint = hint || (toStr.call(O) === '[object Date]' ? String : Number); 1790 1791 if (actualHint === String || actualHint === Number) { 1792 var methods = actualHint === String ? ['toString', 'valueOf'] : ['valueOf', 'toString']; 1793 var value, i; 1794 for (i = 0; i < methods.length; ++i) { 1795 if (isCallable(O[methods[i]])) { 1796 value = O[methods[i]](); 1797 if (isPrimitive(value)) { 1798 return value; 1799 } 1800 } 1801 } 1802 throw new TypeError('No default value'); 1803 } 1804 throw new TypeError('invalid [[DefaultValue]] hint supplied'); 1805 } 1806}; 1807 1808// https://es5.github.io/#x9 1809module.exports = function ToPrimitive(input, PreferredType) { 1810 if (isPrimitive(input)) { 1811 return input; 1812 } 1813 return ES5internalSlots['[[DefaultValue]]'](input, PreferredType); 1814}; 1815 1816},{"./helpers/isPrimitive":20,"is-callable":26}],19:[function(require,module,exports){ 1817'use strict'; 1818 1819var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'; 1820 1821var isPrimitive = require('./helpers/isPrimitive'); 1822var isCallable = require('is-callable'); 1823var isDate = require('is-date-object'); 1824var isSymbol = require('is-symbol'); 1825 1826var ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) { 1827 if (typeof O === 'undefined' || O === null) { 1828 throw new TypeError('Cannot call method on ' + O); 1829 } 1830 if (typeof hint !== 'string' || (hint !== 'number' && hint !== 'string')) { 1831 throw new TypeError('hint must be "string" or "number"'); 1832 } 1833 var methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString']; 1834 var method, result, i; 1835 for (i = 0; i < methodNames.length; ++i) { 1836 method = O[methodNames[i]]; 1837 if (isCallable(method)) { 1838 result = method.call(O); 1839 if (isPrimitive(result)) { 1840 return result; 1841 } 1842 } 1843 } 1844 throw new TypeError('No default value'); 1845}; 1846 1847var GetMethod = function GetMethod(O, P) { 1848 var func = O[P]; 1849 if (func !== null && typeof func !== 'undefined') { 1850 if (!isCallable(func)) { 1851 throw new TypeError(func + ' returned for property ' + P + ' of object ' + O + ' is not a function'); 1852 } 1853 return func; 1854 } 1855}; 1856 1857// http://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive 1858module.exports = function ToPrimitive(input, PreferredType) { 1859 if (isPrimitive(input)) { 1860 return input; 1861 } 1862 var hint = 'default'; 1863 if (arguments.length > 1) { 1864 if (PreferredType === String) { 1865 hint = 'string'; 1866 } else if (PreferredType === Number) { 1867 hint = 'number'; 1868 } 1869 } 1870 1871 var exoticToPrim; 1872 if (hasSymbols) { 1873 if (Symbol.toPrimitive) { 1874 exoticToPrim = GetMethod(input, Symbol.toPrimitive); 1875 } else if (isSymbol(input)) { 1876 exoticToPrim = Symbol.prototype.valueOf; 1877 } 1878 } 1879 if (typeof exoticToPrim !== 'undefined') { 1880 var result = exoticToPrim.call(input, hint); 1881 if (isPrimitive(result)) { 1882 return result; 1883 } 1884 throw new TypeError('unable to convert exotic object to primitive'); 1885 } 1886 if (hint === 'default' && (isDate(input) || isSymbol(input))) { 1887 hint = 'string'; 1888 } 1889 return ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint); 1890}; 1891 1892},{"./helpers/isPrimitive":20,"is-callable":26,"is-date-object":27,"is-symbol":29}],20:[function(require,module,exports){ 1893arguments[4][15][0].apply(exports,arguments) 1894},{"dup":15}],21:[function(require,module,exports){ 1895(function (global){ 1896(function(global){ 1897 1898// 1899// Check for native Promise and it has correct interface 1900// 1901 1902var NativePromise = global['Promise']; 1903var nativePromiseSupported = 1904 NativePromise && 1905 // Some of these methods are missing from 1906 // Firefox/Chrome experimental implementations 1907 'resolve' in NativePromise && 1908 'reject' in NativePromise && 1909 'all' in NativePromise && 1910 'race' in NativePromise && 1911 // Older version of the spec had a resolver object 1912 // as the arg rather than a function 1913 (function(){ 1914 var resolve; 1915 new NativePromise(function(r){ resolve = r; }); 1916 return typeof resolve === 'function'; 1917 })(); 1918 1919 1920//
vendor: 4,103 bytes, lines 1921-2128
1921// export if necessary 1922// 1923 1924if (typeof exports !== 'undefined' && exports) 1925{ 1926 // node.js 1927 exports.Promise = nativePromiseSupported ? NativePromise : Promise; 1928 exports.Polyfill = Promise; 1929} 1930else 1931{ 1932 // AMD 1933 if (typeof define == 'function' && define.amd) 1934 { 1935 define(function(){ 1936 return nativePromiseSupported ? NativePromise : Promise; 1937 }); 1938 } 1939 else 1940 { 1941 // in browser add to global 1942 if (!nativePromiseSupported) 1943 global['Promise'] = Promise; 1944 } 1945} 1946 1947 1948// 1949// Polyfill 1950// 1951 1952var PENDING = 'pending'; 1953var SEALED = 'sealed'; 1954var FULFILLED = 'fulfilled'; 1955var REJECTED = 'rejected'; 1956var NOOP = function(){}; 1957 1958function isArray(value) { 1959 return Object.prototype.toString.call(value) === '[object Array]'; 1960} 1961 1962// async calls 1963var asyncSetTimer = typeof setImmediate !== 'undefined' ? setImmediate : setTimeout; 1964var asyncQueue = []; 1965var asyncTimer; 1966 1967function asyncFlush(){ 1968 // run promise callbacks 1969 for (var i = 0; i < asyncQueue.length; i++) 1970 asyncQueue[i][0](asyncQueue[i][1]); 1971 1972 // reset async asyncQueue 1973 asyncQueue = []; 1974 asyncTimer = false; 1975} 1976 1977function asyncCall(callback, arg){ 1978 asyncQueue.push([callback, arg]); 1979 1980 if (!asyncTimer) 1981 { 1982 asyncTimer = true; 1983 asyncSetTimer(asyncFlush, 0); 1984 } 1985} 1986 1987 1988function invokeResolver(resolver, promise) { 1989 function resolvePromise(value) { 1990 resolve(promise, value); 1991 } 1992 1993 function rejectPromise(reason) { 1994 reject(promise, reason); 1995 } 1996 1997 try { 1998 resolver(resolvePromise, rejectPromise); 1999 } catch(e) { 2000 rejectPromise(e); 2001 } 2002} 2003 2004function invokeCallback(subscriber){ 2005 var owner = subscriber.owner; 2006 var settled = owner.state_; 2007 var value = owner.data_; 2008 var callback = subscriber[settled]; 2009 var promise = subscriber.then; 2010 2011 if (typeof callback === 'function') 2012 { 2013 settled = FULFILLED; 2014 try { 2015 value = callback(value); 2016 } catch(e) { 2017 reject(promise, e); 2018 } 2019 } 2020 2021 if (!handleThenable(promise, value)) 2022 { 2023 if (settled === FULFILLED) 2024 resolve(promise, value); 2025 2026 if (settled === REJECTED) 2027 reject(promise, value); 2028 } 2029} 2030 2031function handleThenable(promise, value) { 2032 var resolved; 2033 2034 try { 2035 if (promise === value) 2036 throw new TypeError('A promises callback cannot return that same promise.'); 2037 2038 if (value && (typeof value === 'function' || typeof value === 'object')) 2039 { 2040 var then = value.then; // then should be retrived only once 2041 2042 if (typeof then === 'function') 2043 { 2044 then.call(value, function(val){ 2045 if (!resolved) 2046 { 2047 resolved = true; 2048 2049 if (value !== val) 2050 resolve(promise, val); 2051 else 2052 fulfill(promise, val); 2053 } 2054 }, function(reason){ 2055 if (!resolved) 2056 { 2057 resolved = true; 2058 2059 reject(promise, reason); 2060 } 2061 }); 2062 2063 return true; 2064 } 2065 } 2066 } catch (e) { 2067 if (!resolved) 2068 reject(promise, e); 2069 2070 return true; 2071 } 2072 2073 return false; 2074} 2075 2076function resolve(promise, value){ 2077 if (promise === value || !handleThenable(promise, value)) 2078 fulfill(promise, value); 2079} 2080 2081function fulfill(promise, value){ 2082 if (promise.state_ === PENDING) 2083 { 2084 promise.state_ = SEALED; 2085 promise.data_ = value; 2086 2087 asyncCall(publishFulfillment, promise); 2088 } 2089} 2090 2091function reject(promise, reason){ 2092 if (promise.state_ === PENDING) 2093 { 2094 promise.state_ = SEALED; 2095 promise.data_ = reason; 2096 2097 asyncCall(publishRejection, promise); 2098 } 2099} 2100 2101function publish(promise) { 2102 var callbacks = promise.then_; 2103 promise.then_ = undefined; 2104 2105 for (var i = 0; i < callbacks.length; i++) { 2106 invokeCallback(callbacks[i]); 2107 } 2108} 2109 2110function publishFulfillment(promise){ 2111 promise.state_ = FULFILLED; 2112 publish(promise); 2113} 2114 2115function publishRejection(promise){ 2116 promise.state_ = REJECTED; 2117 publish(promise); 2118} 2119 2120/** 2121* @class 2122*/ 2123function Promise(resolver){ 2124 if (typeof resolver !== 'function') 2125 throw new TypeError('Promise constructor takes a function argument'); 2126 2127 if (this instanceof Promise === false) 2128 throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object c
2128onstructor cannot be called as a function.'); 2129 2130 this.then_ = []; 2131 2132 invokeResolver(resolver, this); 2133} 2134 2135Promise.prototype = { 2136 constructor: Promise, 2137 2138 state_: PENDING, 2139 then_: null, 2140 data_: undefined, 2141 2142 then: function(onFulfillment, onRejection){ 2143 var subscriber = { 2144 owner: this, 2145 then: new this.constructor(NOOP), 2146 fulfilled: onFulfillment, 2147 rejected: onRejection 2148 }; 2149 2150 if (this.state_ === FULFILLED || this.state_ === REJECTED) 2151 { 2152 // already resolved, call callback async 2153 asyncCall(invokeCallback, subscriber); 2154 } 2155 else 2156 { 2157 // subscribe 2158 this.then_.push(subscriber); 2159 } 2160 2161 return subscriber.then; 2162 }, 2163 2164 'catch': function(onRejection) { 2165 return this.then(null, onRejection); 2166 } 2167}; 2168 2169Promise.all = function(promises){ 2170 var Class = this; 2171 2172 if (!isArray(promises)) 2173 throw new TypeError('You must pass an array to Promise.all().'); 2174 2175 return new Class(function(resolve, reject){ 2176 var results = []; 2177 var remaining = 0; 2178 2179 function resolver(index){ 2180 remaining++; 2181 return function(value){ 2182 results[index] = value; 2183 if (!--remaining) 2184 resolve(results); 2185 }; 2186 } 2187 2188 for (var i = 0, promise; i < promises.length; i++) 2189 { 2190 promise = promises[i]; 2191 2192 if (promise && typeof promise.then === 'function') 2193 promise.then(resolver(i), reject); 2194 else 2195 results[i] = promise; 2196 } 2197 2198 if (!remaining) 2199 resolve(results); 2200 }); 2201}; 2202 2203Promise.race = function(promises){ 2204 var Class = this; 2205 2206 if (!isArray(promises)) 2207 throw new TypeError('You must pass an array to Promise.race().'); 2208 2209 return new Class(function(resolve, reject) { 2210 for (var i = 0, promise; i < promises.length; i++) 2211 { 2212 promise = promises[i]; 2213 2214 if (promise && typeof promise.then === 'function') 2215 promise.then(resolve, reject); 2216 else 2217 resolve(promise); 2218 } 2219 }); 2220}; 2221 2222Promise.resolve = function(value){ 2223 var Class = this; 2224 2225 if (value && typeof value === 'object' && value.constructor === Class) 2226 return value; 2227 2228 return new Class(function(resolve){ 2229 resolve(value); 2230 }); 2231}; 2232 2233Promise.reject = function(reason){ 2234 var Class = this; 2235 2236 return new Class(function(resolve, reject){ 2237 reject(reason); 2238 }); 2239}; 2240 2241})(typeof window != 'undefined' ? window : typeof global != 'undefined' ? global : typeof self != 'undefined' ? self : this); 2242 2243}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 2244},{}],22:[function(require,module,exports){ 2245 2246var hasOwn = Object.prototype.hasOwnProperty; 2247var toString = Object.prototype.toString; 2248 2249module.exports = function forEach (obj, fn, ctx) { 2250 if (toString.call(fn) !== '[object Function]') { 2251 throw new TypeError('iterator must be a function'); 2252 } 2253 var l = obj.length; 2254 if (l === +l) { 2255 for (var i = 0; i < l; i++) { 2256 fn.call(ctx, obj[i], i, obj); 2257 } 2258 } else { 2259 for (var k in obj) { 2260 if (hasOwn.call(obj, k)) { 2261 fn.call(ctx, obj[k], k, obj); 2262 } 2263 } 2264 } 2265}; 2266 2267 2268},{}],23:[function(require,module,exports){ 2269'use strict'; 2270 2271/* eslint no-invalid-this: 1 */ 2272 2273var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; 2274var slice = Array.prototype.slice; 2275var toStr = Object.prototype.toString; 2276var funcType = '[object Function]'; 2277 2278module.exports = function bind(that) { 2279 var target = this; 2280 if (typeof target !== 'function' || toStr.call(target) !== funcType) { 2281 throw new TypeError(ERROR_MESSAGE + target); 2282 } 2283 var args = slice.call(arguments, 1); 2284 2285 var bound; 2286 var binder = function () { 2287 if (this instanceof bound) { 2288 var result = target.apply( 2289 this, 2290 args.concat(slice.call(arguments)) 2291 ); 2292 if (Object(result) === result) { 2293 return result; 2294 } 2295 return this; 2296 } else { 2297 return target.apply( 2298 that, 2299 args.concat(slice.call(arguments)) 2300 ); 2301 } 2302 }; 2303 2304 var boundLength = Math.max(0, target.length - args.length); 2305 var boundArgs = []; 2306 for (var i = 0; i < boundLength; i++) { 2307 boundArgs.push('$' + i); 2308 } 2309 2310 bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder); 2311 2312 if (target.prototype) { 2313 var Empty = function Empty() {}; 2314 Empty.prototype = target.prototype; 2315 bound.prototype = new Empty(); 2316 Empty.prototype = null; 2317 } 2318 2319 return bound; 2320}; 2321 2322},{}],24:[function(require,module,exports){ 2323'use strict'; 2324 2325var implementation = require('./implementation'); 2326 2327module.exports = Function.prototype.bind || implementation; 2328 2329},{"./implementation":23}],25:[function(require,module,exports){ 2330var bind = require('function-bind'); 2331 2332module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty); 2333 2334},{"function-bind":24}],26:[function(require,module,exports){ 2335'use strict'; 2336 2337var fnToStr = Function.prototype.toString; 2338 2339var constructorRegex = /^\s*class /; 2340var isES6ClassFn = function isES6ClassFn(value) { 2341 try { 2342 var fnStr = fnToStr.call(value); 2343 var singleStripped = fnStr.replace(/\/\/.*\n/g, ''); 2344 var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, ''); 2345 var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' '); 2346 return constructorRegex.test(spaceStripped); 2347 } catch (e) { 2348 return false; // not a function 2349 } 2350}; 2351 2352var tryFunctionObject = function tryFunctionObject(value) { 2353 try { 2354 if (isES6ClassFn(value)) { return false; } 2355 fnToStr.call(value); 2356 return true; 2357 } catch (e) { 2358 return false;
2359 } 2360}; 2361var toStr = Object.prototype.toString; 2362var fnClass = '[object Function]'; 2363var genClass = '[object GeneratorFunction]'; 2364var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; 2365 2366module.exports = function isCallable(value) { 2367 if (!value) { return false; } 2368 if (typeof value !== 'function' && typeof value !== 'object') { return false; } 2369 if (hasToStringTag) { return tryFunctionObject(value); } 2370 if (isES6ClassFn(value)) { return false; } 2371 var strClass = toStr.call(value); 2372 return strClass === fnClass || strClass === genClass; 2373}; 2374 2375},{}],27:[function(require,module,exports){ 2376'use strict'; 2377 2378var getDay = Date.prototype.getDay; 2379var tryDateObject = function tryDateObject(value) { 2380 try { 2381 getDay.call(value); 2382 return true; 2383 } catch (e) { 2384 return false; 2385 } 2386}; 2387 2388var toStr = Object.prototype.toString; 2389var dateClass = '[object Date]'; 2390var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; 2391 2392module.exports = function isDateObject(value) { 2393 if (typeof value !== 'object' || value === null) { return false; } 2394 return hasToStringTag ? tryDateObject(value) : toStr.call(value) === dateClass; 2395}; 2396 2397},{}],28:[function(require,module,exports){ 2398'use strict'; 2399 2400var has = require('has'); 2401var regexExec = RegExp.prototype.exec; 2402var gOPD = Object.getOwnPropertyDescriptor; 2403 2404var tryRegexExecCall = function tryRegexExec(value) { 2405 try { 2406 var lastIndex = value.lastIndex; 2407 value.lastIndex = 0; 2408 2409 regexExec.call(value); 2410 return true; 2411 } catch (e) { 2412 return false; 2413 } finally { 2414 value.lastIndex = lastIndex; 2415 } 2416}; 2417var toStr = Object.prototype.toString; 2418var regexClass = '[object RegExp]'; 2419var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; 2420 2421module.exports = function isRegex(value) { 2422 if (!value || typeof value !== 'object') { 2423 return false; 2424 } 2425 if (!hasToStringTag) { 2426 return toStr.call(value) === regexClass; 2427 } 2428 2429 var descriptor = gOPD(value, 'lastIndex'); 2430 var hasLastIndexDataProperty = descriptor && has(descriptor, 'value'); 2431 if (!hasLastIndexDataProperty) { 2432 return false; 2433 } 2434 2435 return tryRegexExecCall(value); 2436}; 2437 2438},{"has":25}],29:[function(require,module,exports){ 2439'use strict'; 2440 2441var toStr = Object.prototype.toString; 2442var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol'; 2443 2444if (hasSymbols) { 2445 var symToStr = Symbol.prototype.toString; 2446 var symStringRegex = /^Symbol\(.*\)$/; 2447 var isSymbolObject = function isSymbolObject(value) { 2448 if (typeof value.valueOf() !== 'symbol') { return false; } 2449 return symStringRegex.test(symToStr.call(value)); 2450 }; 2451 module.exports = function isSymbol(value) { 2452 if (typeof value === 'symbol') { return true; } 2453 if (toStr.call(value) !== '[object Symbol]') { return false; } 2454 try { 2455 return isSymbolObject(value); 2456 } catch (e) { 2457 return false; 2458 } 2459 }; 2460} else { 2461 module.exports = function isSymbol(value) { 2462 // this environment does not support Symbols. 2463 return false; 2464 }; 2465} 2466 2467},{}],30:[function(require,module,exports){ 2468'use strict'; 2469 2470var range; // Create a range object for efficently rendering strings to elements. 2471var NS_XHTML = 'http://www.w3.org/1999/xhtml'; 2472 2473var doc = typeof document === 'undefined' ? undefined : document; 2474 2475var testEl = doc ? 2476 doc.body || doc.createElement('div') : 2477 {}; 2478 2479// Fixes <https://github.com/patrick-steele-idem/morphdom/issues/32> 2480// (IE7+ support) <=IE7 does not support el.hasAttribute(name) 2481var actualHasAttributeNS; 2482 2483if (testEl.hasAttributeNS) { 2484 actualHasAttributeNS = function(el, namespaceURI, name) { 2485 return el.hasAttributeNS(namespaceURI, name); 2486 }; 2487} else if (testEl.hasAttribute) { 2488 actualHasAttributeNS = function(el, namespaceURI, name) { 2489 return el.hasAttribute(name); 2490 }; 2491} else { 2492 actualHasAttributeNS = function(el, namespaceURI, name) { 2493 return el.getAttributeNode(namespaceURI, name) != null; 2494 }; 2495} 2496 2497var hasAttributeNS = actualHasAttributeNS; 2498 2499 2500function toElement(str) { 2501 if (!range && doc.createRange) { 2502 range = doc.createRange(); 2503 range.selectNode(doc.body); 2504 } 2505 2506 var fragment; 2507 if (range && range.createContextualFragment) { 2508 fragment = range.createContextualFragment(str); 2509 } else { 2510 fragment = doc.createElement('body'); 2511 fragment.innerHTML = str; 2512 } 2513 return fragment.childNodes[0]; 2514} 2515 2516/** 2517 * Returns true if two node's names are the same. 2518 * 2519 * NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same 2520 * nodeName and different namespace URIs. 2521 * 2522 * @param {Element} a 2523 * @param {Element} b The target element 2524 * @return {boolean} 2525 */ 2526function compareNodeNames(fromEl, toEl) { 2527 var fromNodeName = fromEl.nodeName; 2528 var toNodeName = toEl.nodeName; 2529 2530 if (fromNodeName === toNodeName) { 2531 return true; 2532 } 2533 2534 if (toEl.actualize && 2535 fromNodeName.charCodeAt(0) < 91 && /* from tag name is upper case */ 2536 toNodeName.charCodeAt(0) > 90 /* target tag name is lower case */) { 2537 // If the target element is a virtual DOM node then we may need to normalize the tag name 2538 // before comparing. Normal HTML elements that are in the "http://www.w3.org/1999/xhtml" 2539 // are converted to upper case 2540 return fromNodeName === toNodeName.toUpperCase(); 2541 } else { 2542 return false;
2543 } 2544} 2545 2546/** 2547 * Create an element, optionally with a known namespace URI. 2548 * 2549 * @param {string} name the element name, e.g. 'div' or 'svg' 2550 * @param {string} [namespaceURI] the element's namespace URI, i.e. the value of 2551 * its `xmlns` attribute or its inferred namespace. 2552 * 2553 * @return {Element} 2554 */ 2555function createElementNS(name, namespaceURI) { 2556 return !namespaceURI || namespaceURI === NS_XHTML ? 2557 doc.createElement(name) : 2558 doc.createElementNS(namespaceURI, name); 2559} 2560 2561/** 2562 * Copies the children of one DOM element to another DOM element 2563 */ 2564function moveChildren(fromEl, toEl) { 2565 var curChild = fromEl.firstChild; 2566 while (curChild) { 2567 var nextChild = curChild.nextSibling; 2568 toEl.appendChild(curChild); 2569 curChild = nextChild; 2570 } 2571 return toEl; 2572} 2573 2574function morphAttrs(fromNode, toNode) { 2575 var attrs = toNode.attributes; 2576 var i; 2577 var attr; 2578 var attrName; 2579 var attrNamespaceURI; 2580 var attrValue; 2581 var fromValue; 2582 2583 for (i = attrs.length - 1; i >= 0; --i) { 2584 attr = attrs[i]; 2585 attrName = attr.name; 2586 attrNamespaceURI = attr.namespaceURI; 2587 attrValue = attr.value; 2588 2589 if (attrNamespaceURI) { 2590 attrName = attr.localName || attrName; 2591 fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName); 2592 2593 if (fromValue !== attrValue) { 2594 fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); 2595 } 2596 } else { 2597 fromValue = fromNode.getAttribute(attrName); 2598 2599 if (fromValue !== attrValue) { 2600 fromNode.setAttribute(attrName, attrValue); 2601 } 2602 } 2603 } 2604 2605 // Remove any extra attributes found on the original DOM element that 2606 // weren't found on the target element. 2607 attrs = fromNode.attributes; 2608 2609 for (i = attrs.length - 1; i >= 0; --i) { 2610 attr = attrs[i]; 2611 if (attr.specified !== false) { 2612 attrName = attr.name; 2613 attrNamespaceURI = attr.namespaceURI; 2614 2615 if (attrNamespaceURI) { 2616 attrName = attr.localName || attrName; 2617 2618 if (!hasAttributeNS(toNode, attrNamespaceURI, attrName)) { 2619 fromNode.removeAttributeNS(attrNamespaceURI, attrName); 2620 } 2621 } else { 2622 if (!hasAttributeNS(toNode, null, attrName)) { 2623 fromNode.removeAttribute(attrName); 2624 } 2625 } 2626 } 2627 } 2628} 2629 2630function syncBooleanAttrProp(fromEl, toEl, name) { 2631 if (fromEl[name] !== toEl[name]) { 2632 fromEl[name] = toEl[name]; 2633 if (fromEl[name]) { 2634 fromEl.setAttribute(name, ''); 2635 } else { 2636 fromEl.removeAttribute(name, ''); 2637 } 2638 } 2639} 2640 2641var specialElHandlers = { 2642 /** 2643 * Needed for IE. Apparently IE doesn't think that "selected" is an 2644 * attribute when reading over the attributes using selectEl.attributes 2645 */ 2646 OPTION: function(fromEl, toEl) { 2647 syncBooleanAttrProp(fromEl, toEl, 'selected'); 2648 }, 2649 /** 2650 * The "value" attribute is special for the <input> element since it sets 2651 * the initial value. Changing the "value" attribute without changing the 2652 * "value" property will have no effect since it is only used to the set the 2653 * initial value. Similar for the "checked" attribute, and "disabled". 2654 */ 2655 INPUT: function(fromEl, toEl) { 2656 syncBooleanAttrProp(fromEl, toEl, 'checked'); 2657 syncBooleanAttrProp(fromEl, toEl, 'disabled'); 2658 2659 if (fromEl.value !== toEl.value) { 2660 fromEl.value = toEl.value; 2661 } 2662 2663 if (!hasAttributeNS(toEl, null, 'value')) { 2664 fromEl.removeAttribute('value'); 2665 } 2666 }, 2667 2668 TEXTAREA: function(fromEl, toEl) { 2669 var newValue = toEl.value; 2670 if (fromEl.value !== newValue) { 2671 fromEl.value = newValue; 2672 } 2673 2674 var firstChild = fromEl.firstChild; 2675 if (firstChild) { 2676 // Needed for IE. Apparently IE sets the placeholder as the 2677 // node value and vise versa. This ignores an empty update. 2678 var oldValue = firstChild.nodeValue; 2679 2680 if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) { 2681 return; 2682 } 2683 2684 firstChild.nodeValue = newValue; 2685 } 2686 }, 2687 SELECT: function(fromEl, toEl) { 2688 if (!hasAttributeNS(toEl, null, 'multiple')) { 2689 var selectedIndex = -1; 2690 var i = 0; 2691 var curChild = toEl.firstChild; 2692 while(curChild) { 2693 var nodeName = curChild.nodeName; 2694 if (nodeName && nodeName.toUpperCase() === 'OPTION') { 2695 if (hasAttributeNS(curChild, null, 'selected')) { 2696 selectedIndex = i; 2697 break; 2698 } 2699 i++; 2700 } 2701 curChild = curChild.nextSibling; 2702 } 2703 2704 fromEl.selectedIndex = i; 2705 } 2706 } 2707}; 2708 2709var ELEMENT_NODE = 1; 2710var TEXT_NODE = 3; 2711var COMMENT_NODE = 8; 2712 2713function noop() {} 2714 2715function defaultGetNodeKey(node) { 2716 return node.id; 2717} 2718 2719function morphdomFactory(morphAttrs) { 2720 2721 return function morphdom(fromNode, toNode, options) { 2722 if (!options) { 2723 options = {}; 2724 } 2725 2726 if (typeof toNode === 'string') { 2727 if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML') { 2728 var toNodeHtml = toNode; 2729 toNode = doc.createElement('html'); 2730 toNode.innerHTML = toNodeHtml; 2731 } else { 2732 toNode = toElement(toNode); 2733 } 2734 } 2735 2736 var getNodeKey = options.getNodeKey || defaultGetNodeKey; 2737 var onBeforeNodeAdded = options.onBeforeNodeAdded || noop; 2738 var onNodeAdded = options.onNodeAdded || noop; 2739 var onBeforeElUpdated = options.onBeforeElUpdated || noop; 2740 var onElUpdated = options.onElUpdated || noop; 2741 var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop; 2742 var onNodeDiscarded = options.onNodeDiscarded || noop; 2743 var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop; 2744 var childrenOnly = options.childrenOnly === true; 2745 2746 // This object is used as a lookup to quickly find all keyed elements in the original DOM tree. 2747 var fromNodesLookup = {}; 2748 var keyedRemovalList; 2749 2750 function addKeyedRemoval(key) { 2751 if (keyedRemovalList) { 2752 keyedRemovalList.push(key); 2753 } else { 2754 keyedRemovalList = [key]; 2755 } 2756 } 2757 2758 function walkDiscardedChildNodes(node, skipKeyedNodes) { 2759 if (node.nodeType === ELEMENT_NODE) { 2760 var curChild = node.firstChild; 2761 while (curChild) { 2762 2763 var key = undefined; 2764 2765 if (skipKeyedNodes && (key = getNodeKey(curChild))) { 2766 // If we are skipping keyed nodes then we add the key 2767 // to a list so that it can be handled at the very end. 2768 addKeyedRemoval(key); 2769 } else { 2770 // Only report the node as discarded if it is not keyed. We do this because 2771 // at the end we loop through all keyed elements that were unmatched 2772 // and then discard them in one final pass. 2773 onNodeDiscarded(curChild); 2774 if (curChild.firstChild) { 2775 walkDiscardedChildNodes(curChild, skipKeyedNodes); 2776 } 2777 } 2778 2779 curChild = curChild.nextSibling; 2780 } 2781 } 2782 } 2783 2784 /** 2785 * Removes a DOM node out of the original DOM 2786 * 2787 * @param {Node} node The node to remove 2788 * @param {Node} parentNode The nodes parent 2789 * @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded. 2790 * @return {undefined} 2791 */ 2792 function removeNode(node, parentNode, skipKeyedNodes) { 2793 if (onBeforeNodeDiscarded(node) === false) { 2794 return; 2795 } 2796 2797 if (parentNode) { 2798 parentNode.removeChild(node); 2799 } 2800 2801 onNodeDiscarded(node); 2802 walkDiscardedChildNodes(node, skipKeyedNodes); 2803 } 2804 2805 // // TreeWalker implementation is no faster, but keeping this around in case this changes in the future 2806 // function indexTree(root) { 2807 // var treeWalker = document.createTreeWalker( 2808 // root, 2809 // NodeFilter.SHOW_ELEMENT); 2810 // 2811 // var el; 2812 // while((el = treeWalker.nextNode())) { 2813 // var key = getNodeKey(el); 2814 // if (key) { 2815 // fromNodesLookup[key] = el; 2816 // } 2817 // } 2818 // } 2819 2820 // // NodeIterator implementation is no faster, but keeping this around in case this changes in the future 2821 // 2822 // function indexTree(node) { 2823 // var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT); 2824 // var el; 2825 // while((el = nodeIterator.nextNode())) { 2826 // var key = getNodeKey(el); 2827 // if (key) { 2828 // fromNodesLookup[key] = el; 2829 // } 2830 // } 2831 // } 2832 2833 function indexTree(node) { 2834 if (node.nodeType === ELEMENT_NODE) { 2835 var curChild = node.firstChild; 2836 while (curChild) { 2837 var key = getNodeKey(curChild); 2838 if (key) { 2839 fromNodesLookup[key] = curChild; 2840 } 2841 2842 // Walk recursively 2843 indexTree(curChild); 2844 2845 curChild = curChild.nextSibling; 2846 } 2847 } 2848 } 2849 2850 indexTree(fromNode); 2851 2852 function handleNodeAdded(el) { 2853 onNodeAdded(el); 2854 2855 var curChild = el.firstChild; 2856 while (curChild) { 2857 var nextSibling = curChild.nextSibling; 2858 2859 var key = getNodeKey(curChild); 2860 if (key) { 2861 var unmatchedFromEl = fromNodesLookup[key]; 2862 if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) { 2863 curChild.parentNode.replaceChild(unmatchedFromEl, curChild); 2864 morphEl(unmatchedFromEl, curChild); 2865 } 2866 } 2867 2868 handleNodeAdded(curChild); 2869 curChild = nextSibling; 2870 } 2871 } 2872 2873 function morphEl(fromEl, toEl, childrenOnly) { 2874 var toElKey = getNodeKey(toEl); 2875 var curFromNodeKey; 2876 2877 if (toElKey) { 2878 // If an element with an ID is being morphed then it is will be in the final 2879 // DOM so clear it out of the saved elements collection 2880 delete fromNodesLookup[toElKey]; 2881 } 2882 2883 if (toNode.isSameNode && toNode.isSameNode(fromNode)) { 2884 return; 2885 } 2886 2887 if (!childrenOnly) { 2888 if (onBeforeElUpdated(fromEl, toEl) === false) { 2889 return; 2890 } 2891 2892 morphAttrs(fromEl, toEl); 2893 onElUpdated(fromEl); 2894 2895 if (onBeforeElChildrenUpdated(fromEl, toEl) === false) { 2896 return; 2897 } 2898 } 2899 2900 if (fromEl.nodeName !== 'TEXTAREA') { 2901 var curToNodeChild = toEl.firstChild; 2902 var curFromNodeChild = fromEl.firstChild; 2903 var curToNodeKey; 2904 2905 var fromNextSibling; 2906 var toNextSibling; 2907 var matchingFromEl; 2908 2909 outer: while (curToNodeChild) { 2910 toNextSibling = curToNodeChild.nextSibling; 2911 curToNodeKey = getNodeKey(curToNodeChild); 2912 2913 while (curFromNodeChild) { 2914 fromNextSibling = curFromNodeChild.nextSibling; 2915 2916 if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) { 2917 curToNodeChild = toNextSibling; 2918 curFromNodeChild = fromNextSibling; 2919 continue outer; 2920 } 2921 2922 curFromNodeKey = getNodeKey(curFromNodeChild); 2923 2924 var curFromNodeType = curFromNodeChild.nodeType; 2925 2926 var isCompatible = undefined; 2927 2928 if (curFromNodeType === curToNodeChild.nodeType) { 2929 if (curFromNodeType === ELEMENT_NODE) {
vendor: 4,596 bytes, lines 2930-2990
2930 // Both nodes being compared are Element nodes 2931 2932 if (curToNodeKey) { 2933 // The target node has a key so we want to match it up with the correct element 2934 // in the original DOM tree 2935 if (curToNodeKey !== curFromNodeKey) { 2936 // The current element in the original DOM tree does not have a matching key so 2937 // let's check our lookup to see if there is a matching element in the original 2938 // DOM tree 2939 if ((matchingFromEl = fromNodesLookup[curToNodeKey])) { 2940 if (curFromNodeChild.nextSibling === matchingFromEl) { 2941 // Special case for single element removals. To avoid removing the original 2942 // DOM node out of the tree (since that can break CSS transitions, etc.), 2943 // we will instead discard the current node and wait until the next 2944 // iteration to properly match up the keyed target element with its matching 2945 // element in the original tree 2946 isCompatible = false; 2947 } else { 2948 // We found a matching keyed element somewhere in the original DOM tree. 2949 // Let's moving the original DOM node into the current position and morph 2950 // it. 2951 2952 // NOTE: We use insertBefore instead of replaceChild because we want to go through 2953 // the `removeNode()` function for the node that is being discarded so that 2954 // all lifecycle hooks are correctly invoked 2955 fromEl.insertBefore(matchingFromEl, curFromNodeChild); 2956 2957 fromNextSibling = curFromNodeChild.nextSibling; 2958 2959 if (curFromNodeKey) { 2960 // Since the node is keyed it might be matched up later so we defer 2961 // the actual removal to later 2962 addKeyedRemoval(curFromNodeKey); 2963 } else { 2964 // NOTE: we skip nested keyed nodes from being removed since there is 2965 // still a chance they will be matched up later 2966 removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */); 2967 } 2968 2969 curFromNodeChild = matchingFromEl; 2970 } 2971 } else { 2972 // The nodes are not compatible since the "to" node has a key and there 2973 // is no matching keyed node in the source tree 2974 isCompatible = false; 2975 } 2976 } 2977 } else if (curFromNodeKey) { 2978 // The original has a key 2979 isCompatible = false; 2980 } 2981 2982 isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild); 2983 if (isCompatible) { 2984 // We found compatible DOM elements so transform 2985 // the current "from" node to match the current 2986 // target DOM node. 2987 morphEl(curFromNodeChild, curToNodeChild); 2988 } 2989 2990 } else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {
2991 // Both nodes being compared are Text or Comment nodes 2992 isCompatible = true; 2993 // Simply update nodeValue on the original node to 2994 // change the text value 2995 if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) { 2996 curFromNodeChild.nodeValue = curToNodeChild.nodeValue; 2997 } 2998 2999 } 3000 } 3001 3002 if (isCompatible) { 3003 // Advance both the "to" child and the "from" child since we found a match 3004 curToNodeChild = toNextSibling; 3005 curFromNodeChild = fromNextSibling; 3006 continue outer; 3007 } 3008 3009 // No compatible match so remove the old node from the DOM and continue trying to find a 3010 // match in the original DOM. However, we only do this if the from node is not keyed 3011 // since it is possible that a keyed node might match up with a node somewhere else in the 3012 // target tree and we don't want to discard it just yet since it still might find a 3013 // home in the final DOM tree. After everything is done we will remove any keyed nodes 3014 // that didn't find a home 3015 if (curFromNodeKey) { 3016 // Since the node is keyed it might be matched up later so we defer 3017 // the actual removal to later 3018 addKeyedRemoval(curFromNodeKey); 3019 } else { 3020 // NOTE: we skip nested keyed nodes from being removed since there is 3021 // still a chance they will be matched up later 3022 removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */); 3023 } 3024 3025 curFromNodeChild = fromNextSibling; 3026 } 3027 3028 // If we got this far then we did not find a candidate match for 3029 // our "to node" and we exhausted all of the children "from" 3030 // nodes. Therefore, we will just append the current "to" node 3031 // to the end 3032 if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) { 3033 fromEl.appendChild(matchingFromEl); 3034 morphEl(matchingFromEl, curToNodeChild); 3035 } else { 3036 var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild); 3037 if (onBeforeNodeAddedResult !== false) { 3038 if (onBeforeNodeAddedResult) { 3039 curToNodeChild = onBeforeNodeAddedResult; 3040 } 3041 3042 if (curToNodeChild.actualize) { 3043 curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc); 3044 } 3045 fromEl.appendChild(curToNodeChild); 3046 handleNodeAdded(curToNodeChild); 3047 } 3048 } 3049 3050 curToNodeChild = toNextSibling; 3051 curFromNodeChild = fromNextSibling; 3052 } 3053 3054 // We have processed all of the "to nodes". If curFromNodeChild is 3055 // non-null then we still have some from nodes left over that need 3056 // to be removed 3057 while (curFromNodeChild) { 3058 fromNextSibling = curFromNodeChild.nextSibling; 3059 if ((curFromNodeKey = getNodeKey(curFromNodeChild))) { 3060 // Since the node is keyed it might be matched up later so we defer 3061 // the actual removal to later 3062 addKeyedRemoval(curFromNodeKey); 3063 } else { 3064 // NOTE: we skip nested keyed nodes from being removed since there is 3065 // still a chance they will be matched up later 3066 removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */); 3067 } 3068 curFromNodeChild = fromNextSibling; 3069 } 3070 } 3071 3072 var specialElHandler = specialElHandlers[fromEl.nodeName]; 3073 if (specialElHandler) { 3074 specialElHandler(fromEl, toEl); 3075 } 3076 } // END: morphEl(...) 3077 3078 var morphedNode = fromNode; 3079 var morphedNodeType = morphedNode.nodeType; 3080 var toNodeType = toNode.nodeType; 3081 3082 if (!childrenOnly) { 3083 // Handle the case where we are given two DOM nodes that are not 3084 // compatible (e.g. <div> --> <span> or <div> --> TEXT) 3085 if (morphedNodeType === ELEMENT_NODE) { 3086 if (toNodeType === ELEMENT_NODE) { 3087 if (!compareNodeNames(fromNode, toNode)) { 3088 onNodeDiscarded(fromNode); 3089 morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI)); 3090 } 3091 } else { 3092 // Going from an element node to a text node 3093 morphedNode = toNode; 3094 } 3095 } else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) { // Text or comment node 3096 if (toNodeType === morphedNodeType) { 3097 if (morphedNode.nodeValue !== toNode.nodeValue) { 3098 morphedNode.nodeValue = toNode.nodeValue; 3099 } 3100 3101 return morphedNode; 3102 } else { 3103 // Text node to something else 3104 morphedNode = toNode; 3105 } 3106 } 3107 } 3108 3109 if (morphedNode === toNode) { 3110 // The "to node" was not compatible with the "from node" so we had to 3111 // toss out the "from node" and use the "to node" 3112 onNodeDiscarded(fromNode); 3113 } else { 3114 morphEl(morphedNode, toNode, childrenOnly); 3115 3116 // We now need to loop over any keyed nodes that might need to be 3117 // removed. We only do the removal if we know that the keyed node 3118 // never found a match. When a keyed node is matched up we remove 3119 // it out of fromNodesLookup and we use fromNodesLookup to determine 3120 // if a keyed node has been matched up or not 3121 if (keyedRemovalList) { 3122 for (var i=0, len=keyedRemovalList.length; i<len; i++) { 3123 var elToRemove = fromNodesLookup[keyedRemovalList[i]]; 3124 if (elToRemove) { 3125 removeNode(elToRemove, elToRemove.parentNode, false); 3126 } 3127 } 3128 } 3129 } 3130 3131 if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) { 3132 if (morphedNode.actualize) { 3133 morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc); 3134 } 3135 // If we had to swap out the from node with a new node because the old 3136 // node was not compatible with the target node then we need to 3137 // replace the old DOM node in the original DOM tree. This is only 3138 // possible if the original DOM node was part of a DOM tree which 3139 // we know is the case if it has a parent node. 3140 fromNode.parentNode.replaceChild(morphedNode, fromNode); 3141 } 3142 3143 return morphedNode; 3144 }; 3145} 3146 3147var morphdom = morphdomFactory(morphAttrs); 3148 3149module.exports = morphdom; 3150 3151},{}],31:[function(require,module,exports){ 3152'use strict'; 3153 3154// modified from https://github.com/es-shims/es5-shim 3155var has = Object.prototype.hasOwnProperty; 3156var toStr = Object.prototype.toString; 3157var slice = Array.prototype.slice; 3158var isArgs = require('./isArguments'); 3159var isEnumerable = Object.prototype.propertyIsEnumerable; 3160var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString'); 3161var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype'); 3162var dontEnums = [ 3163 'toString',
3164 'toLocaleString', 3165 'valueOf', 3166 'hasOwnProperty', 3167 'isPrototypeOf', 3168 'propertyIsEnumerable', 3169 'constructor' 3170]; 3171var equalsConstructorPrototype = function (o) { 3172 var ctor = o.constructor; 3173 return ctor && ctor.prototype === o; 3174}; 3175var excludedKeys = { 3176 $console: true, 3177 $external: true, 3178 $frame: true, 3179 $frameElement: true, 3180 $frames: true, 3181 $innerHeight: true, 3182 $innerWidth: true, 3183 $outerHeight: true, 3184 $outerWidth: true, 3185 $pageXOffset: true, 3186 $pageYOffset: true, 3187 $parent: true, 3188 $scrollLeft: true, 3189 $scrollTop: true, 3190 $scrollX: true, 3191 $scrollY: true, 3192 $self: true, 3193 $webkitIndexedDB: true, 3194 $webkitStorageInfo: true, 3195 $window: true 3196}; 3197var hasAutomationEqualityBug = (function () { 3198 /* global window */ 3199 if (typeof window === 'undefined') { return false; } 3200 for (var k in window) { 3201 try { 3202 if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { 3203 try { 3204 equalsConstructorPrototype(window[k]); 3205 } catch (e) { 3206 return true; 3207 } 3208 } 3209 } catch (e) { 3210 return true; 3211 } 3212 } 3213 return false; 3214}()); 3215var equalsConstructorPrototypeIfNotBuggy = function (o) { 3216 /* global window */ 3217 if (typeof window === 'undefined' || !hasAutomationEqualityBug) { 3218 return equalsConstructorPrototype(o); 3219 } 3220 try { 3221 return equalsConstructorPrototype(o); 3222 } catch (e) { 3223 return false; 3224 } 3225}; 3226 3227var keysShim = function keys(object) { 3228 var isObject = object !== null && typeof object === 'object'; 3229 var isFunction = toStr.call(object) === '[object Function]'; 3230 var isArguments = isArgs(object); 3231 var isString = isObject && toStr.call(object) === '[object String]'; 3232 var theKeys = []; 3233 3234 if (!isObject && !isFunction && !isArguments) { 3235 throw new TypeError('Object.keys called on a non-object'); 3236 } 3237 3238 var skipProto = hasProtoEnumBug && isFunction; 3239 if (isString && object.length > 0 && !has.call(object, 0)) { 3240 for (var i = 0; i < object.length; ++i) { 3241 theKeys.push(String(i)); 3242 } 3243 } 3244 3245 if (isArguments && object.length > 0) { 3246 for (var j = 0; j < object.length; ++j) { 3247 theKeys.push(String(j)); 3248 } 3249 } else { 3250 for (var name in object) { 3251 if (!(skipProto && name === 'prototype') && has.call(object, name)) { 3252 theKeys.push(String(name)); 3253 } 3254 } 3255 } 3256 3257 if (hasDontEnumBug) { 3258 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); 3259 3260 for (var k = 0; k < dontEnums.length; ++k) { 3261 if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { 3262 theKeys.push(dontEnums[k]); 3263 } 3264 } 3265 } 3266 return theKeys; 3267}; 3268 3269keysShim.shim = function shimObjectKeys() { 3270 if (Object.keys) { 3271 var keysWorksWithArguments = (function () { 3272 // Safari 5.0 bug 3273 return (Object.keys(arguments) || '').length === 2; 3274 }(1, 2)); 3275 if (!keysWorksWithArguments) { 3276 var originalKeys = Object.keys; 3277 Object.keys = function keys(object) { 3278 if (isArgs(object)) { 3279 return originalKeys(slice.call(object)); 3280 } else { 3281 return originalKeys(object); 3282 } 3283 }; 3284 } 3285 } else { 3286 Object.keys = keysShim; 3287 } 3288 return Object.keys || keysShim; 3289}; 3290 3291module.exports = keysShim; 3292 3293},{"./isArguments":32}],32:[function(require,module,exports){ 3294'use strict'; 3295 3296var toStr = Object.prototype.toString; 3297 3298module.exports = function isArguments(value) { 3299 var str = toStr.call(value); 3300 var isArgs = str === '[object Arguments]'; 3301 if (!isArgs) { 3302 isArgs = str !== '[object Array]' && 3303 value !== null && 3304 typeof value === 'object' && 3305 typeof value.length === 'number' && 3306 value.length >= 0 && 3307 toStr.call(value.callee) === '[object Function]'; 3308 } 3309 return isArgs; 3310}; 3311 3312},{}],33:[function(require,module,exports){ 3313'use strict'; 3314 3315var SmartPhoto = require('../index'); 3316 3317var applyJQuery = function applyJQuery(jQuery) { 3318 jQuery.fn.SmartPhoto = function (settings) { 3319 if (typeof settings === 'strings') {} else { 3320 new SmartPhoto(this, settings); 3321 } 3322 return this; 3323 }; 3324}; 3325 3326if (typeof define === 'function' && define.amd) { 3327 define(['jquery'], applyJQuery); 3328} else { 3329 var jq = window.jQuery ? window.jQuery : window.$; 3330 if (typeof jq !== 'undefined') { 3331 applyJQuery(jq); 3332 } 3333} 3334 3335module.exports = applyJQuery; 3336 3337},{"../index":35}],34:[function(require,module,exports){ 3338'use strict'; 3339 3340Object.defineProperty(exports, "__esModule", { 3341 value: true 3342}); 3343 3344var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 3345 3346var _aTemplate = require('a-template'); 3347 3348var _aTemplate2 = _interopRequireDefault(_aTemplate); 3349 3350require('custom-event-polyfill'); 3351 3352function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 3353 3354function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 3355 3356function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 3357 3358function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { c
3358onstructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 3359 3360var template = '<div class="\\{classNames.smartPhoto\\}"<!-- BEGIN hide:exist --> aria-hidden="true"<!-- END hide:exist --><!-- BEGIN hide:empty --> aria-hidden="false"<!-- END hide:empty --> role="dialog">\n\t<div class="\\{classNames.smartPhotoBody\\}">\n\t\t<div class="\\{classNames.smartPhotoInner\\}">\n\t\t\t <div class="\\{classNames.smartPhotoHeader\\}">\n\t\t\t\t\t<span class="\\{classNames.smartPhotoCount\\}">{currentIndex}[increment]/{total}</span>\n\t\t\t\t\t<span class="\\{classNames.smartPhotoCaption\\}" aria-live="polite" tabindex="-1"><!-- BEGIN groupItems:loop --><!-- \\BEGIN currentIndex:touch#{index} -->{caption}<!-- \\END currentIndex:touch#{index} --><!-- END groupItems:loop --></span>\n\t\t\t\t\t<button class="\\{classNames.smartPhotoDismiss\\}" data-action-click="hidePhoto()"><span class="smartphoto-sr-only">\\{message.closeDialog\\}</span></button>\n\t\t\t\t</div>\n\t\t\t\t<div class="\\{classNames.smartPhotoContent\\}"<!-- BEGIN isSmartPhone:exist --> data-action-touchstart="beforeDrag" data-action-touchmove="onDrag" data-action-touchend="afterDrag(false)"<!-- END isSmartPhone:exist --><!-- BEGIN isSmartPhone:empty --> <!-- END isSmartPhone:empty -->>\n\t\t\t\t</div>\n\t\t\t\t<ul style="transform:translate({translateX}px,{translateY}px);" class="\\{classNames.smartPhotoList\\}<!-- BEGIN onMoveClass:exist --> \\{classNames.smartPhotoListOnMove\\}<!-- END onMoveClass:exist -->">\n\t\t\t\t\t<!-- BEGIN groupItems:loop -->\n\t\t\t\t\t<li style="transform:translate({translateX}px,{translateY}px);" class="<!-- \\BEGIN currentIndex:touch#{index} -->current<!-- \\END currentIndex:touch#{index} -->">\n\t\t\t\t\t\t<!-- BEGIN processed:exist -->\n\t\t\t\t\t\t<div style="transform:translate({x}px,{y}px) scale({scale});" class="\\\\{classNames.smartPhotoImgWrap\\\\}"<!-- \\BEGIN isSmartPhone:empty --> data-action-mousemove="onDrag" data-action-mousedown="beforeDrag" data-action-mouseup="afterDrag"<!-- \\END isSmartPhone:empty --><!-- \\BEGIN isSmartPhone:exist --> data-action-touchstart="beforeDrag" data-action-touchmove="onDrag" data-action-touchend="afterDrag"<!-- \\END isSmartPhone:exist -->>\n\t\t\t\t\t\t\t<img style="<!-- \\BEGIN currentIndex:touch#{index} -->transform:translate(\\{photoPosX\\}[virtualPos]px,\\{photoPosY\\}[virtualPos]px) scale(\\{scaleSize\\});<!-- \\END currentIndex:touch#{index} -->width:{width}px;" src="{src}" class="\\\\{classNames.smartPhotoImg\\\\}<!-- \\BEGIN scale:exist --> \\\\{classNames.smartPhotoImgOnMove\\\\}<!-- \\END scale:exist --><!-- \\BEGIN elastic:exist --> \\\\{classNames.smartPhotoImgElasticMove\\\\}<!-- \\END elastic:exist --><!-- \\BEGIN appear:exist --> active<!-- \\END appear:exist -->" ondragstart="return false;">\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<!-- END processed:exist -->\n\t\t\t\t\t\t<!-- BEGIN processed:empty -->\n\t\t\t\t\t\t<div class="\\\\{classNames.smartPhotoLoaderWrap\\\\}">\n\t\t\t\t\t\t\t<span class="\\\\{classNames.smartPhotoLoader\\\\}"></span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<!-- END processed:empty -->\n\t\t\t\t\t</li>\n\t\t\t\t\t<!-- END groupItems:loop -->\n\t\t\t\t</ul>\n\t\t\t\t<!-- BEGIN arrows:exist -->\n\t\t\t\t<ul class="\\{classNames.smartPhotoArrows\\}"<!-- BEGIN hideUi:exist --> aria-hidden="true"<!-- END hideUi:exist --><!-- BEGIN hideUi:exist --> aria-hidden="false"<!-- END hideUi:exist -->>\n\t\t\t\t\t<li class="\\{classNames.smartPhotoArrowLeft\\}"<!-- BEGIN showPrevArrow:empty --> aria-hidden="true"<!-- END showPrevArrow:empty -->><a href="#" data-action-click="gotoSlide({prev})" role="button"><span class="smartphoto-sr-only">\\{message.gotoPrevImage\\}</span></a></li>\n\t\t\t\t\t<li class="\\{classNames.smartPhotoArrowRight\\}"<!-- BEGIN showNextArrow:empty --> aria-hidden="true"<!-- END showNextArrow:empty -->><a href="#" data-action-click="gotoSlide({next})" role="button"><span class="smartphoto-sr-only">\\{message.gotoNextImage\\}</span></a></li>\n\t\t\t\t</ul>\n\t\t\t\t<!-- END arrows:exist -->\n\t\t\t\t<!-- BEGIN nav:exist -->\n\t\t\t\t<nav class="\\{classNames.smartPhotoNav\\}"<!-- BEGIN hideUi:exist --> aria-hidden="true"<!-- END hideUi:exist --><!-- BEGIN hideUi:exist --> aria-hidden="false"<!-- END hideUi:exist -->>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<!-- BEGIN groupItems:loop -->\n\t\t\t\t\t\t<li><a href="#" data-action-click="gotoSlide({index})" class="<!-- \\BEGIN currentIndex:touch#{index} -->current<!-- \\END currentIndex:touch#{index} -->" style="background-image:url({src});" role="button"><span class="smartphoto-sr-only">go to {caption}</span></a></li>\n\t\t\t\t\t\t<!-- END groupItems:loop -->\n\t\t\t\t\t</ul>\n\t\t\t\t</nav>\n\t\t\t\t<!-- END nav:exist -->\n\t\t</div>\n\t\t<!-- BEGIN appearEffect:exist -->\n\t\t<img src=\\{appearEffect.img\\}\n\t\tclass="\\{classNames.smartPhotoImgClone\\}"\n\t\tstyle="width:\\{appearEffect.width\\}px;height:\\{appearEffect.height\\}px;transform:translate(\\{appearEffect.left\\}px,\\{appearEffect.top\\}px) scale(1)" />\n\t\t<!-- END appearEffect:exist -->\n\t</div>\n</div>\n'; 3361 3362 3363var util = require('../lib/util'); 3364var Promise = require('es6-promise-polyfill').Promise; 3365 3366var defaults = { 3367 classNames: { 3368 smartPhoto: 'smartphoto', 3369 smartPhotoClose: 'smartphoto-close', 3370 smartPhotoBody: 'smartphoto-body', 3371 smartPhotoInner: 'smartphoto-inner', 3372 smartPhotoContent: 'smartphoto-content', 3373 smartPhotoImg: 'smartphoto-img', 3374 smartPhotoImgOnMove: 'smartphoto-img-onmove', 3375 smartPhotoImgElasticMove: 'smartphoto-img-elasticmove', 3376 smartPhotoImgWrap: 'smartphoto-img-wrap', 3377 smartPhotoArrows: 'smartphoto-arrows', 3378 smartPhotoNav: 'smartphoto-nav', 3379 smartPhotoArrowRight: 'smartphoto-arrow-right', 3380 smartPhotoArrowLeft: 'smartphoto-arrow-left', 3381 smartPhotoImgLeft: 'smartphoto-img-left', 3382 smartPhotoImgRight: 'smartphoto-img-right', 3383 smartPhotoList: 'smartphoto-list', 3384 smartPhotoListOnMove: 'smartphoto-list-onmove',
3385 smartPhotoHeader: 'smartphoto-header', 3386 smartPhotoCount: 'smartphoto-count', 3387 smartPhotoCaption: 'smartphoto-caption', 3388 smartPhotoDismiss: 'smartphoto-dismiss', 3389 smartPhotoLoader: 'smartphoto-loader', 3390 smartPhotoLoaderWrap: 'smartphoto-loader-wrap', 3391 smartPhotoImgClone: 'smartphoto-img-clone' 3392 }, 3393 message: { 3394 gotoNextImage: 'go to the next image', 3395 gotoPrevImage: 'go to the previous image', 3396 closeDialog: 'close the image dialog' 3397 }, 3398 arrows: true, 3399 nav: false, 3400 showAnimation: true, 3401 verticalGravity: false, 3402 useOrientationApi: false, 3403 useHistoryApi: true, 3404 swipeTopToClose: false, 3405 swipeBottomToClose: true, 3406 swipeOffset: 100, 3407 headerHeight: 0, 3408 footerHeight: 0, 3409 forceInterval: 10, 3410 registance: 0.5, 3411 resizeStyle: 'fit' 3412}; 3413 3414var SmartPhoto = function (_ATemplate) { 3415 _inherits(SmartPhoto, _ATemplate); 3416 3417 function SmartPhoto(selector, settings) { 3418 _classCallCheck(this, SmartPhoto); 3419 3420 var _this = _possibleConstructorReturn(this, (SmartPhoto.__proto__ || Object.getPrototypeOf(SmartPhoto)).call(this)); 3421 3422 _this.data = util.extend({}, defaults, settings); 3423 _this.data.currentIndex = 0; 3424 _this.data.oldIndex = 0; 3425 _this.data.hide = true; 3426 _this.data.group = {}; 3427 _this.data.scaleSize = 1; 3428 _this.data.scale = false; 3429 _this.pos = { x: 0, y: 0 }; 3430 _this.data.photoPosX = 0; 3431 _this.data.photoPosY = 0; 3432 _this.convert = { 3433 increment: _this.increment, 3434 virtualPos: _this.virtualPos 3435 }; 3436 _this.data.groupItems = _this.groupItems; 3437 _this.elements = typeof selector === 'string' ? document.querySelectorAll(selector) : selector; 3438 var date = new Date(); 3439 _this.tapSecond = date.getTime(); 3440 _this.onListMove = false; 3441 _this.clicked = false; 3442 _this.id = _this._getUniqId(); 3443 _this.vx = 0; 3444 _this.vy = 0; 3445 _this.data.appearEffect = null; 3446 _this.addTemplate(_this.id, template); 3447 _this.data.isSmartPhone = _this._isSmartPhone(); 3448 var body = document.querySelector('body'); 3449 util.append(body, '<div data-id=\'' + _this.id + '\'></div>'); 3450 [].forEach.call(_this.elements, function (element) { 3451 _this.addNewItem(element); 3452 }); 3453 3454 _this.update(); 3455 _this._getEachImageSize().then(function () { 3456 _this._fireEvent('loadall'); 3457 var currentItem = _this._getCurrentItemByHash(); 3458 if (currentItem) { 3459 util.triggerEvent(currentItem.element, 'click'); 3460 } 3461 }); 3462 3463 setInterval(function () { 3464 _this._doAnim(); 3465 }, _this.data.forceInterval); 3466 3467 if (!_this.data.isSmartPhone) { 3468 window.addEventListener('resize', function () { 3469 if (!_this.groupItems()) { 3470 return; 3471 } 3472 _this._resetTranslate(); 3473 _this._setPosByCurrentIndex(); 3474 _this._setSizeByScreen(); 3475 _this.update(); 3476 }); 3477 3478 window.addEventListener('keydown', function (e) { 3479 var code = e.keyCode || e.which; 3480 if (_this.data.hide === true) { 3481 return; 3482 } 3483 if (code === 37) { 3484 _this.gotoSlide(_this.data.prev); 3485 } else if (code === 39) { 3486 _this.gotoSlide(_this.data.next); 3487 } else if (code === 27) { 3488 _this.hidePhoto(); 3489 } 3490 }); 3491 return _possibleConstructorReturn(_this); 3492 } 3493 3494 window.addEventListener('orientationchange', function () { 3495 if (!_this.groupItems()) { 3496 return; 3497 } 3498 _this._resetTranslate(); 3499 _this._setPosByCurrentIndex(); 3500 _this._setHashByCurrentIndex(); 3501 _this._setSizeByScreen(); 3502 _this.update(); 3503 }); 3504 3505 if (!_this.data.useOrientationApi) { 3506 return _possibleConstructorReturn(_this); 3507 } 3508 3509 window.addEventListener('deviceorientation', function (e) { 3510 var orientation = window.orientation; 3511 if (!e || !e.gamma || _this.data.appearEffect) { 3512 return; 3513 } 3514 if (!_this.isBeingZoomed && !_this.photoSwipable && !_this.data.elastic && _this.data.scale) { 3515 if (orientation === 0) { 3516 _this._calcGravity(e.gamma, e.beta); 3517 } else if (orientation === 90) { 3518 _this._calcGravity(e.beta, e.gamma); 3519 } else if (orientation === -90) { 3520 _this._calcGravity(-e.beta, -e.gamma); 3521 } else if (orientation === 180) { 3522 _this._calcGravity(-e.gamma, -e.beta); 3523 } 3524 } 3525 }); 3526 return _this; 3527 } 3528 3529 _createClass(SmartPhoto, [{ 3530 key: 'on', 3531 value: function on(event, fn) { 3532 var _this2 = this; 3533 3534 var photo = this._getElementByClass(this.data.classNames.smartPhoto); 3535 photo.addEventListener(event, function (e) { 3536 fn.call(_this2, e); 3537 }); 3538 } 3539 }, { 3540 key: 'increment', 3541 value: function increment(item) { 3542 return item + 1; 3543 } 3544 }, { 3545 key: 'virtualPos', 3546 value: function virtualPos(pos) { 3547 pos = parseInt(pos, 10); 3548 var item = this._getSelectedItem(); 3549 return pos / item.scale / this.data.scaleSize; 3550 } 3551 }, { 3552 key: 'groupItems', 3553 value: function groupItems() { 3554 return this.data.group[this.data.currentGroup]; 3555 } 3556 }, { 3557 key: '_getEachImageSize', 3558 value: function _getEachImageSize() { 3559 var arr = []; 3560 var group = this.data.group; 3561 var loadItems = function loadItems(item) { 3562 var promise = new Promise(function (resolve, reject) { 3563 var img = new Image(); 3564 img.onload = function () { 3565 item.width = img.width;
3566 item.height = img.height; 3567 item.loaded = true; 3568 resolve(); 3569 }; 3570 img.onerror = function () { 3571 reject(); 3572 }; 3573 img.src = item.src; 3574 }); 3575 arr.push(promise); 3576 }; 3577 Object.keys(group).forEach(function (key) { 3578 group[key].forEach(loadItems); 3579 }); 3580 return Promise.all(arr); 3581 } 3582 }, { 3583 key: '_resetTranslate', 3584 value: function _resetTranslate() { 3585 var _this3 = this; 3586 3587 var items = this.groupItems(); 3588 items.forEach(function (item, index) { 3589 item.translateX = _this3._getWindowWidth() * index; 3590 }); 3591 } 3592 }, { 3593 key: 'addNewItem', 3594 value: function addNewItem(element) { 3595 var _this4 = this; 3596 3597 var groupId = element.getAttribute('data-group') || 'nogroup'; 3598 var group = this.data.group; 3599 if (groupId === 'nogroup') { 3600 element.setAttribute('data-group', 'nogroup'); 3601 } 3602 if (!group[groupId]) { 3603 group[groupId] = []; 3604 } 3605 var index = group[groupId].length; 3606 var body = document.querySelector('body'); 3607 var item = { 3608 src: element.getAttribute('href'), 3609 caption: element.getAttribute('data-caption'), 3610 groupId: groupId, 3611 translateX: this._getWindowWidth() * index, 3612 index: index, 3613 translateY: 0, 3614 width: 50, 3615 height: 50, 3616 id: element.getAttribute('data-id') || index, 3617 loaded: false, 3618 processed: false, 3619 element: element 3620 }; 3621 group[groupId].push(item); 3622 this.data.currentGroup = groupId; 3623 var id = element.getAttribute('data-id'); 3624 if (!id) { 3625 element.setAttribute('data-id', index); 3626 } 3627 element.setAttribute('data-index', index); 3628 element.addEventListener('click', function (event) { 3629 event.preventDefault(); 3630 _this4.data.currentGroup = element.getAttribute('data-group'); 3631 _this4.data.currentIndex = parseInt(element.getAttribute('data-index'), 10); 3632 _this4._setHashByCurrentIndex(); 3633 var currentItem = _this4._getSelectedItem(); 3634 if (currentItem.loaded) { 3635 _this4._initPhoto(); 3636 _this4.addAppearEffect(element, currentItem); 3637 _this4.clicked = true; 3638 _this4.update(); 3639 body.style.overflow = 'hidden'; 3640 _this4._fireEvent('open'); 3641 } else { 3642 _this4._loadItem(currentItem).then(function () { 3643 _this4._initPhoto(); 3644 _this4.addAppearEffect(element, currentItem); 3645 _this4.clicked = true; 3646 _this4.update(); 3647 body.style.overflow = 'hidden'; 3648 _this4._fireEvent('open'); 3649 }); 3650 } 3651 }); 3652 } 3653 }, { 3654 key: '_initPhoto', 3655 value: function _initPhoto() { 3656 this.data.total = this.groupItems().length; 3657 this.data.hide = false;
3658 this.data.photoPosX = 0; 3659 this.data.photoPosY = 0; 3660 this._setPosByCurrentIndex(); 3661 this._setSizeByScreen(); 3662 this.setArrow(); 3663 if (this.data.resizeStyle === 'fill' && this.data.isSmartPhone) { 3664 this.data.scale = true; 3665 this.data.hideUi = true; 3666 this.data.scaleSize = this._getScaleBoarder(); 3667 } 3668 } 3669 }, { 3670 key: 'onUpdated', 3671 value: function onUpdated() { 3672 var _this5 = this; 3673 3674 if (this.data.appearEffect && this.data.appearEffect.once) { 3675 this.data.appearEffect.once = false; 3676 this.execEffect().then(function () { 3677 _this5.data.appearEffect = null; 3678 _this5.data.appear = true; 3679 _this5.update(); 3680 }); 3681 } 3682 if (this.clicked) { 3683 this.clicked = false; 3684 var classNames = this.data.classNames; 3685 var caption = this._getElementByClass(classNames.smartPhotoCaption); 3686 caption.focus(); 3687 } 3688 } 3689 }, { 3690 key: 'execEffect', 3691 value: function execEffect() { 3692 var _this6 = this; 3693 3694 return new Promise(function (resolve) { 3695 var appearEffect = _this6.data.appearEffect; 3696 var classNames = _this6.data.classNames; 3697 var effect = _this6._getElementByClass(classNames.smartPhotoImgClone); 3698 var handler = function handler() { 3699 effect.removeEventListener('transitionend', handler, true); 3700 resolve(); 3701 }; 3702 effect.addEventListener('transitionend', handler, true); 3703 setTimeout(function () { 3704 effect.style.transform = 'translate(' + appearEffect.afterX + 'px, ' + appearEffect.afterY + 'px) scale(' + appearEffect.scale + ')'; 3705 }, 10); 3706 }); 3707 } 3708 }, { 3709 key: 'addAppearEffect', 3710 value: function addAppearEffect(element, item) { 3711 if (this.data.showAnimation === false) { 3712 this.data.appear = true; 3713 return; 3714 } 3715 var img = element.querySelector('img'); 3716 var pos = util.getViewPos(img); 3717 var appear = {}; 3718 var scale = 1; 3719 appear.width = img.offsetWidth; 3720 appear.height = img.offsetHeight; 3721 appear.top = pos.top; 3722 appear.left = pos.left; 3723 appear.once = true; 3724 appear.img = img.getAttribute('src'); 3725 var toX = this._getWindowWidth(); 3726 var toY = this._getWindowHeight(); 3727 var screenY = toY - this.data.headerHeight - this.data.footerHeight; 3728 3729 if (this.data.resizeStyle === 'fill' && this.data.isSmartPhone) { 3730 if (img.offsetWidth > img.offsetHeight) { 3731 scale = toY / img.offsetHeight; 3732 } else { 3733 scale = toX / img.offsetWidth; 3734 } 3735 } else { 3736 if (appear.width > appear.height) { 3737 if (item.height < screenY) { 3738 scale = item.width / appear.width; 3739 } else { 3740 scale = screenY / appear.height; 3741 } 3742 } else if (appear.height > appear.width) { 3743 if (item.height < screenY) { 3744 scale = item.height / appear.height; 3745 } else { 3746 scale = screenY / appear.height; 3747 } 3748 } 3749 if (appear.width * scale > toX) { 3750 scale = toX / appear.width; 3751 } 3752 } 3753 3754 var x = (scale - 1) / 2 * img.offsetWidth + (toX - img.offsetWidth * scale) / 2; 3755 var y = (scale - 1) / 2 * img.offsetHeight + (toY - img.offsetHeight * scale) / 2; 3756 appear.afterX = x; 3757 appear.afterY = y; 3758 appear.scale = scale; 3759 this.data.appearEffect = appear; 3760 } 3761 }, { 3762 key: 'hidePhoto', 3763 value: function hidePhoto() { 3764 var _this7 = this; 3765 3766 var dir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottom'; 3767 3768 this.data.hide = true; 3769 this.data.appear = false; 3770 this.data.appearEffect = null; 3771 this.data.hideUi = false; 3772 this.data.scale = false; 3773 this.data.scaleSize = 1; 3774 var scrollX = window.scrollX; 3775 var scrollY = window.scrollY; 3776 var body = document.querySelector('body'); 3777 if (location.hash) { 3778 this._setHash(''); 3779 } 3780 window.scroll(scrollX, scrollY); 3781 this._doHideEffect(dir).then(function () { 3782 _this7.update(); 3783 body.style.overflow = ''; 3784 _this7._fireEvent('close'); 3785 }); 3786 } 3787 }, { 3788 key: '_doHideEffect', 3789 value: function _doHideEffect(dir) { 3790 var _this8 = this; 3791 3792 return new Promise(function (resolve) { 3793 var classNames = _this8.data.classNames; 3794 var photo = _this8._getElementByClass(classNames.smartPhoto); 3795 var img = _this8._getElementByQuery('.current .' + classNames.smartPhotoImg); 3796 var height = _this8._getWindowHeight(); 3797 var handler = function handler() { 3798 photo.removeEventListener('transitionend', handler, true); 3799 resolve(); 3800 }; 3801 photo.style.opacity = 0; 3802 if (dir === 'bottom') { 3803 img.style.transform = 'translateY(' + height + 'px)'; 3804 } else if (dir === 'top') { 3805 img.style.transform = 'translateY(-' + height + 'px)'; 3806 } 3807 photo.addEventListener('transitionend', handler, true); 3808 }); 3809 } 3810 }, { 3811 key: '_getElementByClass', 3812 value: function _getElementByClass(className) { 3813 return document.querySelector('[data-id="' + this.id + '"] .' + className); 3814 } 3815 }, { 3816 key: '_getElementByQuery', 3817 value: function _getElementByQuery(query) { 3818 return document.querySelector('[data-id="' + this.id + '"] ' + query); 3819 } 3820 }, { 3821 key: '_getTouchPos', 3822 value: function _getTouchPos() { 3823 var x = 0; 3824 var y = 0; 3825 var e = typeof event === 'undefined' ? this.e : event; 3826 if (this._isTouched(e)) { 3827 x = e.touches[0].pageX; 3828 y = e.touches[0].pageY; 3829 } else if (e.pageX) { 3830 x = e.pageX; 3831 y = e.pageY; 3832 } 3833 return { x: x, y: y }; 3834 } 3835 }, { 3836 key: '_getGesturePos', 3837 value: function _getGesturePos(e) { 3838 var touches = e.touches; 3839 return [{ x: touches[0].pageX, y: touches[0].pageY }, { x: touches[1].pageX, y: touches[1].pageY }]; 3840 } 3841 }, { 3842 key: '_setPosByCurrentIndex', 3843 value: function _setPosByCurrentIndex() { 3844 var _this9 = this; 3845 3846 var items = this.groupItems(); 3847 var moveX = -1 * items[this.data.currentIndex].translateX; 3848 this.pos.x = moveX; 3849 setTimeout(function () { 3850 _this9.data.translateX = moveX; 3851 _this9.data.translateY = 0; 3852 _this9._listUpdate(); 3853 }, 1); 3854 } 3855 }, { 3856 key: '_setHashByCurrentIndex', 3857 value: function _setHashByCurrentIndex() { 3858 var scrollX = window.scrollX; 3859 var scrollY = window.scrollY; 3860 var items = this.groupItems(); 3861 var id = items[this.data.currentIndex].id; 3862 var group = this.data.currentGroup; 3863 var hash = 'group=' + group + '&photo=' + id; 3864 this._setHash(hash); 3865 window.scroll(scrollX, scrollY); 3866 } 3867 }, { 3868 key: '_setHash', 3869 value: function _setHash(hash) { 3870 if (!(window.history && window.history.pushState) || !this.data.useHistoryApi) { 3871 return; 3872 } 3873 if (hash) { 3874 window.history.replaceState(null, null, '' + location.pathname + location.search + '#' + hash); 3875 } else { 3876 window.history.replaceState(null, null, '' + location.pathname + location.search); 3877 } 3878 } 3879 }, { 3880 key: '_getCurrentItemByHash', 3881 value: function _getCurrentItemByHash() { 3882 var group = this.data.group; 3883 var hash = location.hash.substr(1); 3884 var hashObj = util.parseQuery(hash); 3885 var currentItem = null; 3886 var getCurrentItem = function getCurrentItem(item) { 3887 if (hashObj.group === item.groupId && hashObj.photo === item.id) { 3888 currentItem = item; 3889 } 3890 };
3891 Object.keys(group).forEach(function (key) { 3892 group[key].forEach(getCurrentItem); 3893 }); 3894 return currentItem; 3895 } 3896 }, { 3897 key: '_loadItem', 3898 value: function _loadItem(item) { 3899 return new Promise(function (resolve) { 3900 var img = new Image(); 3901 img.onload = function () { 3902 item.width = img.width; 3903 item.height = img.height; 3904 item.loaded = true; 3905 resolve(); 3906 }; 3907 img.onerror = function () { 3908 resolve(); 3909 }; 3910 img.src = item.src; 3911 }); 3912 } 3913 }, { 3914 key: '_setSizeByScreen', 3915 value: function _setSizeByScreen() { 3916 var windowX = this._getWindowWidth(); 3917 var windowY = this._getWindowHeight(); 3918 var headerHeight = this.data.headerHeight; 3919 var footerHeight = this.data.footerHeight; 3920 var screenY = windowY - (headerHeight + footerHeight); 3921 var items = this.groupItems(); 3922 items.forEach(function (item) { 3923 if (!item.loaded) { 3924 return; 3925 } 3926 item.processed = true; 3927 item.scale = screenY / item.height; 3928 if (item.height < screenY) { 3929 item.scale = 1; 3930 } 3931 item.x = (item.scale - 1) / 2 * item.width + (windowX - item.width * item.scale) / 2; 3932 item.y = (item.scale - 1) / 2 * item.height + (windowY - item.height * item.scale) / 2; 3933 if (item.width * item.scale > windowX) { 3934 item.scale = windowX / item.width; 3935 item.x = (item.scale - 1) / 2 * item.width; 3936 } 3937 }); 3938 } 3939 }, { 3940 key: '_slideList', 3941 value: function _slideList() { 3942 var _this10 = this; 3943 3944 this.data.scaleSize = 1; 3945 this.isBeingZoomed = false; 3946 this.data.hideUi = false; 3947 this.data.scale = false; 3948 this.data.photoPosX = 0; 3949 this.data.photoPosY = 0; 3950 this.data.onMoveClass = true; 3951 this._setPosByCurrentIndex(); 3952 this._setHashByCurrentIndex(); 3953 this._setSizeByScreen(); 3954 setTimeout(function () { 3955 _this10.data.onMoveClass = false; 3956 _this10.setArrow(); 3957 _this10.update(); 3958 if (_this10.data.oldIndex !== _this10.data.currentIndex) { 3959 _this10._fireEvent('change'); 3960 } 3961 _this10.data.oldIndex = _this10.data.currentIndex; 3962 }, 200); 3963 } 3964 }, { 3965 key: 'gotoSlide',
3966 value: function gotoSlide(index) { 3967 if (this.e && this.e.preventDefault) { 3968 this.e.preventDefault(); 3969 } 3970 this.data.currentIndex = parseInt(index, 10); 3971 if (!this.data.currentIndex) { 3972 this.data.currentIndex = 0; 3973 } 3974 this._slideList(); 3975 } 3976 }, { 3977 key: 'setArrow', 3978 value: function setArrow() { 3979 var items = this.groupItems(); 3980 var length = items.length; 3981 var next = this.data.currentIndex + 1; 3982 var prev = this.data.currentIndex - 1; 3983 this.data.showNextArrow = false; 3984 this.data.showPrevArrow = false; 3985 if (next !== length) { 3986 this.data.next = next; 3987 this.data.showNextArrow = true; 3988 } 3989 if (prev !== -1) { 3990 this.data.prev = prev; 3991 this.data.showPrevArrow = true; 3992 } 3993 } 3994 }, { 3995 key: 'beforeDrag', 3996 value: function beforeDrag() { 3997 if (this._isGestured(this.e)) { 3998 this.beforeGesture(); 3999 return; 4000 } 4001 this.isBeingZoomed = false; 4002 if (this.data.scale) { 4003 this.beforePhotoDrag(); 4004 return; 4005 } 4006 var pos = this._getTouchPos(); 4007 this.isSwipable = true; 4008 this.dragStart = true; 4009 this.firstPos = pos; 4010 this.oldPos = pos; 4011 } 4012 }, { 4013 key: 'afterDrag', 4014 value: function afterDrag() { 4015 var items = this.groupItems(); 4016 var date = new Date(); 4017 var tapSecond = date.getTime(); 4018 var offset = this.tapSecond - tapSecond; 4019 var swipeWidth = 0; 4020 var swipeHeight = 0; 4021 this.isSwipable = false; 4022 this.onListMove = false; 4023 4024 if (this.oldPos) { 4025 swipeWidth = this.oldPos.x - this.firstPos.x; 4026 swipeHeight = this.oldPos.y - this.firstPos.y; 4027 } 4028 if (this.isBeingZoomed) { 4029 this.afterGesture(); 4030 return; 4031 } 4032 if (this.data.scale) { 4033 this.afterPhotoDrag(); 4034 return; 4035 } else if (!util.isSmartPhone() && swipeWidth === 0 && swipeHeight === 0) { 4036 this.zoomPhoto(); 4037 return; 4038 } 4039 if (Math.abs(offset) <= 500 && swipeWidth === 0 && swipeHeight === 0) { 4040 this.e.preventDefault(); 4041 this.zoomPhoto(); 4042 return; 4043 } 4044 this.tapSecond = tapSecond; 4045 this._fireEvent('swipeend'); 4046 if (this.moveDir === 'horizontal') { 4047 if (swipeWidth >= this.data.swipeOffset && this.data.currentIndex !== 0) { 4048 this.data.currentIndex -= 1; 4049 } else if (swipeWidth <= -this.data.swipeOffset && this.data.currentIndex !== items.length - 1) { 4050 this.data.currentIndex += 1; 4051 } 4052 this._slideList(); 4053 } 4054 if (this.moveDir === 'vertical') { 4055 if (this.data.swipeBottomToClose && swipeHeight >= this.data.swipeOffset) { 4056 this.hidePhoto('bottom'); 4057 } else if (this.data.swipeTopToClose && swipeHeight <= -this.data.swipeOffset) { 4058 this.hidePhoto('top'); 4059 } else { 4060 this.data.translateY = 0; 4061 this._slideList(); 4062 } 4063 } 4064 } 4065 }, { 4066 key: 'onDrag', 4067 value: function onDrag() { 4068 this.e.preventDefault(); 4069 if (this._isGestured(this.e) && this.onListMove === false) { 4070 this.onGesture(); 4071 return; 4072 } 4073 if (this.isBeingZoomed) { 4074 return; 4075 } 4076 if (this.data.scale) { 4077 this.onPhotoDrag(); 4078 return; 4079 } 4080 if (!this.isSwipable) { 4081 return; 4082 } 4083 4084 var pos = this._getTouchPos(); 4085 var x = pos.x - this.oldPos.x; 4086 var y = pos.y - this.firstPos.y; 4087 4088 if (this.dragStart) { 4089 this._fireEvent('swipestart'); 4090 this.dragStart = false;
4091 if (Math.abs(x) > Math.abs(y)) { 4092 this.moveDir = 'horizontal'; 4093 } else { 4094 this.moveDir = 'vertical'; 4095 } 4096 } 4097 4098 if (this.moveDir === 'horizontal') { 4099 this.pos.x += x; 4100 this.data.translateX = this.pos.x; 4101 } else { 4102 this.data.translateY = y; 4103 } 4104 this.onListMove = true; 4105 this.oldPos = pos; 4106 this._listUpdate(); 4107 } 4108 }, { 4109 key: 'zoomPhoto', 4110 value: function zoomPhoto() { 4111 var _this11 = this; 4112 4113 this.data.hideUi = true; 4114 this.data.scaleSize = this._getScaleBoarder(); 4115 if (this.data.scaleSize <= 1) { 4116 return; 4117 } 4118 this.data.photoPosX = 0; 4119 this.data.photoPosY = 0; 4120 this._photoUpdate(); 4121 setTimeout(function () { 4122 _this11.data.scale = true; 4123 _this11._photoUpdate(); 4124 _this11._fireEvent('zoomin'); 4125 }, 300); 4126 } 4127 }, { 4128 key: 'zoomOutPhoto', 4129 value: function zoomOutPhoto() { 4130 this.data.scaleSize = 1; 4131 this.isBeingZoomed = false; 4132 this.data.hideUi = false; 4133 this.data.scale = false; 4134 this.data.photoPosX = 0; 4135 this.data.photoPosY = 0; 4136 this._photoUpdate(); 4137 this._fireEvent('zoomout'); 4138 } 4139 }, { 4140 key: 'beforePhotoDrag', 4141 value: function beforePhotoDrag() { 4142 var pos = this._getTouchPos(); 4143 this.photoSwipable = true; 4144 if (!this.data.photoPosX) { 4145 this.data.photoPosX = 0; 4146 } 4147 if (!this.data.photoPosY) { 4148 this.data.photoPosY = 0; 4149 } 4150 this.oldPhotoPos = pos; 4151 this.firstPhotoPos = pos; 4152 } 4153 }, { 4154 key: 'onPhotoDrag', 4155 value: function onPhotoDrag() { 4156 if (!this.photoSwipable) { 4157 return; 4158 } 4159 this.e.preventDefault(); 4160 var pos = this._getTouchPos(); 4161 var x = pos.x - this.oldPhotoPos.x; 4162 var y = pos.y - this.oldPhotoPos.y; 4163 var moveX = this._round(this.data.scaleSize * x, 6); 4164 var moveY = this._round(this.data.scaleSize * y, 6); 4165 if (typeof moveX === 'number') { 4166 this.data.photoPosX += moveX; 4167 this.photoVX = moveX; 4168 } 4169 if (typeof moveY === 'number') { 4170 this.data.photoPosY += moveY; 4171 this.photoVY = moveY; 4172 } 4173 this.oldPhotoPos = pos; 4174 this._photoUpdate(); 4175 } 4176 }, { 4177 key: 'afterPhotoDrag', 4178 value: function afterPhotoDrag() { 4179 if (this.oldPhotoPos.x === this.firstPhotoPos.x && this.photoSwipable) { 4180 this.photoSwipable = false; 4181 this.zoomOutPhoto(); 4182 } else { 4183 this.photoSwipable = false; 4184 var item = this._getSelectedItem(); 4185 var bound = this._makeBound(item); 4186 var offset = this.data.swipeOffset * this.data.scaleSize; 4187 var flagX = 0; 4188 var flagY = 0; 4189 if (this.data.photoPosX > bound.maxX) { 4190 flagX = -1; 4191 } else if (this.data.photoPosX < bound.minX) { 4192 flagX = 1; 4193 } 4194 if (this.data.photoPosY > bound.maxY) { 4195 flagY = -1; 4196 } else if (this.data.photoPosY < bound.minY) { 4197 flagY = 1; 4198 } 4199 4200 if (this.data.photoPosX - bound.maxX > offset && this.data.currentIndex !== 0) { 4201 this.gotoSlide(this.data.prev); 4202 return; 4203 } 4204 4205 if (bound.minX - this.data.photoPosX > offset && this.data.currentIndex + 1 !== this.data.total) { 4206 this.gotoSlide(this.data.next); 4207 return; 4208 } 4209 4210 // todo 4211 // if(this.data.photoPosY - bound.maxY > offset) { 4212 // this.hidePhoto(); 4213 // return; 4214 // } 4215 4216 if (flagX === 0 && flagY === 0) { 4217 this.vx = this.photoVX / 5; 4218 this.vy = this.photoVY / 5; 4219 } else { 4220 this._registerElasticForce(flagX, flagY); 4221 } 4222 } 4223 } 4224 }, { 4225 key: 'beforeGesture', 4226 value: function beforeGesture() { 4227 this._fireEvent('gesturestart'); 4228 var pos = this._getGesturePos(this.e); 4229 var distance = this._getDistance(pos[0], pos[1]); 4230 this.isBeingZoomed = true; 4231 this.oldDistance = distance; 4232 this.data.scale = true; 4233 this.e.preventDefault(); 4234 } 4235 }, { 4236 key: 'onGesture', 4237 value: function onGesture() { 4238 var pos = this._getGesturePos(this.e); 4239 var distance = this._getDistance(pos[0], pos[1]); 4240 var size = (distance - this.oldDistance) / 100; 4241 var oldScaleSize = this.data.scaleSize; 4242 var posX = this.data.photoPosX; 4243 var posY = this.data.photoPosY; 4244 this.isBeingZoomed = true; 4245 this.data.scaleSize += this._round(size, 6); 4246 if (this.data.scaleSize < 0.2) { 4247 this.data.scaleSize = 0.2; 4248 } 4249 // todo 4250 if (this.data.scaleSize < oldScaleSize) { 4251 this.data.photoPosX = (1 + this.data.scaleSize - oldScaleSize) * posX; 4252 this.data.photoPosY = (1 + this.data.scaleSize - oldScaleSize) * posY; 4253 } 4254 4255 if (this.data.scaleSize < 1 || this.data.scaleSize > this._getScaleBoarder()) { 4256 this.data.hideUi = true; 4257 } else { 4258 this.data.hideUi = false;
4259 } 4260 this.oldDistance = distance; 4261 this.e.preventDefault(); 4262 this._photoUpdate(); 4263 } 4264 }, { 4265 key: 'afterGesture', 4266 value: function afterGesture() { 4267 if (this.data.scaleSize > this._getScaleBoarder()) { 4268 return; 4269 } 4270 this.data.photoPosX = 0; 4271 this.data.photoPosY = 0; 4272 this.data.scale = false; 4273 this.data.scaleSize = 1; 4274 this.data.hideUi = false; 4275 this._fireEvent('gestureend'); 4276 this._photoUpdate(); 4277 } 4278 }, { 4279 key: '_getForceAndTheta', 4280 value: function _getForceAndTheta(vx, vy) { 4281 return { 4282 force: Math.sqrt(vx * vx + vy * vy), 4283 theta: Math.atan2(vy, vx) 4284 }; 4285 } 4286 }, { 4287 key: '_getScaleBoarder', 4288 value: function _getScaleBoarder() { 4289 var item = this._getSelectedItem(); 4290 var windowWidth = this._getWindowWidth(); 4291 var windowHeight = this._getWindowHeight(); 4292 if (!util.isSmartPhone()) { 4293 return 1 / item.scale; 4294 } 4295 if (item.width > item.height) { 4296 return windowHeight / (item.height * item.scale); 4297 } 4298 return windowWidth / (item.width * item.scale); 4299 } 4300 }, { 4301 key: '_makeBound', 4302 value: function _makeBound(item) { 4303 var width = item.width * item.scale * this.data.scaleSize; 4304 var height = item.height * item.scale * this.data.scaleSize; 4305 var minX = void 0; 4306 var minY = void 0; 4307 var maxX = void 0; 4308 var maxY = void 0; 4309 var windowWidth = this._getWindowWidth(); 4310 var windowHeight = this._getWindowHeight(); 4311 if (windowWidth > width) { 4312 maxX = (windowWidth - width) / 2; 4313 minX = -1 * maxX; 4314 } else { 4315 maxX = (width - windowWidth) / 2; 4316 minX = -1 * maxX; 4317 } 4318 if (windowHeight > height) { 4319 maxY = (windowHeight - height) / 2; 4320 minY = -1 * maxY; 4321 } else { 4322 maxY = (height - windowHeight) / 2; 4323 minY = -1 * maxY; 4324 } 4325 return { 4326 minX: this._round(minX, 6) * this.data.scaleSize, 4327 minY: this._round(minY, 6) * this.data.scaleSize, 4328 maxX: this._round(maxX, 6) * this.data.scaleSize, 4329 maxY: this._round(maxY, 6) * this.data.scaleSize 4330 }; 4331 } 4332 }, { 4333 key: '_registerElasticForce', 4334 value: function _registerElasticForce(x, y) { 4335 var _this12 = this; 4336 4337 var item = this._getSelectedItem(); 4338 var bound = this._makeBound(item); 4339 this.data.elastic = true; 4340 if (x === 1) { 4341 this.data.photoPosX = bound.minX; 4342 } else if (x === -1) { 4343 this.data.photoPosX = bound.maxX; 4344 } 4345 if (y === 1) { 4346 this.data.photoPosY = bound.minY; 4347 } else if (y === -1) { 4348 this.data.photoPosY = bound.maxY; 4349 } 4350 this._photoUpdate(); 4351 setTimeout(function () { 4352 _this12.data.elastic = false; 4353 _this12._photoUpdate(); 4354 }, 300); 4355 } 4356 }, { 4357 key: '_getSelectedItem', 4358 value: function _getSelectedItem() { 4359 var data = this.data; 4360 var index = data.currentIndex; 4361 return data.group[data.currentGroup][index]; 4362 } 4363 }, { 4364 key: '_getUniqId', 4365 value: function _getUniqId() { 4366 return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase(); 4367 } 4368 }, { 4369 key: '_getDistance', 4370 value: function _getDistance(point1, point2) { 4371 var x = point1.x - point2.x; 4372 var y = point1.y - point2.y; 4373 return Math.sqrt(x * x + y * y); 4374 } 4375 }, { 4376 key: '_round', 4377 value: function _round(val, precision) { 4378 var digit = Math.pow(10, precision); 4379 val *= digit; 4380 val = Math.round(val); 4381 val /= digit; 4382 return val; 4383 } 4384 }, { 4385 key: '_isTouched', 4386 value: function _isTouched(e) { 4387 if (e && e.touches) { 4388 return true; 4389 } 4390 return false; 4391 } 4392 }, { 4393 key: '_isGestured', 4394 value: function _isGestured(e) { 4395 if (e && e.touches && e.touches.length > 1) { 4396 return true; 4397 } 4398 return false; 4399 } 4400 }, { 4401 key: '_isSmartPhone', 4402 value: function _isSmartPhone() { 4403 var agent = navigator.userAgent; 4404 if (agent.indexOf('iPhone') > 0 || agent.indexOf('iPad') > 0 || agent.indexOf('ipod') > 0 || agent.indexOf('Android') > 0) { 4405 return true; 4406 } 4407 return false;
4408 } 4409 }, { 4410 key: '_calcGravity', 4411 value: function _calcGravity(gamma, beta) { 4412 if (gamma > 5 || gamma < -5) { 4413 this.vx += gamma * 0.05; 4414 } 4415 if (this.data.verticalGravity === false) { 4416 return; 4417 } 4418 if (beta > 5 || beta < -5) { 4419 this.vy += beta * 0.05; 4420 } 4421 } 4422 }, { 4423 key: '_photoUpdate', 4424 value: function _photoUpdate() { 4425 var classNames = this.data.classNames; 4426 var current = this._getElementByQuery('.current'); 4427 var img = current.querySelector('.' + classNames.smartPhotoImg); 4428 var nav = this._getElementByQuery('.' + classNames.smartPhotoNav); 4429 var arrows = this._getElementByQuery('.' + classNames.smartPhotoArrows); 4430 var photoPosX = this.virtualPos(this.data.photoPosX); 4431 var photoPosY = this.virtualPos(this.data.photoPosY); 4432 var scaleSize = this.data.scaleSize; 4433 var transform = 'translate(' + photoPosX + 'px,' + photoPosY + 'px) scale(' + scaleSize + ')'; 4434 4435 img.style.transform = transform; 4436 if (this.data.scale) { 4437 util.addClass(img, classNames.smartPhotoImgOnMove); 4438 } else { 4439 util.removeClass(img, classNames.smartPhotoImgOnMove); 4440 } 4441 if (this.data.elastic) { 4442 util.addClass(img, classNames.smartPhotoImgElasticMove); 4443 } else { 4444 util.removeClass(img, classNames.smartPhotoImgElasticMove); 4445 } 4446 if (this.data.hideUi) { 4447 if (nav) { 4448 nav.setAttribute('aria-hidden', 'true'); 4449 } 4450 if (arrows) { 4451 arrows.setAttribute('aria-hidden', 'true'); 4452 } 4453 } else { 4454 if (nav) { 4455 nav.setAttribute('aria-hidden', 'false'); 4456 } 4457 if (arrows) { 4458 arrows.setAttribute('aria-hidden', 'false'); 4459 } 4460 } 4461 } 4462 }, { 4463 key: '_getWindowWidth', 4464 value: function _getWindowWidth() { 4465 if (document && document.documentElement) { 4466 return document.documentElement.clientWidth; 4467 } else if (window && window.innerWidth) { 4468 return window.innerWidth; 4469 } 4470 return 0; 4471 } 4472 }, { 4473 key: '_getWindowHeight', 4474 value: function _getWindowHeight() { 4475 if (document && document.documentElement) { 4476 return document.documentElement.clientHeight; 4477 } else if (window && window.innerHeight) { 4478 return window.innerHeight; 4479 } 4480 return 0; 4481 } 4482 }, { 4483 key: '_listUpdate', 4484 value: function _listUpdate() { 4485 var classNames = this.data.classNames; 4486 var list = this._getElementByQuery('.' + classNames.smartPhotoList); 4487 var transform = 'translate(' + this.data.translateX + 'px,' + this.data.translateY + 'px)'; 4488 list.style.transform = transform; 4489 // $list 4490 if (this.data.onMoveClass) { 4491 util.addClass(list, classNames.smartPhotoListOnMove); 4492 } else { 4493 util.removeClass(list, classNames.smartPhotoListOnMove); 4494 } 4495 } 4496 }, { 4497 key: '_fireEvent', 4498 value: function _fireEvent(eventName) { 4499 var photo = this._getElementByClass(this.data.classNames.smartPhoto); 4500 util.triggerEvent(photo, eventName); 4501 } 4502 }, { 4503 key: '_doAnim', 4504 value: function _doAnim() { 4505 if (this.isBeingZoomed || this.isSwipable || this.photoSwipable || this.data.elastic || !this.data.scale) { 4506 return; 4507 } 4508 this.data.photoPosX += this.vx; 4509 this.data.photoPosY += this.vy; 4510 var item = this._getSelectedItem(); 4511 var bound = this._makeBound(item); 4512 if (this.data.photoPosX < bound.minX) { 4513 this.data.photoPosX = bound.minX; 4514 this.vx *= -0.2; 4515 } else if (this.data.photoPosX > bound.maxX) { 4516 this.data.photoPosX = bound.maxX; 4517 this.vx *= -0.2; 4518 } 4519 if (this.data.photoPosY < bound.minY) { 4520 this.data.photoPosY = bound.minY; 4521 this.vy *= -0.2; 4522 } else if (this.data.photoPosY > bound.maxY) { 4523 this.data.photoPosY = bound.maxY; 4524 this.vy *= -0.2; 4525 } 4526 var power = this._getForceAndTheta(this.vx, this.vy); 4527 var force = power.force; 4528 var theta = power.theta; 4529 force -= this.data.registance; 4530 if (Math.abs(force) < 0.5) { 4531 return; 4532 } 4533 this.vx = Math.cos(theta) * force; 4534 this.vy = Math.sin(theta) * force; 4535 this._photoUpdate(); 4536 } 4537 }]); 4538 4539 return SmartPhoto; 4540}(_aTemplate2.default); 4541 4542exports.default = SmartPhoto; 4543module.exports = exports['default']; 4544 4545},{"../lib/util":36,"a-template":1,"custom-event-polyfill":7,"es6-promise-polyfill":21}],35:[function(require,module,exports){ 4546'use strict'; 4547 4548module.exports = require('./core/'); 4549 4550},{"./core/":34}],36:[function(require,module,exports){ 4551'use strict'; 4552 4553var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 4554 4555module.exports.isSmartPhone = function () { 4556 var agent = navigator.userAgent; 4557 if (agent.indexOf('iPhone') > 0 || agent.indexOf('iPad') > 0 || agent.indexOf('ipod') > 0 || agent.indexOf('Android') > 0) { 4558 return true; 4559 } else { 4560 return false;
4561 } 4562}; 4563 4564function deepExtend(out) { 4565 out = out || {}; 4566 4567 for (var i = 1; i < arguments.length; i++) { 4568 var obj = arguments[i]; 4569 if (!obj) { 4570 continue; 4571 } 4572 4573 for (var key in obj) { 4574 if (obj.hasOwnProperty(key)) { 4575 if (_typeof(obj[key]) === 'object') out[key] = deepExtend(out[key], obj[key]);else out[key] = obj[key]; 4576 } 4577 } 4578 } 4579 4580 return out; 4581}; 4582 4583module.exports.extend = deepExtend; 4584 4585module.exports.triggerEvent = function (el, eventName, options) { 4586 var event = void 0; 4587 if (window.CustomEvent) { 4588 event = new CustomEvent(eventName, { cancelable: true }); 4589 } else { 4590 event = document.createEvent('CustomEvent'); 4591 event.initCustomEvent(eventName, false, false, options); 4592 } 4593 el.dispatchEvent(event); 4594}; 4595 4596module.exports.parseQuery = function (query) { 4597 var s = query.split('&'), 4598 data = {}, 4599 i = 0, 4600 iz = s.length, 4601 param, 4602 key, 4603 value; 4604 for (; i < iz; i++) { 4605 param = s[i].split('='); 4606 if (param[0] !== void 0) { 4607 key = param[0]; 4608 value = param[1] !== void 0 ? param.slice(1).join('=') : key; 4609 data[key] = decodeURIComponent(value); 4610 } 4611 } 4612 return data; 4613}; 4614 4615module.exports.getViewPos = function (element) { 4616 return { 4617 left: element.getBoundingClientRect().left, 4618 top: element.getBoundingClientRect().top 4619 }; 4620}; 4621 4622module.exports.removeElement = function (element) { 4623 if (element && element.parentNode) { 4624 element.parentNode.removeChild(element); 4625 } 4626}; 4627 4628module.exports.append = function (element, string) { 4629 var parser = new DOMParser(); 4630 var doc = parser.parseFromString(string, 'text/html'); 4631 element.appendChild(doc.querySelector('body').childNodes[0]); 4632}; 4633 4634module.exports.addClass = function (element, className) { 4635 if (element.classList) { 4636 element.classList.add(className); 4637 } else { 4638 element.className += ' ' + className; 4639 } 4640}; 4641 4642module.exports.removeClass = function (element, className) { 4643 if (element.classList) { 4644 element.classList.remove(className); 4645 } else { 4646 element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); 4647 } 4648}; 4649 4650},{}]},{},[33]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.