| 1 |
/* assets/wpuf/vendor/vue/vue.js */ |
| 2 |
/*! |
| 3 |
* Vue.js v2.2.4 |
| 4 |
* (c) 2014-2017 Evan You |
| 5 |
* Released under the MIT License. |
| 6 |
*/ |
| 7 |
(function (global, factory) { |
| 8 |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 9 |
typeof define === 'function' && define.amd ? define(factory) : |
| 10 |
(global.Vue = factory()); |
| 11 |
}(this, (function () { 'use strict'; |
| 12 |
|
| 13 |
/* */ |
| 14 |
|
| 15 |
/** |
| 16 |
* Convert a value to a string that is actually rendered. |
| 17 |
*/ |
| 18 |
function _toString (val) { |
| 19 |
return val == null |
| 20 |
? '' |
| 21 |
: typeof val === 'object' |
| 22 |
? JSON.stringify(val, null, 2) |
| 23 |
: String(val) |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Convert a input value to a number for persistence. |
| 28 |
* If the conversion fails, return original string. |
| 29 |
*/ |
| 30 |
function toNumber (val) { |
| 31 |
var n = parseFloat(val); |
| 32 |
return isNaN(n) ? val : n |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Make a map and return a function for checking if a key |
| 37 |
* is in that map. |
| 38 |
*/ |
| 39 |
function makeMap ( |
| 40 |
str, |
| 41 |
expectsLowerCase |
| 42 |
) { |
| 43 |
var map = Object.create(null); |
| 44 |
var list = str.split(','); |
| 45 |
for (var i = 0; i < list.length; i++) { |
| 46 |
map[list[i]] = true; |
| 47 |
} |
| 48 |
return expectsLowerCase |
| 49 |
? function (val) { return map[val.toLowerCase()]; } |
| 50 |
: function (val) { return map[val]; } |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Check if a tag is a built-in tag. |
| 55 |
*/ |
| 56 |
var isBuiltInTag = makeMap('slot,component', true); |
| 57 |
|
| 58 |
/** |
| 59 |
* Remove an item from an array |
| 60 |
*/ |
| 61 |
function remove (arr, item) { |
| 62 |
if (arr.length) { |
| 63 |
var index = arr.indexOf(item); |
| 64 |
if (index > -1) { |
| 65 |
return arr.splice(index, 1) |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Check whether the object has the property. |
| 72 |
*/ |
| 73 |
var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 74 |
function hasOwn (obj, key) { |
| 75 |
return hasOwnProperty.call(obj, key) |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Check if value is primitive |
| 80 |
*/ |
| 81 |
function isPrimitive (value) { |
| 82 |
return typeof value === 'string' || typeof value === 'number' |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Create a cached version of a pure function. |
| 87 |
*/ |
| 88 |
function cached (fn) { |
| 89 |
var cache = Object.create(null); |
| 90 |
return (function cachedFn (str) { |
| 91 |
var hit = cache[str]; |
| 92 |
return hit || (cache[str] = fn(str)) |
| 93 |
}) |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Camelize a hyphen-delimited string. |
| 98 |
*/ |
| 99 |
var camelizeRE = /-(\w)/g; |
| 100 |
var camelize = cached(function (str) { |
| 101 |
return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; }) |
| 102 |
}); |
| 103 |
|
| 104 |
/** |
| 105 |
* Capitalize a string. |
| 106 |
*/ |
| 107 |
var capitalize = cached(function (str) { |
| 108 |
return str.charAt(0).toUpperCase() + str.slice(1) |
| 109 |
}); |
| 110 |
|
| 111 |
/** |
| 112 |
* Hyphenate a camelCase string. |
| 113 |
*/ |
| 114 |
var hyphenateRE = /([^-])([A-Z])/g; |
| 115 |
var hyphenate = cached(function (str) { |
| 116 |
return str |
| 117 |
.replace(hyphenateRE, '$1-$2') |
| 118 |
.replace(hyphenateRE, '$1-$2') |
| 119 |
.toLowerCase() |
| 120 |
}); |
| 121 |
|
| 122 |
/** |
| 123 |
* Simple bind, faster than native |
| 124 |
*/ |
| 125 |
function bind (fn, ctx) { |
| 126 |
function boundFn (a) { |
| 127 |
var l = arguments.length; |
| 128 |
return l |
| 129 |
? l > 1 |
| 130 |
? fn.apply(ctx, arguments) |
| 131 |
: fn.call(ctx, a) |
| 132 |
: fn.call(ctx) |
| 133 |
} |
| 134 |
// record original fn length |
| 135 |
boundFn._length = fn.length; |
| 136 |
return boundFn |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Convert an Array-like object to a real Array. |
| 141 |
*/ |
| 142 |
function toArray (list, start) { |
| 143 |
start = start || 0; |
| 144 |
var i = list.length - start; |
| 145 |
var ret = new Array(i); |
| 146 |
while (i--) { |
| 147 |
ret[i] = list[i + start]; |
| 148 |
} |
| 149 |
return ret |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Mix properties into target object. |
| 154 |
*/ |
| 155 |
function extend (to, _from) { |
| 156 |
for (var key in _from) { |
| 157 |
to[key] = _from[key]; |
| 158 |
} |
| 159 |
return to |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Quick object check - this is primarily used to tell |
| 164 |
* Objects from primitive values when we know the value |
| 165 |
* is a JSON-compliant type. |
| 166 |
*/ |
| 167 |
function isObject (obj) { |
| 168 |
return obj !== null && typeof obj === 'object' |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Strict object type check. Only returns true |
| 173 |
* for plain JavaScript objects. |
| 174 |
*/ |
| 175 |
var toString = Object.prototype.toString; |
| 176 |
var OBJECT_STRING = '[object Object]'; |
| 177 |
function isPlainObject (obj) { |
| 178 |
return toString.call(obj) === OBJECT_STRING |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Merge an Array of Objects into a single Object. |
| 183 |
*/ |
| 184 |
function toObject (arr) { |
| 185 |
var res = {}; |
| 186 |
for (var i = 0; i < arr.length; i++) { |
| 187 |
if (arr[i]) { |
| 188 |
extend(res, arr[i]); |
| 189 |
} |
| 190 |
} |
| 191 |
return res |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Perform no operation. |
| 196 |
*/ |
| 197 |
function noop () {} |
| 198 |
|
| 199 |
/** |
| 200 |
* Always return false. |
| 201 |
*/ |
| 202 |
var no = function () { return false; }; |
| 203 |
|
| 204 |
/** |
| 205 |
* Return same value |
| 206 |
*/ |
| 207 |
var identity = function (_) { return _; }; |
| 208 |
|
| 209 |
/** |
| 210 |
* Generate a static keys string from compiler modules. |
| 211 |
*/ |
| 212 |
function genStaticKeys (modules) { |
| 213 |
return modules.reduce(function (keys, m) { |
| 214 |
return keys.concat(m.staticKeys || []) |
| 215 |
}, []).join(',') |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Check if two values are loosely equal - that is, |
| 220 |
* if they are plain objects, do they have the same shape? |
| 221 |
*/ |
| 222 |
function looseEqual (a, b) { |
| 223 |
var isObjectA = isObject(a); |
| 224 |
var isObjectB = isObject(b); |
| 225 |
if (isObjectA && isObjectB) { |
| 226 |
try { |
| 227 |
return JSON.stringify(a) === JSON.stringify(b) |
| 228 |
} catch (e) { |
| 229 |
// possible circular reference |
| 230 |
return a === b |
| 231 |
} |
| 232 |
} else if (!isObjectA && !isObjectB) { |
| 233 |
return String(a) === String(b) |
| 234 |
} else { |
| 235 |
return false |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
function looseIndexOf (arr, val) { |
| 240 |
for (var i = 0; i < arr.length; i++) { |
| 241 |
if (looseEqual(arr[i], val)) { return i } |
| 242 |
} |
| 243 |
return -1 |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Ensure a function is called only once. |
| 248 |
*/ |
| 249 |
function once (fn) { |
| 250 |
var called = false; |
| 251 |
return function () { |
| 252 |
if (!called) { |
| 253 |
called = true; |
| 254 |
fn(); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
/* */ |
| 260 |
|
| 261 |
var config = { |
| 262 |
/** |
| 263 |
* Option merge strategies (used in core/util/options) |
| 264 |
*/ |
| 265 |
optionMergeStrategies: Object.create(null), |
| 266 |
|
| 267 |
/** |
| 268 |
* Whether to suppress warnings. |
| 269 |
*/ |
| 270 |
silent: false, |
| 271 |
|
| 272 |
/** |
| 273 |
* Show production mode tip message on boot? |
| 274 |
*/ |
| 275 |
productionTip: "development" !== 'production', |
| 276 |
|
| 277 |
/** |
| 278 |
* Whether to enable devtools |
| 279 |
*/ |
| 280 |
devtools: "development" !== 'production', |
| 281 |
|
| 282 |
/** |
| 283 |
* Whether to record perf |
| 284 |
*/ |
| 285 |
performance: false, |
| 286 |
|
| 287 |
/** |
| 288 |
* Error handler for watcher errors |
| 289 |
*/ |
| 290 |
errorHandler: null, |
| 291 |
|
| 292 |
/** |
| 293 |
* Ignore certain custom elements |
| 294 |
*/ |
| 295 |
ignoredElements: [], |
| 296 |
|
| 297 |
/** |
| 298 |
* Custom user key aliases for v-on |
| 299 |
*/ |
| 300 |
keyCodes: Object.create(null), |
| 301 |
|
| 302 |
/** |
| 303 |
* Check if a tag is reserved so that it cannot be registered as a |
| 304 |
* component. This is platform-dependent and may be overwritten. |
| 305 |
*/ |
| 306 |
isReservedTag: no, |
| 307 |
|
| 308 |
/** |
| 309 |
* Check if a tag is an unknown element. |
| 310 |
* Platform-dependent. |
| 311 |
*/ |
| 312 |
isUnknownElement: no, |
| 313 |
|
| 314 |
/** |
| 315 |
* Get the namespace of an element |
| 316 |
*/ |
| 317 |
getTagNamespace: noop, |
| 318 |
|
| 319 |
/** |
| 320 |
* Parse the real tag name for the specific platform. |
| 321 |
*/ |
| 322 |
parsePlatformTagName: identity, |
| 323 |
|
| 324 |
/** |
| 325 |
* Check if an attribute must be bound using property, e.g. value |
| 326 |
* Platform-dependent. |
| 327 |
*/ |
| 328 |
mustUseProp: no, |
| 329 |
|
| 330 |
/** |
| 331 |
* List of asset types that a component can own. |
| 332 |
*/ |
| 333 |
_assetTypes: [ |
| 334 |
'component', |
| 335 |
'directive', |
| 336 |
'filter' |
| 337 |
], |
| 338 |
|
| 339 |
/** |
| 340 |
* List of lifecycle hooks. |
| 341 |
*/ |
| 342 |
_lifecycleHooks: [ |
| 343 |
'beforeCreate', |
| 344 |
'created', |
| 345 |
'beforeMount', |
| 346 |
'mounted', |
| 347 |
'beforeUpdate', |
| 348 |
'updated', |
| 349 |
'beforeDestroy', |
| 350 |
'destroyed', |
| 351 |
'activated', |
| 352 |
'deactivated' |
| 353 |
], |
| 354 |
|
| 355 |
/** |
| 356 |
* Max circular updates allowed in a scheduler flush cycle. |
| 357 |
*/ |
| 358 |
_maxUpdateCount: 100 |
| 359 |
}; |
| 360 |
|
| 361 |
/* */ |
| 362 |
|
| 363 |
var emptyObject = Object.freeze({}); |
| 364 |
|
| 365 |
/** |
| 366 |
* Check if a string starts with $ or _ |
| 367 |
*/ |
| 368 |
function isReserved (str) { |
| 369 |
var c = (str + '').charCodeAt(0); |
| 370 |
return c === 0x24 || c === 0x5F |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Define a property. |
| 375 |
*/ |
| 376 |
function def (obj, key, val, enumerable) { |
| 377 |
Object.defineProperty(obj, key, { |
| 378 |
value: val, |
| 379 |
enumerable: !!enumerable, |
| 380 |
writable: true, |
| 381 |
configurable: true |
| 382 |
}); |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Parse simple path. |
| 387 |
*/ |
| 388 |
var bailRE = /[^\w.$]/; |
| 389 |
function parsePath (path) { |
| 390 |
if (bailRE.test(path)) { |
| 391 |
return |
| 392 |
} |
| 393 |
var segments = path.split('.'); |
| 394 |
return function (obj) { |
| 395 |
for (var i = 0; i < segments.length; i++) { |
| 396 |
if (!obj) { return } |
| 397 |
obj = obj[segments[i]]; |
| 398 |
} |
| 399 |
return obj |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
/* */ |
| 404 |
/* globals MutationObserver */ |
| 405 |
|
| 406 |
// can we use __proto__? |
| 407 |
var hasProto = '__proto__' in {}; |
| 408 |
|
| 409 |
// Browser environment sniffing |
| 410 |
var inBrowser = typeof window !== 'undefined'; |
| 411 |
var UA = inBrowser && window.navigator.userAgent.toLowerCase(); |
| 412 |
var isIE = UA && /msie|trident/.test(UA); |
| 413 |
var isIE9 = UA && UA.indexOf('msie 9.0') > 0; |
| 414 |
var isEdge = UA && UA.indexOf('edge/') > 0; |
| 415 |
var isAndroid = UA && UA.indexOf('android') > 0; |
| 416 |
var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); |
| 417 |
var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; |
| 418 |
|
| 419 |
// this needs to be lazy-evaled because vue may be required before |
| 420 |
// vue-server-renderer can set VUE_ENV |
| 421 |
var _isServer; |
| 422 |
var isServerRendering = function () { |
| 423 |
if (_isServer === undefined) { |
| 424 |
/* istanbul ignore if */ |
| 425 |
if (!inBrowser && typeof global !== 'undefined') { |
| 426 |
// detect presence of vue-server-renderer and avoid |
| 427 |
// Webpack shimming the process |
| 428 |
_isServer = global['process'].env.VUE_ENV === 'server'; |
| 429 |
} else { |
| 430 |
_isServer = false; |
| 431 |
} |
| 432 |
} |
| 433 |
return _isServer |
| 434 |
}; |
| 435 |
|
| 436 |
// detect devtools |
| 437 |
var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; |
| 438 |
|
| 439 |
/* istanbul ignore next */ |
| 440 |
function isNative (Ctor) { |
| 441 |
return /native code/.test(Ctor.toString()) |
| 442 |
} |
| 443 |
|
| 444 |
var hasSymbol = |
| 445 |
typeof Symbol !== 'undefined' && isNative(Symbol) && |
| 446 |
typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys); |
| 447 |
|
| 448 |
/** |
| 449 |
* Defer a task to execute it asynchronously. |
| 450 |
*/ |
| 451 |
var nextTick = (function () { |
| 452 |
var callbacks = []; |
| 453 |
var pending = false; |
| 454 |
var timerFunc; |
| 455 |
|
| 456 |
function nextTickHandler () { |
| 457 |
pending = false; |
| 458 |
var copies = callbacks.slice(0); |
| 459 |
callbacks.length = 0; |
| 460 |
for (var i = 0; i < copies.length; i++) { |
| 461 |
copies[i](); |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
// the nextTick behavior leverages the microtask queue, which can be accessed |
| 466 |
// via either native Promise.then or MutationObserver. |
| 467 |
// MutationObserver has wider support, however it is seriously bugged in |
| 468 |
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It |
| 469 |
// completely stops working after triggering a few times... so, if native |
| 470 |
// Promise is available, we will use it: |
| 471 |
/* istanbul ignore if */ |
| 472 |
if (typeof Promise !== 'undefined' && isNative(Promise)) { |
| 473 |
var p = Promise.resolve(); |
| 474 |
var logError = function (err) { console.error(err); }; |
| 475 |
timerFunc = function () { |
| 476 |
p.then(nextTickHandler).catch(logError); |
| 477 |
// in problematic UIWebViews, Promise.then doesn't completely break, but |
| 478 |
// it can get stuck in a weird state where callbacks are pushed into the |
| 479 |
// microtask queue but the queue isn't being flushed, until the browser |
| 480 |
// needs to do some other work, e.g. handle a timer. Therefore we can |
| 481 |
// "force" the microtask queue to be flushed by adding an empty timer. |
| 482 |
if (isIOS) { setTimeout(noop); } |
| 483 |
}; |
| 484 |
} else if (typeof MutationObserver !== 'undefined' && ( |
| 485 |
isNative(MutationObserver) || |
| 486 |
// PhantomJS and iOS 7.x |
| 487 |
MutationObserver.toString() === '[object MutationObserverConstructor]' |
| 488 |
)) { |
| 489 |
// use MutationObserver where native Promise is not available, |
| 490 |
// e.g. PhantomJS IE11, iOS7, Android 4.4 |
| 491 |
var counter = 1; |
| 492 |
var observer = new MutationObserver(nextTickHandler); |
| 493 |
var textNode = document.createTextNode(String(counter)); |
| 494 |
observer.observe(textNode, { |
| 495 |
characterData: true |
| 496 |
}); |
| 497 |
timerFunc = function () { |
| 498 |
counter = (counter + 1) % 2; |
| 499 |
textNode.data = String(counter); |
| 500 |
}; |
| 501 |
} else { |
| 502 |
// fallback to setTimeout |
| 503 |
/* istanbul ignore next */ |
| 504 |
timerFunc = function () { |
| 505 |
setTimeout(nextTickHandler, 0); |
| 506 |
}; |
| 507 |
} |
| 508 |
|
| 509 |
return function queueNextTick (cb, ctx) { |
| 510 |
var _resolve; |
| 511 |
callbacks.push(function () { |
| 512 |
if (cb) { cb.call(ctx); } |
| 513 |
if (_resolve) { _resolve(ctx); } |
| 514 |
}); |
| 515 |
if (!pending) { |
| 516 |
pending = true; |
| 517 |
timerFunc(); |
| 518 |
} |
| 519 |
if (!cb && typeof Promise !== 'undefined') { |
| 520 |
return new Promise(function (resolve) { |
| 521 |
_resolve = resolve; |
| 522 |
}) |
| 523 |
} |
| 524 |
} |
| 525 |
})(); |
| 526 |
|
| 527 |
var _Set; |
| 528 |
/* istanbul ignore if */ |
| 529 |
if (typeof Set !== 'undefined' && isNative(Set)) { |
| 530 |
// use native Set when available. |
| 531 |
_Set = Set; |
| 532 |
} else { |
| 533 |
// a non-standard Set polyfill that only works with primitive keys. |
| 534 |
_Set = (function () { |
| 535 |
function Set () { |
| 536 |
this.set = Object.create(null); |
| 537 |
} |
| 538 |
Set.prototype.has = function has (key) { |
| 539 |
return this.set[key] === true |
| 540 |
}; |
| 541 |
Set.prototype.add = function add (key) { |
| 542 |
this.set[key] = true; |
| 543 |
}; |
| 544 |
Set.prototype.clear = function clear () { |
| 545 |
this.set = Object.create(null); |
| 546 |
}; |
| 547 |
|
| 548 |
return Set; |
| 549 |
}()); |
| 550 |
} |
| 551 |
|
| 552 |
var warn = noop; |
| 553 |
var tip = noop; |
| 554 |
var formatComponentName; |
| 555 |
|
| 556 |
{ |
| 557 |
var hasConsole = typeof console !== 'undefined'; |
| 558 |
var classifyRE = /(?:^|[-_])(\w)/g; |
| 559 |
var classify = function (str) { return str |
| 560 |
.replace(classifyRE, function (c) { return c.toUpperCase(); }) |
| 561 |
.replace(/[-_]/g, ''); }; |
| 562 |
|
| 563 |
warn = function (msg, vm) { |
| 564 |
if (hasConsole && (!config.silent)) { |
| 565 |
console.error("[Vue warn]: " + msg + " " + ( |
| 566 |
vm ? formatLocation(formatComponentName(vm)) : '' |
| 567 |
)); |
| 568 |
} |
| 569 |
}; |
| 570 |
|
| 571 |
tip = function (msg, vm) { |
| 572 |
if (hasConsole && (!config.silent)) { |
| 573 |
console.warn("[Vue tip]: " + msg + " " + ( |
| 574 |
vm ? formatLocation(formatComponentName(vm)) : '' |
| 575 |
)); |
| 576 |
} |
| 577 |
}; |
| 578 |
|
| 579 |
formatComponentName = function (vm, includeFile) { |
| 580 |
if (vm.$root === vm) { |
| 581 |
return '<Root>' |
| 582 |
} |
| 583 |
var name = typeof vm === 'function' && vm.options |
| 584 |
? vm.options.name |
| 585 |
: vm._isVue |
| 586 |
? vm.$options.name || vm.$options._componentTag |
| 587 |
: vm.name; |
| 588 |
|
| 589 |
var file = vm._isVue && vm.$options.__file; |
| 590 |
if (!name && file) { |
| 591 |
var match = file.match(/([^/\\]+)\.vue$/); |
| 592 |
name = match && match[1]; |
| 593 |
} |
| 594 |
|
| 595 |
return ( |
| 596 |
(name ? ("<" + (classify(name)) + ">") : "<Anonymous>") + |
| 597 |
(file && includeFile !== false ? (" at " + file) : '') |
| 598 |
) |
| 599 |
}; |
| 600 |
|
| 601 |
var formatLocation = function (str) { |
| 602 |
if (str === "<Anonymous>") { |
| 603 |
str += " - use the \"name\" option for better debugging messages."; |
| 604 |
} |
| 605 |
return ("\n(found in " + str + ")") |
| 606 |
}; |
| 607 |
} |
| 608 |
|
| 609 |
/* */ |
| 610 |
|
| 611 |
|
| 612 |
var uid$1 = 0; |
| 613 |
|
| 614 |
/** |
| 615 |
* A dep is an observable that can have multiple |
| 616 |
* directives subscribing to it. |
| 617 |
*/ |
| 618 |
var Dep = function Dep () { |
| 619 |
this.id = uid$1++; |
| 620 |
this.subs = []; |
| 621 |
}; |
| 622 |
|
| 623 |
Dep.prototype.addSub = function addSub (sub) { |
| 624 |
this.subs.push(sub); |
| 625 |
}; |
| 626 |
|
| 627 |
Dep.prototype.removeSub = function removeSub (sub) { |
| 628 |
remove(this.subs, sub); |
| 629 |
}; |
| 630 |
|
| 631 |
Dep.prototype.depend = function depend () { |
| 632 |
if (Dep.target) { |
| 633 |
Dep.target.addDep(this); |
| 634 |
} |
| 635 |
}; |
| 636 |
|
| 637 |
Dep.prototype.notify = function notify () { |
| 638 |
// stabilize the subscriber list first |
| 639 |
var subs = this.subs.slice(); |
| 640 |
for (var i = 0, l = subs.length; i < l; i++) { |
| 641 |
subs[i].update(); |
| 642 |
} |
| 643 |
}; |
| 644 |
|
| 645 |
// the current target watcher being evaluated. |
| 646 |
// this is globally unique because there could be only one |
| 647 |
// watcher being evaluated at any time. |
| 648 |
Dep.target = null; |
| 649 |
var targetStack = []; |
| 650 |
|
| 651 |
function pushTarget (_target) { |
| 652 |
if (Dep.target) { targetStack.push(Dep.target); } |
| 653 |
Dep.target = _target; |
| 654 |
} |
| 655 |
|
| 656 |
function popTarget () { |
| 657 |
Dep.target = targetStack.pop(); |
| 658 |
} |
| 659 |
|
| 660 |
/* |
| 661 |
* not type checking this file because flow doesn't play well with |
| 662 |
* dynamically accessing methods on Array prototype |
| 663 |
*/ |
| 664 |
|
| 665 |
var arrayProto = Array.prototype; |
| 666 |
var arrayMethods = Object.create(arrayProto);[ |
| 667 |
'push', |
| 668 |
'pop', |
| 669 |
'shift', |
| 670 |
'unshift', |
| 671 |
'splice', |
| 672 |
'sort', |
| 673 |
'reverse' |
| 674 |
] |
| 675 |
.forEach(function (method) { |
| 676 |
// cache original method |
| 677 |
var original = arrayProto[method]; |
| 678 |
def(arrayMethods, method, function mutator () { |
| 679 |
var arguments$1 = arguments; |
| 680 |
|
| 681 |
// avoid leaking arguments: |
| 682 |
// http://jsperf.com/closure-with-arguments |
| 683 |
var i = arguments.length; |
| 684 |
var args = new Array(i); |
| 685 |
while (i--) { |
| 686 |
args[i] = arguments$1[i]; |
| 687 |
} |
| 688 |
var result = original.apply(this, args); |
| 689 |
var ob = this.__ob__; |
| 690 |
var inserted; |
| 691 |
switch (method) { |
| 692 |
case 'push': |
| 693 |
inserted = args; |
| 694 |
break |
| 695 |
case 'unshift': |
| 696 |
inserted = args; |
| 697 |
break |
| 698 |
case 'splice': |
| 699 |
inserted = args.slice(2); |
| 700 |
break |
| 701 |
} |
| 702 |
if (inserted) { ob.observeArray(inserted); } |
| 703 |
// notify change |
| 704 |
ob.dep.notify(); |
| 705 |
return result |
| 706 |
}); |
| 707 |
}); |
| 708 |
|
| 709 |
/* */ |
| 710 |
|
| 711 |
var arrayKeys = Object.getOwnPropertyNames(arrayMethods); |
| 712 |
|
| 713 |
/** |
| 714 |
* By default, when a reactive property is set, the new value is |
| 715 |
* also converted to become reactive. However when passing down props, |
| 716 |
* we don't want to force conversion because the value may be a nested value |
| 717 |
* under a frozen data structure. Converting it would defeat the optimization. |
| 718 |
*/ |
| 719 |
var observerState = { |
| 720 |
shouldConvert: true, |
| 721 |
isSettingProps: false |
| 722 |
}; |
| 723 |
|
| 724 |
/** |
| 725 |
* Observer class that are attached to each observed |
| 726 |
* object. Once attached, the observer converts target |
| 727 |
* object's property keys into getter/setters that |
| 728 |
* collect dependencies and dispatches updates. |
| 729 |
*/ |
| 730 |
var Observer = function Observer (value) { |
| 731 |
this.value = value; |
| 732 |
this.dep = new Dep(); |
| 733 |
this.vmCount = 0; |
| 734 |
def(value, '__ob__', this); |
| 735 |
if (Array.isArray(value)) { |
| 736 |
var augment = hasProto |
| 737 |
? protoAugment |
| 738 |
: copyAugment; |
| 739 |
augment(value, arrayMethods, arrayKeys); |
| 740 |
this.observeArray(value); |
| 741 |
} else { |
| 742 |
this.walk(value); |
| 743 |
} |
| 744 |
}; |
| 745 |
|
| 746 |
/** |
| 747 |
* Walk through each property and convert them into |
| 748 |
* getter/setters. This method should only be called when |
| 749 |
* value type is Object. |
| 750 |
*/ |
| 751 |
Observer.prototype.walk = function walk (obj) { |
| 752 |
var keys = Object.keys(obj); |
| 753 |
for (var i = 0; i < keys.length; i++) { |
| 754 |
defineReactive$$1(obj, keys[i], obj[keys[i]]); |
| 755 |
} |
| 756 |
}; |
| 757 |
|
| 758 |
/** |
| 759 |
* Observe a list of Array items. |
| 760 |
*/ |
| 761 |
Observer.prototype.observeArray = function observeArray (items) { |
| 762 |
for (var i = 0, l = items.length; i < l; i++) { |
| 763 |
observe(items[i]); |
| 764 |
} |
| 765 |
}; |
| 766 |
|
| 767 |
// helpers |
| 768 |
|
| 769 |
/** |
| 770 |
* Augment an target Object or Array by intercepting |
| 771 |
* the prototype chain using __proto__ |
| 772 |
*/ |
| 773 |
function protoAugment (target, src) { |
| 774 |
/* eslint-disable no-proto */ |
| 775 |
target.__proto__ = src; |
| 776 |
/* eslint-enable no-proto */ |
| 777 |
} |
| 778 |
|
| 779 |
/** |
| 780 |
* Augment an target Object or Array by defining |
| 781 |
* hidden properties. |
| 782 |
*/ |
| 783 |
/* istanbul ignore next */ |
| 784 |
function copyAugment (target, src, keys) { |
| 785 |
for (var i = 0, l = keys.length; i < l; i++) { |
| 786 |
var key = keys[i]; |
| 787 |
def(target, key, src[key]); |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
/** |
| 792 |
* Attempt to create an observer instance for a value, |
| 793 |
* returns the new observer if successfully observed, |
| 794 |
* or the existing observer if the value already has one. |
| 795 |
*/ |
| 796 |
function observe (value, asRootData) { |
| 797 |
if (!isObject(value)) { |
| 798 |
return |
| 799 |
} |
| 800 |
var ob; |
| 801 |
if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) { |
| 802 |
ob = value.__ob__; |
| 803 |
} else if ( |
| 804 |
observerState.shouldConvert && |
| 805 |
!isServerRendering() && |
| 806 |
(Array.isArray(value) || isPlainObject(value)) && |
| 807 |
Object.isExtensible(value) && |
| 808 |
!value._isVue |
| 809 |
) { |
| 810 |
ob = new Observer(value); |
| 811 |
} |
| 812 |
if (asRootData && ob) { |
| 813 |
ob.vmCount++; |
| 814 |
} |
| 815 |
return ob |
| 816 |
} |
| 817 |
|
| 818 |
/** |
| 819 |
* Define a reactive property on an Object. |
| 820 |
*/ |
| 821 |
function defineReactive$$1 ( |
| 822 |
obj, |
| 823 |
key, |
| 824 |
val, |
| 825 |
customSetter |
| 826 |
) { |
| 827 |
var dep = new Dep(); |
| 828 |
|
| 829 |
var property = Object.getOwnPropertyDescriptor(obj, key); |
| 830 |
if (property && property.configurable === false) { |
| 831 |
return |
| 832 |
} |
| 833 |
|
| 834 |
// cater for pre-defined getter/setters |
| 835 |
var getter = property && property.get; |
| 836 |
var setter = property && property.set; |
| 837 |
|
| 838 |
var childOb = observe(val); |
| 839 |
Object.defineProperty(obj, key, { |
| 840 |
enumerable: true, |
| 841 |
configurable: true, |
| 842 |
get: function reactiveGetter () { |
| 843 |
var value = getter ? getter.call(obj) : val; |
| 844 |
if (Dep.target) { |
| 845 |
dep.depend(); |
| 846 |
if (childOb) { |
| 847 |
childOb.dep.depend(); |
| 848 |
} |
| 849 |
if (Array.isArray(value)) { |
| 850 |
dependArray(value); |
| 851 |
} |
| 852 |
} |
| 853 |
return value |
| 854 |
}, |
| 855 |
set: function reactiveSetter (newVal) { |
| 856 |
var value = getter ? getter.call(obj) : val; |
| 857 |
/* eslint-disable no-self-compare */ |
| 858 |
if (newVal === value || (newVal !== newVal && value !== value)) { |
| 859 |
return |
| 860 |
} |
| 861 |
/* eslint-enable no-self-compare */ |
| 862 |
if ("development" !== 'production' && customSetter) { |
| 863 |
customSetter(); |
| 864 |
} |
| 865 |
if (setter) { |
| 866 |
setter.call(obj, newVal); |
| 867 |
} else { |
| 868 |
val = newVal; |
| 869 |
} |
| 870 |
childOb = observe(newVal); |
| 871 |
dep.notify(); |
| 872 |
} |
| 873 |
}); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* Set a property on an object. Adds the new property and |
| 878 |
* triggers change notification if the property doesn't |
| 879 |
* already exist. |
| 880 |
*/ |
| 881 |
function set (target, key, val) { |
| 882 |
if (Array.isArray(target)) { |
| 883 |
target.length = Math.max(target.length, key); |
| 884 |
target.splice(key, 1, val); |
| 885 |
return val |
| 886 |
} |
| 887 |
if (hasOwn(target, key)) { |
| 888 |
target[key] = val; |
| 889 |
return val |
| 890 |
} |
| 891 |
var ob = target.__ob__; |
| 892 |
if (target._isVue || (ob && ob.vmCount)) { |
| 893 |
"development" !== 'production' && warn( |
| 894 |
'Avoid adding reactive properties to a Vue instance or its root $data ' + |
| 895 |
'at runtime - declare it upfront in the data option.' |
| 896 |
); |
| 897 |
return val |
| 898 |
} |
| 899 |
if (!ob) { |
| 900 |
target[key] = val; |
| 901 |
return val |
| 902 |
} |
| 903 |
defineReactive$$1(ob.value, key, val); |
| 904 |
ob.dep.notify(); |
| 905 |
return val |
| 906 |
} |
| 907 |
|
| 908 |
/** |
| 909 |
* Delete a property and trigger change if necessary. |
| 910 |
*/ |
| 911 |
function del (target, key) { |
| 912 |
if (Array.isArray(target)) { |
| 913 |
target.splice(key, 1); |
| 914 |
return |
| 915 |
} |
| 916 |
var ob = target.__ob__; |
| 917 |
if (target._isVue || (ob && ob.vmCount)) { |
| 918 |
"development" !== 'production' && warn( |
| 919 |
'Avoid deleting properties on a Vue instance or its root $data ' + |
| 920 |
'- just set it to null.' |
| 921 |
); |
| 922 |
return |
| 923 |
} |
| 924 |
if (!hasOwn(target, key)) { |
| 925 |
return |
| 926 |
} |
| 927 |
delete target[key]; |
| 928 |
if (!ob) { |
| 929 |
return |
| 930 |
} |
| 931 |
ob.dep.notify(); |
| 932 |
} |
| 933 |
|
| 934 |
/** |
| 935 |
* Collect dependencies on array elements when the array is touched, since |
| 936 |
* we cannot intercept array element access like property getters. |
| 937 |
*/ |
| 938 |
function dependArray (value) { |
| 939 |
for (var e = (void 0), i = 0, l = value.length; i < l; i++) { |
| 940 |
e = value[i]; |
| 941 |
e && e.__ob__ && e.__ob__.dep.depend(); |
| 942 |
if (Array.isArray(e)) { |
| 943 |
dependArray(e); |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
/* */ |
| 949 |
|
| 950 |
/** |
| 951 |
* Option overwriting strategies are functions that handle |
| 952 |
* how to merge a parent option value and a child option |
| 953 |
* value into the final value. |
| 954 |
*/ |
| 955 |
var strats = config.optionMergeStrategies; |
| 956 |
|
| 957 |
/** |
| 958 |
* Options with restrictions |
| 959 |
*/ |
| 960 |
{ |
| 961 |
strats.el = strats.propsData = function (parent, child, vm, key) { |
| 962 |
if (!vm) { |
| 963 |
warn( |
| 964 |
"option \"" + key + "\" can only be used during instance " + |
| 965 |
'creation with the `new` keyword.' |
| 966 |
); |
| 967 |
} |
| 968 |
return defaultStrat(parent, child) |
| 969 |
}; |
| 970 |
} |
| 971 |
|
| 972 |
/** |
| 973 |
* Helper that recursively merges two data objects together. |
| 974 |
*/ |
| 975 |
function mergeData (to, from) { |
| 976 |
if (!from) { return to } |
| 977 |
var key, toVal, fromVal; |
| 978 |
var keys = Object.keys(from); |
| 979 |
for (var i = 0; i < keys.length; i++) { |
| 980 |
key = keys[i]; |
| 981 |
toVal = to[key]; |
| 982 |
fromVal = from[key]; |
| 983 |
if (!hasOwn(to, key)) { |
| 984 |
set(to, key, fromVal); |
| 985 |
} else if (isPlainObject(toVal) && isPlainObject(fromVal)) { |
| 986 |
mergeData(toVal, fromVal); |
| 987 |
} |
| 988 |
} |
| 989 |
return to |
| 990 |
} |
| 991 |
|
| 992 |
/** |
| 993 |
* Data |
| 994 |
*/ |
| 995 |
strats.data = function ( |
| 996 |
parentVal, |
| 997 |
childVal, |
| 998 |
vm |
| 999 |
) { |
| 1000 |
if (!vm) { |
| 1001 |
// in a Vue.extend merge, both should be functions |
| 1002 |
if (!childVal) { |
| 1003 |
return parentVal |
| 1004 |
} |
| 1005 |
if (typeof childVal !== 'function') { |
| 1006 |
"development" !== 'production' && warn( |
| 1007 |
'The "data" option should be a function ' + |
| 1008 |
'that returns a per-instance value in component ' + |
| 1009 |
'definitions.', |
| 1010 |
vm |
| 1011 |
); |
| 1012 |
return parentVal |
| 1013 |
} |
| 1014 |
if (!parentVal) { |
| 1015 |
return childVal |
| 1016 |
} |
| 1017 |
// when parentVal & childVal are both present, |
| 1018 |
// we need to return a function that returns the |
| 1019 |
// merged result of both functions... no need to |
| 1020 |
// check if parentVal is a function here because |
| 1021 |
// it has to be a function to pass previous merges. |
| 1022 |
return function mergedDataFn () { |
| 1023 |
return mergeData( |
| 1024 |
childVal.call(this), |
| 1025 |
parentVal.call(this) |
| 1026 |
) |
| 1027 |
} |
| 1028 |
} else if (parentVal || childVal) { |
| 1029 |
return function mergedInstanceDataFn () { |
| 1030 |
// instance merge |
| 1031 |
var instanceData = typeof childVal === 'function' |
| 1032 |
? childVal.call(vm) |
| 1033 |
: childVal; |
| 1034 |
var defaultData = typeof parentVal === 'function' |
| 1035 |
? parentVal.call(vm) |
| 1036 |
: undefined; |
| 1037 |
if (instanceData) { |
| 1038 |
return mergeData(instanceData, defaultData) |
| 1039 |
} else { |
| 1040 |
return defaultData |
| 1041 |
} |
| 1042 |
} |
| 1043 |
} |
| 1044 |
}; |
| 1045 |
|
| 1046 |
/** |
| 1047 |
* Hooks and props are merged as arrays. |
| 1048 |
*/ |
| 1049 |
function mergeHook ( |
| 1050 |
parentVal, |
| 1051 |
childVal |
| 1052 |
) { |
| 1053 |
return childVal |
| 1054 |
? parentVal |
| 1055 |
? parentVal.concat(childVal) |
| 1056 |
: Array.isArray(childVal) |
| 1057 |
? childVal |
| 1058 |
: [childVal] |
| 1059 |
: parentVal |
| 1060 |
} |
| 1061 |
|
| 1062 |
config._lifecycleHooks.forEach(function (hook) { |
| 1063 |
strats[hook] = mergeHook; |
| 1064 |
}); |
| 1065 |
|
| 1066 |
/** |
| 1067 |
* Assets |
| 1068 |
* |
| 1069 |
* When a vm is present (instance creation), we need to do |
| 1070 |
* a three-way merge between constructor options, instance |
| 1071 |
* options and parent options. |
| 1072 |
*/ |
| 1073 |
function mergeAssets (parentVal, childVal) { |
| 1074 |
var res = Object.create(parentVal || null); |
| 1075 |
return childVal |
| 1076 |
? extend(res, childVal) |
| 1077 |
: res |
| 1078 |
} |
| 1079 |
|
| 1080 |
config._assetTypes.forEach(function (type) { |
| 1081 |
strats[type + 's'] = mergeAssets; |
| 1082 |
}); |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* Watchers. |
| 1086 |
* |
| 1087 |
* Watchers hashes should not overwrite one |
| 1088 |
* another, so we merge them as arrays. |
| 1089 |
*/ |
| 1090 |
strats.watch = function (parentVal, childVal) { |
| 1091 |
/* istanbul ignore if */ |
| 1092 |
if (!childVal) { return Object.create(parentVal || null) } |
| 1093 |
if (!parentVal) { return childVal } |
| 1094 |
var ret = {}; |
| 1095 |
extend(ret, parentVal); |
| 1096 |
for (var key in childVal) { |
| 1097 |
var parent = ret[key]; |
| 1098 |
var child = childVal[key]; |
| 1099 |
if (parent && !Array.isArray(parent)) { |
| 1100 |
parent = [parent]; |
| 1101 |
} |
| 1102 |
ret[key] = parent |
| 1103 |
? parent.concat(child) |
| 1104 |
: [child]; |
| 1105 |
} |
| 1106 |
return ret |
| 1107 |
}; |
| 1108 |
|
| 1109 |
/** |
| 1110 |
* Other object hashes. |
| 1111 |
*/ |
| 1112 |
strats.props = |
| 1113 |
strats.methods = |
| 1114 |
strats.computed = function (parentVal, childVal) { |
| 1115 |
if (!childVal) { return Object.create(parentVal || null) } |
| 1116 |
if (!parentVal) { return childVal } |
| 1117 |
var ret = Object.create(null); |
| 1118 |
extend(ret, parentVal); |
| 1119 |
extend(ret, childVal); |
| 1120 |
return ret |
| 1121 |
}; |
| 1122 |
|
| 1123 |
/** |
| 1124 |
* Default strategy. |
| 1125 |
*/ |
| 1126 |
var defaultStrat = function (parentVal, childVal) { |
| 1127 |
return childVal === undefined |
| 1128 |
? parentVal |
| 1129 |
: childVal |
| 1130 |
}; |
| 1131 |
|
| 1132 |
/** |
| 1133 |
* Validate component names |
| 1134 |
*/ |
| 1135 |
function checkComponents (options) { |
| 1136 |
for (var key in options.components) { |
| 1137 |
var lower = key.toLowerCase(); |
| 1138 |
if (isBuiltInTag(lower) || config.isReservedTag(lower)) { |
| 1139 |
warn( |
| 1140 |
'Do not use built-in or reserved HTML elements as component ' + |
| 1141 |
'id: ' + key |
| 1142 |
); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
} |
| 1146 |
|
| 1147 |
/** |
| 1148 |
* Ensure all props option syntax are normalized into the |
| 1149 |
* Object-based format. |
| 1150 |
*/ |
| 1151 |
function normalizeProps (options) { |
| 1152 |
var props = options.props; |
| 1153 |
if (!props) { return } |
| 1154 |
var res = {}; |
| 1155 |
var i, val, name; |
| 1156 |
if (Array.isArray(props)) { |
| 1157 |
i = props.length; |
| 1158 |
while (i--) { |
| 1159 |
val = props[i]; |
| 1160 |
if (typeof val === 'string') { |
| 1161 |
name = camelize(val); |
| 1162 |
res[name] = { type: null }; |
| 1163 |
} else { |
| 1164 |
warn('props must be strings when using array syntax.'); |
| 1165 |
} |
| 1166 |
} |
| 1167 |
} else if (isPlainObject(props)) { |
| 1168 |
for (var key in props) { |
| 1169 |
val = props[key]; |
| 1170 |
name = camelize(key); |
| 1171 |
res[name] = isPlainObject(val) |
| 1172 |
? val |
| 1173 |
: { type: val }; |
| 1174 |
} |
| 1175 |
} |
| 1176 |
options.props = res; |
| 1177 |
} |
| 1178 |
|
| 1179 |
/** |
| 1180 |
* Normalize raw function directives into object format. |
| 1181 |
*/ |
| 1182 |
function normalizeDirectives (options) { |
| 1183 |
var dirs = options.directives; |
| 1184 |
if (dirs) { |
| 1185 |
for (var key in dirs) { |
| 1186 |
var def = dirs[key]; |
| 1187 |
if (typeof def === 'function') { |
| 1188 |
dirs[key] = { bind: def, update: def }; |
| 1189 |
} |
| 1190 |
} |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
/** |
| 1195 |
* Merge two option objects into a new one. |
| 1196 |
* Core utility used in both instantiation and inheritance. |
| 1197 |
*/ |
| 1198 |
function mergeOptions ( |
| 1199 |
parent, |
| 1200 |
child, |
| 1201 |
vm |
| 1202 |
) { |
| 1203 |
{ |
| 1204 |
checkComponents(child); |
| 1205 |
} |
| 1206 |
normalizeProps(child); |
| 1207 |
normalizeDirectives(child); |
| 1208 |
var extendsFrom = child.extends; |
| 1209 |
if (extendsFrom) { |
| 1210 |
parent = typeof extendsFrom === 'function' |
| 1211 |
? mergeOptions(parent, extendsFrom.options, vm) |
| 1212 |
: mergeOptions(parent, extendsFrom, vm); |
| 1213 |
} |
| 1214 |
if (child.mixins) { |
| 1215 |
for (var i = 0, l = child.mixins.length; i < l; i++) { |
| 1216 |
var mixin = child.mixins[i]; |
| 1217 |
if (mixin.prototype instanceof Vue$3) { |
| 1218 |
mixin = mixin.options; |
| 1219 |
} |
| 1220 |
parent = mergeOptions(parent, mixin, vm); |
| 1221 |
} |
| 1222 |
} |
| 1223 |
var options = {}; |
| 1224 |
var key; |
| 1225 |
for (key in parent) { |
| 1226 |
mergeField(key); |
| 1227 |
} |
| 1228 |
for (key in child) { |
| 1229 |
if (!hasOwn(parent, key)) { |
| 1230 |
mergeField(key); |
| 1231 |
} |
| 1232 |
} |
| 1233 |
function mergeField (key) { |
| 1234 |
var strat = strats[key] || defaultStrat; |
| 1235 |
options[key] = strat(parent[key], child[key], vm, key); |
| 1236 |
} |
| 1237 |
return options |
| 1238 |
} |
| 1239 |
|
| 1240 |
/** |
| 1241 |
* Resolve an asset. |
| 1242 |
* This function is used because child instances need access |
| 1243 |
* to assets defined in its ancestor chain. |
| 1244 |
*/ |
| 1245 |
function resolveAsset ( |
| 1246 |
options, |
| 1247 |
type, |
| 1248 |
id, |
| 1249 |
warnMissing |
| 1250 |
) { |
| 1251 |
/* istanbul ignore if */ |
| 1252 |
if (typeof id !== 'string') { |
| 1253 |
return |
| 1254 |
} |
| 1255 |
var assets = options[type]; |
| 1256 |
// check local registration variations first |
| 1257 |
if (hasOwn(assets, id)) { return assets[id] } |
| 1258 |
var camelizedId = camelize(id); |
| 1259 |
if (hasOwn(assets, camelizedId)) { return assets[camelizedId] } |
| 1260 |
var PascalCaseId = capitalize(camelizedId); |
| 1261 |
if (hasOwn(assets, PascalCaseId)) { return assets[PascalCaseId] } |
| 1262 |
// fallback to prototype chain |
| 1263 |
var res = assets[id] || assets[camelizedId] || assets[PascalCaseId]; |
| 1264 |
if ("development" !== 'production' && warnMissing && !res) { |
| 1265 |
warn( |
| 1266 |
'Failed to resolve ' + type.slice(0, -1) + ': ' + id, |
| 1267 |
options |
| 1268 |
); |
| 1269 |
} |
| 1270 |
return res |
| 1271 |
} |
| 1272 |
|
| 1273 |
/* */ |
| 1274 |
|
| 1275 |
function validateProp ( |
| 1276 |
key, |
| 1277 |
propOptions, |
| 1278 |
propsData, |
| 1279 |
vm |
| 1280 |
) { |
| 1281 |
var prop = propOptions[key]; |
| 1282 |
var absent = !hasOwn(propsData, key); |
| 1283 |
var value = propsData[key]; |
| 1284 |
// handle boolean props |
| 1285 |
if (isType(Boolean, prop.type)) { |
| 1286 |
if (absent && !hasOwn(prop, 'default')) { |
| 1287 |
value = false; |
| 1288 |
} else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) { |
| 1289 |
value = true; |
| 1290 |
} |
| 1291 |
} |
| 1292 |
// check default value |
| 1293 |
if (value === undefined) { |
| 1294 |
value = getPropDefaultValue(vm, prop, key); |
| 1295 |
// since the default value is a fresh copy, |
| 1296 |
// make sure to observe it. |
| 1297 |
var prevShouldConvert = observerState.shouldConvert; |
| 1298 |
observerState.shouldConvert = true; |
| 1299 |
observe(value); |
| 1300 |
observerState.shouldConvert = prevShouldConvert; |
| 1301 |
} |
| 1302 |
{ |
| 1303 |
assertProp(prop, key, value, vm, absent); |
| 1304 |
} |
| 1305 |
return value |
| 1306 |
} |
| 1307 |
|
| 1308 |
/** |
| 1309 |
* Get the default value of a prop. |
| 1310 |
*/ |
| 1311 |
function getPropDefaultValue (vm, prop, key) { |
| 1312 |
// no default, return undefined |
| 1313 |
if (!hasOwn(prop, 'default')) { |
| 1314 |
return undefined |
| 1315 |
} |
| 1316 |
var def = prop.default; |
| 1317 |
// warn against non-factory defaults for Object & Array |
| 1318 |
if ("development" !== 'production' && isObject(def)) { |
| 1319 |
warn( |
| 1320 |
'Invalid default value for prop "' + key + '": ' + |
| 1321 |
'Props with type Object/Array must use a factory function ' + |
| 1322 |
'to return the default value.', |
| 1323 |
vm |
| 1324 |
); |
| 1325 |
} |
| 1326 |
// the raw prop value was also undefined from previous render, |
| 1327 |
// return previous default value to avoid unnecessary watcher trigger |
| 1328 |
if (vm && vm.$options.propsData && |
| 1329 |
vm.$options.propsData[key] === undefined && |
| 1330 |
vm._props[key] !== undefined) { |
| 1331 |
return vm._props[key] |
| 1332 |
} |
| 1333 |
// call factory function for non-Function types |
| 1334 |
// a value is Function if its prototype is function even across different execution context |
| 1335 |
return typeof def === 'function' && getType(prop.type) !== 'Function' |
| 1336 |
? def.call(vm) |
| 1337 |
: def |
| 1338 |
} |
| 1339 |
|
| 1340 |
/** |
| 1341 |
* Assert whether a prop is valid. |
| 1342 |
*/ |
| 1343 |
function assertProp ( |
| 1344 |
prop, |
| 1345 |
name, |
| 1346 |
value, |
| 1347 |
vm, |
| 1348 |
absent |
| 1349 |
) { |
| 1350 |
if (prop.required && absent) { |
| 1351 |
warn( |
| 1352 |
'Missing required prop: "' + name + '"', |
| 1353 |
vm |
| 1354 |
); |
| 1355 |
return |
| 1356 |
} |
| 1357 |
if (value == null && !prop.required) { |
| 1358 |
return |
| 1359 |
} |
| 1360 |
var type = prop.type; |
| 1361 |
var valid = !type || type === true; |
| 1362 |
var expectedTypes = []; |
| 1363 |
if (type) { |
| 1364 |
if (!Array.isArray(type)) { |
| 1365 |
type = [type]; |
| 1366 |
} |
| 1367 |
for (var i = 0; i < type.length && !valid; i++) { |
| 1368 |
var assertedType = assertType(value, type[i]); |
| 1369 |
expectedTypes.push(assertedType.expectedType || ''); |
| 1370 |
valid = assertedType.valid; |
| 1371 |
} |
| 1372 |
} |
| 1373 |
if (!valid) { |
| 1374 |
warn( |
| 1375 |
'Invalid prop: type check failed for prop "' + name + '".' + |
| 1376 |
' Expected ' + expectedTypes.map(capitalize).join(', ') + |
| 1377 |
', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.', |
| 1378 |
vm |
| 1379 |
); |
| 1380 |
return |
| 1381 |
} |
| 1382 |
var validator = prop.validator; |
| 1383 |
if (validator) { |
| 1384 |
if (!validator(value)) { |
| 1385 |
warn( |
| 1386 |
'Invalid prop: custom validator check failed for prop "' + name + '".', |
| 1387 |
vm |
| 1388 |
); |
| 1389 |
} |
| 1390 |
} |
| 1391 |
} |
| 1392 |
|
| 1393 |
/** |
| 1394 |
* Assert the type of a value |
| 1395 |
*/ |
| 1396 |
function assertType (value, type) { |
| 1397 |
var valid; |
| 1398 |
var expectedType = getType(type); |
| 1399 |
if (expectedType === 'String') { |
| 1400 |
valid = typeof value === (expectedType = 'string'); |
| 1401 |
} else if (expectedType === 'Number') { |
| 1402 |
valid = typeof value === (expectedType = 'number'); |
| 1403 |
} else if (expectedType === 'Boolean') { |
| 1404 |
valid = typeof value === (expectedType = 'boolean'); |
| 1405 |
} else if (expectedType === 'Function') { |
| 1406 |
valid = typeof value === (expectedType = 'function'); |
| 1407 |
} else if (expectedType === 'Object') { |
| 1408 |
valid = isPlainObject(value); |
| 1409 |
} else if (expectedType === 'Array') { |
| 1410 |
valid = Array.isArray(value); |
| 1411 |
} else { |
| 1412 |
valid = value instanceof type; |
| 1413 |
} |
| 1414 |
return { |
| 1415 |
valid: valid, |
| 1416 |
expectedType: expectedType |
| 1417 |
} |
| 1418 |
} |
| 1419 |
|
| 1420 |
/** |
| 1421 |
* Use function string name to check built-in types, |
| 1422 |
* because a simple equality check will fail when running |
| 1423 |
* across different vms / iframes. |
| 1424 |
*/ |
| 1425 |
function getType (fn) { |
| 1426 |
var match = fn && fn.toString().match(/^\s*function (\w+)/); |
| 1427 |
return match && match[1] |
| 1428 |
} |
| 1429 |
|
| 1430 |
function isType (type, fn) { |
| 1431 |
if (!Array.isArray(fn)) { |
| 1432 |
return getType(fn) === getType(type) |
| 1433 |
} |
| 1434 |
for (var i = 0, len = fn.length; i < len; i++) { |
| 1435 |
if (getType(fn[i]) === getType(type)) { |
| 1436 |
return true |
| 1437 |
} |
| 1438 |
} |
| 1439 |
/* istanbul ignore next */ |
| 1440 |
return false |
| 1441 |
} |
| 1442 |
|
| 1443 |
function handleError (err, vm, info) { |
| 1444 |
if (config.errorHandler) { |
| 1445 |
config.errorHandler.call(null, err, vm, info); |
| 1446 |
} else { |
| 1447 |
{ |
| 1448 |
warn(("Error in " + info + ":"), vm); |
| 1449 |
} |
| 1450 |
/* istanbul ignore else */ |
| 1451 |
if (inBrowser && typeof console !== 'undefined') { |
| 1452 |
console.error(err); |
| 1453 |
} else { |
| 1454 |
throw err |
| 1455 |
} |
| 1456 |
} |
| 1457 |
} |
| 1458 |
|
| 1459 |
/* not type checking this file because flow doesn't play well with Proxy */ |
| 1460 |
|
| 1461 |
var initProxy; |
| 1462 |
|
| 1463 |
{ |
| 1464 |
var allowedGlobals = makeMap( |
| 1465 |
'Infinity,undefined,NaN,isFinite,isNaN,' + |
| 1466 |
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' + |
| 1467 |
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' + |
| 1468 |
'require' // for Webpack/Browserify |
| 1469 |
); |
| 1470 |
|
| 1471 |
var warnNonPresent = function (target, key) { |
| 1472 |
warn( |
| 1473 |
"Property or method \"" + key + "\" is not defined on the instance but " + |
| 1474 |
"referenced during render. Make sure to declare reactive data " + |
| 1475 |
"properties in the data option.", |
| 1476 |
target |
| 1477 |
); |
| 1478 |
}; |
| 1479 |
|
| 1480 |
var hasProxy = |
| 1481 |
typeof Proxy !== 'undefined' && |
| 1482 |
Proxy.toString().match(/native code/); |
| 1483 |
|
| 1484 |
if (hasProxy) { |
| 1485 |
var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta'); |
| 1486 |
config.keyCodes = new Proxy(config.keyCodes, { |
| 1487 |
set: function set (target, key, value) { |
| 1488 |
if (isBuiltInModifier(key)) { |
| 1489 |
warn(("Avoid overwriting built-in modifier in config.keyCodes: ." + key)); |
| 1490 |
return false |
| 1491 |
} else { |
| 1492 |
target[key] = value; |
| 1493 |
return true |
| 1494 |
} |
| 1495 |
} |
| 1496 |
}); |
| 1497 |
} |
| 1498 |
|
| 1499 |
var hasHandler = { |
| 1500 |
has: function has (target, key) { |
| 1501 |
var has = key in target; |
| 1502 |
var isAllowed = allowedGlobals(key) || key.charAt(0) === '_'; |
| 1503 |
if (!has && !isAllowed) { |
| 1504 |
warnNonPresent(target, key); |
| 1505 |
} |
| 1506 |
return has || !isAllowed |
| 1507 |
} |
| 1508 |
}; |
| 1509 |
|
| 1510 |
var getHandler = { |
| 1511 |
get: function get (target, key) { |
| 1512 |
if (typeof key === 'string' && !(key in target)) { |
| 1513 |
warnNonPresent(target, key); |
| 1514 |
} |
| 1515 |
return target[key] |
| 1516 |
} |
| 1517 |
}; |
| 1518 |
|
| 1519 |
initProxy = function initProxy (vm) { |
| 1520 |
if (hasProxy) { |
| 1521 |
// determine which proxy handler to use |
| 1522 |
var options = vm.$options; |
| 1523 |
var handlers = options.render && options.render._withStripped |
| 1524 |
? getHandler |
| 1525 |
: hasHandler; |
| 1526 |
vm._renderProxy = new Proxy(vm, handlers); |
| 1527 |
} else { |
| 1528 |
vm._renderProxy = vm; |
| 1529 |
} |
| 1530 |
}; |
| 1531 |
} |
| 1532 |
|
| 1533 |
var mark; |
| 1534 |
var measure; |
| 1535 |
|
| 1536 |
{ |
| 1537 |
var perf = inBrowser && window.performance; |
| 1538 |
/* istanbul ignore if */ |
| 1539 |
if ( |
| 1540 |
perf && |
| 1541 |
perf.mark && |
| 1542 |
perf.measure && |
| 1543 |
perf.clearMarks && |
| 1544 |
perf.clearMeasures |
| 1545 |
) { |
| 1546 |
mark = function (tag) { return perf.mark(tag); }; |
| 1547 |
measure = function (name, startTag, endTag) { |
| 1548 |
perf.measure(name, startTag, endTag); |
| 1549 |
perf.clearMarks(startTag); |
| 1550 |
perf.clearMarks(endTag); |
| 1551 |
perf.clearMeasures(name); |
| 1552 |
}; |
| 1553 |
} |
| 1554 |
} |
| 1555 |
|
| 1556 |
/* */ |
| 1557 |
|
| 1558 |
var VNode = function VNode ( |
| 1559 |
tag, |
| 1560 |
data, |
| 1561 |
children, |
| 1562 |
text, |
| 1563 |
elm, |
| 1564 |
context, |
| 1565 |
componentOptions |
| 1566 |
) { |
| 1567 |
this.tag = tag; |
| 1568 |
this.data = data; |
| 1569 |
this.children = children; |
| 1570 |
this.text = text; |
| 1571 |
this.elm = elm; |
| 1572 |
this.ns = undefined; |
| 1573 |
this.context = context; |
| 1574 |
this.functionalContext = undefined; |
| 1575 |
this.key = data && data.key; |
| 1576 |
this.componentOptions = componentOptions; |
| 1577 |
this.componentInstance = undefined; |
| 1578 |
this.parent = undefined; |
| 1579 |
this.raw = false; |
| 1580 |
this.isStatic = false; |
| 1581 |
this.isRootInsert = true; |
| 1582 |
this.isComment = false; |
| 1583 |
this.isCloned = false; |
| 1584 |
this.isOnce = false; |
| 1585 |
}; |
| 1586 |
|
| 1587 |
var prototypeAccessors = { child: {} }; |
| 1588 |
|
| 1589 |
// DEPRECATED: alias for componentInstance for backwards compat. |
| 1590 |
/* istanbul ignore next */ |
| 1591 |
prototypeAccessors.child.get = function () { |
| 1592 |
return this.componentInstance |
| 1593 |
}; |
| 1594 |
|
| 1595 |
Object.defineProperties( VNode.prototype, prototypeAccessors ); |
| 1596 |
|
| 1597 |
var createEmptyVNode = function () { |
| 1598 |
var node = new VNode(); |
| 1599 |
node.text = ''; |
| 1600 |
node.isComment = true; |
| 1601 |
return node |
| 1602 |
}; |
| 1603 |
|
| 1604 |
function createTextVNode (val) { |
| 1605 |
return new VNode(undefined, undefined, undefined, String(val)) |
| 1606 |
} |
| 1607 |
|
| 1608 |
// optimized shallow clone |
| 1609 |
// used for static nodes and slot nodes because they may be reused across |
| 1610 |
// multiple renders, cloning them avoids errors when DOM manipulations rely |
| 1611 |
// on their elm reference. |
| 1612 |
function cloneVNode (vnode) { |
| 1613 |
var cloned = new VNode( |
| 1614 |
vnode.tag, |
| 1615 |
vnode.data, |
| 1616 |
vnode.children, |
| 1617 |
vnode.text, |
| 1618 |
vnode.elm, |
| 1619 |
vnode.context, |
| 1620 |
vnode.componentOptions |
| 1621 |
); |
| 1622 |
cloned.ns = vnode.ns; |
| 1623 |
cloned.isStatic = vnode.isStatic; |
| 1624 |
cloned.key = vnode.key; |
| 1625 |
cloned.isCloned = true; |
| 1626 |
return cloned |
| 1627 |
} |
| 1628 |
|
| 1629 |
function cloneVNodes (vnodes) { |
| 1630 |
var len = vnodes.length; |
| 1631 |
var res = new Array(len); |
| 1632 |
for (var i = 0; i < len; i++) { |
| 1633 |
res[i] = cloneVNode(vnodes[i]); |
| 1634 |
} |
| 1635 |
return res |
| 1636 |
} |
| 1637 |
|
| 1638 |
/* */ |
| 1639 |
|
| 1640 |
var normalizeEvent = cached(function (name) { |
| 1641 |
var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first |
| 1642 |
name = once$$1 ? name.slice(1) : name; |
| 1643 |
var capture = name.charAt(0) === '!'; |
| 1644 |
name = capture ? name.slice(1) : name; |
| 1645 |
return { |
| 1646 |
name: name, |
| 1647 |
once: once$$1, |
| 1648 |
capture: capture |
| 1649 |
} |
| 1650 |
}); |
| 1651 |
|
| 1652 |
function createFnInvoker (fns) { |
| 1653 |
function invoker () { |
| 1654 |
var arguments$1 = arguments; |
| 1655 |
|
| 1656 |
var fns = invoker.fns; |
| 1657 |
if (Array.isArray(fns)) { |
| 1658 |
for (var i = 0; i < fns.length; i++) { |
| 1659 |
fns[i].apply(null, arguments$1); |
| 1660 |
} |
| 1661 |
} else { |
| 1662 |
// return handler return value for single handlers |
| 1663 |
return fns.apply(null, arguments) |
| 1664 |
} |
| 1665 |
} |
| 1666 |
invoker.fns = fns; |
| 1667 |
return invoker |
| 1668 |
} |
| 1669 |
|
| 1670 |
function updateListeners ( |
| 1671 |
on, |
| 1672 |
oldOn, |
| 1673 |
add, |
| 1674 |
remove$$1, |
| 1675 |
vm |
| 1676 |
) { |
| 1677 |
var name, cur, old, event; |
| 1678 |
for (name in on) { |
| 1679 |
cur = on[name]; |
| 1680 |
old = oldOn[name]; |
| 1681 |
event = normalizeEvent(name); |
| 1682 |
if (!cur) { |
| 1683 |
"development" !== 'production' && warn( |
| 1684 |
"Invalid handler for event \"" + (event.name) + "\": got " + String(cur), |
| 1685 |
vm |
| 1686 |
); |
| 1687 |
} else if (!old) { |
| 1688 |
if (!cur.fns) { |
| 1689 |
cur = on[name] = createFnInvoker(cur); |
| 1690 |
} |
| 1691 |
add(event.name, cur, event.once, event.capture); |
| 1692 |
} else if (cur !== old) { |
| 1693 |
old.fns = cur; |
| 1694 |
on[name] = old; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
for (name in oldOn) { |
| 1698 |
if (!on[name]) { |
| 1699 |
event = normalizeEvent(name); |
| 1700 |
remove$$1(event.name, oldOn[name], event.capture); |
| 1701 |
} |
| 1702 |
} |
| 1703 |
} |
| 1704 |
|
| 1705 |
/* */ |
| 1706 |
|
| 1707 |
function mergeVNodeHook (def, hookKey, hook) { |
| 1708 |
var invoker; |
| 1709 |
var oldHook = def[hookKey]; |
| 1710 |
|
| 1711 |
function wrappedHook () { |
| 1712 |
hook.apply(this, arguments); |
| 1713 |
// important: remove merged hook to ensure it's called only once |
| 1714 |
// and prevent memory leak |
| 1715 |
remove(invoker.fns, wrappedHook); |
| 1716 |
} |
| 1717 |
|
| 1718 |
if (!oldHook) { |
| 1719 |
// no existing hook |
| 1720 |
invoker = createFnInvoker([wrappedHook]); |
| 1721 |
} else { |
| 1722 |
/* istanbul ignore if */ |
| 1723 |
if (oldHook.fns && oldHook.merged) { |
| 1724 |
// already a merged invoker |
| 1725 |
invoker = oldHook; |
| 1726 |
invoker.fns.push(wrappedHook); |
| 1727 |
} else { |
| 1728 |
// existing plain hook |
| 1729 |
invoker = createFnInvoker([oldHook, wrappedHook]); |
| 1730 |
} |
| 1731 |
} |
| 1732 |
|
| 1733 |
invoker.merged = true; |
| 1734 |
def[hookKey] = invoker; |
| 1735 |
} |
| 1736 |
|
| 1737 |
/* */ |
| 1738 |
|
| 1739 |
// The template compiler attempts to minimize the need for normalization by |
| 1740 |
// statically analyzing the template at compile time. |
| 1741 |
// |
| 1742 |
// For plain HTML markup, normalization can be completely skipped because the |
| 1743 |
// generated render function is guaranteed to return Array<VNode>. There are |
| 1744 |
// two cases where extra normalization is needed: |
| 1745 |
|
| 1746 |
// 1. When the children contains components - because a functional component |
| 1747 |
// may return an Array instead of a single root. In this case, just a simple |
| 1748 |
// normalization is needed - if any child is an Array, we flatten the whole |
| 1749 |
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep |
| 1750 |
// because functional components already normalize their own children. |
| 1751 |
function simpleNormalizeChildren (children) { |
| 1752 |
for (var i = 0; i < children.length; i++) { |
| 1753 |
if (Array.isArray(children[i])) { |
| 1754 |
return Array.prototype.concat.apply([], children) |
| 1755 |
} |
| 1756 |
} |
| 1757 |
return children |
| 1758 |
} |
| 1759 |
|
| 1760 |
// 2. When the children contains constructs that always generated nested Arrays, |
| 1761 |
// e.g. <template>, <slot>, v-for, or when the children is provided by user |
| 1762 |
// with hand-written render functions / JSX. In such cases a full normalization |
| 1763 |
// is needed to cater to all possible types of children values. |
| 1764 |
function normalizeChildren (children) { |
| 1765 |
return isPrimitive(children) |
| 1766 |
? [createTextVNode(children)] |
| 1767 |
: Array.isArray(children) |
| 1768 |
? normalizeArrayChildren(children) |
| 1769 |
: undefined |
| 1770 |
} |
| 1771 |
|
| 1772 |
function normalizeArrayChildren (children, nestedIndex) { |
| 1773 |
var res = []; |
| 1774 |
var i, c, last; |
| 1775 |
for (i = 0; i < children.length; i++) { |
| 1776 |
c = children[i]; |
| 1777 |
if (c == null || typeof c === 'boolean') { continue } |
| 1778 |
last = res[res.length - 1]; |
| 1779 |
// nested |
| 1780 |
if (Array.isArray(c)) { |
| 1781 |
res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); |
| 1782 |
} else if (isPrimitive(c)) { |
| 1783 |
if (last && last.text) { |
| 1784 |
last.text += String(c); |
| 1785 |
} else if (c !== '') { |
| 1786 |
// convert primitive to vnode |
| 1787 |
res.push(createTextVNode(c)); |
| 1788 |
} |
| 1789 |
} else { |
| 1790 |
if (c.text && last && last.text) { |
| 1791 |
res[res.length - 1] = createTextVNode(last.text + c.text); |
| 1792 |
} else { |
| 1793 |
// default key for nested array children (likely generated by v-for) |
| 1794 |
if (c.tag && c.key == null && nestedIndex != null) { |
| 1795 |
c.key = "__vlist" + nestedIndex + "_" + i + "__"; |
| 1796 |
} |
| 1797 |
res.push(c); |
| 1798 |
} |
| 1799 |
} |
| 1800 |
} |
| 1801 |
return res |
| 1802 |
} |
| 1803 |
|
| 1804 |
/* */ |
| 1805 |
|
| 1806 |
function getFirstComponentChild (children) { |
| 1807 |
return children && children.filter(function (c) { return c && c.componentOptions; })[0] |
| 1808 |
} |
| 1809 |
|
| 1810 |
/* */ |
| 1811 |
|
| 1812 |
function initEvents (vm) { |
| 1813 |
vm._events = Object.create(null); |
| 1814 |
vm._hasHookEvent = false; |
| 1815 |
// init parent attached events |
| 1816 |
var listeners = vm.$options._parentListeners; |
| 1817 |
if (listeners) { |
| 1818 |
updateComponentListeners(vm, listeners); |
| 1819 |
} |
| 1820 |
} |
| 1821 |
|
| 1822 |
var target; |
| 1823 |
|
| 1824 |
function add (event, fn, once$$1) { |
| 1825 |
if (once$$1) { |
| 1826 |
target.$once(event, fn); |
| 1827 |
} else { |
| 1828 |
target.$on(event, fn); |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
function remove$1 (event, fn) { |
| 1833 |
target.$off(event, fn); |
| 1834 |
} |
| 1835 |
|
| 1836 |
function updateComponentListeners ( |
| 1837 |
vm, |
| 1838 |
listeners, |
| 1839 |
oldListeners |
| 1840 |
) { |
| 1841 |
target = vm; |
| 1842 |
updateListeners(listeners, oldListeners || {}, add, remove$1, vm); |
| 1843 |
} |
| 1844 |
|
| 1845 |
function eventsMixin (Vue) { |
| 1846 |
var hookRE = /^hook:/; |
| 1847 |
Vue.prototype.$on = function (event, fn) { |
| 1848 |
var this$1 = this; |
| 1849 |
|
| 1850 |
var vm = this; |
| 1851 |
if (Array.isArray(event)) { |
| 1852 |
for (var i = 0, l = event.length; i < l; i++) { |
| 1853 |
this$1.$on(event[i], fn); |
| 1854 |
} |
| 1855 |
} else { |
| 1856 |
(vm._events[event] || (vm._events[event] = [])).push(fn); |
| 1857 |
// optimize hook:event cost by using a boolean flag marked at registration |
| 1858 |
// instead of a hash lookup |
| 1859 |
if (hookRE.test(event)) { |
| 1860 |
vm._hasHookEvent = true; |
| 1861 |
} |
| 1862 |
} |
| 1863 |
return vm |
| 1864 |
}; |
| 1865 |
|
| 1866 |
Vue.prototype.$once = function (event, fn) { |
| 1867 |
var vm = this; |
| 1868 |
function on () { |
| 1869 |
vm.$off(event, on); |
| 1870 |
fn.apply(vm, arguments); |
| 1871 |
} |
| 1872 |
on.fn = fn; |
| 1873 |
vm.$on(event, on); |
| 1874 |
return vm |
| 1875 |
}; |
| 1876 |
|
| 1877 |
Vue.prototype.$off = function (event, fn) { |
| 1878 |
var this$1 = this; |
| 1879 |
|
| 1880 |
var vm = this; |
| 1881 |
// all |
| 1882 |
if (!arguments.length) { |
| 1883 |
vm._events = Object.create(null); |
| 1884 |
return vm |
| 1885 |
} |
| 1886 |
// array of events |
| 1887 |
if (Array.isArray(event)) { |
| 1888 |
for (var i$1 = 0, l = event.length; i$1 < l; i$1++) { |
| 1889 |
this$1.$off(event[i$1], fn); |
| 1890 |
} |
| 1891 |
return vm |
| 1892 |
} |
| 1893 |
// specific event |
| 1894 |
var cbs = vm._events[event]; |
| 1895 |
if (!cbs) { |
| 1896 |
return vm |
| 1897 |
} |
| 1898 |
if (arguments.length === 1) { |
| 1899 |
vm._events[event] = null; |
| 1900 |
return vm |
| 1901 |
} |
| 1902 |
// specific handler |
| 1903 |
var cb; |
| 1904 |
var i = cbs.length; |
| 1905 |
while (i--) { |
| 1906 |
cb = cbs[i]; |
| 1907 |
if (cb === fn || cb.fn === fn) { |
| 1908 |
cbs.splice(i, 1); |
| 1909 |
break |
| 1910 |
} |
| 1911 |
} |
| 1912 |
return vm |
| 1913 |
}; |
| 1914 |
|
| 1915 |
Vue.prototype.$emit = function (event) { |
| 1916 |
var vm = this; |
| 1917 |
var cbs = vm._events[event]; |
| 1918 |
if (cbs) { |
| 1919 |
cbs = cbs.length > 1 ? toArray(cbs) : cbs; |
| 1920 |
var args = toArray(arguments, 1); |
| 1921 |
for (var i = 0, l = cbs.length; i < l; i++) { |
| 1922 |
cbs[i].apply(vm, args); |
| 1923 |
} |
| 1924 |
} |
| 1925 |
return vm |
| 1926 |
}; |
| 1927 |
} |
| 1928 |
|
| 1929 |
/* */ |
| 1930 |
|
| 1931 |
/** |
| 1932 |
* Runtime helper for resolving raw children VNodes into a slot object. |
| 1933 |
*/ |
| 1934 |
function resolveSlots ( |
| 1935 |
children, |
| 1936 |
context |
| 1937 |
) { |
| 1938 |
var slots = {}; |
| 1939 |
if (!children) { |
| 1940 |
return slots |
| 1941 |
} |
| 1942 |
var defaultSlot = []; |
| 1943 |
var name, child; |
| 1944 |
for (var i = 0, l = children.length; i < l; i++) { |
| 1945 |
child = children[i]; |
| 1946 |
// named slots should only be respected if the vnode was rendered in the |
| 1947 |
// same context. |
| 1948 |
if ((child.context === context || child.functionalContext === context) && |
| 1949 |
child.data && (name = child.data.slot)) { |
| 1950 |
var slot = (slots[name] || (slots[name] = [])); |
| 1951 |
if (child.tag === 'template') { |
| 1952 |
slot.push.apply(slot, child.children); |
| 1953 |
} else { |
| 1954 |
slot.push(child); |
| 1955 |
} |
| 1956 |
} else { |
| 1957 |
defaultSlot.push(child); |
| 1958 |
} |
| 1959 |
} |
| 1960 |
// ignore whitespace |
| 1961 |
if (!defaultSlot.every(isWhitespace)) { |
| 1962 |
slots.default = defaultSlot; |
| 1963 |
} |
| 1964 |
return slots |
| 1965 |
} |
| 1966 |
|
| 1967 |
function isWhitespace (node) { |
| 1968 |
return node.isComment || node.text === ' ' |
| 1969 |
} |
| 1970 |
|
| 1971 |
function resolveScopedSlots ( |
| 1972 |
fns |
| 1973 |
) { |
| 1974 |
var res = {}; |
| 1975 |
for (var i = 0; i < fns.length; i++) { |
| 1976 |
res[fns[i][0]] = fns[i][1]; |
| 1977 |
} |
| 1978 |
return res |
| 1979 |
} |
| 1980 |
|
| 1981 |
/* */ |
| 1982 |
|
| 1983 |
var activeInstance = null; |
| 1984 |
|
| 1985 |
function initLifecycle (vm) { |
| 1986 |
var options = vm.$options; |
| 1987 |
|
| 1988 |
// locate first non-abstract parent |
| 1989 |
var parent = options.parent; |
| 1990 |
if (parent && !options.abstract) { |
| 1991 |
while (parent.$options.abstract && parent.$parent) { |
| 1992 |
parent = parent.$parent; |
| 1993 |
} |
| 1994 |
parent.$children.push(vm); |
| 1995 |
} |
| 1996 |
|
| 1997 |
vm.$parent = parent; |
| 1998 |
vm.$root = parent ? parent.$root : vm; |
| 1999 |
|
| 2000 |
vm.$children = []; |
| 2001 |
vm.$refs = {}; |
| 2002 |
|
| 2003 |
vm._watcher = null; |
| 2004 |
vm._inactive = null; |
| 2005 |
vm._directInactive = false; |
| 2006 |
vm._isMounted = false; |
| 2007 |
vm._isDestroyed = false; |
| 2008 |
vm._isBeingDestroyed = false; |
| 2009 |
} |
| 2010 |
|
| 2011 |
function lifecycleMixin (Vue) { |
| 2012 |
Vue.prototype._update = function (vnode, hydrating) { |
| 2013 |
var vm = this; |
| 2014 |
if (vm._isMounted) { |
| 2015 |
callHook(vm, 'beforeUpdate'); |
| 2016 |
} |
| 2017 |
var prevEl = vm.$el; |
| 2018 |
var prevVnode = vm._vnode; |
| 2019 |
var prevActiveInstance = activeInstance; |
| 2020 |
activeInstance = vm; |
| 2021 |
vm._vnode = vnode; |
| 2022 |
// Vue.prototype.__patch__ is injected in entry points |
| 2023 |
// based on the rendering backend used. |
| 2024 |
if (!prevVnode) { |
| 2025 |
// initial render |
| 2026 |
vm.$el = vm.__patch__( |
| 2027 |
vm.$el, vnode, hydrating, false /* removeOnly */, |
| 2028 |
vm.$options._parentElm, |
| 2029 |
vm.$options._refElm |
| 2030 |
); |
| 2031 |
} else { |
| 2032 |
// updates |
| 2033 |
vm.$el = vm.__patch__(prevVnode, vnode); |
| 2034 |
} |
| 2035 |
activeInstance = prevActiveInstance; |
| 2036 |
// update __vue__ reference |
| 2037 |
if (prevEl) { |
| 2038 |
prevEl.__vue__ = null; |
| 2039 |
} |
| 2040 |
if (vm.$el) { |
| 2041 |
vm.$el.__vue__ = vm; |
| 2042 |
} |
| 2043 |
// if parent is an HOC, update its $el as well |
| 2044 |
if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) { |
| 2045 |
vm.$parent.$el = vm.$el; |
| 2046 |
} |
| 2047 |
// updated hook is called by the scheduler to ensure that children are |
| 2048 |
// updated in a parent's updated hook. |
| 2049 |
}; |
| 2050 |
|
| 2051 |
Vue.prototype.$forceUpdate = function () { |
| 2052 |
var vm = this; |
| 2053 |
if (vm._watcher) { |
| 2054 |
vm._watcher.update(); |
| 2055 |
} |
| 2056 |
}; |
| 2057 |
|
| 2058 |
Vue.prototype.$destroy = function () { |
| 2059 |
var vm = this; |
| 2060 |
if (vm._isBeingDestroyed) { |
| 2061 |
return |
| 2062 |
} |
| 2063 |
callHook(vm, 'beforeDestroy'); |
| 2064 |
vm._isBeingDestroyed = true; |
| 2065 |
// remove self from parent |
| 2066 |
var parent = vm.$parent; |
| 2067 |
if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) { |
| 2068 |
remove(parent.$children, vm); |
| 2069 |
} |
| 2070 |
// teardown watchers |
| 2071 |
if (vm._watcher) { |
| 2072 |
vm._watcher.teardown(); |
| 2073 |
} |
| 2074 |
var i = vm._watchers.length; |
| 2075 |
while (i--) { |
| 2076 |
vm._watchers[i].teardown(); |
| 2077 |
} |
| 2078 |
// remove reference from data ob |
| 2079 |
// frozen object may not have observer. |
| 2080 |
if (vm._data.__ob__) { |
| 2081 |
vm._data.__ob__.vmCount--; |
| 2082 |
} |
| 2083 |
// call the last hook... |
| 2084 |
vm._isDestroyed = true; |
| 2085 |
callHook(vm, 'destroyed'); |
| 2086 |
// turn off all instance listeners. |
| 2087 |
vm.$off(); |
| 2088 |
// remove __vue__ reference |
| 2089 |
if (vm.$el) { |
| 2090 |
vm.$el.__vue__ = null; |
| 2091 |
} |
| 2092 |
// invoke destroy hooks on current rendered tree |
| 2093 |
vm.__patch__(vm._vnode, null); |
| 2094 |
}; |
| 2095 |
} |
| 2096 |
|
| 2097 |
function mountComponent ( |
| 2098 |
vm, |
| 2099 |
el, |
| 2100 |
hydrating |
| 2101 |
) { |
| 2102 |
vm.$el = el; |
| 2103 |
if (!vm.$options.render) { |
| 2104 |
vm.$options.render = createEmptyVNode; |
| 2105 |
{ |
| 2106 |
/* istanbul ignore if */ |
| 2107 |
if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') || |
| 2108 |
vm.$options.el || el) { |
| 2109 |
warn( |
| 2110 |
'You are using the runtime-only build of Vue where the template ' + |
| 2111 |
'compiler is not available. Either pre-compile the templates into ' + |
| 2112 |
'render functions, or use the compiler-included build.', |
| 2113 |
vm |
| 2114 |
); |
| 2115 |
} else { |
| 2116 |
warn( |
| 2117 |
'Failed to mount component: template or render function not defined.', |
| 2118 |
vm |
| 2119 |
); |
| 2120 |
} |
| 2121 |
} |
| 2122 |
} |
| 2123 |
callHook(vm, 'beforeMount'); |
| 2124 |
|
| 2125 |
var updateComponent; |
| 2126 |
/* istanbul ignore if */ |
| 2127 |
if ("development" !== 'production' && config.performance && mark) { |
| 2128 |
updateComponent = function () { |
| 2129 |
var name = vm._name; |
| 2130 |
var id = vm._uid; |
| 2131 |
var startTag = "vue-perf-start:" + id; |
| 2132 |
var endTag = "vue-perf-end:" + id; |
| 2133 |
|
| 2134 |
mark(startTag); |
| 2135 |
var vnode = vm._render(); |
| 2136 |
mark(endTag); |
| 2137 |
measure((name + " render"), startTag, endTag); |
| 2138 |
|
| 2139 |
mark(startTag); |
| 2140 |
vm._update(vnode, hydrating); |
| 2141 |
mark(endTag); |
| 2142 |
measure((name + " patch"), startTag, endTag); |
| 2143 |
}; |
| 2144 |
} else { |
| 2145 |
updateComponent = function () { |
| 2146 |
vm._update(vm._render(), hydrating); |
| 2147 |
}; |
| 2148 |
} |
| 2149 |
|
| 2150 |
vm._watcher = new Watcher(vm, updateComponent, noop); |
| 2151 |
hydrating = false; |
| 2152 |
|
| 2153 |
// manually mounted instance, call mounted on self |
| 2154 |
// mounted is called for render-created child components in its inserted hook |
| 2155 |
if (vm.$vnode == null) { |
| 2156 |
vm._isMounted = true; |
| 2157 |
callHook(vm, 'mounted'); |
| 2158 |
} |
| 2159 |
return vm |
| 2160 |
} |
| 2161 |
|
| 2162 |
function updateChildComponent ( |
| 2163 |
vm, |
| 2164 |
propsData, |
| 2165 |
listeners, |
| 2166 |
parentVnode, |
| 2167 |
renderChildren |
| 2168 |
) { |
| 2169 |
// determine whether component has slot children |
| 2170 |
// we need to do this before overwriting $options._renderChildren |
| 2171 |
var hasChildren = !!( |
| 2172 |
renderChildren || // has new static slots |
| 2173 |
vm.$options._renderChildren || // has old static slots |
| 2174 |
parentVnode.data.scopedSlots || // has new scoped slots |
| 2175 |
vm.$scopedSlots !== emptyObject // has old scoped slots |
| 2176 |
); |
| 2177 |
|
| 2178 |
vm.$options._parentVnode = parentVnode; |
| 2179 |
vm.$vnode = parentVnode; // update vm's placeholder node without re-render |
| 2180 |
if (vm._vnode) { // update child tree's parent |
| 2181 |
vm._vnode.parent = parentVnode; |
| 2182 |
} |
| 2183 |
vm.$options._renderChildren = renderChildren; |
| 2184 |
|
| 2185 |
// update props |
| 2186 |
if (propsData && vm.$options.props) { |
| 2187 |
observerState.shouldConvert = false; |
| 2188 |
{ |
| 2189 |
observerState.isSettingProps = true; |
| 2190 |
} |
| 2191 |
var props = vm._props; |
| 2192 |
var propKeys = vm.$options._propKeys || []; |
| 2193 |
for (var i = 0; i < propKeys.length; i++) { |
| 2194 |
var key = propKeys[i]; |
| 2195 |
props[key] = validateProp(key, vm.$options.props, propsData, vm); |
| 2196 |
} |
| 2197 |
observerState.shouldConvert = true; |
| 2198 |
{ |
| 2199 |
observerState.isSettingProps = false; |
| 2200 |
} |
| 2201 |
// keep a copy of raw propsData |
| 2202 |
vm.$options.propsData = propsData; |
| 2203 |
} |
| 2204 |
// update listeners |
| 2205 |
if (listeners) { |
| 2206 |
var oldListeners = vm.$options._parentListeners; |
| 2207 |
vm.$options._parentListeners = listeners; |
| 2208 |
updateComponentListeners(vm, listeners, oldListeners); |
| 2209 |
} |
| 2210 |
// resolve slots + force update if has children |
| 2211 |
if (hasChildren) { |
| 2212 |
vm.$slots = resolveSlots(renderChildren, parentVnode.context); |
| 2213 |
vm.$forceUpdate(); |
| 2214 |
} |
| 2215 |
} |
| 2216 |
|
| 2217 |
function isInInactiveTree (vm) { |
| 2218 |
while (vm && (vm = vm.$parent)) { |
| 2219 |
if (vm._inactive) { return true } |
| 2220 |
} |
| 2221 |
return false |
| 2222 |
} |
| 2223 |
|
| 2224 |
function activateChildComponent (vm, direct) { |
| 2225 |
if (direct) { |
| 2226 |
vm._directInactive = false; |
| 2227 |
if (isInInactiveTree(vm)) { |
| 2228 |
return |
| 2229 |
} |
| 2230 |
} else if (vm._directInactive) { |
| 2231 |
return |
| 2232 |
} |
| 2233 |
if (vm._inactive || vm._inactive == null) { |
| 2234 |
vm._inactive = false; |
| 2235 |
for (var i = 0; i < vm.$children.length; i++) { |
| 2236 |
activateChildComponent(vm.$children[i]); |
| 2237 |
} |
| 2238 |
callHook(vm, 'activated'); |
| 2239 |
} |
| 2240 |
} |
| 2241 |
|
| 2242 |
function deactivateChildComponent (vm, direct) { |
| 2243 |
if (direct) { |
| 2244 |
vm._directInactive = true; |
| 2245 |
if (isInInactiveTree(vm)) { |
| 2246 |
return |
| 2247 |
} |
| 2248 |
} |
| 2249 |
if (!vm._inactive) { |
| 2250 |
vm._inactive = true; |
| 2251 |
for (var i = 0; i < vm.$children.length; i++) { |
| 2252 |
deactivateChildComponent(vm.$children[i]); |
| 2253 |
} |
| 2254 |
callHook(vm, 'deactivated'); |
| 2255 |
} |
| 2256 |
} |
| 2257 |
|
| 2258 |
function callHook (vm, hook) { |
| 2259 |
var handlers = vm.$options[hook]; |
| 2260 |
if (handlers) { |
| 2261 |
for (var i = 0, j = handlers.length; i < j; i++) { |
| 2262 |
try { |
| 2263 |
handlers[i].call(vm); |
| 2264 |
} catch (e) { |
| 2265 |
handleError(e, vm, (hook + " hook")); |
| 2266 |
} |
| 2267 |
} |
| 2268 |
} |
| 2269 |
if (vm._hasHookEvent) { |
| 2270 |
vm.$emit('hook:' + hook); |
| 2271 |
} |
| 2272 |
} |
| 2273 |
|
| 2274 |
/* */ |
| 2275 |
|
| 2276 |
|
| 2277 |
var queue = []; |
| 2278 |
var has = {}; |
| 2279 |
var circular = {}; |
| 2280 |
var waiting = false; |
| 2281 |
var flushing = false; |
| 2282 |
var index = 0; |
| 2283 |
|
| 2284 |
/** |
| 2285 |
* Reset the scheduler's state. |
| 2286 |
*/ |
| 2287 |
function resetSchedulerState () { |
| 2288 |
queue.length = 0; |
| 2289 |
has = {}; |
| 2290 |
{ |
| 2291 |
circular = {}; |
| 2292 |
} |
| 2293 |
waiting = flushing = false; |
| 2294 |
} |
| 2295 |
|
| 2296 |
/** |
| 2297 |
* Flush both queues and run the watchers. |
| 2298 |
*/ |
| 2299 |
function flushSchedulerQueue () { |
| 2300 |
flushing = true; |
| 2301 |
var watcher, id, vm; |
| 2302 |
|
| 2303 |
// Sort queue before flush. |
| 2304 |
// This ensures that: |
| 2305 |
// 1. Components are updated from parent to child. (because parent is always |
| 2306 |
// created before the child) |
| 2307 |
// 2. A component's user watchers are run before its render watcher (because |
| 2308 |
// user watchers are created before the render watcher) |
| 2309 |
// 3. If a component is destroyed during a parent component's watcher run, |
| 2310 |
// its watchers can be skipped. |
| 2311 |
queue.sort(function (a, b) { return a.id - b.id; }); |
| 2312 |
|
| 2313 |
// do not cache length because more watchers might be pushed |
| 2314 |
// as we run existing watchers |
| 2315 |
for (index = 0; index < queue.length; index++) { |
| 2316 |
watcher = queue[index]; |
| 2317 |
id = watcher.id; |
| 2318 |
has[id] = null; |
| 2319 |
watcher.run(); |
| 2320 |
// in dev build, check and stop circular updates. |
| 2321 |
if ("development" !== 'production' && has[id] != null) { |
| 2322 |
circular[id] = (circular[id] || 0) + 1; |
| 2323 |
if (circular[id] > config._maxUpdateCount) { |
| 2324 |
warn( |
| 2325 |
'You may have an infinite update loop ' + ( |
| 2326 |
watcher.user |
| 2327 |
? ("in watcher with expression \"" + (watcher.expression) + "\"") |
| 2328 |
: "in a component render function." |
| 2329 |
), |
| 2330 |
watcher.vm |
| 2331 |
); |
| 2332 |
break |
| 2333 |
} |
| 2334 |
} |
| 2335 |
} |
| 2336 |
|
| 2337 |
// call updated hooks |
| 2338 |
index = queue.length; |
| 2339 |
while (index--) { |
| 2340 |
watcher = queue[index]; |
| 2341 |
vm = watcher.vm; |
| 2342 |
if (vm._watcher === watcher && vm._isMounted) { |
| 2343 |
callHook(vm, 'updated'); |
| 2344 |
} |
| 2345 |
} |
| 2346 |
|
| 2347 |
// devtool hook |
| 2348 |
/* istanbul ignore if */ |
| 2349 |
if (devtools && config.devtools) { |
| 2350 |
devtools.emit('flush'); |
| 2351 |
} |
| 2352 |
|
| 2353 |
resetSchedulerState(); |
| 2354 |
} |
| 2355 |
|
| 2356 |
/** |
| 2357 |
* Push a watcher into the watcher queue. |
| 2358 |
* Jobs with duplicate IDs will be skipped unless it's |
| 2359 |
* pushed when the queue is being flushed. |
| 2360 |
*/ |
| 2361 |
function queueWatcher (watcher) { |
| 2362 |
var id = watcher.id; |
| 2363 |
if (has[id] == null) { |
| 2364 |
has[id] = true; |
| 2365 |
if (!flushing) { |
| 2366 |
queue.push(watcher); |
| 2367 |
} else { |
| 2368 |
// if already flushing, splice the watcher based on its id |
| 2369 |
// if already past its id, it will be run next immediately. |
| 2370 |
var i = queue.length - 1; |
| 2371 |
while (i >= 0 && queue[i].id > watcher.id) { |
| 2372 |
i--; |
| 2373 |
} |
| 2374 |
queue.splice(Math.max(i, index) + 1, 0, watcher); |
| 2375 |
} |
| 2376 |
// queue the flush |
| 2377 |
if (!waiting) { |
| 2378 |
waiting = true; |
| 2379 |
nextTick(flushSchedulerQueue); |
| 2380 |
} |
| 2381 |
} |
| 2382 |
} |
| 2383 |
|
| 2384 |
/* */ |
| 2385 |
|
| 2386 |
var uid$2 = 0; |
| 2387 |
|
| 2388 |
/** |
| 2389 |
* A watcher parses an expression, collects dependencies, |
| 2390 |
* and fires callback when the expression value changes. |
| 2391 |
* This is used for both the $watch() api and directives. |
| 2392 |
*/ |
| 2393 |
var Watcher = function Watcher ( |
| 2394 |
vm, |
| 2395 |
expOrFn, |
| 2396 |
cb, |
| 2397 |
options |
| 2398 |
) { |
| 2399 |
this.vm = vm; |
| 2400 |
vm._watchers.push(this); |
| 2401 |
// options |
| 2402 |
if (options) { |
| 2403 |
this.deep = !!options.deep; |
| 2404 |
this.user = !!options.user; |
| 2405 |
this.lazy = !!options.lazy; |
| 2406 |
this.sync = !!options.sync; |
| 2407 |
} else { |
| 2408 |
this.deep = this.user = this.lazy = this.sync = false; |
| 2409 |
} |
| 2410 |
this.cb = cb; |
| 2411 |
this.id = ++uid$2; // uid for batching |
| 2412 |
this.active = true; |
| 2413 |
this.dirty = this.lazy; // for lazy watchers |
| 2414 |
this.deps = []; |
| 2415 |
this.newDeps = []; |
| 2416 |
this.depIds = new _Set(); |
| 2417 |
this.newDepIds = new _Set(); |
| 2418 |
this.expression = expOrFn.toString(); |
| 2419 |
// parse expression for getter |
| 2420 |
if (typeof expOrFn === 'function') { |
| 2421 |
this.getter = expOrFn; |
| 2422 |
} else { |
| 2423 |
this.getter = parsePath(expOrFn); |
| 2424 |
if (!this.getter) { |
| 2425 |
this.getter = function () {}; |
| 2426 |
"development" !== 'production' && warn( |
| 2427 |
"Failed watching path: \"" + expOrFn + "\" " + |
| 2428 |
'Watcher only accepts simple dot-delimited paths. ' + |
| 2429 |
'For full control, use a function instead.', |
| 2430 |
vm |
| 2431 |
); |
| 2432 |
} |
| 2433 |
} |
| 2434 |
this.value = this.lazy |
| 2435 |
? undefined |
| 2436 |
: this.get(); |
| 2437 |
}; |
| 2438 |
|
| 2439 |
/** |
| 2440 |
* Evaluate the getter, and re-collect dependencies. |
| 2441 |
*/ |
| 2442 |
Watcher.prototype.get = function get () { |
| 2443 |
pushTarget(this); |
| 2444 |
var value; |
| 2445 |
var vm = this.vm; |
| 2446 |
if (this.user) { |
| 2447 |
try { |
| 2448 |
value = this.getter.call(vm, vm); |
| 2449 |
} catch (e) { |
| 2450 |
handleError(e, vm, ("getter for watcher \"" + (this.expression) + "\"")); |
| 2451 |
} |
| 2452 |
} else { |
| 2453 |
value = this.getter.call(vm, vm); |
| 2454 |
} |
| 2455 |
// "touch" every property so they are all tracked as |
| 2456 |
// dependencies for deep watching |
| 2457 |
if (this.deep) { |
| 2458 |
traverse(value); |
| 2459 |
} |
| 2460 |
popTarget(); |
| 2461 |
this.cleanupDeps(); |
| 2462 |
return value |
| 2463 |
}; |
| 2464 |
|
| 2465 |
/** |
| 2466 |
* Add a dependency to this directive. |
| 2467 |
*/ |
| 2468 |
Watcher.prototype.addDep = function addDep (dep) { |
| 2469 |
var id = dep.id; |
| 2470 |
if (!this.newDepIds.has(id)) { |
| 2471 |
this.newDepIds.add(id); |
| 2472 |
this.newDeps.push(dep); |
| 2473 |
if (!this.depIds.has(id)) { |
| 2474 |
dep.addSub(this); |
| 2475 |
} |
| 2476 |
} |
| 2477 |
}; |
| 2478 |
|
| 2479 |
/** |
| 2480 |
* Clean up for dependency collection. |
| 2481 |
*/ |
| 2482 |
Watcher.prototype.cleanupDeps = function cleanupDeps () { |
| 2483 |
var this$1 = this; |
| 2484 |
|
| 2485 |
var i = this.deps.length; |
| 2486 |
while (i--) { |
| 2487 |
var dep = this$1.deps[i]; |
| 2488 |
if (!this$1.newDepIds.has(dep.id)) { |
| 2489 |
dep.removeSub(this$1); |
| 2490 |
} |
| 2491 |
} |
| 2492 |
var tmp = this.depIds; |
| 2493 |
this.depIds = this.newDepIds; |
| 2494 |
this.newDepIds = tmp; |
| 2495 |
this.newDepIds.clear(); |
| 2496 |
tmp = this.deps; |
| 2497 |
this.deps = this.newDeps; |
| 2498 |
this.newDeps = tmp; |
| 2499 |
this.newDeps.length = 0; |
| 2500 |
}; |
| 2501 |
|
| 2502 |
/** |
| 2503 |
* Subscriber interface. |
| 2504 |
* Will be called when a dependency changes. |
| 2505 |
*/ |
| 2506 |
Watcher.prototype.update = function update () { |
| 2507 |
/* istanbul ignore else */ |
| 2508 |
if (this.lazy) { |
| 2509 |
this.dirty = true; |
| 2510 |
} else if (this.sync) { |
| 2511 |
this.run(); |
| 2512 |
} else { |
| 2513 |
queueWatcher(this); |
| 2514 |
} |
| 2515 |
}; |
| 2516 |
|
| 2517 |
/** |
| 2518 |
* Scheduler job interface. |
| 2519 |
* Will be called by the scheduler. |
| 2520 |
*/ |
| 2521 |
Watcher.prototype.run = function run () { |
| 2522 |
if (this.active) { |
| 2523 |
var value = this.get(); |
| 2524 |
if ( |
| 2525 |
value !== this.value || |
| 2526 |
// Deep watchers and watchers on Object/Arrays should fire even |
| 2527 |
// when the value is the same, because the value may |
| 2528 |
// have mutated. |
| 2529 |
isObject(value) || |
| 2530 |
this.deep |
| 2531 |
) { |
| 2532 |
// set new value |
| 2533 |
var oldValue = this.value; |
| 2534 |
this.value = value; |
| 2535 |
if (this.user) { |
| 2536 |
try { |
| 2537 |
this.cb.call(this.vm, value, oldValue); |
| 2538 |
} catch (e) { |
| 2539 |
handleError(e, this.vm, ("callback for watcher \"" + (this.expression) + "\"")); |
| 2540 |
} |
| 2541 |
} else { |
| 2542 |
this.cb.call(this.vm, value, oldValue); |
| 2543 |
} |
| 2544 |
} |
| 2545 |
} |
| 2546 |
}; |
| 2547 |
|
| 2548 |
/** |
| 2549 |
* Evaluate the value of the watcher. |
| 2550 |
* This only gets called for lazy watchers. |
| 2551 |
*/ |
| 2552 |
Watcher.prototype.evaluate = function evaluate () { |
| 2553 |
this.value = this.get(); |
| 2554 |
this.dirty = false; |
| 2555 |
}; |
| 2556 |
|
| 2557 |
/** |
| 2558 |
* Depend on all deps collected by this watcher. |
| 2559 |
*/ |
| 2560 |
Watcher.prototype.depend = function depend () { |
| 2561 |
var this$1 = this; |
| 2562 |
|
| 2563 |
var i = this.deps.length; |
| 2564 |
while (i--) { |
| 2565 |
this$1.deps[i].depend(); |
| 2566 |
} |
| 2567 |
}; |
| 2568 |
|
| 2569 |
/** |
| 2570 |
* Remove self from all dependencies' subscriber list. |
| 2571 |
*/ |
| 2572 |
Watcher.prototype.teardown = function teardown () { |
| 2573 |
var this$1 = this; |
| 2574 |
|
| 2575 |
if (this.active) { |
| 2576 |
// remove self from vm's watcher list |
| 2577 |
// this is a somewhat expensive operation so we skip it |
| 2578 |
// if the vm is being destroyed. |
| 2579 |
if (!this.vm._isBeingDestroyed) { |
| 2580 |
remove(this.vm._watchers, this); |
| 2581 |
} |
| 2582 |
var i = this.deps.length; |
| 2583 |
while (i--) { |
| 2584 |
this$1.deps[i].removeSub(this$1); |
| 2585 |
} |
| 2586 |
this.active = false; |
| 2587 |
} |
| 2588 |
}; |
| 2589 |
|
| 2590 |
/** |
| 2591 |
* Recursively traverse an object to evoke all converted |
| 2592 |
* getters, so that every nested property inside the object |
| 2593 |
* is collected as a "deep" dependency. |
| 2594 |
*/ |
| 2595 |
var seenObjects = new _Set(); |
| 2596 |
function traverse (val) { |
| 2597 |
seenObjects.clear(); |
| 2598 |
_traverse(val, seenObjects); |
| 2599 |
} |
| 2600 |
|
| 2601 |
function _traverse (val, seen) { |
| 2602 |
var i, keys; |
| 2603 |
var isA = Array.isArray(val); |
| 2604 |
if ((!isA && !isObject(val)) || !Object.isExtensible(val)) { |
| 2605 |
return |
| 2606 |
} |
| 2607 |
if (val.__ob__) { |
| 2608 |
var depId = val.__ob__.dep.id; |
| 2609 |
if (seen.has(depId)) { |
| 2610 |
return |
| 2611 |
} |
| 2612 |
seen.add(depId); |
| 2613 |
} |
| 2614 |
if (isA) { |
| 2615 |
i = val.length; |
| 2616 |
while (i--) { _traverse(val[i], seen); } |
| 2617 |
} else { |
| 2618 |
keys = Object.keys(val); |
| 2619 |
i = keys.length; |
| 2620 |
while (i--) { _traverse(val[keys[i]], seen); } |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
/* */ |
| 2625 |
|
| 2626 |
var sharedPropertyDefinition = { |
| 2627 |
enumerable: true, |
| 2628 |
configurable: true, |
| 2629 |
get: noop, |
| 2630 |
set: noop |
| 2631 |
}; |
| 2632 |
|
| 2633 |
function proxy (target, sourceKey, key) { |
| 2634 |
sharedPropertyDefinition.get = function proxyGetter () { |
| 2635 |
return this[sourceKey][key] |
| 2636 |
}; |
| 2637 |
sharedPropertyDefinition.set = function proxySetter (val) { |
| 2638 |
this[sourceKey][key] = val; |
| 2639 |
}; |
| 2640 |
Object.defineProperty(target, key, sharedPropertyDefinition); |
| 2641 |
} |
| 2642 |
|
| 2643 |
function initState (vm) { |
| 2644 |
vm._watchers = []; |
| 2645 |
var opts = vm.$options; |
| 2646 |
if (opts.props) { initProps(vm, opts.props); } |
| 2647 |
if (opts.methods) { initMethods(vm, opts.methods); } |
| 2648 |
if (opts.data) { |
| 2649 |
initData(vm); |
| 2650 |
} else { |
| 2651 |
observe(vm._data = {}, true /* asRootData */); |
| 2652 |
} |
| 2653 |
if (opts.computed) { initComputed(vm, opts.computed); } |
| 2654 |
if (opts.watch) { initWatch(vm, opts.watch); } |
| 2655 |
} |
| 2656 |
|
| 2657 |
var isReservedProp = { key: 1, ref: 1, slot: 1 }; |
| 2658 |
|
| 2659 |
function initProps (vm, propsOptions) { |
| 2660 |
var propsData = vm.$options.propsData || {}; |
| 2661 |
var props = vm._props = {}; |
| 2662 |
// cache prop keys so that future props updates can iterate using Array |
| 2663 |
// instead of dynamic object key enumeration. |
| 2664 |
var keys = vm.$options._propKeys = []; |
| 2665 |
var isRoot = !vm.$parent; |
| 2666 |
// root instance props should be converted |
| 2667 |
observerState.shouldConvert = isRoot; |
| 2668 |
var loop = function ( key ) { |
| 2669 |
keys.push(key); |
| 2670 |
var value = validateProp(key, propsOptions, propsData, vm); |
| 2671 |
/* istanbul ignore else */ |
| 2672 |
{ |
| 2673 |
if (isReservedProp[key]) { |
| 2674 |
warn( |
| 2675 |
("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), |
| 2676 |
vm |
| 2677 |
); |
| 2678 |
} |
| 2679 |
defineReactive$$1(props, key, value, function () { |
| 2680 |
if (vm.$parent && !observerState.isSettingProps) { |
| 2681 |
warn( |
| 2682 |
"Avoid mutating a prop directly since the value will be " + |
| 2683 |
"overwritten whenever the parent component re-renders. " + |
| 2684 |
"Instead, use a data or computed property based on the prop's " + |
| 2685 |
"value. Prop being mutated: \"" + key + "\"", |
| 2686 |
vm |
| 2687 |
); |
| 2688 |
} |
| 2689 |
}); |
| 2690 |
} |
| 2691 |
// static props are already proxied on the component's prototype |
| 2692 |
// during Vue.extend(). We only need to proxy props defined at |
| 2693 |
// instantiation here. |
| 2694 |
if (!(key in vm)) { |
| 2695 |
proxy(vm, "_props", key); |
| 2696 |
} |
| 2697 |
}; |
| 2698 |
|
| 2699 |
for (var key in propsOptions) loop( key ); |
| 2700 |
observerState.shouldConvert = true; |
| 2701 |
} |
| 2702 |
|
| 2703 |
function initData (vm) { |
| 2704 |
var data = vm.$options.data; |
| 2705 |
data = vm._data = typeof data === 'function' |
| 2706 |
? data.call(vm) |
| 2707 |
: data || {}; |
| 2708 |
if (!isPlainObject(data)) { |
| 2709 |
data = {}; |
| 2710 |
"development" !== 'production' && warn( |
| 2711 |
'data functions should return an object:\n' + |
| 2712 |
'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', |
| 2713 |
vm |
| 2714 |
); |
| 2715 |
} |
| 2716 |
// proxy data on instance |
| 2717 |
var keys = Object.keys(data); |
| 2718 |
var props = vm.$options.props; |
| 2719 |
var i = keys.length; |
| 2720 |
while (i--) { |
| 2721 |
if (props && hasOwn(props, keys[i])) { |
| 2722 |
"development" !== 'production' && warn( |
| 2723 |
"The data property \"" + (keys[i]) + "\" is already declared as a prop. " + |
| 2724 |
"Use prop default value instead.", |
| 2725 |
vm |
| 2726 |
); |
| 2727 |
} else if (!isReserved(keys[i])) { |
| 2728 |
proxy(vm, "_data", keys[i]); |
| 2729 |
} |
| 2730 |
} |
| 2731 |
// observe data |
| 2732 |
observe(data, true /* asRootData */); |
| 2733 |
} |
| 2734 |
|
| 2735 |
var computedWatcherOptions = { lazy: true }; |
| 2736 |
|
| 2737 |
function initComputed (vm, computed) { |
| 2738 |
var watchers = vm._computedWatchers = Object.create(null); |
| 2739 |
|
| 2740 |
for (var key in computed) { |
| 2741 |
var userDef = computed[key]; |
| 2742 |
var getter = typeof userDef === 'function' ? userDef : userDef.get; |
| 2743 |
// create internal watcher for the computed property. |
| 2744 |
watchers[key] = new Watcher(vm, getter, noop, computedWatcherOptions); |
| 2745 |
|
| 2746 |
// component-defined computed properties are already defined on the |
| 2747 |
// component prototype. We only need to define computed properties defined |
| 2748 |
// at instantiation here. |
| 2749 |
if (!(key in vm)) { |
| 2750 |
defineComputed(vm, key, userDef); |
| 2751 |
} |
| 2752 |
} |
| 2753 |
} |
| 2754 |
|
| 2755 |
function defineComputed (target, key, userDef) { |
| 2756 |
if (typeof userDef === 'function') { |
| 2757 |
sharedPropertyDefinition.get = createComputedGetter(key); |
| 2758 |
sharedPropertyDefinition.set = noop; |
| 2759 |
} else { |
| 2760 |
sharedPropertyDefinition.get = userDef.get |
| 2761 |
? userDef.cache !== false |
| 2762 |
? createComputedGetter(key) |
| 2763 |
: userDef.get |
| 2764 |
: noop; |
| 2765 |
sharedPropertyDefinition.set = userDef.set |
| 2766 |
? userDef.set |
| 2767 |
: noop; |
| 2768 |
} |
| 2769 |
Object.defineProperty(target, key, sharedPropertyDefinition); |
| 2770 |
} |
| 2771 |
|
| 2772 |
function createComputedGetter (key) { |
| 2773 |
return function computedGetter () { |
| 2774 |
var watcher = this._computedWatchers && this._computedWatchers[key]; |
| 2775 |
if (watcher) { |
| 2776 |
if (watcher.dirty) { |
| 2777 |
watcher.evaluate(); |
| 2778 |
} |
| 2779 |
if (Dep.target) { |
| 2780 |
watcher.depend(); |
| 2781 |
} |
| 2782 |
return watcher.value |
| 2783 |
} |
| 2784 |
} |
| 2785 |
} |
| 2786 |
|
| 2787 |
function initMethods (vm, methods) { |
| 2788 |
var props = vm.$options.props; |
| 2789 |
for (var key in methods) { |
| 2790 |
vm[key] = methods[key] == null ? noop : bind(methods[key], vm); |
| 2791 |
{ |
| 2792 |
if (methods[key] == null) { |
| 2793 |
warn( |
| 2794 |
"method \"" + key + "\" has an undefined value in the component definition. " + |
| 2795 |
"Did you reference the function correctly?", |
| 2796 |
vm |
| 2797 |
); |
| 2798 |
} |
| 2799 |
if (props && hasOwn(props, key)) { |
| 2800 |
warn( |
| 2801 |
("method \"" + key + "\" has already been defined as a prop."), |
| 2802 |
vm |
| 2803 |
); |
| 2804 |
} |
| 2805 |
} |
| 2806 |
} |
| 2807 |
} |
| 2808 |
|
| 2809 |
function initWatch (vm, watch) { |
| 2810 |
for (var key in watch) { |
| 2811 |
var handler = watch[key]; |
| 2812 |
if (Array.isArray(handler)) { |
| 2813 |
for (var i = 0; i < handler.length; i++) { |
| 2814 |
createWatcher(vm, key, handler[i]); |
| 2815 |
} |
| 2816 |
} else { |
| 2817 |
createWatcher(vm, key, handler); |
| 2818 |
} |
| 2819 |
} |
| 2820 |
} |
| 2821 |
|
| 2822 |
function createWatcher (vm, key, handler) { |
| 2823 |
var options; |
| 2824 |
if (isPlainObject(handler)) { |
| 2825 |
options = handler; |
| 2826 |
handler = handler.handler; |
| 2827 |
} |
| 2828 |
if (typeof handler === 'string') { |
| 2829 |
handler = vm[handler]; |
| 2830 |
} |
| 2831 |
vm.$watch(key, handler, options); |
| 2832 |
} |
| 2833 |
|
| 2834 |
function stateMixin (Vue) { |
| 2835 |
// flow somehow has problems with directly declared definition object |
| 2836 |
// when using Object.defineProperty, so we have to procedurally build up |
| 2837 |
// the object here. |
| 2838 |
var dataDef = {}; |
| 2839 |
dataDef.get = function () { return this._data }; |
| 2840 |
var propsDef = {}; |
| 2841 |
propsDef.get = function () { return this._props }; |
| 2842 |
{ |
| 2843 |
dataDef.set = function (newData) { |
| 2844 |
warn( |
| 2845 |
'Avoid replacing instance root $data. ' + |
| 2846 |
'Use nested data properties instead.', |
| 2847 |
this |
| 2848 |
); |
| 2849 |
}; |
| 2850 |
propsDef.set = function () { |
| 2851 |
warn("$props is readonly.", this); |
| 2852 |
}; |
| 2853 |
} |
| 2854 |
Object.defineProperty(Vue.prototype, '$data', dataDef); |
| 2855 |
Object.defineProperty(Vue.prototype, '$props', propsDef); |
| 2856 |
|
| 2857 |
Vue.prototype.$set = set; |
| 2858 |
Vue.prototype.$delete = del; |
| 2859 |
|
| 2860 |
Vue.prototype.$watch = function ( |
| 2861 |
expOrFn, |
| 2862 |
cb, |
| 2863 |
options |
| 2864 |
) { |
| 2865 |
var vm = this; |
| 2866 |
options = options || {}; |
| 2867 |
options.user = true; |
| 2868 |
var watcher = new Watcher(vm, expOrFn, cb, options); |
| 2869 |
if (options.immediate) { |
| 2870 |
cb.call(vm, watcher.value); |
| 2871 |
} |
| 2872 |
return function unwatchFn () { |
| 2873 |
watcher.teardown(); |
| 2874 |
} |
| 2875 |
}; |
| 2876 |
} |
| 2877 |
|
| 2878 |
/* */ |
| 2879 |
|
| 2880 |
// hooks to be invoked on component VNodes during patch |
| 2881 |
var componentVNodeHooks = { |
| 2882 |
init: function init ( |
| 2883 |
vnode, |
| 2884 |
hydrating, |
| 2885 |
parentElm, |
| 2886 |
refElm |
| 2887 |
) { |
| 2888 |
if (!vnode.componentInstance || vnode.componentInstance._isDestroyed) { |
| 2889 |
var child = vnode.componentInstance = createComponentInstanceForVnode( |
| 2890 |
vnode, |
| 2891 |
activeInstance, |
| 2892 |
parentElm, |
| 2893 |
refElm |
| 2894 |
); |
| 2895 |
child.$mount(hydrating ? vnode.elm : undefined, hydrating); |
| 2896 |
} else if (vnode.data.keepAlive) { |
| 2897 |
// kept-alive components, treat as a patch |
| 2898 |
var mountedNode = vnode; // work around flow |
| 2899 |
componentVNodeHooks.prepatch(mountedNode, mountedNode); |
| 2900 |
} |
| 2901 |
}, |
| 2902 |
|
| 2903 |
prepatch: function prepatch (oldVnode, vnode) { |
| 2904 |
var options = vnode.componentOptions; |
| 2905 |
var child = vnode.componentInstance = oldVnode.componentInstance; |
| 2906 |
updateChildComponent( |
| 2907 |
child, |
| 2908 |
options.propsData, // updated props |
| 2909 |
options.listeners, // updated listeners |
| 2910 |
vnode, // new parent vnode |
| 2911 |
options.children // new children |
| 2912 |
); |
| 2913 |
}, |
| 2914 |
|
| 2915 |
insert: function insert (vnode) { |
| 2916 |
if (!vnode.componentInstance._isMounted) { |
| 2917 |
vnode.componentInstance._isMounted = true; |
| 2918 |
callHook(vnode.componentInstance, 'mounted'); |
| 2919 |
} |
| 2920 |
if (vnode.data.keepAlive) { |
| 2921 |
activateChildComponent(vnode.componentInstance, true /* direct */); |
| 2922 |
} |
| 2923 |
}, |
| 2924 |
|
| 2925 |
destroy: function destroy (vnode) { |
| 2926 |
if (!vnode.componentInstance._isDestroyed) { |
| 2927 |
if (!vnode.data.keepAlive) { |
| 2928 |
vnode.componentInstance.$destroy(); |
| 2929 |
} else { |
| 2930 |
deactivateChildComponent(vnode.componentInstance, true /* direct */); |
| 2931 |
} |
| 2932 |
} |
| 2933 |
} |
| 2934 |
}; |
| 2935 |
|
| 2936 |
var hooksToMerge = Object.keys(componentVNodeHooks); |
| 2937 |
|
| 2938 |
function createComponent ( |
| 2939 |
Ctor, |
| 2940 |
data, |
| 2941 |
context, |
| 2942 |
children, |
| 2943 |
tag |
| 2944 |
) { |
| 2945 |
if (!Ctor) { |
| 2946 |
return |
| 2947 |
} |
| 2948 |
|
| 2949 |
var baseCtor = context.$options._base; |
| 2950 |
if (isObject(Ctor)) { |
| 2951 |
Ctor = baseCtor.extend(Ctor); |
| 2952 |
} |
| 2953 |
|
| 2954 |
if (typeof Ctor !== 'function') { |
| 2955 |
{ |
| 2956 |
warn(("Invalid Component definition: " + (String(Ctor))), context); |
| 2957 |
} |
| 2958 |
return |
| 2959 |
} |
| 2960 |
|
| 2961 |
// async component |
| 2962 |
if (!Ctor.cid) { |
| 2963 |
if (Ctor.resolved) { |
| 2964 |
Ctor = Ctor.resolved; |
| 2965 |
} else { |
| 2966 |
Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { |
| 2967 |
// it's ok to queue this on every render because |
| 2968 |
// $forceUpdate is buffered by the scheduler. |
| 2969 |
context.$forceUpdate(); |
| 2970 |
}); |
| 2971 |
if (!Ctor) { |
| 2972 |
// return nothing if this is indeed an async component |
| 2973 |
// wait for the callback to trigger parent update. |
| 2974 |
return |
| 2975 |
} |
| 2976 |
} |
| 2977 |
} |
| 2978 |
|
| 2979 |
// resolve constructor options in case global mixins are applied after |
| 2980 |
// component constructor creation |
| 2981 |
resolveConstructorOptions(Ctor); |
| 2982 |
|
| 2983 |
data = data || {}; |
| 2984 |
|
| 2985 |
// transform component v-model data into props & events |
| 2986 |
if (data.model) { |
| 2987 |
transformModel(Ctor.options, data); |
| 2988 |
} |
| 2989 |
|
| 2990 |
// extract props |
| 2991 |
var propsData = extractProps(data, Ctor); |
| 2992 |
|
| 2993 |
// functional component |
| 2994 |
if (Ctor.options.functional) { |
| 2995 |
return createFunctionalComponent(Ctor, propsData, data, context, children) |
| 2996 |
} |
| 2997 |
|
| 2998 |
// extract listeners, since these needs to be treated as |
| 2999 |
// child component listeners instead of DOM listeners |
| 3000 |
var listeners = data.on; |
| 3001 |
// replace with listeners with .native modifier |
| 3002 |
data.on = data.nativeOn; |
| 3003 |
|
| 3004 |
if (Ctor.options.abstract) { |
| 3005 |
// abstract components do not keep anything |
| 3006 |
// other than props & listeners |
| 3007 |
data = {}; |
| 3008 |
} |
| 3009 |
|
| 3010 |
// merge component management hooks onto the placeholder node |
| 3011 |
mergeHooks(data); |
| 3012 |
|
| 3013 |
// return a placeholder vnode |
| 3014 |
var name = Ctor.options.name || tag; |
| 3015 |
var vnode = new VNode( |
| 3016 |
("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')), |
| 3017 |
data, undefined, undefined, undefined, context, |
| 3018 |
{ Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children } |
| 3019 |
); |
| 3020 |
return vnode |
| 3021 |
} |
| 3022 |
|
| 3023 |
function createFunctionalComponent ( |
| 3024 |
Ctor, |
| 3025 |
propsData, |
| 3026 |
data, |
| 3027 |
context, |
| 3028 |
children |
| 3029 |
) { |
| 3030 |
var props = {}; |
| 3031 |
var propOptions = Ctor.options.props; |
| 3032 |
if (propOptions) { |
| 3033 |
for (var key in propOptions) { |
| 3034 |
props[key] = validateProp(key, propOptions, propsData); |
| 3035 |
} |
| 3036 |
} |
| 3037 |
// ensure the createElement function in functional components |
| 3038 |
// gets a unique context - this is necessary for correct named slot check |
| 3039 |
var _context = Object.create(context); |
| 3040 |
var h = function (a, b, c, d) { return createElement(_context, a, b, c, d, true); }; |
| 3041 |
var vnode = Ctor.options.render.call(null, h, { |
| 3042 |
props: props, |
| 3043 |
data: data, |
| 3044 |
parent: context, |
| 3045 |
children: children, |
| 3046 |
slots: function () { return resolveSlots(children, context); } |
| 3047 |
}); |
| 3048 |
if (vnode instanceof VNode) { |
| 3049 |
vnode.functionalContext = context; |
| 3050 |
if (data.slot) { |
| 3051 |
(vnode.data || (vnode.data = {})).slot = data.slot; |
| 3052 |
} |
| 3053 |
} |
| 3054 |
return vnode |
| 3055 |
} |
| 3056 |
|
| 3057 |
function createComponentInstanceForVnode ( |
| 3058 |
vnode, // we know it's MountedComponentVNode but flow doesn't |
| 3059 |
parent, // activeInstance in lifecycle state |
| 3060 |
parentElm, |
| 3061 |
refElm |
| 3062 |
) { |
| 3063 |
var vnodeComponentOptions = vnode.componentOptions; |
| 3064 |
var options = { |
| 3065 |
_isComponent: true, |
| 3066 |
parent: parent, |
| 3067 |
propsData: vnodeComponentOptions.propsData, |
| 3068 |
_componentTag: vnodeComponentOptions.tag, |
| 3069 |
_parentVnode: vnode, |
| 3070 |
_parentListeners: vnodeComponentOptions.listeners, |
| 3071 |
_renderChildren: vnodeComponentOptions.children, |
| 3072 |
_parentElm: parentElm || null, |
| 3073 |
_refElm: refElm || null |
| 3074 |
}; |
| 3075 |
// check inline-template render functions |
| 3076 |
var inlineTemplate = vnode.data.inlineTemplate; |
| 3077 |
if (inlineTemplate) { |
| 3078 |
options.render = inlineTemplate.render; |
| 3079 |
options.staticRenderFns = inlineTemplate.staticRenderFns; |
| 3080 |
} |
| 3081 |
return new vnodeComponentOptions.Ctor(options) |
| 3082 |
} |
| 3083 |
|
| 3084 |
function resolveAsyncComponent ( |
| 3085 |
factory, |
| 3086 |
baseCtor, |
| 3087 |
cb |
| 3088 |
) { |
| 3089 |
if (factory.requested) { |
| 3090 |
// pool callbacks |
| 3091 |
factory.pendingCallbacks.push(cb); |
| 3092 |
} else { |
| 3093 |
factory.requested = true; |
| 3094 |
var cbs = factory.pendingCallbacks = [cb]; |
| 3095 |
var sync = true; |
| 3096 |
|
| 3097 |
var resolve = function (res) { |
| 3098 |
if (isObject(res)) { |
| 3099 |
res = baseCtor.extend(res); |
| 3100 |
} |
| 3101 |
// cache resolved |
| 3102 |
factory.resolved = res; |
| 3103 |
// invoke callbacks only if this is not a synchronous resolve |
| 3104 |
// (async resolves are shimmed as synchronous during SSR) |
| 3105 |
if (!sync) { |
| 3106 |
for (var i = 0, l = cbs.length; i < l; i++) { |
| 3107 |
cbs[i](res); |
| 3108 |
} |
| 3109 |
} |
| 3110 |
}; |
| 3111 |
|
| 3112 |
var reject = function (reason) { |
| 3113 |
"development" !== 'production' && warn( |
| 3114 |
"Failed to resolve async component: " + (String(factory)) + |
| 3115 |
(reason ? ("\nReason: " + reason) : '') |
| 3116 |
); |
| 3117 |
}; |
| 3118 |
|
| 3119 |
var res = factory(resolve, reject); |
| 3120 |
|
| 3121 |
// handle promise |
| 3122 |
if (res && typeof res.then === 'function' && !factory.resolved) { |
| 3123 |
res.then(resolve, reject); |
| 3124 |
} |
| 3125 |
|
| 3126 |
sync = false; |
| 3127 |
// return in case resolved synchronously |
| 3128 |
return factory.resolved |
| 3129 |
} |
| 3130 |
} |
| 3131 |
|
| 3132 |
function extractProps (data, Ctor) { |
| 3133 |
// we are only extracting raw values here. |
| 3134 |
// validation and default values are handled in the child |
| 3135 |
// component itself. |
| 3136 |
var propOptions = Ctor.options.props; |
| 3137 |
if (!propOptions) { |
| 3138 |
return |
| 3139 |
} |
| 3140 |
var res = {}; |
| 3141 |
var attrs = data.attrs; |
| 3142 |
var props = data.props; |
| 3143 |
var domProps = data.domProps; |
| 3144 |
if (attrs || props || domProps) { |
| 3145 |
for (var key in propOptions) { |
| 3146 |
var altKey = hyphenate(key); |
| 3147 |
{ |
| 3148 |
var keyInLowerCase = key.toLowerCase(); |
| 3149 |
if ( |
| 3150 |
key !== keyInLowerCase && |
| 3151 |
attrs && attrs.hasOwnProperty(keyInLowerCase) |
| 3152 |
) { |
| 3153 |
warn( |
| 3154 |
"Prop \"" + keyInLowerCase + "\" is not declared in component " + |
| 3155 |
(formatComponentName(Ctor)) + ". Note that HTML attributes are " + |
| 3156 |
"case-insensitive and camelCased props need to use their kebab-case " + |
| 3157 |
"equivalents when using in-DOM templates. You should probably use " + |
| 3158 |
"\"" + altKey + "\" instead of \"" + key + "\"." |
| 3159 |
); |
| 3160 |
} |
| 3161 |
} |
| 3162 |
checkProp(res, props, key, altKey, true) || |
| 3163 |
checkProp(res, attrs, key, altKey) || |
| 3164 |
checkProp(res, domProps, key, altKey); |
| 3165 |
} |
| 3166 |
} |
| 3167 |
return res |
| 3168 |
} |
| 3169 |
|
| 3170 |
function checkProp ( |
| 3171 |
res, |
| 3172 |
hash, |
| 3173 |
key, |
| 3174 |
altKey, |
| 3175 |
preserve |
| 3176 |
) { |
| 3177 |
if (hash) { |
| 3178 |
if (hasOwn(hash, key)) { |
| 3179 |
res[key] = hash[key]; |
| 3180 |
if (!preserve) { |
| 3181 |
delete hash[key]; |
| 3182 |
} |
| 3183 |
return true |
| 3184 |
} else if (hasOwn(hash, altKey)) { |
| 3185 |
res[key] = hash[altKey]; |
| 3186 |
if (!preserve) { |
| 3187 |
delete hash[altKey]; |
| 3188 |
} |
| 3189 |
return true |
| 3190 |
} |
| 3191 |
} |
| 3192 |
return false |
| 3193 |
} |
| 3194 |
|
| 3195 |
function mergeHooks (data) { |
| 3196 |
if (!data.hook) { |
| 3197 |
data.hook = {}; |
| 3198 |
} |
| 3199 |
for (var i = 0; i < hooksToMerge.length; i++) { |
| 3200 |
var key = hooksToMerge[i]; |
| 3201 |
var fromParent = data.hook[key]; |
| 3202 |
var ours = componentVNodeHooks[key]; |
| 3203 |
data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours; |
| 3204 |
} |
| 3205 |
} |
| 3206 |
|
| 3207 |
function mergeHook$1 (one, two) { |
| 3208 |
return function (a, b, c, d) { |
| 3209 |
one(a, b, c, d); |
| 3210 |
two(a, b, c, d); |
| 3211 |
} |
| 3212 |
} |
| 3213 |
|
| 3214 |
// transform component v-model info (value and callback) into |
| 3215 |
// prop and event handler respectively. |
| 3216 |
function transformModel (options, data) { |
| 3217 |
var prop = (options.model && options.model.prop) || 'value'; |
| 3218 |
var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; |
| 3219 |
var on = data.on || (data.on = {}); |
| 3220 |
if (on[event]) { |
| 3221 |
on[event] = [data.model.callback].concat(on[event]); |
| 3222 |
} else { |
| 3223 |
on[event] = data.model.callback; |
| 3224 |
} |
| 3225 |
} |
| 3226 |
|
| 3227 |
/* */ |
| 3228 |
|
| 3229 |
var SIMPLE_NORMALIZE = 1; |
| 3230 |
var ALWAYS_NORMALIZE = 2; |
| 3231 |
|
| 3232 |
// wrapper function for providing a more flexible interface |
| 3233 |
// without getting yelled at by flow |
| 3234 |
function createElement ( |
| 3235 |
context, |
| 3236 |
tag, |
| 3237 |
data, |
| 3238 |
children, |
| 3239 |
normalizationType, |
| 3240 |
alwaysNormalize |
| 3241 |
) { |
| 3242 |
if (Array.isArray(data) || isPrimitive(data)) { |
| 3243 |
normalizationType = children; |
| 3244 |
children = data; |
| 3245 |
data = undefined; |
| 3246 |
} |
| 3247 |
if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } |
| 3248 |
return _createElement(context, tag, data, children, normalizationType) |
| 3249 |
} |
| 3250 |
|
| 3251 |
function _createElement ( |
| 3252 |
context, |
| 3253 |
tag, |
| 3254 |
data, |
| 3255 |
children, |
| 3256 |
normalizationType |
| 3257 |
) { |
| 3258 |
if (data && data.__ob__) { |
| 3259 |
"development" !== 'production' && warn( |
| 3260 |
"Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + |
| 3261 |
'Always create fresh vnode data objects in each render!', |
| 3262 |
context |
| 3263 |
); |
| 3264 |
return createEmptyVNode() |
| 3265 |
} |
| 3266 |
if (!tag) { |
| 3267 |
// in case of component :is set to falsy value |
| 3268 |
return createEmptyVNode() |
| 3269 |
} |
| 3270 |
// support single function children as default scoped slot |
| 3271 |
if (Array.isArray(children) && |
| 3272 |
typeof children[0] === 'function') { |
| 3273 |
data = data || {}; |
| 3274 |
data.scopedSlots = { default: children[0] }; |
| 3275 |
children.length = 0; |
| 3276 |
} |
| 3277 |
if (normalizationType === ALWAYS_NORMALIZE) { |
| 3278 |
children = normalizeChildren(children); |
| 3279 |
} else if (normalizationType === SIMPLE_NORMALIZE) { |
| 3280 |
children = simpleNormalizeChildren(children); |
| 3281 |
} |
| 3282 |
var vnode, ns; |
| 3283 |
if (typeof tag === 'string') { |
| 3284 |
var Ctor; |
| 3285 |
ns = config.getTagNamespace(tag); |
| 3286 |
if (config.isReservedTag(tag)) { |
| 3287 |
// platform built-in elements |
| 3288 |
vnode = new VNode( |
| 3289 |
config.parsePlatformTagName(tag), data, children, |
| 3290 |
undefined, undefined, context |
| 3291 |
); |
| 3292 |
} else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { |
| 3293 |
// component |
| 3294 |
vnode = createComponent(Ctor, data, context, children, tag); |
| 3295 |
} else { |
| 3296 |
// unknown or unlisted namespaced elements |
| 3297 |
// check at runtime because it may get assigned a namespace when its |
| 3298 |
// parent normalizes children |
| 3299 |
vnode = new VNode( |
| 3300 |
tag, data, children, |
| 3301 |
undefined, undefined, context |
| 3302 |
); |
| 3303 |
} |
| 3304 |
} else { |
| 3305 |
// direct component options / constructor |
| 3306 |
vnode = createComponent(tag, data, context, children); |
| 3307 |
} |
| 3308 |
if (vnode) { |
| 3309 |
if (ns) { applyNS(vnode, ns); } |
| 3310 |
return vnode |
| 3311 |
} else { |
| 3312 |
return createEmptyVNode() |
| 3313 |
} |
| 3314 |
} |
| 3315 |
|
| 3316 |
function applyNS (vnode, ns) { |
| 3317 |
vnode.ns = ns; |
| 3318 |
if (vnode.tag === 'foreignObject') { |
| 3319 |
// use default namespace inside foreignObject |
| 3320 |
return |
| 3321 |
} |
| 3322 |
if (vnode.children) { |
| 3323 |
for (var i = 0, l = vnode.children.length; i < l; i++) { |
| 3324 |
var child = vnode.children[i]; |
| 3325 |
if (child.tag && !child.ns) { |
| 3326 |
applyNS(child, ns); |
| 3327 |
} |
| 3328 |
} |
| 3329 |
} |
| 3330 |
} |
| 3331 |
|
| 3332 |
/* */ |
| 3333 |
|
| 3334 |
/** |
| 3335 |
* Runtime helper for rendering v-for lists. |
| 3336 |
*/ |
| 3337 |
function renderList ( |
| 3338 |
val, |
| 3339 |
render |
| 3340 |
) { |
| 3341 |
var ret, i, l, keys, key; |
| 3342 |
if (Array.isArray(val) || typeof val === 'string') { |
| 3343 |
ret = new Array(val.length); |
| 3344 |
for (i = 0, l = val.length; i < l; i++) { |
| 3345 |
ret[i] = render(val[i], i); |
| 3346 |
} |
| 3347 |
} else if (typeof val === 'number') { |
| 3348 |
ret = new Array(val); |
| 3349 |
for (i = 0; i < val; i++) { |
| 3350 |
ret[i] = render(i + 1, i); |
| 3351 |
} |
| 3352 |
} else if (isObject(val)) { |
| 3353 |
keys = Object.keys(val); |
| 3354 |
ret = new Array(keys.length); |
| 3355 |
for (i = 0, l = keys.length; i < l; i++) { |
| 3356 |
key = keys[i]; |
| 3357 |
ret[i] = render(val[key], key, i); |
| 3358 |
} |
| 3359 |
} |
| 3360 |
return ret |
| 3361 |
} |
| 3362 |
|
| 3363 |
/* */ |
| 3364 |
|
| 3365 |
/** |
| 3366 |
* Runtime helper for rendering <slot> |
| 3367 |
*/ |
| 3368 |
function renderSlot ( |
| 3369 |
name, |
| 3370 |
fallback, |
| 3371 |
props, |
| 3372 |
bindObject |
| 3373 |
) { |
| 3374 |
var scopedSlotFn = this.$scopedSlots[name]; |
| 3375 |
if (scopedSlotFn) { // scoped slot |
| 3376 |
props = props || {}; |
| 3377 |
if (bindObject) { |
| 3378 |
extend(props, bindObject); |
| 3379 |
} |
| 3380 |
return scopedSlotFn(props) || fallback |
| 3381 |
} else { |
| 3382 |
var slotNodes = this.$slots[name]; |
| 3383 |
// warn duplicate slot usage |
| 3384 |
if (slotNodes && "development" !== 'production') { |
| 3385 |
slotNodes._rendered && warn( |
| 3386 |
"Duplicate presence of slot \"" + name + "\" found in the same render tree " + |
| 3387 |
"- this will likely cause render errors.", |
| 3388 |
this |
| 3389 |
); |
| 3390 |
slotNodes._rendered = true; |
| 3391 |
} |
| 3392 |
return slotNodes || fallback |
| 3393 |
} |
| 3394 |
} |
| 3395 |
|
| 3396 |
/* */ |
| 3397 |
|
| 3398 |
/** |
| 3399 |
* Runtime helper for resolving filters |
| 3400 |
*/ |
| 3401 |
function resolveFilter (id) { |
| 3402 |
return resolveAsset(this.$options, 'filters', id, true) || identity |
| 3403 |
} |
| 3404 |
|
| 3405 |
/* */ |
| 3406 |
|
| 3407 |
/** |
| 3408 |
* Runtime helper for checking keyCodes from config. |
| 3409 |
*/ |
| 3410 |
function checkKeyCodes ( |
| 3411 |
eventKeyCode, |
| 3412 |
key, |
| 3413 |
builtInAlias |
| 3414 |
) { |
| 3415 |
var keyCodes = config.keyCodes[key] || builtInAlias; |
| 3416 |
if (Array.isArray(keyCodes)) { |
| 3417 |
return keyCodes.indexOf(eventKeyCode) === -1 |
| 3418 |
} else { |
| 3419 |
return keyCodes !== eventKeyCode |
| 3420 |
} |
| 3421 |
} |
| 3422 |
|
| 3423 |
/* */ |
| 3424 |
|
| 3425 |
/** |
| 3426 |
* Runtime helper for merging v-bind="object" into a VNode's data. |
| 3427 |
*/ |
| 3428 |
function bindObjectProps ( |
| 3429 |
data, |
| 3430 |
tag, |
| 3431 |
value, |
| 3432 |
asProp |
| 3433 |
) { |
| 3434 |
if (value) { |
| 3435 |
if (!isObject(value)) { |
| 3436 |
"development" !== 'production' && warn( |
| 3437 |
'v-bind without argument expects an Object or Array value', |
| 3438 |
this |
| 3439 |
); |
| 3440 |
} else { |
| 3441 |
if (Array.isArray(value)) { |
| 3442 |
value = toObject(value); |
| 3443 |
} |
| 3444 |
var hash; |
| 3445 |
for (var key in value) { |
| 3446 |
if (key === 'class' || key === 'style') { |
| 3447 |
hash = data; |
| 3448 |
} else { |
| 3449 |
var type = data.attrs && data.attrs.type; |
| 3450 |
hash = asProp || config.mustUseProp(tag, type, key) |
| 3451 |
? data.domProps || (data.domProps = {}) |
| 3452 |
: data.attrs || (data.attrs = {}); |
| 3453 |
} |
| 3454 |
if (!(key in hash)) { |
| 3455 |
hash[key] = value[key]; |
| 3456 |
} |
| 3457 |
} |
| 3458 |
} |
| 3459 |
} |
| 3460 |
return data |
| 3461 |
} |
| 3462 |
|
| 3463 |
/* */ |
| 3464 |
|
| 3465 |
/** |
| 3466 |
* Runtime helper for rendering static trees. |
| 3467 |
*/ |
| 3468 |
function renderStatic ( |
| 3469 |
index, |
| 3470 |
isInFor |
| 3471 |
) { |
| 3472 |
var tree = this._staticTrees[index]; |
| 3473 |
// if has already-rendered static tree and not inside v-for, |
| 3474 |
// we can reuse the same tree by doing a shallow clone. |
| 3475 |
if (tree && !isInFor) { |
| 3476 |
return Array.isArray(tree) |
| 3477 |
? cloneVNodes(tree) |
| 3478 |
: cloneVNode(tree) |
| 3479 |
} |
| 3480 |
// otherwise, render a fresh tree. |
| 3481 |
tree = this._staticTrees[index] = |
| 3482 |
this.$options.staticRenderFns[index].call(this._renderProxy); |
| 3483 |
markStatic(tree, ("__static__" + index), false); |
| 3484 |
return tree |
| 3485 |
} |
| 3486 |
|
| 3487 |
/** |
| 3488 |
* Runtime helper for v-once. |
| 3489 |
* Effectively it means marking the node as static with a unique key. |
| 3490 |
*/ |
| 3491 |
function markOnce ( |
| 3492 |
tree, |
| 3493 |
index, |
| 3494 |
key |
| 3495 |
) { |
| 3496 |
markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true); |
| 3497 |
return tree |
| 3498 |
} |
| 3499 |
|
| 3500 |
function markStatic ( |
| 3501 |
tree, |
| 3502 |
key, |
| 3503 |
isOnce |
| 3504 |
) { |
| 3505 |
if (Array.isArray(tree)) { |
| 3506 |
for (var i = 0; i < tree.length; i++) { |
| 3507 |
if (tree[i] && typeof tree[i] !== 'string') { |
| 3508 |
markStaticNode(tree[i], (key + "_" + i), isOnce); |
| 3509 |
} |
| 3510 |
} |
| 3511 |
} else { |
| 3512 |
markStaticNode(tree, key, isOnce); |
| 3513 |
} |
| 3514 |
} |
| 3515 |
|
| 3516 |
function markStaticNode (node, key, isOnce) { |
| 3517 |
node.isStatic = true; |
| 3518 |
node.key = key; |
| 3519 |
node.isOnce = isOnce; |
| 3520 |
} |
| 3521 |
|
| 3522 |
/* */ |
| 3523 |
|
| 3524 |
function initRender (vm) { |
| 3525 |
vm.$vnode = null; // the placeholder node in parent tree |
| 3526 |
vm._vnode = null; // the root of the child tree |
| 3527 |
vm._staticTrees = null; |
| 3528 |
var parentVnode = vm.$options._parentVnode; |
| 3529 |
var renderContext = parentVnode && parentVnode.context; |
| 3530 |
vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); |
| 3531 |
vm.$scopedSlots = emptyObject; |
| 3532 |
// bind the createElement fn to this instance |
| 3533 |
// so that we get proper render context inside it. |
| 3534 |
// args order: tag, data, children, normalizationType, alwaysNormalize |
| 3535 |
// internal version is used by render functions compiled from templates |
| 3536 |
vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); }; |
| 3537 |
// normalization is always applied for the public version, used in |
| 3538 |
// user-written render functions. |
| 3539 |
vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); }; |
| 3540 |
} |
| 3541 |
|
| 3542 |
function renderMixin (Vue) { |
| 3543 |
Vue.prototype.$nextTick = function (fn) { |
| 3544 |
return nextTick(fn, this) |
| 3545 |
}; |
| 3546 |
|
| 3547 |
Vue.prototype._render = function () { |
| 3548 |
var vm = this; |
| 3549 |
var ref = vm.$options; |
| 3550 |
var render = ref.render; |
| 3551 |
var staticRenderFns = ref.staticRenderFns; |
| 3552 |
var _parentVnode = ref._parentVnode; |
| 3553 |
|
| 3554 |
if (vm._isMounted) { |
| 3555 |
// clone slot nodes on re-renders |
| 3556 |
for (var key in vm.$slots) { |
| 3557 |
vm.$slots[key] = cloneVNodes(vm.$slots[key]); |
| 3558 |
} |
| 3559 |
} |
| 3560 |
|
| 3561 |
vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject; |
| 3562 |
|
| 3563 |
if (staticRenderFns && !vm._staticTrees) { |
| 3564 |
vm._staticTrees = []; |
| 3565 |
} |
| 3566 |
// set parent vnode. this allows render functions to have access |
| 3567 |
// to the data on the placeholder node. |
| 3568 |
vm.$vnode = _parentVnode; |
| 3569 |
// render self |
| 3570 |
var vnode; |
| 3571 |
try { |
| 3572 |
vnode = render.call(vm._renderProxy, vm.$createElement); |
| 3573 |
} catch (e) { |
| 3574 |
handleError(e, vm, "render function"); |
| 3575 |
// return error render result, |
| 3576 |
// or previous vnode to prevent render error causing blank component |
| 3577 |
/* istanbul ignore else */ |
| 3578 |
{ |
| 3579 |
vnode = vm.$options.renderError |
| 3580 |
? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e) |
| 3581 |
: vm._vnode; |
| 3582 |
} |
| 3583 |
} |
| 3584 |
// return empty vnode in case the render function errored out |
| 3585 |
if (!(vnode instanceof VNode)) { |
| 3586 |
if ("development" !== 'production' && Array.isArray(vnode)) { |
| 3587 |
warn( |
| 3588 |
'Multiple root nodes returned from render function. Render function ' + |
| 3589 |
'should return a single root node.', |
| 3590 |
vm |
| 3591 |
); |
| 3592 |
} |
| 3593 |
vnode = createEmptyVNode(); |
| 3594 |
} |
| 3595 |
// set parent |
| 3596 |
vnode.parent = _parentVnode; |
| 3597 |
return vnode |
| 3598 |
}; |
| 3599 |
|
| 3600 |
// internal render helpers. |
| 3601 |
// these are exposed on the instance prototype to reduce generated render |
| 3602 |
// code size. |
| 3603 |
Vue.prototype._o = markOnce; |
| 3604 |
Vue.prototype._n = toNumber; |
| 3605 |
Vue.prototype._s = _toString; |
| 3606 |
Vue.prototype._l = renderList; |
| 3607 |
Vue.prototype._t = renderSlot; |
| 3608 |
Vue.prototype._q = looseEqual; |
| 3609 |
Vue.prototype._i = looseIndexOf; |
| 3610 |
Vue.prototype._m = renderStatic; |
| 3611 |
Vue.prototype._f = resolveFilter; |
| 3612 |
Vue.prototype._k = checkKeyCodes; |
| 3613 |
Vue.prototype._b = bindObjectProps; |
| 3614 |
Vue.prototype._v = createTextVNode; |
| 3615 |
Vue.prototype._e = createEmptyVNode; |
| 3616 |
Vue.prototype._u = resolveScopedSlots; |
| 3617 |
} |
| 3618 |
|
| 3619 |
/* */ |
| 3620 |
|
| 3621 |
function initProvide (vm) { |
| 3622 |
var provide = vm.$options.provide; |
| 3623 |
if (provide) { |
| 3624 |
vm._provided = typeof provide === 'function' |
| 3625 |
? provide.call(vm) |
| 3626 |
: provide; |
| 3627 |
} |
| 3628 |
} |
| 3629 |
|
| 3630 |
function initInjections (vm) { |
| 3631 |
var inject = vm.$options.inject; |
| 3632 |
if (inject) { |
| 3633 |
// inject is :any because flow is not smart enough to figure out cached |
| 3634 |
// isArray here |
| 3635 |
var isArray = Array.isArray(inject); |
| 3636 |
var keys = isArray |
| 3637 |
? inject |
| 3638 |
: hasSymbol |
| 3639 |
? Reflect.ownKeys(inject) |
| 3640 |
: Object.keys(inject); |
| 3641 |
|
| 3642 |
for (var i = 0; i < keys.length; i++) { |
| 3643 |
var key = keys[i]; |
| 3644 |
var provideKey = isArray ? key : inject[key]; |
| 3645 |
var source = vm; |
| 3646 |
while (source) { |
| 3647 |
if (source._provided && provideKey in source._provided) { |
| 3648 |
vm[key] = source._provided[provideKey]; |
| 3649 |
break |
| 3650 |
} |
| 3651 |
source = source.$parent; |
| 3652 |
} |
| 3653 |
} |
| 3654 |
} |
| 3655 |
} |
| 3656 |
|
| 3657 |
/* */ |
| 3658 |
|
| 3659 |
var uid = 0; |
| 3660 |
|
| 3661 |
function initMixin (Vue) { |
| 3662 |
Vue.prototype._init = function (options) { |
| 3663 |
/* istanbul ignore if */ |
| 3664 |
if ("development" !== 'production' && config.performance && mark) { |
| 3665 |
mark('vue-perf-init'); |
| 3666 |
} |
| 3667 |
|
| 3668 |
var vm = this; |
| 3669 |
// a uid |
| 3670 |
vm._uid = uid++; |
| 3671 |
// a flag to avoid this being observed |
| 3672 |
vm._isVue = true; |
| 3673 |
// merge options |
| 3674 |
if (options && options._isComponent) { |
| 3675 |
// optimize internal component instantiation |
| 3676 |
// since dynamic options merging is pretty slow, and none of the |
| 3677 |
// internal component options needs special treatment. |
| 3678 |
initInternalComponent(vm, options); |
| 3679 |
} else { |
| 3680 |
vm.$options = mergeOptions( |
| 3681 |
resolveConstructorOptions(vm.constructor), |
| 3682 |
options || {}, |
| 3683 |
vm |
| 3684 |
); |
| 3685 |
} |
| 3686 |
/* istanbul ignore else */ |
| 3687 |
{ |
| 3688 |
initProxy(vm); |
| 3689 |
} |
| 3690 |
// expose real self |
| 3691 |
vm._self = vm; |
| 3692 |
initLifecycle(vm); |
| 3693 |
initEvents(vm); |
| 3694 |
initRender(vm); |
| 3695 |
callHook(vm, 'beforeCreate'); |
| 3696 |
initInjections(vm); // resolve injections before data/props |
| 3697 |
initState(vm); |
| 3698 |
initProvide(vm); // resolve provide after data/props |
| 3699 |
callHook(vm, 'created'); |
| 3700 |
|
| 3701 |
/* istanbul ignore if */ |
| 3702 |
if ("development" !== 'production' && config.performance && mark) { |
| 3703 |
vm._name = formatComponentName(vm, false); |
| 3704 |
mark('vue-perf-init-end'); |
| 3705 |
measure(((vm._name) + " init"), 'vue-perf-init', 'vue-perf-init-end'); |
| 3706 |
} |
| 3707 |
|
| 3708 |
if (vm.$options.el) { |
| 3709 |
vm.$mount(vm.$options.el); |
| 3710 |
} |
| 3711 |
}; |
| 3712 |
} |
| 3713 |
|
| 3714 |
function initInternalComponent (vm, options) { |
| 3715 |
var opts = vm.$options = Object.create(vm.constructor.options); |
| 3716 |
// doing this because it's faster than dynamic enumeration. |
| 3717 |
opts.parent = options.parent; |
| 3718 |
opts.propsData = options.propsData; |
| 3719 |
opts._parentVnode = options._parentVnode; |
| 3720 |
opts._parentListeners = options._parentListeners; |
| 3721 |
opts._renderChildren = options._renderChildren; |
| 3722 |
opts._componentTag = options._componentTag; |
| 3723 |
opts._parentElm = options._parentElm; |
| 3724 |
opts._refElm = options._refElm; |
| 3725 |
if (options.render) { |
| 3726 |
opts.render = options.render; |
| 3727 |
opts.staticRenderFns = options.staticRenderFns; |
| 3728 |
} |
| 3729 |
} |
| 3730 |
|
| 3731 |
function resolveConstructorOptions (Ctor) { |
| 3732 |
var options = Ctor.options; |
| 3733 |
if (Ctor.super) { |
| 3734 |
var superOptions = resolveConstructorOptions(Ctor.super); |
| 3735 |
var cachedSuperOptions = Ctor.superOptions; |
| 3736 |
if (superOptions !== cachedSuperOptions) { |
| 3737 |
// super option changed, |
| 3738 |
// need to resolve new options. |
| 3739 |
Ctor.superOptions = superOptions; |
| 3740 |
// check if there are any late-modified/attached options (#4976) |
| 3741 |
var modifiedOptions = resolveModifiedOptions(Ctor); |
| 3742 |
// update base extend options |
| 3743 |
if (modifiedOptions) { |
| 3744 |
extend(Ctor.extendOptions, modifiedOptions); |
| 3745 |
} |
| 3746 |
options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions); |
| 3747 |
if (options.name) { |
| 3748 |
options.components[options.name] = Ctor; |
| 3749 |
} |
| 3750 |
} |
| 3751 |
} |
| 3752 |
return options |
| 3753 |
} |
| 3754 |
|
| 3755 |
function resolveModifiedOptions (Ctor) { |
| 3756 |
var modified; |
| 3757 |
var latest = Ctor.options; |
| 3758 |
var sealed = Ctor.sealedOptions; |
| 3759 |
for (var key in latest) { |
| 3760 |
if (latest[key] !== sealed[key]) { |
| 3761 |
if (!modified) { modified = {}; } |
| 3762 |
modified[key] = dedupe(latest[key], sealed[key]); |
| 3763 |
} |
| 3764 |
} |
| 3765 |
return modified |
| 3766 |
} |
| 3767 |
|
| 3768 |
function dedupe (latest, sealed) { |
| 3769 |
// compare latest and sealed to ensure lifecycle hooks won't be duplicated |
| 3770 |
// between merges |
| 3771 |
if (Array.isArray(latest)) { |
| 3772 |
var res = []; |
| 3773 |
sealed = Array.isArray(sealed) ? sealed : [sealed]; |
| 3774 |
for (var i = 0; i < latest.length; i++) { |
| 3775 |
if (sealed.indexOf(latest[i]) < 0) { |
| 3776 |
res.push(latest[i]); |
| 3777 |
} |
| 3778 |
} |
| 3779 |
return res |
| 3780 |
} else { |
| 3781 |
return latest |
| 3782 |
} |
| 3783 |
} |
| 3784 |
|
| 3785 |
function Vue$3 (options) { |
| 3786 |
if ("development" !== 'production' && |
| 3787 |
!(this instanceof Vue$3)) { |
| 3788 |
warn('Vue is a constructor and should be called with the `new` keyword'); |
| 3789 |
} |
| 3790 |
this._init(options); |
| 3791 |
} |
| 3792 |
|
| 3793 |
initMixin(Vue$3); |
| 3794 |
stateMixin(Vue$3); |
| 3795 |
eventsMixin(Vue$3); |
| 3796 |
lifecycleMixin(Vue$3); |
| 3797 |
renderMixin(Vue$3); |
| 3798 |
|
| 3799 |
/* */ |
| 3800 |
|
| 3801 |
function initUse (Vue) { |
| 3802 |
Vue.use = function (plugin) { |
| 3803 |
/* istanbul ignore if */ |
| 3804 |
if (plugin.installed) { |
| 3805 |
return |
| 3806 |
} |
| 3807 |
// additional parameters |
| 3808 |
var args = toArray(arguments, 1); |
| 3809 |
args.unshift(this); |
| 3810 |
if (typeof plugin.install === 'function') { |
| 3811 |
plugin.install.apply(plugin, args); |
| 3812 |
} else if (typeof plugin === 'function') { |
| 3813 |
plugin.apply(null, args); |
| 3814 |
} |
| 3815 |
plugin.installed = true; |
| 3816 |
return this |
| 3817 |
}; |
| 3818 |
} |
| 3819 |
|
| 3820 |
/* */ |
| 3821 |
|
| 3822 |
function initMixin$1 (Vue) { |
| 3823 |
Vue.mixin = function (mixin) { |
| 3824 |
this.options = mergeOptions(this.options, mixin); |
| 3825 |
}; |
| 3826 |
} |
| 3827 |
|
| 3828 |
/* */ |
| 3829 |
|
| 3830 |
function initExtend (Vue) { |
| 3831 |
/** |
| 3832 |
* Each instance constructor, including Vue, has a unique |
| 3833 |
* cid. This enables us to create wrapped "child |
| 3834 |
* constructors" for prototypal inheritance and cache them. |
| 3835 |
*/ |
| 3836 |
Vue.cid = 0; |
| 3837 |
var cid = 1; |
| 3838 |
|
| 3839 |
/** |
| 3840 |
* Class inheritance |
| 3841 |
*/ |
| 3842 |
Vue.extend = function (extendOptions) { |
| 3843 |
extendOptions = extendOptions || {}; |
| 3844 |
var Super = this; |
| 3845 |
var SuperId = Super.cid; |
| 3846 |
var cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {}); |
| 3847 |
if (cachedCtors[SuperId]) { |
| 3848 |
return cachedCtors[SuperId] |
| 3849 |
} |
| 3850 |
|
| 3851 |
var name = extendOptions.name || Super.options.name; |
| 3852 |
{ |
| 3853 |
if (!/^[a-zA-Z][\w-]*$/.test(name)) { |
| 3854 |
warn( |
| 3855 |
'Invalid component name: "' + name + '". Component names ' + |
| 3856 |
'can only contain alphanumeric characters and the hyphen, ' + |
| 3857 |
'and must start with a letter.' |
| 3858 |
); |
| 3859 |
} |
| 3860 |
} |
| 3861 |
|
| 3862 |
var Sub = function VueComponent (options) { |
| 3863 |
this._init(options); |
| 3864 |
}; |
| 3865 |
Sub.prototype = Object.create(Super.prototype); |
| 3866 |
Sub.prototype.constructor = Sub; |
| 3867 |
Sub.cid = cid++; |
| 3868 |
Sub.options = mergeOptions( |
| 3869 |
Super.options, |
| 3870 |
extendOptions |
| 3871 |
); |
| 3872 |
Sub['super'] = Super; |
| 3873 |
|
| 3874 |
// For props and computed properties, we define the proxy getters on |
| 3875 |
// the Vue instances at extension time, on the extended prototype. This |
| 3876 |
// avoids Object.defineProperty calls for each instance created. |
| 3877 |
if (Sub.options.props) { |
| 3878 |
initProps$1(Sub); |
| 3879 |
} |
| 3880 |
if (Sub.options.computed) { |
| 3881 |
initComputed$1(Sub); |
| 3882 |
} |
| 3883 |
|
| 3884 |
// allow further extension/mixin/plugin usage |
| 3885 |
Sub.extend = Super.extend; |
| 3886 |
Sub.mixin = Super.mixin; |
| 3887 |
Sub.use = Super.use; |
| 3888 |
|
| 3889 |
// create asset registers, so extended classes |
| 3890 |
// can have their private assets too. |
| 3891 |
config._assetTypes.forEach(function (type) { |
| 3892 |
Sub[type] = Super[type]; |
| 3893 |
}); |
| 3894 |
// enable recursive self-lookup |
| 3895 |
if (name) { |
| 3896 |
Sub.options.components[name] = Sub; |
| 3897 |
} |
| 3898 |
|
| 3899 |
// keep a reference to the super options at extension time. |
| 3900 |
// later at instantiation we can check if Super's options have |
| 3901 |
// been updated. |
| 3902 |
Sub.superOptions = Super.options; |
| 3903 |
Sub.extendOptions = extendOptions; |
| 3904 |
Sub.sealedOptions = extend({}, Sub.options); |
| 3905 |
|
| 3906 |
// cache constructor |
| 3907 |
cachedCtors[SuperId] = Sub; |
| 3908 |
return Sub |
| 3909 |
}; |
| 3910 |
} |
| 3911 |
|
| 3912 |
function initProps$1 (Comp) { |
| 3913 |
var props = Comp.options.props; |
| 3914 |
for (var key in props) { |
| 3915 |
proxy(Comp.prototype, "_props", key); |
| 3916 |
} |
| 3917 |
} |
| 3918 |
|
| 3919 |
function initComputed$1 (Comp) { |
| 3920 |
var computed = Comp.options.computed; |
| 3921 |
for (var key in computed) { |
| 3922 |
defineComputed(Comp.prototype, key, computed[key]); |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
/* */ |
| 3927 |
|
| 3928 |
function initAssetRegisters (Vue) { |
| 3929 |
/** |
| 3930 |
* Create asset registration methods. |
| 3931 |
*/ |
| 3932 |
config._assetTypes.forEach(function (type) { |
| 3933 |
Vue[type] = function ( |
| 3934 |
id, |
| 3935 |
definition |
| 3936 |
) { |
| 3937 |
if (!definition) { |
| 3938 |
return this.options[type + 's'][id] |
| 3939 |
} else { |
| 3940 |
/* istanbul ignore if */ |
| 3941 |
{ |
| 3942 |
if (type === 'component' && config.isReservedTag(id)) { |
| 3943 |
warn( |
| 3944 |
'Do not use built-in or reserved HTML elements as component ' + |
| 3945 |
'id: ' + id |
| 3946 |
); |
| 3947 |
} |
| 3948 |
} |
| 3949 |
if (type === 'component' && isPlainObject(definition)) { |
| 3950 |
definition.name = definition.name || id; |
| 3951 |
definition = this.options._base.extend(definition); |
| 3952 |
} |
| 3953 |
if (type === 'directive' && typeof definition === 'function') { |
| 3954 |
definition = { bind: definition, update: definition }; |
| 3955 |
} |
| 3956 |
this.options[type + 's'][id] = definition; |
| 3957 |
return definition |
| 3958 |
} |
| 3959 |
}; |
| 3960 |
}); |
| 3961 |
} |
| 3962 |
|
| 3963 |
/* */ |
| 3964 |
|
| 3965 |
var patternTypes = [String, RegExp]; |
| 3966 |
|
| 3967 |
function getComponentName (opts) { |
| 3968 |
return opts && (opts.Ctor.options.name || opts.tag) |
| 3969 |
} |
| 3970 |
|
| 3971 |
function matches (pattern, name) { |
| 3972 |
if (typeof pattern === 'string') { |
| 3973 |
return pattern.split(',').indexOf(name) > -1 |
| 3974 |
} else if (pattern instanceof RegExp) { |
| 3975 |
return pattern.test(name) |
| 3976 |
} |
| 3977 |
/* istanbul ignore next */ |
| 3978 |
return false |
| 3979 |
} |
| 3980 |
|
| 3981 |
function pruneCache (cache, filter) { |
| 3982 |
for (var key in cache) { |
| 3983 |
var cachedNode = cache[key]; |
| 3984 |
if (cachedNode) { |
| 3985 |
var name = getComponentName(cachedNode.componentOptions); |
| 3986 |
if (name && !filter(name)) { |
| 3987 |
pruneCacheEntry(cachedNode); |
| 3988 |
cache[key] = null; |
| 3989 |
} |
| 3990 |
} |
| 3991 |
} |
| 3992 |
} |
| 3993 |
|
| 3994 |
function pruneCacheEntry (vnode) { |
| 3995 |
if (vnode) { |
| 3996 |
if (!vnode.componentInstance._inactive) { |
| 3997 |
callHook(vnode.componentInstance, 'deactivated'); |
| 3998 |
} |
| 3999 |
vnode.componentInstance.$destroy(); |
| 4000 |
} |
| 4001 |
} |
| 4002 |
|
| 4003 |
var KeepAlive = { |
| 4004 |
name: 'keep-alive', |
| 4005 |
abstract: true, |
| 4006 |
|
| 4007 |
props: { |
| 4008 |
include: patternTypes, |
| 4009 |
exclude: patternTypes |
| 4010 |
}, |
| 4011 |
|
| 4012 |
created: function created () { |
| 4013 |
this.cache = Object.create(null); |
| 4014 |
}, |
| 4015 |
|
| 4016 |
destroyed: function destroyed () { |
| 4017 |
var this$1 = this; |
| 4018 |
|
| 4019 |
for (var key in this$1.cache) { |
| 4020 |
pruneCacheEntry(this$1.cache[key]); |
| 4021 |
} |
| 4022 |
}, |
| 4023 |
|
| 4024 |
watch: { |
| 4025 |
include: function include (val) { |
| 4026 |
pruneCache(this.cache, function (name) { return matches(val, name); }); |
| 4027 |
}, |
| 4028 |
exclude: function exclude (val) { |
| 4029 |
pruneCache(this.cache, function (name) { return !matches(val, name); }); |
| 4030 |
} |
| 4031 |
}, |
| 4032 |
|
| 4033 |
render: function render () { |
| 4034 |
var vnode = getFirstComponentChild(this.$slots.default); |
| 4035 |
var componentOptions = vnode && vnode.componentOptions; |
| 4036 |
if (componentOptions) { |
| 4037 |
// check pattern |
| 4038 |
var name = getComponentName(componentOptions); |
| 4039 |
if (name && ( |
| 4040 |
(this.include && !matches(this.include, name)) || |
| 4041 |
(this.exclude && matches(this.exclude, name)) |
| 4042 |
)) { |
| 4043 |
return vnode |
| 4044 |
} |
| 4045 |
var key = vnode.key == null |
| 4046 |
// same constructor may get registered as different local components |
| 4047 |
// so cid alone is not enough (#3269) |
| 4048 |
? componentOptions.Ctor.cid + (componentOptions.tag ? ("::" + (componentOptions.tag)) : '') |
| 4049 |
: vnode.key; |
| 4050 |
if (this.cache[key]) { |
| 4051 |
vnode.componentInstance = this.cache[key].componentInstance; |
| 4052 |
} else { |
| 4053 |
this.cache[key] = vnode; |
| 4054 |
} |
| 4055 |
vnode.data.keepAlive = true; |
| 4056 |
} |
| 4057 |
return vnode |
| 4058 |
} |
| 4059 |
}; |
| 4060 |
|
| 4061 |
var builtInComponents = { |
| 4062 |
KeepAlive: KeepAlive |
| 4063 |
}; |
| 4064 |
|
| 4065 |
/* */ |
| 4066 |
|
| 4067 |
function initGlobalAPI (Vue) { |
| 4068 |
// config |
| 4069 |
var configDef = {}; |
| 4070 |
configDef.get = function () { return config; }; |
| 4071 |
{ |
| 4072 |
configDef.set = function () { |
| 4073 |
warn( |
| 4074 |
'Do not replace the Vue.config object, set individual fields instead.' |
| 4075 |
); |
| 4076 |
}; |
| 4077 |
} |
| 4078 |
Object.defineProperty(Vue, 'config', configDef); |
| 4079 |
|
| 4080 |
// exposed util methods. |
| 4081 |
// NOTE: these are not considered part of the public API - avoid relying on |
| 4082 |
// them unless you are aware of the risk. |
| 4083 |
Vue.util = { |
| 4084 |
warn: warn, |
| 4085 |
extend: extend, |
| 4086 |
mergeOptions: mergeOptions, |
| 4087 |
defineReactive: defineReactive$$1 |
| 4088 |
}; |
| 4089 |
|
| 4090 |
Vue.set = set; |
| 4091 |
Vue.delete = del; |
| 4092 |
Vue.nextTick = nextTick; |
| 4093 |
|
| 4094 |
Vue.options = Object.create(null); |
| 4095 |
config._assetTypes.forEach(function (type) { |
| 4096 |
Vue.options[type + 's'] = Object.create(null); |
| 4097 |
}); |
| 4098 |
|
| 4099 |
// this is used to identify the "base" constructor to extend all plain-object |
| 4100 |
// components with in Weex's multi-instance scenarios. |
| 4101 |
Vue.options._base = Vue; |
| 4102 |
|
| 4103 |
extend(Vue.options.components, builtInComponents); |
| 4104 |
|
| 4105 |
initUse(Vue); |
| 4106 |
initMixin$1(Vue); |
| 4107 |
initExtend(Vue); |
| 4108 |
initAssetRegisters(Vue); |
| 4109 |
} |
| 4110 |
|
| 4111 |
initGlobalAPI(Vue$3); |
| 4112 |
|
| 4113 |
Object.defineProperty(Vue$3.prototype, '$isServer', { |
| 4114 |
get: isServerRendering |
| 4115 |
}); |
| 4116 |
|
| 4117 |
Vue$3.version = '2.2.4'; |
| 4118 |
|
| 4119 |
/* */ |
| 4120 |
|
| 4121 |
// attributes that should be using props for binding |
| 4122 |
var acceptValue = makeMap('input,textarea,option,select'); |
| 4123 |
var mustUseProp = function (tag, type, attr) { |
| 4124 |
return ( |
| 4125 |
(attr === 'value' && acceptValue(tag)) && type !== 'button' || |
| 4126 |
(attr === 'selected' && tag === 'option') || |
| 4127 |
(attr === 'checked' && tag === 'input') || |
| 4128 |
(attr === 'muted' && tag === 'video') |
| 4129 |
) |
| 4130 |
}; |
| 4131 |
|
| 4132 |
var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck'); |
| 4133 |
|
| 4134 |
var isBooleanAttr = makeMap( |
| 4135 |
'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' + |
| 4136 |
'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' + |
| 4137 |
'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' + |
| 4138 |
'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' + |
| 4139 |
'required,reversed,scoped,seamless,selected,sortable,translate,' + |
| 4140 |
'truespeed,typemustmatch,visible' |
| 4141 |
); |
| 4142 |
|
| 4143 |
var xlinkNS = 'http://www.w3.org/1999/xlink'; |
| 4144 |
|
| 4145 |
var isXlink = function (name) { |
| 4146 |
return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink' |
| 4147 |
}; |
| 4148 |
|
| 4149 |
var getXlinkProp = function (name) { |
| 4150 |
return isXlink(name) ? name.slice(6, name.length) : '' |
| 4151 |
}; |
| 4152 |
|
| 4153 |
var isFalsyAttrValue = function (val) { |
| 4154 |
return val == null || val === false |
| 4155 |
}; |
| 4156 |
|
| 4157 |
/* */ |
| 4158 |
|
| 4159 |
function genClassForVnode (vnode) { |
| 4160 |
var data = vnode.data; |
| 4161 |
var parentNode = vnode; |
| 4162 |
var childNode = vnode; |
| 4163 |
while (childNode.componentInstance) { |
| 4164 |
childNode = childNode.componentInstance._vnode; |
| 4165 |
if (childNode.data) { |
| 4166 |
data = mergeClassData(childNode.data, data); |
| 4167 |
} |
| 4168 |
} |
| 4169 |
while ((parentNode = parentNode.parent)) { |
| 4170 |
if (parentNode.data) { |
| 4171 |
data = mergeClassData(data, parentNode.data); |
| 4172 |
} |
| 4173 |
} |
| 4174 |
return genClassFromData(data) |
| 4175 |
} |
| 4176 |
|
| 4177 |
function mergeClassData (child, parent) { |
| 4178 |
return { |
| 4179 |
staticClass: concat(child.staticClass, parent.staticClass), |
| 4180 |
class: child.class |
| 4181 |
? [child.class, parent.class] |
| 4182 |
: parent.class |
| 4183 |
} |
| 4184 |
} |
| 4185 |
|
| 4186 |
function genClassFromData (data) { |
| 4187 |
var dynamicClass = data.class; |
| 4188 |
var staticClass = data.staticClass; |
| 4189 |
if (staticClass || dynamicClass) { |
| 4190 |
return concat(staticClass, stringifyClass(dynamicClass)) |
| 4191 |
} |
| 4192 |
/* istanbul ignore next */ |
| 4193 |
return '' |
| 4194 |
} |
| 4195 |
|
| 4196 |
function concat (a, b) { |
| 4197 |
return a ? b ? (a + ' ' + b) : a : (b || '') |
| 4198 |
} |
| 4199 |
|
| 4200 |
function stringifyClass (value) { |
| 4201 |
var res = ''; |
| 4202 |
if (!value) { |
| 4203 |
return res |
| 4204 |
} |
| 4205 |
if (typeof value === 'string') { |
| 4206 |
return value |
| 4207 |
} |
| 4208 |
if (Array.isArray(value)) { |
| 4209 |
var stringified; |
| 4210 |
for (var i = 0, l = value.length; i < l; i++) { |
| 4211 |
if (value[i]) { |
| 4212 |
if ((stringified = stringifyClass(value[i]))) { |
| 4213 |
res += stringified + ' '; |
| 4214 |
} |
| 4215 |
} |
| 4216 |
} |
| 4217 |
return res.slice(0, -1) |
| 4218 |
} |
| 4219 |
if (isObject(value)) { |
| 4220 |
for (var key in value) { |
| 4221 |
if (value[key]) { res += key + ' '; } |
| 4222 |
} |
| 4223 |
return res.slice(0, -1) |
| 4224 |
} |
| 4225 |
/* istanbul ignore next */ |
| 4226 |
return res |
| 4227 |
} |
| 4228 |
|
| 4229 |
/* */ |
| 4230 |
|
| 4231 |
var namespaceMap = { |
| 4232 |
svg: 'http://www.w3.org/2000/svg', |
| 4233 |
math: 'http://www.w3.org/1998/Math/MathML' |
| 4234 |
}; |
| 4235 |
|
| 4236 |
var isHTMLTag = makeMap( |
| 4237 |
'html,body,base,head,link,meta,style,title,' + |
| 4238 |
'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' + |
| 4239 |
'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' + |
| 4240 |
'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' + |
| 4241 |
's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' + |
| 4242 |
'embed,object,param,source,canvas,script,noscript,del,ins,' + |
| 4243 |
'caption,col,colgroup,table,thead,tbody,td,th,tr,' + |
| 4244 |
'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' + |
| 4245 |
'output,progress,select,textarea,' + |
| 4246 |
'details,dialog,menu,menuitem,summary,' + |
| 4247 |
'content,element,shadow,template' |
| 4248 |
); |
| 4249 |
|
| 4250 |
// this map is intentionally selective, only covering SVG elements that may |
| 4251 |
// contain child elements. |
| 4252 |
var isSVG = makeMap( |
| 4253 |
'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' + |
| 4254 |
'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' + |
| 4255 |
'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view', |
| 4256 |
true |
| 4257 |
); |
| 4258 |
|
| 4259 |
var isPreTag = function (tag) { return tag === 'pre'; }; |
| 4260 |
|
| 4261 |
var isReservedTag = function (tag) { |
| 4262 |
return isHTMLTag(tag) || isSVG(tag) |
| 4263 |
}; |
| 4264 |
|
| 4265 |
function getTagNamespace (tag) { |
| 4266 |
if (isSVG(tag)) { |
| 4267 |
return 'svg' |
| 4268 |
} |
| 4269 |
// basic support for MathML |
| 4270 |
// note it doesn't support other MathML elements being component roots |
| 4271 |
if (tag === 'math') { |
| 4272 |
return 'math' |
| 4273 |
} |
| 4274 |
} |
| 4275 |
|
| 4276 |
var unknownElementCache = Object.create(null); |
| 4277 |
function isUnknownElement (tag) { |
| 4278 |
/* istanbul ignore if */ |
| 4279 |
if (!inBrowser) { |
| 4280 |
return true |
| 4281 |
} |
| 4282 |
if (isReservedTag(tag)) { |
| 4283 |
return false |
| 4284 |
} |
| 4285 |
tag = tag.toLowerCase(); |
| 4286 |
/* istanbul ignore if */ |
| 4287 |
if (unknownElementCache[tag] != null) { |
| 4288 |
return unknownElementCache[tag] |
| 4289 |
} |
| 4290 |
var el = document.createElement(tag); |
| 4291 |
if (tag.indexOf('-') > -1) { |
| 4292 |
// http://stackoverflow.com/a/28210364/1070244 |
| 4293 |
return (unknownElementCache[tag] = ( |
| 4294 |
el.constructor === window.HTMLUnknownElement || |
| 4295 |
el.constructor === window.HTMLElement |
| 4296 |
)) |
| 4297 |
} else { |
| 4298 |
return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString())) |
| 4299 |
} |
| 4300 |
} |
| 4301 |
|
| 4302 |
/* */ |
| 4303 |
|
| 4304 |
/** |
| 4305 |
* Query an element selector if it's not an element already. |
| 4306 |
*/ |
| 4307 |
function query (el) { |
| 4308 |
if (typeof el === 'string') { |
| 4309 |
var selected = document.querySelector(el); |
| 4310 |
if (!selected) { |
| 4311 |
"development" !== 'production' && warn( |
| 4312 |
'Cannot find element: ' + el |
| 4313 |
); |
| 4314 |
return document.createElement('div') |
| 4315 |
} |
| 4316 |
return selected |
| 4317 |
} else { |
| 4318 |
return el |
| 4319 |
} |
| 4320 |
} |
| 4321 |
|
| 4322 |
/* */ |
| 4323 |
|
| 4324 |
function createElement$1 (tagName, vnode) { |
| 4325 |
var elm = document.createElement(tagName); |
| 4326 |
if (tagName !== 'select') { |
| 4327 |
return elm |
| 4328 |
} |
| 4329 |
// false or null will remove the attribute but undefined will not |
| 4330 |
if (vnode.data && vnode.data.attrs && vnode.data.attrs.multiple !== undefined) { |
| 4331 |
elm.setAttribute('multiple', 'multiple'); |
| 4332 |
} |
| 4333 |
return elm |
| 4334 |
} |
| 4335 |
|
| 4336 |
function createElementNS (namespace, tagName) { |
| 4337 |
return document.createElementNS(namespaceMap[namespace], tagName) |
| 4338 |
} |
| 4339 |
|
| 4340 |
function createTextNode (text) { |
| 4341 |
return document.createTextNode(text) |
| 4342 |
} |
| 4343 |
|
| 4344 |
function createComment (text) { |
| 4345 |
return document.createComment(text) |
| 4346 |
} |
| 4347 |
|
| 4348 |
function insertBefore (parentNode, newNode, referenceNode) { |
| 4349 |
parentNode.insertBefore(newNode, referenceNode); |
| 4350 |
} |
| 4351 |
|
| 4352 |
function removeChild (node, child) { |
| 4353 |
node.removeChild(child); |
| 4354 |
} |
| 4355 |
|
| 4356 |
function appendChild (node, child) { |
| 4357 |
node.appendChild(child); |
| 4358 |
} |
| 4359 |
|
| 4360 |
function parentNode (node) { |
| 4361 |
return node.parentNode |
| 4362 |
} |
| 4363 |
|
| 4364 |
function nextSibling (node) { |
| 4365 |
return node.nextSibling |
| 4366 |
} |
| 4367 |
|
| 4368 |
function tagName (node) { |
| 4369 |
return node.tagName |
| 4370 |
} |
| 4371 |
|
| 4372 |
function setTextContent (node, text) { |
| 4373 |
node.textContent = text; |
| 4374 |
} |
| 4375 |
|
| 4376 |
function setAttribute (node, key, val) { |
| 4377 |
node.setAttribute(key, val); |
| 4378 |
} |
| 4379 |
|
| 4380 |
|
| 4381 |
var nodeOps = Object.freeze({ |
| 4382 |
createElement: createElement$1, |
| 4383 |
createElementNS: createElementNS, |
| 4384 |
createTextNode: createTextNode, |
| 4385 |
createComment: createComment, |
| 4386 |
insertBefore: insertBefore, |
| 4387 |
removeChild: removeChild, |
| 4388 |
appendChild: appendChild, |
| 4389 |
parentNode: parentNode, |
| 4390 |
nextSibling: nextSibling, |
| 4391 |
tagName: tagName, |
| 4392 |
setTextContent: setTextContent, |
| 4393 |
setAttribute: setAttribute |
| 4394 |
}); |
| 4395 |
|
| 4396 |
/* */ |
| 4397 |
|
| 4398 |
var ref = { |
| 4399 |
create: function create (_, vnode) { |
| 4400 |
registerRef(vnode); |
| 4401 |
}, |
| 4402 |
update: function update (oldVnode, vnode) { |
| 4403 |
if (oldVnode.data.ref !== vnode.data.ref) { |
| 4404 |
registerRef(oldVnode, true); |
| 4405 |
registerRef(vnode); |
| 4406 |
} |
| 4407 |
}, |
| 4408 |
destroy: function destroy (vnode) { |
| 4409 |
registerRef(vnode, true); |
| 4410 |
} |
| 4411 |
}; |
| 4412 |
|
| 4413 |
function registerRef (vnode, isRemoval) { |
| 4414 |
var key = vnode.data.ref; |
| 4415 |
if (!key) { return } |
| 4416 |
|
| 4417 |
var vm = vnode.context; |
| 4418 |
var ref = vnode.componentInstance || vnode.elm; |
| 4419 |
var refs = vm.$refs; |
| 4420 |
if (isRemoval) { |
| 4421 |
if (Array.isArray(refs[key])) { |
| 4422 |
remove(refs[key], ref); |
| 4423 |
} else if (refs[key] === ref) { |
| 4424 |
refs[key] = undefined; |
| 4425 |
} |
| 4426 |
} else { |
| 4427 |
if (vnode.data.refInFor) { |
| 4428 |
if (Array.isArray(refs[key]) && refs[key].indexOf(ref) < 0) { |
| 4429 |
refs[key].push(ref); |
| 4430 |
} else { |
| 4431 |
refs[key] = [ref]; |
| 4432 |
} |
| 4433 |
} else { |
| 4434 |
refs[key] = ref; |
| 4435 |
} |
| 4436 |
} |
| 4437 |
} |
| 4438 |
|
| 4439 |
/** |
| 4440 |
* Virtual DOM patching algorithm based on Snabbdom by |
| 4441 |
* Simon Friis Vindum (@paldepind) |
| 4442 |
* Licensed under the MIT License |
| 4443 |
* https://github.com/paldepind/snabbdom/blob/master/LICENSE |
| 4444 |
* |
| 4445 |
* modified by Evan You (@yyx990803) |
| 4446 |
* |
| 4447 |
|
| 4448 |
/* |
| 4449 |
* Not type-checking this because this file is perf-critical and the cost |
| 4450 |
* of making flow understand it is not worth it. |
| 4451 |
*/ |
| 4452 |
|
| 4453 |
var emptyNode = new VNode('', {}, []); |
| 4454 |
|
| 4455 |
var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; |
| 4456 |
|
| 4457 |
function isUndef (s) { |
| 4458 |
return s == null |
| 4459 |
} |
| 4460 |
|
| 4461 |
function isDef (s) { |
| 4462 |
return s != null |
| 4463 |
} |
| 4464 |
|
| 4465 |
function sameVnode (vnode1, vnode2) { |
| 4466 |
return ( |
| 4467 |
vnode1.key === vnode2.key && |
| 4468 |
vnode1.tag === vnode2.tag && |
| 4469 |
vnode1.isComment === vnode2.isComment && |
| 4470 |
!vnode1.data === !vnode2.data |
| 4471 |
) |
| 4472 |
} |
| 4473 |
|
| 4474 |
function createKeyToOldIdx (children, beginIdx, endIdx) { |
| 4475 |
var i, key; |
| 4476 |
var map = {}; |
| 4477 |
for (i = beginIdx; i <= endIdx; ++i) { |
| 4478 |
key = children[i].key; |
| 4479 |
if (isDef(key)) { map[key] = i; } |
| 4480 |
} |
| 4481 |
return map |
| 4482 |
} |
| 4483 |
|
| 4484 |
function createPatchFunction (backend) { |
| 4485 |
var i, j; |
| 4486 |
var cbs = {}; |
| 4487 |
|
| 4488 |
var modules = backend.modules; |
| 4489 |
var nodeOps = backend.nodeOps; |
| 4490 |
|
| 4491 |
for (i = 0; i < hooks.length; ++i) { |
| 4492 |
cbs[hooks[i]] = []; |
| 4493 |
for (j = 0; j < modules.length; ++j) { |
| 4494 |
if (modules[j][hooks[i]] !== undefined) { cbs[hooks[i]].push(modules[j][hooks[i]]); } |
| 4495 |
} |
| 4496 |
} |
| 4497 |
|
| 4498 |
function emptyNodeAt (elm) { |
| 4499 |
return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm) |
| 4500 |
} |
| 4501 |
|
| 4502 |
function createRmCb (childElm, listeners) { |
| 4503 |
function remove$$1 () { |
| 4504 |
if (--remove$$1.listeners === 0) { |
| 4505 |
removeNode(childElm); |
| 4506 |
} |
| 4507 |
} |
| 4508 |
remove$$1.listeners = listeners; |
| 4509 |
return remove$$1 |
| 4510 |
} |
| 4511 |
|
| 4512 |
function removeNode (el) { |
| 4513 |
var parent = nodeOps.parentNode(el); |
| 4514 |
// element may have already been removed due to v-html / v-text |
| 4515 |
if (parent) { |
| 4516 |
nodeOps.removeChild(parent, el); |
| 4517 |
} |
| 4518 |
} |
| 4519 |
|
| 4520 |
var inPre = 0; |
| 4521 |
function createElm (vnode, insertedVnodeQueue, parentElm, refElm, nested) { |
| 4522 |
vnode.isRootInsert = !nested; // for transition enter check |
| 4523 |
if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) { |
| 4524 |
return |
| 4525 |
} |
| 4526 |
|
| 4527 |
var data = vnode.data; |
| 4528 |
var children = vnode.children; |
| 4529 |
var tag = vnode.tag; |
| 4530 |
if (isDef(tag)) { |
| 4531 |
{ |
| 4532 |
if (data && data.pre) { |
| 4533 |
inPre++; |
| 4534 |
} |
| 4535 |
if ( |
| 4536 |
!inPre && |
| 4537 |
!vnode.ns && |
| 4538 |
!(config.ignoredElements.length && config.ignoredElements.indexOf(tag) > -1) && |
| 4539 |
config.isUnknownElement(tag) |
| 4540 |
) { |
| 4541 |
warn( |
| 4542 |
'Unknown custom element: <' + tag + '> - did you ' + |
| 4543 |
'register the component correctly? For recursive components, ' + |
| 4544 |
'make sure to provide the "name" option.', |
| 4545 |
vnode.context |
| 4546 |
); |
| 4547 |
} |
| 4548 |
} |
| 4549 |
vnode.elm = vnode.ns |
| 4550 |
? nodeOps.createElementNS(vnode.ns, tag) |
| 4551 |
: nodeOps.createElement(tag, vnode); |
| 4552 |
setScope(vnode); |
| 4553 |
|
| 4554 |
/* istanbul ignore if */ |
| 4555 |
{ |
| 4556 |
createChildren(vnode, children, insertedVnodeQueue); |
| 4557 |
if (isDef(data)) { |
| 4558 |
invokeCreateHooks(vnode, insertedVnodeQueue); |
| 4559 |
} |
| 4560 |
insert(parentElm, vnode.elm, refElm); |
| 4561 |
} |
| 4562 |
|
| 4563 |
if ("development" !== 'production' && data && data.pre) { |
| 4564 |
inPre--; |
| 4565 |
} |
| 4566 |
} else if (vnode.isComment) { |
| 4567 |
vnode.elm = nodeOps.createComment(vnode.text); |
| 4568 |
insert(parentElm, vnode.elm, refElm); |
| 4569 |
} else { |
| 4570 |
vnode.elm = nodeOps.createTextNode(vnode.text); |
| 4571 |
insert(parentElm, vnode.elm, refElm); |
| 4572 |
} |
| 4573 |
} |
| 4574 |
|
| 4575 |
function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) { |
| 4576 |
var i = vnode.data; |
| 4577 |
if (isDef(i)) { |
| 4578 |
var isReactivated = isDef(vnode.componentInstance) && i.keepAlive; |
| 4579 |
if (isDef(i = i.hook) && isDef(i = i.init)) { |
| 4580 |
i(vnode, false /* hydrating */, parentElm, refElm); |
| 4581 |
} |
| 4582 |
// after calling the init hook, if the vnode is a child component |
| 4583 |
// it should've created a child instance and mounted it. the child |
| 4584 |
// component also has set the placeholder vnode's elm. |
| 4585 |
// in that case we can just return the element and be done. |
| 4586 |
if (isDef(vnode.componentInstance)) { |
| 4587 |
initComponent(vnode, insertedVnodeQueue); |
| 4588 |
if (isReactivated) { |
| 4589 |
reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm); |
| 4590 |
} |
| 4591 |
return true |
| 4592 |
} |
| 4593 |
} |
| 4594 |
} |
| 4595 |
|
| 4596 |
function initComponent (vnode, insertedVnodeQueue) { |
| 4597 |
if (vnode.data.pendingInsert) { |
| 4598 |
insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert); |
| 4599 |
} |
| 4600 |
vnode.elm = vnode.componentInstance.$el; |
| 4601 |
if (isPatchable(vnode)) { |
| 4602 |
invokeCreateHooks(vnode, insertedVnodeQueue); |
| 4603 |
setScope(vnode); |
| 4604 |
} else { |
| 4605 |
// empty component root. |
| 4606 |
// skip all element-related modules except for ref (#3455) |
| 4607 |
registerRef(vnode); |
| 4608 |
// make sure to invoke the insert hook |
| 4609 |
insertedVnodeQueue.push(vnode); |
| 4610 |
} |
| 4611 |
} |
| 4612 |
|
| 4613 |
function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) { |
| 4614 |
var i; |
| 4615 |
// hack for #4339: a reactivated component with inner transition |
| 4616 |
// does not trigger because the inner node's created hooks are not called |
| 4617 |
// again. It's not ideal to involve module-specific logic in here but |
| 4618 |
// there doesn't seem to be a better way to do it. |
| 4619 |
var innerNode = vnode; |
| 4620 |
while (innerNode.componentInstance) { |
| 4621 |
innerNode = innerNode.componentInstance._vnode; |
| 4622 |
if (isDef(i = innerNode.data) && isDef(i = i.transition)) { |
| 4623 |
for (i = 0; i < cbs.activate.length; ++i) { |
| 4624 |
cbs.activate[i](emptyNode, innerNode); |
| 4625 |
} |
| 4626 |
insertedVnodeQueue.push(innerNode); |
| 4627 |
break |
| 4628 |
} |
| 4629 |
} |
| 4630 |
// unlike a newly created component, |
| 4631 |
// a reactivated keep-alive component doesn't insert itself |
| 4632 |
insert(parentElm, vnode.elm, refElm); |
| 4633 |
} |
| 4634 |
|
| 4635 |
function insert (parent, elm, ref) { |
| 4636 |
if (parent) { |
| 4637 |
if (ref) { |
| 4638 |
nodeOps.insertBefore(parent, elm, ref); |
| 4639 |
} else { |
| 4640 |
nodeOps.appendChild(parent, elm); |
| 4641 |
} |
| 4642 |
} |
| 4643 |
} |
| 4644 |
|
| 4645 |
function createChildren (vnode, children, insertedVnodeQueue) { |
| 4646 |
if (Array.isArray(children)) { |
| 4647 |
for (var i = 0; i < children.length; ++i) { |
| 4648 |
createElm(children[i], insertedVnodeQueue, vnode.elm, null, true); |
| 4649 |
} |
| 4650 |
} else if (isPrimitive(vnode.text)) { |
| 4651 |
nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text)); |
| 4652 |
} |
| 4653 |
} |
| 4654 |
|
| 4655 |
function isPatchable (vnode) { |
| 4656 |
while (vnode.componentInstance) { |
| 4657 |
vnode = vnode.componentInstance._vnode; |
| 4658 |
} |
| 4659 |
return isDef(vnode.tag) |
| 4660 |
} |
| 4661 |
|
| 4662 |
function invokeCreateHooks (vnode, insertedVnodeQueue) { |
| 4663 |
for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) { |
| 4664 |
cbs.create[i$1](emptyNode, vnode); |
| 4665 |
} |
| 4666 |
i = vnode.data.hook; // Reuse variable |
| 4667 |
if (isDef(i)) { |
| 4668 |
if (i.create) { i.create(emptyNode, vnode); } |
| 4669 |
if (i.insert) { insertedVnodeQueue.push(vnode); } |
| 4670 |
} |
| 4671 |
} |
| 4672 |
|
| 4673 |
// set scope id attribute for scoped CSS. |
| 4674 |
// this is implemented as a special case to avoid the overhead |
| 4675 |
// of going through the normal attribute patching process. |
| 4676 |
function setScope (vnode) { |
| 4677 |
var i; |
| 4678 |
var ancestor = vnode; |
| 4679 |
while (ancestor) { |
| 4680 |
if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) { |
| 4681 |
nodeOps.setAttribute(vnode.elm, i, ''); |
| 4682 |
} |
| 4683 |
ancestor = ancestor.parent; |
| 4684 |
} |
| 4685 |
// for slot content they should also get the scopeId from the host instance. |
| 4686 |
if (isDef(i = activeInstance) && |
| 4687 |
i !== vnode.context && |
| 4688 |
isDef(i = i.$options._scopeId)) { |
| 4689 |
nodeOps.setAttribute(vnode.elm, i, ''); |
| 4690 |
} |
| 4691 |
} |
| 4692 |
|
| 4693 |
function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx, insertedVnodeQueue) { |
| 4694 |
for (; startIdx <= endIdx; ++startIdx) { |
| 4695 |
createElm(vnodes[startIdx], insertedVnodeQueue, parentElm, refElm); |
| 4696 |
} |
| 4697 |
} |
| 4698 |
|
| 4699 |
function invokeDestroyHook (vnode) { |
| 4700 |
var i, j; |
| 4701 |
var data = vnode.data; |
| 4702 |
if (isDef(data)) { |
| 4703 |
if (isDef(i = data.hook) && isDef(i = i.destroy)) { i(vnode); } |
| 4704 |
for (i = 0; i < cbs.destroy.length; ++i) { cbs.destroy[i](vnode); } |
| 4705 |
} |
| 4706 |
if (isDef(i = vnode.children)) { |
| 4707 |
for (j = 0; j < vnode.children.length; ++j) { |
| 4708 |
invokeDestroyHook(vnode.children[j]); |
| 4709 |
} |
| 4710 |
} |
| 4711 |
} |
| 4712 |
|
| 4713 |
function removeVnodes (parentElm, vnodes, startIdx, endIdx) { |
| 4714 |
for (; startIdx <= endIdx; ++startIdx) { |
| 4715 |
var ch = vnodes[startIdx]; |
| 4716 |
if (isDef(ch)) { |
| 4717 |
if (isDef(ch.tag)) { |
| 4718 |
removeAndInvokeRemoveHook(ch); |
| 4719 |
invokeDestroyHook(ch); |
| 4720 |
} else { // Text node |
| 4721 |
removeNode(ch.elm); |
| 4722 |
} |
| 4723 |
} |
| 4724 |
} |
| 4725 |
} |
| 4726 |
|
| 4727 |
function removeAndInvokeRemoveHook (vnode, rm) { |
| 4728 |
if (rm || isDef(vnode.data)) { |
| 4729 |
var listeners = cbs.remove.length + 1; |
| 4730 |
if (!rm) { |
| 4731 |
// directly removing |
| 4732 |
rm = createRmCb(vnode.elm, listeners); |
| 4733 |
} else { |
| 4734 |
// we have a recursively passed down rm callback |
| 4735 |
// increase the listeners count |
| 4736 |
rm.listeners += listeners; |
| 4737 |
} |
| 4738 |
// recursively invoke hooks on child component root node |
| 4739 |
if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) { |
| 4740 |
removeAndInvokeRemoveHook(i, rm); |
| 4741 |
} |
| 4742 |
for (i = 0; i < cbs.remove.length; ++i) { |
| 4743 |
cbs.remove[i](vnode, rm); |
| 4744 |
} |
| 4745 |
if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) { |
| 4746 |
i(vnode, rm); |
| 4747 |
} else { |
| 4748 |
rm(); |
| 4749 |
} |
| 4750 |
} else { |
| 4751 |
removeNode(vnode.elm); |
| 4752 |
} |
| 4753 |
} |
| 4754 |
|
| 4755 |
function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) { |
| 4756 |
var oldStartIdx = 0; |
| 4757 |
var newStartIdx = 0; |
| 4758 |
var oldEndIdx = oldCh.length - 1; |
| 4759 |
var oldStartVnode = oldCh[0]; |
| 4760 |
var oldEndVnode = oldCh[oldEndIdx]; |
| 4761 |
var newEndIdx = newCh.length - 1; |
| 4762 |
var newStartVnode = newCh[0]; |
| 4763 |
var newEndVnode = newCh[newEndIdx]; |
| 4764 |
var oldKeyToIdx, idxInOld, elmToMove, refElm; |
| 4765 |
|
| 4766 |
// removeOnly is a special flag used only by <transition-group> |
| 4767 |
// to ensure removed elements stay in correct relative positions |
| 4768 |
// during leaving transitions |
| 4769 |
var canMove = !removeOnly; |
| 4770 |
|
| 4771 |
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) { |
| 4772 |
if (isUndef(oldStartVnode)) { |
| 4773 |
oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left |
| 4774 |
} else if (isUndef(oldEndVnode)) { |
| 4775 |
oldEndVnode = oldCh[--oldEndIdx]; |
| 4776 |
} else if (sameVnode(oldStartVnode, newStartVnode)) { |
| 4777 |
patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue); |
| 4778 |
oldStartVnode = oldCh[++oldStartIdx]; |
| 4779 |
newStartVnode = newCh[++newStartIdx]; |
| 4780 |
} else if (sameVnode(oldEndVnode, newEndVnode)) { |
| 4781 |
patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue); |
| 4782 |
oldEndVnode = oldCh[--oldEndIdx]; |
| 4783 |
newEndVnode = newCh[--newEndIdx]; |
| 4784 |
} else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right |
| 4785 |
patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue); |
| 4786 |
canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm)); |
| 4787 |
oldStartVnode = oldCh[++oldStartIdx]; |
| 4788 |
newEndVnode = newCh[--newEndIdx]; |
| 4789 |
} else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left |
| 4790 |
patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue); |
| 4791 |
canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm); |
| 4792 |
oldEndVnode = oldCh[--oldEndIdx]; |
| 4793 |
newStartVnode = newCh[++newStartIdx]; |
| 4794 |
} else { |
| 4795 |
if (isUndef(oldKeyToIdx)) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); } |
| 4796 |
idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null; |
| 4797 |
if (isUndef(idxInOld)) { // New element |
| 4798 |
createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm); |
| 4799 |
newStartVnode = newCh[++newStartIdx]; |
| 4800 |
} else { |
| 4801 |
elmToMove = oldCh[idxInOld]; |
| 4802 |
/* istanbul ignore if */ |
| 4803 |
if ("development" !== 'production' && !elmToMove) { |
| 4804 |
warn( |
| 4805 |
'It seems there are duplicate keys that is causing an update error. ' + |
| 4806 |
'Make sure each v-for item has a unique key.' |
| 4807 |
); |
| 4808 |
} |
| 4809 |
if (sameVnode(elmToMove, newStartVnode)) { |
| 4810 |
patchVnode(elmToMove, newStartVnode, insertedVnodeQueue); |
| 4811 |
oldCh[idxInOld] = undefined; |
| 4812 |
canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm); |
| 4813 |
newStartVnode = newCh[++newStartIdx]; |
| 4814 |
} else { |
| 4815 |
// same key but different element. treat as new element |
| 4816 |
createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm); |
| 4817 |
newStartVnode = newCh[++newStartIdx]; |
| 4818 |
} |
| 4819 |
} |
| 4820 |
} |
| 4821 |
} |
| 4822 |
if (oldStartIdx > oldEndIdx) { |
| 4823 |
refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm; |
| 4824 |
addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx, insertedVnodeQueue); |
| 4825 |
} else if (newStartIdx > newEndIdx) { |
| 4826 |
removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); |
| 4827 |
} |
| 4828 |
} |
| 4829 |
|
| 4830 |
function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) { |
| 4831 |
if (oldVnode === vnode) { |
| 4832 |
return |
| 4833 |
} |
| 4834 |
// reuse element for static trees. |
| 4835 |
// note we only do this if the vnode is cloned - |
| 4836 |
// if the new node is not cloned it means the render functions have been |
| 4837 |
// reset by the hot-reload-api and we need to do a proper re-render. |
| 4838 |
if (vnode.isStatic && |
| 4839 |
oldVnode.isStatic && |
| 4840 |
vnode.key === oldVnode.key && |
| 4841 |
(vnode.isCloned || vnode.isOnce)) { |
| 4842 |
vnode.elm = oldVnode.elm; |
| 4843 |
vnode.componentInstance = oldVnode.componentInstance; |
| 4844 |
return |
| 4845 |
} |
| 4846 |
var i; |
| 4847 |
var data = vnode.data; |
| 4848 |
var hasData = isDef(data); |
| 4849 |
if (hasData && isDef(i = data.hook) && isDef(i = i.prepatch)) { |
| 4850 |
i(oldVnode, vnode); |
| 4851 |
} |
| 4852 |
var elm = vnode.elm = oldVnode.elm; |
| 4853 |
var oldCh = oldVnode.children; |
| 4854 |
var ch = vnode.children; |
| 4855 |
if (hasData && isPatchable(vnode)) { |
| 4856 |
for (i = 0; i < cbs.update.length; ++i) { cbs.update[i](oldVnode, vnode); } |
| 4857 |
if (isDef(i = data.hook) && isDef(i = i.update)) { i(oldVnode, vnode); } |
| 4858 |
} |
| 4859 |
if (isUndef(vnode.text)) { |
| 4860 |
if (isDef(oldCh) && isDef(ch)) { |
| 4861 |
if (oldCh !== ch) { updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly); } |
| 4862 |
} else if (isDef(ch)) { |
| 4863 |
if (isDef(oldVnode.text)) { nodeOps.setTextContent(elm, ''); } |
| 4864 |
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue); |
| 4865 |
} else if (isDef(oldCh)) { |
| 4866 |
removeVnodes(elm, oldCh, 0, oldCh.length - 1); |
| 4867 |
} else if (isDef(oldVnode.text)) { |
| 4868 |
nodeOps.setTextContent(elm, ''); |
| 4869 |
} |
| 4870 |
} else if (oldVnode.text !== vnode.text) { |
| 4871 |
nodeOps.setTextContent(elm, vnode.text); |
| 4872 |
} |
| 4873 |
if (hasData) { |
| 4874 |
if (isDef(i = data.hook) && isDef(i = i.postpatch)) { i(oldVnode, vnode); } |
| 4875 |
} |
| 4876 |
} |
| 4877 |
|
| 4878 |
function invokeInsertHook (vnode, queue, initial) { |
| 4879 |
// delay insert hooks for component root nodes, invoke them after the |
| 4880 |
// element is really inserted |
| 4881 |
if (initial && vnode.parent) { |
| 4882 |
vnode.parent.data.pendingInsert = queue; |
| 4883 |
} else { |
| 4884 |
for (var i = 0; i < queue.length; ++i) { |
| 4885 |
queue[i].data.hook.insert(queue[i]); |
| 4886 |
} |
| 4887 |
} |
| 4888 |
} |
| 4889 |
|
| 4890 |
var bailed = false; |
| 4891 |
// list of modules that can skip create hook during hydration because they |
| 4892 |
// are already rendered on the client or has no need for initialization |
| 4893 |
var isRenderedModule = makeMap('attrs,style,class,staticClass,staticStyle,key'); |
| 4894 |
|
| 4895 |
// Note: this is a browser-only function so we can assume elms are DOM nodes. |
| 4896 |
function hydrate (elm, vnode, insertedVnodeQueue) { |
| 4897 |
{ |
| 4898 |
if (!assertNodeMatch(elm, vnode)) { |
| 4899 |
return false |
| 4900 |
} |
| 4901 |
} |
| 4902 |
vnode.elm = elm; |
| 4903 |
var tag = vnode.tag; |
| 4904 |
var data = vnode.data; |
| 4905 |
var children = vnode.children; |
| 4906 |
if (isDef(data)) { |
| 4907 |
if (isDef(i = data.hook) && isDef(i = i.init)) { i(vnode, true /* hydrating */); } |
| 4908 |
if (isDef(i = vnode.componentInstance)) { |
| 4909 |
// child component. it should have hydrated its own tree. |
| 4910 |
initComponent(vnode, insertedVnodeQueue); |
| 4911 |
return true |
| 4912 |
} |
| 4913 |
} |
| 4914 |
if (isDef(tag)) { |
| 4915 |
if (isDef(children)) { |
| 4916 |
// empty element, allow client to pick up and populate children |
| 4917 |
if (!elm.hasChildNodes()) { |
| 4918 |
createChildren(vnode, children, insertedVnodeQueue); |
| 4919 |
} else { |
| 4920 |
var childrenMatch = true; |
| 4921 |
var childNode = elm.firstChild; |
| 4922 |
for (var i$1 = 0; i$1 < children.length; i$1++) { |
| 4923 |
if (!childNode || !hydrate(childNode, children[i$1], insertedVnodeQueue)) { |
| 4924 |
childrenMatch = false; |
| 4925 |
break |
| 4926 |
} |
| 4927 |
childNode = childNode.nextSibling; |
| 4928 |
} |
| 4929 |
// if childNode is not null, it means the actual childNodes list is |
| 4930 |
// longer than the virtual children list. |
| 4931 |
if (!childrenMatch || childNode) { |
| 4932 |
if ("development" !== 'production' && |
| 4933 |
typeof console !== 'undefined' && |
| 4934 |
!bailed) { |
| 4935 |
bailed = true; |
| 4936 |
console.warn('Parent: ', elm); |
| 4937 |
console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children); |
| 4938 |
} |
| 4939 |
return false |
| 4940 |
} |
| 4941 |
} |
| 4942 |
} |
| 4943 |
if (isDef(data)) { |
| 4944 |
for (var key in data) { |
| 4945 |
if (!isRenderedModule(key)) { |
| 4946 |
invokeCreateHooks(vnode, insertedVnodeQueue); |
| 4947 |
break |
| 4948 |
} |
| 4949 |
} |
| 4950 |
} |
| 4951 |
} else if (elm.data !== vnode.text) { |
| 4952 |
elm.data = vnode.text; |
| 4953 |
} |
| 4954 |
return true |
| 4955 |
} |
| 4956 |
|
| 4957 |
function assertNodeMatch (node, vnode) { |
| 4958 |
if (vnode.tag) { |
| 4959 |
return ( |
| 4960 |
vnode.tag.indexOf('vue-component') === 0 || |
| 4961 |
vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase()) |
| 4962 |
) |
| 4963 |
} else { |
| 4964 |
return node.nodeType === (vnode.isComment ? 8 : 3) |
| 4965 |
} |
| 4966 |
} |
| 4967 |
|
| 4968 |
return function patch (oldVnode, vnode, hydrating, removeOnly, parentElm, refElm) { |
| 4969 |
if (!vnode) { |
| 4970 |
if (oldVnode) { invokeDestroyHook(oldVnode); } |
| 4971 |
return |
| 4972 |
} |
| 4973 |
|
| 4974 |
var isInitialPatch = false; |
| 4975 |
var insertedVnodeQueue = []; |
| 4976 |
|
| 4977 |
if (!oldVnode) { |
| 4978 |
// empty mount (likely as component), create new root element |
| 4979 |
isInitialPatch = true; |
| 4980 |
createElm(vnode, insertedVnodeQueue, parentElm, refElm); |
| 4981 |
} else { |
| 4982 |
var isRealElement = isDef(oldVnode.nodeType); |
| 4983 |
if (!isRealElement && sameVnode(oldVnode, vnode)) { |
| 4984 |
// patch existing root node |
| 4985 |
patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly); |
| 4986 |
} else { |
| 4987 |
if (isRealElement) { |
| 4988 |
// mounting to a real element |
| 4989 |
// check if this is server-rendered content and if we can perform |
| 4990 |
// a successful hydration. |
| 4991 |
if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { |
| 4992 |
oldVnode.removeAttribute('server-rendered'); |
| 4993 |
hydrating = true; |
| 4994 |
} |
| 4995 |
if (hydrating) { |
| 4996 |
if (hydrate(oldVnode, vnode, insertedVnodeQueue)) { |
| 4997 |
invokeInsertHook(vnode, insertedVnodeQueue, true); |
| 4998 |
return oldVnode |
| 4999 |
} else { |
| 5000 |
warn( |
| 5001 |
'The client-side rendered virtual DOM tree is not matching ' + |
| 5002 |
'server-rendered content. This is likely caused by incorrect ' + |
| 5003 |
'HTML markup, for example nesting block-level elements inside ' + |
| 5004 |
'<p>, or missing <tbody>. Bailing hydration and performing ' + |
| 5005 |
'full client-side render.' |
| 5006 |
); |
| 5007 |
} |
| 5008 |
} |
| 5009 |
// either not server-rendered, or hydration failed. |
| 5010 |
// create an empty node and replace it |
| 5011 |
oldVnode = emptyNodeAt(oldVnode); |
| 5012 |
} |
| 5013 |
// replacing existing element |
| 5014 |
var oldElm = oldVnode.elm; |
| 5015 |
var parentElm$1 = nodeOps.parentNode(oldElm); |
| 5016 |
createElm( |
| 5017 |
vnode, |
| 5018 |
insertedVnodeQueue, |
| 5019 |
// extremely rare edge case: do not insert if old element is in a |
| 5020 |
// leaving transition. Only happens when combining transition + |
| 5021 |
// keep-alive + HOCs. (#4590) |
| 5022 |
oldElm._leaveCb ? null : parentElm$1, |
| 5023 |
nodeOps.nextSibling(oldElm) |
| 5024 |
); |
| 5025 |
|
| 5026 |
if (vnode.parent) { |
| 5027 |
// component root element replaced. |
| 5028 |
// update parent placeholder node element, recursively |
| 5029 |
var ancestor = vnode.parent; |
| 5030 |
while (ancestor) { |
| 5031 |
ancestor.elm = vnode.elm; |
| 5032 |
ancestor = ancestor.parent; |
| 5033 |
} |
| 5034 |
if (isPatchable(vnode)) { |
| 5035 |
for (var i = 0; i < cbs.create.length; ++i) { |
| 5036 |
cbs.create[i](emptyNode, vnode.parent); |
| 5037 |
} |
| 5038 |
} |
| 5039 |
} |
| 5040 |
|
| 5041 |
if (parentElm$1 !== null) { |
| 5042 |
removeVnodes(parentElm$1, [oldVnode], 0, 0); |
| 5043 |
} else if (isDef(oldVnode.tag)) { |
| 5044 |
invokeDestroyHook(oldVnode); |
| 5045 |
} |
| 5046 |
} |
| 5047 |
} |
| 5048 |
|
| 5049 |
invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch); |
| 5050 |
return vnode.elm |
| 5051 |
} |
| 5052 |
} |
| 5053 |
|
| 5054 |
/* */ |
| 5055 |
|
| 5056 |
var directives = { |
| 5057 |
create: updateDirectives, |
| 5058 |
update: updateDirectives, |
| 5059 |
destroy: function unbindDirectives (vnode) { |
| 5060 |
updateDirectives(vnode, emptyNode); |
| 5061 |
} |
| 5062 |
}; |
| 5063 |
|
| 5064 |
function updateDirectives (oldVnode, vnode) { |
| 5065 |
if (oldVnode.data.directives || vnode.data.directives) { |
| 5066 |
_update(oldVnode, vnode); |
| 5067 |
} |
| 5068 |
} |
| 5069 |
|
| 5070 |
function _update (oldVnode, vnode) { |
| 5071 |
var isCreate = oldVnode === emptyNode; |
| 5072 |
var isDestroy = vnode === emptyNode; |
| 5073 |
var oldDirs = normalizeDirectives$1(oldVnode.data.directives, oldVnode.context); |
| 5074 |
var newDirs = normalizeDirectives$1(vnode.data.directives, vnode.context); |
| 5075 |
|
| 5076 |
var dirsWithInsert = []; |
| 5077 |
var dirsWithPostpatch = []; |
| 5078 |
|
| 5079 |
var key, oldDir, dir; |
| 5080 |
for (key in newDirs) { |
| 5081 |
oldDir = oldDirs[key]; |
| 5082 |
dir = newDirs[key]; |
| 5083 |
if (!oldDir) { |
| 5084 |
// new directive, bind |
| 5085 |
callHook$1(dir, 'bind', vnode, oldVnode); |
| 5086 |
if (dir.def && dir.def.inserted) { |
| 5087 |
dirsWithInsert.push(dir); |
| 5088 |
} |
| 5089 |
} else { |
| 5090 |
// existing directive, update |
| 5091 |
dir.oldValue = oldDir.value; |
| 5092 |
callHook$1(dir, 'update', vnode, oldVnode); |
| 5093 |
if (dir.def && dir.def.componentUpdated) { |
| 5094 |
dirsWithPostpatch.push(dir); |
| 5095 |
} |
| 5096 |
} |
| 5097 |
} |
| 5098 |
|
| 5099 |
if (dirsWithInsert.length) { |
| 5100 |
var callInsert = function () { |
| 5101 |
for (var i = 0; i < dirsWithInsert.length; i++) { |
| 5102 |
callHook$1(dirsWithInsert[i], 'inserted', vnode, oldVnode); |
| 5103 |
} |
| 5104 |
}; |
| 5105 |
if (isCreate) { |
| 5106 |
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert); |
| 5107 |
} else { |
| 5108 |
callInsert(); |
| 5109 |
} |
| 5110 |
} |
| 5111 |
|
| 5112 |
if (dirsWithPostpatch.length) { |
| 5113 |
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', function () { |
| 5114 |
for (var i = 0; i < dirsWithPostpatch.length; i++) { |
| 5115 |
callHook$1(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode); |
| 5116 |
} |
| 5117 |
}); |
| 5118 |
} |
| 5119 |
|
| 5120 |
if (!isCreate) { |
| 5121 |
for (key in oldDirs) { |
| 5122 |
if (!newDirs[key]) { |
| 5123 |
// no longer present, unbind |
| 5124 |
callHook$1(oldDirs[key], 'unbind', oldVnode, oldVnode, isDestroy); |
| 5125 |
} |
| 5126 |
} |
| 5127 |
} |
| 5128 |
} |
| 5129 |
|
| 5130 |
var emptyModifiers = Object.create(null); |
| 5131 |
|
| 5132 |
function normalizeDirectives$1 ( |
| 5133 |
dirs, |
| 5134 |
vm |
| 5135 |
) { |
| 5136 |
var res = Object.create(null); |
| 5137 |
if (!dirs) { |
| 5138 |
return res |
| 5139 |
} |
| 5140 |
var i, dir; |
| 5141 |
for (i = 0; i < dirs.length; i++) { |
| 5142 |
dir = dirs[i]; |
| 5143 |
if (!dir.modifiers) { |
| 5144 |
dir.modifiers = emptyModifiers; |
| 5145 |
} |
| 5146 |
res[getRawDirName(dir)] = dir; |
| 5147 |
dir.def = resolveAsset(vm.$options, 'directives', dir.name, true); |
| 5148 |
} |
| 5149 |
return res |
| 5150 |
} |
| 5151 |
|
| 5152 |
function getRawDirName (dir) { |
| 5153 |
return dir.rawName || ((dir.name) + "." + (Object.keys(dir.modifiers || {}).join('.'))) |
| 5154 |
} |
| 5155 |
|
| 5156 |
function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { |
| 5157 |
var fn = dir.def && dir.def[hook]; |
| 5158 |
if (fn) { |
| 5159 |
fn(vnode.elm, dir, vnode, oldVnode, isDestroy); |
| 5160 |
} |
| 5161 |
} |
| 5162 |
|
| 5163 |
var baseModules = [ |
| 5164 |
ref, |
| 5165 |
directives |
| 5166 |
]; |
| 5167 |
|
| 5168 |
/* */ |
| 5169 |
|
| 5170 |
function updateAttrs (oldVnode, vnode) { |
| 5171 |
if (!oldVnode.data.attrs && !vnode.data.attrs) { |
| 5172 |
return |
| 5173 |
} |
| 5174 |
var key, cur, old; |
| 5175 |
var elm = vnode.elm; |
| 5176 |
var oldAttrs = oldVnode.data.attrs || {}; |
| 5177 |
var attrs = vnode.data.attrs || {}; |
| 5178 |
// clone observed objects, as the user probably wants to mutate it |
| 5179 |
if (attrs.__ob__) { |
| 5180 |
attrs = vnode.data.attrs = extend({}, attrs); |
| 5181 |
} |
| 5182 |
|
| 5183 |
for (key in attrs) { |
| 5184 |
cur = attrs[key]; |
| 5185 |
old = oldAttrs[key]; |
| 5186 |
if (old !== cur) { |
| 5187 |
setAttr(elm, key, cur); |
| 5188 |
} |
| 5189 |
} |
| 5190 |
// #4391: in IE9, setting type can reset value for input[type=radio] |
| 5191 |
/* istanbul ignore if */ |
| 5192 |
if (isIE9 && attrs.value !== oldAttrs.value) { |
| 5193 |
setAttr(elm, 'value', attrs.value); |
| 5194 |
} |
| 5195 |
for (key in oldAttrs) { |
| 5196 |
if (attrs[key] == null) { |
| 5197 |
if (isXlink(key)) { |
| 5198 |
elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); |
| 5199 |
} else if (!isEnumeratedAttr(key)) { |
| 5200 |
elm.removeAttribute(key); |
| 5201 |
} |
| 5202 |
} |
| 5203 |
} |
| 5204 |
} |
| 5205 |
|
| 5206 |
function setAttr (el, key, value) { |
| 5207 |
if (isBooleanAttr(key)) { |
| 5208 |
// set attribute for blank value |
| 5209 |
// e.g. <option disabled>Select one</option> |
| 5210 |
if (isFalsyAttrValue(value)) { |
| 5211 |
el.removeAttribute(key); |
| 5212 |
} else { |
| 5213 |
el.setAttribute(key, key); |
| 5214 |
} |
| 5215 |
} else if (isEnumeratedAttr(key)) { |
| 5216 |
el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'); |
| 5217 |
} else if (isXlink(key)) { |
| 5218 |
if (isFalsyAttrValue(value)) { |
| 5219 |
el.removeAttributeNS(xlinkNS, getXlinkProp(key)); |
| 5220 |
} else { |
| 5221 |
el.setAttributeNS(xlinkNS, key, value); |
| 5222 |
} |
| 5223 |
} else { |
| 5224 |
if (isFalsyAttrValue(value)) { |
| 5225 |
el.removeAttribute(key); |
| 5226 |
} else { |
| 5227 |
el.setAttribute(key, value); |
| 5228 |
} |
| 5229 |
} |
| 5230 |
} |
| 5231 |
|
| 5232 |
var attrs = { |
| 5233 |
create: updateAttrs, |
| 5234 |
update: updateAttrs |
| 5235 |
}; |
| 5236 |
|
| 5237 |
/* */ |
| 5238 |
|
| 5239 |
function updateClass (oldVnode, vnode) { |
| 5240 |
var el = vnode.elm; |
| 5241 |
var data = vnode.data; |
| 5242 |
var oldData = oldVnode.data; |
| 5243 |
if (!data.staticClass && !data.class && |
| 5244 |
(!oldData || (!oldData.staticClass && !oldData.class))) { |
| 5245 |
return |
| 5246 |
} |
| 5247 |
|
| 5248 |
var cls = genClassForVnode(vnode); |
| 5249 |
|
| 5250 |
// handle transition classes |
| 5251 |
var transitionClass = el._transitionClasses; |
| 5252 |
if (transitionClass) { |
| 5253 |
cls = concat(cls, stringifyClass(transitionClass)); |
| 5254 |
} |
| 5255 |
|
| 5256 |
// set the class |
| 5257 |
if (cls !== el._prevClass) { |
| 5258 |
el.setAttribute('class', cls); |
| 5259 |
el._prevClass = cls; |
| 5260 |
} |
| 5261 |
} |
| 5262 |
|
| 5263 |
var klass = { |
| 5264 |
create: updateClass, |
| 5265 |
update: updateClass |
| 5266 |
}; |
| 5267 |
|
| 5268 |
/* */ |
| 5269 |
|
| 5270 |
var validDivisionCharRE = /[\w).+\-_$\]]/; |
| 5271 |
|
| 5272 |
function parseFilters (exp) { |
| 5273 |
var inSingle = false; |
| 5274 |
var inDouble = false; |
| 5275 |
var inTemplateString = false; |
| 5276 |
var inRegex = false; |
| 5277 |
var curly = 0; |
| 5278 |
var square = 0; |
| 5279 |
var paren = 0; |
| 5280 |
var lastFilterIndex = 0; |
| 5281 |
var c, prev, i, expression, filters; |
| 5282 |
|
| 5283 |
for (i = 0; i < exp.length; i++) { |
| 5284 |
prev = c; |
| 5285 |
c = exp.charCodeAt(i); |
| 5286 |
if (inSingle) { |
| 5287 |
if (c === 0x27 && prev !== 0x5C) { inSingle = false; } |
| 5288 |
} else if (inDouble) { |
| 5289 |
if (c === 0x22 && prev !== 0x5C) { inDouble = false; } |
| 5290 |
} else if (inTemplateString) { |
| 5291 |
if (c === 0x60 && prev !== 0x5C) { inTemplateString = false; } |
| 5292 |
} else if (inRegex) { |
| 5293 |
if (c === 0x2f && prev !== 0x5C) { inRegex = false; } |
| 5294 |
} else if ( |
| 5295 |
c === 0x7C && // pipe |
| 5296 |
exp.charCodeAt(i + 1) !== 0x7C && |
| 5297 |
exp.charCodeAt(i - 1) !== 0x7C && |
| 5298 |
!curly && !square && !paren |
| 5299 |
) { |
| 5300 |
if (expression === undefined) { |
| 5301 |
// first filter, end of expression |
| 5302 |
lastFilterIndex = i + 1; |
| 5303 |
expression = exp.slice(0, i).trim(); |
| 5304 |
} else { |
| 5305 |
pushFilter(); |
| 5306 |
} |
| 5307 |
} else { |
| 5308 |
switch (c) { |
| 5309 |
case 0x22: inDouble = true; break // " |
| 5310 |
case 0x27: inSingle = true; break // ' |
| 5311 |
case 0x60: inTemplateString = true; break // ` |
| 5312 |
case 0x28: paren++; break // ( |
| 5313 |
case 0x29: paren--; break // ) |
| 5314 |
case 0x5B: square++; break // [ |
| 5315 |
case 0x5D: square--; break // ] |
| 5316 |
case 0x7B: curly++; break // { |
| 5317 |
case 0x7D: curly--; break // } |
| 5318 |
} |
| 5319 |
if (c === 0x2f) { // / |
| 5320 |
var j = i - 1; |
| 5321 |
var p = (void 0); |
| 5322 |
// find first non-whitespace prev char |
| 5323 |
for (; j >= 0; j--) { |
| 5324 |
p = exp.charAt(j); |
| 5325 |
if (p !== ' ') { break } |
| 5326 |
} |
| 5327 |
if (!p || !validDivisionCharRE.test(p)) { |
| 5328 |
inRegex = true; |
| 5329 |
} |
| 5330 |
} |
| 5331 |
} |
| 5332 |
} |
| 5333 |
|
| 5334 |
if (expression === undefined) { |
| 5335 |
expression = exp.slice(0, i).trim(); |
| 5336 |
} else if (lastFilterIndex !== 0) { |
| 5337 |
pushFilter(); |
| 5338 |
} |
| 5339 |
|
| 5340 |
function pushFilter () { |
| 5341 |
(filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim()); |
| 5342 |
lastFilterIndex = i + 1; |
| 5343 |
} |
| 5344 |
|
| 5345 |
if (filters) { |
| 5346 |
for (i = 0; i < filters.length; i++) { |
| 5347 |
expression = wrapFilter(expression, filters[i]); |
| 5348 |
} |
| 5349 |
} |
| 5350 |
|
| 5351 |
return expression |
| 5352 |
} |
| 5353 |
|
| 5354 |
function wrapFilter (exp, filter) { |
| 5355 |
var i = filter.indexOf('('); |
| 5356 |
if (i < 0) { |
| 5357 |
// _f: resolveFilter |
| 5358 |
return ("_f(\"" + filter + "\")(" + exp + ")") |
| 5359 |
} else { |
| 5360 |
var name = filter.slice(0, i); |
| 5361 |
var args = filter.slice(i + 1); |
| 5362 |
return ("_f(\"" + name + "\")(" + exp + "," + args) |
| 5363 |
} |
| 5364 |
} |
| 5365 |
|
| 5366 |
/* */ |
| 5367 |
|
| 5368 |
function baseWarn (msg) { |
| 5369 |
console.error(("[Vue compiler]: " + msg)); |
| 5370 |
} |
| 5371 |
|
| 5372 |
function pluckModuleFunction ( |
| 5373 |
modules, |
| 5374 |
key |
| 5375 |
) { |
| 5376 |
return modules |
| 5377 |
? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; }) |
| 5378 |
: [] |
| 5379 |
} |
| 5380 |
|
| 5381 |
function addProp (el, name, value) { |
| 5382 |
(el.props || (el.props = [])).push({ name: name, value: value }); |
| 5383 |
} |
| 5384 |
|
| 5385 |
function addAttr (el, name, value) { |
| 5386 |
(el.attrs || (el.attrs = [])).push({ name: name, value: value }); |
| 5387 |
} |
| 5388 |
|
| 5389 |
function addDirective ( |
| 5390 |
el, |
| 5391 |
name, |
| 5392 |
rawName, |
| 5393 |
value, |
| 5394 |
arg, |
| 5395 |
modifiers |
| 5396 |
) { |
| 5397 |
(el.directives || (el.directives = [])).push({ name: name, rawName: rawName, value: value, arg: arg, modifiers: modifiers }); |
| 5398 |
} |
| 5399 |
|
| 5400 |
function addHandler ( |
| 5401 |
el, |
| 5402 |
name, |
| 5403 |
value, |
| 5404 |
modifiers, |
| 5405 |
important |
| 5406 |
) { |
| 5407 |
// check capture modifier |
| 5408 |
if (modifiers && modifiers.capture) { |
| 5409 |
delete modifiers.capture; |
| 5410 |
name = '!' + name; // mark the event as captured |
| 5411 |
} |
| 5412 |
if (modifiers && modifiers.once) { |
| 5413 |
delete modifiers.once; |
| 5414 |
name = '~' + name; // mark the event as once |
| 5415 |
} |
| 5416 |
var events; |
| 5417 |
if (modifiers && modifiers.native) { |
| 5418 |
delete modifiers.native; |
| 5419 |
events = el.nativeEvents || (el.nativeEvents = {}); |
| 5420 |
} else { |
| 5421 |
events = el.events || (el.events = {}); |
| 5422 |
} |
| 5423 |
var newHandler = { value: value, modifiers: modifiers }; |
| 5424 |
var handlers = events[name]; |
| 5425 |
/* istanbul ignore if */ |
| 5426 |
if (Array.isArray(handlers)) { |
| 5427 |
important ? handlers.unshift(newHandler) : handlers.push(newHandler); |
| 5428 |
} else if (handlers) { |
| 5429 |
events[name] = important ? [newHandler, handlers] : [handlers, newHandler]; |
| 5430 |
} else { |
| 5431 |
events[name] = newHandler; |
| 5432 |
} |
| 5433 |
} |
| 5434 |
|
| 5435 |
function getBindingAttr ( |
| 5436 |
el, |
| 5437 |
name, |
| 5438 |
getStatic |
| 5439 |
) { |
| 5440 |
var dynamicValue = |
| 5441 |
getAndRemoveAttr(el, ':' + name) || |
| 5442 |
getAndRemoveAttr(el, 'v-bind:' + name); |
| 5443 |
if (dynamicValue != null) { |
| 5444 |
return parseFilters(dynamicValue) |
| 5445 |
} else if (getStatic !== false) { |
| 5446 |
var staticValue = getAndRemoveAttr(el, name); |
| 5447 |
if (staticValue != null) { |
| 5448 |
return JSON.stringify(staticValue) |
| 5449 |
} |
| 5450 |
} |
| 5451 |
} |
| 5452 |
|
| 5453 |
function getAndRemoveAttr (el, name) { |
| 5454 |
var val; |
| 5455 |
if ((val = el.attrsMap[name]) != null) { |
| 5456 |
var list = el.attrsList; |
| 5457 |
for (var i = 0, l = list.length; i < l; i++) { |
| 5458 |
if (list[i].name === name) { |
| 5459 |
list.splice(i, 1); |
| 5460 |
break |
| 5461 |
} |
| 5462 |
} |
| 5463 |
} |
| 5464 |
return val |
| 5465 |
} |
| 5466 |
|
| 5467 |
/* */ |
| 5468 |
|
| 5469 |
/** |
| 5470 |
* Cross-platform code generation for component v-model |
| 5471 |
*/ |
| 5472 |
function genComponentModel ( |
| 5473 |
el, |
| 5474 |
value, |
| 5475 |
modifiers |
| 5476 |
) { |
| 5477 |
var ref = modifiers || {}; |
| 5478 |
var number = ref.number; |
| 5479 |
var trim = ref.trim; |
| 5480 |
|
| 5481 |
var baseValueExpression = '$$v'; |
| 5482 |
var valueExpression = baseValueExpression; |
| 5483 |
if (trim) { |
| 5484 |
valueExpression = |
| 5485 |
"(typeof " + baseValueExpression + " === 'string'" + |
| 5486 |
"? " + baseValueExpression + ".trim()" + |
| 5487 |
": " + baseValueExpression + ")"; |
| 5488 |
} |
| 5489 |
if (number) { |
| 5490 |
valueExpression = "_n(" + valueExpression + ")"; |
| 5491 |
} |
| 5492 |
var assignment = genAssignmentCode(value, valueExpression); |
| 5493 |
|
| 5494 |
el.model = { |
| 5495 |
value: ("(" + value + ")"), |
| 5496 |
expression: ("\"" + value + "\""), |
| 5497 |
callback: ("function (" + baseValueExpression + ") {" + assignment + "}") |
| 5498 |
}; |
| 5499 |
} |
| 5500 |
|
| 5501 |
/** |
| 5502 |
* Cross-platform codegen helper for generating v-model value assignment code. |
| 5503 |
*/ |
| 5504 |
function genAssignmentCode ( |
| 5505 |
value, |
| 5506 |
assignment |
| 5507 |
) { |
| 5508 |
var modelRs = parseModel(value); |
| 5509 |
if (modelRs.idx === null) { |
| 5510 |
return (value + "=" + assignment) |
| 5511 |
} else { |
| 5512 |
return "var $$exp = " + (modelRs.exp) + ", $$idx = " + (modelRs.idx) + ";" + |
| 5513 |
"if (!Array.isArray($$exp)){" + |
| 5514 |
value + "=" + assignment + "}" + |
| 5515 |
"else{$$exp.splice($$idx, 1, " + assignment + ")}" |
| 5516 |
} |
| 5517 |
} |
| 5518 |
|
| 5519 |
/** |
| 5520 |
* parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val) |
| 5521 |
* |
| 5522 |
* for loop possible cases: |
| 5523 |
* |
| 5524 |
* - test |
| 5525 |
* - test[idx] |
| 5526 |
* - test[test1[idx]] |
| 5527 |
* - test["a"][idx] |
| 5528 |
* - xxx.test[a[a].test1[idx]] |
| 5529 |
* - test.xxx.a["asa"][test1[idx]] |
| 5530 |
* |
| 5531 |
*/ |
| 5532 |
|
| 5533 |
var len; |
| 5534 |
var str; |
| 5535 |
var chr; |
| 5536 |
var index$1; |
| 5537 |
var expressionPos; |
| 5538 |
var expressionEndPos; |
| 5539 |
|
| 5540 |
function parseModel (val) { |
| 5541 |
str = val; |
| 5542 |
len = str.length; |
| 5543 |
index$1 = expressionPos = expressionEndPos = 0; |
| 5544 |
|
| 5545 |
if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) { |
| 5546 |
return { |
| 5547 |
exp: val, |
| 5548 |
idx: null |
| 5549 |
} |
| 5550 |
} |
| 5551 |
|
| 5552 |
while (!eof()) { |
| 5553 |
chr = next(); |
| 5554 |
/* istanbul ignore if */ |
| 5555 |
if (isStringStart(chr)) { |
| 5556 |
parseString(chr); |
| 5557 |
} else if (chr === 0x5B) { |
| 5558 |
parseBracket(chr); |
| 5559 |
} |
| 5560 |
} |
| 5561 |
|
| 5562 |
return { |
| 5563 |
exp: val.substring(0, expressionPos), |
| 5564 |
idx: val.substring(expressionPos + 1, expressionEndPos) |
| 5565 |
} |
| 5566 |
} |
| 5567 |
|
| 5568 |
function next () { |
| 5569 |
return str.charCodeAt(++index$1) |
| 5570 |
} |
| 5571 |
|
| 5572 |
function eof () { |
| 5573 |
return index$1 >= len |
| 5574 |
} |
| 5575 |
|
| 5576 |
function isStringStart (chr) { |
| 5577 |
return chr === 0x22 || chr === 0x27 |
| 5578 |
} |
| 5579 |
|
| 5580 |
function parseBracket (chr) { |
| 5581 |
var inBracket = 1; |
| 5582 |
expressionPos = index$1; |
| 5583 |
while (!eof()) { |
| 5584 |
chr = next(); |
| 5585 |
if (isStringStart(chr)) { |
| 5586 |
parseString(chr); |
| 5587 |
continue |
| 5588 |
} |
| 5589 |
if (chr === 0x5B) { inBracket++; } |
| 5590 |
if (chr === 0x5D) { inBracket--; } |
| 5591 |
if (inBracket === 0) { |
| 5592 |
expressionEndPos = index$1; |
| 5593 |
break |
| 5594 |
} |
| 5595 |
} |
| 5596 |
} |
| 5597 |
|
| 5598 |
function parseString (chr) { |
| 5599 |
var stringQuote = chr; |
| 5600 |
while (!eof()) { |
| 5601 |
chr = next(); |
| 5602 |
if (chr === stringQuote) { |
| 5603 |
break |
| 5604 |
} |
| 5605 |
} |
| 5606 |
} |
| 5607 |
|
| 5608 |
/* */ |
| 5609 |
|
| 5610 |
var warn$1; |
| 5611 |
|
| 5612 |
// in some cases, the event used has to be determined at runtime |
| 5613 |
// so we used some reserved tokens during compile. |
| 5614 |
var RANGE_TOKEN = '__r'; |
| 5615 |
var CHECKBOX_RADIO_TOKEN = '__c'; |
| 5616 |
|
| 5617 |
function model ( |
| 5618 |
el, |
| 5619 |
dir, |
| 5620 |
_warn |
| 5621 |
) { |
| 5622 |
warn$1 = _warn; |
| 5623 |
var value = dir.value; |
| 5624 |
var modifiers = dir.modifiers; |
| 5625 |
var tag = el.tag; |
| 5626 |
var type = el.attrsMap.type; |
| 5627 |
|
| 5628 |
{ |
| 5629 |
var dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type']; |
| 5630 |
if (tag === 'input' && dynamicType) { |
| 5631 |
warn$1( |
| 5632 |
"<input :type=\"" + dynamicType + "\" v-model=\"" + value + "\">:\n" + |
| 5633 |
"v-model does not support dynamic input types. Use v-if branches instead." |
| 5634 |
); |
| 5635 |
} |
| 5636 |
// inputs with type="file" are read only and setting the input's |
| 5637 |
// value will throw an error. |
| 5638 |
if (tag === 'input' && type === 'file') { |
| 5639 |
warn$1( |
| 5640 |
"<" + (el.tag) + " v-model=\"" + value + "\" type=\"file\">:\n" + |
| 5641 |
"File inputs are read only. Use a v-on:change listener instead." |
| 5642 |
); |
| 5643 |
} |
| 5644 |
} |
| 5645 |
|
| 5646 |
if (tag === 'select') { |
| 5647 |
genSelect(el, value, modifiers); |
| 5648 |
} else if (tag === 'input' && type === 'checkbox') { |
| 5649 |
genCheckboxModel(el, value, modifiers); |
| 5650 |
} else if (tag === 'input' && type === 'radio') { |
| 5651 |
genRadioModel(el, value, modifiers); |
| 5652 |
} else if (tag === 'input' || tag === 'textarea') { |
| 5653 |
genDefaultModel(el, value, modifiers); |
| 5654 |
} else if (!config.isReservedTag(tag)) { |
| 5655 |
genComponentModel(el, value, modifiers); |
| 5656 |
// component v-model doesn't need extra runtime |
| 5657 |
return false |
| 5658 |
} else { |
| 5659 |
warn$1( |
| 5660 |
"<" + (el.tag) + " v-model=\"" + value + "\">: " + |
| 5661 |
"v-model is not supported on this element type. " + |
| 5662 |
'If you are working with contenteditable, it\'s recommended to ' + |
| 5663 |
'wrap a library dedicated for that purpose inside a custom component.' |
| 5664 |
); |
| 5665 |
} |
| 5666 |
|
| 5667 |
// ensure runtime directive metadata |
| 5668 |
return true |
| 5669 |
} |
| 5670 |
|
| 5671 |
function genCheckboxModel ( |
| 5672 |
el, |
| 5673 |
value, |
| 5674 |
modifiers |
| 5675 |
) { |
| 5676 |
var number = modifiers && modifiers.number; |
| 5677 |
var valueBinding = getBindingAttr(el, 'value') || 'null'; |
| 5678 |
var trueValueBinding = getBindingAttr(el, 'true-value') || 'true'; |
| 5679 |
var falseValueBinding = getBindingAttr(el, 'false-value') || 'false'; |
| 5680 |
addProp(el, 'checked', |
| 5681 |
"Array.isArray(" + value + ")" + |
| 5682 |
"?_i(" + value + "," + valueBinding + ")>-1" + ( |
| 5683 |
trueValueBinding === 'true' |
| 5684 |
? (":(" + value + ")") |
| 5685 |
: (":_q(" + value + "," + trueValueBinding + ")") |
| 5686 |
) |
| 5687 |
); |
| 5688 |
addHandler(el, CHECKBOX_RADIO_TOKEN, |
| 5689 |
"var $$a=" + value + "," + |
| 5690 |
'$$el=$event.target,' + |
| 5691 |
"$$c=$$el.checked?(" + trueValueBinding + "):(" + falseValueBinding + ");" + |
| 5692 |
'if(Array.isArray($$a)){' + |
| 5693 |
"var $$v=" + (number ? '_n(' + valueBinding + ')' : valueBinding) + "," + |
| 5694 |
'$$i=_i($$a,$$v);' + |
| 5695 |
"if($$c){$$i<0&&(" + value + "=$$a.concat($$v))}" + |
| 5696 |
"else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" + |
| 5697 |
"}else{" + value + "=$$c}", |
| 5698 |
null, true |
| 5699 |
); |
| 5700 |
} |
| 5701 |
|
| 5702 |
function genRadioModel ( |
| 5703 |
el, |
| 5704 |
value, |
| 5705 |
modifiers |
| 5706 |
) { |
| 5707 |
var number = modifiers && modifiers.number; |
| 5708 |
var valueBinding = getBindingAttr(el, 'value') || 'null'; |
| 5709 |
valueBinding = number ? ("_n(" + valueBinding + ")") : valueBinding; |
| 5710 |
addProp(el, 'checked', ("_q(" + value + "," + valueBinding + ")")); |
| 5711 |
addHandler(el, CHECKBOX_RADIO_TOKEN, genAssignmentCode(value, valueBinding), null, true); |
| 5712 |
} |
| 5713 |
|
| 5714 |
function genSelect ( |
| 5715 |
el, |
| 5716 |
value, |
| 5717 |
modifiers |
| 5718 |
) { |
| 5719 |
var number = modifiers && modifiers.number; |
| 5720 |
var selectedVal = "Array.prototype.filter" + |
| 5721 |
".call($event.target.options,function(o){return o.selected})" + |
| 5722 |
".map(function(o){var val = \"_value\" in o ? o._value : o.value;" + |
| 5723 |
"return " + (number ? '_n(val)' : 'val') + "})"; |
| 5724 |
|
| 5725 |
var assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]'; |
| 5726 |
var code = "var $$selectedVal = " + selectedVal + ";"; |
| 5727 |
code = code + " " + (genAssignmentCode(value, assignment)); |
| 5728 |
addHandler(el, 'change', code, null, true); |
| 5729 |
} |
| 5730 |
|
| 5731 |
function genDefaultModel ( |
| 5732 |
el, |
| 5733 |
value, |
| 5734 |
modifiers |
| 5735 |
) { |
| 5736 |
var type = el.attrsMap.type; |
| 5737 |
var ref = modifiers || {}; |
| 5738 |
var lazy = ref.lazy; |
| 5739 |
var number = ref.number; |
| 5740 |
var trim = ref.trim; |
| 5741 |
var needCompositionGuard = !lazy && type !== 'range'; |
| 5742 |
var event = lazy |
| 5743 |
? 'change' |
| 5744 |
: type === 'range' |
| 5745 |
? RANGE_TOKEN |
| 5746 |
: 'input'; |
| 5747 |
|
| 5748 |
var valueExpression = '$event.target.value'; |
| 5749 |
if (trim) { |
| 5750 |
valueExpression = "$event.target.value.trim()"; |
| 5751 |
} |
| 5752 |
if (number) { |
| 5753 |
valueExpression = "_n(" + valueExpression + ")"; |
| 5754 |
} |
| 5755 |
|
| 5756 |
var code = genAssignmentCode(value, valueExpression); |
| 5757 |
if (needCompositionGuard) { |
| 5758 |
code = "if($event.target.composing)return;" + code; |
| 5759 |
} |
| 5760 |
|
| 5761 |
addProp(el, 'value', ("(" + value + ")")); |
| 5762 |
addHandler(el, event, code, null, true); |
| 5763 |
if (trim || number || type === 'number') { |
| 5764 |
addHandler(el, 'blur', '$forceUpdate()'); |
| 5765 |
} |
| 5766 |
} |
| 5767 |
|
| 5768 |
/* */ |
| 5769 |
|
| 5770 |
// normalize v-model event tokens that can only be determined at runtime. |
| 5771 |
// it's important to place the event as the first in the array because |
| 5772 |
// the whole point is ensuring the v-model callback gets called before |
| 5773 |
// user-attached handlers. |
| 5774 |
function normalizeEvents (on) { |
| 5775 |
var event; |
| 5776 |
/* istanbul ignore if */ |
| 5777 |
if (on[RANGE_TOKEN]) { |
| 5778 |
// IE input[type=range] only supports `change` event |
| 5779 |
event = isIE ? 'change' : 'input'; |
| 5780 |
on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); |
| 5781 |
delete on[RANGE_TOKEN]; |
| 5782 |
} |
| 5783 |
if (on[CHECKBOX_RADIO_TOKEN]) { |
| 5784 |
// Chrome fires microtasks in between click/change, leads to #4521 |
| 5785 |
event = isChrome ? 'click' : 'change'; |
| 5786 |
on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || []); |
| 5787 |
delete on[CHECKBOX_RADIO_TOKEN]; |
| 5788 |
} |
| 5789 |
} |
| 5790 |
|
| 5791 |
var target$1; |
| 5792 |
|
| 5793 |
function add$1 ( |
| 5794 |
event, |
| 5795 |
handler, |
| 5796 |
once, |
| 5797 |
capture |
| 5798 |
) { |
| 5799 |
if (once) { |
| 5800 |
var oldHandler = handler; |
| 5801 |
var _target = target$1; // save current target element in closure |
| 5802 |
handler = function (ev) { |
| 5803 |
var res = arguments.length === 1 |
| 5804 |
? oldHandler(ev) |
| 5805 |
: oldHandler.apply(null, arguments); |
| 5806 |
if (res !== null) { |
| 5807 |
remove$2(event, handler, capture, _target); |
| 5808 |
} |
| 5809 |
}; |
| 5810 |
} |
| 5811 |
target$1.addEventListener(event, handler, capture); |
| 5812 |
} |
| 5813 |
|
| 5814 |
function remove$2 ( |
| 5815 |
event, |
| 5816 |
handler, |
| 5817 |
capture, |
| 5818 |
_target |
| 5819 |
) { |
| 5820 |
(_target || target$1).removeEventListener(event, handler, capture); |
| 5821 |
} |
| 5822 |
|
| 5823 |
function updateDOMListeners (oldVnode, vnode) { |
| 5824 |
if (!oldVnode.data.on && !vnode.data.on) { |
| 5825 |
return |
| 5826 |
} |
| 5827 |
var on = vnode.data.on || {}; |
| 5828 |
var oldOn = oldVnode.data.on || {}; |
| 5829 |
target$1 = vnode.elm; |
| 5830 |
normalizeEvents(on); |
| 5831 |
updateListeners(on, oldOn, add$1, remove$2, vnode.context); |
| 5832 |
} |
| 5833 |
|
| 5834 |
var events = { |
| 5835 |
create: updateDOMListeners, |
| 5836 |
update: updateDOMListeners |
| 5837 |
}; |
| 5838 |
|
| 5839 |
/* */ |
| 5840 |
|
| 5841 |
function updateDOMProps (oldVnode, vnode) { |
| 5842 |
if (!oldVnode.data.domProps && !vnode.data.domProps) { |
| 5843 |
return |
| 5844 |
} |
| 5845 |
var key, cur; |
| 5846 |
var elm = vnode.elm; |
| 5847 |
var oldProps = oldVnode.data.domProps || {}; |
| 5848 |
var props = vnode.data.domProps || {}; |
| 5849 |
// clone observed objects, as the user probably wants to mutate it |
| 5850 |
if (props.__ob__) { |
| 5851 |
props = vnode.data.domProps = extend({}, props); |
| 5852 |
} |
| 5853 |
|
| 5854 |
for (key in oldProps) { |
| 5855 |
if (props[key] == null) { |
| 5856 |
elm[key] = ''; |
| 5857 |
} |
| 5858 |
} |
| 5859 |
for (key in props) { |
| 5860 |
cur = props[key]; |
| 5861 |
// ignore children if the node has textContent or innerHTML, |
| 5862 |
// as these will throw away existing DOM nodes and cause removal errors |
| 5863 |
// on subsequent patches (#3360) |
| 5864 |
if (key === 'textContent' || key === 'innerHTML') { |
| 5865 |
if (vnode.children) { vnode.children.length = 0; } |
| 5866 |
if (cur === oldProps[key]) { continue } |
| 5867 |
} |
| 5868 |
|
| 5869 |
if (key === 'value') { |
| 5870 |
// store value as _value as well since |
| 5871 |
// non-string values will be stringified |
| 5872 |
elm._value = cur; |
| 5873 |
// avoid resetting cursor position when value is the same |
| 5874 |
var strCur = cur == null ? '' : String(cur); |
| 5875 |
if (shouldUpdateValue(elm, vnode, strCur)) { |
| 5876 |
elm.value = strCur; |
| 5877 |
} |
| 5878 |
} else { |
| 5879 |
elm[key] = cur; |
| 5880 |
} |
| 5881 |
} |
| 5882 |
} |
| 5883 |
|
| 5884 |
// check platforms/web/util/attrs.js acceptValue |
| 5885 |
|
| 5886 |
|
| 5887 |
function shouldUpdateValue ( |
| 5888 |
elm, |
| 5889 |
vnode, |
| 5890 |
checkVal |
| 5891 |
) { |
| 5892 |
return (!elm.composing && ( |
| 5893 |
vnode.tag === 'option' || |
| 5894 |
isDirty(elm, checkVal) || |
| 5895 |
isInputChanged(elm, checkVal) |
| 5896 |
)) |
| 5897 |
} |
| 5898 |
|
| 5899 |
function isDirty (elm, checkVal) { |
| 5900 |
// return true when textbox (.number and .trim) loses focus and its value is not equal to the updated value |
| 5901 |
return document.activeElement !== elm && elm.value !== checkVal |
| 5902 |
} |
| 5903 |
|
| 5904 |
function isInputChanged (elm, newVal) { |
| 5905 |
var value = elm.value; |
| 5906 |
var modifiers = elm._vModifiers; // injected by v-model runtime |
| 5907 |
if ((modifiers && modifiers.number) || elm.type === 'number') { |
| 5908 |
return toNumber(value) !== toNumber(newVal) |
| 5909 |
} |
| 5910 |
if (modifiers && modifiers.trim) { |
| 5911 |
return value.trim() !== newVal.trim() |
| 5912 |
} |
| 5913 |
return value !== newVal |
| 5914 |
} |
| 5915 |
|
| 5916 |
var domProps = { |
| 5917 |
create: updateDOMProps, |
| 5918 |
update: updateDOMProps |
| 5919 |
}; |
| 5920 |
|
| 5921 |
/* */ |
| 5922 |
|
| 5923 |
var parseStyleText = cached(function (cssText) { |
| 5924 |
var res = {}; |
| 5925 |
var listDelimiter = /;(?![^(]*\))/g; |
| 5926 |
var propertyDelimiter = /:(.+)/; |
| 5927 |
cssText.split(listDelimiter).forEach(function (item) { |
| 5928 |
if (item) { |
| 5929 |
var tmp = item.split(propertyDelimiter); |
| 5930 |
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); |
| 5931 |
} |
| 5932 |
}); |
| 5933 |
return res |
| 5934 |
}); |
| 5935 |
|
| 5936 |
// merge static and dynamic style data on the same vnode |
| 5937 |
function normalizeStyleData (data) { |
| 5938 |
var style = normalizeStyleBinding(data.style); |
| 5939 |
// static style is pre-processed into an object during compilation |
| 5940 |
// and is always a fresh object, so it's safe to merge into it |
| 5941 |
return data.staticStyle |
| 5942 |
? extend(data.staticStyle, style) |
| 5943 |
: style |
| 5944 |
} |
| 5945 |
|
| 5946 |
// normalize possible array / string values into Object |
| 5947 |
function normalizeStyleBinding (bindingStyle) { |
| 5948 |
if (Array.isArray(bindingStyle)) { |
| 5949 |
return toObject(bindingStyle) |
| 5950 |
} |
| 5951 |
if (typeof bindingStyle === 'string') { |
| 5952 |
return parseStyleText(bindingStyle) |
| 5953 |
} |
| 5954 |
return bindingStyle |
| 5955 |
} |
| 5956 |
|
| 5957 |
/** |
| 5958 |
* parent component style should be after child's |
| 5959 |
* so that parent component's style could override it |
| 5960 |
*/ |
| 5961 |
function getStyle (vnode, checkChild) { |
| 5962 |
var res = {}; |
| 5963 |
var styleData; |
| 5964 |
|
| 5965 |
if (checkChild) { |
| 5966 |
var childNode = vnode; |
| 5967 |
while (childNode.componentInstance) { |
| 5968 |
childNode = childNode.componentInstance._vnode; |
| 5969 |
if (childNode.data && (styleData = normalizeStyleData(childNode.data))) { |
| 5970 |
extend(res, styleData); |
| 5971 |
} |
| 5972 |
} |
| 5973 |
} |
| 5974 |
|
| 5975 |
if ((styleData = normalizeStyleData(vnode.data))) { |
| 5976 |
extend(res, styleData); |
| 5977 |
} |
| 5978 |
|
| 5979 |
var parentNode = vnode; |
| 5980 |
while ((parentNode = parentNode.parent)) { |
| 5981 |
if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) { |
| 5982 |
extend(res, styleData); |
| 5983 |
} |
| 5984 |
} |
| 5985 |
return res |
| 5986 |
} |
| 5987 |
|
| 5988 |
/* */ |
| 5989 |
|
| 5990 |
var cssVarRE = /^--/; |
| 5991 |
var importantRE = /\s*!important$/; |
| 5992 |
var setProp = function (el, name, val) { |
| 5993 |
/* istanbul ignore if */ |
| 5994 |
if (cssVarRE.test(name)) { |
| 5995 |
el.style.setProperty(name, val); |
| 5996 |
} else if (importantRE.test(val)) { |
| 5997 |
el.style.setProperty(name, val.replace(importantRE, ''), 'important'); |
| 5998 |
} else { |
| 5999 |
el.style[normalize(name)] = val; |
| 6000 |
} |
| 6001 |
}; |
| 6002 |
|
| 6003 |
var prefixes = ['Webkit', 'Moz', 'ms']; |
| 6004 |
|
| 6005 |
var testEl; |
| 6006 |
var normalize = cached(function (prop) { |
| 6007 |
testEl = testEl || document.createElement('div'); |
| 6008 |
prop = camelize(prop); |
| 6009 |
if (prop !== 'filter' && (prop in testEl.style)) { |
| 6010 |
return prop |
| 6011 |
} |
| 6012 |
var upper = prop.charAt(0).toUpperCase() + prop.slice(1); |
| 6013 |
for (var i = 0; i < prefixes.length; i++) { |
| 6014 |
var prefixed = prefixes[i] + upper; |
| 6015 |
if (prefixed in testEl.style) { |
| 6016 |
return prefixed |
| 6017 |
} |
| 6018 |
} |
| 6019 |
}); |
| 6020 |
|
| 6021 |
function updateStyle (oldVnode, vnode) { |
| 6022 |
var data = vnode.data; |
| 6023 |
var oldData = oldVnode.data; |
| 6024 |
|
| 6025 |
if (!data.staticStyle && !data.style && |
| 6026 |
!oldData.staticStyle && !oldData.style) { |
| 6027 |
return |
| 6028 |
} |
| 6029 |
|
| 6030 |
var cur, name; |
| 6031 |
var el = vnode.elm; |
| 6032 |
var oldStaticStyle = oldVnode.data.staticStyle; |
| 6033 |
var oldStyleBinding = oldVnode.data.style || {}; |
| 6034 |
|
| 6035 |
// if static style exists, stylebinding already merged into it when doing normalizeStyleData |
| 6036 |
var oldStyle = oldStaticStyle || oldStyleBinding; |
| 6037 |
|
| 6038 |
var style = normalizeStyleBinding(vnode.data.style) || {}; |
| 6039 |
|
| 6040 |
vnode.data.style = style.__ob__ ? extend({}, style) : style; |
| 6041 |
|
| 6042 |
var newStyle = getStyle(vnode, true); |
| 6043 |
|
| 6044 |
for (name in oldStyle) { |
| 6045 |
if (newStyle[name] == null) { |
| 6046 |
setProp(el, name, ''); |
| 6047 |
} |
| 6048 |
} |
| 6049 |
for (name in newStyle) { |
| 6050 |
cur = newStyle[name]; |
| 6051 |
if (cur !== oldStyle[name]) { |
| 6052 |
// ie9 setting to null has no effect, must use empty string |
| 6053 |
setProp(el, name, cur == null ? '' : cur); |
| 6054 |
} |
| 6055 |
} |
| 6056 |
} |
| 6057 |
|
| 6058 |
var style = { |
| 6059 |
create: updateStyle, |
| 6060 |
update: updateStyle |
| 6061 |
}; |
| 6062 |
|
| 6063 |
/* */ |
| 6064 |
|
| 6065 |
/** |
| 6066 |
* Add class with compatibility for SVG since classList is not supported on |
| 6067 |
* SVG elements in IE |
| 6068 |
*/ |
| 6069 |
function addClass (el, cls) { |
| 6070 |
/* istanbul ignore if */ |
| 6071 |
if (!cls || !(cls = cls.trim())) { |
| 6072 |
return |
| 6073 |
} |
| 6074 |
|
| 6075 |
/* istanbul ignore else */ |
| 6076 |
if (el.classList) { |
| 6077 |
if (cls.indexOf(' ') > -1) { |
| 6078 |
cls.split(/\s+/).forEach(function (c) { return el.classList.add(c); }); |
| 6079 |
} else { |
| 6080 |
el.classList.add(cls); |
| 6081 |
} |
| 6082 |
} else { |
| 6083 |
var cur = " " + (el.getAttribute('class') || '') + " "; |
| 6084 |
if (cur.indexOf(' ' + cls + ' ') < 0) { |
| 6085 |
el.setAttribute('class', (cur + cls).trim()); |
| 6086 |
} |
| 6087 |
} |
| 6088 |
} |
| 6089 |
|
| 6090 |
/** |
| 6091 |
* Remove class with compatibility for SVG since classList is not supported on |
| 6092 |
* SVG elements in IE |
| 6093 |
*/ |
| 6094 |
function removeClass (el, cls) { |
| 6095 |
/* istanbul ignore if */ |
| 6096 |
if (!cls || !(cls = cls.trim())) { |
| 6097 |
return |
| 6098 |
} |
| 6099 |
|
| 6100 |
/* istanbul ignore else */ |
| 6101 |
if (el.classList) { |
| 6102 |
if (cls.indexOf(' ') > -1) { |
| 6103 |
cls.split(/\s+/).forEach(function (c) { return el.classList.remove(c); }); |
| 6104 |
} else { |
| 6105 |
el.classList.remove(cls); |
| 6106 |
} |
| 6107 |
} else { |
| 6108 |
var cur = " " + (el.getAttribute('class') || '') + " "; |
| 6109 |
var tar = ' ' + cls + ' '; |
| 6110 |
while (cur.indexOf(tar) >= 0) { |
| 6111 |
cur = cur.replace(tar, ' '); |
| 6112 |
} |
| 6113 |
el.setAttribute('class', cur.trim()); |
| 6114 |
} |
| 6115 |
} |
| 6116 |
|
| 6117 |
/* */ |
| 6118 |
|
| 6119 |
function resolveTransition (def$$1) { |
| 6120 |
if (!def$$1) { |
| 6121 |
return |
| 6122 |
} |
| 6123 |
/* istanbul ignore else */ |
| 6124 |
if (typeof def$$1 === 'object') { |
| 6125 |
var res = {}; |
| 6126 |
if (def$$1.css !== false) { |
| 6127 |
extend(res, autoCssTransition(def$$1.name || 'v')); |
| 6128 |
} |
| 6129 |
extend(res, def$$1); |
| 6130 |
return res |
| 6131 |
} else if (typeof def$$1 === 'string') { |
| 6132 |
return autoCssTransition(def$$1) |
| 6133 |
} |
| 6134 |
} |
| 6135 |
|
| 6136 |
var autoCssTransition = cached(function (name) { |
| 6137 |
return { |
| 6138 |
enterClass: (name + "-enter"), |
| 6139 |
enterToClass: (name + "-enter-to"), |
| 6140 |
enterActiveClass: (name + "-enter-active"), |
| 6141 |
leaveClass: (name + "-leave"), |
| 6142 |
leaveToClass: (name + "-leave-to"), |
| 6143 |
leaveActiveClass: (name + "-leave-active") |
| 6144 |
} |
| 6145 |
}); |
| 6146 |
|
| 6147 |
var hasTransition = inBrowser && !isIE9; |
| 6148 |
var TRANSITION = 'transition'; |
| 6149 |
var ANIMATION = 'animation'; |
| 6150 |
|
| 6151 |
// Transition property/event sniffing |
| 6152 |
var transitionProp = 'transition'; |
| 6153 |
var transitionEndEvent = 'transitionend'; |
| 6154 |
var animationProp = 'animation'; |
| 6155 |
var animationEndEvent = 'animationend'; |
| 6156 |
if (hasTransition) { |
| 6157 |
/* istanbul ignore if */ |
| 6158 |
if (window.ontransitionend === undefined && |
| 6159 |
window.onwebkittransitionend !== undefined) { |
| 6160 |
transitionProp = 'WebkitTransition'; |
| 6161 |
transitionEndEvent = 'webkitTransitionEnd'; |
| 6162 |
} |
| 6163 |
if (window.onanimationend === undefined && |
| 6164 |
window.onwebkitanimationend !== undefined) { |
| 6165 |
animationProp = 'WebkitAnimation'; |
| 6166 |
animationEndEvent = 'webkitAnimationEnd'; |
| 6167 |
} |
| 6168 |
} |
| 6169 |
|
| 6170 |
// binding to window is necessary to make hot reload work in IE in strict mode |
| 6171 |
var raf = inBrowser && window.requestAnimationFrame |
| 6172 |
? window.requestAnimationFrame.bind(window) |
| 6173 |
: setTimeout; |
| 6174 |
|
| 6175 |
function nextFrame (fn) { |
| 6176 |
raf(function () { |
| 6177 |
raf(fn); |
| 6178 |
}); |
| 6179 |
} |
| 6180 |
|
| 6181 |
function addTransitionClass (el, cls) { |
| 6182 |
(el._transitionClasses || (el._transitionClasses = [])).push(cls); |
| 6183 |
addClass(el, cls); |
| 6184 |
} |
| 6185 |
|
| 6186 |
function removeTransitionClass (el, cls) { |
| 6187 |
if (el._transitionClasses) { |
| 6188 |
remove(el._transitionClasses, cls); |
| 6189 |
} |
| 6190 |
removeClass(el, cls); |
| 6191 |
} |
| 6192 |
|
| 6193 |
function whenTransitionEnds ( |
| 6194 |
el, |
| 6195 |
expectedType, |
| 6196 |
cb |
| 6197 |
) { |
| 6198 |
var ref = getTransitionInfo(el, expectedType); |
| 6199 |
var type = ref.type; |
| 6200 |
var timeout = ref.timeout; |
| 6201 |
var propCount = ref.propCount; |
| 6202 |
if (!type) { return cb() } |
| 6203 |
var event = type === TRANSITION ? transitionEndEvent : animationEndEvent; |
| 6204 |
var ended = 0; |
| 6205 |
var end = function () { |
| 6206 |
el.removeEventListener(event, onEnd); |
| 6207 |
cb(); |
| 6208 |
}; |
| 6209 |
var onEnd = function (e) { |
| 6210 |
if (e.target === el) { |
| 6211 |
if (++ended >= propCount) { |
| 6212 |
end(); |
| 6213 |
} |
| 6214 |
} |
| 6215 |
}; |
| 6216 |
setTimeout(function () { |
| 6217 |
if (ended < propCount) { |
| 6218 |
end(); |
| 6219 |
} |
| 6220 |
}, timeout + 1); |
| 6221 |
el.addEventListener(event, onEnd); |
| 6222 |
} |
| 6223 |
|
| 6224 |
var transformRE = /\b(transform|all)(,|$)/; |
| 6225 |
|
| 6226 |
function getTransitionInfo (el, expectedType) { |
| 6227 |
var styles = window.getComputedStyle(el); |
| 6228 |
var transitionDelays = styles[transitionProp + 'Delay'].split(', '); |
| 6229 |
var transitionDurations = styles[transitionProp + 'Duration'].split(', '); |
| 6230 |
var transitionTimeout = getTimeout(transitionDelays, transitionDurations); |
| 6231 |
var animationDelays = styles[animationProp + 'Delay'].split(', '); |
| 6232 |
var animationDurations = styles[animationProp + 'Duration'].split(', '); |
| 6233 |
var animationTimeout = getTimeout(animationDelays, animationDurations); |
| 6234 |
|
| 6235 |
var type; |
| 6236 |
var timeout = 0; |
| 6237 |
var propCount = 0; |
| 6238 |
/* istanbul ignore if */ |
| 6239 |
if (expectedType === TRANSITION) { |
| 6240 |
if (transitionTimeout > 0) { |
| 6241 |
type = TRANSITION; |
| 6242 |
timeout = transitionTimeout; |
| 6243 |
propCount = transitionDurations.length; |
| 6244 |
} |
| 6245 |
} else if (expectedType === ANIMATION) { |
| 6246 |
if (animationTimeout > 0) { |
| 6247 |
type = ANIMATION; |
| 6248 |
timeout = animationTimeout; |
| 6249 |
propCount = animationDurations.length; |
| 6250 |
} |
| 6251 |
} else { |
| 6252 |
timeout = Math.max(transitionTimeout, animationTimeout); |
| 6253 |
type = timeout > 0 |
| 6254 |
? transitionTimeout > animationTimeout |
| 6255 |
? TRANSITION |
| 6256 |
: ANIMATION |
| 6257 |
: null; |
| 6258 |
propCount = type |
| 6259 |
? type === TRANSITION |
| 6260 |
? transitionDurations.length |
| 6261 |
: animationDurations.length |
| 6262 |
: 0; |
| 6263 |
} |
| 6264 |
var hasTransform = |
| 6265 |
type === TRANSITION && |
| 6266 |
transformRE.test(styles[transitionProp + 'Property']); |
| 6267 |
return { |
| 6268 |
type: type, |
| 6269 |
timeout: timeout, |
| 6270 |
propCount: propCount, |
| 6271 |
hasTransform: hasTransform |
| 6272 |
} |
| 6273 |
} |
| 6274 |
|
| 6275 |
function getTimeout (delays, durations) { |
| 6276 |
/* istanbul ignore next */ |
| 6277 |
while (delays.length < durations.length) { |
| 6278 |
delays = delays.concat(delays); |
| 6279 |
} |
| 6280 |
|
| 6281 |
return Math.max.apply(null, durations.map(function (d, i) { |
| 6282 |
return toMs(d) + toMs(delays[i]) |
| 6283 |
})) |
| 6284 |
} |
| 6285 |
|
| 6286 |
function toMs (s) { |
| 6287 |
return Number(s.slice(0, -1)) * 1000 |
| 6288 |
} |
| 6289 |
|
| 6290 |
/* */ |
| 6291 |
|
| 6292 |
function enter (vnode, toggleDisplay) { |
| 6293 |
var el = vnode.elm; |
| 6294 |
|
| 6295 |
// call leave callback now |
| 6296 |
if (el._leaveCb) { |
| 6297 |
el._leaveCb.cancelled = true; |
| 6298 |
el._leaveCb(); |
| 6299 |
} |
| 6300 |
|
| 6301 |
var data = resolveTransition(vnode.data.transition); |
| 6302 |
if (!data) { |
| 6303 |
return |
| 6304 |
} |
| 6305 |
|
| 6306 |
/* istanbul ignore if */ |
| 6307 |
if (el._enterCb || el.nodeType !== 1) { |
| 6308 |
return |
| 6309 |
} |
| 6310 |
|
| 6311 |
var css = data.css; |
| 6312 |
var type = data.type; |
| 6313 |
var enterClass = data.enterClass; |
| 6314 |
var enterToClass = data.enterToClass; |
| 6315 |
var enterActiveClass = data.enterActiveClass; |
| 6316 |
var appearClass = data.appearClass; |
| 6317 |
var appearToClass = data.appearToClass; |
| 6318 |
var appearActiveClass = data.appearActiveClass; |
| 6319 |
var beforeEnter = data.beforeEnter; |
| 6320 |
var enter = data.enter; |
| 6321 |
var afterEnter = data.afterEnter; |
| 6322 |
var enterCancelled = data.enterCancelled; |
| 6323 |
var beforeAppear = data.beforeAppear; |
| 6324 |
var appear = data.appear; |
| 6325 |
var afterAppear = data.afterAppear; |
| 6326 |
var appearCancelled = data.appearCancelled; |
| 6327 |
var duration = data.duration; |
| 6328 |
|
| 6329 |
// activeInstance will always be the <transition> component managing this |
| 6330 |
// transition. One edge case to check is when the <transition> is placed |
| 6331 |
// as the root node of a child component. In that case we need to check |
| 6332 |
// <transition>'s parent for appear check. |
| 6333 |
var context = activeInstance; |
| 6334 |
var transitionNode = activeInstance.$vnode; |
| 6335 |
while (transitionNode && transitionNode.parent) { |
| 6336 |
transitionNode = transitionNode.parent; |
| 6337 |
context = transitionNode.context; |
| 6338 |
} |
| 6339 |
|
| 6340 |
var isAppear = !context._isMounted || !vnode.isRootInsert; |
| 6341 |
|
| 6342 |
if (isAppear && !appear && appear !== '') { |
| 6343 |
return |
| 6344 |
} |
| 6345 |
|
| 6346 |
var startClass = isAppear && appearClass |
| 6347 |
? appearClass |
| 6348 |
: enterClass; |
| 6349 |
var activeClass = isAppear && appearActiveClass |
| 6350 |
? appearActiveClass |
| 6351 |
: enterActiveClass; |
| 6352 |
var toClass = isAppear && appearToClass |
| 6353 |
? appearToClass |
| 6354 |
: enterToClass; |
| 6355 |
|
| 6356 |
var beforeEnterHook = isAppear |
| 6357 |
? (beforeAppear || beforeEnter) |
| 6358 |
: beforeEnter; |
| 6359 |
var enterHook = isAppear |
| 6360 |
? (typeof appear === 'function' ? appear : enter) |
| 6361 |
: enter; |
| 6362 |
var afterEnterHook = isAppear |
| 6363 |
? (afterAppear || afterEnter) |
| 6364 |
: afterEnter; |
| 6365 |
var enterCancelledHook = isAppear |
| 6366 |
? (appearCancelled || enterCancelled) |
| 6367 |
: enterCancelled; |
| 6368 |
|
| 6369 |
var explicitEnterDuration = toNumber( |
| 6370 |
isObject(duration) |
| 6371 |
? duration.enter |
| 6372 |
: duration |
| 6373 |
); |
| 6374 |
|
| 6375 |
if ("development" !== 'production' && explicitEnterDuration != null) { |
| 6376 |
checkDuration(explicitEnterDuration, 'enter', vnode); |
| 6377 |
} |
| 6378 |
|
| 6379 |
var expectsCSS = css !== false && !isIE9; |
| 6380 |
var userWantsControl = getHookArgumentsLength(enterHook); |
| 6381 |
|
| 6382 |
var cb = el._enterCb = once(function () { |
| 6383 |
if (expectsCSS) { |
| 6384 |
removeTransitionClass(el, toClass); |
| 6385 |
removeTransitionClass(el, activeClass); |
| 6386 |
} |
| 6387 |
if (cb.cancelled) { |
| 6388 |
if (expectsCSS) { |
| 6389 |
removeTransitionClass(el, startClass); |
| 6390 |
} |
| 6391 |
enterCancelledHook && enterCancelledHook(el); |
| 6392 |
} else { |
| 6393 |
afterEnterHook && afterEnterHook(el); |
| 6394 |
} |
| 6395 |
el._enterCb = null; |
| 6396 |
}); |
| 6397 |
|
| 6398 |
if (!vnode.data.show) { |
| 6399 |
// remove pending leave element on enter by injecting an insert hook |
| 6400 |
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () { |
| 6401 |
var parent = el.parentNode; |
| 6402 |
var pendingNode = parent && parent._pending && parent._pending[vnode.key]; |
| 6403 |
if (pendingNode && |
| 6404 |
pendingNode.tag === vnode.tag && |
| 6405 |
pendingNode.elm._leaveCb) { |
| 6406 |
pendingNode.elm._leaveCb(); |
| 6407 |
} |
| 6408 |
enterHook && enterHook(el, cb); |
| 6409 |
}); |
| 6410 |
} |
| 6411 |
|
| 6412 |
// start enter transition |
| 6413 |
beforeEnterHook && beforeEnterHook(el); |
| 6414 |
if (expectsCSS) { |
| 6415 |
addTransitionClass(el, startClass); |
| 6416 |
addTransitionClass(el, activeClass); |
| 6417 |
nextFrame(function () { |
| 6418 |
addTransitionClass(el, toClass); |
| 6419 |
removeTransitionClass(el, startClass); |
| 6420 |
if (!cb.cancelled && !userWantsControl) { |
| 6421 |
if (isValidDuration(explicitEnterDuration)) { |
| 6422 |
setTimeout(cb, explicitEnterDuration); |
| 6423 |
} else { |
| 6424 |
whenTransitionEnds(el, type, cb); |
| 6425 |
} |
| 6426 |
} |
| 6427 |
}); |
| 6428 |
} |
| 6429 |
|
| 6430 |
if (vnode.data.show) { |
| 6431 |
toggleDisplay && toggleDisplay(); |
| 6432 |
enterHook && enterHook(el, cb); |
| 6433 |
} |
| 6434 |
|
| 6435 |
if (!expectsCSS && !userWantsControl) { |
| 6436 |
cb(); |
| 6437 |
} |
| 6438 |
} |
| 6439 |
|
| 6440 |
function leave (vnode, rm) { |
| 6441 |
var el = vnode.elm; |
| 6442 |
|
| 6443 |
// call enter callback now |
| 6444 |
if (el._enterCb) { |
| 6445 |
el._enterCb.cancelled = true; |
| 6446 |
el._enterCb(); |
| 6447 |
} |
| 6448 |
|
| 6449 |
var data = resolveTransition(vnode.data.transition); |
| 6450 |
if (!data) { |
| 6451 |
return rm() |
| 6452 |
} |
| 6453 |
|
| 6454 |
/* istanbul ignore if */ |
| 6455 |
if (el._leaveCb || el.nodeType !== 1) { |
| 6456 |
return |
| 6457 |
} |
| 6458 |
|
| 6459 |
var css = data.css; |
| 6460 |
var type = data.type; |
| 6461 |
var leaveClass = data.leaveClass; |
| 6462 |
var leaveToClass = data.leaveToClass; |
| 6463 |
var leaveActiveClass = data.leaveActiveClass; |
| 6464 |
var beforeLeave = data.beforeLeave; |
| 6465 |
var leave = data.leave; |
| 6466 |
var afterLeave = data.afterLeave; |
| 6467 |
var leaveCancelled = data.leaveCancelled; |
| 6468 |
var delayLeave = data.delayLeave; |
| 6469 |
var duration = data.duration; |
| 6470 |
|
| 6471 |
var expectsCSS = css !== false && !isIE9; |
| 6472 |
var userWantsControl = getHookArgumentsLength(leave); |
| 6473 |
|
| 6474 |
var explicitLeaveDuration = toNumber( |
| 6475 |
isObject(duration) |
| 6476 |
? duration.leave |
| 6477 |
: duration |
| 6478 |
); |
| 6479 |
|
| 6480 |
if ("development" !== 'production' && explicitLeaveDuration != null) { |
| 6481 |
checkDuration(explicitLeaveDuration, 'leave', vnode); |
| 6482 |
} |
| 6483 |
|
| 6484 |
var cb = el._leaveCb = once(function () { |
| 6485 |
if (el.parentNode && el.parentNode._pending) { |
| 6486 |
el.parentNode._pending[vnode.key] = null; |
| 6487 |
} |
| 6488 |
if (expectsCSS) { |
| 6489 |
removeTransitionClass(el, leaveToClass); |
| 6490 |
removeTransitionClass(el, leaveActiveClass); |
| 6491 |
} |
| 6492 |
if (cb.cancelled) { |
| 6493 |
if (expectsCSS) { |
| 6494 |
removeTransitionClass(el, leaveClass); |
| 6495 |
} |
| 6496 |
leaveCancelled && leaveCancelled(el); |
| 6497 |
} else { |
| 6498 |
rm(); |
| 6499 |
afterLeave && afterLeave(el); |
| 6500 |
} |
| 6501 |
el._leaveCb = null; |
| 6502 |
}); |
| 6503 |
|
| 6504 |
if (delayLeave) { |
| 6505 |
delayLeave(performLeave); |
| 6506 |
} else { |
| 6507 |
performLeave(); |
| 6508 |
} |
| 6509 |
|
| 6510 |
function performLeave () { |
| 6511 |
// the delayed leave may have already been cancelled |
| 6512 |
if (cb.cancelled) { |
| 6513 |
return |
| 6514 |
} |
| 6515 |
// record leaving element |
| 6516 |
if (!vnode.data.show) { |
| 6517 |
(el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode; |
| 6518 |
} |
| 6519 |
beforeLeave && beforeLeave(el); |
| 6520 |
if (expectsCSS) { |
| 6521 |
addTransitionClass(el, leaveClass); |
| 6522 |
addTransitionClass(el, leaveActiveClass); |
| 6523 |
nextFrame(function () { |
| 6524 |
addTransitionClass(el, leaveToClass); |
| 6525 |
removeTransitionClass(el, leaveClass); |
| 6526 |
if (!cb.cancelled && !userWantsControl) { |
| 6527 |
if (isValidDuration(explicitLeaveDuration)) { |
| 6528 |
setTimeout(cb, explicitLeaveDuration); |
| 6529 |
} else { |
| 6530 |
whenTransitionEnds(el, type, cb); |
| 6531 |
} |
| 6532 |
} |
| 6533 |
}); |
| 6534 |
} |
| 6535 |
leave && leave(el, cb); |
| 6536 |
if (!expectsCSS && !userWantsControl) { |
| 6537 |
cb(); |
| 6538 |
} |
| 6539 |
} |
| 6540 |
} |
| 6541 |
|
| 6542 |
// only used in dev mode |
| 6543 |
function checkDuration (val, name, vnode) { |
| 6544 |
if (typeof val !== 'number') { |
| 6545 |
warn( |
| 6546 |
"<transition> explicit " + name + " duration is not a valid number - " + |
| 6547 |
"got " + (JSON.stringify(val)) + ".", |
| 6548 |
vnode.context |
| 6549 |
); |
| 6550 |
} else if (isNaN(val)) { |
| 6551 |
warn( |
| 6552 |
"<transition> explicit " + name + " duration is NaN - " + |
| 6553 |
'the duration expression might be incorrect.', |
| 6554 |
vnode.context |
| 6555 |
); |
| 6556 |
} |
| 6557 |
} |
| 6558 |
|
| 6559 |
function isValidDuration (val) { |
| 6560 |
return typeof val === 'number' && !isNaN(val) |
| 6561 |
} |
| 6562 |
|
| 6563 |
/** |
| 6564 |
* Normalize a transition hook's argument length. The hook may be: |
| 6565 |
* - a merged hook (invoker) with the original in .fns |
| 6566 |
* - a wrapped component method (check ._length) |
| 6567 |
* - a plain function (.length) |
| 6568 |
*/ |
| 6569 |
function getHookArgumentsLength (fn) { |
| 6570 |
if (!fn) { return false } |
| 6571 |
var invokerFns = fn.fns; |
| 6572 |
if (invokerFns) { |
| 6573 |
// invoker |
| 6574 |
return getHookArgumentsLength( |
| 6575 |
Array.isArray(invokerFns) |
| 6576 |
? invokerFns[0] |
| 6577 |
: invokerFns |
| 6578 |
) |
| 6579 |
} else { |
| 6580 |
return (fn._length || fn.length) > 1 |
| 6581 |
} |
| 6582 |
} |
| 6583 |
|
| 6584 |
function _enter (_, vnode) { |
| 6585 |
if (!vnode.data.show) { |
| 6586 |
enter(vnode); |
| 6587 |
} |
| 6588 |
} |
| 6589 |
|
| 6590 |
var transition = inBrowser ? { |
| 6591 |
create: _enter, |
| 6592 |
activate: _enter, |
| 6593 |
remove: function remove$$1 (vnode, rm) { |
| 6594 |
/* istanbul ignore else */ |
| 6595 |
if (!vnode.data.show) { |
| 6596 |
leave(vnode, rm); |
| 6597 |
} else { |
| 6598 |
rm(); |
| 6599 |
} |
| 6600 |
} |
| 6601 |
} : {}; |
| 6602 |
|
| 6603 |
var platformModules = [ |
| 6604 |
attrs, |
| 6605 |
klass, |
| 6606 |
events, |
| 6607 |
domProps, |
| 6608 |
style, |
| 6609 |
transition |
| 6610 |
]; |
| 6611 |
|
| 6612 |
/* */ |
| 6613 |
|
| 6614 |
// the directive module should be applied last, after all |
| 6615 |
// built-in modules have been applied. |
| 6616 |
var modules = platformModules.concat(baseModules); |
| 6617 |
|
| 6618 |
var patch = createPatchFunction({ nodeOps: nodeOps, modules: modules }); |
| 6619 |
|
| 6620 |
/** |
| 6621 |
* Not type checking this file because flow doesn't like attaching |
| 6622 |
* properties to Elements. |
| 6623 |
*/ |
| 6624 |
|
| 6625 |
/* istanbul ignore if */ |
| 6626 |
if (isIE9) { |
| 6627 |
// http://www.matts411.com/post/internet-explorer-9-oninput/ |
| 6628 |
document.addEventListener('selectionchange', function () { |
| 6629 |
var el = document.activeElement; |
| 6630 |
if (el && el.vmodel) { |
| 6631 |
trigger(el, 'input'); |
| 6632 |
} |
| 6633 |
}); |
| 6634 |
} |
| 6635 |
|
| 6636 |
var model$1 = { |
| 6637 |
inserted: function inserted (el, binding, vnode) { |
| 6638 |
if (vnode.tag === 'select') { |
| 6639 |
var cb = function () { |
| 6640 |
setSelected(el, binding, vnode.context); |
| 6641 |
}; |
| 6642 |
cb(); |
| 6643 |
/* istanbul ignore if */ |
| 6644 |
if (isIE || isEdge) { |
| 6645 |
setTimeout(cb, 0); |
| 6646 |
} |
| 6647 |
} else if (vnode.tag === 'textarea' || el.type === 'text') { |
| 6648 |
el._vModifiers = binding.modifiers; |
| 6649 |
if (!binding.modifiers.lazy) { |
| 6650 |
if (!isAndroid) { |
| 6651 |
el.addEventListener('compositionstart', onCompositionStart); |
| 6652 |
el.addEventListener('compositionend', onCompositionEnd); |
| 6653 |
} |
| 6654 |
/* istanbul ignore if */ |
| 6655 |
if (isIE9) { |
| 6656 |
el.vmodel = true; |
| 6657 |
} |
| 6658 |
} |
| 6659 |
} |
| 6660 |
}, |
| 6661 |
componentUpdated: function componentUpdated (el, binding, vnode) { |
| 6662 |
if (vnode.tag === 'select') { |
| 6663 |
setSelected(el, binding, vnode.context); |
| 6664 |
// in case the options rendered by v-for have changed, |
| 6665 |
// it's possible that the value is out-of-sync with the rendered options. |
| 6666 |
// detect such cases and filter out values that no longer has a matching |
| 6667 |
// option in the DOM. |
| 6668 |
var needReset = el.multiple |
| 6669 |
? binding.value.some(function (v) { return hasNoMatchingOption(v, el.options); }) |
| 6670 |
: binding.value !== binding.oldValue && hasNoMatchingOption(binding.value, el.options); |
| 6671 |
if (needReset) { |
| 6672 |
trigger(el, 'change'); |
| 6673 |
} |
| 6674 |
} |
| 6675 |
} |
| 6676 |
}; |
| 6677 |
|
| 6678 |
function setSelected (el, binding, vm) { |
| 6679 |
var value = binding.value; |
| 6680 |
var isMultiple = el.multiple; |
| 6681 |
if (isMultiple && !Array.isArray(value)) { |
| 6682 |
"development" !== 'production' && warn( |
| 6683 |
"<select multiple v-model=\"" + (binding.expression) + "\"> " + |
| 6684 |
"expects an Array value for its binding, but got " + (Object.prototype.toString.call(value).slice(8, -1)), |
| 6685 |
vm |
| 6686 |
); |
| 6687 |
return |
| 6688 |
} |
| 6689 |
var selected, option; |
| 6690 |
for (var i = 0, l = el.options.length; i < l; i++) { |
| 6691 |
option = el.options[i]; |
| 6692 |
if (isMultiple) { |
| 6693 |
selected = looseIndexOf(value, getValue(option)) > -1; |
| 6694 |
if (option.selected !== selected) { |
| 6695 |
option.selected = selected; |
| 6696 |
} |
| 6697 |
} else { |
| 6698 |
if (looseEqual(getValue(option), value)) { |
| 6699 |
if (el.selectedIndex !== i) { |
| 6700 |
el.selectedIndex = i; |
| 6701 |
} |
| 6702 |
return |
| 6703 |
} |
| 6704 |
} |
| 6705 |
} |
| 6706 |
if (!isMultiple) { |
| 6707 |
el.selectedIndex = -1; |
| 6708 |
} |
| 6709 |
} |
| 6710 |
|
| 6711 |
function hasNoMatchingOption (value, options) { |
| 6712 |
for (var i = 0, l = options.length; i < l; i++) { |
| 6713 |
if (looseEqual(getValue(options[i]), value)) { |
| 6714 |
return false |
| 6715 |
} |
| 6716 |
} |
| 6717 |
return true |
| 6718 |
} |
| 6719 |
|
| 6720 |
function getValue (option) { |
| 6721 |
return '_value' in option |
| 6722 |
? option._value |
| 6723 |
: option.value |
| 6724 |
} |
| 6725 |
|
| 6726 |
function onCompositionStart (e) { |
| 6727 |
e.target.composing = true; |
| 6728 |
} |
| 6729 |
|
| 6730 |
function onCompositionEnd (e) { |
| 6731 |
e.target.composing = false; |
| 6732 |
trigger(e.target, 'input'); |
| 6733 |
} |
| 6734 |
|
| 6735 |
function trigger (el, type) { |
| 6736 |
var e = document.createEvent('HTMLEvents'); |
| 6737 |
e.initEvent(type, true, true); |
| 6738 |
el.dispatchEvent(e); |
| 6739 |
} |
| 6740 |
|
| 6741 |
/* */ |
| 6742 |
|
| 6743 |
// recursively search for possible transition defined inside the component root |
| 6744 |
function locateNode (vnode) { |
| 6745 |
return vnode.componentInstance && (!vnode.data || !vnode.data.transition) |
| 6746 |
? locateNode(vnode.componentInstance._vnode) |
| 6747 |
: vnode |
| 6748 |
} |
| 6749 |
|
| 6750 |
var show = { |
| 6751 |
bind: function bind (el, ref, vnode) { |
| 6752 |
var value = ref.value; |
| 6753 |
|
| 6754 |
vnode = locateNode(vnode); |
| 6755 |
var transition = vnode.data && vnode.data.transition; |
| 6756 |
var originalDisplay = el.__vOriginalDisplay = |
| 6757 |
el.style.display === 'none' ? '' : el.style.display; |
| 6758 |
if (value && transition && !isIE9) { |
| 6759 |
vnode.data.show = true; |
| 6760 |
enter(vnode, function () { |
| 6761 |
el.style.display = originalDisplay; |
| 6762 |
}); |
| 6763 |
} else { |
| 6764 |
el.style.display = value ? originalDisplay : 'none'; |
| 6765 |
} |
| 6766 |
}, |
| 6767 |
|
| 6768 |
update: function update (el, ref, vnode) { |
| 6769 |
var value = ref.value; |
| 6770 |
var oldValue = ref.oldValue; |
| 6771 |
|
| 6772 |
/* istanbul ignore if */ |
| 6773 |
if (value === oldValue) { return } |
| 6774 |
vnode = locateNode(vnode); |
| 6775 |
var transition = vnode.data && vnode.data.transition; |
| 6776 |
if (transition && !isIE9) { |
| 6777 |
vnode.data.show = true; |
| 6778 |
if (value) { |
| 6779 |
enter(vnode, function () { |
| 6780 |
el.style.display = el.__vOriginalDisplay; |
| 6781 |
}); |
| 6782 |
} else { |
| 6783 |
leave(vnode, function () { |
| 6784 |
el.style.display = 'none'; |
| 6785 |
}); |
| 6786 |
} |
| 6787 |
} else { |
| 6788 |
el.style.display = value ? el.__vOriginalDisplay : 'none'; |
| 6789 |
} |
| 6790 |
}, |
| 6791 |
|
| 6792 |
unbind: function unbind ( |
| 6793 |
el, |
| 6794 |
binding, |
| 6795 |
vnode, |
| 6796 |
oldVnode, |
| 6797 |
isDestroy |
| 6798 |
) { |
| 6799 |
if (!isDestroy) { |
| 6800 |
el.style.display = el.__vOriginalDisplay; |
| 6801 |
} |
| 6802 |
} |
| 6803 |
}; |
| 6804 |
|
| 6805 |
var platformDirectives = { |
| 6806 |
model: model$1, |
| 6807 |
show: show |
| 6808 |
}; |
| 6809 |
|
| 6810 |
/* */ |
| 6811 |
|
| 6812 |
// Provides transition support for a single element/component. |
| 6813 |
// supports transition mode (out-in / in-out) |
| 6814 |
|
| 6815 |
var transitionProps = { |
| 6816 |
name: String, |
| 6817 |
appear: Boolean, |
| 6818 |
css: Boolean, |
| 6819 |
mode: String, |
| 6820 |
type: String, |
| 6821 |
enterClass: String, |
| 6822 |
leaveClass: String, |
| 6823 |
enterToClass: String, |
| 6824 |
leaveToClass: String, |
| 6825 |
enterActiveClass: String, |
| 6826 |
leaveActiveClass: String, |
| 6827 |
appearClass: String, |
| 6828 |
appearActiveClass: String, |
| 6829 |
appearToClass: String, |
| 6830 |
duration: [Number, String, Object] |
| 6831 |
}; |
| 6832 |
|
| 6833 |
// in case the child is also an abstract component, e.g. <keep-alive> |
| 6834 |
// we want to recursively retrieve the real component to be rendered |
| 6835 |
function getRealChild (vnode) { |
| 6836 |
var compOptions = vnode && vnode.componentOptions; |
| 6837 |
if (compOptions && compOptions.Ctor.options.abstract) { |
| 6838 |
return getRealChild(getFirstComponentChild(compOptions.children)) |
| 6839 |
} else { |
| 6840 |
return vnode |
| 6841 |
} |
| 6842 |
} |
| 6843 |
|
| 6844 |
function extractTransitionData (comp) { |
| 6845 |
var data = {}; |
| 6846 |
var options = comp.$options; |
| 6847 |
// props |
| 6848 |
for (var key in options.propsData) { |
| 6849 |
data[key] = comp[key]; |
| 6850 |
} |
| 6851 |
// events. |
| 6852 |
// extract listeners and pass them directly to the transition methods |
| 6853 |
var listeners = options._parentListeners; |
| 6854 |
for (var key$1 in listeners) { |
| 6855 |
data[camelize(key$1)] = listeners[key$1]; |
| 6856 |
} |
| 6857 |
return data |
| 6858 |
} |
| 6859 |
|
| 6860 |
function placeholder (h, rawChild) { |
| 6861 |
return /\d-keep-alive$/.test(rawChild.tag) |
| 6862 |
? h('keep-alive') |
| 6863 |
: null |
| 6864 |
} |
| 6865 |
|
| 6866 |
function hasParentTransition (vnode) { |
| 6867 |
while ((vnode = vnode.parent)) { |
| 6868 |
if (vnode.data.transition) { |
| 6869 |
return true |
| 6870 |
} |
| 6871 |
} |
| 6872 |
} |
| 6873 |
|
| 6874 |
function isSameChild (child, oldChild) { |
| 6875 |
return oldChild.key === child.key && oldChild.tag === child.tag |
| 6876 |
} |
| 6877 |
|
| 6878 |
var Transition = { |
| 6879 |
name: 'transition', |
| 6880 |
props: transitionProps, |
| 6881 |
abstract: true, |
| 6882 |
|
| 6883 |
render: function render (h) { |
| 6884 |
var this$1 = this; |
| 6885 |
|
| 6886 |
var children = this.$slots.default; |
| 6887 |
if (!children) { |
| 6888 |
return |
| 6889 |
} |
| 6890 |
|
| 6891 |
// filter out text nodes (possible whitespaces) |
| 6892 |
children = children.filter(function (c) { return c.tag; }); |
| 6893 |
/* istanbul ignore if */ |
| 6894 |
if (!children.length) { |
| 6895 |
return |
| 6896 |
} |
| 6897 |
|
| 6898 |
// warn multiple elements |
| 6899 |
if ("development" !== 'production' && children.length > 1) { |
| 6900 |
warn( |
| 6901 |
'<transition> can only be used on a single element. Use ' + |
| 6902 |
'<transition-group> for lists.', |
| 6903 |
this.$parent |
| 6904 |
); |
| 6905 |
} |
| 6906 |
|
| 6907 |
var mode = this.mode; |
| 6908 |
|
| 6909 |
// warn invalid mode |
| 6910 |
if ("development" !== 'production' && |
| 6911 |
mode && mode !== 'in-out' && mode !== 'out-in') { |
| 6912 |
warn( |
| 6913 |
'invalid <transition> mode: ' + mode, |
| 6914 |
this.$parent |
| 6915 |
); |
| 6916 |
} |
| 6917 |
|
| 6918 |
var rawChild = children[0]; |
| 6919 |
|
| 6920 |
// if this is a component root node and the component's |
| 6921 |
// parent container node also has transition, skip. |
| 6922 |
if (hasParentTransition(this.$vnode)) { |
| 6923 |
return rawChild |
| 6924 |
} |
| 6925 |
|
| 6926 |
// apply transition data to child |
| 6927 |
// use getRealChild() to ignore abstract components e.g. keep-alive |
| 6928 |
var child = getRealChild(rawChild); |
| 6929 |
/* istanbul ignore if */ |
| 6930 |
if (!child) { |
| 6931 |
return rawChild |
| 6932 |
} |
| 6933 |
|
| 6934 |
if (this._leaving) { |
| 6935 |
return placeholder(h, rawChild) |
| 6936 |
} |
| 6937 |
|
| 6938 |
// ensure a key that is unique to the vnode type and to this transition |
| 6939 |
// component instance. This key will be used to remove pending leaving nodes |
| 6940 |
// during entering. |
| 6941 |
var id = "__transition-" + (this._uid) + "-"; |
| 6942 |
child.key = child.key == null |
| 6943 |
? id + child.tag |
| 6944 |
: isPrimitive(child.key) |
| 6945 |
? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key) |
| 6946 |
: child.key; |
| 6947 |
|
| 6948 |
var data = (child.data || (child.data = {})).transition = extractTransitionData(this); |
| 6949 |
var oldRawChild = this._vnode; |
| 6950 |
var oldChild = getRealChild(oldRawChild); |
| 6951 |
|
| 6952 |
// mark v-show |
| 6953 |
// so that the transition module can hand over the control to the directive |
| 6954 |
if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) { |
| 6955 |
child.data.show = true; |
| 6956 |
} |
| 6957 |
|
| 6958 |
if (oldChild && oldChild.data && !isSameChild(child, oldChild)) { |
| 6959 |
// replace old child transition data with fresh one |
| 6960 |
// important for dynamic transitions! |
| 6961 |
var oldData = oldChild && (oldChild.data.transition = extend({}, data)); |
| 6962 |
// handle transition mode |
| 6963 |
if (mode === 'out-in') { |
| 6964 |
// return placeholder node and queue update when leave finishes |
| 6965 |
this._leaving = true; |
| 6966 |
mergeVNodeHook(oldData, 'afterLeave', function () { |
| 6967 |
this$1._leaving = false; |
| 6968 |
this$1.$forceUpdate(); |
| 6969 |
}); |
| 6970 |
return placeholder(h, rawChild) |
| 6971 |
} else if (mode === 'in-out') { |
| 6972 |
var delayedLeave; |
| 6973 |
var performLeave = function () { delayedLeave(); }; |
| 6974 |
mergeVNodeHook(data, 'afterEnter', performLeave); |
| 6975 |
mergeVNodeHook(data, 'enterCancelled', performLeave); |
| 6976 |
mergeVNodeHook(oldData, 'delayLeave', function (leave) { delayedLeave = leave; }); |
| 6977 |
} |
| 6978 |
} |
| 6979 |
|
| 6980 |
return rawChild |
| 6981 |
} |
| 6982 |
}; |
| 6983 |
|
| 6984 |
/* */ |
| 6985 |
|
| 6986 |
// Provides transition support for list items. |
| 6987 |
// supports move transitions using the FLIP technique. |
| 6988 |
|
| 6989 |
// Because the vdom's children update algorithm is "unstable" - i.e. |
| 6990 |
// it doesn't guarantee the relative positioning of removed elements, |
| 6991 |
// we force transition-group to update its children into two passes: |
| 6992 |
// in the first pass, we remove all nodes that need to be removed, |
| 6993 |
// triggering their leaving transition; in the second pass, we insert/move |
| 6994 |
// into the final desired state. This way in the second pass removed |
| 6995 |
// nodes will remain where they should be. |
| 6996 |
|
| 6997 |
var props = extend({ |
| 6998 |
tag: String, |
| 6999 |
moveClass: String |
| 7000 |
}, transitionProps); |
| 7001 |
|
| 7002 |
delete props.mode; |
| 7003 |
|
| 7004 |
var TransitionGroup = { |
| 7005 |
props: props, |
| 7006 |
|
| 7007 |
render: function render (h) { |
| 7008 |
var tag = this.tag || this.$vnode.data.tag || 'span'; |
| 7009 |
var map = Object.create(null); |
| 7010 |
var prevChildren = this.prevChildren = this.children; |
| 7011 |
var rawChildren = this.$slots.default || []; |
| 7012 |
var children = this.children = []; |
| 7013 |
var transitionData = extractTransitionData(this); |
| 7014 |
|
| 7015 |
for (var i = 0; i < rawChildren.length; i++) { |
| 7016 |
var c = rawChildren[i]; |
| 7017 |
if (c.tag) { |
| 7018 |
if (c.key != null && String(c.key).indexOf('__vlist') !== 0) { |
| 7019 |
children.push(c); |
| 7020 |
map[c.key] = c |
| 7021 |
;(c.data || (c.data = {})).transition = transitionData; |
| 7022 |
} else { |
| 7023 |
var opts = c.componentOptions; |
| 7024 |
var name = opts ? (opts.Ctor.options.name || opts.tag || '') : c.tag; |
| 7025 |
warn(("<transition-group> children must be keyed: <" + name + ">")); |
| 7026 |
} |
| 7027 |
} |
| 7028 |
} |
| 7029 |
|
| 7030 |
if (prevChildren) { |
| 7031 |
var kept = []; |
| 7032 |
var removed = []; |
| 7033 |
for (var i$1 = 0; i$1 < prevChildren.length; i$1++) { |
| 7034 |
var c$1 = prevChildren[i$1]; |
| 7035 |
c$1.data.transition = transitionData; |
| 7036 |
c$1.data.pos = c$1.elm.getBoundingClientRect(); |
| 7037 |
if (map[c$1.key]) { |
| 7038 |
kept.push(c$1); |
| 7039 |
} else { |
| 7040 |
removed.push(c$1); |
| 7041 |
} |
| 7042 |
} |
| 7043 |
this.kept = h(tag, null, kept); |
| 7044 |
this.removed = removed; |
| 7045 |
} |
| 7046 |
|
| 7047 |
return h(tag, null, children) |
| 7048 |
}, |
| 7049 |
|
| 7050 |
beforeUpdate: function beforeUpdate () { |
| 7051 |
// force removing pass |
| 7052 |
this.__patch__( |
| 7053 |
this._vnode, |
| 7054 |
this.kept, |
| 7055 |
false, // hydrating |
| 7056 |
true // removeOnly (!important, avoids unnecessary moves) |
| 7057 |
); |
| 7058 |
this._vnode = this.kept; |
| 7059 |
}, |
| 7060 |
|
| 7061 |
updated: function updated () { |
| 7062 |
var children = this.prevChildren; |
| 7063 |
var moveClass = this.moveClass || ((this.name || 'v') + '-move'); |
| 7064 |
if (!children.length || !this.hasMove(children[0].elm, moveClass)) { |
| 7065 |
return |
| 7066 |
} |
| 7067 |
|
| 7068 |
// we divide the work into three loops to avoid mixing DOM reads and writes |
| 7069 |
// in each iteration - which helps prevent layout thrashing. |
| 7070 |
children.forEach(callPendingCbs); |
| 7071 |
children.forEach(recordPosition); |
| 7072 |
children.forEach(applyTranslation); |
| 7073 |
|
| 7074 |
// force reflow to put everything in position |
| 7075 |
var body = document.body; |
| 7076 |
var f = body.offsetHeight; // eslint-disable-line |
| 7077 |
|
| 7078 |
children.forEach(function (c) { |
| 7079 |
if (c.data.moved) { |
| 7080 |
var el = c.elm; |
| 7081 |
var s = el.style; |
| 7082 |
addTransitionClass(el, moveClass); |
| 7083 |
s.transform = s.WebkitTransform = s.transitionDuration = ''; |
| 7084 |
el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) { |
| 7085 |
if (!e || /transform$/.test(e.propertyName)) { |
| 7086 |
el.removeEventListener(transitionEndEvent, cb); |
| 7087 |
el._moveCb = null; |
| 7088 |
removeTransitionClass(el, moveClass); |
| 7089 |
} |
| 7090 |
}); |
| 7091 |
} |
| 7092 |
}); |
| 7093 |
}, |
| 7094 |
|
| 7095 |
methods: { |
| 7096 |
hasMove: function hasMove (el, moveClass) { |
| 7097 |
/* istanbul ignore if */ |
| 7098 |
if (!hasTransition) { |
| 7099 |
return false |
| 7100 |
} |
| 7101 |
if (this._hasMove != null) { |
| 7102 |
return this._hasMove |
| 7103 |
} |
| 7104 |
// Detect whether an element with the move class applied has |
| 7105 |
// CSS transitions. Since the element may be inside an entering |
| 7106 |
// transition at this very moment, we make a clone of it and remove |
| 7107 |
// all other transition classes applied to ensure only the move class |
| 7108 |
// is applied. |
| 7109 |
var clone = el.cloneNode(); |
| 7110 |
if (el._transitionClasses) { |
| 7111 |
el._transitionClasses.forEach(function (cls) { removeClass(clone, cls); }); |
| 7112 |
} |
| 7113 |
addClass(clone, moveClass); |
| 7114 |
clone.style.display = 'none'; |
| 7115 |
this.$el.appendChild(clone); |
| 7116 |
var info = getTransitionInfo(clone); |
| 7117 |
this.$el.removeChild(clone); |
| 7118 |
return (this._hasMove = info.hasTransform) |
| 7119 |
} |
| 7120 |
} |
| 7121 |
}; |
| 7122 |
|
| 7123 |
function callPendingCbs (c) { |
| 7124 |
/* istanbul ignore if */ |
| 7125 |
if (c.elm._moveCb) { |
| 7126 |
c.elm._moveCb(); |
| 7127 |
} |
| 7128 |
/* istanbul ignore if */ |
| 7129 |
if (c.elm._enterCb) { |
| 7130 |
c.elm._enterCb(); |
| 7131 |
} |
| 7132 |
} |
| 7133 |
|
| 7134 |
function recordPosition (c) { |
| 7135 |
c.data.newPos = c.elm.getBoundingClientRect(); |
| 7136 |
} |
| 7137 |
|
| 7138 |
function applyTranslation (c) { |
| 7139 |
var oldPos = c.data.pos; |
| 7140 |
var newPos = c.data.newPos; |
| 7141 |
var dx = oldPos.left - newPos.left; |
| 7142 |
var dy = oldPos.top - newPos.top; |
| 7143 |
if (dx || dy) { |
| 7144 |
c.data.moved = true; |
| 7145 |
var s = c.elm.style; |
| 7146 |
s.transform = s.WebkitTransform = "translate(" + dx + "px," + dy + "px)"; |
| 7147 |
s.transitionDuration = '0s'; |
| 7148 |
} |
| 7149 |
} |
| 7150 |
|
| 7151 |
var platformComponents = { |
| 7152 |
Transition: Transition, |
| 7153 |
TransitionGroup: TransitionGroup |
| 7154 |
}; |
| 7155 |
|
| 7156 |
/* */ |
| 7157 |
|
| 7158 |
// install platform specific utils |
| 7159 |
Vue$3.config.mustUseProp = mustUseProp; |
| 7160 |
Vue$3.config.isReservedTag = isReservedTag; |
| 7161 |
Vue$3.config.getTagNamespace = getTagNamespace; |
| 7162 |
Vue$3.config.isUnknownElement = isUnknownElement; |
| 7163 |
|
| 7164 |
// install platform runtime directives & components |
| 7165 |
extend(Vue$3.options.directives, platformDirectives); |
| 7166 |
extend(Vue$3.options.components, platformComponents); |
| 7167 |
|
| 7168 |
// install platform patch function |
| 7169 |
Vue$3.prototype.__patch__ = inBrowser ? patch : noop; |
| 7170 |
|
| 7171 |
// public mount method |
| 7172 |
Vue$3.prototype.$mount = function ( |
| 7173 |
el, |
| 7174 |
hydrating |
| 7175 |
) { |
| 7176 |
el = el && inBrowser ? query(el) : undefined; |
| 7177 |
return mountComponent(this, el, hydrating) |
| 7178 |
}; |
| 7179 |
|
| 7180 |
// devtools global hook |
| 7181 |
/* istanbul ignore next */ |
| 7182 |
setTimeout(function () { |
| 7183 |
if (config.devtools) { |
| 7184 |
if (devtools) { |
| 7185 |
devtools.emit('init', Vue$3); |
| 7186 |
} else if ("development" !== 'production' && isChrome) { |
| 7187 |
console[console.info ? 'info' : 'log']( |
| 7188 |
'Download the Vue Devtools extension for a better development experience:\n' + |
| 7189 |
'https://github.com/vuejs/vue-devtools' |
| 7190 |
); |
| 7191 |
} |
| 7192 |
} |
| 7193 |
if ("development" !== 'production' && |
| 7194 |
config.productionTip !== false && |
| 7195 |
inBrowser && typeof console !== 'undefined') { |
| 7196 |
console[console.info ? 'info' : 'log']( |
| 7197 |
"You are running Vue in development mode.\n" + |
| 7198 |
"Make sure to turn on production mode when deploying for production.\n" + |
| 7199 |
"See more tips at https://vuejs.org/guide/deployment.html" |
| 7200 |
); |
| 7201 |
} |
| 7202 |
}, 0); |
| 7203 |
|
| 7204 |
/* */ |
| 7205 |
|
| 7206 |
// check whether current browser encodes a char inside attribute values |
| 7207 |
function shouldDecode (content, encoded) { |
| 7208 |
var div = document.createElement('div'); |
| 7209 |
div.innerHTML = "<div a=\"" + content + "\">"; |
| 7210 |
return div.innerHTML.indexOf(encoded) > 0 |
| 7211 |
} |
| 7212 |
|
| 7213 |
// #3663 |
| 7214 |
// IE encodes newlines inside attribute values while other browsers don't |
| 7215 |
var shouldDecodeNewlines = inBrowser ? shouldDecode('\n', ' ') : false; |
| 7216 |
|
| 7217 |
/* */ |
| 7218 |
|
| 7219 |
var isUnaryTag = makeMap( |
| 7220 |
'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + |
| 7221 |
'link,meta,param,source,track,wbr' |
| 7222 |
); |
| 7223 |
|
| 7224 |
// Elements that you can, intentionally, leave open |
| 7225 |
// (and which close themselves) |
| 7226 |
var canBeLeftOpenTag = makeMap( |
| 7227 |
'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source' |
| 7228 |
); |
| 7229 |
|
| 7230 |
// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3 |
| 7231 |
// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content |
| 7232 |
var isNonPhrasingTag = makeMap( |
| 7233 |
'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' + |
| 7234 |
'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' + |
| 7235 |
'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' + |
| 7236 |
'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' + |
| 7237 |
'title,tr,track' |
| 7238 |
); |
| 7239 |
|
| 7240 |
/* */ |
| 7241 |
|
| 7242 |
var decoder; |
| 7243 |
|
| 7244 |
function decode (html) { |
| 7245 |
decoder = decoder || document.createElement('div'); |
| 7246 |
decoder.innerHTML = html; |
| 7247 |
return decoder.textContent |
| 7248 |
} |
| 7249 |
|
| 7250 |
/** |
| 7251 |
* Not type-checking this file because it's mostly vendor code. |
| 7252 |
*/ |
| 7253 |
|
| 7254 |
/*! |
| 7255 |
* HTML Parser By John Resig (ejohn.org) |
| 7256 |
* Modified by Juriy "kangax" Zaytsev |
| 7257 |
* Original code by Erik Arvidsson, Mozilla Public License |
| 7258 |
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js |
| 7259 |
*/ |
| 7260 |
|
| 7261 |
// Regular Expressions for parsing tags and attributes |
| 7262 |
var singleAttrIdentifier = /([^\s"'<>/=]+)/; |
| 7263 |
var singleAttrAssign = /(?:=)/; |
| 7264 |
var singleAttrValues = [ |
| 7265 |
// attr value double quotes |
| 7266 |
/"([^"]*)"+/.source, |
| 7267 |
// attr value, single quotes |
| 7268 |
/'([^']*)'+/.source, |
| 7269 |
// attr value, no quotes |
| 7270 |
/([^\s"'=<>`]+)/.source |
| 7271 |
]; |
| 7272 |
var attribute = new RegExp( |
| 7273 |
'^\\s*' + singleAttrIdentifier.source + |
| 7274 |
'(?:\\s*(' + singleAttrAssign.source + ')' + |
| 7275 |
'\\s*(?:' + singleAttrValues.join('|') + '))?' |
| 7276 |
); |
| 7277 |
|
| 7278 |
// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName |
| 7279 |
// but for Vue templates we can enforce a simple charset |
| 7280 |
var ncname = '[a-zA-Z_][\\w\\-\\.]*'; |
| 7281 |
var qnameCapture = '((?:' + ncname + '\\:)?' + ncname + ')'; |
| 7282 |
var startTagOpen = new RegExp('^<' + qnameCapture); |
| 7283 |
var startTagClose = /^\s*(\/?)>/; |
| 7284 |
var endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>'); |
| 7285 |
var doctype = /^<!DOCTYPE [^>]+>/i; |
| 7286 |
var comment = /^<!--/; |
| 7287 |
var conditionalComment = /^<!\[/; |
| 7288 |
|
| 7289 |
var IS_REGEX_CAPTURING_BROKEN = false; |
| 7290 |
'x'.replace(/x(.)?/g, function (m, g) { |
| 7291 |
IS_REGEX_CAPTURING_BROKEN = g === ''; |
| 7292 |
}); |
| 7293 |
|
| 7294 |
// Special Elements (can contain anything) |
| 7295 |
var isPlainTextElement = makeMap('script,style,textarea', true); |
| 7296 |
var reCache = {}; |
| 7297 |
|
| 7298 |
var decodingMap = { |
| 7299 |
'<': '<', |
| 7300 |
'>': '>', |
| 7301 |
'"': '"', |
| 7302 |
'&': '&', |
| 7303 |
' ': '\n' |
| 7304 |
}; |
| 7305 |
var encodedAttr = /&(?:lt|gt|quot|amp);/g; |
| 7306 |
var encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10);/g; |
| 7307 |
|
| 7308 |
function decodeAttr (value, shouldDecodeNewlines) { |
| 7309 |
var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr; |
| 7310 |
return value.replace(re, function (match) { return decodingMap[match]; }) |
| 7311 |
} |
| 7312 |
|
| 7313 |
function parseHTML (html, options) { |
| 7314 |
var stack = []; |
| 7315 |
var expectHTML = options.expectHTML; |
| 7316 |
var isUnaryTag$$1 = options.isUnaryTag || no; |
| 7317 |
var index = 0; |
| 7318 |
var last, lastTag; |
| 7319 |
while (html) { |
| 7320 |
last = html; |
| 7321 |
// Make sure we're not in a plaintext content element like script/style |
| 7322 |
if (!lastTag || !isPlainTextElement(lastTag)) { |
| 7323 |
var textEnd = html.indexOf('<'); |
| 7324 |
if (textEnd === 0) { |
| 7325 |
// Comment: |
| 7326 |
if (comment.test(html)) { |
| 7327 |
var commentEnd = html.indexOf('-->'); |
| 7328 |
|
| 7329 |
if (commentEnd >= 0) { |
| 7330 |
advance(commentEnd + 3); |
| 7331 |
continue |
| 7332 |
} |
| 7333 |
} |
| 7334 |
|
| 7335 |
// http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment |
| 7336 |
if (conditionalComment.test(html)) { |
| 7337 |
var conditionalEnd = html.indexOf(']>'); |
| 7338 |
|
| 7339 |
if (conditionalEnd >= 0) { |
| 7340 |
advance(conditionalEnd + 2); |
| 7341 |
continue |
| 7342 |
} |
| 7343 |
} |
| 7344 |
|
| 7345 |
// Doctype: |
| 7346 |
var doctypeMatch = html.match(doctype); |
| 7347 |
if (doctypeMatch) { |
| 7348 |
advance(doctypeMatch[0].length); |
| 7349 |
continue |
| 7350 |
} |
| 7351 |
|
| 7352 |
// End tag: |
| 7353 |
var endTagMatch = html.match(endTag); |
| 7354 |
if (endTagMatch) { |
| 7355 |
var curIndex = index; |
| 7356 |
advance(endTagMatch[0].length); |
| 7357 |
parseEndTag(endTagMatch[1], curIndex, index); |
| 7358 |
continue |
| 7359 |
} |
| 7360 |
|
| 7361 |
// Start tag: |
| 7362 |
var startTagMatch = parseStartTag(); |
| 7363 |
if (startTagMatch) { |
| 7364 |
handleStartTag(startTagMatch); |
| 7365 |
continue |
| 7366 |
} |
| 7367 |
} |
| 7368 |
|
| 7369 |
var text = (void 0), rest$1 = (void 0), next = (void 0); |
| 7370 |
if (textEnd >= 0) { |
| 7371 |
rest$1 = html.slice(textEnd); |
| 7372 |
while ( |
| 7373 |
!endTag.test(rest$1) && |
| 7374 |
!startTagOpen.test(rest$1) && |
| 7375 |
!comment.test(rest$1) && |
| 7376 |
!conditionalComment.test(rest$1) |
| 7377 |
) { |
| 7378 |
// < in plain text, be forgiving and treat it as text |
| 7379 |
next = rest$1.indexOf('<', 1); |
| 7380 |
if (next < 0) { break } |
| 7381 |
textEnd += next; |
| 7382 |
rest$1 = html.slice(textEnd); |
| 7383 |
} |
| 7384 |
text = html.substring(0, textEnd); |
| 7385 |
advance(textEnd); |
| 7386 |
} |
| 7387 |
|
| 7388 |
if (textEnd < 0) { |
| 7389 |
text = html; |
| 7390 |
html = ''; |
| 7391 |
} |
| 7392 |
|
| 7393 |
if (options.chars && text) { |
| 7394 |
options.chars(text); |
| 7395 |
} |
| 7396 |
} else { |
| 7397 |
var stackedTag = lastTag.toLowerCase(); |
| 7398 |
var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i')); |
| 7399 |
var endTagLength = 0; |
| 7400 |
var rest = html.replace(reStackedTag, function (all, text, endTag) { |
| 7401 |
endTagLength = endTag.length; |
| 7402 |
if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') { |
| 7403 |
text = text |
| 7404 |
.replace(/<!--([\s\S]*?)-->/g, '$1') |
| 7405 |
.replace(/<!\[CDATA\[([\s\S]*?)]]>/g, '$1'); |
| 7406 |
} |
| 7407 |
if (options.chars) { |
| 7408 |
options.chars(text); |
| 7409 |
} |
| 7410 |
return '' |
| 7411 |
}); |
| 7412 |
index += html.length - rest.length; |
| 7413 |
html = rest; |
| 7414 |
parseEndTag(stackedTag, index - endTagLength, index); |
| 7415 |
} |
| 7416 |
|
| 7417 |
if (html === last) { |
| 7418 |
options.chars && options.chars(html); |
| 7419 |
if ("development" !== 'production' && !stack.length && options.warn) { |
| 7420 |
options.warn(("Mal-formatted tag at end of template: \"" + html + "\"")); |
| 7421 |
} |
| 7422 |
break |
| 7423 |
} |
| 7424 |
} |
| 7425 |
|
| 7426 |
// Clean up any remaining tags |
| 7427 |
parseEndTag(); |
| 7428 |
|
| 7429 |
function advance (n) { |
| 7430 |
index += n; |
| 7431 |
html = html.substring(n); |
| 7432 |
} |
| 7433 |
|
| 7434 |
function parseStartTag () { |
| 7435 |
var start = html.match(startTagOpen); |
| 7436 |
if (start) { |
| 7437 |
var match = { |
| 7438 |
tagName: start[1], |
| 7439 |
attrs: [], |
| 7440 |
start: index |
| 7441 |
}; |
| 7442 |
advance(start[0].length); |
| 7443 |
var end, attr; |
| 7444 |
while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) { |
| 7445 |
advance(attr[0].length); |
| 7446 |
match.attrs.push(attr); |
| 7447 |
} |
| 7448 |
if (end) { |
| 7449 |
match.unarySlash = end[1]; |
| 7450 |
advance(end[0].length); |
| 7451 |
match.end = index; |
| 7452 |
return match |
| 7453 |
} |
| 7454 |
} |
| 7455 |
} |
| 7456 |
|
| 7457 |
function handleStartTag (match) { |
| 7458 |
var tagName = match.tagName; |
| 7459 |
var unarySlash = match.unarySlash; |
| 7460 |
|
| 7461 |
if (expectHTML) { |
| 7462 |
if (lastTag === 'p' && isNonPhrasingTag(tagName)) { |
| 7463 |
parseEndTag(lastTag); |
| 7464 |
} |
| 7465 |
if (canBeLeftOpenTag(tagName) && lastTag === tagName) { |
| 7466 |
parseEndTag(tagName); |
| 7467 |
} |
| 7468 |
} |
| 7469 |
|
| 7470 |
var unary = isUnaryTag$$1(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash; |
| 7471 |
|
| 7472 |
var l = match.attrs.length; |
| 7473 |
var attrs = new Array(l); |
| 7474 |
for (var i = 0; i < l; i++) { |
| 7475 |
var args = match.attrs[i]; |
| 7476 |
// hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778 |
| 7477 |
if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) { |
| 7478 |
if (args[3] === '') { delete args[3]; } |
| 7479 |
if (args[4] === '') { delete args[4]; } |
| 7480 |
if (args[5] === '') { delete args[5]; } |
| 7481 |
} |
| 7482 |
var value = args[3] || args[4] || args[5] || ''; |
| 7483 |
attrs[i] = { |
| 7484 |
name: args[1], |
| 7485 |
value: decodeAttr( |
| 7486 |
value, |
| 7487 |
options.shouldDecodeNewlines |
| 7488 |
) |
| 7489 |
}; |
| 7490 |
} |
| 7491 |
|
| 7492 |
if (!unary) { |
| 7493 |
stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs }); |
| 7494 |
lastTag = tagName; |
| 7495 |
} |
| 7496 |
|
| 7497 |
if (options.start) { |
| 7498 |
options.start(tagName, attrs, unary, match.start, match.end); |
| 7499 |
} |
| 7500 |
} |
| 7501 |
|
| 7502 |
function parseEndTag (tagName, start, end) { |
| 7503 |
var pos, lowerCasedTagName; |
| 7504 |
if (start == null) { start = index; } |
| 7505 |
if (end == null) { end = index; } |
| 7506 |
|
| 7507 |
if (tagName) { |
| 7508 |
lowerCasedTagName = tagName.toLowerCase(); |
| 7509 |
} |
| 7510 |
|
| 7511 |
// Find the closest opened tag of the same type |
| 7512 |
if (tagName) { |
| 7513 |
for (pos = stack.length - 1; pos >= 0; pos--) { |
| 7514 |
if (stack[pos].lowerCasedTag === lowerCasedTagName) { |
| 7515 |
break |
| 7516 |
} |
| 7517 |
} |
| 7518 |
} else { |
| 7519 |
// If no tag name is provided, clean shop |
| 7520 |
pos = 0; |
| 7521 |
} |
| 7522 |
|
| 7523 |
if (pos >= 0) { |
| 7524 |
// Close all the open elements, up the stack |
| 7525 |
for (var i = stack.length - 1; i >= pos; i--) { |
| 7526 |
if ("development" !== 'production' && |
| 7527 |
(i > pos || !tagName) && |
| 7528 |
options.warn) { |
| 7529 |
options.warn( |
| 7530 |
("tag <" + (stack[i].tag) + "> has no matching end tag.") |
| 7531 |
); |
| 7532 |
} |
| 7533 |
if (options.end) { |
| 7534 |
options.end(stack[i].tag, start, end); |
| 7535 |
} |
| 7536 |
} |
| 7537 |
|
| 7538 |
// Remove the open elements from the stack |
| 7539 |
stack.length = pos; |
| 7540 |
lastTag = pos && stack[pos - 1].tag; |
| 7541 |
} else if (lowerCasedTagName === 'br') { |
| 7542 |
if (options.start) { |
| 7543 |
options.start(tagName, [], true, start, end); |
| 7544 |
} |
| 7545 |
} else if (lowerCasedTagName === 'p') { |
| 7546 |
if (options.start) { |
| 7547 |
options.start(tagName, [], false, start, end); |
| 7548 |
} |
| 7549 |
if (options.end) { |
| 7550 |
options.end(tagName, start, end); |
| 7551 |
} |
| 7552 |
} |
| 7553 |
} |
| 7554 |
} |
| 7555 |
|
| 7556 |
/* */ |
| 7557 |
|
| 7558 |
var defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g; |
| 7559 |
var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g; |
| 7560 |
|
| 7561 |
var buildRegex = cached(function (delimiters) { |
| 7562 |
var open = delimiters[0].replace(regexEscapeRE, '\\$&'); |
| 7563 |
var close = delimiters[1].replace(regexEscapeRE, '\\$&'); |
| 7564 |
return new RegExp(open + '((?:.|\\n)+?)' + close, 'g') |
| 7565 |
}); |
| 7566 |
|
| 7567 |
function parseText ( |
| 7568 |
text, |
| 7569 |
delimiters |
| 7570 |
) { |
| 7571 |
var tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE; |
| 7572 |
if (!tagRE.test(text)) { |
| 7573 |
return |
| 7574 |
} |
| 7575 |
var tokens = []; |
| 7576 |
var lastIndex = tagRE.lastIndex = 0; |
| 7577 |
var match, index; |
| 7578 |
while ((match = tagRE.exec(text))) { |
| 7579 |
index = match.index; |
| 7580 |
// push text token |
| 7581 |
if (index > lastIndex) { |
| 7582 |
tokens.push(JSON.stringify(text.slice(lastIndex, index))); |
| 7583 |
} |
| 7584 |
// tag token |
| 7585 |
var exp = parseFilters(match[1].trim()); |
| 7586 |
tokens.push(("_s(" + exp + ")")); |
| 7587 |
lastIndex = index + match[0].length; |
| 7588 |
} |
| 7589 |
if (lastIndex < text.length) { |
| 7590 |
tokens.push(JSON.stringify(text.slice(lastIndex))); |
| 7591 |
} |
| 7592 |
return tokens.join('+') |
| 7593 |
} |
| 7594 |
|
| 7595 |
/* */ |
| 7596 |
|
| 7597 |
var onRE = /^@|^v-on:/; |
| 7598 |
var dirRE = /^v-|^@|^:/; |
| 7599 |
var forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/; |
| 7600 |
var forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/; |
| 7601 |
|
| 7602 |
var argRE = /:(.*)$/; |
| 7603 |
var bindRE = /^:|^v-bind:/; |
| 7604 |
var modifierRE = /\.[^.]+/g; |
| 7605 |
|
| 7606 |
var decodeHTMLCached = cached(decode); |
| 7607 |
|
| 7608 |
// configurable state |
| 7609 |
var warn$2; |
| 7610 |
var delimiters; |
| 7611 |
var transforms; |
| 7612 |
var preTransforms; |
| 7613 |
var postTransforms; |
| 7614 |
var platformIsPreTag; |
| 7615 |
var platformMustUseProp; |
| 7616 |
var platformGetTagNamespace; |
| 7617 |
|
| 7618 |
/** |
| 7619 |
* Convert HTML string to AST. |
| 7620 |
*/ |
| 7621 |
function parse ( |
| 7622 |
template, |
| 7623 |
options |
| 7624 |
) { |
| 7625 |
warn$2 = options.warn || baseWarn; |
| 7626 |
platformGetTagNamespace = options.getTagNamespace || no; |
| 7627 |
platformMustUseProp = options.mustUseProp || no; |
| 7628 |
platformIsPreTag = options.isPreTag || no; |
| 7629 |
preTransforms = pluckModuleFunction(options.modules, 'preTransformNode'); |
| 7630 |
transforms = pluckModuleFunction(options.modules, 'transformNode'); |
| 7631 |
postTransforms = pluckModuleFunction(options.modules, 'postTransformNode'); |
| 7632 |
delimiters = options.delimiters; |
| 7633 |
|
| 7634 |
var stack = []; |
| 7635 |
var preserveWhitespace = options.preserveWhitespace !== false; |
| 7636 |
var root; |
| 7637 |
var currentParent; |
| 7638 |
var inVPre = false; |
| 7639 |
var inPre = false; |
| 7640 |
var warned = false; |
| 7641 |
|
| 7642 |
function warnOnce (msg) { |
| 7643 |
if (!warned) { |
| 7644 |
warned = true; |
| 7645 |
warn$2(msg); |
| 7646 |
} |
| 7647 |
} |
| 7648 |
|
| 7649 |
function endPre (element) { |
| 7650 |
// check pre state |
| 7651 |
if (element.pre) { |
| 7652 |
inVPre = false; |
| 7653 |
} |
| 7654 |
if (platformIsPreTag(element.tag)) { |
| 7655 |
inPre = false; |
| 7656 |
} |
| 7657 |
} |
| 7658 |
|
| 7659 |
parseHTML(template, { |
| 7660 |
warn: warn$2, |
| 7661 |
expectHTML: options.expectHTML, |
| 7662 |
isUnaryTag: options.isUnaryTag, |
| 7663 |
shouldDecodeNewlines: options.shouldDecodeNewlines, |
| 7664 |
start: function start (tag, attrs, unary) { |
| 7665 |
// check namespace. |
| 7666 |
// inherit parent ns if there is one |
| 7667 |
var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag); |
| 7668 |
|
| 7669 |
// handle IE svg bug |
| 7670 |
/* istanbul ignore if */ |
| 7671 |
if (isIE && ns === 'svg') { |
| 7672 |
attrs = guardIESVGBug(attrs); |
| 7673 |
} |
| 7674 |
|
| 7675 |
var element = { |
| 7676 |
type: 1, |
| 7677 |
tag: tag, |
| 7678 |
attrsList: attrs, |
| 7679 |
attrsMap: makeAttrsMap(attrs), |
| 7680 |
parent: currentParent, |
| 7681 |
children: [] |
| 7682 |
}; |
| 7683 |
if (ns) { |
| 7684 |
element.ns = ns; |
| 7685 |
} |
| 7686 |
|
| 7687 |
if (isForbiddenTag(element) && !isServerRendering()) { |
| 7688 |
element.forbidden = true; |
| 7689 |
"development" !== 'production' && warn$2( |
| 7690 |
'Templates should only be responsible for mapping the state to the ' + |
| 7691 |
'UI. Avoid placing tags with side-effects in your templates, such as ' + |
| 7692 |
"<" + tag + ">" + ', as they will not be parsed.' |
| 7693 |
); |
| 7694 |
} |
| 7695 |
|
| 7696 |
// apply pre-transforms |
| 7697 |
for (var i = 0; i < preTransforms.length; i++) { |
| 7698 |
preTransforms[i](element, options); |
| 7699 |
} |
| 7700 |
|
| 7701 |
if (!inVPre) { |
| 7702 |
processPre(element); |
| 7703 |
if (element.pre) { |
| 7704 |
inVPre = true; |
| 7705 |
} |
| 7706 |
} |
| 7707 |
if (platformIsPreTag(element.tag)) { |
| 7708 |
inPre = true; |
| 7709 |
} |
| 7710 |
if (inVPre) { |
| 7711 |
processRawAttrs(element); |
| 7712 |
} else { |
| 7713 |
processFor(element); |
| 7714 |
processIf(element); |
| 7715 |
processOnce(element); |
| 7716 |
processKey(element); |
| 7717 |
|
| 7718 |
// determine whether this is a plain element after |
| 7719 |
// removing structural attributes |
| 7720 |
element.plain = !element.key && !attrs.length; |
| 7721 |
|
| 7722 |
processRef(element); |
| 7723 |
processSlot(element); |
| 7724 |
processComponent(element); |
| 7725 |
for (var i$1 = 0; i$1 < transforms.length; i$1++) { |
| 7726 |
transforms[i$1](element, options); |
| 7727 |
} |
| 7728 |
processAttrs(element); |
| 7729 |
} |
| 7730 |
|
| 7731 |
function checkRootConstraints (el) { |
| 7732 |
{ |
| 7733 |
if (el.tag === 'slot' || el.tag === 'template') { |
| 7734 |
warnOnce( |
| 7735 |
"Cannot use <" + (el.tag) + "> as component root element because it may " + |
| 7736 |
'contain multiple nodes.' |
| 7737 |
); |
| 7738 |
} |
| 7739 |
if (el.attrsMap.hasOwnProperty('v-for')) { |
| 7740 |
warnOnce( |
| 7741 |
'Cannot use v-for on stateful component root element because ' + |
| 7742 |
'it renders multiple elements.' |
| 7743 |
); |
| 7744 |
} |
| 7745 |
} |
| 7746 |
} |
| 7747 |
|
| 7748 |
// tree management |
| 7749 |
if (!root) { |
| 7750 |
root = element; |
| 7751 |
checkRootConstraints(root); |
| 7752 |
} else if (!stack.length) { |
| 7753 |
// allow root elements with v-if, v-else-if and v-else |
| 7754 |
if (root.if && (element.elseif || element.else)) { |
| 7755 |
checkRootConstraints(element); |
| 7756 |
addIfCondition(root, { |
| 7757 |
exp: element.elseif, |
| 7758 |
block: element |
| 7759 |
}); |
| 7760 |
} else { |
| 7761 |
warnOnce( |
| 7762 |
"Component template should contain exactly one root element. " + |
| 7763 |
"If you are using v-if on multiple elements, " + |
| 7764 |
"use v-else-if to chain them instead." |
| 7765 |
); |
| 7766 |
} |
| 7767 |
} |
| 7768 |
if (currentParent && !element.forbidden) { |
| 7769 |
if (element.elseif || element.else) { |
| 7770 |
processIfConditions(element, currentParent); |
| 7771 |
} else if (element.slotScope) { // scoped slot |
| 7772 |
currentParent.plain = false; |
| 7773 |
var name = element.slotTarget || '"default"';(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element; |
| 7774 |
} else { |
| 7775 |
currentParent.children.push(element); |
| 7776 |
element.parent = currentParent; |
| 7777 |
} |
| 7778 |
} |
| 7779 |
if (!unary) { |
| 7780 |
currentParent = element; |
| 7781 |
stack.push(element); |
| 7782 |
} else { |
| 7783 |
endPre(element); |
| 7784 |
} |
| 7785 |
// apply post-transforms |
| 7786 |
for (var i$2 = 0; i$2 < postTransforms.length; i$2++) { |
| 7787 |
postTransforms[i$2](element, options); |
| 7788 |
} |
| 7789 |
}, |
| 7790 |
|
| 7791 |
end: function end () { |
| 7792 |
// remove trailing whitespace |
| 7793 |
var element = stack[stack.length - 1]; |
| 7794 |
var lastNode = element.children[element.children.length - 1]; |
| 7795 |
if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) { |
| 7796 |
element.children.pop(); |
| 7797 |
} |
| 7798 |
// pop stack |
| 7799 |
stack.length -= 1; |
| 7800 |
currentParent = stack[stack.length - 1]; |
| 7801 |
endPre(element); |
| 7802 |
}, |
| 7803 |
|
| 7804 |
chars: function chars (text) { |
| 7805 |
if (!currentParent) { |
| 7806 |
{ |
| 7807 |
if (text === template) { |
| 7808 |
warnOnce( |
| 7809 |
'Component template requires a root element, rather than just text.' |
| 7810 |
); |
| 7811 |
} else if ((text = text.trim())) { |
| 7812 |
warnOnce( |
| 7813 |
("text \"" + text + "\" outside root element will be ignored.") |
| 7814 |
); |
| 7815 |
} |
| 7816 |
} |
| 7817 |
return |
| 7818 |
} |
| 7819 |
// IE textarea placeholder bug |
| 7820 |
/* istanbul ignore if */ |
| 7821 |
if (isIE && |
| 7822 |
currentParent.tag === 'textarea' && |
| 7823 |
currentParent.attrsMap.placeholder === text) { |
| 7824 |
return |
| 7825 |
} |
| 7826 |
var children = currentParent.children; |
| 7827 |
text = inPre || text.trim() |
| 7828 |
? decodeHTMLCached(text) |
| 7829 |
// only preserve whitespace if its not right after a starting tag |
| 7830 |
: preserveWhitespace && children.length ? ' ' : ''; |
| 7831 |
if (text) { |
| 7832 |
var expression; |
| 7833 |
if (!inVPre && text !== ' ' && (expression = parseText(text, delimiters))) { |
| 7834 |
children.push({ |
| 7835 |
type: 2, |
| 7836 |
expression: expression, |
| 7837 |
text: text |
| 7838 |
}); |
| 7839 |
} else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') { |
| 7840 |
children.push({ |
| 7841 |
type: 3, |
| 7842 |
text: text |
| 7843 |
}); |
| 7844 |
} |
| 7845 |
} |
| 7846 |
} |
| 7847 |
}); |
| 7848 |
return root |
| 7849 |
} |
| 7850 |
|
| 7851 |
function processPre (el) { |
| 7852 |
if (getAndRemoveAttr(el, 'v-pre') != null) { |
| 7853 |
el.pre = true; |
| 7854 |
} |
| 7855 |
} |
| 7856 |
|
| 7857 |
function processRawAttrs (el) { |
| 7858 |
var l = el.attrsList.length; |
| 7859 |
if (l) { |
| 7860 |
var attrs = el.attrs = new Array(l); |
| 7861 |
for (var i = 0; i < l; i++) { |
| 7862 |
attrs[i] = { |
| 7863 |
name: el.attrsList[i].name, |
| 7864 |
value: JSON.stringify(el.attrsList[i].value) |
| 7865 |
}; |
| 7866 |
} |
| 7867 |
} else if (!el.pre) { |
| 7868 |
// non root node in pre blocks with no attributes |
| 7869 |
el.plain = true; |
| 7870 |
} |
| 7871 |
} |
| 7872 |
|
| 7873 |
function processKey (el) { |
| 7874 |
var exp = getBindingAttr(el, 'key'); |
| 7875 |
if (exp) { |
| 7876 |
if ("development" !== 'production' && el.tag === 'template') { |
| 7877 |
warn$2("<template> cannot be keyed. Place the key on real elements instead."); |
| 7878 |
} |
| 7879 |
el.key = exp; |
| 7880 |
} |
| 7881 |
} |
| 7882 |
|
| 7883 |
function processRef (el) { |
| 7884 |
var ref = getBindingAttr(el, 'ref'); |
| 7885 |
if (ref) { |
| 7886 |
el.ref = ref; |
| 7887 |
el.refInFor = checkInFor(el); |
| 7888 |
} |
| 7889 |
} |
| 7890 |
|
| 7891 |
function processFor (el) { |
| 7892 |
var exp; |
| 7893 |
if ((exp = getAndRemoveAttr(el, 'v-for'))) { |
| 7894 |
var inMatch = exp.match(forAliasRE); |
| 7895 |
if (!inMatch) { |
| 7896 |
"development" !== 'production' && warn$2( |
| 7897 |
("Invalid v-for expression: " + exp) |
| 7898 |
); |
| 7899 |
return |
| 7900 |
} |
| 7901 |
el.for = inMatch[2].trim(); |
| 7902 |
var alias = inMatch[1].trim(); |
| 7903 |
var iteratorMatch = alias.match(forIteratorRE); |
| 7904 |
if (iteratorMatch) { |
| 7905 |
el.alias = iteratorMatch[1].trim(); |
| 7906 |
el.iterator1 = iteratorMatch[2].trim(); |
| 7907 |
if (iteratorMatch[3]) { |
| 7908 |
el.iterator2 = iteratorMatch[3].trim(); |
| 7909 |
} |
| 7910 |
} else { |
| 7911 |
el.alias = alias; |
| 7912 |
} |
| 7913 |
} |
| 7914 |
} |
| 7915 |
|
| 7916 |
function processIf (el) { |
| 7917 |
var exp = getAndRemoveAttr(el, 'v-if'); |
| 7918 |
if (exp) { |
| 7919 |
el.if = exp; |
| 7920 |
addIfCondition(el, { |
| 7921 |
exp: exp, |
| 7922 |
block: el |
| 7923 |
}); |
| 7924 |
} else { |
| 7925 |
if (getAndRemoveAttr(el, 'v-else') != null) { |
| 7926 |
el.else = true; |
| 7927 |
} |
| 7928 |
var elseif = getAndRemoveAttr(el, 'v-else-if'); |
| 7929 |
if (elseif) { |
| 7930 |
el.elseif = elseif; |
| 7931 |
} |
| 7932 |
} |
| 7933 |
} |
| 7934 |
|
| 7935 |
function processIfConditions (el, parent) { |
| 7936 |
var prev = findPrevElement(parent.children); |
| 7937 |
if (prev && prev.if) { |
| 7938 |
addIfCondition(prev, { |
| 7939 |
exp: el.elseif, |
| 7940 |
block: el |
| 7941 |
}); |
| 7942 |
} else { |
| 7943 |
warn$2( |
| 7944 |
"v-" + (el.elseif ? ('else-if="' + el.elseif + '"') : 'else') + " " + |
| 7945 |
"used on element <" + (el.tag) + "> without corresponding v-if." |
| 7946 |
); |
| 7947 |
} |
| 7948 |
} |
| 7949 |
|
| 7950 |
function findPrevElement (children) { |
| 7951 |
var i = children.length; |
| 7952 |
while (i--) { |
| 7953 |
if (children[i].type === 1) { |
| 7954 |
return children[i] |
| 7955 |
} else { |
| 7956 |
if ("development" !== 'production' && children[i].text !== ' ') { |
| 7957 |
warn$2( |
| 7958 |
"text \"" + (children[i].text.trim()) + "\" between v-if and v-else(-if) " + |
| 7959 |
"will be ignored." |
| 7960 |
); |
| 7961 |
} |
| 7962 |
children.pop(); |
| 7963 |
} |
| 7964 |
} |
| 7965 |
} |
| 7966 |
|
| 7967 |
function addIfCondition (el, condition) { |
| 7968 |
if (!el.ifConditions) { |
| 7969 |
el.ifConditions = []; |
| 7970 |
} |
| 7971 |
el.ifConditions.push(condition); |
| 7972 |
} |
| 7973 |
|
| 7974 |
function processOnce (el) { |
| 7975 |
var once$$1 = getAndRemoveAttr(el, 'v-once'); |
| 7976 |
if (once$$1 != null) { |
| 7977 |
el.once = true; |
| 7978 |
} |
| 7979 |
} |
| 7980 |
|
| 7981 |
function processSlot (el) { |
| 7982 |
if (el.tag === 'slot') { |
| 7983 |
el.slotName = getBindingAttr(el, 'name'); |
| 7984 |
if ("development" !== 'production' && el.key) { |
| 7985 |
warn$2( |
| 7986 |
"`key` does not work on <slot> because slots are abstract outlets " + |
| 7987 |
"and can possibly expand into multiple elements. " + |
| 7988 |
"Use the key on a wrapping element instead." |
| 7989 |
); |
| 7990 |
} |
| 7991 |
} else { |
| 7992 |
var slotTarget = getBindingAttr(el, 'slot'); |
| 7993 |
if (slotTarget) { |
| 7994 |
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget; |
| 7995 |
} |
| 7996 |
if (el.tag === 'template') { |
| 7997 |
el.slotScope = getAndRemoveAttr(el, 'scope'); |
| 7998 |
} |
| 7999 |
} |
| 8000 |
} |
| 8001 |
|
| 8002 |
function processComponent (el) { |
| 8003 |
var binding; |
| 8004 |
if ((binding = getBindingAttr(el, 'is'))) { |
| 8005 |
el.component = binding; |
| 8006 |
} |
| 8007 |
if (getAndRemoveAttr(el, 'inline-template') != null) { |
| 8008 |
el.inlineTemplate = true; |
| 8009 |
} |
| 8010 |
} |
| 8011 |
|
| 8012 |
function processAttrs (el) { |
| 8013 |
var list = el.attrsList; |
| 8014 |
var i, l, name, rawName, value, modifiers, isProp; |
| 8015 |
for (i = 0, l = list.length; i < l; i++) { |
| 8016 |
name = rawName = list[i].name; |
| 8017 |
value = list[i].value; |
| 8018 |
if (dirRE.test(name)) { |
| 8019 |
// mark element as dynamic |
| 8020 |
el.hasBindings = true; |
| 8021 |
// modifiers |
| 8022 |
modifiers = parseModifiers(name); |
| 8023 |
if (modifiers) { |
| 8024 |
name = name.replace(modifierRE, ''); |
| 8025 |
} |
| 8026 |
if (bindRE.test(name)) { // v-bind |
| 8027 |
name = name.replace(bindRE, ''); |
| 8028 |
value = parseFilters(value); |
| 8029 |
isProp = false; |
| 8030 |
if (modifiers) { |
| 8031 |
if (modifiers.prop) { |
| 8032 |
isProp = true; |
| 8033 |
name = camelize(name); |
| 8034 |
if (name === 'innerHtml') { name = 'innerHTML'; } |
| 8035 |
} |
| 8036 |
if (modifiers.camel) { |
| 8037 |
name = camelize(name); |
| 8038 |
} |
| 8039 |
} |
| 8040 |
if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) { |
| 8041 |
addProp(el, name, value); |
| 8042 |
} else { |
| 8043 |
addAttr(el, name, value); |
| 8044 |
} |
| 8045 |
} else if (onRE.test(name)) { // v-on |
| 8046 |
name = name.replace(onRE, ''); |
| 8047 |
addHandler(el, name, value, modifiers); |
| 8048 |
} else { // normal directives |
| 8049 |
name = name.replace(dirRE, ''); |
| 8050 |
// parse arg |
| 8051 |
var argMatch = name.match(argRE); |
| 8052 |
var arg = argMatch && argMatch[1]; |
| 8053 |
if (arg) { |
| 8054 |
name = name.slice(0, -(arg.length + 1)); |
| 8055 |
} |
| 8056 |
addDirective(el, name, rawName, value, arg, modifiers); |
| 8057 |
if ("development" !== 'production' && name === 'model') { |
| 8058 |
checkForAliasModel(el, value); |
| 8059 |
} |
| 8060 |
} |
| 8061 |
} else { |
| 8062 |
// literal attribute |
| 8063 |
{ |
| 8064 |
var expression = parseText(value, delimiters); |
| 8065 |
if (expression) { |
| 8066 |
warn$2( |
| 8067 |
name + "=\"" + value + "\": " + |
| 8068 |
'Interpolation inside attributes has been removed. ' + |
| 8069 |
'Use v-bind or the colon shorthand instead. For example, ' + |
| 8070 |
'instead of <div id="{{ val }}">, use <div :id="val">.' |
| 8071 |
); |
| 8072 |
} |
| 8073 |
} |
| 8074 |
addAttr(el, name, JSON.stringify(value)); |
| 8075 |
} |
| 8076 |
} |
| 8077 |
} |
| 8078 |
|
| 8079 |
function checkInFor (el) { |
| 8080 |
var parent = el; |
| 8081 |
while (parent) { |
| 8082 |
if (parent.for !== undefined) { |
| 8083 |
return true |
| 8084 |
} |
| 8085 |
parent = parent.parent; |
| 8086 |
} |
| 8087 |
return false |
| 8088 |
} |
| 8089 |
|
| 8090 |
function parseModifiers (name) { |
| 8091 |
var match = name.match(modifierRE); |
| 8092 |
if (match) { |
| 8093 |
var ret = {}; |
| 8094 |
match.forEach(function (m) { ret[m.slice(1)] = true; }); |
| 8095 |
return ret |
| 8096 |
} |
| 8097 |
} |
| 8098 |
|
| 8099 |
function makeAttrsMap (attrs) { |
| 8100 |
var map = {}; |
| 8101 |
for (var i = 0, l = attrs.length; i < l; i++) { |
| 8102 |
if ("development" !== 'production' && map[attrs[i].name] && !isIE) { |
| 8103 |
warn$2('duplicate attribute: ' + attrs[i].name); |
| 8104 |
} |
| 8105 |
map[attrs[i].name] = attrs[i].value; |
| 8106 |
} |
| 8107 |
return map |
| 8108 |
} |
| 8109 |
|
| 8110 |
function isForbiddenTag (el) { |
| 8111 |
return ( |
| 8112 |
el.tag === 'style' || |
| 8113 |
(el.tag === 'script' && ( |
| 8114 |
!el.attrsMap.type || |
| 8115 |
el.attrsMap.type === 'text/javascript' |
| 8116 |
)) |
| 8117 |
) |
| 8118 |
} |
| 8119 |
|
| 8120 |
var ieNSBug = /^xmlns:NS\d+/; |
| 8121 |
var ieNSPrefix = /^NS\d+:/; |
| 8122 |
|
| 8123 |
/* istanbul ignore next */ |
| 8124 |
function guardIESVGBug (attrs) { |
| 8125 |
var res = []; |
| 8126 |
for (var i = 0; i < attrs.length; i++) { |
| 8127 |
var attr = attrs[i]; |
| 8128 |
if (!ieNSBug.test(attr.name)) { |
| 8129 |
attr.name = attr.name.replace(ieNSPrefix, ''); |
| 8130 |
res.push(attr); |
| 8131 |
} |
| 8132 |
} |
| 8133 |
return res |
| 8134 |
} |
| 8135 |
|
| 8136 |
function checkForAliasModel (el, value) { |
| 8137 |
var _el = el; |
| 8138 |
while (_el) { |
| 8139 |
if (_el.for && _el.alias === value) { |
| 8140 |
warn$2( |
| 8141 |
"<" + (el.tag) + " v-model=\"" + value + "\">: " + |
| 8142 |
"You are binding v-model directly to a v-for iteration alias. " + |
| 8143 |
"This will not be able to modify the v-for source array because " + |
| 8144 |
"writing to the alias is like modifying a function local variable. " + |
| 8145 |
"Consider using an array of objects and use v-model on an object property instead." |
| 8146 |
); |
| 8147 |
} |
| 8148 |
_el = _el.parent; |
| 8149 |
} |
| 8150 |
} |
| 8151 |
|
| 8152 |
/* */ |
| 8153 |
|
| 8154 |
var isStaticKey; |
| 8155 |
var isPlatformReservedTag; |
| 8156 |
|
| 8157 |
var genStaticKeysCached = cached(genStaticKeys$1); |
| 8158 |
|
| 8159 |
/** |
| 8160 |
* Goal of the optimizer: walk the generated template AST tree |
| 8161 |
* and detect sub-trees that are purely static, i.e. parts of |
| 8162 |
* the DOM that never needs to change. |
| 8163 |
* |
| 8164 |
* Once we detect these sub-trees, we can: |
| 8165 |
* |
| 8166 |
* 1. Hoist them into constants, so that we no longer need to |
| 8167 |
* create fresh nodes for them on each re-render; |
| 8168 |
* 2. Completely skip them in the patching process. |
| 8169 |
*/ |
| 8170 |
function optimize (root, options) { |
| 8171 |
if (!root) { return } |
| 8172 |
isStaticKey = genStaticKeysCached(options.staticKeys || ''); |
| 8173 |
isPlatformReservedTag = options.isReservedTag || no; |
| 8174 |
// first pass: mark all non-static nodes. |
| 8175 |
markStatic$1(root); |
| 8176 |
// second pass: mark static roots. |
| 8177 |
markStaticRoots(root, false); |
| 8178 |
} |
| 8179 |
|
| 8180 |
function genStaticKeys$1 (keys) { |
| 8181 |
return makeMap( |
| 8182 |
'type,tag,attrsList,attrsMap,plain,parent,children,attrs' + |
| 8183 |
(keys ? ',' + keys : '') |
| 8184 |
) |
| 8185 |
} |
| 8186 |
|
| 8187 |
function markStatic$1 (node) { |
| 8188 |
node.static = isStatic(node); |
| 8189 |
if (node.type === 1) { |
| 8190 |
// do not make component slot content static. this avoids |
| 8191 |
// 1. components not able to mutate slot nodes |
| 8192 |
// 2. static slot content fails for hot-reloading |
| 8193 |
if ( |
| 8194 |
!isPlatformReservedTag(node.tag) && |
| 8195 |
node.tag !== 'slot' && |
| 8196 |
node.attrsMap['inline-template'] == null |
| 8197 |
) { |
| 8198 |
return |
| 8199 |
} |
| 8200 |
for (var i = 0, l = node.children.length; i < l; i++) { |
| 8201 |
var child = node.children[i]; |
| 8202 |
markStatic$1(child); |
| 8203 |
if (!child.static) { |
| 8204 |
node.static = false; |
| 8205 |
} |
| 8206 |
} |
| 8207 |
} |
| 8208 |
} |
| 8209 |
|
| 8210 |
function markStaticRoots (node, isInFor) { |
| 8211 |
if (node.type === 1) { |
| 8212 |
if (node.static || node.once) { |
| 8213 |
node.staticInFor = isInFor; |
| 8214 |
} |
| 8215 |
// For a node to qualify as a static root, it should have children that |
| 8216 |
// are not just static text. Otherwise the cost of hoisting out will |
| 8217 |
// outweigh the benefits and it's better off to just always render it fresh. |
| 8218 |
if (node.static && node.children.length && !( |
| 8219 |
node.children.length === 1 && |
| 8220 |
node.children[0].type === 3 |
| 8221 |
)) { |
| 8222 |
node.staticRoot = true; |
| 8223 |
return |
| 8224 |
} else { |
| 8225 |
node.staticRoot = false; |
| 8226 |
} |
| 8227 |
if (node.children) { |
| 8228 |
for (var i = 0, l = node.children.length; i < l; i++) { |
| 8229 |
markStaticRoots(node.children[i], isInFor || !!node.for); |
| 8230 |
} |
| 8231 |
} |
| 8232 |
if (node.ifConditions) { |
| 8233 |
walkThroughConditionsBlocks(node.ifConditions, isInFor); |
| 8234 |
} |
| 8235 |
} |
| 8236 |
} |
| 8237 |
|
| 8238 |
function walkThroughConditionsBlocks (conditionBlocks, isInFor) { |
| 8239 |
for (var i = 1, len = conditionBlocks.length; i < len; i++) { |
| 8240 |
markStaticRoots(conditionBlocks[i].block, isInFor); |
| 8241 |
} |
| 8242 |
} |
| 8243 |
|
| 8244 |
function isStatic (node) { |
| 8245 |
if (node.type === 2) { // expression |
| 8246 |
return false |
| 8247 |
} |
| 8248 |
if (node.type === 3) { // text |
| 8249 |
return true |
| 8250 |
} |
| 8251 |
return !!(node.pre || ( |
| 8252 |
!node.hasBindings && // no dynamic bindings |
| 8253 |
!node.if && !node.for && // not v-if or v-for or v-else |
| 8254 |
!isBuiltInTag(node.tag) && // not a built-in |
| 8255 |
isPlatformReservedTag(node.tag) && // not a component |
| 8256 |
!isDirectChildOfTemplateFor(node) && |
| 8257 |
Object.keys(node).every(isStaticKey) |
| 8258 |
)) |
| 8259 |
} |
| 8260 |
|
| 8261 |
function isDirectChildOfTemplateFor (node) { |
| 8262 |
while (node.parent) { |
| 8263 |
node = node.parent; |
| 8264 |
if (node.tag !== 'template') { |
| 8265 |
return false |
| 8266 |
} |
| 8267 |
if (node.for) { |
| 8268 |
return true |
| 8269 |
} |
| 8270 |
} |
| 8271 |
return false |
| 8272 |
} |
| 8273 |
|
| 8274 |
/* */ |
| 8275 |
|
| 8276 |
var fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/; |
| 8277 |
var simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/; |
| 8278 |
|
| 8279 |
// keyCode aliases |
| 8280 |
var keyCodes = { |
| 8281 |
esc: 27, |
| 8282 |
tab: 9, |
| 8283 |
enter: 13, |
| 8284 |
space: 32, |
| 8285 |
up: 38, |
| 8286 |
left: 37, |
| 8287 |
right: 39, |
| 8288 |
down: 40, |
| 8289 |
'delete': [8, 46] |
| 8290 |
}; |
| 8291 |
|
| 8292 |
// #4868: modifiers that prevent the execution of the listener |
| 8293 |
// need to explicitly return null so that we can determine whether to remove |
| 8294 |
// the listener for .once |
| 8295 |
var genGuard = function (condition) { return ("if(" + condition + ")return null;"); }; |
| 8296 |
|
| 8297 |
var modifierCode = { |
| 8298 |
stop: '$event.stopPropagation();', |
| 8299 |
prevent: '$event.preventDefault();', |
| 8300 |
self: genGuard("$event.target !== $event.currentTarget"), |
| 8301 |
ctrl: genGuard("!$event.ctrlKey"), |
| 8302 |
shift: genGuard("!$event.shiftKey"), |
| 8303 |
alt: genGuard("!$event.altKey"), |
| 8304 |
meta: genGuard("!$event.metaKey"), |
| 8305 |
left: genGuard("'button' in $event && $event.button !== 0"), |
| 8306 |
middle: genGuard("'button' in $event && $event.button !== 1"), |
| 8307 |
right: genGuard("'button' in $event && $event.button !== 2") |
| 8308 |
}; |
| 8309 |
|
| 8310 |
function genHandlers (events, native) { |
| 8311 |
var res = native ? 'nativeOn:{' : 'on:{'; |
| 8312 |
for (var name in events) { |
| 8313 |
res += "\"" + name + "\":" + (genHandler(name, events[name])) + ","; |
| 8314 |
} |
| 8315 |
return res.slice(0, -1) + '}' |
| 8316 |
} |
| 8317 |
|
| 8318 |
function genHandler ( |
| 8319 |
name, |
| 8320 |
handler |
| 8321 |
) { |
| 8322 |
if (!handler) { |
| 8323 |
return 'function(){}' |
| 8324 |
} |
| 8325 |
|
| 8326 |
if (Array.isArray(handler)) { |
| 8327 |
return ("[" + (handler.map(function (handler) { return genHandler(name, handler); }).join(',')) + "]") |
| 8328 |
} |
| 8329 |
|
| 8330 |
var isMethodPath = simplePathRE.test(handler.value); |
| 8331 |
var isFunctionExpression = fnExpRE.test(handler.value); |
| 8332 |
|
| 8333 |
if (!handler.modifiers) { |
| 8334 |
return isMethodPath || isFunctionExpression |
| 8335 |
? handler.value |
| 8336 |
: ("function($event){" + (handler.value) + "}") // inline statement |
| 8337 |
} else { |
| 8338 |
var code = ''; |
| 8339 |
var genModifierCode = ''; |
| 8340 |
var keys = []; |
| 8341 |
for (var key in handler.modifiers) { |
| 8342 |
if (modifierCode[key]) { |
| 8343 |
genModifierCode += modifierCode[key]; |
| 8344 |
// left/right |
| 8345 |
if (keyCodes[key]) { |
| 8346 |
keys.push(key); |
| 8347 |
} |
| 8348 |
} else { |
| 8349 |
keys.push(key); |
| 8350 |
} |
| 8351 |
} |
| 8352 |
if (keys.length) { |
| 8353 |
code += genKeyFilter(keys); |
| 8354 |
} |
| 8355 |
// Make sure modifiers like prevent and stop get executed after key filtering |
| 8356 |
if (genModifierCode) { |
| 8357 |
code += genModifierCode; |
| 8358 |
} |
| 8359 |
var handlerCode = isMethodPath |
| 8360 |
? handler.value + '($event)' |
| 8361 |
: isFunctionExpression |
| 8362 |
? ("(" + (handler.value) + ")($event)") |
| 8363 |
: handler.value; |
| 8364 |
return ("function($event){" + code + handlerCode + "}") |
| 8365 |
} |
| 8366 |
} |
| 8367 |
|
| 8368 |
function genKeyFilter (keys) { |
| 8369 |
return ("if(!('button' in $event)&&" + (keys.map(genFilterCode).join('&&')) + ")return null;") |
| 8370 |
} |
| 8371 |
|
| 8372 |
function genFilterCode (key) { |
| 8373 |
var keyVal = parseInt(key, 10); |
| 8374 |
if (keyVal) { |
| 8375 |
return ("$event.keyCode!==" + keyVal) |
| 8376 |
} |
| 8377 |
var alias = keyCodes[key]; |
| 8378 |
return ("_k($event.keyCode," + (JSON.stringify(key)) + (alias ? ',' + JSON.stringify(alias) : '') + ")") |
| 8379 |
} |
| 8380 |
|
| 8381 |
/* */ |
| 8382 |
|
| 8383 |
function bind$1 (el, dir) { |
| 8384 |
el.wrapData = function (code) { |
| 8385 |
return ("_b(" + code + ",'" + (el.tag) + "'," + (dir.value) + (dir.modifiers && dir.modifiers.prop ? ',true' : '') + ")") |
| 8386 |
}; |
| 8387 |
} |
| 8388 |
|
| 8389 |
/* */ |
| 8390 |
|
| 8391 |
var baseDirectives = { |
| 8392 |
bind: bind$1, |
| 8393 |
cloak: noop |
| 8394 |
}; |
| 8395 |
|
| 8396 |
/* */ |
| 8397 |
|
| 8398 |
// configurable state |
| 8399 |
var warn$3; |
| 8400 |
var transforms$1; |
| 8401 |
var dataGenFns; |
| 8402 |
var platformDirectives$1; |
| 8403 |
var isPlatformReservedTag$1; |
| 8404 |
var staticRenderFns; |
| 8405 |
var onceCount; |
| 8406 |
var currentOptions; |
| 8407 |
|
| 8408 |
function generate ( |
| 8409 |
ast, |
| 8410 |
options |
| 8411 |
) { |
| 8412 |
// save previous staticRenderFns so generate calls can be nested |
| 8413 |
var prevStaticRenderFns = staticRenderFns; |
| 8414 |
var currentStaticRenderFns = staticRenderFns = []; |
| 8415 |
var prevOnceCount = onceCount; |
| 8416 |
onceCount = 0; |
| 8417 |
currentOptions = options; |
| 8418 |
warn$3 = options.warn || baseWarn; |
| 8419 |
transforms$1 = pluckModuleFunction(options.modules, 'transformCode'); |
| 8420 |
dataGenFns = pluckModuleFunction(options.modules, 'genData'); |
| 8421 |
platformDirectives$1 = options.directives || {}; |
| 8422 |
isPlatformReservedTag$1 = options.isReservedTag || no; |
| 8423 |
var code = ast ? genElement(ast) : '_c("div")'; |
| 8424 |
staticRenderFns = prevStaticRenderFns; |
| 8425 |
onceCount = prevOnceCount; |
| 8426 |
return { |
| 8427 |
render: ("with(this){return " + code + "}"), |
| 8428 |
staticRenderFns: currentStaticRenderFns |
| 8429 |
} |
| 8430 |
} |
| 8431 |
|
| 8432 |
function genElement (el) { |
| 8433 |
if (el.staticRoot && !el.staticProcessed) { |
| 8434 |
return genStatic(el) |
| 8435 |
} else if (el.once && !el.onceProcessed) { |
| 8436 |
return genOnce(el) |
| 8437 |
} else if (el.for && !el.forProcessed) { |
| 8438 |
return genFor(el) |
| 8439 |
} else if (el.if && !el.ifProcessed) { |
| 8440 |
return genIf(el) |
| 8441 |
} else if (el.tag === 'template' && !el.slotTarget) { |
| 8442 |
return genChildren(el) || 'void 0' |
| 8443 |
} else if (el.tag === 'slot') { |
| 8444 |
return genSlot(el) |
| 8445 |
} else { |
| 8446 |
// component or element |
| 8447 |
var code; |
| 8448 |
if (el.component) { |
| 8449 |
code = genComponent(el.component, el); |
| 8450 |
} else { |
| 8451 |
var data = el.plain ? undefined : genData(el); |
| 8452 |
|
| 8453 |
var children = el.inlineTemplate ? null : genChildren(el, true); |
| 8454 |
code = "_c('" + (el.tag) + "'" + (data ? ("," + data) : '') + (children ? ("," + children) : '') + ")"; |
| 8455 |
} |
| 8456 |
// module transforms |
| 8457 |
for (var i = 0; i < transforms$1.length; i++) { |
| 8458 |
code = transforms$1[i](el, code); |
| 8459 |
} |
| 8460 |
return code |
| 8461 |
} |
| 8462 |
} |
| 8463 |
|
| 8464 |
// hoist static sub-trees out |
| 8465 |
function genStatic (el) { |
| 8466 |
el.staticProcessed = true; |
| 8467 |
staticRenderFns.push(("with(this){return " + (genElement(el)) + "}")); |
| 8468 |
return ("_m(" + (staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + ")") |
| 8469 |
} |
| 8470 |
|
| 8471 |
// v-once |
| 8472 |
function genOnce (el) { |
| 8473 |
el.onceProcessed = true; |
| 8474 |
if (el.if && !el.ifProcessed) { |
| 8475 |
return genIf(el) |
| 8476 |
} else if (el.staticInFor) { |
| 8477 |
var key = ''; |
| 8478 |
var parent = el.parent; |
| 8479 |
while (parent) { |
| 8480 |
if (parent.for) { |
| 8481 |
key = parent.key; |
| 8482 |
break |
| 8483 |
} |
| 8484 |
parent = parent.parent; |
| 8485 |
} |
| 8486 |
if (!key) { |
| 8487 |
"development" !== 'production' && warn$3( |
| 8488 |
"v-once can only be used inside v-for that is keyed. " |
| 8489 |
); |
| 8490 |
return genElement(el) |
| 8491 |
} |
| 8492 |
return ("_o(" + (genElement(el)) + "," + (onceCount++) + (key ? ("," + key) : "") + ")") |
| 8493 |
} else { |
| 8494 |
return genStatic(el) |
| 8495 |
} |
| 8496 |
} |
| 8497 |
|
| 8498 |
function genIf (el) { |
| 8499 |
el.ifProcessed = true; // avoid recursion |
| 8500 |
return genIfConditions(el.ifConditions.slice()) |
| 8501 |
} |
| 8502 |
|
| 8503 |
function genIfConditions (conditions) { |
| 8504 |
if (!conditions.length) { |
| 8505 |
return '_e()' |
| 8506 |
} |
| 8507 |
|
| 8508 |
var condition = conditions.shift(); |
| 8509 |
if (condition.exp) { |
| 8510 |
return ("(" + (condition.exp) + ")?" + (genTernaryExp(condition.block)) + ":" + (genIfConditions(conditions))) |
| 8511 |
} else { |
| 8512 |
return ("" + (genTernaryExp(condition.block))) |
| 8513 |
} |
| 8514 |
|
| 8515 |
// v-if with v-once should generate code like (a)?_m(0):_m(1) |
| 8516 |
function genTernaryExp (el) { |
| 8517 |
return el.once ? genOnce(el) : genElement(el) |
| 8518 |
} |
| 8519 |
} |
| 8520 |
|
| 8521 |
function genFor (el) { |
| 8522 |
var exp = el.for; |
| 8523 |
var alias = el.alias; |
| 8524 |
var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : ''; |
| 8525 |
var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : ''; |
| 8526 |
|
| 8527 |
if ( |
| 8528 |
"development" !== 'production' && |
| 8529 |
maybeComponent(el) && el.tag !== 'slot' && el.tag !== 'template' && !el.key |
| 8530 |
) { |
| 8531 |
warn$3( |
| 8532 |
"<" + (el.tag) + " v-for=\"" + alias + " in " + exp + "\">: component lists rendered with " + |
| 8533 |
"v-for should have explicit keys. " + |
| 8534 |
"See https://vuejs.org/guide/list.html#key for more info.", |
| 8535 |
true /* tip */ |
| 8536 |
); |
| 8537 |
} |
| 8538 |
|
| 8539 |
el.forProcessed = true; // avoid recursion |
| 8540 |
return "_l((" + exp + ")," + |
| 8541 |
"function(" + alias + iterator1 + iterator2 + "){" + |
| 8542 |
"return " + (genElement(el)) + |
| 8543 |
'})' |
| 8544 |
} |
| 8545 |
|
| 8546 |
function genData (el) { |
| 8547 |
var data = '{'; |
| 8548 |
|
| 8549 |
// directives first. |
| 8550 |
// directives may mutate the el's other properties before they are generated. |
| 8551 |
var dirs = genDirectives(el); |
| 8552 |
if (dirs) { data += dirs + ','; } |
| 8553 |
|
| 8554 |
// key |
| 8555 |
if (el.key) { |
| 8556 |
data += "key:" + (el.key) + ","; |
| 8557 |
} |
| 8558 |
// ref |
| 8559 |
if (el.ref) { |
| 8560 |
data += "ref:" + (el.ref) + ","; |
| 8561 |
} |
| 8562 |
if (el.refInFor) { |
| 8563 |
data += "refInFor:true,"; |
| 8564 |
} |
| 8565 |
// pre |
| 8566 |
if (el.pre) { |
| 8567 |
data += "pre:true,"; |
| 8568 |
} |
| 8569 |
// record original tag name for components using "is" attribute |
| 8570 |
if (el.component) { |
| 8571 |
data += "tag:\"" + (el.tag) + "\","; |
| 8572 |
} |
| 8573 |
// module data generation functions |
| 8574 |
for (var i = 0; i < dataGenFns.length; i++) { |
| 8575 |
data += dataGenFns[i](el); |
| 8576 |
} |
| 8577 |
// attributes |
| 8578 |
if (el.attrs) { |
| 8579 |
data += "attrs:{" + (genProps(el.attrs)) + "},"; |
| 8580 |
} |
| 8581 |
// DOM props |
| 8582 |
if (el.props) { |
| 8583 |
data += "domProps:{" + (genProps(el.props)) + "},"; |
| 8584 |
} |
| 8585 |
// event handlers |
| 8586 |
if (el.events) { |
| 8587 |
data += (genHandlers(el.events)) + ","; |
| 8588 |
} |
| 8589 |
if (el.nativeEvents) { |
| 8590 |
data += (genHandlers(el.nativeEvents, true)) + ","; |
| 8591 |
} |
| 8592 |
// slot target |
| 8593 |
if (el.slotTarget) { |
| 8594 |
data += "slot:" + (el.slotTarget) + ","; |
| 8595 |
} |
| 8596 |
// scoped slots |
| 8597 |
if (el.scopedSlots) { |
| 8598 |
data += (genScopedSlots(el.scopedSlots)) + ","; |
| 8599 |
} |
| 8600 |
// component v-model |
| 8601 |
if (el.model) { |
| 8602 |
data += "model:{value:" + (el.model.value) + ",callback:" + (el.model.callback) + ",expression:" + (el.model.expression) + "},"; |
| 8603 |
} |
| 8604 |
// inline-template |
| 8605 |
if (el.inlineTemplate) { |
| 8606 |
var inlineTemplate = genInlineTemplate(el); |
| 8607 |
if (inlineTemplate) { |
| 8608 |
data += inlineTemplate + ","; |
| 8609 |
} |
| 8610 |
} |
| 8611 |
data = data.replace(/,$/, '') + '}'; |
| 8612 |
// v-bind data wrap |
| 8613 |
if (el.wrapData) { |
| 8614 |
data = el.wrapData(data); |
| 8615 |
} |
| 8616 |
return data |
| 8617 |
} |
| 8618 |
|
| 8619 |
function genDirectives (el) { |
| 8620 |
var dirs = el.directives; |
| 8621 |
if (!dirs) { return } |
| 8622 |
var res = 'directives:['; |
| 8623 |
var hasRuntime = false; |
| 8624 |
var i, l, dir, needRuntime; |
| 8625 |
for (i = 0, l = dirs.length; i < l; i++) { |
| 8626 |
dir = dirs[i]; |
| 8627 |
needRuntime = true; |
| 8628 |
var gen = platformDirectives$1[dir.name] || baseDirectives[dir.name]; |
| 8629 |
if (gen) { |
| 8630 |
// compile-time directive that manipulates AST. |
| 8631 |
// returns true if it also needs a runtime counterpart. |
| 8632 |
needRuntime = !!gen(el, dir, warn$3); |
| 8633 |
} |
| 8634 |
if (needRuntime) { |
| 8635 |
hasRuntime = true; |
| 8636 |
res += "{name:\"" + (dir.name) + "\",rawName:\"" + (dir.rawName) + "\"" + (dir.value ? (",value:(" + (dir.value) + "),expression:" + (JSON.stringify(dir.value))) : '') + (dir.arg ? (",arg:\"" + (dir.arg) + "\"") : '') + (dir.modifiers ? (",modifiers:" + (JSON.stringify(dir.modifiers))) : '') + "},"; |
| 8637 |
} |
| 8638 |
} |
| 8639 |
if (hasRuntime) { |
| 8640 |
return res.slice(0, -1) + ']' |
| 8641 |
} |
| 8642 |
} |
| 8643 |
|
| 8644 |
function genInlineTemplate (el) { |
| 8645 |
var ast = el.children[0]; |
| 8646 |
if ("development" !== 'production' && ( |
| 8647 |
el.children.length > 1 || ast.type !== 1 |
| 8648 |
)) { |
| 8649 |
warn$3('Inline-template components must have exactly one child element.'); |
| 8650 |
} |
| 8651 |
if (ast.type === 1) { |
| 8652 |
var inlineRenderFns = generate(ast, currentOptions); |
| 8653 |
return ("inlineTemplate:{render:function(){" + (inlineRenderFns.render) + "},staticRenderFns:[" + (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){" + code + "}"); }).join(',')) + "]}") |
| 8654 |
} |
| 8655 |
} |
| 8656 |
|
| 8657 |
function genScopedSlots (slots) { |
| 8658 |
return ("scopedSlots:_u([" + (Object.keys(slots).map(function (key) { return genScopedSlot(key, slots[key]); }).join(',')) + "])") |
| 8659 |
} |
| 8660 |
|
| 8661 |
function genScopedSlot (key, el) { |
| 8662 |
return "[" + key + ",function(" + (String(el.attrsMap.scope)) + "){" + |
| 8663 |
"return " + (el.tag === 'template' |
| 8664 |
? genChildren(el) || 'void 0' |
| 8665 |
: genElement(el)) + "}]" |
| 8666 |
} |
| 8667 |
|
| 8668 |
function genChildren (el, checkSkip) { |
| 8669 |
var children = el.children; |
| 8670 |
if (children.length) { |
| 8671 |
var el$1 = children[0]; |
| 8672 |
// optimize single v-for |
| 8673 |
if (children.length === 1 && |
| 8674 |
el$1.for && |
| 8675 |
el$1.tag !== 'template' && |
| 8676 |
el$1.tag !== 'slot') { |
| 8677 |
return genElement(el$1) |
| 8678 |
} |
| 8679 |
var normalizationType = checkSkip ? getNormalizationType(children) : 0; |
| 8680 |
return ("[" + (children.map(genNode).join(',')) + "]" + (normalizationType ? ("," + normalizationType) : '')) |
| 8681 |
} |
| 8682 |
} |
| 8683 |
|
| 8684 |
// determine the normalization needed for the children array. |
| 8685 |
// 0: no normalization needed |
| 8686 |
// 1: simple normalization needed (possible 1-level deep nested array) |
| 8687 |
// 2: full normalization needed |
| 8688 |
function getNormalizationType (children) { |
| 8689 |
var res = 0; |
| 8690 |
for (var i = 0; i < children.length; i++) { |
| 8691 |
var el = children[i]; |
| 8692 |
if (el.type !== 1) { |
| 8693 |
continue |
| 8694 |
} |
| 8695 |
if (needsNormalization(el) || |
| 8696 |
(el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) { |
| 8697 |
res = 2; |
| 8698 |
break |
| 8699 |
} |
| 8700 |
if (maybeComponent(el) || |
| 8701 |
(el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) { |
| 8702 |
res = 1; |
| 8703 |
} |
| 8704 |
} |
| 8705 |
return res |
| 8706 |
} |
| 8707 |
|
| 8708 |
function needsNormalization (el) { |
| 8709 |
return el.for !== undefined || el.tag === 'template' || el.tag === 'slot' |
| 8710 |
} |
| 8711 |
|
| 8712 |
function maybeComponent (el) { |
| 8713 |
return !isPlatformReservedTag$1(el.tag) |
| 8714 |
} |
| 8715 |
|
| 8716 |
function genNode (node) { |
| 8717 |
if (node.type === 1) { |
| 8718 |
return genElement(node) |
| 8719 |
} else { |
| 8720 |
return genText(node) |
| 8721 |
} |
| 8722 |
} |
| 8723 |
|
| 8724 |
function genText (text) { |
| 8725 |
return ("_v(" + (text.type === 2 |
| 8726 |
? text.expression // no need for () because already wrapped in _s() |
| 8727 |
: transformSpecialNewlines(JSON.stringify(text.text))) + ")") |
| 8728 |
} |
| 8729 |
|
| 8730 |
function genSlot (el) { |
| 8731 |
var slotName = el.slotName || '"default"'; |
| 8732 |
var children = genChildren(el); |
| 8733 |
var res = "_t(" + slotName + (children ? ("," + children) : ''); |
| 8734 |
var attrs = el.attrs && ("{" + (el.attrs.map(function (a) { return ((camelize(a.name)) + ":" + (a.value)); }).join(',')) + "}"); |
| 8735 |
var bind$$1 = el.attrsMap['v-bind']; |
| 8736 |
if ((attrs || bind$$1) && !children) { |
| 8737 |
res += ",null"; |
| 8738 |
} |
| 8739 |
if (attrs) { |
| 8740 |
res += "," + attrs; |
| 8741 |
} |
| 8742 |
if (bind$$1) { |
| 8743 |
res += (attrs ? '' : ',null') + "," + bind$$1; |
| 8744 |
} |
| 8745 |
return res + ')' |
| 8746 |
} |
| 8747 |
|
| 8748 |
// componentName is el.component, take it as argument to shun flow's pessimistic refinement |
| 8749 |
function genComponent (componentName, el) { |
| 8750 |
var children = el.inlineTemplate ? null : genChildren(el, true); |
| 8751 |
return ("_c(" + componentName + "," + (genData(el)) + (children ? ("," + children) : '') + ")") |
| 8752 |
} |
| 8753 |
|
| 8754 |
function genProps (props) { |
| 8755 |
var res = ''; |
| 8756 |
for (var i = 0; i < props.length; i++) { |
| 8757 |
var prop = props[i]; |
| 8758 |
res += "\"" + (prop.name) + "\":" + (transformSpecialNewlines(prop.value)) + ","; |
| 8759 |
} |
| 8760 |
return res.slice(0, -1) |
| 8761 |
} |
| 8762 |
|
| 8763 |
// #3895, #4268 |
| 8764 |
function transformSpecialNewlines (text) { |
| 8765 |
return text |
| 8766 |
.replace(/\u2028/g, '\\u2028') |
| 8767 |
.replace(/\u2029/g, '\\u2029') |
| 8768 |
} |
| 8769 |
|
| 8770 |
/* */ |
| 8771 |
|
| 8772 |
// these keywords should not appear inside expressions, but operators like |
| 8773 |
// typeof, instanceof and in are allowed |
| 8774 |
var prohibitedKeywordRE = new RegExp('\\b' + ( |
| 8775 |
'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' + |
| 8776 |
'super,throw,while,yield,delete,export,import,return,switch,default,' + |
| 8777 |
'extends,finally,continue,debugger,function,arguments' |
| 8778 |
).split(',').join('\\b|\\b') + '\\b'); |
| 8779 |
|
| 8780 |
// these unary operators should not be used as property/method names |
| 8781 |
var unaryOperatorsRE = new RegExp('\\b' + ( |
| 8782 |
'delete,typeof,void' |
| 8783 |
).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)'); |
| 8784 |
|
| 8785 |
// check valid identifier for v-for |
| 8786 |
var identRE = /[A-Za-z_$][\w$]*/; |
| 8787 |
|
| 8788 |
// strip strings in expressions |
| 8789 |
var stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g; |
| 8790 |
|
| 8791 |
// detect problematic expressions in a template |
| 8792 |
function detectErrors (ast) { |
| 8793 |
var errors = []; |
| 8794 |
if (ast) { |
| 8795 |
checkNode(ast, errors); |
| 8796 |
} |
| 8797 |
return errors |
| 8798 |
} |
| 8799 |
|
| 8800 |
function checkNode (node, errors) { |
| 8801 |
if (node.type === 1) { |
| 8802 |
for (var name in node.attrsMap) { |
| 8803 |
if (dirRE.test(name)) { |
| 8804 |
var value = node.attrsMap[name]; |
| 8805 |
if (value) { |
| 8806 |
if (name === 'v-for') { |
| 8807 |
checkFor(node, ("v-for=\"" + value + "\""), errors); |
| 8808 |
} else if (onRE.test(name)) { |
| 8809 |
checkEvent(value, (name + "=\"" + value + "\""), errors); |
| 8810 |
} else { |
| 8811 |
checkExpression(value, (name + "=\"" + value + "\""), errors); |
| 8812 |
} |
| 8813 |
} |
| 8814 |
} |
| 8815 |
} |
| 8816 |
if (node.children) { |
| 8817 |
for (var i = 0; i < node.children.length; i++) { |
| 8818 |
checkNode(node.children[i], errors); |
| 8819 |
} |
| 8820 |
} |
| 8821 |
} else if (node.type === 2) { |
| 8822 |
checkExpression(node.expression, node.text, errors); |
| 8823 |
} |
| 8824 |
} |
| 8825 |
|
| 8826 |
function checkEvent (exp, text, errors) { |
| 8827 |
var keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE); |
| 8828 |
if (keywordMatch) { |
| 8829 |
errors.push( |
| 8830 |
"avoid using JavaScript unary operator as property name: " + |
| 8831 |
"\"" + (keywordMatch[0]) + "\" in expression " + (text.trim()) |
| 8832 |
); |
| 8833 |
} |
| 8834 |
checkExpression(exp, text, errors); |
| 8835 |
} |
| 8836 |
|
| 8837 |
function checkFor (node, text, errors) { |
| 8838 |
checkExpression(node.for || '', text, errors); |
| 8839 |
checkIdentifier(node.alias, 'v-for alias', text, errors); |
| 8840 |
checkIdentifier(node.iterator1, 'v-for iterator', text, errors); |
| 8841 |
checkIdentifier(node.iterator2, 'v-for iterator', text, errors); |
| 8842 |
} |
| 8843 |
|
| 8844 |
function checkIdentifier (ident, type, text, errors) { |
| 8845 |
if (typeof ident === 'string' && !identRE.test(ident)) { |
| 8846 |
errors.push(("invalid " + type + " \"" + ident + "\" in expression: " + (text.trim()))); |
| 8847 |
} |
| 8848 |
} |
| 8849 |
|
| 8850 |
function checkExpression (exp, text, errors) { |
| 8851 |
try { |
| 8852 |
new Function(("return " + exp)); |
| 8853 |
} catch (e) { |
| 8854 |
var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE); |
| 8855 |
if (keywordMatch) { |
| 8856 |
errors.push( |
| 8857 |
"avoid using JavaScript keyword as property name: " + |
| 8858 |
"\"" + (keywordMatch[0]) + "\" in expression " + (text.trim()) |
| 8859 |
); |
| 8860 |
} else { |
| 8861 |
errors.push(("invalid expression: " + (text.trim()))); |
| 8862 |
} |
| 8863 |
} |
| 8864 |
} |
| 8865 |
|
| 8866 |
/* */ |
| 8867 |
|
| 8868 |
function baseCompile ( |
| 8869 |
template, |
| 8870 |
options |
| 8871 |
) { |
| 8872 |
var ast = parse(template.trim(), options); |
| 8873 |
optimize(ast, options); |
| 8874 |
var code = generate(ast, options); |
| 8875 |
return { |
| 8876 |
ast: ast, |
| 8877 |
render: code.render, |
| 8878 |
staticRenderFns: code.staticRenderFns |
| 8879 |
} |
| 8880 |
} |
| 8881 |
|
| 8882 |
function makeFunction (code, errors) { |
| 8883 |
try { |
| 8884 |
return new Function(code) |
| 8885 |
} catch (err) { |
| 8886 |
errors.push({ err: err, code: code }); |
| 8887 |
return noop |
| 8888 |
} |
| 8889 |
} |
| 8890 |
|
| 8891 |
function createCompiler (baseOptions) { |
| 8892 |
var functionCompileCache = Object.create(null); |
| 8893 |
|
| 8894 |
function compile ( |
| 8895 |
template, |
| 8896 |
options |
| 8897 |
) { |
| 8898 |
var finalOptions = Object.create(baseOptions); |
| 8899 |
var errors = []; |
| 8900 |
var tips = []; |
| 8901 |
finalOptions.warn = function (msg, tip$$1) { |
| 8902 |
(tip$$1 ? tips : errors).push(msg); |
| 8903 |
}; |
| 8904 |
|
| 8905 |
if (options) { |
| 8906 |
// merge custom modules |
| 8907 |
if (options.modules) { |
| 8908 |
finalOptions.modules = (baseOptions.modules || []).concat(options.modules); |
| 8909 |
} |
| 8910 |
// merge custom directives |
| 8911 |
if (options.directives) { |
| 8912 |
finalOptions.directives = extend( |
| 8913 |
Object.create(baseOptions.directives), |
| 8914 |
options.directives |
| 8915 |
); |
| 8916 |
} |
| 8917 |
// copy other options |
| 8918 |
for (var key in options) { |
| 8919 |
if (key !== 'modules' && key !== 'directives') { |
| 8920 |
finalOptions[key] = options[key]; |
| 8921 |
} |
| 8922 |
} |
| 8923 |
} |
| 8924 |
|
| 8925 |
var compiled = baseCompile(template, finalOptions); |
| 8926 |
{ |
| 8927 |
errors.push.apply(errors, detectErrors(compiled.ast)); |
| 8928 |
} |
| 8929 |
compiled.errors = errors; |
| 8930 |
compiled.tips = tips; |
| 8931 |
return compiled |
| 8932 |
} |
| 8933 |
|
| 8934 |
function compileToFunctions ( |
| 8935 |
template, |
| 8936 |
options, |
| 8937 |
vm |
| 8938 |
) { |
| 8939 |
options = options || {}; |
| 8940 |
|
| 8941 |
/* istanbul ignore if */ |
| 8942 |
{ |
| 8943 |
// detect possible CSP restriction |
| 8944 |
try { |
| 8945 |
new Function('return 1'); |
| 8946 |
} catch (e) { |
| 8947 |
if (e.toString().match(/unsafe-eval|CSP/)) { |
| 8948 |
warn( |
| 8949 |
'It seems you are using the standalone build of Vue.js in an ' + |
| 8950 |
'environment with Content Security Policy that prohibits unsafe-eval. ' + |
| 8951 |
'The template compiler cannot work in this environment. Consider ' + |
| 8952 |
'relaxing the policy to allow unsafe-eval or pre-compiling your ' + |
| 8953 |
'templates into render functions.' |
| 8954 |
); |
| 8955 |
} |
| 8956 |
} |
| 8957 |
} |
| 8958 |
|
| 8959 |
// check cache |
| 8960 |
var key = options.delimiters |
| 8961 |
? String(options.delimiters) + template |
| 8962 |
: template; |
| 8963 |
if (functionCompileCache[key]) { |
| 8964 |
return functionCompileCache[key] |
| 8965 |
} |
| 8966 |
|
| 8967 |
// compile |
| 8968 |
var compiled = compile(template, options); |
| 8969 |
|
| 8970 |
// check compilation errors/tips |
| 8971 |
{ |
| 8972 |
if (compiled.errors && compiled.errors.length) { |
| 8973 |
warn( |
| 8974 |
"Error compiling template:\n\n" + template + "\n\n" + |
| 8975 |
compiled.errors.map(function (e) { return ("- " + e); }).join('\n') + '\n', |
| 8976 |
vm |
| 8977 |
); |
| 8978 |
} |
| 8979 |
if (compiled.tips && compiled.tips.length) { |
| 8980 |
compiled.tips.forEach(function (msg) { return tip(msg, vm); }); |
| 8981 |
} |
| 8982 |
} |
| 8983 |
|
| 8984 |
// turn code into functions |
| 8985 |
var res = {}; |
| 8986 |
var fnGenErrors = []; |
| 8987 |
res.render = makeFunction(compiled.render, fnGenErrors); |
| 8988 |
var l = compiled.staticRenderFns.length; |
| 8989 |
res.staticRenderFns = new Array(l); |
| 8990 |
for (var i = 0; i < l; i++) { |
| 8991 |
res.staticRenderFns[i] = makeFunction(compiled.staticRenderFns[i], fnGenErrors); |
| 8992 |
} |
| 8993 |
|
| 8994 |
// check function generation errors. |
| 8995 |
// this should only happen if there is a bug in the compiler itself. |
| 8996 |
// mostly for codegen development use |
| 8997 |
/* istanbul ignore if */ |
| 8998 |
{ |
| 8999 |
if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) { |
| 9000 |
warn( |
| 9001 |
"Failed to generate render function:\n\n" + |
| 9002 |
fnGenErrors.map(function (ref) { |
| 9003 |
var err = ref.err; |
| 9004 |
var code = ref.code; |
| 9005 |
|
| 9006 |
return ((err.toString()) + " in\n\n" + code + "\n"); |
| 9007 |
}).join('\n'), |
| 9008 |
vm |
| 9009 |
); |
| 9010 |
} |
| 9011 |
} |
| 9012 |
|
| 9013 |
return (functionCompileCache[key] = res) |
| 9014 |
} |
| 9015 |
|
| 9016 |
return { |
| 9017 |
compile: compile, |
| 9018 |
compileToFunctions: compileToFunctions |
| 9019 |
} |
| 9020 |
} |
| 9021 |
|
| 9022 |
/* */ |
| 9023 |
|
| 9024 |
function transformNode (el, options) { |
| 9025 |
var warn = options.warn || baseWarn; |
| 9026 |
var staticClass = getAndRemoveAttr(el, 'class'); |
| 9027 |
if ("development" !== 'production' && staticClass) { |
| 9028 |
var expression = parseText(staticClass, options.delimiters); |
| 9029 |
if (expression) { |
| 9030 |
warn( |
| 9031 |
"class=\"" + staticClass + "\": " + |
| 9032 |
'Interpolation inside attributes has been removed. ' + |
| 9033 |
'Use v-bind or the colon shorthand instead. For example, ' + |
| 9034 |
'instead of <div class="{{ val }}">, use <div :class="val">.' |
| 9035 |
); |
| 9036 |
} |
| 9037 |
} |
| 9038 |
if (staticClass) { |
| 9039 |
el.staticClass = JSON.stringify(staticClass); |
| 9040 |
} |
| 9041 |
var classBinding = getBindingAttr(el, 'class', false /* getStatic */); |
| 9042 |
if (classBinding) { |
| 9043 |
el.classBinding = classBinding; |
| 9044 |
} |
| 9045 |
} |
| 9046 |
|
| 9047 |
function genData$1 (el) { |
| 9048 |
var data = ''; |
| 9049 |
if (el.staticClass) { |
| 9050 |
data += "staticClass:" + (el.staticClass) + ","; |
| 9051 |
} |
| 9052 |
if (el.classBinding) { |
| 9053 |
data += "class:" + (el.classBinding) + ","; |
| 9054 |
} |
| 9055 |
return data |
| 9056 |
} |
| 9057 |
|
| 9058 |
var klass$1 = { |
| 9059 |
staticKeys: ['staticClass'], |
| 9060 |
transformNode: transformNode, |
| 9061 |
genData: genData$1 |
| 9062 |
}; |
| 9063 |
|
| 9064 |
/* */ |
| 9065 |
|
| 9066 |
function transformNode$1 (el, options) { |
| 9067 |
var warn = options.warn || baseWarn; |
| 9068 |
var staticStyle = getAndRemoveAttr(el, 'style'); |
| 9069 |
if (staticStyle) { |
| 9070 |
/* istanbul ignore if */ |
| 9071 |
{ |
| 9072 |
var expression = parseText(staticStyle, options.delimiters); |
| 9073 |
if (expression) { |
| 9074 |
warn( |
| 9075 |
"style=\"" + staticStyle + "\": " + |
| 9076 |
'Interpolation inside attributes has been removed. ' + |
| 9077 |
'Use v-bind or the colon shorthand instead. For example, ' + |
| 9078 |
'instead of <div style="{{ val }}">, use <div :style="val">.' |
| 9079 |
); |
| 9080 |
} |
| 9081 |
} |
| 9082 |
el.staticStyle = JSON.stringify(parseStyleText(staticStyle)); |
| 9083 |
} |
| 9084 |
|
| 9085 |
var styleBinding = getBindingAttr(el, 'style', false /* getStatic */); |
| 9086 |
if (styleBinding) { |
| 9087 |
el.styleBinding = styleBinding; |
| 9088 |
} |
| 9089 |
} |
| 9090 |
|
| 9091 |
function genData$2 (el) { |
| 9092 |
var data = ''; |
| 9093 |
if (el.staticStyle) { |
| 9094 |
data += "staticStyle:" + (el.staticStyle) + ","; |
| 9095 |
} |
| 9096 |
if (el.styleBinding) { |
| 9097 |
data += "style:(" + (el.styleBinding) + "),"; |
| 9098 |
} |
| 9099 |
return data |
| 9100 |
} |
| 9101 |
|
| 9102 |
var style$1 = { |
| 9103 |
staticKeys: ['staticStyle'], |
| 9104 |
transformNode: transformNode$1, |
| 9105 |
genData: genData$2 |
| 9106 |
}; |
| 9107 |
|
| 9108 |
var modules$1 = [ |
| 9109 |
klass$1, |
| 9110 |
style$1 |
| 9111 |
]; |
| 9112 |
|
| 9113 |
/* */ |
| 9114 |
|
| 9115 |
function text (el, dir) { |
| 9116 |
if (dir.value) { |
| 9117 |
addProp(el, 'textContent', ("_s(" + (dir.value) + ")")); |
| 9118 |
} |
| 9119 |
} |
| 9120 |
|
| 9121 |
/* */ |
| 9122 |
|
| 9123 |
function html (el, dir) { |
| 9124 |
if (dir.value) { |
| 9125 |
addProp(el, 'innerHTML', ("_s(" + (dir.value) + ")")); |
| 9126 |
} |
| 9127 |
} |
| 9128 |
|
| 9129 |
var directives$1 = { |
| 9130 |
model: model, |
| 9131 |
text: text, |
| 9132 |
html: html |
| 9133 |
}; |
| 9134 |
|
| 9135 |
/* */ |
| 9136 |
|
| 9137 |
var baseOptions = { |
| 9138 |
expectHTML: true, |
| 9139 |
modules: modules$1, |
| 9140 |
directives: directives$1, |
| 9141 |
isPreTag: isPreTag, |
| 9142 |
isUnaryTag: isUnaryTag, |
| 9143 |
mustUseProp: mustUseProp, |
| 9144 |
isReservedTag: isReservedTag, |
| 9145 |
getTagNamespace: getTagNamespace, |
| 9146 |
staticKeys: genStaticKeys(modules$1) |
| 9147 |
}; |
| 9148 |
|
| 9149 |
var ref$1 = createCompiler(baseOptions); |
| 9150 |
var compileToFunctions = ref$1.compileToFunctions; |
| 9151 |
|
| 9152 |
/* */ |
| 9153 |
|
| 9154 |
var idToTemplate = cached(function (id) { |
| 9155 |
var el = query(id); |
| 9156 |
return el && el.innerHTML |
| 9157 |
}); |
| 9158 |
|
| 9159 |
var mount = Vue$3.prototype.$mount; |
| 9160 |
Vue$3.prototype.$mount = function ( |
| 9161 |
el, |
| 9162 |
hydrating |
| 9163 |
) { |
| 9164 |
el = el && query(el); |
| 9165 |
|
| 9166 |
/* istanbul ignore if */ |
| 9167 |
if (el === document.body || el === document.documentElement) { |
| 9168 |
"development" !== 'production' && warn( |
| 9169 |
"Do not mount Vue to <html> or <body> - mount to normal elements instead." |
| 9170 |
); |
| 9171 |
return this |
| 9172 |
} |
| 9173 |
|
| 9174 |
var options = this.$options; |
| 9175 |
// resolve template/el and convert to render function |
| 9176 |
if (!options.render) { |
| 9177 |
var template = options.template; |
| 9178 |
if (template) { |
| 9179 |
if (typeof template === 'string') { |
| 9180 |
if (template.charAt(0) === '#') { |
| 9181 |
template = idToTemplate(template); |
| 9182 |
/* istanbul ignore if */ |
| 9183 |
if ("development" !== 'production' && !template) { |
| 9184 |
warn( |
| 9185 |
("Template element not found or is empty: " + (options.template)), |
| 9186 |
this |
| 9187 |
); |
| 9188 |
} |
| 9189 |
} |
| 9190 |
} else if (template.nodeType) { |
| 9191 |
template = template.innerHTML; |
| 9192 |
} else { |
| 9193 |
{ |
| 9194 |
warn('invalid template option:' + template, this); |
| 9195 |
} |
| 9196 |
return this |
| 9197 |
} |
| 9198 |
} else if (el) { |
| 9199 |
template = getOuterHTML(el); |
| 9200 |
} |
| 9201 |
if (template) { |
| 9202 |
/* istanbul ignore if */ |
| 9203 |
if ("development" !== 'production' && config.performance && mark) { |
| 9204 |
mark('compile'); |
| 9205 |
} |
| 9206 |
|
| 9207 |
var ref = compileToFunctions(template, { |
| 9208 |
shouldDecodeNewlines: shouldDecodeNewlines, |
| 9209 |
delimiters: options.delimiters |
| 9210 |
}, this); |
| 9211 |
var render = ref.render; |
| 9212 |
var staticRenderFns = ref.staticRenderFns; |
| 9213 |
options.render = render; |
| 9214 |
options.staticRenderFns = staticRenderFns; |
| 9215 |
|
| 9216 |
/* istanbul ignore if */ |
| 9217 |
if ("development" !== 'production' && config.performance && mark) { |
| 9218 |
mark('compile end'); |
| 9219 |
measure(((this._name) + " compile"), 'compile', 'compile end'); |
| 9220 |
} |
| 9221 |
} |
| 9222 |
} |
| 9223 |
return mount.call(this, el, hydrating) |
| 9224 |
}; |
| 9225 |
|
| 9226 |
/** |
| 9227 |
* Get outerHTML of elements, taking care |
| 9228 |
* of SVG elements in IE as well. |
| 9229 |
*/ |
| 9230 |
function getOuterHTML (el) { |
| 9231 |
if (el.outerHTML) { |
| 9232 |
return el.outerHTML |
| 9233 |
} else { |
| 9234 |
var container = document.createElement('div'); |
| 9235 |
container.appendChild(el.cloneNode(true)); |
| 9236 |
return container.innerHTML |
| 9237 |
} |
| 9238 |
} |
| 9239 |
|
| 9240 |
Vue$3.compile = compileToFunctions; |
| 9241 |
|
| 9242 |
return Vue$3; |
| 9243 |
|
| 9244 |
}))); |
| 9245 |
|
| 9246 |
/* assets/wpuf/vendor/vuex/vuex.js */ |
| 9247 |
/** |
| 9248 |
* vuex v2.2.1 |
| 9249 |
* (c) 2017 Evan You |
| 9250 |
* @license MIT |
| 9251 |
*/ |
| 9252 |
(function (global, factory) { |
| 9253 |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 9254 |
typeof define === 'function' && define.amd ? define(factory) : |
| 9255 |
(global.Vuex = factory()); |
| 9256 |
}(this, (function () { 'use strict'; |
| 9257 |
|
| 9258 |
var applyMixin = function (Vue) { |
| 9259 |
var version = Number(Vue.version.split('.')[0]); |
| 9260 |
|
| 9261 |
if (version >= 2) { |
| 9262 |
var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1; |
| 9263 |
Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit }); |
| 9264 |
} else { |
| 9265 |
// override init and inject vuex init procedure |
| 9266 |
// for 1.x backwards compatibility. |
| 9267 |
var _init = Vue.prototype._init; |
| 9268 |
Vue.prototype._init = function (options) { |
| 9269 |
if ( options === void 0 ) options = {}; |
| 9270 |
|
| 9271 |
options.init = options.init |
| 9272 |
? [vuexInit].concat(options.init) |
| 9273 |
: vuexInit; |
| 9274 |
_init.call(this, options); |
| 9275 |
}; |
| 9276 |
} |
| 9277 |
|
| 9278 |
/** |
| 9279 |
* Vuex init hook, injected into each instances init hooks list. |
| 9280 |
*/ |
| 9281 |
|
| 9282 |
function vuexInit () { |
| 9283 |
var options = this.$options; |
| 9284 |
// store injection |
| 9285 |
if (options.store) { |
| 9286 |
this.$store = options.store; |
| 9287 |
} else if (options.parent && options.parent.$store) { |
| 9288 |
this.$store = options.parent.$store; |
| 9289 |
} |
| 9290 |
} |
| 9291 |
}; |
| 9292 |
|
| 9293 |
var devtoolHook = |
| 9294 |
typeof window !== 'undefined' && |
| 9295 |
window.__VUE_DEVTOOLS_GLOBAL_HOOK__; |
| 9296 |
|
| 9297 |
function devtoolPlugin (store) { |
| 9298 |
if (!devtoolHook) { return } |
| 9299 |
|
| 9300 |
store._devtoolHook = devtoolHook; |
| 9301 |
|
| 9302 |
devtoolHook.emit('vuex:init', store); |
| 9303 |
|
| 9304 |
devtoolHook.on('vuex:travel-to-state', function (targetState) { |
| 9305 |
store.replaceState(targetState); |
| 9306 |
}); |
| 9307 |
|
| 9308 |
store.subscribe(function (mutation, state) { |
| 9309 |
devtoolHook.emit('vuex:mutation', mutation, state); |
| 9310 |
}); |
| 9311 |
} |
| 9312 |
|
| 9313 |
/** |
| 9314 |
* Get the first item that pass the test |
| 9315 |
* by second argument function |
| 9316 |
* |
| 9317 |
* @param {Array} list |
| 9318 |
* @param {Function} f |
| 9319 |
* @return {*} |
| 9320 |
*/ |
| 9321 |
/** |
| 9322 |
* Deep copy the given object considering circular structure. |
| 9323 |
* This function caches all nested objects and its copies. |
| 9324 |
* If it detects circular structure, use cached copy to avoid infinite loop. |
| 9325 |
* |
| 9326 |
* @param {*} obj |
| 9327 |
* @param {Array<Object>} cache |
| 9328 |
* @return {*} |
| 9329 |
*/ |
| 9330 |
|
| 9331 |
|
| 9332 |
/** |
| 9333 |
* forEach for object |
| 9334 |
*/ |
| 9335 |
function forEachValue (obj, fn) { |
| 9336 |
Object.keys(obj).forEach(function (key) { return fn(obj[key], key); }); |
| 9337 |
} |
| 9338 |
|
| 9339 |
function isObject (obj) { |
| 9340 |
return obj !== null && typeof obj === 'object' |
| 9341 |
} |
| 9342 |
|
| 9343 |
function isPromise (val) { |
| 9344 |
return val && typeof val.then === 'function' |
| 9345 |
} |
| 9346 |
|
| 9347 |
function assert (condition, msg) { |
| 9348 |
if (!condition) { throw new Error(("[vuex] " + msg)) } |
| 9349 |
} |
| 9350 |
|
| 9351 |
var Module = function Module (rawModule, runtime) { |
| 9352 |
this.runtime = runtime; |
| 9353 |
this._children = Object.create(null); |
| 9354 |
this._rawModule = rawModule; |
| 9355 |
}; |
| 9356 |
|
| 9357 |
var prototypeAccessors$1 = { state: {},namespaced: {} }; |
| 9358 |
|
| 9359 |
prototypeAccessors$1.state.get = function () { |
| 9360 |
return this._rawModule.state || {} |
| 9361 |
}; |
| 9362 |
|
| 9363 |
prototypeAccessors$1.namespaced.get = function () { |
| 9364 |
return !!this._rawModule.namespaced |
| 9365 |
}; |
| 9366 |
|
| 9367 |
Module.prototype.addChild = function addChild (key, module) { |
| 9368 |
this._children[key] = module; |
| 9369 |
}; |
| 9370 |
|
| 9371 |
Module.prototype.removeChild = function removeChild (key) { |
| 9372 |
delete this._children[key]; |
| 9373 |
}; |
| 9374 |
|
| 9375 |
Module.prototype.getChild = function getChild (key) { |
| 9376 |
return this._children[key] |
| 9377 |
}; |
| 9378 |
|
| 9379 |
Module.prototype.update = function update (rawModule) { |
| 9380 |
this._rawModule.namespaced = rawModule.namespaced; |
| 9381 |
if (rawModule.actions) { |
| 9382 |
this._rawModule.actions = rawModule.actions; |
| 9383 |
} |
| 9384 |
if (rawModule.mutations) { |
| 9385 |
this._rawModule.mutations = rawModule.mutations; |
| 9386 |
} |
| 9387 |
if (rawModule.getters) { |
| 9388 |
this._rawModule.getters = rawModule.getters; |
| 9389 |
} |
| 9390 |
}; |
| 9391 |
|
| 9392 |
Module.prototype.forEachChild = function forEachChild (fn) { |
| 9393 |
forEachValue(this._children, fn); |
| 9394 |
}; |
| 9395 |
|
| 9396 |
Module.prototype.forEachGetter = function forEachGetter (fn) { |
| 9397 |
if (this._rawModule.getters) { |
| 9398 |
forEachValue(this._rawModule.getters, fn); |
| 9399 |
} |
| 9400 |
}; |
| 9401 |
|
| 9402 |
Module.prototype.forEachAction = function forEachAction (fn) { |
| 9403 |
if (this._rawModule.actions) { |
| 9404 |
forEachValue(this._rawModule.actions, fn); |
| 9405 |
} |
| 9406 |
}; |
| 9407 |
|
| 9408 |
Module.prototype.forEachMutation = function forEachMutation (fn) { |
| 9409 |
if (this._rawModule.mutations) { |
| 9410 |
forEachValue(this._rawModule.mutations, fn); |
| 9411 |
} |
| 9412 |
}; |
| 9413 |
|
| 9414 |
Object.defineProperties( Module.prototype, prototypeAccessors$1 ); |
| 9415 |
|
| 9416 |
var ModuleCollection = function ModuleCollection (rawRootModule) { |
| 9417 |
var this$1 = this; |
| 9418 |
|
| 9419 |
// register root module (Vuex.Store options) |
| 9420 |
this.root = new Module(rawRootModule, false); |
| 9421 |
|
| 9422 |
// register all nested modules |
| 9423 |
if (rawRootModule.modules) { |
| 9424 |
forEachValue(rawRootModule.modules, function (rawModule, key) { |
| 9425 |
this$1.register([key], rawModule, false); |
| 9426 |
}); |
| 9427 |
} |
| 9428 |
}; |
| 9429 |
|
| 9430 |
ModuleCollection.prototype.get = function get (path) { |
| 9431 |
return path.reduce(function (module, key) { |
| 9432 |
return module.getChild(key) |
| 9433 |
}, this.root) |
| 9434 |
}; |
| 9435 |
|
| 9436 |
ModuleCollection.prototype.getNamespace = function getNamespace (path) { |
| 9437 |
var module = this.root; |
| 9438 |
return path.reduce(function (namespace, key) { |
| 9439 |
module = module.getChild(key); |
| 9440 |
return namespace + (module.namespaced ? key + '/' : '') |
| 9441 |
}, '') |
| 9442 |
}; |
| 9443 |
|
| 9444 |
ModuleCollection.prototype.update = function update$1 (rawRootModule) { |
| 9445 |
update(this.root, rawRootModule); |
| 9446 |
}; |
| 9447 |
|
| 9448 |
ModuleCollection.prototype.register = function register (path, rawModule, runtime) { |
| 9449 |
var this$1 = this; |
| 9450 |
if ( runtime === void 0 ) runtime = true; |
| 9451 |
|
| 9452 |
var parent = this.get(path.slice(0, -1)); |
| 9453 |
var newModule = new Module(rawModule, runtime); |
| 9454 |
parent.addChild(path[path.length - 1], newModule); |
| 9455 |
|
| 9456 |
// register nested modules |
| 9457 |
if (rawModule.modules) { |
| 9458 |
forEachValue(rawModule.modules, function (rawChildModule, key) { |
| 9459 |
this$1.register(path.concat(key), rawChildModule, runtime); |
| 9460 |
}); |
| 9461 |
} |
| 9462 |
}; |
| 9463 |
|
| 9464 |
ModuleCollection.prototype.unregister = function unregister (path) { |
| 9465 |
var parent = this.get(path.slice(0, -1)); |
| 9466 |
var key = path[path.length - 1]; |
| 9467 |
if (!parent.getChild(key).runtime) { return } |
| 9468 |
|
| 9469 |
parent.removeChild(key); |
| 9470 |
}; |
| 9471 |
|
| 9472 |
function update (targetModule, newModule) { |
| 9473 |
// update target module |
| 9474 |
targetModule.update(newModule); |
| 9475 |
|
| 9476 |
// update nested modules |
| 9477 |
if (newModule.modules) { |
| 9478 |
for (var key in newModule.modules) { |
| 9479 |
if (!targetModule.getChild(key)) { |
| 9480 |
console.warn( |
| 9481 |
"[vuex] trying to add a new module '" + key + "' on hot reloading, " + |
| 9482 |
'manual reload is needed' |
| 9483 |
); |
| 9484 |
return |
| 9485 |
} |
| 9486 |
update(targetModule.getChild(key), newModule.modules[key]); |
| 9487 |
} |
| 9488 |
} |
| 9489 |
} |
| 9490 |
|
| 9491 |
var Vue; // bind on install |
| 9492 |
|
| 9493 |
var Store = function Store (options) { |
| 9494 |
var this$1 = this; |
| 9495 |
if ( options === void 0 ) options = {}; |
| 9496 |
|
| 9497 |
assert(Vue, "must call Vue.use(Vuex) before creating a store instance."); |
| 9498 |
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); |
| 9499 |
|
| 9500 |
var state = options.state; if ( state === void 0 ) state = {}; |
| 9501 |
var plugins = options.plugins; if ( plugins === void 0 ) plugins = []; |
| 9502 |
var strict = options.strict; if ( strict === void 0 ) strict = false; |
| 9503 |
|
| 9504 |
// store internal state |
| 9505 |
this._committing = false; |
| 9506 |
this._actions = Object.create(null); |
| 9507 |
this._mutations = Object.create(null); |
| 9508 |
this._wrappedGetters = Object.create(null); |
| 9509 |
this._modules = new ModuleCollection(options); |
| 9510 |
this._modulesNamespaceMap = Object.create(null); |
| 9511 |
this._subscribers = []; |
| 9512 |
this._watcherVM = new Vue(); |
| 9513 |
|
| 9514 |
// bind commit and dispatch to self |
| 9515 |
var store = this; |
| 9516 |
var ref = this; |
| 9517 |
var dispatch = ref.dispatch; |
| 9518 |
var commit = ref.commit; |
| 9519 |
this.dispatch = function boundDispatch (type, payload) { |
| 9520 |
return dispatch.call(store, type, payload) |
| 9521 |
}; |
| 9522 |
this.commit = function boundCommit (type, payload, options) { |
| 9523 |
return commit.call(store, type, payload, options) |
| 9524 |
}; |
| 9525 |
|
| 9526 |
// strict mode |
| 9527 |
this.strict = strict; |
| 9528 |
|
| 9529 |
// init root module. |
| 9530 |
// this also recursively registers all sub-modules |
| 9531 |
// and collects all module getters inside this._wrappedGetters |
| 9532 |
installModule(this, state, [], this._modules.root); |
| 9533 |
|
| 9534 |
// initialize the store vm, which is responsible for the reactivity |
| 9535 |
// (also registers _wrappedGetters as computed properties) |
| 9536 |
resetStoreVM(this, state); |
| 9537 |
|
| 9538 |
// apply plugins |
| 9539 |
plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); }); |
| 9540 |
}; |
| 9541 |
|
| 9542 |
var prototypeAccessors = { state: {} }; |
| 9543 |
|
| 9544 |
prototypeAccessors.state.get = function () { |
| 9545 |
return this._vm._data.$$state |
| 9546 |
}; |
| 9547 |
|
| 9548 |
prototypeAccessors.state.set = function (v) { |
| 9549 |
assert(false, "Use store.replaceState() to explicit replace store state."); |
| 9550 |
}; |
| 9551 |
|
| 9552 |
Store.prototype.commit = function commit (_type, _payload, _options) { |
| 9553 |
var this$1 = this; |
| 9554 |
|
| 9555 |
// check object-style commit |
| 9556 |
var ref = unifyObjectStyle(_type, _payload, _options); |
| 9557 |
var type = ref.type; |
| 9558 |
var payload = ref.payload; |
| 9559 |
var options = ref.options; |
| 9560 |
|
| 9561 |
var mutation = { type: type, payload: payload }; |
| 9562 |
var entry = this._mutations[type]; |
| 9563 |
if (!entry) { |
| 9564 |
console.error(("[vuex] unknown mutation type: " + type)); |
| 9565 |
return |
| 9566 |
} |
| 9567 |
this._withCommit(function () { |
| 9568 |
entry.forEach(function commitIterator (handler) { |
| 9569 |
handler(payload); |
| 9570 |
}); |
| 9571 |
}); |
| 9572 |
this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); }); |
| 9573 |
|
| 9574 |
if (options && options.silent) { |
| 9575 |
console.warn( |
| 9576 |
"[vuex] mutation type: " + type + ". Silent option has been removed. " + |
| 9577 |
'Use the filter functionality in the vue-devtools' |
| 9578 |
); |
| 9579 |
} |
| 9580 |
}; |
| 9581 |
|
| 9582 |
Store.prototype.dispatch = function dispatch (_type, _payload) { |
| 9583 |
// check object-style dispatch |
| 9584 |
var ref = unifyObjectStyle(_type, _payload); |
| 9585 |
var type = ref.type; |
| 9586 |
var payload = ref.payload; |
| 9587 |
|
| 9588 |
var entry = this._actions[type]; |
| 9589 |
if (!entry) { |
| 9590 |
console.error(("[vuex] unknown action type: " + type)); |
| 9591 |
return |
| 9592 |
} |
| 9593 |
return entry.length > 1 |
| 9594 |
? Promise.all(entry.map(function (handler) { return handler(payload); })) |
| 9595 |
: entry[0](payload) |
| 9596 |
}; |
| 9597 |
|
| 9598 |
Store.prototype.subscribe = function subscribe (fn) { |
| 9599 |
var subs = this._subscribers; |
| 9600 |
if (subs.indexOf(fn) < 0) { |
| 9601 |
subs.push(fn); |
| 9602 |
} |
| 9603 |
return function () { |
| 9604 |
var i = subs.indexOf(fn); |
| 9605 |
if (i > -1) { |
| 9606 |
subs.splice(i, 1); |
| 9607 |
} |
| 9608 |
} |
| 9609 |
}; |
| 9610 |
|
| 9611 |
Store.prototype.watch = function watch (getter, cb, options) { |
| 9612 |
var this$1 = this; |
| 9613 |
|
| 9614 |
assert(typeof getter === 'function', "store.watch only accepts a function."); |
| 9615 |
return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options) |
| 9616 |
}; |
| 9617 |
|
| 9618 |
Store.prototype.replaceState = function replaceState (state) { |
| 9619 |
var this$1 = this; |
| 9620 |
|
| 9621 |
this._withCommit(function () { |
| 9622 |
this$1._vm._data.$$state = state; |
| 9623 |
}); |
| 9624 |
}; |
| 9625 |
|
| 9626 |
Store.prototype.registerModule = function registerModule (path, rawModule) { |
| 9627 |
if (typeof path === 'string') { path = [path]; } |
| 9628 |
assert(Array.isArray(path), "module path must be a string or an Array."); |
| 9629 |
this._modules.register(path, rawModule); |
| 9630 |
installModule(this, this.state, path, this._modules.get(path)); |
| 9631 |
// reset store to update getters... |
| 9632 |
resetStoreVM(this, this.state); |
| 9633 |
}; |
| 9634 |
|
| 9635 |
Store.prototype.unregisterModule = function unregisterModule (path) { |
| 9636 |
var this$1 = this; |
| 9637 |
|
| 9638 |
if (typeof path === 'string') { path = [path]; } |
| 9639 |
assert(Array.isArray(path), "module path must be a string or an Array."); |
| 9640 |
this._modules.unregister(path); |
| 9641 |
this._withCommit(function () { |
| 9642 |
var parentState = getNestedState(this$1.state, path.slice(0, -1)); |
| 9643 |
Vue.delete(parentState, path[path.length - 1]); |
| 9644 |
}); |
| 9645 |
resetStore(this); |
| 9646 |
}; |
| 9647 |
|
| 9648 |
Store.prototype.hotUpdate = function hotUpdate (newOptions) { |
| 9649 |
this._modules.update(newOptions); |
| 9650 |
resetStore(this, true); |
| 9651 |
}; |
| 9652 |
|
| 9653 |
Store.prototype._withCommit = function _withCommit (fn) { |
| 9654 |
var committing = this._committing; |
| 9655 |
this._committing = true; |
| 9656 |
fn(); |
| 9657 |
this._committing = committing; |
| 9658 |
}; |
| 9659 |
|
| 9660 |
Object.defineProperties( Store.prototype, prototypeAccessors ); |
| 9661 |
|
| 9662 |
function resetStore (store, hot) { |
| 9663 |
store._actions = Object.create(null); |
| 9664 |
store._mutations = Object.create(null); |
| 9665 |
store._wrappedGetters = Object.create(null); |
| 9666 |
store._modulesNamespaceMap = Object.create(null); |
| 9667 |
var state = store.state; |
| 9668 |
// init all modules |
| 9669 |
installModule(store, state, [], store._modules.root, true); |
| 9670 |
// reset vm |
| 9671 |
resetStoreVM(store, state, hot); |
| 9672 |
} |
| 9673 |
|
| 9674 |
function resetStoreVM (store, state, hot) { |
| 9675 |
var oldVm = store._vm; |
| 9676 |
|
| 9677 |
// bind store public getters |
| 9678 |
store.getters = {}; |
| 9679 |
var wrappedGetters = store._wrappedGetters; |
| 9680 |
var computed = {}; |
| 9681 |
forEachValue(wrappedGetters, function (fn, key) { |
| 9682 |
// use computed to leverage its lazy-caching mechanism |
| 9683 |
computed[key] = function () { return fn(store); }; |
| 9684 |
Object.defineProperty(store.getters, key, { |
| 9685 |
get: function () { return store._vm[key]; }, |
| 9686 |
enumerable: true // for local getters |
| 9687 |
}); |
| 9688 |
}); |
| 9689 |
|
| 9690 |
// use a Vue instance to store the state tree |
| 9691 |
// suppress warnings just in case the user has added |
| 9692 |
// some funky global mixins |
| 9693 |
var silent = Vue.config.silent; |
| 9694 |
Vue.config.silent = true; |
| 9695 |
store._vm = new Vue({ |
| 9696 |
data: { |
| 9697 |
$$state: state |
| 9698 |
}, |
| 9699 |
computed: computed |
| 9700 |
}); |
| 9701 |
Vue.config.silent = silent; |
| 9702 |
|
| 9703 |
// enable strict mode for new vm |
| 9704 |
if (store.strict) { |
| 9705 |
enableStrictMode(store); |
| 9706 |
} |
| 9707 |
|
| 9708 |
if (oldVm) { |
| 9709 |
if (hot) { |
| 9710 |
// dispatch changes in all subscribed watchers |
| 9711 |
// to force getter re-evaluation for hot reloading. |
| 9712 |
store._withCommit(function () { |
| 9713 |
oldVm._data.$$state = null; |
| 9714 |
}); |
| 9715 |
} |
| 9716 |
Vue.nextTick(function () { return oldVm.$destroy(); }); |
| 9717 |
} |
| 9718 |
} |
| 9719 |
|
| 9720 |
function installModule (store, rootState, path, module, hot) { |
| 9721 |
var isRoot = !path.length; |
| 9722 |
var namespace = store._modules.getNamespace(path); |
| 9723 |
|
| 9724 |
// register in namespace map |
| 9725 |
if (namespace) { |
| 9726 |
store._modulesNamespaceMap[namespace] = module; |
| 9727 |
} |
| 9728 |
|
| 9729 |
// set state |
| 9730 |
if (!isRoot && !hot) { |
| 9731 |
var parentState = getNestedState(rootState, path.slice(0, -1)); |
| 9732 |
var moduleName = path[path.length - 1]; |
| 9733 |
store._withCommit(function () { |
| 9734 |
Vue.set(parentState, moduleName, module.state); |
| 9735 |
}); |
| 9736 |
} |
| 9737 |
|
| 9738 |
var local = module.context = makeLocalContext(store, namespace, path); |
| 9739 |
|
| 9740 |
module.forEachMutation(function (mutation, key) { |
| 9741 |
var namespacedType = namespace + key; |
| 9742 |
registerMutation(store, namespacedType, mutation, local); |
| 9743 |
}); |
| 9744 |
|
| 9745 |
module.forEachAction(function (action, key) { |
| 9746 |
var namespacedType = namespace + key; |
| 9747 |
registerAction(store, namespacedType, action, local); |
| 9748 |
}); |
| 9749 |
|
| 9750 |
module.forEachGetter(function (getter, key) { |
| 9751 |
var namespacedType = namespace + key; |
| 9752 |
registerGetter(store, namespacedType, getter, local); |
| 9753 |
}); |
| 9754 |
|
| 9755 |
module.forEachChild(function (child, key) { |
| 9756 |
installModule(store, rootState, path.concat(key), child, hot); |
| 9757 |
}); |
| 9758 |
} |
| 9759 |
|
| 9760 |
/** |
| 9761 |
* make localized dispatch, commit, getters and state |
| 9762 |
* if there is no namespace, just use root ones |
| 9763 |
*/ |
| 9764 |
function makeLocalContext (store, namespace, path) { |
| 9765 |
var noNamespace = namespace === ''; |
| 9766 |
|
| 9767 |
var local = { |
| 9768 |
dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) { |
| 9769 |
var args = unifyObjectStyle(_type, _payload, _options); |
| 9770 |
var payload = args.payload; |
| 9771 |
var options = args.options; |
| 9772 |
var type = args.type; |
| 9773 |
|
| 9774 |
if (!options || !options.root) { |
| 9775 |
type = namespace + type; |
| 9776 |
if (!store._actions[type]) { |
| 9777 |
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type)); |
| 9778 |
return |
| 9779 |
} |
| 9780 |
} |
| 9781 |
|
| 9782 |
return store.dispatch(type, payload) |
| 9783 |
}, |
| 9784 |
|
| 9785 |
commit: noNamespace ? store.commit : function (_type, _payload, _options) { |
| 9786 |
var args = unifyObjectStyle(_type, _payload, _options); |
| 9787 |
var payload = args.payload; |
| 9788 |
var options = args.options; |
| 9789 |
var type = args.type; |
| 9790 |
|
| 9791 |
if (!options || !options.root) { |
| 9792 |
type = namespace + type; |
| 9793 |
if (!store._mutations[type]) { |
| 9794 |
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type)); |
| 9795 |
return |
| 9796 |
} |
| 9797 |
} |
| 9798 |
|
| 9799 |
store.commit(type, payload, options); |
| 9800 |
} |
| 9801 |
}; |
| 9802 |
|
| 9803 |
// getters and state object must be gotten lazily |
| 9804 |
// because they will be changed by vm update |
| 9805 |
Object.defineProperties(local, { |
| 9806 |
getters: { |
| 9807 |
get: noNamespace |
| 9808 |
? function () { return store.getters; } |
| 9809 |
: function () { return makeLocalGetters(store, namespace); } |
| 9810 |
}, |
| 9811 |
state: { |
| 9812 |
get: function () { return getNestedState(store.state, path); } |
| 9813 |
} |
| 9814 |
}); |
| 9815 |
|
| 9816 |
return local |
| 9817 |
} |
| 9818 |
|
| 9819 |
function makeLocalGetters (store, namespace) { |
| 9820 |
var gettersProxy = {}; |
| 9821 |
|
| 9822 |
var splitPos = namespace.length; |
| 9823 |
Object.keys(store.getters).forEach(function (type) { |
| 9824 |
// skip if the target getter is not match this namespace |
| 9825 |
if (type.slice(0, splitPos) !== namespace) { return } |
| 9826 |
|
| 9827 |
// extract local getter type |
| 9828 |
var localType = type.slice(splitPos); |
| 9829 |
|
| 9830 |
// Add a port to the getters proxy. |
| 9831 |
// Define as getter property because |
| 9832 |
// we do not want to evaluate the getters in this time. |
| 9833 |
Object.defineProperty(gettersProxy, localType, { |
| 9834 |
get: function () { return store.getters[type]; }, |
| 9835 |
enumerable: true |
| 9836 |
}); |
| 9837 |
}); |
| 9838 |
|
| 9839 |
return gettersProxy |
| 9840 |
} |
| 9841 |
|
| 9842 |
function registerMutation (store, type, handler, local) { |
| 9843 |
var entry = store._mutations[type] || (store._mutations[type] = []); |
| 9844 |
entry.push(function wrappedMutationHandler (payload) { |
| 9845 |
handler(local.state, payload); |
| 9846 |
}); |
| 9847 |
} |
| 9848 |
|
| 9849 |
function registerAction (store, type, handler, local) { |
| 9850 |
var entry = store._actions[type] || (store._actions[type] = []); |
| 9851 |
entry.push(function wrappedActionHandler (payload, cb) { |
| 9852 |
var res = handler({ |
| 9853 |
dispatch: local.dispatch, |
| 9854 |
commit: local.commit, |
| 9855 |
getters: local.getters, |
| 9856 |
state: local.state, |
| 9857 |
rootGetters: store.getters, |
| 9858 |
rootState: store.state |
| 9859 |
}, payload, cb); |
| 9860 |
if (!isPromise(res)) { |
| 9861 |
res = Promise.resolve(res); |
| 9862 |
} |
| 9863 |
if (store._devtoolHook) { |
| 9864 |
return res.catch(function (err) { |
| 9865 |
store._devtoolHook.emit('vuex:error', err); |
| 9866 |
throw err |
| 9867 |
}) |
| 9868 |
} else { |
| 9869 |
return res |
| 9870 |
} |
| 9871 |
}); |
| 9872 |
} |
| 9873 |
|
| 9874 |
function registerGetter (store, type, rawGetter, local) { |
| 9875 |
if (store._wrappedGetters[type]) { |
| 9876 |
console.error(("[vuex] duplicate getter key: " + type)); |
| 9877 |
return |
| 9878 |
} |
| 9879 |
store._wrappedGetters[type] = function wrappedGetter (store) { |
| 9880 |
return rawGetter( |
| 9881 |
local.state, // local state |
| 9882 |
local.getters, // local getters |
| 9883 |
store.state, // root state |
| 9884 |
store.getters // root getters |
| 9885 |
) |
| 9886 |
}; |
| 9887 |
} |
| 9888 |
|
| 9889 |
function enableStrictMode (store) { |
| 9890 |
store._vm.$watch(function () { return this._data.$$state }, function () { |
| 9891 |
assert(store._committing, "Do not mutate vuex store state outside mutation handlers."); |
| 9892 |
}, { deep: true, sync: true }); |
| 9893 |
} |
| 9894 |
|
| 9895 |
function getNestedState (state, path) { |
| 9896 |
return path.length |
| 9897 |
? path.reduce(function (state, key) { return state[key]; }, state) |
| 9898 |
: state |
| 9899 |
} |
| 9900 |
|
| 9901 |
function unifyObjectStyle (type, payload, options) { |
| 9902 |
if (isObject(type) && type.type) { |
| 9903 |
options = payload; |
| 9904 |
payload = type; |
| 9905 |
type = type.type; |
| 9906 |
} |
| 9907 |
|
| 9908 |
assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + ".")); |
| 9909 |
|
| 9910 |
return { type: type, payload: payload, options: options } |
| 9911 |
} |
| 9912 |
|
| 9913 |
function install (_Vue) { |
| 9914 |
if (Vue) { |
| 9915 |
console.error( |
| 9916 |
'[vuex] already installed. Vue.use(Vuex) should be called only once.' |
| 9917 |
); |
| 9918 |
return |
| 9919 |
} |
| 9920 |
Vue = _Vue; |
| 9921 |
applyMixin(Vue); |
| 9922 |
} |
| 9923 |
|
| 9924 |
// auto install in dist mode |
| 9925 |
if (typeof window !== 'undefined' && window.Vue) { |
| 9926 |
install(window.Vue); |
| 9927 |
} |
| 9928 |
|
| 9929 |
var mapState = normalizeNamespace(function (namespace, states) { |
| 9930 |
var res = {}; |
| 9931 |
normalizeMap(states).forEach(function (ref) { |
| 9932 |
var key = ref.key; |
| 9933 |
var val = ref.val; |
| 9934 |
|
| 9935 |
res[key] = function mappedState () { |
| 9936 |
var state = this.$store.state; |
| 9937 |
var getters = this.$store.getters; |
| 9938 |
if (namespace) { |
| 9939 |
var module = getModuleByNamespace(this.$store, 'mapState', namespace); |
| 9940 |
if (!module) { |
| 9941 |
return |
| 9942 |
} |
| 9943 |
state = module.context.state; |
| 9944 |
getters = module.context.getters; |
| 9945 |
} |
| 9946 |
return typeof val === 'function' |
| 9947 |
? val.call(this, state, getters) |
| 9948 |
: state[val] |
| 9949 |
}; |
| 9950 |
// mark vuex getter for devtools |
| 9951 |
res[key].vuex = true; |
| 9952 |
}); |
| 9953 |
return res |
| 9954 |
}); |
| 9955 |
|
| 9956 |
var mapMutations = normalizeNamespace(function (namespace, mutations) { |
| 9957 |
var res = {}; |
| 9958 |
normalizeMap(mutations).forEach(function (ref) { |
| 9959 |
var key = ref.key; |
| 9960 |
var val = ref.val; |
| 9961 |
|
| 9962 |
val = namespace + val; |
| 9963 |
res[key] = function mappedMutation () { |
| 9964 |
var args = [], len = arguments.length; |
| 9965 |
while ( len-- ) args[ len ] = arguments[ len ]; |
| 9966 |
|
| 9967 |
if (namespace && !getModuleByNamespace(this.$store, 'mapMutations', namespace)) { |
| 9968 |
return |
| 9969 |
} |
| 9970 |
return this.$store.commit.apply(this.$store, [val].concat(args)) |
| 9971 |
}; |
| 9972 |
}); |
| 9973 |
return res |
| 9974 |
}); |
| 9975 |
|
| 9976 |
var mapGetters = normalizeNamespace(function (namespace, getters) { |
| 9977 |
var res = {}; |
| 9978 |
normalizeMap(getters).forEach(function (ref) { |
| 9979 |
var key = ref.key; |
| 9980 |
var val = ref.val; |
| 9981 |
|
| 9982 |
val = namespace + val; |
| 9983 |
res[key] = function mappedGetter () { |
| 9984 |
if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { |
| 9985 |
return |
| 9986 |
} |
| 9987 |
if (!(val in this.$store.getters)) { |
| 9988 |
console.error(("[vuex] unknown getter: " + val)); |
| 9989 |
return |
| 9990 |
} |
| 9991 |
return this.$store.getters[val] |
| 9992 |
}; |
| 9993 |
// mark vuex getter for devtools |
| 9994 |
res[key].vuex = true; |
| 9995 |
}); |
| 9996 |
return res |
| 9997 |
}); |
| 9998 |
|
| 9999 |
var mapActions = normalizeNamespace(function (namespace, actions) { |
| 10000 |
var res = {}; |
| 10001 |
normalizeMap(actions).forEach(function (ref) { |
| 10002 |
var key = ref.key; |
| 10003 |
var val = ref.val; |
| 10004 |
|
| 10005 |
val = namespace + val; |
| 10006 |
res[key] = function mappedAction () { |
| 10007 |
var args = [], len = arguments.length; |
| 10008 |
while ( len-- ) args[ len ] = arguments[ len ]; |
| 10009 |
|
| 10010 |
if (namespace && !getModuleByNamespace(this.$store, 'mapActions', namespace)) { |
| 10011 |
return |
| 10012 |
} |
| 10013 |
return this.$store.dispatch.apply(this.$store, [val].concat(args)) |
| 10014 |
}; |
| 10015 |
}); |
| 10016 |
return res |
| 10017 |
}); |
| 10018 |
|
| 10019 |
function normalizeMap (map) { |
| 10020 |
return Array.isArray(map) |
| 10021 |
? map.map(function (key) { return ({ key: key, val: key }); }) |
| 10022 |
: Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); }) |
| 10023 |
} |
| 10024 |
|
| 10025 |
function normalizeNamespace (fn) { |
| 10026 |
return function (namespace, map) { |
| 10027 |
if (typeof namespace !== 'string') { |
| 10028 |
map = namespace; |
| 10029 |
namespace = ''; |
| 10030 |
} else if (namespace.charAt(namespace.length - 1) !== '/') { |
| 10031 |
namespace += '/'; |
| 10032 |
} |
| 10033 |
return fn(namespace, map) |
| 10034 |
} |
| 10035 |
} |
| 10036 |
|
| 10037 |
function getModuleByNamespace (store, helper, namespace) { |
| 10038 |
var module = store._modulesNamespaceMap[namespace]; |
| 10039 |
if (!module) { |
| 10040 |
console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace)); |
| 10041 |
} |
| 10042 |
return module |
| 10043 |
} |
| 10044 |
|
| 10045 |
var index = { |
| 10046 |
Store: Store, |
| 10047 |
install: install, |
| 10048 |
version: '2.2.1', |
| 10049 |
mapState: mapState, |
| 10050 |
mapMutations: mapMutations, |
| 10051 |
mapGetters: mapGetters, |
| 10052 |
mapActions: mapActions |
| 10053 |
}; |
| 10054 |
|
| 10055 |
return index; |
| 10056 |
|
| 10057 |
}))); |
| 10058 |
|
| 10059 |
/* assets/js/vendor/vue-router.js */ |
| 10060 |
/** |
| 10061 |
* vue-router v2.3.1 |
| 10062 |
* (c) 2017 Evan You |
| 10063 |
* @license MIT |
| 10064 |
*/ |
| 10065 |
(function (global, factory) { |
| 10066 |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 10067 |
typeof define === 'function' && define.amd ? define(factory) : |
| 10068 |
(global.VueRouter = factory()); |
| 10069 |
}(this, (function () { 'use strict'; |
| 10070 |
|
| 10071 |
/* */ |
| 10072 |
|
| 10073 |
function assert (condition, message) { |
| 10074 |
if (!condition) { |
| 10075 |
throw new Error(("[vue-router] " + message)) |
| 10076 |
} |
| 10077 |
} |
| 10078 |
|
| 10079 |
function warn (condition, message) { |
| 10080 |
if (!condition) { |
| 10081 |
typeof console !== 'undefined' && console.warn(("[vue-router] " + message)); |
| 10082 |
} |
| 10083 |
} |
| 10084 |
|
| 10085 |
var View = { |
| 10086 |
name: 'router-view', |
| 10087 |
functional: true, |
| 10088 |
props: { |
| 10089 |
name: { |
| 10090 |
type: String, |
| 10091 |
default: 'default' |
| 10092 |
} |
| 10093 |
}, |
| 10094 |
render: function render (h, ref) { |
| 10095 |
var props = ref.props; |
| 10096 |
var children = ref.children; |
| 10097 |
var parent = ref.parent; |
| 10098 |
var data = ref.data; |
| 10099 |
|
| 10100 |
data.routerView = true; |
| 10101 |
|
| 10102 |
var name = props.name; |
| 10103 |
var route = parent.$route; |
| 10104 |
var cache = parent._routerViewCache || (parent._routerViewCache = {}); |
| 10105 |
|
| 10106 |
// determine current view depth, also check to see if the tree |
| 10107 |
// has been toggled inactive but kept-alive. |
| 10108 |
var depth = 0; |
| 10109 |
var inactive = false; |
| 10110 |
while (parent) { |
| 10111 |
if (parent.$vnode && parent.$vnode.data.routerView) { |
| 10112 |
depth++; |
| 10113 |
} |
| 10114 |
if (parent._inactive) { |
| 10115 |
inactive = true; |
| 10116 |
} |
| 10117 |
parent = parent.$parent; |
| 10118 |
} |
| 10119 |
data.routerViewDepth = depth; |
| 10120 |
|
| 10121 |
// render previous view if the tree is inactive and kept-alive |
| 10122 |
if (inactive) { |
| 10123 |
return h(cache[name], data, children) |
| 10124 |
} |
| 10125 |
|
| 10126 |
var matched = route.matched[depth]; |
| 10127 |
// render empty node if no matched route |
| 10128 |
if (!matched) { |
| 10129 |
cache[name] = null; |
| 10130 |
return h() |
| 10131 |
} |
| 10132 |
|
| 10133 |
var component = cache[name] = matched.components[name]; |
| 10134 |
|
| 10135 |
// inject instance registration hooks |
| 10136 |
var hooks = data.hook || (data.hook = {}); |
| 10137 |
hooks.init = function (vnode) { |
| 10138 |
matched.instances[name] = vnode.child; |
| 10139 |
}; |
| 10140 |
hooks.prepatch = function (oldVnode, vnode) { |
| 10141 |
matched.instances[name] = vnode.child; |
| 10142 |
}; |
| 10143 |
hooks.destroy = function (vnode) { |
| 10144 |
if (matched.instances[name] === vnode.child) { |
| 10145 |
matched.instances[name] = undefined; |
| 10146 |
} |
| 10147 |
}; |
| 10148 |
|
| 10149 |
// resolve props |
| 10150 |
data.props = resolveProps(route, matched.props && matched.props[name]); |
| 10151 |
|
| 10152 |
return h(component, data, children) |
| 10153 |
} |
| 10154 |
}; |
| 10155 |
|
| 10156 |
function resolveProps (route, config) { |
| 10157 |
switch (typeof config) { |
| 10158 |
case 'undefined': |
| 10159 |
return |
| 10160 |
case 'object': |
| 10161 |
return config |
| 10162 |
case 'function': |
| 10163 |
return config(route) |
| 10164 |
case 'boolean': |
| 10165 |
return config ? route.params : undefined |
| 10166 |
default: |
| 10167 |
warn(false, ("props in \"" + (route.path) + "\" is a " + (typeof config) + ", expecting an object, function or boolean.")); |
| 10168 |
} |
| 10169 |
} |
| 10170 |
|
| 10171 |
/* */ |
| 10172 |
|
| 10173 |
var encodeReserveRE = /[!'()*]/g; |
| 10174 |
var encodeReserveReplacer = function (c) { return '%' + c.charCodeAt(0).toString(16); }; |
| 10175 |
var commaRE = /%2C/g; |
| 10176 |
|
| 10177 |
// fixed encodeURIComponent which is more comformant to RFC3986: |
| 10178 |
// - escapes [!'()*] |
| 10179 |
// - preserve commas |
| 10180 |
var encode = function (str) { return encodeURIComponent(str) |
| 10181 |
.replace(encodeReserveRE, encodeReserveReplacer) |
| 10182 |
.replace(commaRE, ','); }; |
| 10183 |
|
| 10184 |
var decode = decodeURIComponent; |
| 10185 |
|
| 10186 |
function resolveQuery ( |
| 10187 |
query, |
| 10188 |
extraQuery |
| 10189 |
) { |
| 10190 |
if ( extraQuery === void 0 ) extraQuery = {}; |
| 10191 |
|
| 10192 |
if (query) { |
| 10193 |
var parsedQuery; |
| 10194 |
try { |
| 10195 |
parsedQuery = parseQuery(query); |
| 10196 |
} catch (e) { |
| 10197 |
"development" !== 'production' && warn(false, e.message); |
| 10198 |
parsedQuery = {}; |
| 10199 |
} |
| 10200 |
for (var key in extraQuery) { |
| 10201 |
parsedQuery[key] = extraQuery[key]; |
| 10202 |
} |
| 10203 |
return parsedQuery |
| 10204 |
} else { |
| 10205 |
return extraQuery |
| 10206 |
} |
| 10207 |
} |
| 10208 |
|
| 10209 |
function parseQuery (query) { |
| 10210 |
var res = {}; |
| 10211 |
|
| 10212 |
query = query.trim().replace(/^(\?|#|&)/, ''); |
| 10213 |
|
| 10214 |
if (!query) { |
| 10215 |
return res |
| 10216 |
} |
| 10217 |
|
| 10218 |
query.split('&').forEach(function (param) { |
| 10219 |
var parts = param.replace(/\+/g, ' ').split('='); |
| 10220 |
var key = decode(parts.shift()); |
| 10221 |
var val = parts.length > 0 |
| 10222 |
? decode(parts.join('=')) |
| 10223 |
: null; |
| 10224 |
|
| 10225 |
if (res[key] === undefined) { |
| 10226 |
res[key] = val; |
| 10227 |
} else if (Array.isArray(res[key])) { |
| 10228 |
res[key].push(val); |
| 10229 |
} else { |
| 10230 |
res[key] = [res[key], val]; |
| 10231 |
} |
| 10232 |
}); |
| 10233 |
|
| 10234 |
return res |
| 10235 |
} |
| 10236 |
|
| 10237 |
function stringifyQuery (obj) { |
| 10238 |
var res = obj ? Object.keys(obj).map(function (key) { |
| 10239 |
var val = obj[key]; |
| 10240 |
|
| 10241 |
if (val === undefined) { |
| 10242 |
return '' |
| 10243 |
} |
| 10244 |
|
| 10245 |
if (val === null) { |
| 10246 |
return encode(key) |
| 10247 |
} |
| 10248 |
|
| 10249 |
if (Array.isArray(val)) { |
| 10250 |
var result = []; |
| 10251 |
val.slice().forEach(function (val2) { |
| 10252 |
if (val2 === undefined) { |
| 10253 |
return |
| 10254 |
} |
| 10255 |
if (val2 === null) { |
| 10256 |
result.push(encode(key)); |
| 10257 |
} else { |
| 10258 |
result.push(encode(key) + '=' + encode(val2)); |
| 10259 |
} |
| 10260 |
}); |
| 10261 |
return result.join('&') |
| 10262 |
} |
| 10263 |
|
| 10264 |
return encode(key) + '=' + encode(val) |
| 10265 |
}).filter(function (x) { return x.length > 0; }).join('&') : null; |
| 10266 |
return res ? ("?" + res) : '' |
| 10267 |
} |
| 10268 |
|
| 10269 |
/* */ |
| 10270 |
|
| 10271 |
var trailingSlashRE = /\/?$/; |
| 10272 |
|
| 10273 |
function createRoute ( |
| 10274 |
record, |
| 10275 |
location, |
| 10276 |
redirectedFrom |
| 10277 |
) { |
| 10278 |
var route = { |
| 10279 |
name: location.name || (record && record.name), |
| 10280 |
meta: (record && record.meta) || {}, |
| 10281 |
path: location.path || '/', |
| 10282 |
hash: location.hash || '', |
| 10283 |
query: location.query || {}, |
| 10284 |
params: location.params || {}, |
| 10285 |
fullPath: getFullPath(location), |
| 10286 |
matched: record ? formatMatch(record) : [] |
| 10287 |
}; |
| 10288 |
if (redirectedFrom) { |
| 10289 |
route.redirectedFrom = getFullPath(redirectedFrom); |
| 10290 |
} |
| 10291 |
return Object.freeze(route) |
| 10292 |
} |
| 10293 |
|
| 10294 |
// the starting route that represents the initial state |
| 10295 |
var START = createRoute(null, { |
| 10296 |
path: '/' |
| 10297 |
}); |
| 10298 |
|
| 10299 |
function formatMatch (record) { |
| 10300 |
var res = []; |
| 10301 |
while (record) { |
| 10302 |
res.unshift(record); |
| 10303 |
record = record.parent; |
| 10304 |
} |
| 10305 |
return res |
| 10306 |
} |
| 10307 |
|
| 10308 |
function getFullPath (ref) { |
| 10309 |
var path = ref.path; |
| 10310 |
var query = ref.query; if ( query === void 0 ) query = {}; |
| 10311 |
var hash = ref.hash; if ( hash === void 0 ) hash = ''; |
| 10312 |
|
| 10313 |
return (path || '/') + stringifyQuery(query) + hash |
| 10314 |
} |
| 10315 |
|
| 10316 |
function isSameRoute (a, b) { |
| 10317 |
if (b === START) { |
| 10318 |
return a === b |
| 10319 |
} else if (!b) { |
| 10320 |
return false |
| 10321 |
} else if (a.path && b.path) { |
| 10322 |
return ( |
| 10323 |
a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') && |
| 10324 |
a.hash === b.hash && |
| 10325 |
isObjectEqual(a.query, b.query) |
| 10326 |
) |
| 10327 |
} else if (a.name && b.name) { |
| 10328 |
return ( |
| 10329 |
a.name === b.name && |
| 10330 |
a.hash === b.hash && |
| 10331 |
isObjectEqual(a.query, b.query) && |
| 10332 |
isObjectEqual(a.params, b.params) |
| 10333 |
) |
| 10334 |
} else { |
| 10335 |
return false |
| 10336 |
} |
| 10337 |
} |
| 10338 |
|
| 10339 |
function isObjectEqual (a, b) { |
| 10340 |
if ( a === void 0 ) a = {}; |
| 10341 |
if ( b === void 0 ) b = {}; |
| 10342 |
|
| 10343 |
var aKeys = Object.keys(a); |
| 10344 |
var bKeys = Object.keys(b); |
| 10345 |
if (aKeys.length !== bKeys.length) { |
| 10346 |
return false |
| 10347 |
} |
| 10348 |
return aKeys.every(function (key) { return String(a[key]) === String(b[key]); }) |
| 10349 |
} |
| 10350 |
|
| 10351 |
function isIncludedRoute (current, target) { |
| 10352 |
return ( |
| 10353 |
current.path.replace(trailingSlashRE, '/').indexOf( |
| 10354 |
target.path.replace(trailingSlashRE, '/') |
| 10355 |
) === 0 && |
| 10356 |
(!target.hash || current.hash === target.hash) && |
| 10357 |
queryIncludes(current.query, target.query) |
| 10358 |
) |
| 10359 |
} |
| 10360 |
|
| 10361 |
function queryIncludes (current, target) { |
| 10362 |
for (var key in target) { |
| 10363 |
if (!(key in current)) { |
| 10364 |
return false |
| 10365 |
} |
| 10366 |
} |
| 10367 |
return true |
| 10368 |
} |
| 10369 |
|
| 10370 |
/* */ |
| 10371 |
|
| 10372 |
// work around weird flow bug |
| 10373 |
var toTypes = [String, Object]; |
| 10374 |
var eventTypes = [String, Array]; |
| 10375 |
|
| 10376 |
var Link = { |
| 10377 |
name: 'router-link', |
| 10378 |
props: { |
| 10379 |
to: { |
| 10380 |
type: toTypes, |
| 10381 |
required: true |
| 10382 |
}, |
| 10383 |
tag: { |
| 10384 |
type: String, |
| 10385 |
default: 'a' |
| 10386 |
}, |
| 10387 |
exact: Boolean, |
| 10388 |
append: Boolean, |
| 10389 |
replace: Boolean, |
| 10390 |
activeClass: String, |
| 10391 |
event: { |
| 10392 |
type: eventTypes, |
| 10393 |
default: 'click' |
| 10394 |
} |
| 10395 |
}, |
| 10396 |
render: function render (h) { |
| 10397 |
var this$1 = this; |
| 10398 |
|
| 10399 |
var router = this.$router; |
| 10400 |
var current = this.$route; |
| 10401 |
var ref = router.resolve(this.to, current, this.append); |
| 10402 |
var location = ref.location; |
| 10403 |
var route = ref.route; |
| 10404 |
var href = ref.href; |
| 10405 |
var classes = {}; |
| 10406 |
var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active'; |
| 10407 |
var compareTarget = location.path ? createRoute(null, location) : route; |
| 10408 |
classes[activeClass] = this.exact |
| 10409 |
? isSameRoute(current, compareTarget) |
| 10410 |
: isIncludedRoute(current, compareTarget); |
| 10411 |
|
| 10412 |
var handler = function (e) { |
| 10413 |
if (guardEvent(e)) { |
| 10414 |
if (this$1.replace) { |
| 10415 |
router.replace(location); |
| 10416 |
} else { |
| 10417 |
router.push(location); |
| 10418 |
} |
| 10419 |
} |
| 10420 |
}; |
| 10421 |
|
| 10422 |
var on = { click: guardEvent }; |
| 10423 |
if (Array.isArray(this.event)) { |
| 10424 |
this.event.forEach(function (e) { on[e] = handler; }); |
| 10425 |
} else { |
| 10426 |
on[this.event] = handler; |
| 10427 |
} |
| 10428 |
|
| 10429 |
var data = { |
| 10430 |
class: classes |
| 10431 |
}; |
| 10432 |
|
| 10433 |
if (this.tag === 'a') { |
| 10434 |
data.on = on; |
| 10435 |
data.attrs = { href: href }; |
| 10436 |
} else { |
| 10437 |
// find the first <a> child and apply listener and href |
| 10438 |
var a = findAnchor(this.$slots.default); |
| 10439 |
if (a) { |
| 10440 |
// in case the <a> is a static node |
| 10441 |
a.isStatic = false; |
| 10442 |
var extend = _Vue.util.extend; |
| 10443 |
var aData = a.data = extend({}, a.data); |
| 10444 |
aData.on = on; |
| 10445 |
var aAttrs = a.data.attrs = extend({}, a.data.attrs); |
| 10446 |
aAttrs.href = href; |
| 10447 |
} else { |
| 10448 |
// doesn't have <a> child, apply listener to self |
| 10449 |
data.on = on; |
| 10450 |
} |
| 10451 |
} |
| 10452 |
|
| 10453 |
return h(this.tag, data, this.$slots.default) |
| 10454 |
} |
| 10455 |
}; |
| 10456 |
|
| 10457 |
function guardEvent (e) { |
| 10458 |
// don't redirect with control keys |
| 10459 |
if (e.metaKey || e.ctrlKey || e.shiftKey) { return } |
| 10460 |
// don't redirect when preventDefault called |
| 10461 |
if (e.defaultPrevented) { return } |
| 10462 |
// don't redirect on right click |
| 10463 |
if (e.button !== undefined && e.button !== 0) { return } |
| 10464 |
// don't redirect if `target="_blank"` |
| 10465 |
if (e.target && e.target.getAttribute) { |
| 10466 |
var target = e.target.getAttribute('target'); |
| 10467 |
if (/\b_blank\b/i.test(target)) { return } |
| 10468 |
} |
| 10469 |
// this may be a Weex event which doesn't have this method |
| 10470 |
if (e.preventDefault) { |
| 10471 |
e.preventDefault(); |
| 10472 |
} |
| 10473 |
return true |
| 10474 |
} |
| 10475 |
|
| 10476 |
function findAnchor (children) { |
| 10477 |
if (children) { |
| 10478 |
var child; |
| 10479 |
for (var i = 0; i < children.length; i++) { |
| 10480 |
child = children[i]; |
| 10481 |
if (child.tag === 'a') { |
| 10482 |
return child |
| 10483 |
} |
| 10484 |
if (child.children && (child = findAnchor(child.children))) { |
| 10485 |
return child |
| 10486 |
} |
| 10487 |
} |
| 10488 |
} |
| 10489 |
} |
| 10490 |
|
| 10491 |
var _Vue; |
| 10492 |
|
| 10493 |
function install (Vue) { |
| 10494 |
if (install.installed) { return } |
| 10495 |
install.installed = true; |
| 10496 |
|
| 10497 |
_Vue = Vue; |
| 10498 |
|
| 10499 |
Object.defineProperty(Vue.prototype, '$router', { |
| 10500 |
get: function get () { return this.$root._router } |
| 10501 |
}); |
| 10502 |
|
| 10503 |
Object.defineProperty(Vue.prototype, '$route', { |
| 10504 |
get: function get () { return this.$root._route } |
| 10505 |
}); |
| 10506 |
|
| 10507 |
Vue.mixin({ |
| 10508 |
beforeCreate: function beforeCreate () { |
| 10509 |
if (this.$options.router) { |
| 10510 |
this._router = this.$options.router; |
| 10511 |
this._router.init(this); |
| 10512 |
Vue.util.defineReactive(this, '_route', this._router.history.current); |
| 10513 |
} |
| 10514 |
} |
| 10515 |
}); |
| 10516 |
|
| 10517 |
Vue.component('router-view', View); |
| 10518 |
Vue.component('router-link', Link); |
| 10519 |
|
| 10520 |
var strats = Vue.config.optionMergeStrategies; |
| 10521 |
// use the same hook merging strategy for route hooks |
| 10522 |
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created; |
| 10523 |
} |
| 10524 |
|
| 10525 |
/* */ |
| 10526 |
|
| 10527 |
var inBrowser = typeof window !== 'undefined'; |
| 10528 |
|
| 10529 |
/* */ |
| 10530 |
|
| 10531 |
function resolvePath ( |
| 10532 |
relative, |
| 10533 |
base, |
| 10534 |
append |
| 10535 |
) { |
| 10536 |
if (relative.charAt(0) === '/') { |
| 10537 |
return relative |
| 10538 |
} |
| 10539 |
|
| 10540 |
if (relative.charAt(0) === '?' || relative.charAt(0) === '#') { |
| 10541 |
return base + relative |
| 10542 |
} |
| 10543 |
|
| 10544 |
var stack = base.split('/'); |
| 10545 |
|
| 10546 |
// remove trailing segment if: |
| 10547 |
// - not appending |
| 10548 |
// - appending to trailing slash (last segment is empty) |
| 10549 |
if (!append || !stack[stack.length - 1]) { |
| 10550 |
stack.pop(); |
| 10551 |
} |
| 10552 |
|
| 10553 |
// resolve relative path |
| 10554 |
var segments = relative.replace(/^\//, '').split('/'); |
| 10555 |
for (var i = 0; i < segments.length; i++) { |
| 10556 |
var segment = segments[i]; |
| 10557 |
if (segment === '.') { |
| 10558 |
continue |
| 10559 |
} else if (segment === '..') { |
| 10560 |
stack.pop(); |
| 10561 |
} else { |
| 10562 |
stack.push(segment); |
| 10563 |
} |
| 10564 |
} |
| 10565 |
|
| 10566 |
// ensure leading slash |
| 10567 |
if (stack[0] !== '') { |
| 10568 |
stack.unshift(''); |
| 10569 |
} |
| 10570 |
|
| 10571 |
return stack.join('/') |
| 10572 |
} |
| 10573 |
|
| 10574 |
function parsePath (path) { |
| 10575 |
var hash = ''; |
| 10576 |
var query = ''; |
| 10577 |
|
| 10578 |
var hashIndex = path.indexOf('#'); |
| 10579 |
if (hashIndex >= 0) { |
| 10580 |
hash = path.slice(hashIndex); |
| 10581 |
path = path.slice(0, hashIndex); |
| 10582 |
} |
| 10583 |
|
| 10584 |
var queryIndex = path.indexOf('?'); |
| 10585 |
if (queryIndex >= 0) { |
| 10586 |
query = path.slice(queryIndex + 1); |
| 10587 |
path = path.slice(0, queryIndex); |
| 10588 |
} |
| 10589 |
|
| 10590 |
return { |
| 10591 |
path: path, |
| 10592 |
query: query, |
| 10593 |
hash: hash |
| 10594 |
} |
| 10595 |
} |
| 10596 |
|
| 10597 |
function cleanPath (path) { |
| 10598 |
return path.replace(/\/\//g, '/') |
| 10599 |
} |
| 10600 |
|
| 10601 |
/* */ |
| 10602 |
|
| 10603 |
function createRouteMap ( |
| 10604 |
routes, |
| 10605 |
oldPathMap, |
| 10606 |
oldNameMap |
| 10607 |
) { |
| 10608 |
var pathMap = oldPathMap || Object.create(null); |
| 10609 |
var nameMap = oldNameMap || Object.create(null); |
| 10610 |
|
| 10611 |
routes.forEach(function (route) { |
| 10612 |
addRouteRecord(pathMap, nameMap, route); |
| 10613 |
}); |
| 10614 |
|
| 10615 |
return { |
| 10616 |
pathMap: pathMap, |
| 10617 |
nameMap: nameMap |
| 10618 |
} |
| 10619 |
} |
| 10620 |
|
| 10621 |
function addRouteRecord ( |
| 10622 |
pathMap, |
| 10623 |
nameMap, |
| 10624 |
route, |
| 10625 |
parent, |
| 10626 |
matchAs |
| 10627 |
) { |
| 10628 |
var path = route.path; |
| 10629 |
var name = route.name; |
| 10630 |
{ |
| 10631 |
assert(path != null, "\"path\" is required in a route configuration."); |
| 10632 |
assert( |
| 10633 |
typeof route.component !== 'string', |
| 10634 |
"route config \"component\" for path: " + (String(path || name)) + " cannot be a " + |
| 10635 |
"string id. Use an actual component instead." |
| 10636 |
); |
| 10637 |
} |
| 10638 |
|
| 10639 |
var record = { |
| 10640 |
path: normalizePath(path, parent), |
| 10641 |
components: route.components || { default: route.component }, |
| 10642 |
instances: {}, |
| 10643 |
name: name, |
| 10644 |
parent: parent, |
| 10645 |
matchAs: matchAs, |
| 10646 |
redirect: route.redirect, |
| 10647 |
beforeEnter: route.beforeEnter, |
| 10648 |
meta: route.meta || {}, |
| 10649 |
props: route.props == null |
| 10650 |
? {} |
| 10651 |
: route.components |
| 10652 |
? route.props |
| 10653 |
: { default: route.props } |
| 10654 |
}; |
| 10655 |
|
| 10656 |
if (route.children) { |
| 10657 |
// Warn if route is named and has a default child route. |
| 10658 |
// If users navigate to this route by name, the default child will |
| 10659 |
// not be rendered (GH Issue #629) |
| 10660 |
{ |
| 10661 |
if (route.name && route.children.some(function (child) { return /^\/?$/.test(child.path); })) { |
| 10662 |
warn( |
| 10663 |
false, |
| 10664 |
"Named Route '" + (route.name) + "' has a default child route. " + |
| 10665 |
"When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), " + |
| 10666 |
"the default child route will not be rendered. Remove the name from " + |
| 10667 |
"this route and use the name of the default child route for named " + |
| 10668 |
"links instead." |
| 10669 |
); |
| 10670 |
} |
| 10671 |
} |
| 10672 |
route.children.forEach(function (child) { |
| 10673 |
var childMatchAs = matchAs |
| 10674 |
? cleanPath((matchAs + "/" + (child.path))) |
| 10675 |
: undefined; |
| 10676 |
addRouteRecord(pathMap, nameMap, child, record, childMatchAs); |
| 10677 |
}); |
| 10678 |
} |
| 10679 |
|
| 10680 |
if (route.alias !== undefined) { |
| 10681 |
if (Array.isArray(route.alias)) { |
| 10682 |
route.alias.forEach(function (alias) { |
| 10683 |
var aliasRoute = { |
| 10684 |
path: alias, |
| 10685 |
children: route.children |
| 10686 |
}; |
| 10687 |
addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path); |
| 10688 |
}); |
| 10689 |
} else { |
| 10690 |
var aliasRoute = { |
| 10691 |
path: route.alias, |
| 10692 |
children: route.children |
| 10693 |
}; |
| 10694 |
addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path); |
| 10695 |
} |
| 10696 |
} |
| 10697 |
|
| 10698 |
if (!pathMap[record.path]) { |
| 10699 |
pathMap[record.path] = record; |
| 10700 |
} |
| 10701 |
|
| 10702 |
if (name) { |
| 10703 |
if (!nameMap[name]) { |
| 10704 |
nameMap[name] = record; |
| 10705 |
} else if ("development" !== 'production' && !matchAs) { |
| 10706 |
warn( |
| 10707 |
false, |
| 10708 |
"Duplicate named routes definition: " + |
| 10709 |
"{ name: \"" + name + "\", path: \"" + (record.path) + "\" }" |
| 10710 |
); |
| 10711 |
} |
| 10712 |
} |
| 10713 |
} |
| 10714 |
|
| 10715 |
function normalizePath (path, parent) { |
| 10716 |
path = path.replace(/\/$/, ''); |
| 10717 |
if (path[0] === '/') { return path } |
| 10718 |
if (parent == null) { return path } |
| 10719 |
return cleanPath(((parent.path) + "/" + path)) |
| 10720 |
} |
| 10721 |
|
| 10722 |
var index$1 = Array.isArray || function (arr) { |
| 10723 |
return Object.prototype.toString.call(arr) == '[object Array]'; |
| 10724 |
}; |
| 10725 |
|
| 10726 |
var isarray = index$1; |
| 10727 |
|
| 10728 |
/** |
| 10729 |
* Expose `pathToRegexp`. |
| 10730 |
*/ |
| 10731 |
var index = pathToRegexp; |
| 10732 |
var parse_1 = parse; |
| 10733 |
var compile_1 = compile; |
| 10734 |
var tokensToFunction_1 = tokensToFunction; |
| 10735 |
var tokensToRegExp_1 = tokensToRegExp; |
| 10736 |
|
| 10737 |
/** |
| 10738 |
* The main path matching regexp utility. |
| 10739 |
* |
| 10740 |
* @type {RegExp} |
| 10741 |
*/ |
| 10742 |
var PATH_REGEXP = new RegExp([ |
| 10743 |
// Match escaped characters that would otherwise appear in future matches. |
| 10744 |
// This allows the user to escape special characters that won't transform. |
| 10745 |
'(\\\\.)', |
| 10746 |
// Match Express-style parameters and un-named parameters with a prefix |
| 10747 |
// and optional suffixes. Matches appear as: |
| 10748 |
// |
| 10749 |
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined] |
| 10750 |
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined] |
| 10751 |
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"] |
| 10752 |
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))' |
| 10753 |
].join('|'), 'g'); |
| 10754 |
|
| 10755 |
/** |
| 10756 |
* Parse a string for the raw tokens. |
| 10757 |
* |
| 10758 |
* @param {string} str |
| 10759 |
* @param {Object=} options |
| 10760 |
* @return {!Array} |
| 10761 |
*/ |
| 10762 |
function parse (str, options) { |
| 10763 |
var tokens = []; |
| 10764 |
var key = 0; |
| 10765 |
var index = 0; |
| 10766 |
var path = ''; |
| 10767 |
var defaultDelimiter = options && options.delimiter || '/'; |
| 10768 |
var res; |
| 10769 |
|
| 10770 |
while ((res = PATH_REGEXP.exec(str)) != null) { |
| 10771 |
var m = res[0]; |
| 10772 |
var escaped = res[1]; |
| 10773 |
var offset = res.index; |
| 10774 |
path += str.slice(index, offset); |
| 10775 |
index = offset + m.length; |
| 10776 |
|
| 10777 |
// Ignore already escaped sequences. |
| 10778 |
if (escaped) { |
| 10779 |
path += escaped[1]; |
| 10780 |
continue |
| 10781 |
} |
| 10782 |
|
| 10783 |
var next = str[index]; |
| 10784 |
var prefix = res[2]; |
| 10785 |
var name = res[3]; |
| 10786 |
var capture = res[4]; |
| 10787 |
var group = res[5]; |
| 10788 |
var modifier = res[6]; |
| 10789 |
var asterisk = res[7]; |
| 10790 |
|
| 10791 |
// Push the current path onto the tokens. |
| 10792 |
if (path) { |
| 10793 |
tokens.push(path); |
| 10794 |
path = ''; |
| 10795 |
} |
| 10796 |
|
| 10797 |
var partial = prefix != null && next != null && next !== prefix; |
| 10798 |
var repeat = modifier === '+' || modifier === '*'; |
| 10799 |
var optional = modifier === '?' || modifier === '*'; |
| 10800 |
var delimiter = res[2] || defaultDelimiter; |
| 10801 |
var pattern = capture || group; |
| 10802 |
|
| 10803 |
tokens.push({ |
| 10804 |
name: name || key++, |
| 10805 |
prefix: prefix || '', |
| 10806 |
delimiter: delimiter, |
| 10807 |
optional: optional, |
| 10808 |
repeat: repeat, |
| 10809 |
partial: partial, |
| 10810 |
asterisk: !!asterisk, |
| 10811 |
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') |
| 10812 |
}); |
| 10813 |
} |
| 10814 |
|
| 10815 |
// Match any characters still remaining. |
| 10816 |
if (index < str.length) { |
| 10817 |
path += str.substr(index); |
| 10818 |
} |
| 10819 |
|
| 10820 |
// If the path exists, push it onto the end. |
| 10821 |
if (path) { |
| 10822 |
tokens.push(path); |
| 10823 |
} |
| 10824 |
|
| 10825 |
return tokens |
| 10826 |
} |
| 10827 |
|
| 10828 |
/** |
| 10829 |
* Compile a string to a template function for the path. |
| 10830 |
* |
| 10831 |
* @param {string} str |
| 10832 |
* @param {Object=} options |
| 10833 |
* @return {!function(Object=, Object=)} |
| 10834 |
*/ |
| 10835 |
function compile (str, options) { |
| 10836 |
return tokensToFunction(parse(str, options)) |
| 10837 |
} |
| 10838 |
|
| 10839 |
/** |
| 10840 |
* Prettier encoding of URI path segments. |
| 10841 |
* |
| 10842 |
* @param {string} |
| 10843 |
* @return {string} |
| 10844 |
*/ |
| 10845 |
function encodeURIComponentPretty (str) { |
| 10846 |
return encodeURI(str).replace(/[\/?#]/g, function (c) { |
| 10847 |
return '%' + c.charCodeAt(0).toString(16).toUpperCase() |
| 10848 |
}) |
| 10849 |
} |
| 10850 |
|
| 10851 |
/** |
| 10852 |
* Encode the asterisk parameter. Similar to `pretty`, but allows slashes. |
| 10853 |
* |
| 10854 |
* @param {string} |
| 10855 |
* @return {string} |
| 10856 |
*/ |
| 10857 |
function encodeAsterisk (str) { |
| 10858 |
return encodeURI(str).replace(/[?#]/g, function (c) { |
| 10859 |
return '%' + c.charCodeAt(0).toString(16).toUpperCase() |
| 10860 |
}) |
| 10861 |
} |
| 10862 |
|
| 10863 |
/** |
| 10864 |
* Expose a method for transforming tokens into the path function. |
| 10865 |
*/ |
| 10866 |
function tokensToFunction (tokens) { |
| 10867 |
// Compile all the tokens into regexps. |
| 10868 |
var matches = new Array(tokens.length); |
| 10869 |
|
| 10870 |
// Compile all the patterns before compilation. |
| 10871 |
for (var i = 0; i < tokens.length; i++) { |
| 10872 |
if (typeof tokens[i] === 'object') { |
| 10873 |
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$'); |
| 10874 |
} |
| 10875 |
} |
| 10876 |
|
| 10877 |
return function (obj, opts) { |
| 10878 |
var path = ''; |
| 10879 |
var data = obj || {}; |
| 10880 |
var options = opts || {}; |
| 10881 |
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent; |
| 10882 |
|
| 10883 |
for (var i = 0; i < tokens.length; i++) { |
| 10884 |
var token = tokens[i]; |
| 10885 |
|
| 10886 |
if (typeof token === 'string') { |
| 10887 |
path += token; |
| 10888 |
|
| 10889 |
continue |
| 10890 |
} |
| 10891 |
|
| 10892 |
var value = data[token.name]; |
| 10893 |
var segment; |
| 10894 |
|
| 10895 |
if (value == null) { |
| 10896 |
if (token.optional) { |
| 10897 |
// Prepend partial segment prefixes. |
| 10898 |
if (token.partial) { |
| 10899 |
path += token.prefix; |
| 10900 |
} |
| 10901 |
|
| 10902 |
continue |
| 10903 |
} else { |
| 10904 |
throw new TypeError('Expected "' + token.name + '" to be defined') |
| 10905 |
} |
| 10906 |
} |
| 10907 |
|
| 10908 |
if (isarray(value)) { |
| 10909 |
if (!token.repeat) { |
| 10910 |
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`') |
| 10911 |
} |
| 10912 |
|
| 10913 |
if (value.length === 0) { |
| 10914 |
if (token.optional) { |
| 10915 |
continue |
| 10916 |
} else { |
| 10917 |
throw new TypeError('Expected "' + token.name + '" to not be empty') |
| 10918 |
} |
| 10919 |
} |
| 10920 |
|
| 10921 |
for (var j = 0; j < value.length; j++) { |
| 10922 |
segment = encode(value[j]); |
| 10923 |
|
| 10924 |
if (!matches[i].test(segment)) { |
| 10925 |
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`') |
| 10926 |
} |
| 10927 |
|
| 10928 |
path += (j === 0 ? token.prefix : token.delimiter) + segment; |
| 10929 |
} |
| 10930 |
|
| 10931 |
continue |
| 10932 |
} |
| 10933 |
|
| 10934 |
segment = token.asterisk ? encodeAsterisk(value) : encode(value); |
| 10935 |
|
| 10936 |
if (!matches[i].test(segment)) { |
| 10937 |
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"') |
| 10938 |
} |
| 10939 |
|
| 10940 |
path += token.prefix + segment; |
| 10941 |
} |
| 10942 |
|
| 10943 |
return path |
| 10944 |
} |
| 10945 |
} |
| 10946 |
|
| 10947 |
/** |
| 10948 |
* Escape a regular expression string. |
| 10949 |
* |
| 10950 |
* @param {string} str |
| 10951 |
* @return {string} |
| 10952 |
*/ |
| 10953 |
function escapeString (str) { |
| 10954 |
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1') |
| 10955 |
} |
| 10956 |
|
| 10957 |
/** |
| 10958 |
* Escape the capturing group by escaping special characters and meaning. |
| 10959 |
* |
| 10960 |
* @param {string} group |
| 10961 |
* @return {string} |
| 10962 |
*/ |
| 10963 |
function escapeGroup (group) { |
| 10964 |
return group.replace(/([=!:$\/()])/g, '\\$1') |
| 10965 |
} |
| 10966 |
|
| 10967 |
/** |
| 10968 |
* Attach the keys as a property of the regexp. |
| 10969 |
* |
| 10970 |
* @param {!RegExp} re |
| 10971 |
* @param {Array} keys |
| 10972 |
* @return {!RegExp} |
| 10973 |
*/ |
| 10974 |
function attachKeys (re, keys) { |
| 10975 |
re.keys = keys; |
| 10976 |
return re |
| 10977 |
} |
| 10978 |
|
| 10979 |
/** |
| 10980 |
* Get the flags for a regexp from the options. |
| 10981 |
* |
| 10982 |
* @param {Object} options |
| 10983 |
* @return {string} |
| 10984 |
*/ |
| 10985 |
function flags (options) { |
| 10986 |
return options.sensitive ? '' : 'i' |
| 10987 |
} |
| 10988 |
|
| 10989 |
/** |
| 10990 |
* Pull out keys from a regexp. |
| 10991 |
* |
| 10992 |
* @param {!RegExp} path |
| 10993 |
* @param {!Array} keys |
| 10994 |
* @return {!RegExp} |
| 10995 |
*/ |
| 10996 |
function regexpToRegexp (path, keys) { |
| 10997 |
// Use a negative lookahead to match only capturing groups. |
| 10998 |
var groups = path.source.match(/\((?!\?)/g); |
| 10999 |
|
| 11000 |
if (groups) { |
| 11001 |
for (var i = 0; i < groups.length; i++) { |
| 11002 |
keys.push({ |
| 11003 |
name: i, |
| 11004 |
prefix: null, |
| 11005 |
delimiter: null, |
| 11006 |
optional: false, |
| 11007 |
repeat: false, |
| 11008 |
partial: false, |
| 11009 |
asterisk: false, |
| 11010 |
pattern: null |
| 11011 |
}); |
| 11012 |
} |
| 11013 |
} |
| 11014 |
|
| 11015 |
return attachKeys(path, keys) |
| 11016 |
} |
| 11017 |
|
| 11018 |
/** |
| 11019 |
* Transform an array into a regexp. |
| 11020 |
* |
| 11021 |
* @param {!Array} path |
| 11022 |
* @param {Array} keys |
| 11023 |
* @param {!Object} options |
| 11024 |
* @return {!RegExp} |
| 11025 |
*/ |
| 11026 |
function arrayToRegexp (path, keys, options) { |
| 11027 |
var parts = []; |
| 11028 |
|
| 11029 |
for (var i = 0; i < path.length; i++) { |
| 11030 |
parts.push(pathToRegexp(path[i], keys, options).source); |
| 11031 |
} |
| 11032 |
|
| 11033 |
var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options)); |
| 11034 |
|
| 11035 |
return attachKeys(regexp, keys) |
| 11036 |
} |
| 11037 |
|
| 11038 |
/** |
| 11039 |
* Create a path regexp from string input. |
| 11040 |
* |
| 11041 |
* @param {string} path |
| 11042 |
* @param {!Array} keys |
| 11043 |
* @param {!Object} options |
| 11044 |
* @return {!RegExp} |
| 11045 |
*/ |
| 11046 |
function stringToRegexp (path, keys, options) { |
| 11047 |
return tokensToRegExp(parse(path, options), keys, options) |
| 11048 |
} |
| 11049 |
|
| 11050 |
/** |
| 11051 |
* Expose a function for taking tokens and returning a RegExp. |
| 11052 |
* |
| 11053 |
* @param {!Array} tokens |
| 11054 |
* @param {(Array|Object)=} keys |
| 11055 |
* @param {Object=} options |
| 11056 |
* @return {!RegExp} |
| 11057 |
*/ |
| 11058 |
function tokensToRegExp (tokens, keys, options) { |
| 11059 |
if (!isarray(keys)) { |
| 11060 |
options = /** @type {!Object} */ (keys || options); |
| 11061 |
keys = []; |
| 11062 |
} |
| 11063 |
|
| 11064 |
options = options || {}; |
| 11065 |
|
| 11066 |
var strict = options.strict; |
| 11067 |
var end = options.end !== false; |
| 11068 |
var route = ''; |
| 11069 |
|
| 11070 |
// Iterate over the tokens and create our regexp string. |
| 11071 |
for (var i = 0; i < tokens.length; i++) { |
| 11072 |
var token = tokens[i]; |
| 11073 |
|
| 11074 |
if (typeof token === 'string') { |
| 11075 |
route += escapeString(token); |
| 11076 |
} else { |
| 11077 |
var prefix = escapeString(token.prefix); |
| 11078 |
var capture = '(?:' + token.pattern + ')'; |
| 11079 |
|
| 11080 |
keys.push(token); |
| 11081 |
|
| 11082 |
if (token.repeat) { |
| 11083 |
capture += '(?:' + prefix + capture + ')*'; |
| 11084 |
} |
| 11085 |
|
| 11086 |
if (token.optional) { |
| 11087 |
if (!token.partial) { |
| 11088 |
capture = '(?:' + prefix + '(' + capture + '))?'; |
| 11089 |
} else { |
| 11090 |
capture = prefix + '(' + capture + ')?'; |
| 11091 |
} |
| 11092 |
} else { |
| 11093 |
capture = prefix + '(' + capture + ')'; |
| 11094 |
} |
| 11095 |
|
| 11096 |
route += capture; |
| 11097 |
} |
| 11098 |
} |
| 11099 |
|
| 11100 |
var delimiter = escapeString(options.delimiter || '/'); |
| 11101 |
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter; |
| 11102 |
|
| 11103 |
// In non-strict mode we allow a slash at the end of match. If the path to |
| 11104 |
// match already ends with a slash, we remove it for consistency. The slash |
| 11105 |
// is valid at the end of a path match, not in the middle. This is important |
| 11106 |
// in non-ending mode, where "/test/" shouldn't match "/test//route". |
| 11107 |
if (!strict) { |
| 11108 |
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'; |
| 11109 |
} |
| 11110 |
|
| 11111 |
if (end) { |
| 11112 |
route += '$'; |
| 11113 |
} else { |
| 11114 |
// In non-ending mode, we need the capturing groups to match as much as |
| 11115 |
// possible by using a positive lookahead to the end or next path segment. |
| 11116 |
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'; |
| 11117 |
} |
| 11118 |
|
| 11119 |
return attachKeys(new RegExp('^' + route, flags(options)), keys) |
| 11120 |
} |
| 11121 |
|
| 11122 |
/** |
| 11123 |
* Normalize the given path string, returning a regular expression. |
| 11124 |
* |
| 11125 |
* An empty array can be passed in for the keys, which will hold the |
| 11126 |
* placeholder key descriptions. For example, using `/user/:id`, `keys` will |
| 11127 |
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`. |
| 11128 |
* |
| 11129 |
* @param {(string|RegExp|Array)} path |
| 11130 |
* @param {(Array|Object)=} keys |
| 11131 |
* @param {Object=} options |
| 11132 |
* @return {!RegExp} |
| 11133 |
*/ |
| 11134 |
function pathToRegexp (path, keys, options) { |
| 11135 |
if (!isarray(keys)) { |
| 11136 |
options = /** @type {!Object} */ (keys || options); |
| 11137 |
keys = []; |
| 11138 |
} |
| 11139 |
|
| 11140 |
options = options || {}; |
| 11141 |
|
| 11142 |
if (path instanceof RegExp) { |
| 11143 |
return regexpToRegexp(path, /** @type {!Array} */ (keys)) |
| 11144 |
} |
| 11145 |
|
| 11146 |
if (isarray(path)) { |
| 11147 |
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options) |
| 11148 |
} |
| 11149 |
|
| 11150 |
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options) |
| 11151 |
} |
| 11152 |
|
| 11153 |
index.parse = parse_1; |
| 11154 |
index.compile = compile_1; |
| 11155 |
index.tokensToFunction = tokensToFunction_1; |
| 11156 |
index.tokensToRegExp = tokensToRegExp_1; |
| 11157 |
|
| 11158 |
/* */ |
| 11159 |
|
| 11160 |
var regexpCache = Object.create(null); |
| 11161 |
|
| 11162 |
function getRouteRegex (path) { |
| 11163 |
var hit = regexpCache[path]; |
| 11164 |
var keys, regexp; |
| 11165 |
|
| 11166 |
if (hit) { |
| 11167 |
keys = hit.keys; |
| 11168 |
regexp = hit.regexp; |
| 11169 |
} else { |
| 11170 |
keys = []; |
| 11171 |
regexp = index(path, keys); |
| 11172 |
regexpCache[path] = { keys: keys, regexp: regexp }; |
| 11173 |
} |
| 11174 |
|
| 11175 |
return { keys: keys, regexp: regexp } |
| 11176 |
} |
| 11177 |
|
| 11178 |
var regexpCompileCache = Object.create(null); |
| 11179 |
|
| 11180 |
function fillParams ( |
| 11181 |
path, |
| 11182 |
params, |
| 11183 |
routeMsg |
| 11184 |
) { |
| 11185 |
try { |
| 11186 |
var filler = |
| 11187 |
regexpCompileCache[path] || |
| 11188 |
(regexpCompileCache[path] = index.compile(path)); |
| 11189 |
return filler(params || {}, { pretty: true }) |
| 11190 |
} catch (e) { |
| 11191 |
{ |
| 11192 |
warn(false, ("missing param for " + routeMsg + ": " + (e.message))); |
| 11193 |
} |
| 11194 |
return '' |
| 11195 |
} |
| 11196 |
} |
| 11197 |
|
| 11198 |
/* */ |
| 11199 |
|
| 11200 |
function normalizeLocation ( |
| 11201 |
raw, |
| 11202 |
current, |
| 11203 |
append |
| 11204 |
) { |
| 11205 |
var next = typeof raw === 'string' ? { path: raw } : raw; |
| 11206 |
// named target |
| 11207 |
if (next.name || next._normalized) { |
| 11208 |
return next |
| 11209 |
} |
| 11210 |
|
| 11211 |
// relative params |
| 11212 |
if (!next.path && next.params && current) { |
| 11213 |
next = assign({}, next); |
| 11214 |
next._normalized = true; |
| 11215 |
var params = assign(assign({}, current.params), next.params); |
| 11216 |
if (current.name) { |
| 11217 |
next.name = current.name; |
| 11218 |
next.params = params; |
| 11219 |
} else if (current.matched) { |
| 11220 |
var rawPath = current.matched[current.matched.length - 1].path; |
| 11221 |
next.path = fillParams(rawPath, params, ("path " + (current.path))); |
| 11222 |
} else { |
| 11223 |
warn(false, "relative params navigation requires a current route."); |
| 11224 |
} |
| 11225 |
return next |
| 11226 |
} |
| 11227 |
|
| 11228 |
var parsedPath = parsePath(next.path || ''); |
| 11229 |
var basePath = (current && current.path) || '/'; |
| 11230 |
var path = parsedPath.path |
| 11231 |
? resolvePath(parsedPath.path, basePath, append || next.append) |
| 11232 |
: (current && current.path) || '/'; |
| 11233 |
var query = resolveQuery(parsedPath.query, next.query); |
| 11234 |
var hash = next.hash || parsedPath.hash; |
| 11235 |
if (hash && hash.charAt(0) !== '#') { |
| 11236 |
hash = "#" + hash; |
| 11237 |
} |
| 11238 |
|
| 11239 |
return { |
| 11240 |
_normalized: true, |
| 11241 |
path: path, |
| 11242 |
query: query, |
| 11243 |
hash: hash |
| 11244 |
} |
| 11245 |
} |
| 11246 |
|
| 11247 |
function assign (a, b) { |
| 11248 |
for (var key in b) { |
| 11249 |
a[key] = b[key]; |
| 11250 |
} |
| 11251 |
return a |
| 11252 |
} |
| 11253 |
|
| 11254 |
/* */ |
| 11255 |
|
| 11256 |
function createMatcher (routes) { |
| 11257 |
var ref = createRouteMap(routes); |
| 11258 |
var pathMap = ref.pathMap; |
| 11259 |
var nameMap = ref.nameMap; |
| 11260 |
|
| 11261 |
function addRoutes (routes) { |
| 11262 |
createRouteMap(routes, pathMap, nameMap); |
| 11263 |
} |
| 11264 |
|
| 11265 |
function match ( |
| 11266 |
raw, |
| 11267 |
currentRoute, |
| 11268 |
redirectedFrom |
| 11269 |
) { |
| 11270 |
var location = normalizeLocation(raw, currentRoute); |
| 11271 |
var name = location.name; |
| 11272 |
|
| 11273 |
if (name) { |
| 11274 |
var record = nameMap[name]; |
| 11275 |
{ |
| 11276 |
warn(record, ("Route with name '" + name + "' does not exist")); |
| 11277 |
} |
| 11278 |
var paramNames = getRouteRegex(record.path).keys |
| 11279 |
.filter(function (key) { return !key.optional; }) |
| 11280 |
.map(function (key) { return key.name; }); |
| 11281 |
|
| 11282 |
if (typeof location.params !== 'object') { |
| 11283 |
location.params = {}; |
| 11284 |
} |
| 11285 |
|
| 11286 |
if (currentRoute && typeof currentRoute.params === 'object') { |
| 11287 |
for (var key in currentRoute.params) { |
| 11288 |
if (!(key in location.params) && paramNames.indexOf(key) > -1) { |
| 11289 |
location.params[key] = currentRoute.params[key]; |
| 11290 |
} |
| 11291 |
} |
| 11292 |
} |
| 11293 |
|
| 11294 |
if (record) { |
| 11295 |
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\"")); |
| 11296 |
return _createRoute(record, location, redirectedFrom) |
| 11297 |
} |
| 11298 |
} else if (location.path) { |
| 11299 |
location.params = {}; |
| 11300 |
for (var path in pathMap) { |
| 11301 |
if (matchRoute(path, location.params, location.path)) { |
| 11302 |
return _createRoute(pathMap[path], location, redirectedFrom) |
| 11303 |
} |
| 11304 |
} |
| 11305 |
} |
| 11306 |
// no match |
| 11307 |
return _createRoute(null, location) |
| 11308 |
} |
| 11309 |
|
| 11310 |
function redirect ( |
| 11311 |
record, |
| 11312 |
location |
| 11313 |
) { |
| 11314 |
var originalRedirect = record.redirect; |
| 11315 |
var redirect = typeof originalRedirect === 'function' |
| 11316 |
? originalRedirect(createRoute(record, location)) |
| 11317 |
: originalRedirect; |
| 11318 |
|
| 11319 |
if (typeof redirect === 'string') { |
| 11320 |
redirect = { path: redirect }; |
| 11321 |
} |
| 11322 |
|
| 11323 |
if (!redirect || typeof redirect !== 'object') { |
| 11324 |
"development" !== 'production' && warn( |
| 11325 |
false, ("invalid redirect option: " + (JSON.stringify(redirect))) |
| 11326 |
); |
| 11327 |
return _createRoute(null, location) |
| 11328 |
} |
| 11329 |
|
| 11330 |
var re = redirect; |
| 11331 |
var name = re.name; |
| 11332 |
var path = re.path; |
| 11333 |
var query = location.query; |
| 11334 |
var hash = location.hash; |
| 11335 |
var params = location.params; |
| 11336 |
query = re.hasOwnProperty('query') ? re.query : query; |
| 11337 |
hash = re.hasOwnProperty('hash') ? re.hash : hash; |
| 11338 |
params = re.hasOwnProperty('params') ? re.params : params; |
| 11339 |
|
| 11340 |
if (name) { |
| 11341 |
// resolved named direct |
| 11342 |
var targetRecord = nameMap[name]; |
| 11343 |
{ |
| 11344 |
assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found.")); |
| 11345 |
} |
| 11346 |
return match({ |
| 11347 |
_normalized: true, |
| 11348 |
name: name, |
| 11349 |
query: query, |
| 11350 |
hash: hash, |
| 11351 |
params: params |
| 11352 |
}, undefined, location) |
| 11353 |
} else if (path) { |
| 11354 |
// 1. resolve relative redirect |
| 11355 |
var rawPath = resolveRecordPath(path, record); |
| 11356 |
// 2. resolve params |
| 11357 |
var resolvedPath = fillParams(rawPath, params, ("redirect route with path \"" + rawPath + "\"")); |
| 11358 |
// 3. rematch with existing query and hash |
| 11359 |
return match({ |
| 11360 |
_normalized: true, |
| 11361 |
path: resolvedPath, |
| 11362 |
query: query, |
| 11363 |
hash: hash |
| 11364 |
}, undefined, location) |
| 11365 |
} else { |
| 11366 |
warn(false, ("invalid redirect option: " + (JSON.stringify(redirect)))); |
| 11367 |
return _createRoute(null, location) |
| 11368 |
} |
| 11369 |
} |
| 11370 |
|
| 11371 |
function alias ( |
| 11372 |
record, |
| 11373 |
location, |
| 11374 |
matchAs |
| 11375 |
) { |
| 11376 |
var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\"")); |
| 11377 |
var aliasedMatch = match({ |
| 11378 |
_normalized: true, |
| 11379 |
path: aliasedPath |
| 11380 |
}); |
| 11381 |
if (aliasedMatch) { |
| 11382 |
var matched = aliasedMatch.matched; |
| 11383 |
var aliasedRecord = matched[matched.length - 1]; |
| 11384 |
location.params = aliasedMatch.params; |
| 11385 |
return _createRoute(aliasedRecord, location) |
| 11386 |
} |
| 11387 |
return _createRoute(null, location) |
| 11388 |
} |
| 11389 |
|
| 11390 |
function _createRoute ( |
| 11391 |
record, |
| 11392 |
location, |
| 11393 |
redirectedFrom |
| 11394 |
) { |
| 11395 |
if (record && record.redirect) { |
| 11396 |
return redirect(record, redirectedFrom || location) |
| 11397 |
} |
| 11398 |
if (record && record.matchAs) { |
| 11399 |
return alias(record, location, record.matchAs) |
| 11400 |
} |
| 11401 |
return createRoute(record, location, redirectedFrom) |
| 11402 |
} |
| 11403 |
|
| 11404 |
return { |
| 11405 |
match: match, |
| 11406 |
addRoutes: addRoutes |
| 11407 |
} |
| 11408 |
} |
| 11409 |
|
| 11410 |
function matchRoute ( |
| 11411 |
path, |
| 11412 |
params, |
| 11413 |
pathname |
| 11414 |
) { |
| 11415 |
var ref = getRouteRegex(path); |
| 11416 |
var regexp = ref.regexp; |
| 11417 |
var keys = ref.keys; |
| 11418 |
var m = pathname.match(regexp); |
| 11419 |
|
| 11420 |
if (!m) { |
| 11421 |
return false |
| 11422 |
} else if (!params) { |
| 11423 |
return true |
| 11424 |
} |
| 11425 |
|
| 11426 |
for (var i = 1, len = m.length; i < len; ++i) { |
| 11427 |
var key = keys[i - 1]; |
| 11428 |
var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; |
| 11429 |
if (key) { params[key.name] = val; } |
| 11430 |
} |
| 11431 |
|
| 11432 |
return true |
| 11433 |
} |
| 11434 |
|
| 11435 |
function resolveRecordPath (path, record) { |
| 11436 |
return resolvePath(path, record.parent ? record.parent.path : '/', true) |
| 11437 |
} |
| 11438 |
|
| 11439 |
/* */ |
| 11440 |
|
| 11441 |
|
| 11442 |
var positionStore = Object.create(null); |
| 11443 |
|
| 11444 |
function setupScroll () { |
| 11445 |
window.addEventListener('popstate', function (e) { |
| 11446 |
saveScrollPosition(); |
| 11447 |
if (e.state && e.state.key) { |
| 11448 |
setStateKey(e.state.key); |
| 11449 |
} |
| 11450 |
}); |
| 11451 |
} |
| 11452 |
|
| 11453 |
function handleScroll ( |
| 11454 |
router, |
| 11455 |
to, |
| 11456 |
from, |
| 11457 |
isPop |
| 11458 |
) { |
| 11459 |
if (!router.app) { |
| 11460 |
return |
| 11461 |
} |
| 11462 |
|
| 11463 |
var behavior = router.options.scrollBehavior; |
| 11464 |
if (!behavior) { |
| 11465 |
return |
| 11466 |
} |
| 11467 |
|
| 11468 |
{ |
| 11469 |
assert(typeof behavior === 'function', "scrollBehavior must be a function"); |
| 11470 |
} |
| 11471 |
|
| 11472 |
// wait until re-render finishes before scrolling |
| 11473 |
router.app.$nextTick(function () { |
| 11474 |
var position = getScrollPosition(); |
| 11475 |
var shouldScroll = behavior(to, from, isPop ? position : null); |
| 11476 |
if (!shouldScroll) { |
| 11477 |
return |
| 11478 |
} |
| 11479 |
var isObject = typeof shouldScroll === 'object'; |
| 11480 |
if (isObject && typeof shouldScroll.selector === 'string') { |
| 11481 |
var el = document.querySelector(shouldScroll.selector); |
| 11482 |
if (el) { |
| 11483 |
position = getElementPosition(el); |
| 11484 |
} else if (isValidPosition(shouldScroll)) { |
| 11485 |
position = normalizePosition(shouldScroll); |
| 11486 |
} |
| 11487 |
} else if (isObject && isValidPosition(shouldScroll)) { |
| 11488 |
position = normalizePosition(shouldScroll); |
| 11489 |
} |
| 11490 |
|
| 11491 |
if (position) { |
| 11492 |
window.scrollTo(position.x, position.y); |
| 11493 |
} |
| 11494 |
}); |
| 11495 |
} |
| 11496 |
|
| 11497 |
function saveScrollPosition () { |
| 11498 |
var key = getStateKey(); |
| 11499 |
if (key) { |
| 11500 |
positionStore[key] = { |
| 11501 |
x: window.pageXOffset, |
| 11502 |
y: window.pageYOffset |
| 11503 |
}; |
| 11504 |
} |
| 11505 |
} |
| 11506 |
|
| 11507 |
function getScrollPosition () { |
| 11508 |
var key = getStateKey(); |
| 11509 |
if (key) { |
| 11510 |
return positionStore[key] |
| 11511 |
} |
| 11512 |
} |
| 11513 |
|
| 11514 |
function getElementPosition (el) { |
| 11515 |
var docEl = document.documentElement; |
| 11516 |
var docRect = docEl.getBoundingClientRect(); |
| 11517 |
var elRect = el.getBoundingClientRect(); |
| 11518 |
return { |
| 11519 |
x: elRect.left - docRect.left, |
| 11520 |
y: elRect.top - docRect.top |
| 11521 |
} |
| 11522 |
} |
| 11523 |
|
| 11524 |
function isValidPosition (obj) { |
| 11525 |
return isNumber(obj.x) || isNumber(obj.y) |
| 11526 |
} |
| 11527 |
|
| 11528 |
function normalizePosition (obj) { |
| 11529 |
return { |
| 11530 |
x: isNumber(obj.x) ? obj.x : window.pageXOffset, |
| 11531 |
y: isNumber(obj.y) ? obj.y : window.pageYOffset |
| 11532 |
} |
| 11533 |
} |
| 11534 |
|
| 11535 |
function isNumber (v) { |
| 11536 |
return typeof v === 'number' |
| 11537 |
} |
| 11538 |
|
| 11539 |
/* */ |
| 11540 |
|
| 11541 |
var supportsPushState = inBrowser && (function () { |
| 11542 |
var ua = window.navigator.userAgent; |
| 11543 |
|
| 11544 |
if ( |
| 11545 |
(ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && |
| 11546 |
ua.indexOf('Mobile Safari') !== -1 && |
| 11547 |
ua.indexOf('Chrome') === -1 && |
| 11548 |
ua.indexOf('Windows Phone') === -1 |
| 11549 |
) { |
| 11550 |
return false |
| 11551 |
} |
| 11552 |
|
| 11553 |
return window.history && 'pushState' in window.history |
| 11554 |
})(); |
| 11555 |
|
| 11556 |
// use User Timing api (if present) for more accurate key precision |
| 11557 |
var Time = inBrowser && window.performance && window.performance.now |
| 11558 |
? window.performance |
| 11559 |
: Date; |
| 11560 |
|
| 11561 |
var _key = genKey(); |
| 11562 |
|
| 11563 |
function genKey () { |
| 11564 |
return Time.now().toFixed(3) |
| 11565 |
} |
| 11566 |
|
| 11567 |
function getStateKey () { |
| 11568 |
return _key |
| 11569 |
} |
| 11570 |
|
| 11571 |
function setStateKey (key) { |
| 11572 |
_key = key; |
| 11573 |
} |
| 11574 |
|
| 11575 |
function pushState (url, replace) { |
| 11576 |
saveScrollPosition(); |
| 11577 |
// try...catch the pushState call to get around Safari |
| 11578 |
// DOM Exception 18 where it limits to 100 pushState calls |
| 11579 |
var history = window.history; |
| 11580 |
try { |
| 11581 |
if (replace) { |
| 11582 |
history.replaceState({ key: _key }, '', url); |
| 11583 |
} else { |
| 11584 |
_key = genKey(); |
| 11585 |
history.pushState({ key: _key }, '', url); |
| 11586 |
} |
| 11587 |
} catch (e) { |
| 11588 |
window.location[replace ? 'replace' : 'assign'](url); |
| 11589 |
} |
| 11590 |
} |
| 11591 |
|
| 11592 |
function replaceState (url) { |
| 11593 |
pushState(url, true); |
| 11594 |
} |
| 11595 |
|
| 11596 |
/* */ |
| 11597 |
|
| 11598 |
function runQueue (queue, fn, cb) { |
| 11599 |
var step = function (index) { |
| 11600 |
if (index >= queue.length) { |
| 11601 |
cb(); |
| 11602 |
} else { |
| 11603 |
if (queue[index]) { |
| 11604 |
fn(queue[index], function () { |
| 11605 |
step(index + 1); |
| 11606 |
}); |
| 11607 |
} else { |
| 11608 |
step(index + 1); |
| 11609 |
} |
| 11610 |
} |
| 11611 |
}; |
| 11612 |
step(0); |
| 11613 |
} |
| 11614 |
|
| 11615 |
/* */ |
| 11616 |
|
| 11617 |
|
| 11618 |
var History = function History (router, base) { |
| 11619 |
this.router = router; |
| 11620 |
this.base = normalizeBase(base); |
| 11621 |
// start with a route object that stands for "nowhere" |
| 11622 |
this.current = START; |
| 11623 |
this.pending = null; |
| 11624 |
this.ready = false; |
| 11625 |
this.readyCbs = []; |
| 11626 |
}; |
| 11627 |
|
| 11628 |
History.prototype.listen = function listen (cb) { |
| 11629 |
this.cb = cb; |
| 11630 |
}; |
| 11631 |
|
| 11632 |
History.prototype.onReady = function onReady (cb) { |
| 11633 |
if (this.ready) { |
| 11634 |
cb(); |
| 11635 |
} else { |
| 11636 |
this.readyCbs.push(cb); |
| 11637 |
} |
| 11638 |
}; |
| 11639 |
|
| 11640 |
History.prototype.transitionTo = function transitionTo (location, onComplete, onAbort) { |
| 11641 |
var this$1 = this; |
| 11642 |
|
| 11643 |
var route = this.router.match(location, this.current); |
| 11644 |
this.confirmTransition(route, function () { |
| 11645 |
this$1.updateRoute(route); |
| 11646 |
onComplete && onComplete(route); |
| 11647 |
this$1.ensureURL(); |
| 11648 |
|
| 11649 |
// fire ready cbs once |
| 11650 |
if (!this$1.ready) { |
| 11651 |
this$1.ready = true; |
| 11652 |
this$1.readyCbs.forEach(function (cb) { |
| 11653 |
cb(route); |
| 11654 |
}); |
| 11655 |
} |
| 11656 |
}, onAbort); |
| 11657 |
}; |
| 11658 |
|
| 11659 |
History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) { |
| 11660 |
var this$1 = this; |
| 11661 |
|
| 11662 |
var current = this.current; |
| 11663 |
var abort = function () { onAbort && onAbort(); }; |
| 11664 |
if ( |
| 11665 |
isSameRoute(route, current) && |
| 11666 |
// in the case the route map has been dynamically appended to |
| 11667 |
route.matched.length === current.matched.length |
| 11668 |
) { |
| 11669 |
this.ensureURL(); |
| 11670 |
return abort() |
| 11671 |
} |
| 11672 |
|
| 11673 |
var ref = resolveQueue(this.current.matched, route.matched); |
| 11674 |
var updated = ref.updated; |
| 11675 |
var deactivated = ref.deactivated; |
| 11676 |
var activated = ref.activated; |
| 11677 |
|
| 11678 |
var queue = [].concat( |
| 11679 |
// in-component leave guards |
| 11680 |
extractLeaveGuards(deactivated), |
| 11681 |
// global before hooks |
| 11682 |
this.router.beforeHooks, |
| 11683 |
// in-component update hooks |
| 11684 |
extractUpdateHooks(updated), |
| 11685 |
// in-config enter guards |
| 11686 |
activated.map(function (m) { return m.beforeEnter; }), |
| 11687 |
// async components |
| 11688 |
resolveAsyncComponents(activated) |
| 11689 |
); |
| 11690 |
|
| 11691 |
this.pending = route; |
| 11692 |
var iterator = function (hook, next) { |
| 11693 |
if (this$1.pending !== route) { |
| 11694 |
return abort() |
| 11695 |
} |
| 11696 |
hook(route, current, function (to) { |
| 11697 |
if (to === false) { |
| 11698 |
// next(false) -> abort navigation, ensure current URL |
| 11699 |
this$1.ensureURL(true); |
| 11700 |
abort(); |
| 11701 |
} else if (typeof to === 'string' || typeof to === 'object') { |
| 11702 |
// next('/') or next({ path: '/' }) -> redirect |
| 11703 |
(typeof to === 'object' && to.replace) ? this$1.replace(to) : this$1.push(to); |
| 11704 |
abort(); |
| 11705 |
} else { |
| 11706 |
// confirm transition and pass on the value |
| 11707 |
next(to); |
| 11708 |
} |
| 11709 |
}); |
| 11710 |
}; |
| 11711 |
|
| 11712 |
runQueue(queue, iterator, function () { |
| 11713 |
var postEnterCbs = []; |
| 11714 |
var isValid = function () { return this$1.current === route; }; |
| 11715 |
var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); |
| 11716 |
// wait until async components are resolved before |
| 11717 |
// extracting in-component enter guards |
| 11718 |
runQueue(enterGuards, iterator, function () { |
| 11719 |
if (this$1.pending !== route) { |
| 11720 |
return abort() |
| 11721 |
} |
| 11722 |
this$1.pending = null; |
| 11723 |
onComplete(route); |
| 11724 |
if (this$1.router.app) { |
| 11725 |
this$1.router.app.$nextTick(function () { |
| 11726 |
postEnterCbs.forEach(function (cb) { return cb(); }); |
| 11727 |
}); |
| 11728 |
} |
| 11729 |
}); |
| 11730 |
}); |
| 11731 |
}; |
| 11732 |
|
| 11733 |
History.prototype.updateRoute = function updateRoute (route) { |
| 11734 |
var prev = this.current; |
| 11735 |
this.current = route; |
| 11736 |
this.cb && this.cb(route); |
| 11737 |
this.router.afterHooks.forEach(function (hook) { |
| 11738 |
hook && hook(route, prev); |
| 11739 |
}); |
| 11740 |
}; |
| 11741 |
|
| 11742 |
function normalizeBase (base) { |
| 11743 |
if (!base) { |
| 11744 |
if (inBrowser) { |
| 11745 |
// respect <base> tag |
| 11746 |
var baseEl = document.querySelector('base'); |
| 11747 |
base = (baseEl && baseEl.getAttribute('href')) || '/'; |
| 11748 |
} else { |
| 11749 |
base = '/'; |
| 11750 |
} |
| 11751 |
} |
| 11752 |
// make sure there's the starting slash |
| 11753 |
if (base.charAt(0) !== '/') { |
| 11754 |
base = '/' + base; |
| 11755 |
} |
| 11756 |
// remove trailing slash |
| 11757 |
return base.replace(/\/$/, '') |
| 11758 |
} |
| 11759 |
|
| 11760 |
function resolveQueue ( |
| 11761 |
current, |
| 11762 |
next |
| 11763 |
) { |
| 11764 |
var i; |
| 11765 |
var max = Math.max(current.length, next.length); |
| 11766 |
for (i = 0; i < max; i++) { |
| 11767 |
if (current[i] !== next[i]) { |
| 11768 |
break |
| 11769 |
} |
| 11770 |
} |
| 11771 |
return { |
| 11772 |
updated: next.slice(0, i), |
| 11773 |
activated: next.slice(i), |
| 11774 |
deactivated: current.slice(i) |
| 11775 |
} |
| 11776 |
} |
| 11777 |
|
| 11778 |
function extractGuards ( |
| 11779 |
records, |
| 11780 |
name, |
| 11781 |
bind, |
| 11782 |
reverse |
| 11783 |
) { |
| 11784 |
var guards = flatMapComponents(records, function (def, instance, match, key) { |
| 11785 |
var guard = extractGuard(def, name); |
| 11786 |
if (guard) { |
| 11787 |
return Array.isArray(guard) |
| 11788 |
? guard.map(function (guard) { return bind(guard, instance, match, key); }) |
| 11789 |
: bind(guard, instance, match, key) |
| 11790 |
} |
| 11791 |
}); |
| 11792 |
return flatten(reverse ? guards.reverse() : guards) |
| 11793 |
} |
| 11794 |
|
| 11795 |
function extractGuard ( |
| 11796 |
def, |
| 11797 |
key |
| 11798 |
) { |
| 11799 |
if (typeof def !== 'function') { |
| 11800 |
// extend now so that global mixins are applied. |
| 11801 |
def = _Vue.extend(def); |
| 11802 |
} |
| 11803 |
return def.options[key] |
| 11804 |
} |
| 11805 |
|
| 11806 |
function extractLeaveGuards (deactivated) { |
| 11807 |
return extractGuards(deactivated, 'beforeRouteLeave', bindGuard, true) |
| 11808 |
} |
| 11809 |
|
| 11810 |
function extractUpdateHooks (updated) { |
| 11811 |
return extractGuards(updated, 'beforeRouteUpdate', bindGuard) |
| 11812 |
} |
| 11813 |
|
| 11814 |
function bindGuard (guard, instance) { |
| 11815 |
return function boundRouteGuard () { |
| 11816 |
return guard.apply(instance, arguments) |
| 11817 |
} |
| 11818 |
} |
| 11819 |
|
| 11820 |
function extractEnterGuards ( |
| 11821 |
activated, |
| 11822 |
cbs, |
| 11823 |
isValid |
| 11824 |
) { |
| 11825 |
return extractGuards(activated, 'beforeRouteEnter', function (guard, _, match, key) { |
| 11826 |
return bindEnterGuard(guard, match, key, cbs, isValid) |
| 11827 |
}) |
| 11828 |
} |
| 11829 |
|
| 11830 |
function bindEnterGuard ( |
| 11831 |
guard, |
| 11832 |
match, |
| 11833 |
key, |
| 11834 |
cbs, |
| 11835 |
isValid |
| 11836 |
) { |
| 11837 |
return function routeEnterGuard (to, from, next) { |
| 11838 |
return guard(to, from, function (cb) { |
| 11839 |
next(cb); |
| 11840 |
if (typeof cb === 'function') { |
| 11841 |
cbs.push(function () { |
| 11842 |
// #750 |
| 11843 |
// if a router-view is wrapped with an out-in transition, |
| 11844 |
// the instance may not have been registered at this time. |
| 11845 |
// we will need to poll for registration until current route |
| 11846 |
// is no longer valid. |
| 11847 |
poll(cb, match.instances, key, isValid); |
| 11848 |
}); |
| 11849 |
} |
| 11850 |
}) |
| 11851 |
} |
| 11852 |
} |
| 11853 |
|
| 11854 |
function poll ( |
| 11855 |
cb, // somehow flow cannot infer this is a function |
| 11856 |
instances, |
| 11857 |
key, |
| 11858 |
isValid |
| 11859 |
) { |
| 11860 |
if (instances[key]) { |
| 11861 |
cb(instances[key]); |
| 11862 |
} else if (isValid()) { |
| 11863 |
setTimeout(function () { |
| 11864 |
poll(cb, instances, key, isValid); |
| 11865 |
}, 16); |
| 11866 |
} |
| 11867 |
} |
| 11868 |
|
| 11869 |
function resolveAsyncComponents (matched) { |
| 11870 |
return flatMapComponents(matched, function (def, _, match, key) { |
| 11871 |
// if it's a function and doesn't have Vue options attached, |
| 11872 |
// assume it's an async component resolve function. |
| 11873 |
// we are not using Vue's default async resolving mechanism because |
| 11874 |
// we want to halt the navigation until the incoming component has been |
| 11875 |
// resolved. |
| 11876 |
if (typeof def === 'function' && !def.options) { |
| 11877 |
return function (to, from, next) { |
| 11878 |
var resolve = once(function (resolvedDef) { |
| 11879 |
match.components[key] = resolvedDef; |
| 11880 |
next(); |
| 11881 |
}); |
| 11882 |
|
| 11883 |
var reject = once(function (reason) { |
| 11884 |
warn(false, ("Failed to resolve async component " + key + ": " + reason)); |
| 11885 |
next(false); |
| 11886 |
}); |
| 11887 |
|
| 11888 |
var res = def(resolve, reject); |
| 11889 |
if (res && typeof res.then === 'function') { |
| 11890 |
res.then(resolve, reject); |
| 11891 |
} |
| 11892 |
} |
| 11893 |
} |
| 11894 |
}) |
| 11895 |
} |
| 11896 |
|
| 11897 |
function flatMapComponents ( |
| 11898 |
matched, |
| 11899 |
fn |
| 11900 |
) { |
| 11901 |
return flatten(matched.map(function (m) { |
| 11902 |
return Object.keys(m.components).map(function (key) { return fn( |
| 11903 |
m.components[key], |
| 11904 |
m.instances[key], |
| 11905 |
m, key |
| 11906 |
); }) |
| 11907 |
})) |
| 11908 |
} |
| 11909 |
|
| 11910 |
function flatten (arr) { |
| 11911 |
return Array.prototype.concat.apply([], arr) |
| 11912 |
} |
| 11913 |
|
| 11914 |
// in Webpack 2, require.ensure now also returns a Promise |
| 11915 |
// so the resolve/reject functions may get called an extra time |
| 11916 |
// if the user uses an arrow function shorthand that happens to |
| 11917 |
// return that Promise. |
| 11918 |
function once (fn) { |
| 11919 |
var called = false; |
| 11920 |
return function () { |
| 11921 |
if (called) { return } |
| 11922 |
called = true; |
| 11923 |
return fn.apply(this, arguments) |
| 11924 |
} |
| 11925 |
} |
| 11926 |
|
| 11927 |
/* */ |
| 11928 |
|
| 11929 |
|
| 11930 |
var HTML5History = (function (History$$1) { |
| 11931 |
function HTML5History (router, base) { |
| 11932 |
var this$1 = this; |
| 11933 |
|
| 11934 |
History$$1.call(this, router, base); |
| 11935 |
|
| 11936 |
var expectScroll = router.options.scrollBehavior; |
| 11937 |
|
| 11938 |
if (expectScroll) { |
| 11939 |
setupScroll(); |
| 11940 |
} |
| 11941 |
|
| 11942 |
window.addEventListener('popstate', function (e) { |
| 11943 |
this$1.transitionTo(getLocation(this$1.base), function (route) { |
| 11944 |
if (expectScroll) { |
| 11945 |
handleScroll(router, route, this$1.current, true); |
| 11946 |
} |
| 11947 |
}); |
| 11948 |
}); |
| 11949 |
} |
| 11950 |
|
| 11951 |
if ( History$$1 ) HTML5History.__proto__ = History$$1; |
| 11952 |
HTML5History.prototype = Object.create( History$$1 && History$$1.prototype ); |
| 11953 |
HTML5History.prototype.constructor = HTML5History; |
| 11954 |
|
| 11955 |
HTML5History.prototype.go = function go (n) { |
| 11956 |
window.history.go(n); |
| 11957 |
}; |
| 11958 |
|
| 11959 |
HTML5History.prototype.push = function push (location, onComplete, onAbort) { |
| 11960 |
var this$1 = this; |
| 11961 |
|
| 11962 |
var ref = this; |
| 11963 |
var fromRoute = ref.current; |
| 11964 |
this.transitionTo(location, function (route) { |
| 11965 |
pushState(cleanPath(this$1.base + route.fullPath)); |
| 11966 |
handleScroll(this$1.router, route, fromRoute, false); |
| 11967 |
onComplete && onComplete(route); |
| 11968 |
}, onAbort); |
| 11969 |
}; |
| 11970 |
|
| 11971 |
HTML5History.prototype.replace = function replace (location, onComplete, onAbort) { |
| 11972 |
var this$1 = this; |
| 11973 |
|
| 11974 |
var ref = this; |
| 11975 |
var fromRoute = ref.current; |
| 11976 |
this.transitionTo(location, function (route) { |
| 11977 |
replaceState(cleanPath(this$1.base + route.fullPath)); |
| 11978 |
handleScroll(this$1.router, route, fromRoute, false); |
| 11979 |
onComplete && onComplete(route); |
| 11980 |
}, onAbort); |
| 11981 |
}; |
| 11982 |
|
| 11983 |
HTML5History.prototype.ensureURL = function ensureURL (push) { |
| 11984 |
if (getLocation(this.base) !== this.current.fullPath) { |
| 11985 |
var current = cleanPath(this.base + this.current.fullPath); |
| 11986 |
push ? pushState(current) : replaceState(current); |
| 11987 |
} |
| 11988 |
}; |
| 11989 |
|
| 11990 |
HTML5History.prototype.getCurrentLocation = function getCurrentLocation () { |
| 11991 |
return getLocation(this.base) |
| 11992 |
}; |
| 11993 |
|
| 11994 |
return HTML5History; |
| 11995 |
}(History)); |
| 11996 |
|
| 11997 |
function getLocation (base) { |
| 11998 |
var path = window.location.pathname; |
| 11999 |
if (base && path.indexOf(base) === 0) { |
| 12000 |
path = path.slice(base.length); |
| 12001 |
} |
| 12002 |
return (path || '/') + window.location.search + window.location.hash |
| 12003 |
} |
| 12004 |
|
| 12005 |
/* */ |
| 12006 |
|
| 12007 |
|
| 12008 |
var HashHistory = (function (History$$1) { |
| 12009 |
function HashHistory (router, base, fallback) { |
| 12010 |
History$$1.call(this, router, base); |
| 12011 |
// check history fallback deeplinking |
| 12012 |
if (fallback && checkFallback(this.base)) { |
| 12013 |
return |
| 12014 |
} |
| 12015 |
ensureSlash(); |
| 12016 |
} |
| 12017 |
|
| 12018 |
if ( History$$1 ) HashHistory.__proto__ = History$$1; |
| 12019 |
HashHistory.prototype = Object.create( History$$1 && History$$1.prototype ); |
| 12020 |
HashHistory.prototype.constructor = HashHistory; |
| 12021 |
|
| 12022 |
// this is delayed until the app mounts |
| 12023 |
// to avoid the hashchange listener being fired too early |
| 12024 |
HashHistory.prototype.setupListeners = function setupListeners () { |
| 12025 |
var this$1 = this; |
| 12026 |
|
| 12027 |
window.addEventListener('hashchange', function () { |
| 12028 |
if (!ensureSlash()) { |
| 12029 |
return |
| 12030 |
} |
| 12031 |
this$1.transitionTo(getHash(), function (route) { |
| 12032 |
replaceHash(route.fullPath); |
| 12033 |
}); |
| 12034 |
}); |
| 12035 |
}; |
| 12036 |
|
| 12037 |
HashHistory.prototype.push = function push (location, onComplete, onAbort) { |
| 12038 |
this.transitionTo(location, function (route) { |
| 12039 |
pushHash(route.fullPath); |
| 12040 |
onComplete && onComplete(route); |
| 12041 |
}, onAbort); |
| 12042 |
}; |
| 12043 |
|
| 12044 |
HashHistory.prototype.replace = function replace (location, onComplete, onAbort) { |
| 12045 |
this.transitionTo(location, function (route) { |
| 12046 |
replaceHash(route.fullPath); |
| 12047 |
onComplete && onComplete(route); |
| 12048 |
}, onAbort); |
| 12049 |
}; |
| 12050 |
|
| 12051 |
HashHistory.prototype.go = function go (n) { |
| 12052 |
window.history.go(n); |
| 12053 |
}; |
| 12054 |
|
| 12055 |
HashHistory.prototype.ensureURL = function ensureURL (push) { |
| 12056 |
var current = this.current.fullPath; |
| 12057 |
if (getHash() !== current) { |
| 12058 |
push ? pushHash(current) : replaceHash(current); |
| 12059 |
} |
| 12060 |
}; |
| 12061 |
|
| 12062 |
HashHistory.prototype.getCurrentLocation = function getCurrentLocation () { |
| 12063 |
return getHash() |
| 12064 |
}; |
| 12065 |
|
| 12066 |
return HashHistory; |
| 12067 |
}(History)); |
| 12068 |
|
| 12069 |
function checkFallback (base) { |
| 12070 |
var location = getLocation(base); |
| 12071 |
if (!/^\/#/.test(location)) { |
| 12072 |
window.location.replace( |
| 12073 |
cleanPath(base + '/#' + location) |
| 12074 |
); |
| 12075 |
return true |
| 12076 |
} |
| 12077 |
} |
| 12078 |
|
| 12079 |
function ensureSlash () { |
| 12080 |
var path = getHash(); |
| 12081 |
if (path.charAt(0) === '/') { |
| 12082 |
return true |
| 12083 |
} |
| 12084 |
replaceHash('/' + path); |
| 12085 |
return false |
| 12086 |
} |
| 12087 |
|
| 12088 |
function getHash () { |
| 12089 |
// We can't use window.location.hash here because it's not |
| 12090 |
// consistent across browsers - Firefox will pre-decode it! |
| 12091 |
var href = window.location.href; |
| 12092 |
var index = href.indexOf('#'); |
| 12093 |
return index === -1 ? '' : href.slice(index + 1) |
| 12094 |
} |
| 12095 |
|
| 12096 |
function pushHash (path) { |
| 12097 |
window.location.hash = path; |
| 12098 |
} |
| 12099 |
|
| 12100 |
function replaceHash (path) { |
| 12101 |
var i = window.location.href.indexOf('#'); |
| 12102 |
window.location.replace( |
| 12103 |
window.location.href.slice(0, i >= 0 ? i : 0) + '#' + path |
| 12104 |
); |
| 12105 |
} |
| 12106 |
|
| 12107 |
/* */ |
| 12108 |
|
| 12109 |
|
| 12110 |
var AbstractHistory = (function (History$$1) { |
| 12111 |
function AbstractHistory (router, base) { |
| 12112 |
History$$1.call(this, router, base); |
| 12113 |
this.stack = []; |
| 12114 |
this.index = -1; |
| 12115 |
} |
| 12116 |
|
| 12117 |
if ( History$$1 ) AbstractHistory.__proto__ = History$$1; |
| 12118 |
AbstractHistory.prototype = Object.create( History$$1 && History$$1.prototype ); |
| 12119 |
AbstractHistory.prototype.constructor = AbstractHistory; |
| 12120 |
|
| 12121 |
AbstractHistory.prototype.push = function push (location, onComplete, onAbort) { |
| 12122 |
var this$1 = this; |
| 12123 |
|
| 12124 |
this.transitionTo(location, function (route) { |
| 12125 |
this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route); |
| 12126 |
this$1.index++; |
| 12127 |
onComplete && onComplete(route); |
| 12128 |
}, onAbort); |
| 12129 |
}; |
| 12130 |
|
| 12131 |
AbstractHistory.prototype.replace = function replace (location, onComplete, onAbort) { |
| 12132 |
var this$1 = this; |
| 12133 |
|
| 12134 |
this.transitionTo(location, function (route) { |
| 12135 |
this$1.stack = this$1.stack.slice(0, this$1.index).concat(route); |
| 12136 |
onComplete && onComplete(route); |
| 12137 |
}, onAbort); |
| 12138 |
}; |
| 12139 |
|
| 12140 |
AbstractHistory.prototype.go = function go (n) { |
| 12141 |
var this$1 = this; |
| 12142 |
|
| 12143 |
var targetIndex = this.index + n; |
| 12144 |
if (targetIndex < 0 || targetIndex >= this.stack.length) { |
| 12145 |
return |
| 12146 |
} |
| 12147 |
var route = this.stack[targetIndex]; |
| 12148 |
this.confirmTransition(route, function () { |
| 12149 |
this$1.index = targetIndex; |
| 12150 |
this$1.updateRoute(route); |
| 12151 |
}); |
| 12152 |
}; |
| 12153 |
|
| 12154 |
AbstractHistory.prototype.getCurrentLocation = function getCurrentLocation () { |
| 12155 |
var current = this.stack[this.stack.length - 1]; |
| 12156 |
return current ? current.fullPath : '/' |
| 12157 |
}; |
| 12158 |
|
| 12159 |
AbstractHistory.prototype.ensureURL = function ensureURL () { |
| 12160 |
// noop |
| 12161 |
}; |
| 12162 |
|
| 12163 |
return AbstractHistory; |
| 12164 |
}(History)); |
| 12165 |
|
| 12166 |
/* */ |
| 12167 |
|
| 12168 |
var VueRouter = function VueRouter (options) { |
| 12169 |
if ( options === void 0 ) options = {}; |
| 12170 |
|
| 12171 |
this.app = null; |
| 12172 |
this.apps = []; |
| 12173 |
this.options = options; |
| 12174 |
this.beforeHooks = []; |
| 12175 |
this.afterHooks = []; |
| 12176 |
this.matcher = createMatcher(options.routes || []); |
| 12177 |
|
| 12178 |
var mode = options.mode || 'hash'; |
| 12179 |
this.fallback = mode === 'history' && !supportsPushState; |
| 12180 |
if (this.fallback) { |
| 12181 |
mode = 'hash'; |
| 12182 |
} |
| 12183 |
if (!inBrowser) { |
| 12184 |
mode = 'abstract'; |
| 12185 |
} |
| 12186 |
this.mode = mode; |
| 12187 |
|
| 12188 |
switch (mode) { |
| 12189 |
case 'history': |
| 12190 |
this.history = new HTML5History(this, options.base); |
| 12191 |
break |
| 12192 |
case 'hash': |
| 12193 |
this.history = new HashHistory(this, options.base, this.fallback); |
| 12194 |
break |
| 12195 |
case 'abstract': |
| 12196 |
this.history = new AbstractHistory(this, options.base); |
| 12197 |
break |
| 12198 |
default: |
| 12199 |
{ |
| 12200 |
assert(false, ("invalid mode: " + mode)); |
| 12201 |
} |
| 12202 |
} |
| 12203 |
}; |
| 12204 |
|
| 12205 |
var prototypeAccessors = { currentRoute: {} }; |
| 12206 |
|
| 12207 |
VueRouter.prototype.match = function match ( |
| 12208 |
raw, |
| 12209 |
current, |
| 12210 |
redirectedFrom |
| 12211 |
) { |
| 12212 |
return this.matcher.match(raw, current, redirectedFrom) |
| 12213 |
}; |
| 12214 |
|
| 12215 |
prototypeAccessors.currentRoute.get = function () { |
| 12216 |
return this.history && this.history.current |
| 12217 |
}; |
| 12218 |
|
| 12219 |
VueRouter.prototype.init = function init (app /* Vue component instance */) { |
| 12220 |
var this$1 = this; |
| 12221 |
|
| 12222 |
"development" !== 'production' && assert( |
| 12223 |
install.installed, |
| 12224 |
"not installed. Make sure to call `Vue.use(VueRouter)` " + |
| 12225 |
"before creating root instance." |
| 12226 |
); |
| 12227 |
|
| 12228 |
this.apps.push(app); |
| 12229 |
|
| 12230 |
// main app already initialized. |
| 12231 |
if (this.app) { |
| 12232 |
return |
| 12233 |
} |
| 12234 |
|
| 12235 |
this.app = app; |
| 12236 |
|
| 12237 |
var history = this.history; |
| 12238 |
|
| 12239 |
if (history instanceof HTML5History) { |
| 12240 |
history.transitionTo(history.getCurrentLocation()); |
| 12241 |
} else if (history instanceof HashHistory) { |
| 12242 |
var setupHashListener = function () { |
| 12243 |
history.setupListeners(); |
| 12244 |
}; |
| 12245 |
history.transitionTo( |
| 12246 |
history.getCurrentLocation(), |
| 12247 |
setupHashListener, |
| 12248 |
setupHashListener |
| 12249 |
); |
| 12250 |
} |
| 12251 |
|
| 12252 |
history.listen(function (route) { |
| 12253 |
this$1.apps.forEach(function (app) { |
| 12254 |
app._route = route; |
| 12255 |
}); |
| 12256 |
}); |
| 12257 |
}; |
| 12258 |
|
| 12259 |
VueRouter.prototype.beforeEach = function beforeEach (fn) { |
| 12260 |
this.beforeHooks.push(fn); |
| 12261 |
}; |
| 12262 |
|
| 12263 |
VueRouter.prototype.afterEach = function afterEach (fn) { |
| 12264 |
this.afterHooks.push(fn); |
| 12265 |
}; |
| 12266 |
|
| 12267 |
VueRouter.prototype.onReady = function onReady (cb) { |
| 12268 |
this.history.onReady(cb); |
| 12269 |
}; |
| 12270 |
|
| 12271 |
VueRouter.prototype.push = function push (location, onComplete, onAbort) { |
| 12272 |
this.history.push(location, onComplete, onAbort); |
| 12273 |
}; |
| 12274 |
|
| 12275 |
VueRouter.prototype.replace = function replace (location, onComplete, onAbort) { |
| 12276 |
this.history.replace(location, onComplete, onAbort); |
| 12277 |
}; |
| 12278 |
|
| 12279 |
VueRouter.prototype.go = function go (n) { |
| 12280 |
this.history.go(n); |
| 12281 |
}; |
| 12282 |
|
| 12283 |
VueRouter.prototype.back = function back () { |
| 12284 |
this.go(-1); |
| 12285 |
}; |
| 12286 |
|
| 12287 |
VueRouter.prototype.forward = function forward () { |
| 12288 |
this.go(1); |
| 12289 |
}; |
| 12290 |
|
| 12291 |
VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) { |
| 12292 |
var route = to |
| 12293 |
? this.resolve(to).route |
| 12294 |
: this.currentRoute; |
| 12295 |
if (!route) { |
| 12296 |
return [] |
| 12297 |
} |
| 12298 |
return [].concat.apply([], route.matched.map(function (m) { |
| 12299 |
return Object.keys(m.components).map(function (key) { |
| 12300 |
return m.components[key] |
| 12301 |
}) |
| 12302 |
})) |
| 12303 |
}; |
| 12304 |
|
| 12305 |
VueRouter.prototype.resolve = function resolve ( |
| 12306 |
to, |
| 12307 |
current, |
| 12308 |
append |
| 12309 |
) { |
| 12310 |
var location = normalizeLocation(to, current || this.history.current, append); |
| 12311 |
var route = this.match(location, current); |
| 12312 |
var fullPath = route.redirectedFrom || route.fullPath; |
| 12313 |
var base = this.history.base; |
| 12314 |
var href = createHref(base, fullPath, this.mode); |
| 12315 |
return { |
| 12316 |
location: location, |
| 12317 |
route: route, |
| 12318 |
href: href, |
| 12319 |
// for backwards compat |
| 12320 |
normalizedTo: location, |
| 12321 |
resolved: route |
| 12322 |
} |
| 12323 |
}; |
| 12324 |
|
| 12325 |
VueRouter.prototype.addRoutes = function addRoutes (routes) { |
| 12326 |
this.matcher.addRoutes(routes); |
| 12327 |
if (this.history.current !== START) { |
| 12328 |
this.history.transitionTo(this.history.getCurrentLocation()); |
| 12329 |
} |
| 12330 |
}; |
| 12331 |
|
| 12332 |
Object.defineProperties( VueRouter.prototype, prototypeAccessors ); |
| 12333 |
|
| 12334 |
function createHref (base, fullPath, mode) { |
| 12335 |
var path = mode === 'hash' ? '#' + fullPath : fullPath; |
| 12336 |
return base ? cleanPath(base + '/' + path) : path |
| 12337 |
} |
| 12338 |
|
| 12339 |
VueRouter.install = install; |
| 12340 |
VueRouter.version = '2.3.1'; |
| 12341 |
|
| 12342 |
if (inBrowser && window.Vue) { |
| 12343 |
window.Vue.use(VueRouter); |
| 12344 |
} |
| 12345 |
|
| 12346 |
return VueRouter; |
| 12347 |
|
| 12348 |
}))); |
| 12349 |
|
| 12350 |
/* assets/js/vendor/nprogress.js */ |
| 12351 |
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress |
| 12352 |
* @license MIT */ |
| 12353 |
|
| 12354 |
;(function(root, factory) { |
| 12355 |
|
| 12356 |
if (typeof define === 'function' && define.amd) { |
| 12357 |
define(factory); |
| 12358 |
} else if (typeof exports === 'object') { |
| 12359 |
module.exports = factory(); |
| 12360 |
} else { |
| 12361 |
root.NProgress = factory(); |
| 12362 |
} |
| 12363 |
|
| 12364 |
})(this, function() { |
| 12365 |
var NProgress = {}; |
| 12366 |
|
| 12367 |
NProgress.version = '0.2.0'; |
| 12368 |
|
| 12369 |
var Settings = NProgress.settings = { |
| 12370 |
minimum: 0.08, |
| 12371 |
easing: 'linear', |
| 12372 |
positionUsing: '', |
| 12373 |
speed: 200, |
| 12374 |
trickle: true, |
| 12375 |
trickleSpeed: 200, |
| 12376 |
showSpinner: true, |
| 12377 |
barSelector: '[role="bar"]', |
| 12378 |
spinnerSelector: '[role="spinner"]', |
| 12379 |
parent: 'body', |
| 12380 |
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>' |
| 12381 |
}; |
| 12382 |
|
| 12383 |
/** |
| 12384 |
* Updates configuration. |
| 12385 |
* |
| 12386 |
* NProgress.configure({ |
| 12387 |
* minimum: 0.1 |
| 12388 |
* }); |
| 12389 |
*/ |
| 12390 |
NProgress.configure = function(options) { |
| 12391 |
var key, value; |
| 12392 |
for (key in options) { |
| 12393 |
value = options[key]; |
| 12394 |
if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value; |
| 12395 |
} |
| 12396 |
|
| 12397 |
return this; |
| 12398 |
}; |
| 12399 |
|
| 12400 |
/** |
| 12401 |
* Last number. |
| 12402 |
*/ |
| 12403 |
|
| 12404 |
NProgress.status = null; |
| 12405 |
|
| 12406 |
/** |
| 12407 |
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`. |
| 12408 |
* |
| 12409 |
* NProgress.set(0.4); |
| 12410 |
* NProgress.set(1.0); |
| 12411 |
*/ |
| 12412 |
|
| 12413 |
NProgress.set = function(n) { |
| 12414 |
var started = NProgress.isStarted(); |
| 12415 |
|
| 12416 |
n = clamp(n, Settings.minimum, 1); |
| 12417 |
NProgress.status = (n === 1 ? null : n); |
| 12418 |
|
| 12419 |
var progress = NProgress.render(!started), |
| 12420 |
bar = progress.querySelector(Settings.barSelector), |
| 12421 |
speed = Settings.speed, |
| 12422 |
ease = Settings.easing; |
| 12423 |
|
| 12424 |
progress.offsetWidth; /* Repaint */ |
| 12425 |
|
| 12426 |
queue(function(next) { |
| 12427 |
// Set positionUsing if it hasn't already been set |
| 12428 |
if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS(); |
| 12429 |
|
| 12430 |
// Add transition |
| 12431 |
css(bar, barPositionCSS(n, speed, ease)); |
| 12432 |
|
| 12433 |
if (n === 1) { |
| 12434 |
// Fade out |
| 12435 |
css(progress, { |
| 12436 |
transition: 'none', |
| 12437 |
opacity: 1 |
| 12438 |
}); |
| 12439 |
progress.offsetWidth; /* Repaint */ |
| 12440 |
|
| 12441 |
setTimeout(function() { |
| 12442 |
css(progress, { |
| 12443 |
transition: 'all ' + speed + 'ms linear', |
| 12444 |
opacity: 0 |
| 12445 |
}); |
| 12446 |
setTimeout(function() { |
| 12447 |
NProgress.remove(); |
| 12448 |
next(); |
| 12449 |
}, speed); |
| 12450 |
}, speed); |
| 12451 |
} else { |
| 12452 |
setTimeout(next, speed); |
| 12453 |
} |
| 12454 |
}); |
| 12455 |
|
| 12456 |
return this; |
| 12457 |
}; |
| 12458 |
|
| 12459 |
NProgress.isStarted = function() { |
| 12460 |
return typeof NProgress.status === 'number'; |
| 12461 |
}; |
| 12462 |
|
| 12463 |
/** |
| 12464 |
* Shows the progress bar. |
| 12465 |
* This is the same as setting the status to 0%, except that it doesn't go backwards. |
| 12466 |
* |
| 12467 |
* NProgress.start(); |
| 12468 |
* |
| 12469 |
*/ |
| 12470 |
NProgress.start = function() { |
| 12471 |
if (!NProgress.status) NProgress.set(0); |
| 12472 |
|
| 12473 |
var work = function() { |
| 12474 |
setTimeout(function() { |
| 12475 |
if (!NProgress.status) return; |
| 12476 |
NProgress.trickle(); |
| 12477 |
work(); |
| 12478 |
}, Settings.trickleSpeed); |
| 12479 |
}; |
| 12480 |
|
| 12481 |
if (Settings.trickle) work(); |
| 12482 |
|
| 12483 |
return this; |
| 12484 |
}; |
| 12485 |
|
| 12486 |
/** |
| 12487 |
* Hides the progress bar. |
| 12488 |
* This is the *sort of* the same as setting the status to 100%, with the |
| 12489 |
* difference being `done()` makes some placebo effect of some realistic motion. |
| 12490 |
* |
| 12491 |
* NProgress.done(); |
| 12492 |
* |
| 12493 |
* If `true` is passed, it will show the progress bar even if its hidden. |
| 12494 |
* |
| 12495 |
* NProgress.done(true); |
| 12496 |
*/ |
| 12497 |
|
| 12498 |
NProgress.done = function(force) { |
| 12499 |
if (!force && !NProgress.status) return this; |
| 12500 |
|
| 12501 |
return NProgress.inc(0.3 + 0.5 * Math.random()).set(1); |
| 12502 |
}; |
| 12503 |
|
| 12504 |
/** |
| 12505 |
* Increments by a random amount. |
| 12506 |
*/ |
| 12507 |
|
| 12508 |
NProgress.inc = function(amount) { |
| 12509 |
var n = NProgress.status; |
| 12510 |
|
| 12511 |
if (!n) { |
| 12512 |
return NProgress.start(); |
| 12513 |
} else if(n > 1) { |
| 12514 |
return; |
| 12515 |
} else { |
| 12516 |
if (typeof amount !== 'number') { |
| 12517 |
if (n >= 0 && n < 0.2) { amount = 0.1; } |
| 12518 |
else if (n >= 0.2 && n < 0.5) { amount = 0.04; } |
| 12519 |
else if (n >= 0.5 && n < 0.8) { amount = 0.02; } |
| 12520 |
else if (n >= 0.8 && n < 0.99) { amount = 0.005; } |
| 12521 |
else { amount = 0; } |
| 12522 |
} |
| 12523 |
|
| 12524 |
n = clamp(n + amount, 0, 0.994); |
| 12525 |
return NProgress.set(n); |
| 12526 |
} |
| 12527 |
}; |
| 12528 |
|
| 12529 |
NProgress.trickle = function() { |
| 12530 |
return NProgress.inc(); |
| 12531 |
}; |
| 12532 |
|
| 12533 |
/** |
| 12534 |
* Waits for all supplied jQuery promises and |
| 12535 |
* increases the progress as the promises resolve. |
| 12536 |
* |
| 12537 |
* @param $promise jQUery Promise |
| 12538 |
*/ |
| 12539 |
(function() { |
| 12540 |
var initial = 0, current = 0; |
| 12541 |
|
| 12542 |
NProgress.promise = function($promise) { |
| 12543 |
if (!$promise || $promise.state() === "resolved") { |
| 12544 |
return this; |
| 12545 |
} |
| 12546 |
|
| 12547 |
if (current === 0) { |
| 12548 |
NProgress.start(); |
| 12549 |
} |
| 12550 |
|
| 12551 |
initial++; |
| 12552 |
current++; |
| 12553 |
|
| 12554 |
$promise.always(function() { |
| 12555 |
current--; |
| 12556 |
if (current === 0) { |
| 12557 |
initial = 0; |
| 12558 |
NProgress.done(); |
| 12559 |
} else { |
| 12560 |
NProgress.set((initial - current) / initial); |
| 12561 |
} |
| 12562 |
}); |
| 12563 |
|
| 12564 |
return this; |
| 12565 |
}; |
| 12566 |
|
| 12567 |
})(); |
| 12568 |
|
| 12569 |
/** |
| 12570 |
* (Internal) renders the progress bar markup based on the `template` |
| 12571 |
* setting. |
| 12572 |
*/ |
| 12573 |
|
| 12574 |
NProgress.render = function(fromStart) { |
| 12575 |
if (NProgress.isRendered()) return document.getElementById('nprogress'); |
| 12576 |
|
| 12577 |
addClass(document.documentElement, 'nprogress-busy'); |
| 12578 |
|
| 12579 |
var progress = document.createElement('div'); |
| 12580 |
progress.id = 'nprogress'; |
| 12581 |
progress.innerHTML = Settings.template; |
| 12582 |
|
| 12583 |
var bar = progress.querySelector(Settings.barSelector), |
| 12584 |
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0), |
| 12585 |
parent = document.querySelector(Settings.parent), |
| 12586 |
spinner; |
| 12587 |
|
| 12588 |
css(bar, { |
| 12589 |
transition: 'all 0 linear', |
| 12590 |
transform: 'translate3d(' + perc + '%,0,0)' |
| 12591 |
}); |
| 12592 |
|
| 12593 |
if (!Settings.showSpinner) { |
| 12594 |
spinner = progress.querySelector(Settings.spinnerSelector); |
| 12595 |
spinner && removeElement(spinner); |
| 12596 |
} |
| 12597 |
|
| 12598 |
if (parent != document.body) { |
| 12599 |
addClass(parent, 'nprogress-custom-parent'); |
| 12600 |
} |
| 12601 |
|
| 12602 |
parent.appendChild(progress); |
| 12603 |
return progress; |
| 12604 |
}; |
| 12605 |
|
| 12606 |
/** |
| 12607 |
* Removes the element. Opposite of render(). |
| 12608 |
*/ |
| 12609 |
|
| 12610 |
NProgress.remove = function() { |
| 12611 |
removeClass(document.documentElement, 'nprogress-busy'); |
| 12612 |
removeClass(document.querySelector(Settings.parent), 'nprogress-custom-parent'); |
| 12613 |
var progress = document.getElementById('nprogress'); |
| 12614 |
progress && removeElement(progress); |
| 12615 |
}; |
| 12616 |
|
| 12617 |
/** |
| 12618 |
* Checks if the progress bar is rendered. |
| 12619 |
*/ |
| 12620 |
|
| 12621 |
NProgress.isRendered = function() { |
| 12622 |
return !!document.getElementById('nprogress'); |
| 12623 |
}; |
| 12624 |
|
| 12625 |
/** |
| 12626 |
* Determine which positioning CSS rule to use. |
| 12627 |
*/ |
| 12628 |
|
| 12629 |
NProgress.getPositioningCSS = function() { |
| 12630 |
// Sniff on document.body.style |
| 12631 |
var bodyStyle = document.body.style; |
| 12632 |
|
| 12633 |
// Sniff prefixes |
| 12634 |
var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' : |
| 12635 |
('MozTransform' in bodyStyle) ? 'Moz' : |
| 12636 |
('msTransform' in bodyStyle) ? 'ms' : |
| 12637 |
('OTransform' in bodyStyle) ? 'O' : ''; |
| 12638 |
|
| 12639 |
if (vendorPrefix + 'Perspective' in bodyStyle) { |
| 12640 |
// Modern browsers with 3D support, e.g. Webkit, IE10 |
| 12641 |
return 'translate3d'; |
| 12642 |
} else if (vendorPrefix + 'Transform' in bodyStyle) { |
| 12643 |
// Browsers without 3D support, e.g. IE9 |
| 12644 |
return 'translate'; |
| 12645 |
} else { |
| 12646 |
// Browsers without translate() support, e.g. IE7-8 |
| 12647 |
return 'margin'; |
| 12648 |
} |
| 12649 |
}; |
| 12650 |
|
| 12651 |
/** |
| 12652 |
* Helpers |
| 12653 |
*/ |
| 12654 |
|
| 12655 |
function clamp(n, min, max) { |
| 12656 |
if (n < min) return min; |
| 12657 |
if (n > max) return max; |
| 12658 |
return n; |
| 12659 |
} |
| 12660 |
|
| 12661 |
/** |
| 12662 |
* (Internal) converts a percentage (`0..1`) to a bar translateX |
| 12663 |
* percentage (`-100%..0%`). |
| 12664 |
*/ |
| 12665 |
|
| 12666 |
function toBarPerc(n) { |
| 12667 |
return (-1 + n) * 100; |
| 12668 |
} |
| 12669 |
|
| 12670 |
|
| 12671 |
/** |
| 12672 |
* (Internal) returns the correct CSS for changing the bar's |
| 12673 |
* position given an n percentage, and speed and ease from Settings |
| 12674 |
*/ |
| 12675 |
|
| 12676 |
function barPositionCSS(n, speed, ease) { |
| 12677 |
var barCSS; |
| 12678 |
|
| 12679 |
if (Settings.positionUsing === 'translate3d') { |
| 12680 |
barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' }; |
| 12681 |
} else if (Settings.positionUsing === 'translate') { |
| 12682 |
barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' }; |
| 12683 |
} else { |
| 12684 |
barCSS = { 'margin-left': toBarPerc(n)+'%' }; |
| 12685 |
} |
| 12686 |
|
| 12687 |
barCSS.transition = 'all '+speed+'ms '+ease; |
| 12688 |
|
| 12689 |
return barCSS; |
| 12690 |
} |
| 12691 |
|
| 12692 |
/** |
| 12693 |
* (Internal) Queues a function to be executed. |
| 12694 |
*/ |
| 12695 |
|
| 12696 |
var queue = (function() { |
| 12697 |
var pending = []; |
| 12698 |
|
| 12699 |
function next() { |
| 12700 |
var fn = pending.shift(); |
| 12701 |
if (fn) { |
| 12702 |
fn(next); |
| 12703 |
} |
| 12704 |
} |
| 12705 |
|
| 12706 |
return function(fn) { |
| 12707 |
pending.push(fn); |
| 12708 |
if (pending.length == 1) next(); |
| 12709 |
}; |
| 12710 |
})(); |
| 12711 |
|
| 12712 |
/** |
| 12713 |
* (Internal) Applies css properties to an element, similar to the jQuery |
| 12714 |
* css method. |
| 12715 |
* |
| 12716 |
* While this helper does assist with vendor prefixed property names, it |
| 12717 |
* does not perform any manipulation of values prior to setting styles. |
| 12718 |
*/ |
| 12719 |
|
| 12720 |
var css = (function() { |
| 12721 |
var cssPrefixes = [ 'Webkit', 'O', 'Moz', 'ms' ], |
| 12722 |
cssProps = {}; |
| 12723 |
|
| 12724 |
function camelCase(string) { |
| 12725 |
return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) { |
| 12726 |
return letter.toUpperCase(); |
| 12727 |
}); |
| 12728 |
} |
| 12729 |
|
| 12730 |
function getVendorProp(name) { |
| 12731 |
var style = document.body.style; |
| 12732 |
if (name in style) return name; |
| 12733 |
|
| 12734 |
var i = cssPrefixes.length, |
| 12735 |
capName = name.charAt(0).toUpperCase() + name.slice(1), |
| 12736 |
vendorName; |
| 12737 |
while (i--) { |
| 12738 |
vendorName = cssPrefixes[i] + capName; |
| 12739 |
if (vendorName in style) return vendorName; |
| 12740 |
} |
| 12741 |
|
| 12742 |
return name; |
| 12743 |
} |
| 12744 |
|
| 12745 |
function getStyleProp(name) { |
| 12746 |
name = camelCase(name); |
| 12747 |
return cssProps[name] || (cssProps[name] = getVendorProp(name)); |
| 12748 |
} |
| 12749 |
|
| 12750 |
function applyCss(element, prop, value) { |
| 12751 |
prop = getStyleProp(prop); |
| 12752 |
element.style[prop] = value; |
| 12753 |
} |
| 12754 |
|
| 12755 |
return function(element, properties) { |
| 12756 |
var args = arguments, |
| 12757 |
prop, |
| 12758 |
value; |
| 12759 |
|
| 12760 |
if (args.length == 2) { |
| 12761 |
for (prop in properties) { |
| 12762 |
value = properties[prop]; |
| 12763 |
if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value); |
| 12764 |
} |
| 12765 |
} else { |
| 12766 |
applyCss(element, args[1], args[2]); |
| 12767 |
} |
| 12768 |
} |
| 12769 |
})(); |
| 12770 |
|
| 12771 |
/** |
| 12772 |
* (Internal) Determines if an element or space separated list of class names contains a class name. |
| 12773 |
*/ |
| 12774 |
|
| 12775 |
function hasClass(element, name) { |
| 12776 |
var list = typeof element == 'string' ? element : classList(element); |
| 12777 |
return list.indexOf(' ' + name + ' ') >= 0; |
| 12778 |
} |
| 12779 |
|
| 12780 |
/** |
| 12781 |
* (Internal) Adds a class to an element. |
| 12782 |
*/ |
| 12783 |
|
| 12784 |
function addClass(element, name) { |
| 12785 |
var oldList = classList(element), |
| 12786 |
newList = oldList + name; |
| 12787 |
|
| 12788 |
if (hasClass(oldList, name)) return; |
| 12789 |
|
| 12790 |
// Trim the opening space. |
| 12791 |
element.className = newList.substring(1); |
| 12792 |
} |
| 12793 |
|
| 12794 |
/** |
| 12795 |
* (Internal) Removes a class from an element. |
| 12796 |
*/ |
| 12797 |
|
| 12798 |
function removeClass(element, name) { |
| 12799 |
var oldList = classList(element), |
| 12800 |
newList; |
| 12801 |
|
| 12802 |
if (!hasClass(element, name)) return; |
| 12803 |
|
| 12804 |
// Replace the class name. |
| 12805 |
newList = oldList.replace(' ' + name + ' ', ' '); |
| 12806 |
|
| 12807 |
// Trim the opening and closing spaces. |
| 12808 |
element.className = newList.substring(1, newList.length - 1); |
| 12809 |
} |
| 12810 |
|
| 12811 |
/** |
| 12812 |
* (Internal) Gets a space separated list of the class names on the element. |
| 12813 |
* The list is wrapped with a single space on each end to facilitate finding |
| 12814 |
* matches within the list. |
| 12815 |
*/ |
| 12816 |
|
| 12817 |
function classList(element) { |
| 12818 |
return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' '); |
| 12819 |
} |
| 12820 |
|
| 12821 |
/** |
| 12822 |
* (Internal) Removes an element from the DOM. |
| 12823 |
*/ |
| 12824 |
|
| 12825 |
function removeElement(element) { |
| 12826 |
element && element.parentNode && element.parentNode.removeChild(element); |
| 12827 |
} |
| 12828 |
|
| 12829 |
return NProgress; |
| 12830 |
}); |
| 12831 |
|
| 12832 |
/* assets/wpuf/js/jquery-ui-timepicker-addon.js */ |
| 12833 |
/*
|
| 12834 |
* jQuery timepicker addon
|
| 12835 |
* By: Trent Richardson [http://trentrichardson.com]
|
| 12836 |
* Version 1.2
|
| 12837 |
* Last Modified: 02/02/2013
|
| 12838 |
*
|
| 12839 |
* Copyright 2013 Trent Richardson
|
| 12840 |
* You may use this project under MIT or GPL licenses.
|
| 12841 |
* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
|
| 12842 |
* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
|
| 12843 |
*/
|
| 12844 |
|
| 12845 |
/*jslint evil: true, white: false, undef: false, nomen: false */
|
| 12846 |
|
| 12847 |
(function($) {
|
| 12848 |
|
| 12849 |
/*
|
| 12850 |
* Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded"
|
| 12851 |
*/
|
| 12852 |
$.ui.timepicker = $.ui.timepicker || {};
|
| 12853 |
if ($.ui.timepicker.version) {
|
| 12854 |
return;
|
| 12855 |
}
|
| 12856 |
|
| 12857 |
/*
|
| 12858 |
* Extend jQueryUI, get it started with our version number
|
| 12859 |
*/
|
| 12860 |
$.extend($.ui, {
|
| 12861 |
timepicker: {
|
| 12862 |
version: "1.2"
|
| 12863 |
}
|
| 12864 |
});
|
| 12865 |
|
| 12866 |
/*
|
| 12867 |
* Timepicker manager.
|
| 12868 |
* Use the singleton instance of this class, $.timepicker, to interact with the time picker.
|
| 12869 |
* Settings for (groups of) time pickers are maintained in an instance object,
|
| 12870 |
* allowing multiple different settings on the same page.
|
| 12871 |
*/
|
| 12872 |
var Timepicker = function() {
|
| 12873 |
this.regional = []; // Available regional settings, indexed by language code
|
| 12874 |
this.regional[''] = { // Default regional settings
|
| 12875 |
currentText: 'Now',
|
| 12876 |
closeText: 'Done',
|
| 12877 |
amNames: ['AM', 'A'],
|
| 12878 |
pmNames: ['PM', 'P'],
|
| 12879 |
timeFormat: 'HH:mm',
|
| 12880 |
timeSuffix: '',
|
| 12881 |
timeOnlyTitle: 'Choose Time',
|
| 12882 |
timeText: 'Time',
|
| 12883 |
hourText: 'Hour',
|
| 12884 |
minuteText: 'Minute',
|
| 12885 |
secondText: 'Second',
|
| 12886 |
millisecText: 'Millisecond',
|
| 12887 |
timezoneText: 'Time Zone',
|
| 12888 |
isRTL: false
|
| 12889 |
};
|
| 12890 |
this._defaults = { // Global defaults for all the datetime picker instances
|
| 12891 |
showButtonPanel: true,
|
| 12892 |
timeOnly: false,
|
| 12893 |
showHour: true,
|
| 12894 |
showMinute: true,
|
| 12895 |
showSecond: false,
|
| 12896 |
showMillisec: false,
|
| 12897 |
showTimezone: false,
|
| 12898 |
showTime: true,
|
| 12899 |
stepHour: 1,
|
| 12900 |
stepMinute: 1,
|
| 12901 |
stepSecond: 1,
|
| 12902 |
stepMillisec: 1,
|
| 12903 |
hour: 0,
|
| 12904 |
minute: 0,
|
| 12905 |
second: 0,
|
| 12906 |
millisec: 0,
|
| 12907 |
timezone: null,
|
| 12908 |
useLocalTimezone: false,
|
| 12909 |
defaultTimezone: "+0000",
|
| 12910 |
hourMin: 0,
|
| 12911 |
minuteMin: 0,
|
| 12912 |
secondMin: 0,
|
| 12913 |
millisecMin: 0,
|
| 12914 |
hourMax: 23,
|
| 12915 |
minuteMax: 59,
|
| 12916 |
secondMax: 59,
|
| 12917 |
millisecMax: 999,
|
| 12918 |
minDateTime: null,
|
| 12919 |
maxDateTime: null,
|
| 12920 |
onSelect: null,
|
| 12921 |
hourGrid: 0,
|
| 12922 |
minuteGrid: 0,
|
| 12923 |
secondGrid: 0,
|
| 12924 |
millisecGrid: 0,
|
| 12925 |
alwaysSetTime: true,
|
| 12926 |
separator: ' ',
|
| 12927 |
altFieldTimeOnly: true,
|
| 12928 |
altTimeFormat: null,
|
| 12929 |
altSeparator: null,
|
| 12930 |
altTimeSuffix: null,
|
| 12931 |
pickerTimeFormat: null,
|
| 12932 |
pickerTimeSuffix: null,
|
| 12933 |
showTimepicker: true,
|
| 12934 |
timezoneIso8601: false,
|
| 12935 |
timezoneList: null,
|
| 12936 |
addSliderAccess: false,
|
| 12937 |
sliderAccessArgs: null,
|
| 12938 |
controlType: 'slider',
|
| 12939 |
defaultValue: null,
|
| 12940 |
parse: 'strict'
|
| 12941 |
};
|
| 12942 |
$.extend(this._defaults, this.regional['']);
|
| 12943 |
};
|
| 12944 |
|
| 12945 |
$.extend(Timepicker.prototype, {
|
| 12946 |
$input: null,
|
| 12947 |
$altInput: null,
|
| 12948 |
$timeObj: null,
|
| 12949 |
inst: null,
|
| 12950 |
hour_slider: null,
|
| 12951 |
minute_slider: null,
|
| 12952 |
second_slider: null,
|
| 12953 |
millisec_slider: null,
|
| 12954 |
timezone_select: null,
|
| 12955 |
hour: 0,
|
| 12956 |
minute: 0,
|
| 12957 |
second: 0,
|
| 12958 |
millisec: 0,
|
| 12959 |
timezone: null,
|
| 12960 |
defaultTimezone: "+0000",
|
| 12961 |
hourMinOriginal: null,
|
| 12962 |
minuteMinOriginal: null,
|
| 12963 |
secondMinOriginal: null,
|
| 12964 |
millisecMinOriginal: null,
|
| 12965 |
hourMaxOriginal: null,
|
| 12966 |
minuteMaxOriginal: null,
|
| 12967 |
secondMaxOriginal: null,
|
| 12968 |
millisecMaxOriginal: null,
|
| 12969 |
ampm: '',
|
| 12970 |
formattedDate: '',
|
| 12971 |
formattedTime: '',
|
| 12972 |
formattedDateTime: '',
|
| 12973 |
timezoneList: null,
|
| 12974 |
units: ['hour','minute','second','millisec'],
|
| 12975 |
control: null,
|
| 12976 |
|
| 12977 |
/*
|
| 12978 |
* Override the default settings for all instances of the time picker.
|
| 12979 |
* @param settings object - the new settings to use as defaults (anonymous object)
|
| 12980 |
* @return the manager object
|
| 12981 |
*/
|
| 12982 |
setDefaults: function(settings) {
|
| 12983 |
extendRemove(this._defaults, settings || {});
|
| 12984 |
return this;
|
| 12985 |
},
|
| 12986 |
|
| 12987 |
/*
|
| 12988 |
* Create a new Timepicker instance
|
| 12989 |
*/
|
| 12990 |
_newInst: function($input, o) {
|
| 12991 |
var tp_inst = new Timepicker(),
|
| 12992 |
inlineSettings = {},
|
| 12993 |
fns = {},
|
| 12994 |
overrides, i;
|
| 12995 |
|
| 12996 |
for (var attrName in this._defaults) {
|
| 12997 |
if(this._defaults.hasOwnProperty(attrName)){
|
| 12998 |
var attrValue = $input.attr('time:' + attrName);
|
| 12999 |
if (attrValue) {
|
| 13000 |
try {
|
| 13001 |
inlineSettings[attrName] = eval(attrValue);
|
| 13002 |
} catch (err) {
|
| 13003 |
inlineSettings[attrName] = attrValue;
|
| 13004 |
}
|
| 13005 |
}
|
| 13006 |
}
|
| 13007 |
}
|
| 13008 |
overrides = {
|
| 13009 |
beforeShow: function (input, dp_inst) {
|
| 13010 |
if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {
|
| 13011 |
return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);
|
| 13012 |
}
|
| 13013 |
},
|
| 13014 |
onChangeMonthYear: function (year, month, dp_inst) {
|
| 13015 |
// Update the time as well : this prevents the time from disappearing from the $input field.
|
| 13016 |
tp_inst._updateDateTime(dp_inst);
|
| 13017 |
if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) {
|
| 13018 |
tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
|
| 13019 |
}
|
| 13020 |
},
|
| 13021 |
onClose: function (dateText, dp_inst) {
|
| 13022 |
if (tp_inst.timeDefined === true && $input.val() !== '') {
|
| 13023 |
tp_inst._updateDateTime(dp_inst);
|
| 13024 |
}
|
| 13025 |
if ($.isFunction(tp_inst._defaults.evnts.onClose)) {
|
| 13026 |
tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);
|
| 13027 |
}
|
| 13028 |
}
|
| 13029 |
};
|
| 13030 |
for (i in overrides) {
|
| 13031 |
if (overrides.hasOwnProperty(i)) {
|
| 13032 |
fns[i] = o[i] || null;
|
| 13033 |
}
|
| 13034 |
}
|
| 13035 |
tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, {
|
| 13036 |
evnts:fns,
|
| 13037 |
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
|
| 13038 |
});
|
| 13039 |
tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) {
|
| 13040 |
return val.toUpperCase();
|
| 13041 |
});
|
| 13042 |
tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) {
|
| 13043 |
return val.toUpperCase();
|
| 13044 |
});
|
| 13045 |
|
| 13046 |
// controlType is string - key to our this._controls
|
| 13047 |
if(typeof(tp_inst._defaults.controlType) === 'string'){
|
| 13048 |
if($.fn[tp_inst._defaults.controlType] === undefined){
|
| 13049 |
tp_inst._defaults.controlType = 'select';
|
| 13050 |
}
|
| 13051 |
tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];
|
| 13052 |
}
|
| 13053 |
// controlType is an object and must implement create, options, value methods
|
| 13054 |
else{
|
| 13055 |
tp_inst.control = tp_inst._defaults.controlType;
|
| 13056 |
}
|
| 13057 |
|
| 13058 |
if (tp_inst._defaults.timezoneList === null) {
|
| 13059 |
var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000',
|
| 13060 |
'+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930',
|
| 13061 |
'+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400'];
|
| 13062 |
|
| 13063 |
if (tp_inst._defaults.timezoneIso8601) {
|
| 13064 |
timezoneList = $.map(timezoneList, function(val) {
|
| 13065 |
return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
|
| 13066 |
});
|
| 13067 |
}
|
| 13068 |
tp_inst._defaults.timezoneList = timezoneList;
|
| 13069 |
}
|
| 13070 |
|
| 13071 |
tp_inst.timezone = tp_inst._defaults.timezone;
|
| 13072 |
tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin :
|
| 13073 |
tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
|
| 13074 |
tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin :
|
| 13075 |
tp_inst._defaults.minute > tp_inst._defaults.minuteMax? tp_inst._defaults.minuteMax : tp_inst._defaults.minute;
|
| 13076 |
tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin? tp_inst._defaults.secondMin :
|
| 13077 |
tp_inst._defaults.second > tp_inst._defaults.secondMax? tp_inst._defaults.secondMax : tp_inst._defaults.second;
|
| 13078 |
tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin? tp_inst._defaults.millisecMin :
|
| 13079 |
tp_inst._defaults.millisec > tp_inst._defaults.millisecMax? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec;
|
| 13080 |
tp_inst.ampm = '';
|
| 13081 |
tp_inst.$input = $input;
|
| 13082 |
|
| 13083 |
if (o.altField) {
|
| 13084 |
tp_inst.$altInput = $(o.altField).css({
|
| 13085 |
cursor: 'pointer'
|
| 13086 |
}).focus(function() {
|
| 13087 |
$input.trigger("focus");
|
| 13088 |
});
|
| 13089 |
}
|
| 13090 |
|
| 13091 |
if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) {
|
| 13092 |
tp_inst._defaults.minDate = new Date();
|
| 13093 |
}
|
| 13094 |
if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) {
|
| 13095 |
tp_inst._defaults.maxDate = new Date();
|
| 13096 |
}
|
| 13097 |
|
| 13098 |
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
|
| 13099 |
if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) {
|
| 13100 |
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
|
| 13101 |
}
|
| 13102 |
if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) {
|
| 13103 |
tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
|
| 13104 |
}
|
| 13105 |
if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) {
|
| 13106 |
tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
|
| 13107 |
}
|
| 13108 |
if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) {
|
| 13109 |
tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
|
| 13110 |
}
|
| 13111 |
tp_inst.$input.bind('focus', function() {
|
| 13112 |
tp_inst._onFocus();
|
| 13113 |
});
|
| 13114 |
|
| 13115 |
return tp_inst;
|
| 13116 |
},
|
| 13117 |
|
| 13118 |
/*
|
| 13119 |
* add our sliders to the calendar
|
| 13120 |
*/
|
| 13121 |
_addTimePicker: function(dp_inst) {
|
| 13122 |
var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val();
|
| 13123 |
|
| 13124 |
this.timeDefined = this._parseTime(currDT);
|
| 13125 |
this._limitMinMaxDateTime(dp_inst, false);
|
| 13126 |
this._injectTimePicker();
|
| 13127 |
},
|
| 13128 |
|
| 13129 |
/*
|
| 13130 |
* parse the time string from input value or _setTime
|
| 13131 |
*/
|
| 13132 |
_parseTime: function(timeString, withDate) {
|
| 13133 |
if (!this.inst) {
|
| 13134 |
this.inst = $.datepicker._getInst(this.$input[0]);
|
| 13135 |
}
|
| 13136 |
|
| 13137 |
if (withDate || !this._defaults.timeOnly) {
|
| 13138 |
var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
|
| 13139 |
try {
|
| 13140 |
var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults);
|
| 13141 |
if (!parseRes.timeObj) {
|
| 13142 |
return false;
|
| 13143 |
}
|
| 13144 |
$.extend(this, parseRes.timeObj);
|
| 13145 |
} catch (err) {
|
| 13146 |
$.timepicker.log("Error parsing the date/time string: " + err +
|
| 13147 |
"\ndate/time string = " + timeString +
|
| 13148 |
"\ntimeFormat = " + this._defaults.timeFormat +
|
| 13149 |
"\ndateFormat = " + dp_dateFormat);
|
| 13150 |
return false;
|
| 13151 |
}
|
| 13152 |
return true;
|
| 13153 |
} else {
|
| 13154 |
var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults);
|
| 13155 |
if (!timeObj) {
|
| 13156 |
return false;
|
| 13157 |
}
|
| 13158 |
$.extend(this, timeObj);
|
| 13159 |
return true;
|
| 13160 |
}
|
| 13161 |
},
|
| 13162 |
|
| 13163 |
/*
|
| 13164 |
* generate and inject html for timepicker into ui datepicker
|
| 13165 |
*/
|
| 13166 |
_injectTimePicker: function() {
|
| 13167 |
var $dp = this.inst.dpDiv,
|
| 13168 |
o = this.inst.settings,
|
| 13169 |
tp_inst = this,
|
| 13170 |
litem = '',
|
| 13171 |
uitem = '',
|
| 13172 |
max = {},
|
| 13173 |
gridSize = {},
|
| 13174 |
size = null;
|
| 13175 |
|
| 13176 |
// Prevent displaying twice
|
| 13177 |
if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) {
|
| 13178 |
var noDisplay = ' style="display:none;"',
|
| 13179 |
html = '<div class="ui-timepicker-div'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
|
| 13180 |
'<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>';
|
| 13181 |
|
| 13182 |
// Create the markup
|
| 13183 |
for(var i=0,l=this.units.length; i<l; i++){
|
| 13184 |
litem = this.units[i];
|
| 13185 |
uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
| 13186 |
// Added by Peter Medeiros:
|
| 13187 |
// - Figure out what the hour/minute/second max should be based on the step values.
|
| 13188 |
// - Example: if stepMinute is 15, then minMax is 45.
|
| 13189 |
max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10);
|
| 13190 |
gridSize[litem] = 0;
|
| 13191 |
|
| 13192 |
html += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' +
|
| 13193 |
'<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>';
|
| 13194 |
|
| 13195 |
if (o['show'+uitem] && o[litem+'Grid'] > 0) {
|
| 13196 |
html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
|
| 13197 |
|
| 13198 |
if(litem == 'hour'){
|
| 13199 |
for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) {
|
| 13200 |
gridSize[litem]++;
|
| 13201 |
var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o);
|
| 13202 |
html += '<td data-for="'+litem+'">' + tmph + '</td>';
|
| 13203 |
}
|
| 13204 |
}
|
| 13205 |
else{
|
| 13206 |
for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) {
|
| 13207 |
gridSize[litem]++;
|
| 13208 |
html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>';
|
| 13209 |
}
|
| 13210 |
}
|
| 13211 |
|
| 13212 |
html += '</tr></table></div>';
|
| 13213 |
}
|
| 13214 |
html += '</dd>';
|
| 13215 |
}
|
| 13216 |
|
| 13217 |
// Timezone
|
| 13218 |
html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
|
| 13219 |
html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>';
|
| 13220 |
|
| 13221 |
// Create the elements from string
|
| 13222 |
html += '</dl></div>';
|
| 13223 |
var $tp = $(html);
|
| 13224 |
|
| 13225 |
// if we only want time picker...
|
| 13226 |
if (o.timeOnly === true) {
|
| 13227 |
$tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
|
| 13228 |
$dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
|
| 13229 |
}
|
| 13230 |
|
| 13231 |
// add sliders, adjust grids, add events
|
| 13232 |
for(var i=0,l=tp_inst.units.length; i<l; i++){
|
| 13233 |
litem = tp_inst.units[i];
|
| 13234 |
uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
| 13235 |
|
| 13236 |
// add the slider
|
| 13237 |
tp_inst[litem+'_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_'+litem+'_slider'), litem, tp_inst[litem], o[litem+'Min'], max[litem], o['step'+uitem]);
|
| 13238 |
|
| 13239 |
// adjust the grid and add click event
|
| 13240 |
if (o['show'+uitem] && o[litem+'Grid'] > 0) {
|
| 13241 |
size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']);
|
| 13242 |
$tp.find('.ui_tpicker_'+litem+' table').css({
|
| 13243 |
width: size + "%",
|
| 13244 |
marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"),
|
| 13245 |
marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0',
|
| 13246 |
borderCollapse: 'collapse'
|
| 13247 |
}).find("td").click(function(e){
|
| 13248 |
var $t = $(this),
|
| 13249 |
h = $t.html(),
|
| 13250 |
n = parseInt(h.replace(/[^0-9]/g),10),
|
| 13251 |
ap = h.replace(/[^apm]/ig),
|
| 13252 |
f = $t.data('for'); // loses scope, so we use data-for
|
| 13253 |
|
| 13254 |
if(f == 'hour'){
|
| 13255 |
if(ap.indexOf('p') !== -1 && n < 12){
|
| 13256 |
n += 12;
|
| 13257 |
}
|
| 13258 |
else{
|
| 13259 |
if(ap.indexOf('a') !== -1 && n === 12){
|
| 13260 |
n = 0;
|
| 13261 |
}
|
| 13262 |
}
|
| 13263 |
}
|
| 13264 |
|
| 13265 |
tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n);
|
| 13266 |
|
| 13267 |
tp_inst._onTimeChange();
|
| 13268 |
tp_inst._onSelectHandler();
|
| 13269 |
})
|
| 13270 |
.css({
|
| 13271 |
cursor: 'pointer',
|
| 13272 |
width: (100 / gridSize[litem]) + '%',
|
| 13273 |
textAlign: 'center',
|
| 13274 |
overflow: 'hidden'
|
| 13275 |
});
|
| 13276 |
} // end if grid > 0
|
| 13277 |
} // end for loop
|
| 13278 |
|
| 13279 |
// Add timezone options
|
| 13280 |
this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select");
|
| 13281 |
$.fn.append.apply(this.timezone_select,
|
| 13282 |
$.map(o.timezoneList, function(val, idx) {
|
| 13283 |
return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val);
|
| 13284 |
}));
|
| 13285 |
if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
|
| 13286 |
var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
|
| 13287 |
var local_timezone = $.timepicker.timeZoneOffsetString(local_date);
|
| 13288 |
if (local_timezone == this.timezone) {
|
| 13289 |
selectLocalTimeZone(tp_inst);
|
| 13290 |
} else {
|
| 13291 |
this.timezone_select.val(this.timezone);
|
| 13292 |
}
|
| 13293 |
} else {
|
| 13294 |
if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {
|
| 13295 |
this.timezone_select.val(o.defaultTimezone);
|
| 13296 |
} else {
|
| 13297 |
selectLocalTimeZone(tp_inst);
|
| 13298 |
}
|
| 13299 |
}
|
| 13300 |
this.timezone_select.change(function() {
|
| 13301 |
tp_inst._defaults.useLocalTimezone = false;
|
| 13302 |
tp_inst._onTimeChange();
|
| 13303 |
tp_inst._onSelectHandler();
|
| 13304 |
});
|
| 13305 |
// End timezone options
|
| 13306 |
|
| 13307 |
// inject timepicker into datepicker
|
| 13308 |
var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
|
| 13309 |
if ($buttonPanel.length) {
|
| 13310 |
$buttonPanel.before($tp);
|
| 13311 |
} else {
|
| 13312 |
$dp.append($tp);
|
| 13313 |
}
|
| 13314 |
|
| 13315 |
this.$timeObj = $tp.find('.ui_tpicker_time');
|
| 13316 |
|
| 13317 |
if (this.inst !== null) {
|
| 13318 |
var timeDefined = this.timeDefined;
|
| 13319 |
this._onTimeChange();
|
| 13320 |
this.timeDefined = timeDefined;
|
| 13321 |
}
|
| 13322 |
|
| 13323 |
// slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
|
| 13324 |
if (this._defaults.addSliderAccess) {
|
| 13325 |
var sliderAccessArgs = this._defaults.sliderAccessArgs,
|
| 13326 |
rtl = this._defaults.isRTL;
|
| 13327 |
sliderAccessArgs.isRTL = rtl;
|
| 13328 |
|
| 13329 |
setTimeout(function() { // fix for inline mode
|
| 13330 |
if ($tp.find('.ui-slider-access').length === 0) {
|
| 13331 |
$tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
|
| 13332 |
|
| 13333 |
// fix any grids since sliders are shorter
|
| 13334 |
var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
|
| 13335 |
if (sliderAccessWidth) {
|
| 13336 |
$tp.find('table:visible').each(function() {
|
| 13337 |
var $g = $(this),
|
| 13338 |
oldWidth = $g.outerWidth(),
|
| 13339 |
oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''),
|
| 13340 |
newWidth = oldWidth - sliderAccessWidth,
|
| 13341 |
newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
|
| 13342 |
css = { width: newWidth, marginRight: 0, marginLeft: 0 };
|
| 13343 |
css[rtl? 'marginRight':'marginLeft'] = newMarginLeft;
|
| 13344 |
$g.css(css);
|
| 13345 |
});
|
| 13346 |
}
|
| 13347 |
}
|
| 13348 |
}, 10);
|
| 13349 |
}
|
| 13350 |
// end slideAccess integration
|
| 13351 |
|
| 13352 |
}
|
| 13353 |
},
|
| 13354 |
|
| 13355 |
/*
|
| 13356 |
* This function tries to limit the ability to go outside the
|
| 13357 |
* min/max date range
|
| 13358 |
*/
|
| 13359 |
_limitMinMaxDateTime: function(dp_inst, adjustSliders) {
|
| 13360 |
var o = this._defaults,
|
| 13361 |
dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
|
| 13362 |
|
| 13363 |
if (!this._defaults.showTimepicker) {
|
| 13364 |
return;
|
| 13365 |
} // No time so nothing to check here
|
| 13366 |
|
| 13367 |
if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
|
| 13368 |
var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
|
| 13369 |
minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
|
| 13370 |
|
| 13371 |
if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) {
|
| 13372 |
this.hourMinOriginal = o.hourMin;
|
| 13373 |
this.minuteMinOriginal = o.minuteMin;
|
| 13374 |
this.secondMinOriginal = o.secondMin;
|
| 13375 |
this.millisecMinOriginal = o.millisecMin;
|
| 13376 |
}
|
| 13377 |
|
| 13378 |
if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
|
| 13379 |
this._defaults.hourMin = minDateTime.getHours();
|
| 13380 |
if (this.hour <= this._defaults.hourMin) {
|
| 13381 |
this.hour = this._defaults.hourMin;
|
| 13382 |
this._defaults.minuteMin = minDateTime.getMinutes();
|
| 13383 |
if (this.minute <= this._defaults.minuteMin) {
|
| 13384 |
this.minute = this._defaults.minuteMin;
|
| 13385 |
this._defaults.secondMin = minDateTime.getSeconds();
|
| 13386 |
if (this.second <= this._defaults.secondMin) {
|
| 13387 |
this.second = this._defaults.secondMin;
|
| 13388 |
this._defaults.millisecMin = minDateTime.getMilliseconds();
|
| 13389 |
} else {
|
| 13390 |
if (this.millisec < this._defaults.millisecMin) {
|
| 13391 |
this.millisec = this._defaults.millisecMin;
|
| 13392 |
}
|
| 13393 |
this._defaults.millisecMin = this.millisecMinOriginal;
|
| 13394 |
}
|
| 13395 |
} else {
|
| 13396 |
this._defaults.secondMin = this.secondMinOriginal;
|
| 13397 |
this._defaults.millisecMin = this.millisecMinOriginal;
|
| 13398 |
}
|
| 13399 |
} else {
|
| 13400 |
this._defaults.minuteMin = this.minuteMinOriginal;
|
| 13401 |
this._defaults.secondMin = this.secondMinOriginal;
|
| 13402 |
this._defaults.millisecMin = this.millisecMinOriginal;
|
| 13403 |
}
|
| 13404 |
} else {
|
| 13405 |
this._defaults.hourMin = this.hourMinOriginal;
|
| 13406 |
this._defaults.minuteMin = this.minuteMinOriginal;
|
| 13407 |
this._defaults.secondMin = this.secondMinOriginal;
|
| 13408 |
this._defaults.millisecMin = this.millisecMinOriginal;
|
| 13409 |
}
|
| 13410 |
}
|
| 13411 |
|
| 13412 |
if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
|
| 13413 |
var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
|
| 13414 |
maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
|
| 13415 |
|
| 13416 |
if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) {
|
| 13417 |
this.hourMaxOriginal = o.hourMax;
|
| 13418 |
this.minuteMaxOriginal = o.minuteMax;
|
| 13419 |
this.secondMaxOriginal = o.secondMax;
|
| 13420 |
this.millisecMaxOriginal = o.millisecMax;
|
| 13421 |
}
|
| 13422 |
|
| 13423 |
if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) {
|
| 13424 |
this._defaults.hourMax = maxDateTime.getHours();
|
| 13425 |
if (this.hour >= this._defaults.hourMax) {
|
| 13426 |
this.hour = this._defaults.hourMax;
|
| 13427 |
this._defaults.minuteMax = maxDateTime.getMinutes();
|
| 13428 |
if (this.minute >= this._defaults.minuteMax) {
|
| 13429 |
this.minute = this._defaults.minuteMax;
|
| 13430 |
this._defaults.secondMax = maxDateTime.getSeconds();
|
| 13431 |
if (this.second >= this._defaults.secondMax) {
|
| 13432 |
this.second = this._defaults.secondMax;
|
| 13433 |
this._defaults.millisecMax = maxDateTime.getMilliseconds();
|
| 13434 |
} else {
|
| 13435 |
if (this.millisec > this._defaults.millisecMax) {
|
| 13436 |
this.millisec = this._defaults.millisecMax;
|
| 13437 |
}
|
| 13438 |
this._defaults.millisecMax = this.millisecMaxOriginal;
|
| 13439 |
}
|
| 13440 |
} else {
|
| 13441 |
this._defaults.secondMax = this.secondMaxOriginal;
|
| 13442 |
this._defaults.millisecMax = this.millisecMaxOriginal;
|
| 13443 |
}
|
| 13444 |
} else {
|
| 13445 |
this._defaults.minuteMax = this.minuteMaxOriginal;
|
| 13446 |
this._defaults.secondMax = this.secondMaxOriginal;
|
| 13447 |
this._defaults.millisecMax = this.millisecMaxOriginal;
|
| 13448 |
}
|
| 13449 |
} else {
|
| 13450 |
this._defaults.hourMax = this.hourMaxOriginal;
|
| 13451 |
this._defaults.minuteMax = this.minuteMaxOriginal;
|
| 13452 |
this._defaults.secondMax = this.secondMaxOriginal;
|
| 13453 |
this._defaults.millisecMax = this.millisecMaxOriginal;
|
| 13454 |
}
|
| 13455 |
}
|
| 13456 |
|
| 13457 |
if (adjustSliders !== undefined && adjustSliders === true) {
|
| 13458 |
var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
|
| 13459 |
minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
|
| 13460 |
secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
|
| 13461 |
millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10);
|
| 13462 |
|
| 13463 |
if (this.hour_slider) {
|
| 13464 |
this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax });
|
| 13465 |
this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
|
| 13466 |
}
|
| 13467 |
if (this.minute_slider) {
|
| 13468 |
this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax });
|
| 13469 |
this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
|
| 13470 |
}
|
| 13471 |
if (this.second_slider) {
|
| 13472 |
this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax });
|
| 13473 |
this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
|
| 13474 |
}
|
| 13475 |
if (this.millisec_slider) {
|
| 13476 |
this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax });
|
| 13477 |
this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
|
| 13478 |
}
|
| 13479 |
}
|
| 13480 |
|
| 13481 |
},
|
| 13482 |
|
| 13483 |
/*
|
| 13484 |
* when a slider moves, set the internal time...
|
| 13485 |
* on time change is also called when the time is updated in the text field
|
| 13486 |
*/
|
| 13487 |
_onTimeChange: function() {
|
| 13488 |
var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
|
| 13489 |
minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
|
| 13490 |
second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
|
| 13491 |
millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
|
| 13492 |
timezone = (this.timezone_select) ? this.timezone_select.val() : false,
|
| 13493 |
o = this._defaults,
|
| 13494 |
pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
|
| 13495 |
pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
|
| 13496 |
|
| 13497 |
if (typeof(hour) == 'object') {
|
| 13498 |
hour = false;
|
| 13499 |
}
|
| 13500 |
if (typeof(minute) == 'object') {
|
| 13501 |
minute = false;
|
| 13502 |
}
|
| 13503 |
if (typeof(second) == 'object') {
|
| 13504 |
second = false;
|
| 13505 |
}
|
| 13506 |
if (typeof(millisec) == 'object') {
|
| 13507 |
millisec = false;
|
| 13508 |
}
|
| 13509 |
if (typeof(timezone) == 'object') {
|
| 13510 |
timezone = false;
|
| 13511 |
}
|
| 13512 |
|
| 13513 |
if (hour !== false) {
|
| 13514 |
hour = parseInt(hour, 10);
|
| 13515 |
}
|
| 13516 |
if (minute !== false) {
|
| 13517 |
minute = parseInt(minute, 10);
|
| 13518 |
}
|
| 13519 |
if (second !== false) {
|
| 13520 |
second = parseInt(second, 10);
|
| 13521 |
}
|
| 13522 |
if (millisec !== false) {
|
| 13523 |
millisec = parseInt(millisec, 10);
|
| 13524 |
}
|
| 13525 |
|
| 13526 |
var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
|
| 13527 |
|
| 13528 |
// If the update was done in the input field, the input field should not be updated.
|
| 13529 |
// If the update was done using the sliders, update the input field.
|
| 13530 |
var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec
|
| 13531 |
|| (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
|
| 13532 |
|| ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone)));
|
| 13533 |
|
| 13534 |
if (hasChanged) {
|
| 13535 |
|
| 13536 |
if (hour !== false) {
|
| 13537 |
this.hour = hour;
|
| 13538 |
}
|
| 13539 |
if (minute !== false) {
|
| 13540 |
this.minute = minute;
|
| 13541 |
}
|
| 13542 |
if (second !== false) {
|
| 13543 |
this.second = second;
|
| 13544 |
}
|
| 13545 |
if (millisec !== false) {
|
| 13546 |
this.millisec = millisec;
|
| 13547 |
}
|
| 13548 |
if (timezone !== false) {
|
| 13549 |
this.timezone = timezone;
|
| 13550 |
}
|
| 13551 |
|
| 13552 |
if (!this.inst) {
|
| 13553 |
this.inst = $.datepicker._getInst(this.$input[0]);
|
| 13554 |
}
|
| 13555 |
|
| 13556 |
this._limitMinMaxDateTime(this.inst, true);
|
| 13557 |
}
|
| 13558 |
if (useAmpm(o.timeFormat)) {
|
| 13559 |
this.ampm = ampm;
|
| 13560 |
}
|
| 13561 |
|
| 13562 |
// Updates the time within the timepicker
|
| 13563 |
this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
|
| 13564 |
if (this.$timeObj) {
|
| 13565 |
if(pickerTimeFormat === o.timeFormat){
|
| 13566 |
this.$timeObj.text(this.formattedTime + pickerTimeSuffix);
|
| 13567 |
}
|
| 13568 |
else{
|
| 13569 |
this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
|
| 13570 |
}
|
| 13571 |
}
|
| 13572 |
|
| 13573 |
this.timeDefined = true;
|
| 13574 |
if (hasChanged) {
|
| 13575 |
this._updateDateTime();
|
| 13576 |
}
|
| 13577 |
},
|
| 13578 |
|
| 13579 |
/*
|
| 13580 |
* call custom onSelect.
|
| 13581 |
* bind to sliders slidestop, and grid click.
|
| 13582 |
*/
|
| 13583 |
_onSelectHandler: function() {
|
| 13584 |
var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
|
| 13585 |
var inputEl = this.$input ? this.$input[0] : null;
|
| 13586 |
if (onSelect && inputEl) {
|
| 13587 |
onSelect.apply(inputEl, [this.formattedDateTime, this]);
|
| 13588 |
}
|
| 13589 |
},
|
| 13590 |
|
| 13591 |
/*
|
| 13592 |
* update our input with the new date time..
|
| 13593 |
*/
|
| 13594 |
_updateDateTime: function(dp_inst) {
|
| 13595 |
dp_inst = this.inst || dp_inst;
|
| 13596 |
var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
|
| 13597 |
dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
|
| 13598 |
formatCfg = $.datepicker._getFormatConfig(dp_inst),
|
| 13599 |
timeAvailable = dt !== null && this.timeDefined;
|
| 13600 |
this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
|
| 13601 |
var formattedDateTime = this.formattedDate;
|
| 13602 |
|
| 13603 |
// if a slider was changed but datepicker doesn't have a value yet, set it
|
| 13604 |
if(dp_inst.lastVal==""){
|
| 13605 |
dp_inst.currentYear=dp_inst.selectedYear;
|
| 13606 |
dp_inst.currentMonth=dp_inst.selectedMonth;
|
| 13607 |
dp_inst.currentDay=dp_inst.selectedDay;
|
| 13608 |
}
|
| 13609 |
|
| 13610 |
/*
|
| 13611 |
* remove following lines to force every changes in date picker to change the input value
|
| 13612 |
* Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
|
| 13613 |
* If the user manually empty the value in the input field, the date picker will never change selected value.
|
| 13614 |
*/
|
| 13615 |
//if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
|
| 13616 |
// return;
|
| 13617 |
//}
|
| 13618 |
|
| 13619 |
if (this._defaults.timeOnly === true) {
|
| 13620 |
formattedDateTime = this.formattedTime;
|
| 13621 |
} else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
|
| 13622 |
formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
|
| 13623 |
}
|
| 13624 |
|
| 13625 |
this.formattedDateTime = formattedDateTime;
|
| 13626 |
|
| 13627 |
if (!this._defaults.showTimepicker) {
|
| 13628 |
this.$input.val(this.formattedDate);
|
| 13629 |
} else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
|
| 13630 |
this.$altInput.val(this.formattedTime);
|
| 13631 |
this.$input.val(this.formattedDate);
|
| 13632 |
} else if (this.$altInput) {
|
| 13633 |
this.$input.val(formattedDateTime);
|
| 13634 |
var altFormattedDateTime = '',
|
| 13635 |
altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator,
|
| 13636 |
altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
|
| 13637 |
|
| 13638 |
if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
|
| 13639 |
else altFormattedDateTime = this.formattedDate;
|
| 13640 |
if (altFormattedDateTime) altFormattedDateTime += altSeparator;
|
| 13641 |
if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
|
| 13642 |
else altFormattedDateTime += this.formattedTime + altTimeSuffix;
|
| 13643 |
this.$altInput.val(altFormattedDateTime);
|
| 13644 |
} else {
|
| 13645 |
this.$input.val(formattedDateTime);
|
| 13646 |
}
|
| 13647 |
|
| 13648 |
this.$input.trigger("change");
|
| 13649 |
},
|
| 13650 |
|
| 13651 |
_onFocus: function() {
|
| 13652 |
if (!this.$input.val() && this._defaults.defaultValue) {
|
| 13653 |
this.$input.val(this._defaults.defaultValue);
|
| 13654 |
var inst = $.datepicker._getInst(this.$input.get(0)),
|
| 13655 |
tp_inst = $.datepicker._get(inst, 'timepicker');
|
| 13656 |
if (tp_inst) {
|
| 13657 |
if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
|
| 13658 |
try {
|
| 13659 |
$.datepicker._updateDatepicker(inst);
|
| 13660 |
} catch (err) {
|
| 13661 |
$.timepicker.log(err);
|
| 13662 |
}
|
| 13663 |
}
|
| 13664 |
}
|
| 13665 |
}
|
| 13666 |
},
|
| 13667 |
|
| 13668 |
/*
|
| 13669 |
* Small abstraction to control types
|
| 13670 |
* We can add more, just be sure to follow the pattern: create, options, value
|
| 13671 |
*/
|
| 13672 |
_controls: {
|
| 13673 |
// slider methods
|
| 13674 |
slider: {
|
| 13675 |
create: function(tp_inst, obj, unit, val, min, max, step){
|
| 13676 |
var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
|
| 13677 |
return obj.prop('slide', null).slider({
|
| 13678 |
orientation: "horizontal",
|
| 13679 |
value: rtl? val*-1 : val,
|
| 13680 |
min: rtl? max*-1 : min,
|
| 13681 |
max: rtl? min*-1 : max,
|
| 13682 |
step: step,
|
| 13683 |
slide: function(event, ui) {
|
| 13684 |
tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value);
|
| 13685 |
tp_inst._onTimeChange();
|
| 13686 |
},
|
| 13687 |
stop: function(event, ui) {
|
| 13688 |
tp_inst._onSelectHandler();
|
| 13689 |
}
|
| 13690 |
});
|
| 13691 |
},
|
| 13692 |
options: function(tp_inst, obj, unit, opts, val){
|
| 13693 |
if(tp_inst._defaults.isRTL){
|
| 13694 |
if(typeof(opts) == 'string'){
|
| 13695 |
if(opts == 'min' || opts == 'max'){
|
| 13696 |
if(val !== undefined)
|
| 13697 |
return obj.slider(opts, val*-1);
|
| 13698 |
return Math.abs(obj.slider(opts));
|
| 13699 |
}
|
| 13700 |
return obj.slider(opts);
|
| 13701 |
}
|
| 13702 |
var min = opts.min,
|
| 13703 |
max = opts.max;
|
| 13704 |
opts.min = opts.max = null;
|
| 13705 |
if(min !== undefined)
|
| 13706 |
opts.max = min * -1;
|
| 13707 |
if(max !== undefined)
|
| 13708 |
opts.min = max * -1;
|
| 13709 |
return obj.slider(opts);
|
| 13710 |
}
|
| 13711 |
if(typeof(opts) == 'string' && val !== undefined)
|
| 13712 |
return obj.slider(opts, val);
|
| 13713 |
return obj.slider(opts);
|
| 13714 |
},
|
| 13715 |
value: function(tp_inst, obj, unit, val){
|
| 13716 |
if(tp_inst._defaults.isRTL){
|
| 13717 |
if(val !== undefined)
|
| 13718 |
return obj.slider('value', val*-1);
|
| 13719 |
return Math.abs(obj.slider('value'));
|
| 13720 |
}
|
| 13721 |
if(val !== undefined)
|
| 13722 |
return obj.slider('value', val);
|
| 13723 |
return obj.slider('value');
|
| 13724 |
}
|
| 13725 |
},
|
| 13726 |
// select methods
|
| 13727 |
select: {
|
| 13728 |
create: function(tp_inst, obj, unit, val, min, max, step){
|
| 13729 |
var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">',
|
| 13730 |
ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase',
|
| 13731 |
m = 0;
|
| 13732 |
|
| 13733 |
for(var i=min; i<=max; i+=step){
|
| 13734 |
sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>';
|
| 13735 |
if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat))
|
| 13736 |
sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults);
|
| 13737 |
else if(unit == 'millisec' || i >= 10) sel += i;
|
| 13738 |
else sel += '0'+ i.toString();
|
| 13739 |
sel += '</option>';
|
| 13740 |
}
|
| 13741 |
sel += '</select>';
|
| 13742 |
|
| 13743 |
obj.children('select').remove();
|
| 13744 |
|
| 13745 |
$(sel).appendTo(obj).change(function(e){
|
| 13746 |
tp_inst._onTimeChange();
|
| 13747 |
tp_inst._onSelectHandler();
|
| 13748 |
});
|
| 13749 |
|
| 13750 |
return obj;
|
| 13751 |
},
|
| 13752 |
options: function(tp_inst, obj, unit, opts, val){
|
| 13753 |
var o = {},
|
| 13754 |
$t = obj.children('select');
|
| 13755 |
if(typeof(opts) == 'string'){
|
| 13756 |
if(val === undefined)
|
| 13757 |
return $t.data(opts);
|
| 13758 |
o[opts] = val;
|
| 13759 |
}
|
| 13760 |
else o = opts;
|
| 13761 |
return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
|
| 13762 |
},
|
| 13763 |
value: function(tp_inst, obj, unit, val){
|
| 13764 |
var $t = obj.children('select');
|
| 13765 |
if(val !== undefined)
|
| 13766 |
return $t.val(val);
|
| 13767 |
return $t.val();
|
| 13768 |
}
|
| 13769 |
}
|
| 13770 |
} // end _controls
|
| 13771 |
|
| 13772 |
});
|
| 13773 |
|
| 13774 |
$.fn.extend({
|
| 13775 |
/*
|
| 13776 |
* shorthand just to use timepicker..
|
| 13777 |
*/
|
| 13778 |
timepicker: function(o) {
|
| 13779 |
o = o || {};
|
| 13780 |
var tmp_args = Array.prototype.slice.call(arguments);
|
| 13781 |
|
| 13782 |
if (typeof o == 'object') {
|
| 13783 |
tmp_args[0] = $.extend(o, {
|
| 13784 |
timeOnly: true
|
| 13785 |
});
|
| 13786 |
}
|
| 13787 |
|
| 13788 |
return $(this).each(function() {
|
| 13789 |
$.fn.datetimepicker.apply($(this), tmp_args);
|
| 13790 |
});
|
| 13791 |
},
|
| 13792 |
|
| 13793 |
/*
|
| 13794 |
* extend timepicker to datepicker
|
| 13795 |
*/
|
| 13796 |
datetimepicker: function(o) {
|
| 13797 |
o = o || {};
|
| 13798 |
var tmp_args = arguments;
|
| 13799 |
|
| 13800 |
if (typeof(o) == 'string') {
|
| 13801 |
if (o == 'getDate') {
|
| 13802 |
return $.fn.datepicker.apply($(this[0]), tmp_args);
|
| 13803 |
} else {
|
| 13804 |
return this.each(function() {
|
| 13805 |
var $t = $(this);
|
| 13806 |
$t.datepicker.apply($t, tmp_args);
|
| 13807 |
});
|
| 13808 |
}
|
| 13809 |
} else {
|
| 13810 |
return this.each(function() {
|
| 13811 |
var $t = $(this);
|
| 13812 |
$t.datepicker($.timepicker._newInst($t, o)._defaults);
|
| 13813 |
});
|
| 13814 |
}
|
| 13815 |
}
|
| 13816 |
});
|
| 13817 |
|
| 13818 |
/*
|
| 13819 |
* Public Utility to parse date and time
|
| 13820 |
*/
|
| 13821 |
$.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
|
| 13822 |
var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
|
| 13823 |
if (parseRes.timeObj) {
|
| 13824 |
var t = parseRes.timeObj;
|
| 13825 |
parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
|
| 13826 |
}
|
| 13827 |
|
| 13828 |
return parseRes.date;
|
| 13829 |
};
|
| 13830 |
|
| 13831 |
/*
|
| 13832 |
* Public utility to parse time
|
| 13833 |
*/
|
| 13834 |
$.datepicker.parseTime = function(timeFormat, timeString, options) {
|
| 13835 |
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
|
| 13836 |
|
| 13837 |
// Strict parse requires the timeString to match the timeFormat exactly
|
| 13838 |
var strictParse = function(f, s, o){
|
| 13839 |
|
| 13840 |
// pattern for standard and localized AM/PM markers
|
| 13841 |
var getPatternAmpm = function(amNames, pmNames) {
|
| 13842 |
var markers = [];
|
| 13843 |
if (amNames) {
|
| 13844 |
$.merge(markers, amNames);
|
| 13845 |
}
|
| 13846 |
if (pmNames) {
|
| 13847 |
$.merge(markers, pmNames);
|
| 13848 |
}
|
| 13849 |
markers = $.map(markers, function(val) {
|
| 13850 |
return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
|
| 13851 |
});
|
| 13852 |
return '(' + markers.join('|') + ')?';
|
| 13853 |
};
|
| 13854 |
|
| 13855 |
// figure out position of time elements.. cause js cant do named captures
|
| 13856 |
var getFormatPositions = function(timeFormat) {
|
| 13857 |
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
|
| 13858 |
orders = {
|
| 13859 |
h: -1,
|
| 13860 |
m: -1,
|
| 13861 |
s: -1,
|
| 13862 |
l: -1,
|
| 13863 |
t: -1,
|
| 13864 |
z: -1
|
| 13865 |
};
|
| 13866 |
|
| 13867 |
if (finds) {
|
| 13868 |
for (var i = 0; i < finds.length; i++) {
|
| 13869 |
if (orders[finds[i].toString().charAt(0)] == -1) {
|
| 13870 |
orders[finds[i].toString().charAt(0)] = i + 1;
|
| 13871 |
}
|
| 13872 |
}
|
| 13873 |
}
|
| 13874 |
return orders;
|
| 13875 |
};
|
| 13876 |
|
| 13877 |
var regstr = '^' + f.toString()
|
| 13878 |
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) {
|
| 13879 |
var ml = match.length;
|
| 13880 |
switch (match.charAt(0).toLowerCase()) {
|
| 13881 |
case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
|
| 13882 |
case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
|
| 13883 |
case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
|
| 13884 |
case 'l': return '(\\d?\\d?\\d)';
|
| 13885 |
case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
|
| 13886 |
case 't': return getPatternAmpm(o.amNames, o.pmNames);
|
| 13887 |
default: // literal escaped in quotes
|
| 13888 |
return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
|
| 13889 |
}
|
| 13890 |
})
|
| 13891 |
.replace(/\s/g, '\\s?') +
|
| 13892 |
o.timeSuffix + '$',
|
| 13893 |
order = getFormatPositions(f),
|
| 13894 |
ampm = '',
|
| 13895 |
treg;
|
| 13896 |
|
| 13897 |
treg = s.match(new RegExp(regstr, 'i'));
|
| 13898 |
|
| 13899 |
var resTime = {
|
| 13900 |
hour: 0,
|
| 13901 |
minute: 0,
|
| 13902 |
second: 0,
|
| 13903 |
millisec: 0
|
| 13904 |
};
|
| 13905 |
|
| 13906 |
if (treg) {
|
| 13907 |
if (order.t !== -1) {
|
| 13908 |
if (treg[order.t] === undefined || treg[order.t].length === 0) {
|
| 13909 |
ampm = '';
|
| 13910 |
resTime.ampm = '';
|
| 13911 |
} else {
|
| 13912 |
ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM';
|
| 13913 |
resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
|
| 13914 |
}
|
| 13915 |
}
|
| 13916 |
|
| 13917 |
if (order.h !== -1) {
|
| 13918 |
if (ampm == 'AM' && treg[order.h] == '12') {
|
| 13919 |
resTime.hour = 0; // 12am = 0 hour
|
| 13920 |
} else {
|
| 13921 |
if (ampm == 'PM' && treg[order.h] != '12') {
|
| 13922 |
resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
|
| 13923 |
} else {
|
| 13924 |
resTime.hour = Number(treg[order.h]);
|
| 13925 |
}
|
| 13926 |
}
|
| 13927 |
}
|
| 13928 |
|
| 13929 |
if (order.m !== -1) {
|
| 13930 |
resTime.minute = Number(treg[order.m]);
|
| 13931 |
}
|
| 13932 |
if (order.s !== -1) {
|
| 13933 |
resTime.second = Number(treg[order.s]);
|
| 13934 |
}
|
| 13935 |
if (order.l !== -1) {
|
| 13936 |
resTime.millisec = Number(treg[order.l]);
|
| 13937 |
}
|
| 13938 |
if (order.z !== -1 && treg[order.z] !== undefined) {
|
| 13939 |
var tz = treg[order.z].toUpperCase();
|
| 13940 |
switch (tz.length) {
|
| 13941 |
case 1:
|
| 13942 |
// Z
|
| 13943 |
tz = o.timezoneIso8601 ? 'Z' : '+0000';
|
| 13944 |
break;
|
| 13945 |
case 5:
|
| 13946 |
// +hhmm
|
| 13947 |
if (o.timezoneIso8601) {
|
| 13948 |
tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3);
|
| 13949 |
}
|
| 13950 |
break;
|
| 13951 |
case 6:
|
| 13952 |
// +hh:mm
|
| 13953 |
if (!o.timezoneIso8601) {
|
| 13954 |
tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, '');
|
| 13955 |
} else {
|
| 13956 |
if (tz.substring(1) == '00:00') {
|
| 13957 |
tz = 'Z';
|
| 13958 |
}
|
| 13959 |
}
|
| 13960 |
break;
|
| 13961 |
}
|
| 13962 |
resTime.timezone = tz;
|
| 13963 |
}
|
| 13964 |
|
| 13965 |
|
| 13966 |
return resTime;
|
| 13967 |
}
|
| 13968 |
return false;
|
| 13969 |
};// end strictParse
|
| 13970 |
|
| 13971 |
// First try JS Date, if that fails, use strictParse
|
| 13972 |
var looseParse = function(f,s,o){
|
| 13973 |
try{
|
| 13974 |
var d = new Date('2012-01-01 '+ s);
|
| 13975 |
if(isNaN(d.getTime())){
|
| 13976 |
d = new Date('2012-01-01T'+ s);
|
| 13977 |
if(isNaN(d.getTime())){
|
| 13978 |
d = new Date('01/01/2012 '+ s);
|
| 13979 |
if(isNaN(d.getTime())){
|
| 13980 |
throw "Unable to parse time with native Date: "+ s;
|
| 13981 |
}
|
| 13982 |
}
|
| 13983 |
}
|
| 13984 |
|
| 13985 |
return {
|
| 13986 |
hour: d.getHours(),
|
| 13987 |
minute: d.getMinutes(),
|
| 13988 |
second: d.getSeconds(),
|
| 13989 |
millisec: d.getMilliseconds(),
|
| 13990 |
timezone: $.timepicker.timeZoneOffsetString(d)
|
| 13991 |
};
|
| 13992 |
}
|
| 13993 |
catch(err){
|
| 13994 |
try{
|
| 13995 |
return strictParse(f,s,o);
|
| 13996 |
}
|
| 13997 |
catch(err2){
|
| 13998 |
$.timepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f);
|
| 13999 |
}
|
| 14000 |
}
|
| 14001 |
return false;
|
| 14002 |
}; // end looseParse
|
| 14003 |
|
| 14004 |
if(typeof o.parse === "function"){
|
| 14005 |
return o.parse(timeFormat, timeString, o)
|
| 14006 |
}
|
| 14007 |
if(o.parse === 'loose'){
|
| 14008 |
return looseParse(timeFormat, timeString, o);
|
| 14009 |
}
|
| 14010 |
return strictParse(timeFormat, timeString, o);
|
| 14011 |
};
|
| 14012 |
|
| 14013 |
/*
|
| 14014 |
* Public utility to format the time
|
| 14015 |
* format = string format of the time
|
| 14016 |
* time = a {}, not a Date() for timezones
|
| 14017 |
* options = essentially the regional[].. amNames, pmNames, ampm
|
| 14018 |
*/
|
| 14019 |
$.datepicker.formatTime = function(format, time, options) {
|
| 14020 |
options = options || {};
|
| 14021 |
options = $.extend({}, $.timepicker._defaults, options);
|
| 14022 |
time = $.extend({
|
| 14023 |
hour: 0,
|
| 14024 |
minute: 0,
|
| 14025 |
second: 0,
|
| 14026 |
millisec: 0,
|
| 14027 |
timezone: '+0000'
|
| 14028 |
}, time);
|
| 14029 |
|
| 14030 |
var tmptime = format,
|
| 14031 |
ampmName = options.amNames[0],
|
| 14032 |
hour = parseInt(time.hour, 10);
|
| 14033 |
|
| 14034 |
if (hour > 11) {
|
| 14035 |
ampmName = options.pmNames[0];
|
| 14036 |
}
|
| 14037 |
|
| 14038 |
tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
|
| 14039 |
switch (match) {
|
| 14040 |
case 'HH':
|
| 14041 |
return ('0' + hour).slice(-2);
|
| 14042 |
case 'H':
|
| 14043 |
return hour;
|
| 14044 |
case 'hh':
|
| 14045 |
return ('0' + convert24to12(hour)).slice(-2);
|
| 14046 |
case 'h':
|
| 14047 |
return convert24to12(hour);
|
| 14048 |
case 'mm':
|
| 14049 |
return ('0' + time.minute).slice(-2);
|
| 14050 |
case 'm':
|
| 14051 |
return time.minute;
|
| 14052 |
case 'ss':
|
| 14053 |
return ('0' + time.second).slice(-2);
|
| 14054 |
case 's':
|
| 14055 |
return time.second;
|
| 14056 |
case 'l':
|
| 14057 |
return ('00' + time.millisec).slice(-3);
|
| 14058 |
case 'z':
|
| 14059 |
return time.timezone === null? options.defaultTimezone : time.timezone;
|
| 14060 |
case 'T':
|
| 14061 |
return ampmName.charAt(0).toUpperCase();
|
| 14062 |
case 'TT':
|
| 14063 |
return ampmName.toUpperCase();
|
| 14064 |
case 't':
|
| 14065 |
return ampmName.charAt(0).toLowerCase();
|
| 14066 |
case 'tt':
|
| 14067 |
return ampmName.toLowerCase();
|
| 14068 |
default:
|
| 14069 |
return match.replace(/\'/g, "") || "'";
|
| 14070 |
}
|
| 14071 |
});
|
| 14072 |
|
| 14073 |
tmptime = $.trim(tmptime);
|
| 14074 |
return tmptime;
|
| 14075 |
};
|
| 14076 |
|
| 14077 |
/*
|
| 14078 |
* the bad hack :/ override datepicker so it doesnt close on select
|
| 14079 |
// inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
|
| 14080 |
*/
|
| 14081 |
$.datepicker._base_selectDate = $.datepicker._selectDate;
|
| 14082 |
$.datepicker._selectDate = function(id, dateStr) {
|
| 14083 |
var inst = this._getInst($(id)[0]),
|
| 14084 |
tp_inst = this._get(inst, 'timepicker');
|
| 14085 |
|
| 14086 |
if (tp_inst) {
|
| 14087 |
tp_inst._limitMinMaxDateTime(inst, true);
|
| 14088 |
inst.inline = inst.stay_open = true;
|
| 14089 |
//This way the onSelect handler called from calendarpicker get the full dateTime
|
| 14090 |
this._base_selectDate(id, dateStr);
|
| 14091 |
inst.inline = inst.stay_open = false;
|
| 14092 |
this._notifyChange(inst);
|
| 14093 |
this._updateDatepicker(inst);
|
| 14094 |
} else {
|
| 14095 |
this._base_selectDate(id, dateStr);
|
| 14096 |
}
|
| 14097 |
};
|
| 14098 |
|
| 14099 |
/*
|
| 14100 |
* second bad hack :/ override datepicker so it triggers an event when changing the input field
|
| 14101 |
* and does not redraw the datepicker on every selectDate event
|
| 14102 |
*/
|
| 14103 |
$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
|
| 14104 |
$.datepicker._updateDatepicker = function(inst) {
|
| 14105 |
|
| 14106 |
// don't popup the datepicker if there is another instance already opened
|
| 14107 |
var input = inst.input[0];
|
| 14108 |
if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) {
|
| 14109 |
return;
|
| 14110 |
}
|
| 14111 |
|
| 14112 |
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
|
| 14113 |
|
| 14114 |
this._base_updateDatepicker(inst);
|
| 14115 |
|
| 14116 |
// Reload the time control when changing something in the input text field.
|
| 14117 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14118 |
if (tp_inst) {
|
| 14119 |
tp_inst._addTimePicker(inst);
|
| 14120 |
|
| 14121 |
// if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date.
|
| 14122 |
// var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12);
|
| 14123 |
// selectLocalTimeZone(tp_inst, date);
|
| 14124 |
// tp_inst._onTimeChange();
|
| 14125 |
// }
|
| 14126 |
}
|
| 14127 |
}
|
| 14128 |
};
|
| 14129 |
|
| 14130 |
/*
|
| 14131 |
* third bad hack :/ override datepicker so it allows spaces and colon in the input field
|
| 14132 |
*/
|
| 14133 |
$.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
|
| 14134 |
$.datepicker._doKeyPress = function(event) {
|
| 14135 |
var inst = $.datepicker._getInst(event.target),
|
| 14136 |
tp_inst = $.datepicker._get(inst, 'timepicker');
|
| 14137 |
|
| 14138 |
if (tp_inst) {
|
| 14139 |
if ($.datepicker._get(inst, 'constrainInput')) {
|
| 14140 |
var ampm = useAmpm(tp_inst._defaults.timeFormat),
|
| 14141 |
dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
|
| 14142 |
datetimeChars = tp_inst._defaults.timeFormat.toString()
|
| 14143 |
.replace(/[hms]/g, '')
|
| 14144 |
.replace(/TT/g, ampm ? 'APM' : '')
|
| 14145 |
.replace(/Tt/g, ampm ? 'AaPpMm' : '')
|
| 14146 |
.replace(/tT/g, ampm ? 'AaPpMm' : '')
|
| 14147 |
.replace(/T/g, ampm ? 'AP' : '')
|
| 14148 |
.replace(/tt/g, ampm ? 'apm' : '')
|
| 14149 |
.replace(/t/g, ampm ? 'ap' : '') +
|
| 14150 |
" " + tp_inst._defaults.separator +
|
| 14151 |
tp_inst._defaults.timeSuffix +
|
| 14152 |
(tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
|
| 14153 |
(tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
|
| 14154 |
dateChars,
|
| 14155 |
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
|
| 14156 |
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
|
| 14157 |
}
|
| 14158 |
}
|
| 14159 |
|
| 14160 |
return $.datepicker._base_doKeyPress(event);
|
| 14161 |
};
|
| 14162 |
|
| 14163 |
/*
|
| 14164 |
* Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
|
| 14165 |
*/
|
| 14166 |
$.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
|
| 14167 |
/* Update any alternate field to synchronise with the main field. */
|
| 14168 |
$.datepicker._updateAlternate = function(inst) {
|
| 14169 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14170 |
if(tp_inst){
|
| 14171 |
var altField = tp_inst._defaults.altField;
|
| 14172 |
if (altField) { // update alternate field too
|
| 14173 |
var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
|
| 14174 |
date = this._getDate(inst),
|
| 14175 |
formatCfg = $.datepicker._getFormatConfig(inst),
|
| 14176 |
altFormattedDateTime = '',
|
| 14177 |
altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
|
| 14178 |
altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
|
| 14179 |
altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
|
| 14180 |
|
| 14181 |
altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
|
| 14182 |
if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){
|
| 14183 |
if(tp_inst._defaults.altFormat)
|
| 14184 |
altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
|
| 14185 |
else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
|
| 14186 |
}
|
| 14187 |
$(altField).val(altFormattedDateTime);
|
| 14188 |
}
|
| 14189 |
}
|
| 14190 |
else{
|
| 14191 |
$.datepicker._base_updateAlternate(inst);
|
| 14192 |
}
|
| 14193 |
};
|
| 14194 |
|
| 14195 |
/*
|
| 14196 |
* Override key up event to sync manual input changes.
|
| 14197 |
*/
|
| 14198 |
$.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
|
| 14199 |
$.datepicker._doKeyUp = function(event) {
|
| 14200 |
var inst = $.datepicker._getInst(event.target),
|
| 14201 |
tp_inst = $.datepicker._get(inst, 'timepicker');
|
| 14202 |
|
| 14203 |
if (tp_inst) {
|
| 14204 |
if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
|
| 14205 |
try {
|
| 14206 |
$.datepicker._updateDatepicker(inst);
|
| 14207 |
} catch (err) {
|
| 14208 |
$.timepicker.log(err);
|
| 14209 |
}
|
| 14210 |
}
|
| 14211 |
}
|
| 14212 |
|
| 14213 |
return $.datepicker._base_doKeyUp(event);
|
| 14214 |
};
|
| 14215 |
|
| 14216 |
/*
|
| 14217 |
* override "Today" button to also grab the time.
|
| 14218 |
*/
|
| 14219 |
$.datepicker._base_gotoToday = $.datepicker._gotoToday;
|
| 14220 |
$.datepicker._gotoToday = function(id) {
|
| 14221 |
var inst = this._getInst($(id)[0]),
|
| 14222 |
$dp = inst.dpDiv;
|
| 14223 |
this._base_gotoToday(id);
|
| 14224 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14225 |
selectLocalTimeZone(tp_inst);
|
| 14226 |
var now = new Date();
|
| 14227 |
this._setTime(inst, now);
|
| 14228 |
$('.ui-datepicker-today', $dp).click();
|
| 14229 |
};
|
| 14230 |
|
| 14231 |
/*
|
| 14232 |
* Disable & enable the Time in the datetimepicker
|
| 14233 |
*/
|
| 14234 |
$.datepicker._disableTimepickerDatepicker = function(target) {
|
| 14235 |
var inst = this._getInst(target);
|
| 14236 |
if (!inst) {
|
| 14237 |
return;
|
| 14238 |
}
|
| 14239 |
|
| 14240 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14241 |
$(target).datepicker('getDate'); // Init selected[Year|Month|Day]
|
| 14242 |
if (tp_inst) {
|
| 14243 |
tp_inst._defaults.showTimepicker = false;
|
| 14244 |
tp_inst._updateDateTime(inst);
|
| 14245 |
}
|
| 14246 |
};
|
| 14247 |
|
| 14248 |
$.datepicker._enableTimepickerDatepicker = function(target) {
|
| 14249 |
var inst = this._getInst(target);
|
| 14250 |
if (!inst) {
|
| 14251 |
return;
|
| 14252 |
}
|
| 14253 |
|
| 14254 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14255 |
$(target).datepicker('getDate'); // Init selected[Year|Month|Day]
|
| 14256 |
if (tp_inst) {
|
| 14257 |
tp_inst._defaults.showTimepicker = true;
|
| 14258 |
tp_inst._addTimePicker(inst); // Could be disabled on page load
|
| 14259 |
tp_inst._updateDateTime(inst);
|
| 14260 |
}
|
| 14261 |
};
|
| 14262 |
|
| 14263 |
/*
|
| 14264 |
* Create our own set time function
|
| 14265 |
*/
|
| 14266 |
$.datepicker._setTime = function(inst, date) {
|
| 14267 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14268 |
if (tp_inst) {
|
| 14269 |
var defaults = tp_inst._defaults;
|
| 14270 |
|
| 14271 |
// calling _setTime with no date sets time to defaults
|
| 14272 |
tp_inst.hour = date ? date.getHours() : defaults.hour;
|
| 14273 |
tp_inst.minute = date ? date.getMinutes() : defaults.minute;
|
| 14274 |
tp_inst.second = date ? date.getSeconds() : defaults.second;
|
| 14275 |
tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
|
| 14276 |
|
| 14277 |
//check if within min/max times..
|
| 14278 |
tp_inst._limitMinMaxDateTime(inst, true);
|
| 14279 |
|
| 14280 |
tp_inst._onTimeChange();
|
| 14281 |
tp_inst._updateDateTime(inst);
|
| 14282 |
}
|
| 14283 |
};
|
| 14284 |
|
| 14285 |
/*
|
| 14286 |
* Create new public method to set only time, callable as $().datepicker('setTime', date)
|
| 14287 |
*/
|
| 14288 |
$.datepicker._setTimeDatepicker = function(target, date, withDate) {
|
| 14289 |
var inst = this._getInst(target);
|
| 14290 |
if (!inst) {
|
| 14291 |
return;
|
| 14292 |
}
|
| 14293 |
|
| 14294 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14295 |
|
| 14296 |
if (tp_inst) {
|
| 14297 |
this._setDateFromField(inst);
|
| 14298 |
var tp_date;
|
| 14299 |
if (date) {
|
| 14300 |
if (typeof date == "string") {
|
| 14301 |
tp_inst._parseTime(date, withDate);
|
| 14302 |
tp_date = new Date();
|
| 14303 |
tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
|
| 14304 |
} else {
|
| 14305 |
tp_date = new Date(date.getTime());
|
| 14306 |
}
|
| 14307 |
if (tp_date.toString() == 'Invalid Date') {
|
| 14308 |
tp_date = undefined;
|
| 14309 |
}
|
| 14310 |
this._setTime(inst, tp_date);
|
| 14311 |
}
|
| 14312 |
}
|
| 14313 |
|
| 14314 |
};
|
| 14315 |
|
| 14316 |
/*
|
| 14317 |
* override setDate() to allow setting time too within Date object
|
| 14318 |
*/
|
| 14319 |
$.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
|
| 14320 |
$.datepicker._setDateDatepicker = function(target, date) {
|
| 14321 |
var inst = this._getInst(target);
|
| 14322 |
if (!inst) {
|
| 14323 |
return;
|
| 14324 |
}
|
| 14325 |
|
| 14326 |
var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
|
| 14327 |
|
| 14328 |
this._updateDatepicker(inst);
|
| 14329 |
this._base_setDateDatepicker.apply(this, arguments);
|
| 14330 |
this._setTimeDatepicker(target, tp_date, true);
|
| 14331 |
};
|
| 14332 |
|
| 14333 |
/*
|
| 14334 |
* override getDate() to allow getting time too within Date object
|
| 14335 |
*/
|
| 14336 |
$.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
|
| 14337 |
$.datepicker._getDateDatepicker = function(target, noDefault) {
|
| 14338 |
var inst = this._getInst(target);
|
| 14339 |
if (!inst) {
|
| 14340 |
return;
|
| 14341 |
}
|
| 14342 |
|
| 14343 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14344 |
|
| 14345 |
if (tp_inst) {
|
| 14346 |
// if it hasn't yet been defined, grab from field
|
| 14347 |
if(inst.lastVal === undefined){
|
| 14348 |
this._setDateFromField(inst, noDefault);
|
| 14349 |
}
|
| 14350 |
|
| 14351 |
var date = this._getDate(inst);
|
| 14352 |
if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
|
| 14353 |
date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
|
| 14354 |
}
|
| 14355 |
return date;
|
| 14356 |
}
|
| 14357 |
return this._base_getDateDatepicker(target, noDefault);
|
| 14358 |
};
|
| 14359 |
|
| 14360 |
/*
|
| 14361 |
* override parseDate() because UI 1.8.14 throws an error about "Extra characters"
|
| 14362 |
* An option in datapicker to ignore extra format characters would be nicer.
|
| 14363 |
*/
|
| 14364 |
$.datepicker._base_parseDate = $.datepicker.parseDate;
|
| 14365 |
$.datepicker.parseDate = function(format, value, settings) {
|
| 14366 |
var date;
|
| 14367 |
try {
|
| 14368 |
date = this._base_parseDate(format, value, settings);
|
| 14369 |
} catch (err) {
|
| 14370 |
// Hack! The error message ends with a colon, a space, and
|
| 14371 |
// the "extra" characters. We rely on that instead of
|
| 14372 |
// attempting to perfectly reproduce the parsing algorithm.
|
| 14373 |
date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
|
| 14374 |
$.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
|
| 14375 |
}
|
| 14376 |
return date;
|
| 14377 |
};
|
| 14378 |
|
| 14379 |
/*
|
| 14380 |
* override formatDate to set date with time to the input
|
| 14381 |
*/
|
| 14382 |
$.datepicker._base_formatDate = $.datepicker._formatDate;
|
| 14383 |
$.datepicker._formatDate = function(inst, day, month, year) {
|
| 14384 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14385 |
if (tp_inst) {
|
| 14386 |
tp_inst._updateDateTime(inst);
|
| 14387 |
return tp_inst.$input.val();
|
| 14388 |
}
|
| 14389 |
return this._base_formatDate(inst);
|
| 14390 |
};
|
| 14391 |
|
| 14392 |
/*
|
| 14393 |
* override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
|
| 14394 |
*/
|
| 14395 |
$.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
|
| 14396 |
$.datepicker._optionDatepicker = function(target, name, value) {
|
| 14397 |
var inst = this._getInst(target),
|
| 14398 |
name_clone;
|
| 14399 |
if (!inst) {
|
| 14400 |
return null;
|
| 14401 |
}
|
| 14402 |
|
| 14403 |
var tp_inst = this._get(inst, 'timepicker');
|
| 14404 |
if (tp_inst) {
|
| 14405 |
var min = null,
|
| 14406 |
max = null,
|
| 14407 |
onselect = null,
|
| 14408 |
overrides = tp_inst._defaults.evnts,
|
| 14409 |
fns = {},
|
| 14410 |
prop;
|
| 14411 |
if (typeof name == 'string') { // if min/max was set with the string
|
| 14412 |
if (name === 'minDate' || name === 'minDateTime') {
|
| 14413 |
min = value;
|
| 14414 |
} else if (name === 'maxDate' || name === 'maxDateTime') {
|
| 14415 |
max = value;
|
| 14416 |
} else if (name === 'onSelect') {
|
| 14417 |
onselect = value;
|
| 14418 |
} else if (overrides.hasOwnProperty(name)) {
|
| 14419 |
if (typeof (value) === 'undefined') {
|
| 14420 |
return overrides[name];
|
| 14421 |
}
|
| 14422 |
fns[name] = value;
|
| 14423 |
name_clone = {}; //empty results in exiting function after overrides updated
|
| 14424 |
}
|
| 14425 |
} else if (typeof name == 'object') { //if min/max was set with the JSON
|
| 14426 |
if (name.minDate) {
|
| 14427 |
min = name.minDate;
|
| 14428 |
} else if (name.minDateTime) {
|
| 14429 |
min = name.minDateTime;
|
| 14430 |
} else if (name.maxDate) {
|
| 14431 |
max = name.maxDate;
|
| 14432 |
} else if (name.maxDateTime) {
|
| 14433 |
max = name.maxDateTime;
|
| 14434 |
}
|
| 14435 |
for (prop in overrides) {
|
| 14436 |
if (overrides.hasOwnProperty(prop) && name[prop]) {
|
| 14437 |
fns[prop] = name[prop];
|
| 14438 |
}
|
| 14439 |
}
|
| 14440 |
}
|
| 14441 |
for (prop in fns) {
|
| 14442 |
if (fns.hasOwnProperty(prop)) {
|
| 14443 |
overrides[prop] = fns[prop];
|
| 14444 |
if (!name_clone) { name_clone = $.extend({}, name);}
|
| 14445 |
delete name_clone[prop];
|
| 14446 |
}
|
| 14447 |
}
|
| 14448 |
if (name_clone && isEmptyObject(name_clone)) { return; }
|
| 14449 |
if (min) { //if min was set
|
| 14450 |
if (min === 0) {
|
| 14451 |
min = new Date();
|
| 14452 |
} else {
|
| 14453 |
min = new Date(min);
|
| 14454 |
}
|
| 14455 |
tp_inst._defaults.minDate = min;
|
| 14456 |
tp_inst._defaults.minDateTime = min;
|
| 14457 |
} else if (max) { //if max was set
|
| 14458 |
if (max === 0) {
|
| 14459 |
max = new Date();
|
| 14460 |
} else {
|
| 14461 |
max = new Date(max);
|
| 14462 |
}
|
| 14463 |
tp_inst._defaults.maxDate = max;
|
| 14464 |
tp_inst._defaults.maxDateTime = max;
|
| 14465 |
} else if (onselect) {
|
| 14466 |
tp_inst._defaults.onSelect = onselect;
|
| 14467 |
}
|
| 14468 |
}
|
| 14469 |
if (value === undefined) {
|
| 14470 |
return this._base_optionDatepicker.call($.datepicker, target, name);
|
| 14471 |
}
|
| 14472 |
return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
|
| 14473 |
};
|
| 14474 |
/*
|
| 14475 |
* jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
|
| 14476 |
* it will return false for all objects
|
| 14477 |
*/
|
| 14478 |
var isEmptyObject = function(obj) {
|
| 14479 |
var prop;
|
| 14480 |
for (prop in obj) {
|
| 14481 |
if (obj.hasOwnProperty(obj)) {
|
| 14482 |
return false;
|
| 14483 |
}
|
| 14484 |
}
|
| 14485 |
return true;
|
| 14486 |
};
|
| 14487 |
|
| 14488 |
/*
|
| 14489 |
* jQuery extend now ignores nulls!
|
| 14490 |
*/
|
| 14491 |
var extendRemove = function(target, props) {
|
| 14492 |
$.extend(target, props);
|
| 14493 |
for (var name in props) {
|
| 14494 |
if (props[name] === null || props[name] === undefined) {
|
| 14495 |
target[name] = props[name];
|
| 14496 |
}
|
| 14497 |
}
|
| 14498 |
return target;
|
| 14499 |
};
|
| 14500 |
|
| 14501 |
/*
|
| 14502 |
* Determine by the time format if should use ampm
|
| 14503 |
* Returns true if should use ampm, false if not
|
| 14504 |
*/
|
| 14505 |
var useAmpm = function(timeFormat){
|
| 14506 |
return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1);
|
| 14507 |
};
|
| 14508 |
|
| 14509 |
/*
|
| 14510 |
* Converts 24 hour format into 12 hour
|
| 14511 |
* Returns 12 hour without leading 0
|
| 14512 |
*/
|
| 14513 |
var convert24to12 = function(hour) {
|
| 14514 |
if (hour > 12) {
|
| 14515 |
hour = hour - 12;
|
| 14516 |
}
|
| 14517 |
|
| 14518 |
if (hour == 0) {
|
| 14519 |
hour = 12;
|
| 14520 |
}
|
| 14521 |
|
| 14522 |
return String(hour);
|
| 14523 |
};
|
| 14524 |
|
| 14525 |
/*
|
| 14526 |
* Splits datetime string into date ans time substrings.
|
| 14527 |
* Throws exception when date can't be parsed
|
| 14528 |
* Returns [dateString, timeString]
|
| 14529 |
*/
|
| 14530 |
var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
|
| 14531 |
try {
|
| 14532 |
// The idea is to get the number separator occurances in datetime and the time format requested (since time has
|
| 14533 |
// fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
|
| 14534 |
var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator,
|
| 14535 |
format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat,
|
| 14536 |
timeParts = format.split(separator), // how many occurances of separator may be in our format?
|
| 14537 |
timePartsLen = timeParts.length,
|
| 14538 |
allParts = dateTimeString.split(separator),
|
| 14539 |
allPartsLen = allParts.length;
|
| 14540 |
|
| 14541 |
if (allPartsLen > 1) {
|
| 14542 |
return [
|
| 14543 |
allParts.splice(0,allPartsLen-timePartsLen).join(separator),
|
| 14544 |
allParts.splice(0,timePartsLen).join(separator)
|
| 14545 |
];
|
| 14546 |
}
|
| 14547 |
|
| 14548 |
} catch (err) {
|
| 14549 |
$.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' +
|
| 14550 |
"\nthrown error: " + err +
|
| 14551 |
"\ndateTimeString" + dateTimeString +
|
| 14552 |
"\ndateFormat = " + dateFormat +
|
| 14553 |
"\nseparator = " + timeSettings.separator +
|
| 14554 |
"\ntimeFormat = " + timeSettings.timeFormat);
|
| 14555 |
|
| 14556 |
if (err.indexOf(":") >= 0) {
|
| 14557 |
// Hack! The error message ends with a colon, a space, and
|
| 14558 |
// the "extra" characters. We rely on that instead of
|
| 14559 |
// attempting to perfectly reproduce the parsing algorithm.
|
| 14560 |
var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2),
|
| 14561 |
timeString = dateTimeString.substring(dateStringLength);
|
| 14562 |
|
| 14563 |
return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))];
|
| 14564 |
|
| 14565 |
} else {
|
| 14566 |
throw err;
|
| 14567 |
}
|
| 14568 |
}
|
| 14569 |
return [dateTimeString, ''];
|
| 14570 |
};
|
| 14571 |
|
| 14572 |
/*
|
| 14573 |
* Internal function to parse datetime interval
|
| 14574 |
* Returns: {date: Date, timeObj: Object}, where
|
| 14575 |
* date - parsed date without time (type Date)
|
| 14576 |
* timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional
|
| 14577 |
*/
|
| 14578 |
var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
|
| 14579 |
var date;
|
| 14580 |
var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings);
|
| 14581 |
date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings);
|
| 14582 |
if (splitRes[1] !== '') {
|
| 14583 |
var timeString = splitRes[1],
|
| 14584 |
parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings);
|
| 14585 |
|
| 14586 |
if (parsedTime === null) {
|
| 14587 |
throw 'Wrong time format';
|
| 14588 |
}
|
| 14589 |
return {
|
| 14590 |
date: date,
|
| 14591 |
timeObj: parsedTime
|
| 14592 |
};
|
| 14593 |
} else {
|
| 14594 |
return {
|
| 14595 |
date: date
|
| 14596 |
};
|
| 14597 |
}
|
| 14598 |
};
|
| 14599 |
|
| 14600 |
/*
|
| 14601 |
* Internal function to set timezone_select to the local timezone
|
| 14602 |
*/
|
| 14603 |
var selectLocalTimeZone = function(tp_inst, date) {
|
| 14604 |
if (tp_inst && tp_inst.timezone_select) {
|
| 14605 |
tp_inst._defaults.useLocalTimezone = true;
|
| 14606 |
var now = typeof date !== 'undefined' ? date : new Date();
|
| 14607 |
var tzoffset = $.timepicker.timeZoneOffsetString(now);
|
| 14608 |
if (tp_inst._defaults.timezoneIso8601) {
|
| 14609 |
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
|
| 14610 |
}
|
| 14611 |
tp_inst.timezone_select.val(tzoffset);
|
| 14612 |
}
|
| 14613 |
};
|
| 14614 |
|
| 14615 |
/*
|
| 14616 |
* Create a Singleton Insance
|
| 14617 |
*/
|
| 14618 |
$.timepicker = new Timepicker();
|
| 14619 |
|
| 14620 |
/**
|
| 14621 |
* Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
|
| 14622 |
* @param date
|
| 14623 |
* @return string
|
| 14624 |
*/
|
| 14625 |
$.timepicker.timeZoneOffsetString = function(date) {
|
| 14626 |
var off = date.getTimezoneOffset() * -1,
|
| 14627 |
minutes = off % 60,
|
| 14628 |
hours = (off - minutes) / 60;
|
| 14629 |
return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2);
|
| 14630 |
};
|
| 14631 |
|
| 14632 |
/**
|
| 14633 |
* Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
|
| 14634 |
* enforce date range limits.
|
| 14635 |
* n.b. The input value must be correctly formatted (reformatting is not supported)
|
| 14636 |
* @param Element startTime
|
| 14637 |
* @param Element endTime
|
| 14638 |
* @param obj options Options for the timepicker() call
|
| 14639 |
* @return jQuery
|
| 14640 |
*/
|
| 14641 |
$.timepicker.timeRange = function(startTime, endTime, options) {
|
| 14642 |
return $.timepicker.handleRange('timepicker', startTime, endTime, options);
|
| 14643 |
};
|
| 14644 |
|
| 14645 |
/**
|
| 14646 |
* Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
|
| 14647 |
* enforce date range limits.
|
| 14648 |
* @param Element startTime
|
| 14649 |
* @param Element endTime
|
| 14650 |
* @param obj options Options for the `timepicker()` call. Also supports `reformat`,
|
| 14651 |
* a boolean value that can be used to reformat the input values to the `dateFormat`.
|
| 14652 |
* @param string method Can be used to specify the type of picker to be added
|
| 14653 |
* @return jQuery
|
| 14654 |
*/
|
| 14655 |
$.timepicker.dateTimeRange = function(startTime, endTime, options) {
|
| 14656 |
$.timepicker.dateRange(startTime, endTime, options, 'datetimepicker');
|
| 14657 |
};
|
| 14658 |
|
| 14659 |
/**
|
| 14660 |
* Calls `method` on the `startTime` and `endTime` elements, and configures them to
|
| 14661 |
* enforce date range limits.
|
| 14662 |
* @param Element startTime
|
| 14663 |
* @param Element endTime
|
| 14664 |
* @param obj options Options for the `timepicker()` call. Also supports `reformat`,
|
| 14665 |
* a boolean value that can be used to reformat the input values to the `dateFormat`.
|
| 14666 |
* @param string method Can be used to specify the type of picker to be added
|
| 14667 |
* @return jQuery
|
| 14668 |
*/
|
| 14669 |
$.timepicker.dateRange = function(startTime, endTime, options, method) {
|
| 14670 |
method = method || 'datepicker';
|
| 14671 |
$.timepicker.handleRange(method, startTime, endTime, options);
|
| 14672 |
};
|
| 14673 |
|
| 14674 |
/**
|
| 14675 |
* Calls `method` on the `startTime` and `endTime` elements, and configures them to
|
| 14676 |
* enforce date range limits.
|
| 14677 |
* @param string method Can be used to specify the type of picker to be added
|
| 14678 |
* @param Element startTime
|
| 14679 |
* @param Element endTime
|
| 14680 |
* @param obj options Options for the `timepicker()` call. Also supports `reformat`,
|
| 14681 |
* a boolean value that can be used to reformat the input values to the `dateFormat`.
|
| 14682 |
* @return jQuery
|
| 14683 |
*/
|
| 14684 |
$.timepicker.handleRange = function(method, startTime, endTime, options) {
|
| 14685 |
$.fn[method].call(startTime, $.extend({
|
| 14686 |
onClose: function(dateText, inst) {
|
| 14687 |
checkDates(this, endTime, dateText);
|
| 14688 |
},
|
| 14689 |
onSelect: function(selectedDateTime) {
|
| 14690 |
selected(this, endTime, 'minDate');
|
| 14691 |
}
|
| 14692 |
}, options, options.start));
|
| 14693 |
$.fn[method].call(endTime, $.extend({
|
| 14694 |
onClose: function(dateText, inst) {
|
| 14695 |
checkDates(this, startTime, dateText);
|
| 14696 |
},
|
| 14697 |
onSelect: function(selectedDateTime) {
|
| 14698 |
selected(this, startTime, 'maxDate');
|
| 14699 |
}
|
| 14700 |
}, options, options.end));
|
| 14701 |
// timepicker doesn't provide access to its 'timeFormat' option,
|
| 14702 |
// nor could I get datepicker.formatTime() to behave with times, so I
|
| 14703 |
// have disabled reformatting for timepicker
|
| 14704 |
if (method != 'timepicker' && options.reformat) {
|
| 14705 |
$([startTime, endTime]).each(function() {
|
| 14706 |
var format = $(this)[method].call($(this), 'option', 'dateFormat'),
|
| 14707 |
date = new Date($(this).val());
|
| 14708 |
if ($(this).val() && date) {
|
| 14709 |
$(this).val($.datepicker.formatDate(format, date));
|
| 14710 |
}
|
| 14711 |
});
|
| 14712 |
}
|
| 14713 |
checkDates(startTime, endTime, startTime.val());
|
| 14714 |
|
| 14715 |
function checkDates(changed, other, dateText) {
|
| 14716 |
if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) {
|
| 14717 |
other.val(dateText);
|
| 14718 |
}
|
| 14719 |
}
|
| 14720 |
selected(startTime, endTime, 'minDate');
|
| 14721 |
selected(endTime, startTime, 'maxDate');
|
| 14722 |
|
| 14723 |
function selected(changed, other, option) {
|
| 14724 |
if (!$(changed).val()) {
|
| 14725 |
return;
|
| 14726 |
}
|
| 14727 |
var date = $(changed)[method].call($(changed), 'getDate');
|
| 14728 |
// timepicker doesn't implement 'getDate' and returns a jQuery
|
| 14729 |
if (date.getTime) {
|
| 14730 |
$(other)[method].call($(other), 'option', option, date);
|
| 14731 |
}
|
| 14732 |
}
|
| 14733 |
return $([startTime.get(0), endTime.get(0)]);
|
| 14734 |
};
|
| 14735 |
|
| 14736 |
/**
|
| 14737 |
* Log error or data to the console during error or debugging
|
| 14738 |
* @param Object err pass any type object to log to the console during error or debugging
|
| 14739 |
* @return void
|
| 14740 |
*/
|
| 14741 |
$.timepicker.log = function(err){
|
| 14742 |
if(window.console)
|
| 14743 |
console.log(err);
|
| 14744 |
};
|
| 14745 |
|
| 14746 |
/*
|
| 14747 |
* Keep up with the version
|
| 14748 |
*/
|
| 14749 |
$.timepicker.version = "1.2";
|
| 14750 |
|
| 14751 |
})(jQuery);
|
| 14752 |
|
| 14753 |
/* assets/wpuf/vendor/sweetalert2/dist/sweetalert2.js */ |
| 14754 |
/*! |
| 14755 |
* sweetalert2 v6.6.4 |
| 14756 |
* Released under the MIT License. |
| 14757 |
*/ |
| 14758 |
(function (global, factory) { |
| 14759 |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 14760 |
typeof define === 'function' && define.amd ? define(factory) : |
| 14761 |
(global.Sweetalert2 = factory()); |
| 14762 |
}(this, (function () { 'use strict'; |
| 14763 |
|
| 14764 |
var defaultParams = { |
| 14765 |
title: '', |
| 14766 |
titleText: '', |
| 14767 |
text: '', |
| 14768 |
html: '', |
| 14769 |
type: null, |
| 14770 |
customClass: '', |
| 14771 |
target: 'body', |
| 14772 |
animation: true, |
| 14773 |
allowOutsideClick: true, |
| 14774 |
allowEscapeKey: true, |
| 14775 |
allowEnterKey: true, |
| 14776 |
showConfirmButton: true, |
| 14777 |
showCancelButton: false, |
| 14778 |
preConfirm: null, |
| 14779 |
confirmButtonText: 'OK', |
| 14780 |
confirmButtonColor: '#3085d6', |
| 14781 |
confirmButtonClass: null, |
| 14782 |
cancelButtonText: 'Cancel', |
| 14783 |
cancelButtonColor: '#aaa', |
| 14784 |
cancelButtonClass: null, |
| 14785 |
buttonsStyling: true, |
| 14786 |
reverseButtons: false, |
| 14787 |
focusCancel: false, |
| 14788 |
showCloseButton: false, |
| 14789 |
showLoaderOnConfirm: false, |
| 14790 |
imageUrl: null, |
| 14791 |
imageWidth: null, |
| 14792 |
imageHeight: null, |
| 14793 |
imageClass: null, |
| 14794 |
timer: null, |
| 14795 |
width: 500, |
| 14796 |
padding: 20, |
| 14797 |
background: '#fff', |
| 14798 |
input: null, |
| 14799 |
inputPlaceholder: '', |
| 14800 |
inputValue: '', |
| 14801 |
inputOptions: {}, |
| 14802 |
inputAutoTrim: true, |
| 14803 |
inputClass: null, |
| 14804 |
inputAttributes: {}, |
| 14805 |
inputValidator: null, |
| 14806 |
progressSteps: [], |
| 14807 |
currentProgressStep: null, |
| 14808 |
progressStepsDistance: '40px', |
| 14809 |
onOpen: null, |
| 14810 |
onClose: null, |
| 14811 |
useRejections: true |
| 14812 |
}; |
| 14813 |
|
| 14814 |
var swalPrefix = 'swal2-'; |
| 14815 |
|
| 14816 |
var prefix = function prefix(items) { |
| 14817 |
var result = {}; |
| 14818 |
for (var i in items) { |
| 14819 |
result[items[i]] = swalPrefix + items[i]; |
| 14820 |
} |
| 14821 |
return result; |
| 14822 |
}; |
| 14823 |
|
| 14824 |
var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']); |
| 14825 |
|
| 14826 |
var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); |
| 14827 |
|
| 14828 |
/* |
| 14829 |
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) |
| 14830 |
*/ |
| 14831 |
var colorLuminance = function colorLuminance(hex, lum) { |
| 14832 |
// Validate hex string |
| 14833 |
hex = String(hex).replace(/[^0-9a-f]/gi, ''); |
| 14834 |
if (hex.length < 6) { |
| 14835 |
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; |
| 14836 |
} |
| 14837 |
lum = lum || 0; |
| 14838 |
|
| 14839 |
// Convert to decimal and change luminosity |
| 14840 |
var rgb = '#'; |
| 14841 |
for (var i = 0; i < 3; i++) { |
| 14842 |
var c = parseInt(hex.substr(i * 2, 2), 16); |
| 14843 |
c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16); |
| 14844 |
rgb += ('00' + c).substr(c.length); |
| 14845 |
} |
| 14846 |
|
| 14847 |
return rgb; |
| 14848 |
}; |
| 14849 |
|
| 14850 |
var uniqueArray = function uniqueArray(arr) { |
| 14851 |
var result = []; |
| 14852 |
for (var i in arr) { |
| 14853 |
if (result.indexOf(arr[i]) === -1) { |
| 14854 |
result.push(arr[i]); |
| 14855 |
} |
| 14856 |
} |
| 14857 |
return result; |
| 14858 |
}; |
| 14859 |
|
| 14860 |
/* global MouseEvent */ |
| 14861 |
|
| 14862 |
// Remember state in cases where opening and handling a modal will fiddle with it. |
| 14863 |
var states = { |
| 14864 |
previousWindowKeyDown: null, |
| 14865 |
previousActiveElement: null, |
| 14866 |
previousBodyPadding: null |
| 14867 |
}; |
| 14868 |
|
| 14869 |
/* |
| 14870 |
* Add modal + overlay to DOM |
| 14871 |
*/ |
| 14872 |
var init = function init(params) { |
| 14873 |
if (typeof document === 'undefined') { |
| 14874 |
console.error('SweetAlert2 requires document to initialize'); |
| 14875 |
return; |
| 14876 |
} |
| 14877 |
|
| 14878 |
var container = document.createElement('div'); |
| 14879 |
container.className = swalClasses.container; |
| 14880 |
container.innerHTML = sweetHTML; |
| 14881 |
|
| 14882 |
var targetElement = document.querySelector(params.target); |
| 14883 |
if (!targetElement) { |
| 14884 |
console.warn('SweetAlert2: Can\'t find the target "' + params.target + '"'); |
| 14885 |
targetElement = document.body; |
| 14886 |
} |
| 14887 |
targetElement.appendChild(container); |
| 14888 |
|
| 14889 |
var modal = getModal(); |
| 14890 |
var input = getChildByClass(modal, swalClasses.input); |
| 14891 |
var file = getChildByClass(modal, swalClasses.file); |
| 14892 |
var range = modal.querySelector('.' + swalClasses.range + ' input'); |
| 14893 |
var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output'); |
| 14894 |
var select = getChildByClass(modal, swalClasses.select); |
| 14895 |
var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input'); |
| 14896 |
var textarea = getChildByClass(modal, swalClasses.textarea); |
| 14897 |
|
| 14898 |
input.oninput = function () { |
| 14899 |
sweetAlert.resetValidationError(); |
| 14900 |
}; |
| 14901 |
|
| 14902 |
input.onkeydown = function (event) { |
| 14903 |
setTimeout(function () { |
| 14904 |
if (event.keyCode === 13 && params.allowEnterKey) { |
| 14905 |
event.stopPropagation(); |
| 14906 |
sweetAlert.clickConfirm(); |
| 14907 |
} |
| 14908 |
}, 0); |
| 14909 |
}; |
| 14910 |
|
| 14911 |
file.onchange = function () { |
| 14912 |
sweetAlert.resetValidationError(); |
| 14913 |
}; |
| 14914 |
|
| 14915 |
range.oninput = function () { |
| 14916 |
sweetAlert.resetValidationError(); |
| 14917 |
rangeOutput.value = range.value; |
| 14918 |
}; |
| 14919 |
|
| 14920 |
range.onchange = function () { |
| 14921 |
sweetAlert.resetValidationError(); |
| 14922 |
range.previousSibling.value = range.value; |
| 14923 |
}; |
| 14924 |
|
| 14925 |
select.onchange = function () { |
| 14926 |
sweetAlert.resetValidationError(); |
| 14927 |
}; |
| 14928 |
|
| 14929 |
checkbox.onchange = function () { |
| 14930 |
sweetAlert.resetValidationError(); |
| 14931 |
}; |
| 14932 |
|
| 14933 |
textarea.oninput = function () { |
| 14934 |
sweetAlert.resetValidationError(); |
| 14935 |
}; |
| 14936 |
|
| 14937 |
return modal; |
| 14938 |
}; |
| 14939 |
|
| 14940 |
/* |
| 14941 |
* Manipulate DOM |
| 14942 |
*/ |
| 14943 |
|
| 14944 |
var sweetHTML = ('\n <div role="dialog" aria-labelledby="' + swalClasses.title + '" aria-describedby="' + swalClasses.content + '" class="' + swalClasses.modal + '" tabindex="-1">\n <ul class="' + swalClasses.progresssteps + '"></ul>\n <div class="' + swalClasses.icon + ' ' + iconTypes.error + '">\n <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>\n </div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.success + '">\n <div class="swal2-success-circular-line-left"></div>\n <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>\n <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>\n <div class="swal2-success-circular-line-right"></div>\n </div>\n <img class="' + swalClasses.image + '">\n <h2 class="' + swalClasses.title + '" id="' + swalClasses.title + '"></h2>\n <div id="' + swalClasses.content + '" class="' + swalClasses.content + '"></div>\n <input class="' + swalClasses.input + '">\n <input type="file" class="' + swalClasses.file + '">\n <div class="' + swalClasses.range + '">\n <output></output>\n <input type="range">\n </div>\n <select class="' + swalClasses.select + '"></select>\n <div class="' + swalClasses.radio + '"></div>\n <label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">\n <input type="checkbox">\n </label>\n <textarea class="' + swalClasses.textarea + '"></textarea>\n <div class="' + swalClasses.validationerror + '"></div>\n <div class="' + swalClasses.buttonswrapper + '">\n <button type="button" class="' + swalClasses.confirm + '">OK</button>\n <button type="button" class="' + swalClasses.cancel + '">Cancel</button>\n </div>\n <button type="button" class="' + swalClasses.close + '" aria-label="Close this dialog">×</button>\n </div>\n').replace(/(^|\n)\s*/g, ''); |
| 14945 |
|
| 14946 |
var getContainer = function getContainer() { |
| 14947 |
return document.body.querySelector('.' + swalClasses.container); |
| 14948 |
}; |
| 14949 |
|
| 14950 |
var getModal = function getModal() { |
| 14951 |
return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null; |
| 14952 |
}; |
| 14953 |
|
| 14954 |
var getIcons = function getIcons() { |
| 14955 |
var modal = getModal(); |
| 14956 |
return modal.querySelectorAll('.' + swalClasses.icon); |
| 14957 |
}; |
| 14958 |
|
| 14959 |
var elementByClass = function elementByClass(className) { |
| 14960 |
return getContainer() ? getContainer().querySelector('.' + className) : null; |
| 14961 |
}; |
| 14962 |
|
| 14963 |
var getTitle = function getTitle() { |
| 14964 |
return elementByClass(swalClasses.title); |
| 14965 |
}; |
| 14966 |
|
| 14967 |
var getContent = function getContent() { |
| 14968 |
return elementByClass(swalClasses.content); |
| 14969 |
}; |
| 14970 |
|
| 14971 |
var getImage = function getImage() { |
| 14972 |
return elementByClass(swalClasses.image); |
| 14973 |
}; |
| 14974 |
|
| 14975 |
var getButtonsWrapper = function getButtonsWrapper() { |
| 14976 |
return elementByClass(swalClasses.buttonswrapper); |
| 14977 |
}; |
| 14978 |
|
| 14979 |
var getProgressSteps = function getProgressSteps() { |
| 14980 |
return elementByClass(swalClasses.progresssteps); |
| 14981 |
}; |
| 14982 |
|
| 14983 |
var getValidationError = function getValidationError() { |
| 14984 |
return elementByClass(swalClasses.validationerror); |
| 14985 |
}; |
| 14986 |
|
| 14987 |
var getConfirmButton = function getConfirmButton() { |
| 14988 |
return elementByClass(swalClasses.confirm); |
| 14989 |
}; |
| 14990 |
|
| 14991 |
var getCancelButton = function getCancelButton() { |
| 14992 |
return elementByClass(swalClasses.cancel); |
| 14993 |
}; |
| 14994 |
|
| 14995 |
var getCloseButton = function getCloseButton() { |
| 14996 |
return elementByClass(swalClasses.close); |
| 14997 |
}; |
| 14998 |
|
| 14999 |
var getFocusableElements = function getFocusableElements(focusCancel) { |
| 15000 |
var buttons = [getConfirmButton(), getCancelButton()]; |
| 15001 |
if (focusCancel) { |
| 15002 |
buttons.reverse(); |
| 15003 |
} |
| 15004 |
var focusableElements = buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, *[tabindex]:not([tabindex="-1"])'))); |
| 15005 |
return uniqueArray(focusableElements); |
| 15006 |
}; |
| 15007 |
|
| 15008 |
var hasClass = function hasClass(elem, className) { |
| 15009 |
if (elem.classList) { |
| 15010 |
return elem.classList.contains(className); |
| 15011 |
} |
| 15012 |
return false; |
| 15013 |
}; |
| 15014 |
|
| 15015 |
var focusInput = function focusInput(input) { |
| 15016 |
input.focus(); |
| 15017 |
|
| 15018 |
// place cursor at end of text in text input |
| 15019 |
if (input.type !== 'file') { |
| 15020 |
// http://stackoverflow.com/a/2345915/1331425 |
| 15021 |
var val = input.value; |
| 15022 |
input.value = ''; |
| 15023 |
input.value = val; |
| 15024 |
} |
| 15025 |
}; |
| 15026 |
|
| 15027 |
var addClass = function addClass(elem, className) { |
| 15028 |
if (!elem || !className) { |
| 15029 |
return; |
| 15030 |
} |
| 15031 |
var classes = className.split(/\s+/).filter(Boolean); |
| 15032 |
classes.forEach(function (className) { |
| 15033 |
elem.classList.add(className); |
| 15034 |
}); |
| 15035 |
}; |
| 15036 |
|
| 15037 |
var removeClass = function removeClass(elem, className) { |
| 15038 |
if (!elem || !className) { |
| 15039 |
return; |
| 15040 |
} |
| 15041 |
var classes = className.split(/\s+/).filter(Boolean); |
| 15042 |
classes.forEach(function (className) { |
| 15043 |
elem.classList.remove(className); |
| 15044 |
}); |
| 15045 |
}; |
| 15046 |
|
| 15047 |
var getChildByClass = function getChildByClass(elem, className) { |
| 15048 |
for (var i = 0; i < elem.childNodes.length; i++) { |
| 15049 |
if (hasClass(elem.childNodes[i], className)) { |
| 15050 |
return elem.childNodes[i]; |
| 15051 |
} |
| 15052 |
} |
| 15053 |
}; |
| 15054 |
|
| 15055 |
var show = function show(elem, display) { |
| 15056 |
if (!display) { |
| 15057 |
display = 'block'; |
| 15058 |
} |
| 15059 |
elem.style.opacity = ''; |
| 15060 |
elem.style.display = display; |
| 15061 |
}; |
| 15062 |
|
| 15063 |
var hide = function hide(elem) { |
| 15064 |
elem.style.opacity = ''; |
| 15065 |
elem.style.display = 'none'; |
| 15066 |
}; |
| 15067 |
|
| 15068 |
var empty = function empty(elem) { |
| 15069 |
while (elem.firstChild) { |
| 15070 |
elem.removeChild(elem.firstChild); |
| 15071 |
} |
| 15072 |
}; |
| 15073 |
|
| 15074 |
// borrowed from jqeury $(elem).is(':visible') implementation |
| 15075 |
var isVisible = function isVisible(elem) { |
| 15076 |
return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length; |
| 15077 |
}; |
| 15078 |
|
| 15079 |
var removeStyleProperty = function removeStyleProperty(elem, property) { |
| 15080 |
if (elem.style.removeProperty) { |
| 15081 |
elem.style.removeProperty(property); |
| 15082 |
} else { |
| 15083 |
elem.style.removeAttribute(property); |
| 15084 |
} |
| 15085 |
}; |
| 15086 |
|
| 15087 |
var fireClick = function fireClick(node) { |
| 15088 |
if (!isVisible(node)) { |
| 15089 |
return false; |
| 15090 |
} |
| 15091 |
|
| 15092 |
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ |
| 15093 |
// Then fixed for today's Chrome browser. |
| 15094 |
if (typeof MouseEvent === 'function') { |
| 15095 |
// Up-to-date approach |
| 15096 |
var mevt = new MouseEvent('click', { |
| 15097 |
view: window, |
| 15098 |
bubbles: false, |
| 15099 |
cancelable: true |
| 15100 |
}); |
| 15101 |
node.dispatchEvent(mevt); |
| 15102 |
} else if (document.createEvent) { |
| 15103 |
// Fallback |
| 15104 |
var evt = document.createEvent('MouseEvents'); |
| 15105 |
evt.initEvent('click', false, false); |
| 15106 |
node.dispatchEvent(evt); |
| 15107 |
} else if (document.createEventObject) { |
| 15108 |
node.fireEvent('onclick'); |
| 15109 |
} else if (typeof node.onclick === 'function') { |
| 15110 |
node.onclick(); |
| 15111 |
} |
| 15112 |
}; |
| 15113 |
|
| 15114 |
var animationEndEvent = function () { |
| 15115 |
var testEl = document.createElement('div'); |
| 15116 |
var transEndEventNames = { |
| 15117 |
'WebkitAnimation': 'webkitAnimationEnd', |
| 15118 |
'OAnimation': 'oAnimationEnd oanimationend', |
| 15119 |
'msAnimation': 'MSAnimationEnd', |
| 15120 |
'animation': 'animationend' |
| 15121 |
}; |
| 15122 |
for (var i in transEndEventNames) { |
| 15123 |
if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) { |
| 15124 |
return transEndEventNames[i]; |
| 15125 |
} |
| 15126 |
} |
| 15127 |
|
| 15128 |
return false; |
| 15129 |
}(); |
| 15130 |
|
| 15131 |
// Reset previous window keydown handler and focued element |
| 15132 |
var resetPrevState = function resetPrevState() { |
| 15133 |
window.onkeydown = states.previousWindowKeyDown; |
| 15134 |
if (states.previousActiveElement && states.previousActiveElement.focus) { |
| 15135 |
var x = window.scrollX; |
| 15136 |
var y = window.scrollY; |
| 15137 |
states.previousActiveElement.focus(); |
| 15138 |
if (x && y) { |
| 15139 |
// IE has no scrollX/scrollY support |
| 15140 |
window.scrollTo(x, y); |
| 15141 |
} |
| 15142 |
} |
| 15143 |
}; |
| 15144 |
|
| 15145 |
// Measure width of scrollbar |
| 15146 |
// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 |
| 15147 |
var measureScrollbar = function measureScrollbar() { |
| 15148 |
var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; |
| 15149 |
if (supportsTouch) { |
| 15150 |
return 0; |
| 15151 |
} |
| 15152 |
var scrollDiv = document.createElement('div'); |
| 15153 |
scrollDiv.style.width = '50px'; |
| 15154 |
scrollDiv.style.height = '50px'; |
| 15155 |
scrollDiv.style.overflow = 'scroll'; |
| 15156 |
document.body.appendChild(scrollDiv); |
| 15157 |
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; |
| 15158 |
document.body.removeChild(scrollDiv); |
| 15159 |
return scrollbarWidth; |
| 15160 |
}; |
| 15161 |
|
| 15162 |
// JavaScript Debounce Function |
| 15163 |
// Simplivied version of https://davidwalsh.name/javascript-debounce-function |
| 15164 |
var debounce = function debounce(func, wait) { |
| 15165 |
var timeout = void 0; |
| 15166 |
return function () { |
| 15167 |
var later = function later() { |
| 15168 |
timeout = null; |
| 15169 |
func(); |
| 15170 |
}; |
| 15171 |
clearTimeout(timeout); |
| 15172 |
timeout = setTimeout(later, wait); |
| 15173 |
}; |
| 15174 |
}; |
| 15175 |
|
| 15176 |
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
| 15177 |
return typeof obj; |
| 15178 |
} : function (obj) { |
| 15179 |
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
| 15180 |
}; |
| 15181 |
|
| 15182 |
|
| 15183 |
|
| 15184 |
|
| 15185 |
|
| 15186 |
|
| 15187 |
|
| 15188 |
|
| 15189 |
|
| 15190 |
|
| 15191 |
|
| 15192 |
|
| 15193 |
|
| 15194 |
|
| 15195 |
|
| 15196 |
|
| 15197 |
|
| 15198 |
|
| 15199 |
|
| 15200 |
|
| 15201 |
|
| 15202 |
var _extends = Object.assign || function (target) { |
| 15203 |
for (var i = 1; i < arguments.length; i++) { |
| 15204 |
var source = arguments[i]; |
| 15205 |
|
| 15206 |
for (var key in source) { |
| 15207 |
if (Object.prototype.hasOwnProperty.call(source, key)) { |
| 15208 |
target[key] = source[key]; |
| 15209 |
} |
| 15210 |
} |
| 15211 |
} |
| 15212 |
|
| 15213 |
return target; |
| 15214 |
}; |
| 15215 |
|
| 15216 |
var modalParams = _extends({}, defaultParams); |
| 15217 |
var queue = []; |
| 15218 |
var swal2Observer = void 0; |
| 15219 |
|
| 15220 |
/* |
| 15221 |
* Set type, text and actions on modal |
| 15222 |
*/ |
| 15223 |
var setParameters = function setParameters(params) { |
| 15224 |
var modal = getModal() || init(params); |
| 15225 |
|
| 15226 |
for (var param in params) { |
| 15227 |
if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { |
| 15228 |
console.warn('SweetAlert2: Unknown parameter "' + param + '"'); |
| 15229 |
} |
| 15230 |
} |
| 15231 |
|
| 15232 |
// Set modal width |
| 15233 |
modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width; |
| 15234 |
|
| 15235 |
modal.style.padding = params.padding + 'px'; |
| 15236 |
modal.style.background = params.background; |
| 15237 |
var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); |
| 15238 |
for (var i = 0; i < successIconParts.length; i++) { |
| 15239 |
successIconParts[i].style.background = params.background; |
| 15240 |
} |
| 15241 |
|
| 15242 |
var title = getTitle(); |
| 15243 |
var content = getContent(); |
| 15244 |
var buttonsWrapper = getButtonsWrapper(); |
| 15245 |
var confirmButton = getConfirmButton(); |
| 15246 |
var cancelButton = getCancelButton(); |
| 15247 |
var closeButton = getCloseButton(); |
| 15248 |
|
| 15249 |
// Title |
| 15250 |
if (params.titleText) { |
| 15251 |
title.innerText = params.titleText; |
| 15252 |
} else { |
| 15253 |
title.innerHTML = params.title.split('\n').join('<br>'); |
| 15254 |
} |
| 15255 |
|
| 15256 |
// Content |
| 15257 |
if (params.text || params.html) { |
| 15258 |
if (_typeof(params.html) === 'object') { |
| 15259 |
content.innerHTML = ''; |
| 15260 |
if (0 in params.html) { |
| 15261 |
for (var _i = 0; _i in params.html; _i++) { |
| 15262 |
content.appendChild(params.html[_i].cloneNode(true)); |
| 15263 |
} |
| 15264 |
} else { |
| 15265 |
content.appendChild(params.html.cloneNode(true)); |
| 15266 |
} |
| 15267 |
} else if (params.html) { |
| 15268 |
content.innerHTML = params.html; |
| 15269 |
} else if (params.text) { |
| 15270 |
content.textContent = params.text; |
| 15271 |
} |
| 15272 |
show(content); |
| 15273 |
} else { |
| 15274 |
hide(content); |
| 15275 |
} |
| 15276 |
|
| 15277 |
// Close button |
| 15278 |
if (params.showCloseButton) { |
| 15279 |
show(closeButton); |
| 15280 |
} else { |
| 15281 |
hide(closeButton); |
| 15282 |
} |
| 15283 |
|
| 15284 |
// Custom Class |
| 15285 |
modal.className = swalClasses.modal; |
| 15286 |
if (params.customClass) { |
| 15287 |
addClass(modal, params.customClass); |
| 15288 |
} |
| 15289 |
|
| 15290 |
// Progress steps |
| 15291 |
var progressStepsContainer = getProgressSteps(); |
| 15292 |
var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10); |
| 15293 |
if (params.progressSteps.length) { |
| 15294 |
show(progressStepsContainer); |
| 15295 |
empty(progressStepsContainer); |
| 15296 |
if (currentProgressStep >= params.progressSteps.length) { |
| 15297 |
console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); |
| 15298 |
} |
| 15299 |
params.progressSteps.forEach(function (step, index) { |
| 15300 |
var circle = document.createElement('li'); |
| 15301 |
addClass(circle, swalClasses.progresscircle); |
| 15302 |
circle.innerHTML = step; |
| 15303 |
if (index === currentProgressStep) { |
| 15304 |
addClass(circle, swalClasses.activeprogressstep); |
| 15305 |
} |
| 15306 |
progressStepsContainer.appendChild(circle); |
| 15307 |
if (index !== params.progressSteps.length - 1) { |
| 15308 |
var line = document.createElement('li'); |
| 15309 |
addClass(line, swalClasses.progressline); |
| 15310 |
line.style.width = params.progressStepsDistance; |
| 15311 |
progressStepsContainer.appendChild(line); |
| 15312 |
} |
| 15313 |
}); |
| 15314 |
} else { |
| 15315 |
hide(progressStepsContainer); |
| 15316 |
} |
| 15317 |
|
| 15318 |
// Icon |
| 15319 |
var icons = getIcons(); |
| 15320 |
for (var _i2 = 0; _i2 < icons.length; _i2++) { |
| 15321 |
hide(icons[_i2]); |
| 15322 |
} |
| 15323 |
if (params.type) { |
| 15324 |
var validType = false; |
| 15325 |
for (var iconType in iconTypes) { |
| 15326 |
if (params.type === iconType) { |
| 15327 |
validType = true; |
| 15328 |
break; |
| 15329 |
} |
| 15330 |
} |
| 15331 |
if (!validType) { |
| 15332 |
console.error('SweetAlert2: Unknown alert type: ' + params.type); |
| 15333 |
return false; |
| 15334 |
} |
| 15335 |
var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); |
| 15336 |
show(icon); |
| 15337 |
|
| 15338 |
// Animate icon |
| 15339 |
if (params.animation) { |
| 15340 |
switch (params.type) { |
| 15341 |
case 'success': |
| 15342 |
addClass(icon, 'swal2-animate-success-icon'); |
| 15343 |
addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip'); |
| 15344 |
addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long'); |
| 15345 |
break; |
| 15346 |
case 'error': |
| 15347 |
addClass(icon, 'swal2-animate-error-icon'); |
| 15348 |
addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark'); |
| 15349 |
break; |
| 15350 |
default: |
| 15351 |
break; |
| 15352 |
} |
| 15353 |
} |
| 15354 |
} |
| 15355 |
|
| 15356 |
// Custom image |
| 15357 |
var image = getImage(); |
| 15358 |
if (params.imageUrl) { |
| 15359 |
image.setAttribute('src', params.imageUrl); |
| 15360 |
show(image); |
| 15361 |
|
| 15362 |
if (params.imageWidth) { |
| 15363 |
image.setAttribute('width', params.imageWidth); |
| 15364 |
} else { |
| 15365 |
image.removeAttribute('width'); |
| 15366 |
} |
| 15367 |
|
| 15368 |
if (params.imageHeight) { |
| 15369 |
image.setAttribute('height', params.imageHeight); |
| 15370 |
} else { |
| 15371 |
image.removeAttribute('height'); |
| 15372 |
} |
| 15373 |
|
| 15374 |
image.className = swalClasses.image; |
| 15375 |
if (params.imageClass) { |
| 15376 |
addClass(image, params.imageClass); |
| 15377 |
} |
| 15378 |
} else { |
| 15379 |
hide(image); |
| 15380 |
} |
| 15381 |
|
| 15382 |
// Cancel button |
| 15383 |
if (params.showCancelButton) { |
| 15384 |
cancelButton.style.display = 'inline-block'; |
| 15385 |
} else { |
| 15386 |
hide(cancelButton); |
| 15387 |
} |
| 15388 |
|
| 15389 |
// Confirm button |
| 15390 |
if (params.showConfirmButton) { |
| 15391 |
removeStyleProperty(confirmButton, 'display'); |
| 15392 |
} else { |
| 15393 |
hide(confirmButton); |
| 15394 |
} |
| 15395 |
|
| 15396 |
// Buttons wrapper |
| 15397 |
if (!params.showConfirmButton && !params.showCancelButton) { |
| 15398 |
hide(buttonsWrapper); |
| 15399 |
} else { |
| 15400 |
show(buttonsWrapper); |
| 15401 |
} |
| 15402 |
|
| 15403 |
// Edit text on cancel and confirm buttons |
| 15404 |
confirmButton.innerHTML = params.confirmButtonText; |
| 15405 |
cancelButton.innerHTML = params.cancelButtonText; |
| 15406 |
|
| 15407 |
// Set buttons to selected background colors |
| 15408 |
if (params.buttonsStyling) { |
| 15409 |
confirmButton.style.backgroundColor = params.confirmButtonColor; |
| 15410 |
cancelButton.style.backgroundColor = params.cancelButtonColor; |
| 15411 |
} |
| 15412 |
|
| 15413 |
// Add buttons custom classes |
| 15414 |
confirmButton.className = swalClasses.confirm; |
| 15415 |
addClass(confirmButton, params.confirmButtonClass); |
| 15416 |
cancelButton.className = swalClasses.cancel; |
| 15417 |
addClass(cancelButton, params.cancelButtonClass); |
| 15418 |
|
| 15419 |
// Buttons styling |
| 15420 |
if (params.buttonsStyling) { |
| 15421 |
addClass(confirmButton, swalClasses.styled); |
| 15422 |
addClass(cancelButton, swalClasses.styled); |
| 15423 |
} else { |
| 15424 |
removeClass(confirmButton, swalClasses.styled); |
| 15425 |
removeClass(cancelButton, swalClasses.styled); |
| 15426 |
|
| 15427 |
confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; |
| 15428 |
cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; |
| 15429 |
} |
| 15430 |
|
| 15431 |
// CSS animation |
| 15432 |
if (params.animation === true) { |
| 15433 |
removeClass(modal, swalClasses.noanimation); |
| 15434 |
} else { |
| 15435 |
addClass(modal, swalClasses.noanimation); |
| 15436 |
} |
| 15437 |
}; |
| 15438 |
|
| 15439 |
/* |
| 15440 |
* Animations |
| 15441 |
*/ |
| 15442 |
var openModal = function openModal(animation, onComplete) { |
| 15443 |
var container = getContainer(); |
| 15444 |
var modal = getModal(); |
| 15445 |
|
| 15446 |
if (animation) { |
| 15447 |
addClass(modal, swalClasses.show); |
| 15448 |
addClass(container, swalClasses.fade); |
| 15449 |
removeClass(modal, swalClasses.hide); |
| 15450 |
} else { |
| 15451 |
removeClass(modal, swalClasses.fade); |
| 15452 |
} |
| 15453 |
show(modal); |
| 15454 |
|
| 15455 |
// scrolling is 'hidden' until animation is done, after that 'auto' |
| 15456 |
container.style.overflowY = 'hidden'; |
| 15457 |
if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { |
| 15458 |
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { |
| 15459 |
modal.removeEventListener(animationEndEvent, swalCloseEventFinished); |
| 15460 |
container.style.overflowY = 'auto'; |
| 15461 |
}); |
| 15462 |
} else { |
| 15463 |
container.style.overflowY = 'auto'; |
| 15464 |
} |
| 15465 |
|
| 15466 |
addClass(document.documentElement, swalClasses.shown); |
| 15467 |
addClass(document.body, swalClasses.shown); |
| 15468 |
addClass(container, swalClasses.shown); |
| 15469 |
fixScrollbar(); |
| 15470 |
iOSfix(); |
| 15471 |
states.previousActiveElement = document.activeElement; |
| 15472 |
if (onComplete !== null && typeof onComplete === 'function') { |
| 15473 |
setTimeout(function () { |
| 15474 |
onComplete(modal); |
| 15475 |
}); |
| 15476 |
} |
| 15477 |
}; |
| 15478 |
|
| 15479 |
var fixScrollbar = function fixScrollbar() { |
| 15480 |
// for queues, do not do this more than once |
| 15481 |
if (states.previousBodyPadding !== null) { |
| 15482 |
return; |
| 15483 |
} |
| 15484 |
// if the body has overflow |
| 15485 |
if (document.body.scrollHeight > window.innerHeight) { |
| 15486 |
// add padding so the content doesn't shift after removal of scrollbar |
| 15487 |
states.previousBodyPadding = document.body.style.paddingRight; |
| 15488 |
document.body.style.paddingRight = measureScrollbar() + 'px'; |
| 15489 |
} |
| 15490 |
}; |
| 15491 |
|
| 15492 |
var undoScrollbar = function undoScrollbar() { |
| 15493 |
if (states.previousBodyPadding !== null) { |
| 15494 |
document.body.style.paddingRight = states.previousBodyPadding; |
| 15495 |
states.previousBodyPadding = null; |
| 15496 |
} |
| 15497 |
}; |
| 15498 |
|
| 15499 |
// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425 |
| 15500 |
var iOSfix = function iOSfix() { |
| 15501 |
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; |
| 15502 |
if (iOS && !hasClass(document.body, swalClasses.iosfix)) { |
| 15503 |
var offset = document.body.scrollTop; |
| 15504 |
document.body.style.top = offset * -1 + 'px'; |
| 15505 |
addClass(document.body, swalClasses.iosfix); |
| 15506 |
} |
| 15507 |
}; |
| 15508 |
|
| 15509 |
var undoIOSfix = function undoIOSfix() { |
| 15510 |
if (hasClass(document.body, swalClasses.iosfix)) { |
| 15511 |
var offset = parseInt(document.body.style.top, 10); |
| 15512 |
removeClass(document.body, swalClasses.iosfix); |
| 15513 |
document.body.style.top = ''; |
| 15514 |
document.body.scrollTop = offset * -1; |
| 15515 |
} |
| 15516 |
}; |
| 15517 |
|
| 15518 |
// SweetAlert entry point |
| 15519 |
var sweetAlert = function sweetAlert() { |
| 15520 |
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
| 15521 |
args[_key] = arguments[_key]; |
| 15522 |
} |
| 15523 |
|
| 15524 |
if (args[0] === undefined) { |
| 15525 |
console.error('SweetAlert2 expects at least 1 attribute!'); |
| 15526 |
return false; |
| 15527 |
} |
| 15528 |
|
| 15529 |
var params = _extends({}, modalParams); |
| 15530 |
|
| 15531 |
switch (_typeof(args[0])) { |
| 15532 |
case 'string': |
| 15533 |
params.title = args[0]; |
| 15534 |
params.html = args[1]; |
| 15535 |
params.type = args[2]; |
| 15536 |
|
| 15537 |
break; |
| 15538 |
|
| 15539 |
case 'object': |
| 15540 |
_extends(params, args[0]); |
| 15541 |
params.extraParams = args[0].extraParams; |
| 15542 |
|
| 15543 |
if (params.input === 'email' && params.inputValidator === null) { |
| 15544 |
params.inputValidator = function (email) { |
| 15545 |
return new Promise(function (resolve, reject) { |
| 15546 |
var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; |
| 15547 |
if (emailRegex.test(email)) { |
| 15548 |
resolve(); |
| 15549 |
} else { |
| 15550 |
reject('Invalid email address'); |
| 15551 |
} |
| 15552 |
}); |
| 15553 |
}; |
| 15554 |
} |
| 15555 |
|
| 15556 |
if (params.input === 'url' && params.inputValidator === null) { |
| 15557 |
params.inputValidator = function (url) { |
| 15558 |
return new Promise(function (resolve, reject) { |
| 15559 |
var urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/; |
| 15560 |
if (urlRegex.test(url)) { |
| 15561 |
resolve(); |
| 15562 |
} else { |
| 15563 |
reject('Invalid URL'); |
| 15564 |
} |
| 15565 |
}); |
| 15566 |
}; |
| 15567 |
} |
| 15568 |
break; |
| 15569 |
|
| 15570 |
default: |
| 15571 |
console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0])); |
| 15572 |
return false; |
| 15573 |
} |
| 15574 |
|
| 15575 |
setParameters(params); |
| 15576 |
|
| 15577 |
var container = getContainer(); |
| 15578 |
var modal = getModal(); |
| 15579 |
|
| 15580 |
return new Promise(function (resolve, reject) { |
| 15581 |
// Close on timer |
| 15582 |
if (params.timer) { |
| 15583 |
modal.timeout = setTimeout(function () { |
| 15584 |
sweetAlert.closeModal(params.onClose); |
| 15585 |
if (params.useRejections) { |
| 15586 |
reject('timer'); |
| 15587 |
} else { |
| 15588 |
resolve({ dismiss: 'timer' }); |
| 15589 |
} |
| 15590 |
}, params.timer); |
| 15591 |
} |
| 15592 |
|
| 15593 |
// Get input element by specified type or, if type isn't specified, by params.input |
| 15594 |
var getInput = function getInput(inputType) { |
| 15595 |
inputType = inputType || params.input; |
| 15596 |
if (!inputType) { |
| 15597 |
return null; |
| 15598 |
} |
| 15599 |
switch (inputType) { |
| 15600 |
case 'select': |
| 15601 |
case 'textarea': |
| 15602 |
case 'file': |
| 15603 |
return getChildByClass(modal, swalClasses[inputType]); |
| 15604 |
case 'checkbox': |
| 15605 |
return modal.querySelector('.' + swalClasses.checkbox + ' input'); |
| 15606 |
case 'radio': |
| 15607 |
return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child'); |
| 15608 |
case 'range': |
| 15609 |
return modal.querySelector('.' + swalClasses.range + ' input'); |
| 15610 |
default: |
| 15611 |
return getChildByClass(modal, swalClasses.input); |
| 15612 |
} |
| 15613 |
}; |
| 15614 |
|
| 15615 |
// Get the value of the modal input |
| 15616 |
var getInputValue = function getInputValue() { |
| 15617 |
var input = getInput(); |
| 15618 |
if (!input) { |
| 15619 |
return null; |
| 15620 |
} |
| 15621 |
switch (params.input) { |
| 15622 |
case 'checkbox': |
| 15623 |
return input.checked ? 1 : 0; |
| 15624 |
case 'radio': |
| 15625 |
return input.checked ? input.value : null; |
| 15626 |
case 'file': |
| 15627 |
return input.files.length ? input.files[0] : null; |
| 15628 |
default: |
| 15629 |
return params.inputAutoTrim ? input.value.trim() : input.value; |
| 15630 |
} |
| 15631 |
}; |
| 15632 |
|
| 15633 |
// input autofocus |
| 15634 |
if (params.input) { |
| 15635 |
setTimeout(function () { |
| 15636 |
var input = getInput(); |
| 15637 |
if (input) { |
| 15638 |
focusInput(input); |
| 15639 |
} |
| 15640 |
}, 0); |
| 15641 |
} |
| 15642 |
|
| 15643 |
var confirm = function confirm(value) { |
| 15644 |
if (params.showLoaderOnConfirm) { |
| 15645 |
sweetAlert.showLoading(); |
| 15646 |
} |
| 15647 |
|
| 15648 |
if (params.preConfirm) { |
| 15649 |
params.preConfirm(value, params.extraParams).then(function (preConfirmValue) { |
| 15650 |
sweetAlert.closeModal(params.onClose); |
| 15651 |
resolve(preConfirmValue || value); |
| 15652 |
}, function (error) { |
| 15653 |
sweetAlert.hideLoading(); |
| 15654 |
if (error) { |
| 15655 |
sweetAlert.showValidationError(error); |
| 15656 |
} |
| 15657 |
}); |
| 15658 |
} else { |
| 15659 |
sweetAlert.closeModal(params.onClose); |
| 15660 |
if (params.useRejections) { |
| 15661 |
resolve(value); |
| 15662 |
} else { |
| 15663 |
resolve({ value: value }); |
| 15664 |
} |
| 15665 |
} |
| 15666 |
}; |
| 15667 |
|
| 15668 |
// Mouse interactions |
| 15669 |
var onButtonEvent = function onButtonEvent(event) { |
| 15670 |
var e = event || window.event; |
| 15671 |
var target = e.target || e.srcElement; |
| 15672 |
var confirmButton = getConfirmButton(); |
| 15673 |
var cancelButton = getCancelButton(); |
| 15674 |
var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target)); |
| 15675 |
var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target)); |
| 15676 |
|
| 15677 |
switch (e.type) { |
| 15678 |
case 'mouseover': |
| 15679 |
case 'mouseup': |
| 15680 |
if (params.buttonsStyling) { |
| 15681 |
if (targetedConfirm) { |
| 15682 |
confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1); |
| 15683 |
} else if (targetedCancel) { |
| 15684 |
cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1); |
| 15685 |
} |
| 15686 |
} |
| 15687 |
break; |
| 15688 |
case 'mouseout': |
| 15689 |
if (params.buttonsStyling) { |
| 15690 |
if (targetedConfirm) { |
| 15691 |
confirmButton.style.backgroundColor = params.confirmButtonColor; |
| 15692 |
} else if (targetedCancel) { |
| 15693 |
cancelButton.style.backgroundColor = params.cancelButtonColor; |
| 15694 |
} |
| 15695 |
} |
| 15696 |
break; |
| 15697 |
case 'mousedown': |
| 15698 |
if (params.buttonsStyling) { |
| 15699 |
if (targetedConfirm) { |
| 15700 |
confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2); |
| 15701 |
} else if (targetedCancel) { |
| 15702 |
cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2); |
| 15703 |
} |
| 15704 |
} |
| 15705 |
break; |
| 15706 |
case 'click': |
| 15707 |
// Clicked 'confirm' |
| 15708 |
if (targetedConfirm && sweetAlert.isVisible()) { |
| 15709 |
sweetAlert.disableButtons(); |
| 15710 |
if (params.input) { |
| 15711 |
var inputValue = getInputValue(); |
| 15712 |
|
| 15713 |
if (params.inputValidator) { |
| 15714 |
sweetAlert.disableInput(); |
| 15715 |
params.inputValidator(inputValue, params.extraParams).then(function () { |
| 15716 |
sweetAlert.enableButtons(); |
| 15717 |
sweetAlert.enableInput(); |
| 15718 |
confirm(inputValue); |
| 15719 |
}, function (error) { |
| 15720 |
sweetAlert.enableButtons(); |
| 15721 |
sweetAlert.enableInput(); |
| 15722 |
if (error) { |
| 15723 |
sweetAlert.showValidationError(error); |
| 15724 |
} |
| 15725 |
}); |
| 15726 |
} else { |
| 15727 |
confirm(inputValue); |
| 15728 |
} |
| 15729 |
} else { |
| 15730 |
confirm(true); |
| 15731 |
} |
| 15732 |
|
| 15733 |
// Clicked 'cancel' |
| 15734 |
} else if (targetedCancel && sweetAlert.isVisible()) { |
| 15735 |
sweetAlert.disableButtons(); |
| 15736 |
sweetAlert.closeModal(params.onClose); |
| 15737 |
if (params.useRejections) { |
| 15738 |
reject('cancel'); |
| 15739 |
} else { |
| 15740 |
resolve({ dismiss: 'cancel' }); |
| 15741 |
} |
| 15742 |
} |
| 15743 |
break; |
| 15744 |
default: |
| 15745 |
} |
| 15746 |
}; |
| 15747 |
|
| 15748 |
var buttons = modal.querySelectorAll('button'); |
| 15749 |
for (var i = 0; i < buttons.length; i++) { |
| 15750 |
buttons[i].onclick = onButtonEvent; |
| 15751 |
buttons[i].onmouseover = onButtonEvent; |
| 15752 |
buttons[i].onmouseout = onButtonEvent; |
| 15753 |
buttons[i].onmousedown = onButtonEvent; |
| 15754 |
} |
| 15755 |
|
| 15756 |
// Closing modal by close button |
| 15757 |
getCloseButton().onclick = function () { |
| 15758 |
sweetAlert.closeModal(params.onClose); |
| 15759 |
if (params.useRejections) { |
| 15760 |
reject('close'); |
| 15761 |
} else { |
| 15762 |
resolve({ dismiss: 'close' }); |
| 15763 |
} |
| 15764 |
}; |
| 15765 |
|
| 15766 |
// Closing modal by overlay click |
| 15767 |
container.onclick = function (e) { |
| 15768 |
if (e.target !== container) { |
| 15769 |
return; |
| 15770 |
} |
| 15771 |
if (params.allowOutsideClick) { |
| 15772 |
sweetAlert.closeModal(params.onClose); |
| 15773 |
if (params.useRejections) { |
| 15774 |
reject('overlay'); |
| 15775 |
} else { |
| 15776 |
resolve({ dismiss: 'overlay' }); |
| 15777 |
} |
| 15778 |
} |
| 15779 |
}; |
| 15780 |
|
| 15781 |
var buttonsWrapper = getButtonsWrapper(); |
| 15782 |
var confirmButton = getConfirmButton(); |
| 15783 |
var cancelButton = getCancelButton(); |
| 15784 |
|
| 15785 |
// Reverse buttons (Confirm on the right side) |
| 15786 |
if (params.reverseButtons) { |
| 15787 |
confirmButton.parentNode.insertBefore(cancelButton, confirmButton); |
| 15788 |
} else { |
| 15789 |
confirmButton.parentNode.insertBefore(confirmButton, cancelButton); |
| 15790 |
} |
| 15791 |
|
| 15792 |
// Focus handling |
| 15793 |
var setFocus = function setFocus(index, increment) { |
| 15794 |
var focusableElements = getFocusableElements(params.focusCancel); |
| 15795 |
// search for visible elements and select the next possible match |
| 15796 |
for (var _i3 = 0; _i3 < focusableElements.length; _i3++) { |
| 15797 |
index = index + increment; |
| 15798 |
|
| 15799 |
// rollover to first item |
| 15800 |
if (index === focusableElements.length) { |
| 15801 |
index = 0; |
| 15802 |
|
| 15803 |
// go to last item |
| 15804 |
} else if (index === -1) { |
| 15805 |
index = focusableElements.length - 1; |
| 15806 |
} |
| 15807 |
|
| 15808 |
// determine if element is visible |
| 15809 |
var el = focusableElements[index]; |
| 15810 |
if (isVisible(el)) { |
| 15811 |
return el.focus(); |
| 15812 |
} |
| 15813 |
} |
| 15814 |
}; |
| 15815 |
|
| 15816 |
var handleKeyDown = function handleKeyDown(event) { |
| 15817 |
var e = event || window.event; |
| 15818 |
var keyCode = e.keyCode || e.which; |
| 15819 |
|
| 15820 |
if ([9, 13, 32, 27, 37, 38, 39, 40].indexOf(keyCode) === -1) { |
| 15821 |
// Don't do work on keys we don't care about. |
| 15822 |
return; |
| 15823 |
} |
| 15824 |
|
| 15825 |
var targetElement = e.target || e.srcElement; |
| 15826 |
|
| 15827 |
var focusableElements = getFocusableElements(params.focusCancel); |
| 15828 |
var btnIndex = -1; // Find the button - note, this is a nodelist, not an array. |
| 15829 |
for (var _i4 = 0; _i4 < focusableElements.length; _i4++) { |
| 15830 |
if (targetElement === focusableElements[_i4]) { |
| 15831 |
btnIndex = _i4; |
| 15832 |
break; |
| 15833 |
} |
| 15834 |
} |
| 15835 |
|
| 15836 |
// TAB |
| 15837 |
if (keyCode === 9) { |
| 15838 |
if (!e.shiftKey) { |
| 15839 |
// Cycle to the next button |
| 15840 |
setFocus(btnIndex, 1); |
| 15841 |
} else { |
| 15842 |
// Cycle to the prev button |
| 15843 |
setFocus(btnIndex, -1); |
| 15844 |
} |
| 15845 |
e.stopPropagation(); |
| 15846 |
e.preventDefault(); |
| 15847 |
|
| 15848 |
// ARROWS - switch focus between buttons |
| 15849 |
} else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) { |
| 15850 |
// focus Cancel button if Confirm button is currently focused |
| 15851 |
if (document.activeElement === confirmButton && isVisible(cancelButton)) { |
| 15852 |
cancelButton.focus(); |
| 15853 |
// and vice versa |
| 15854 |
} else if (document.activeElement === cancelButton && isVisible(confirmButton)) { |
| 15855 |
confirmButton.focus(); |
| 15856 |
} |
| 15857 |
|
| 15858 |
// ENTER/SPACE |
| 15859 |
} else if (keyCode === 13 || keyCode === 32) { |
| 15860 |
if (btnIndex === -1 && params.allowEnterKey) { |
| 15861 |
// ENTER/SPACE clicked outside of a button. |
| 15862 |
if (params.focusCancel) { |
| 15863 |
fireClick(cancelButton, e); |
| 15864 |
} else { |
| 15865 |
fireClick(confirmButton, e); |
| 15866 |
} |
| 15867 |
e.stopPropagation(); |
| 15868 |
e.preventDefault(); |
| 15869 |
} |
| 15870 |
|
| 15871 |
// ESC |
| 15872 |
} else if (keyCode === 27 && params.allowEscapeKey === true) { |
| 15873 |
sweetAlert.closeModal(params.onClose); |
| 15874 |
if (params.useRejections) { |
| 15875 |
reject('esc'); |
| 15876 |
} else { |
| 15877 |
resolve({ dismiss: 'esc' }); |
| 15878 |
} |
| 15879 |
} |
| 15880 |
}; |
| 15881 |
|
| 15882 |
if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) { |
| 15883 |
states.previousWindowKeyDown = window.onkeydown; |
| 15884 |
window.onkeydown = handleKeyDown; |
| 15885 |
} |
| 15886 |
|
| 15887 |
// Loading state |
| 15888 |
if (params.buttonsStyling) { |
| 15889 |
confirmButton.style.borderLeftColor = params.confirmButtonColor; |
| 15890 |
confirmButton.style.borderRightColor = params.confirmButtonColor; |
| 15891 |
} |
| 15892 |
|
| 15893 |
/** |
| 15894 |
* Show spinner instead of Confirm button and disable Cancel button |
| 15895 |
*/ |
| 15896 |
sweetAlert.hideLoading = sweetAlert.disableLoading = function () { |
| 15897 |
if (!params.showConfirmButton) { |
| 15898 |
hide(confirmButton); |
| 15899 |
if (!params.showCancelButton) { |
| 15900 |
hide(getButtonsWrapper()); |
| 15901 |
} |
| 15902 |
} |
| 15903 |
removeClass(buttonsWrapper, swalClasses.loading); |
| 15904 |
removeClass(modal, swalClasses.loading); |
| 15905 |
confirmButton.disabled = false; |
| 15906 |
cancelButton.disabled = false; |
| 15907 |
}; |
| 15908 |
|
| 15909 |
sweetAlert.getTitle = function () { |
| 15910 |
return getTitle(); |
| 15911 |
}; |
| 15912 |
sweetAlert.getContent = function () { |
| 15913 |
return getContent(); |
| 15914 |
}; |
| 15915 |
sweetAlert.getInput = function () { |
| 15916 |
return getInput(); |
| 15917 |
}; |
| 15918 |
sweetAlert.getImage = function () { |
| 15919 |
return getImage(); |
| 15920 |
}; |
| 15921 |
sweetAlert.getButtonsWrapper = function () { |
| 15922 |
return getButtonsWrapper(); |
| 15923 |
}; |
| 15924 |
sweetAlert.getConfirmButton = function () { |
| 15925 |
return getConfirmButton(); |
| 15926 |
}; |
| 15927 |
sweetAlert.getCancelButton = function () { |
| 15928 |
return getCancelButton(); |
| 15929 |
}; |
| 15930 |
|
| 15931 |
sweetAlert.enableButtons = function () { |
| 15932 |
confirmButton.disabled = false; |
| 15933 |
cancelButton.disabled = false; |
| 15934 |
}; |
| 15935 |
|
| 15936 |
sweetAlert.disableButtons = function () { |
| 15937 |
confirmButton.disabled = true; |
| 15938 |
cancelButton.disabled = true; |
| 15939 |
}; |
| 15940 |
|
| 15941 |
sweetAlert.enableConfirmButton = function () { |
| 15942 |
confirmButton.disabled = false; |
| 15943 |
}; |
| 15944 |
|
| 15945 |
sweetAlert.disableConfirmButton = function () { |
| 15946 |
confirmButton.disabled = true; |
| 15947 |
}; |
| 15948 |
|
| 15949 |
sweetAlert.enableInput = function () { |
| 15950 |
var input = getInput(); |
| 15951 |
if (!input) { |
| 15952 |
return false; |
| 15953 |
} |
| 15954 |
if (input.type === 'radio') { |
| 15955 |
var radiosContainer = input.parentNode.parentNode; |
| 15956 |
var radios = radiosContainer.querySelectorAll('input'); |
| 15957 |
for (var _i5 = 0; _i5 < radios.length; _i5++) { |
| 15958 |
radios[_i5].disabled = false; |
| 15959 |
} |
| 15960 |
} else { |
| 15961 |
input.disabled = false; |
| 15962 |
} |
| 15963 |
}; |
| 15964 |
|
| 15965 |
sweetAlert.disableInput = function () { |
| 15966 |
var input = getInput(); |
| 15967 |
if (!input) { |
| 15968 |
return false; |
| 15969 |
} |
| 15970 |
if (input && input.type === 'radio') { |
| 15971 |
var radiosContainer = input.parentNode.parentNode; |
| 15972 |
var radios = radiosContainer.querySelectorAll('input'); |
| 15973 |
for (var _i6 = 0; _i6 < radios.length; _i6++) { |
| 15974 |
radios[_i6].disabled = true; |
| 15975 |
} |
| 15976 |
} else { |
| 15977 |
input.disabled = true; |
| 15978 |
} |
| 15979 |
}; |
| 15980 |
|
| 15981 |
// Set modal min-height to disable scrolling inside the modal |
| 15982 |
sweetAlert.recalculateHeight = debounce(function () { |
| 15983 |
var modal = getModal(); |
| 15984 |
if (!modal) { |
| 15985 |
return; |
| 15986 |
} |
| 15987 |
var prevState = modal.style.display; |
| 15988 |
modal.style.minHeight = ''; |
| 15989 |
show(modal); |
| 15990 |
modal.style.minHeight = modal.scrollHeight + 1 + 'px'; |
| 15991 |
modal.style.display = prevState; |
| 15992 |
}, 50); |
| 15993 |
|
| 15994 |
// Show block with validation error |
| 15995 |
sweetAlert.showValidationError = function (error) { |
| 15996 |
var validationError = getValidationError(); |
| 15997 |
validationError.innerHTML = error; |
| 15998 |
show(validationError); |
| 15999 |
|
| 16000 |
var input = getInput(); |
| 16001 |
if (input) { |
| 16002 |
focusInput(input); |
| 16003 |
addClass(input, swalClasses.inputerror); |
| 16004 |
} |
| 16005 |
}; |
| 16006 |
|
| 16007 |
// Hide block with validation error |
| 16008 |
sweetAlert.resetValidationError = function () { |
| 16009 |
var validationError = getValidationError(); |
| 16010 |
hide(validationError); |
| 16011 |
sweetAlert.recalculateHeight(); |
| 16012 |
|
| 16013 |
var input = getInput(); |
| 16014 |
if (input) { |
| 16015 |
removeClass(input, swalClasses.inputerror); |
| 16016 |
} |
| 16017 |
}; |
| 16018 |
|
| 16019 |
sweetAlert.getProgressSteps = function () { |
| 16020 |
return params.progressSteps; |
| 16021 |
}; |
| 16022 |
|
| 16023 |
sweetAlert.setProgressSteps = function (progressSteps) { |
| 16024 |
params.progressSteps = progressSteps; |
| 16025 |
setParameters(params); |
| 16026 |
}; |
| 16027 |
|
| 16028 |
sweetAlert.showProgressSteps = function () { |
| 16029 |
show(getProgressSteps()); |
| 16030 |
}; |
| 16031 |
|
| 16032 |
sweetAlert.hideProgressSteps = function () { |
| 16033 |
hide(getProgressSteps()); |
| 16034 |
}; |
| 16035 |
|
| 16036 |
sweetAlert.enableButtons(); |
| 16037 |
sweetAlert.hideLoading(); |
| 16038 |
sweetAlert.resetValidationError(); |
| 16039 |
|
| 16040 |
// inputs |
| 16041 |
var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; |
| 16042 |
var input = void 0; |
| 16043 |
for (var _i7 = 0; _i7 < inputTypes.length; _i7++) { |
| 16044 |
var inputClass = swalClasses[inputTypes[_i7]]; |
| 16045 |
var inputContainer = getChildByClass(modal, inputClass); |
| 16046 |
input = getInput(inputTypes[_i7]); |
| 16047 |
|
| 16048 |
// set attributes |
| 16049 |
if (input) { |
| 16050 |
for (var j in input.attributes) { |
| 16051 |
if (input.attributes.hasOwnProperty(j)) { |
| 16052 |
var attrName = input.attributes[j].name; |
| 16053 |
if (attrName !== 'type' && attrName !== 'value') { |
| 16054 |
input.removeAttribute(attrName); |
| 16055 |
} |
| 16056 |
} |
| 16057 |
} |
| 16058 |
for (var attr in params.inputAttributes) { |
| 16059 |
input.setAttribute(attr, params.inputAttributes[attr]); |
| 16060 |
} |
| 16061 |
} |
| 16062 |
|
| 16063 |
// set class |
| 16064 |
inputContainer.className = inputClass; |
| 16065 |
if (params.inputClass) { |
| 16066 |
addClass(inputContainer, params.inputClass); |
| 16067 |
} |
| 16068 |
|
| 16069 |
hide(inputContainer); |
| 16070 |
} |
| 16071 |
|
| 16072 |
var populateInputOptions = void 0; |
| 16073 |
switch (params.input) { |
| 16074 |
case 'text': |
| 16075 |
case 'email': |
| 16076 |
case 'password': |
| 16077 |
case 'number': |
| 16078 |
case 'tel': |
| 16079 |
case 'url': |
| 16080 |
input = getChildByClass(modal, swalClasses.input); |
| 16081 |
input.value = params.inputValue; |
| 16082 |
input.placeholder = params.inputPlaceholder; |
| 16083 |
input.type = params.input; |
| 16084 |
show(input); |
| 16085 |
break; |
| 16086 |
case 'file': |
| 16087 |
input = getChildByClass(modal, swalClasses.file); |
| 16088 |
input.placeholder = params.inputPlaceholder; |
| 16089 |
input.type = params.input; |
| 16090 |
show(input); |
| 16091 |
break; |
| 16092 |
case 'range': |
| 16093 |
var range = getChildByClass(modal, swalClasses.range); |
| 16094 |
var rangeInput = range.querySelector('input'); |
| 16095 |
var rangeOutput = range.querySelector('output'); |
| 16096 |
rangeInput.value = params.inputValue; |
| 16097 |
rangeInput.type = params.input; |
| 16098 |
rangeOutput.value = params.inputValue; |
| 16099 |
show(range); |
| 16100 |
break; |
| 16101 |
case 'select': |
| 16102 |
var select = getChildByClass(modal, swalClasses.select); |
| 16103 |
select.innerHTML = ''; |
| 16104 |
if (params.inputPlaceholder) { |
| 16105 |
var placeholder = document.createElement('option'); |
| 16106 |
placeholder.innerHTML = params.inputPlaceholder; |
| 16107 |
placeholder.value = ''; |
| 16108 |
placeholder.disabled = true; |
| 16109 |
placeholder.selected = true; |
| 16110 |
select.appendChild(placeholder); |
| 16111 |
} |
| 16112 |
populateInputOptions = function populateInputOptions(inputOptions) { |
| 16113 |
for (var optionValue in inputOptions) { |
| 16114 |
var option = document.createElement('option'); |
| 16115 |
option.value = optionValue; |
| 16116 |
option.innerHTML = inputOptions[optionValue]; |
| 16117 |
if (params.inputValue === optionValue) { |
| 16118 |
option.selected = true; |
| 16119 |
} |
| 16120 |
select.appendChild(option); |
| 16121 |
} |
| 16122 |
show(select); |
| 16123 |
select.focus(); |
| 16124 |
}; |
| 16125 |
break; |
| 16126 |
case 'radio': |
| 16127 |
var radio = getChildByClass(modal, swalClasses.radio); |
| 16128 |
radio.innerHTML = ''; |
| 16129 |
populateInputOptions = function populateInputOptions(inputOptions) { |
| 16130 |
for (var radioValue in inputOptions) { |
| 16131 |
var radioInput = document.createElement('input'); |
| 16132 |
var radioLabel = document.createElement('label'); |
| 16133 |
var radioLabelSpan = document.createElement('span'); |
| 16134 |
radioInput.type = 'radio'; |
| 16135 |
radioInput.name = swalClasses.radio; |
| 16136 |
radioInput.value = radioValue; |
| 16137 |
if (params.inputValue === radioValue) { |
| 16138 |
radioInput.checked = true; |
| 16139 |
} |
| 16140 |
radioLabelSpan.innerHTML = inputOptions[radioValue]; |
| 16141 |
radioLabel.appendChild(radioInput); |
| 16142 |
radioLabel.appendChild(radioLabelSpan); |
| 16143 |
radioLabel.for = radioInput.id; |
| 16144 |
radio.appendChild(radioLabel); |
| 16145 |
} |
| 16146 |
show(radio); |
| 16147 |
var radios = radio.querySelectorAll('input'); |
| 16148 |
if (radios.length) { |
| 16149 |
radios[0].focus(); |
| 16150 |
} |
| 16151 |
}; |
| 16152 |
break; |
| 16153 |
case 'checkbox': |
| 16154 |
var checkbox = getChildByClass(modal, swalClasses.checkbox); |
| 16155 |
var checkboxInput = getInput('checkbox'); |
| 16156 |
checkboxInput.type = 'checkbox'; |
| 16157 |
checkboxInput.value = 1; |
| 16158 |
checkboxInput.id = swalClasses.checkbox; |
| 16159 |
checkboxInput.checked = Boolean(params.inputValue); |
| 16160 |
var label = checkbox.getElementsByTagName('span'); |
| 16161 |
if (label.length) { |
| 16162 |
checkbox.removeChild(label[0]); |
| 16163 |
} |
| 16164 |
label = document.createElement('span'); |
| 16165 |
label.innerHTML = params.inputPlaceholder; |
| 16166 |
checkbox.appendChild(label); |
| 16167 |
show(checkbox); |
| 16168 |
break; |
| 16169 |
case 'textarea': |
| 16170 |
var textarea = getChildByClass(modal, swalClasses.textarea); |
| 16171 |
textarea.value = params.inputValue; |
| 16172 |
textarea.placeholder = params.inputPlaceholder; |
| 16173 |
show(textarea); |
| 16174 |
break; |
| 16175 |
case null: |
| 16176 |
break; |
| 16177 |
default: |
| 16178 |
console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"'); |
| 16179 |
break; |
| 16180 |
} |
| 16181 |
|
| 16182 |
if (params.input === 'select' || params.input === 'radio') { |
| 16183 |
if (params.inputOptions instanceof Promise) { |
| 16184 |
sweetAlert.showLoading(); |
| 16185 |
params.inputOptions.then(function (inputOptions) { |
| 16186 |
sweetAlert.hideLoading(); |
| 16187 |
populateInputOptions(inputOptions); |
| 16188 |
}); |
| 16189 |
} else if (_typeof(params.inputOptions) === 'object') { |
| 16190 |
populateInputOptions(params.inputOptions); |
| 16191 |
} else { |
| 16192 |
console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions)); |
| 16193 |
} |
| 16194 |
} |
| 16195 |
|
| 16196 |
openModal(params.animation, params.onOpen); |
| 16197 |
|
| 16198 |
// Focus the first element (input or button) |
| 16199 |
if (params.allowEnterKey) { |
| 16200 |
setFocus(-1, 1); |
| 16201 |
} else { |
| 16202 |
if (document.activeElement) { |
| 16203 |
document.activeElement.blur(); |
| 16204 |
} |
| 16205 |
} |
| 16206 |
|
| 16207 |
// fix scroll |
| 16208 |
getContainer().scrollTop = 0; |
| 16209 |
|
| 16210 |
// Observe changes inside the modal and adjust height |
| 16211 |
if (typeof MutationObserver !== 'undefined' && !swal2Observer) { |
| 16212 |
swal2Observer = new MutationObserver(sweetAlert.recalculateHeight); |
| 16213 |
swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true }); |
| 16214 |
} |
| 16215 |
}); |
| 16216 |
}; |
| 16217 |
|
| 16218 |
/* |
| 16219 |
* Global function to determine if swal2 modal is shown |
| 16220 |
*/ |
| 16221 |
sweetAlert.isVisible = function () { |
| 16222 |
return !!getModal(); |
| 16223 |
}; |
| 16224 |
|
| 16225 |
/* |
| 16226 |
* Global function for chaining sweetAlert modals |
| 16227 |
*/ |
| 16228 |
sweetAlert.queue = function (steps) { |
| 16229 |
queue = steps; |
| 16230 |
var resetQueue = function resetQueue() { |
| 16231 |
queue = []; |
| 16232 |
document.body.removeAttribute('data-swal2-queue-step'); |
| 16233 |
}; |
| 16234 |
var queueResult = []; |
| 16235 |
return new Promise(function (resolve, reject) { |
| 16236 |
(function step(i, callback) { |
| 16237 |
if (i < queue.length) { |
| 16238 |
document.body.setAttribute('data-swal2-queue-step', i); |
| 16239 |
|
| 16240 |
sweetAlert(queue[i]).then(function (result) { |
| 16241 |
queueResult.push(result); |
| 16242 |
step(i + 1, callback); |
| 16243 |
}, function (dismiss) { |
| 16244 |
resetQueue(); |
| 16245 |
reject(dismiss); |
| 16246 |
}); |
| 16247 |
} else { |
| 16248 |
resetQueue(); |
| 16249 |
resolve(queueResult); |
| 16250 |
} |
| 16251 |
})(0); |
| 16252 |
}); |
| 16253 |
}; |
| 16254 |
|
| 16255 |
/* |
| 16256 |
* Global function for getting the index of current modal in queue |
| 16257 |
*/ |
| 16258 |
sweetAlert.getQueueStep = function () { |
| 16259 |
return document.body.getAttribute('data-swal2-queue-step'); |
| 16260 |
}; |
| 16261 |
|
| 16262 |
/* |
| 16263 |
* Global function for inserting a modal to the queue |
| 16264 |
*/ |
| 16265 |
sweetAlert.insertQueueStep = function (step, index) { |
| 16266 |
if (index && index < queue.length) { |
| 16267 |
return queue.splice(index, 0, step); |
| 16268 |
} |
| 16269 |
return queue.push(step); |
| 16270 |
}; |
| 16271 |
|
| 16272 |
/* |
| 16273 |
* Global function for deleting a modal from the queue |
| 16274 |
*/ |
| 16275 |
sweetAlert.deleteQueueStep = function (index) { |
| 16276 |
if (typeof queue[index] !== 'undefined') { |
| 16277 |
queue.splice(index, 1); |
| 16278 |
} |
| 16279 |
}; |
| 16280 |
|
| 16281 |
/* |
| 16282 |
* Global function to close sweetAlert |
| 16283 |
*/ |
| 16284 |
sweetAlert.close = sweetAlert.closeModal = function (onComplete) { |
| 16285 |
var container = getContainer(); |
| 16286 |
var modal = getModal(); |
| 16287 |
if (!modal) { |
| 16288 |
return; |
| 16289 |
} |
| 16290 |
removeClass(modal, swalClasses.show); |
| 16291 |
addClass(modal, swalClasses.hide); |
| 16292 |
clearTimeout(modal.timeout); |
| 16293 |
|
| 16294 |
resetPrevState(); |
| 16295 |
|
| 16296 |
var removeModalAndResetState = function removeModalAndResetState() { |
| 16297 |
if (container.parentNode) { |
| 16298 |
container.parentNode.removeChild(container); |
| 16299 |
} |
| 16300 |
removeClass(document.documentElement, swalClasses.shown); |
| 16301 |
removeClass(document.body, swalClasses.shown); |
| 16302 |
undoScrollbar(); |
| 16303 |
undoIOSfix(); |
| 16304 |
}; |
| 16305 |
|
| 16306 |
// If animation is supported, animate |
| 16307 |
if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { |
| 16308 |
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { |
| 16309 |
modal.removeEventListener(animationEndEvent, swalCloseEventFinished); |
| 16310 |
if (hasClass(modal, swalClasses.hide)) { |
| 16311 |
removeModalAndResetState(); |
| 16312 |
} |
| 16313 |
}); |
| 16314 |
} else { |
| 16315 |
// Otherwise, remove immediately |
| 16316 |
removeModalAndResetState(); |
| 16317 |
} |
| 16318 |
if (onComplete !== null && typeof onComplete === 'function') { |
| 16319 |
setTimeout(function () { |
| 16320 |
onComplete(modal); |
| 16321 |
}); |
| 16322 |
} |
| 16323 |
}; |
| 16324 |
|
| 16325 |
/* |
| 16326 |
* Global function to click 'Confirm' button |
| 16327 |
*/ |
| 16328 |
sweetAlert.clickConfirm = function () { |
| 16329 |
return getConfirmButton().click(); |
| 16330 |
}; |
| 16331 |
|
| 16332 |
/* |
| 16333 |
* Global function to click 'Cancel' button |
| 16334 |
*/ |
| 16335 |
sweetAlert.clickCancel = function () { |
| 16336 |
return getCancelButton().click(); |
| 16337 |
}; |
| 16338 |
|
| 16339 |
/** |
| 16340 |
* Show spinner instead of Confirm button and disable Cancel button |
| 16341 |
*/ |
| 16342 |
sweetAlert.showLoading = sweetAlert.enableLoading = function () { |
| 16343 |
var modal = getModal(); |
| 16344 |
if (!modal) { |
| 16345 |
sweetAlert(''); |
| 16346 |
} |
| 16347 |
var buttonsWrapper = getButtonsWrapper(); |
| 16348 |
var confirmButton = getConfirmButton(); |
| 16349 |
var cancelButton = getCancelButton(); |
| 16350 |
|
| 16351 |
show(buttonsWrapper); |
| 16352 |
show(confirmButton, 'inline-block'); |
| 16353 |
addClass(buttonsWrapper, swalClasses.loading); |
| 16354 |
addClass(modal, swalClasses.loading); |
| 16355 |
confirmButton.disabled = true; |
| 16356 |
cancelButton.disabled = true; |
| 16357 |
}; |
| 16358 |
|
| 16359 |
/** |
| 16360 |
* Set default params for each popup |
| 16361 |
* @param {Object} userParams |
| 16362 |
*/ |
| 16363 |
sweetAlert.setDefaults = function (userParams) { |
| 16364 |
if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') { |
| 16365 |
return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object'); |
| 16366 |
} |
| 16367 |
|
| 16368 |
for (var param in userParams) { |
| 16369 |
if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { |
| 16370 |
console.warn('SweetAlert2: Unknown parameter "' + param + '"'); |
| 16371 |
delete userParams[param]; |
| 16372 |
} |
| 16373 |
} |
| 16374 |
|
| 16375 |
_extends(modalParams, userParams); |
| 16376 |
}; |
| 16377 |
|
| 16378 |
/** |
| 16379 |
* Reset default params for each popup |
| 16380 |
*/ |
| 16381 |
sweetAlert.resetDefaults = function () { |
| 16382 |
modalParams = _extends({}, defaultParams); |
| 16383 |
}; |
| 16384 |
|
| 16385 |
sweetAlert.noop = function () {}; |
| 16386 |
|
| 16387 |
sweetAlert.version = '6.6.4'; |
| 16388 |
|
| 16389 |
sweetAlert.default = sweetAlert; |
| 16390 |
|
| 16391 |
return sweetAlert; |
| 16392 |
|
| 16393 |
}))); |
| 16394 |
if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2; |
| 16395 |
|
| 16396 |
/* assets/wpuf/vendor/jquery.scrollTo/jquery.scrollTo.js */ |
| 16397 |
/*! |
| 16398 |
* jQuery.scrollTo |
| 16399 |
* Copyright (c) 2007-2015 Ariel Flesler - aflesler ○ gmail • com | http://flesler.blogspot.com |
| 16400 |
* Licensed under MIT |
| 16401 |
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html |
| 16402 |
* @projectDescription Lightweight, cross-browser and highly customizable animated scrolling with jQuery |
| 16403 |
* @author Ariel Flesler |
| 16404 |
* @version 2.1.2 |
| 16405 |
*/ |
| 16406 |
;(function(factory) { |
| 16407 |
'use strict'; |
| 16408 |
if (typeof define === 'function' && define.amd) { |
| 16409 |
// AMD |
| 16410 |
define(['jquery'], factory); |
| 16411 |
} else if (typeof module !== 'undefined' && module.exports) { |
| 16412 |
// CommonJS |
| 16413 |
module.exports = factory(require('jquery')); |
| 16414 |
} else { |
| 16415 |
// Global |
| 16416 |
factory(jQuery); |
| 16417 |
} |
| 16418 |
})(function($) { |
| 16419 |
'use strict'; |
| 16420 |
|
| 16421 |
var $scrollTo = $.scrollTo = function(target, duration, settings) { |
| 16422 |
return $(window).scrollTo(target, duration, settings); |
| 16423 |
}; |
| 16424 |
|
| 16425 |
$scrollTo.defaults = { |
| 16426 |
axis:'xy', |
| 16427 |
duration: 0, |
| 16428 |
limit:true |
| 16429 |
}; |
| 16430 |
|
| 16431 |
function isWin(elem) { |
| 16432 |
return !elem.nodeName || |
| 16433 |
$.inArray(elem.nodeName.toLowerCase(), ['iframe','#document','html','body']) !== -1; |
| 16434 |
} |
| 16435 |
|
| 16436 |
$.fn.scrollTo = function(target, duration, settings) { |
| 16437 |
if (typeof duration === 'object') { |
| 16438 |
settings = duration; |
| 16439 |
duration = 0; |
| 16440 |
} |
| 16441 |
if (typeof settings === 'function') { |
| 16442 |
settings = { onAfter:settings }; |
| 16443 |
} |
| 16444 |
if (target === 'max') { |
| 16445 |
target = 9e9; |
| 16446 |
} |
| 16447 |
|
| 16448 |
settings = $.extend({}, $scrollTo.defaults, settings); |
| 16449 |
// Speed is still recognized for backwards compatibility |
| 16450 |
duration = duration || settings.duration; |
| 16451 |
// Make sure the settings are given right |
| 16452 |
var queue = settings.queue && settings.axis.length > 1; |
| 16453 |
if (queue) { |
| 16454 |
// Let's keep the overall duration |
| 16455 |
duration /= 2; |
| 16456 |
} |
| 16457 |
settings.offset = both(settings.offset); |
| 16458 |
settings.over = both(settings.over); |
| 16459 |
|
| 16460 |
return this.each(function() { |
| 16461 |
// Null target yields nothing, just like jQuery does |
| 16462 |
if (target === null) return; |
| 16463 |
|
| 16464 |
var win = isWin(this), |
| 16465 |
elem = win ? this.contentWindow || window : this, |
| 16466 |
$elem = $(elem), |
| 16467 |
targ = target, |
| 16468 |
attr = {}, |
| 16469 |
toff; |
| 16470 |
|
| 16471 |
switch (typeof targ) { |
| 16472 |
// A number will pass the regex |
| 16473 |
case 'number': |
| 16474 |
case 'string': |
| 16475 |
if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)) { |
| 16476 |
targ = both(targ); |
| 16477 |
// We are done |
| 16478 |
break; |
| 16479 |
} |
| 16480 |
// Relative/Absolute selector |
| 16481 |
targ = win ? $(targ) : $(targ, elem); |
| 16482 |
/* falls through */ |
| 16483 |
case 'object': |
| 16484 |
if (targ.length === 0) return; |
| 16485 |
// DOMElement / jQuery |
| 16486 |
if (targ.is || targ.style) { |
| 16487 |
// Get the real position of the target |
| 16488 |
toff = (targ = $(targ)).offset(); |
| 16489 |
} |
| 16490 |
} |
| 16491 |
|
| 16492 |
var offset = $.isFunction(settings.offset) && settings.offset(elem, targ) || settings.offset; |
| 16493 |
|
| 16494 |
$.each(settings.axis.split(''), function(i, axis) { |
| 16495 |
var Pos = axis === 'x' ? 'Left' : 'Top', |
| 16496 |
pos = Pos.toLowerCase(), |
| 16497 |
key = 'scroll' + Pos, |
| 16498 |
prev = $elem[key](), |
| 16499 |
max = $scrollTo.max(elem, axis); |
| 16500 |
|
| 16501 |
if (toff) {// jQuery / DOMElement |
| 16502 |
attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()[pos]); |
| 16503 |
|
| 16504 |
// If it's a dom element, reduce the margin |
| 16505 |
if (settings.margin) { |
| 16506 |
attr[key] -= parseInt(targ.css('margin'+Pos), 10) || 0; |
| 16507 |
attr[key] -= parseInt(targ.css('border'+Pos+'Width'), 10) || 0; |
| 16508 |
} |
| 16509 |
|
| 16510 |
attr[key] += offset[pos] || 0; |
| 16511 |
|
| 16512 |
if (settings.over[pos]) { |
| 16513 |
// Scroll to a fraction of its width/height |
| 16514 |
attr[key] += targ[axis === 'x'?'width':'height']() * settings.over[pos]; |
| 16515 |
} |
| 16516 |
} else { |
| 16517 |
var val = targ[pos]; |
| 16518 |
// Handle percentage values |
| 16519 |
attr[key] = val.slice && val.slice(-1) === '%' ? |
| 16520 |
parseFloat(val) / 100 * max |
| 16521 |
: val; |
| 16522 |
} |
| 16523 |
|
| 16524 |
// Number or 'number' |
| 16525 |
if (settings.limit && /^\d+$/.test(attr[key])) { |
| 16526 |
// Check the limits |
| 16527 |
attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max); |
| 16528 |
} |
| 16529 |
|
| 16530 |
// Don't waste time animating, if there's no need. |
| 16531 |
if (!i && settings.axis.length > 1) { |
| 16532 |
if (prev === attr[key]) { |
| 16533 |
// No animation needed |
| 16534 |
attr = {}; |
| 16535 |
} else if (queue) { |
| 16536 |
// Intermediate animation |
| 16537 |
animate(settings.onAfterFirst); |
| 16538 |
// Don't animate this axis again in the next iteration. |
| 16539 |
attr = {}; |
| 16540 |
} |
| 16541 |
} |
| 16542 |
}); |
| 16543 |
|
| 16544 |
animate(settings.onAfter); |
| 16545 |
|
| 16546 |
function animate(callback) { |
| 16547 |
var opts = $.extend({}, settings, { |
| 16548 |
// The queue setting conflicts with animate() |
| 16549 |
// Force it to always be true |
| 16550 |
queue: true, |
| 16551 |
duration: duration, |
| 16552 |
complete: callback && function() { |
| 16553 |
callback.call(elem, targ, settings); |
| 16554 |
} |
| 16555 |
}); |
| 16556 |
$elem.animate(attr, opts); |
| 16557 |
} |
| 16558 |
}); |
| 16559 |
}; |
| 16560 |
|
| 16561 |
// Max scrolling position, works on quirks mode |
| 16562 |
// It only fails (not too badly) on IE, quirks mode. |
| 16563 |
$scrollTo.max = function(elem, axis) { |
| 16564 |
var Dim = axis === 'x' ? 'Width' : 'Height', |
| 16565 |
scroll = 'scroll'+Dim; |
| 16566 |
|
| 16567 |
if (!isWin(elem)) |
| 16568 |
return elem[scroll] - $(elem)[Dim.toLowerCase()](); |
| 16569 |
|
| 16570 |
var size = 'client' + Dim, |
| 16571 |
doc = elem.ownerDocument || elem.document, |
| 16572 |
html = doc.documentElement, |
| 16573 |
body = doc.body; |
| 16574 |
|
| 16575 |
return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]); |
| 16576 |
}; |
| 16577 |
|
| 16578 |
function both(val) { |
| 16579 |
return $.isFunction(val) || $.isPlainObject(val) ? val : { top:val, left:val }; |
| 16580 |
} |
| 16581 |
|
| 16582 |
// Add special hooks so that window scroll properties can be animated |
| 16583 |
$.Tween.propHooks.scrollLeft = |
| 16584 |
$.Tween.propHooks.scrollTop = { |
| 16585 |
get: function(t) { |
| 16586 |
return $(t.elem)[t.prop](); |
| 16587 |
}, |
| 16588 |
set: function(t) { |
| 16589 |
var curr = this.get(t); |
| 16590 |
// If interrupt is true and user scrolled, stop animating |
| 16591 |
if (t.options.interrupt && t._last && t._last !== curr) { |
| 16592 |
return $(t.elem).stop(); |
| 16593 |
} |
| 16594 |
var next = Math.round(t.now); |
| 16595 |
// Don't waste CPU |
| 16596 |
// Browsers don't render floating point scroll |
| 16597 |
if (curr !== next) { |
| 16598 |
$(t.elem)[t.prop](next); |
| 16599 |
t._last = this.get(t); |
| 16600 |
} |
| 16601 |
} |
| 16602 |
}; |
| 16603 |
|
| 16604 |
// AMD requirement |
| 16605 |
return $scrollTo; |
| 16606 |
}); |
| 16607 |
|
| 16608 |
/* assets/wpuf/vendor/selectize/js/standalone/selectize.js */ |
| 16609 |
/** |
| 16610 |
* sifter.js |
| 16611 |
* Copyright (c) 2013 Brian Reavis & contributors |
| 16612 |
* |
| 16613 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 16614 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 16615 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 16616 |
* |
| 16617 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 16618 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 16619 |
* ANY KIND, either express or implied. See the License for the specific language |
| 16620 |
* governing permissions and limitations under the License. |
| 16621 |
* |
| 16622 |
* @author Brian Reavis <brian@thirdroute.com> |
| 16623 |
*/ |
| 16624 |
|
| 16625 |
(function(root, factory) { |
| 16626 |
if (typeof define === 'function' && define.amd) { |
| 16627 |
define('sifter', factory); |
| 16628 |
} else if (typeof exports === 'object') { |
| 16629 |
module.exports = factory(); |
| 16630 |
} else { |
| 16631 |
root.Sifter = factory(); |
| 16632 |
} |
| 16633 |
}(this, function() { |
| 16634 |
|
| 16635 |
/** |
| 16636 |
* Textually searches arrays and hashes of objects |
| 16637 |
* by property (or multiple properties). Designed |
| 16638 |
* specifically for autocomplete. |
| 16639 |
* |
| 16640 |
* @constructor |
| 16641 |
* @param {array|object} items |
| 16642 |
* @param {object} items |
| 16643 |
*/ |
| 16644 |
var Sifter = function(items, settings) { |
| 16645 |
this.items = items; |
| 16646 |
this.settings = settings || {diacritics: true}; |
| 16647 |
}; |
| 16648 |
|
| 16649 |
/** |
| 16650 |
* Splits a search string into an array of individual |
| 16651 |
* regexps to be used to match results. |
| 16652 |
* |
| 16653 |
* @param {string} query |
| 16654 |
* @returns {array} |
| 16655 |
*/ |
| 16656 |
Sifter.prototype.tokenize = function(query) { |
| 16657 |
query = trim(String(query || '').toLowerCase()); |
| 16658 |
if (!query || !query.length) return []; |
| 16659 |
|
| 16660 |
var i, n, regex, letter; |
| 16661 |
var tokens = []; |
| 16662 |
var words = query.split(/ +/); |
| 16663 |
|
| 16664 |
for (i = 0, n = words.length; i < n; i++) { |
| 16665 |
regex = escape_regex(words[i]); |
| 16666 |
if (this.settings.diacritics) { |
| 16667 |
for (letter in DIACRITICS) { |
| 16668 |
if (DIACRITICS.hasOwnProperty(letter)) { |
| 16669 |
regex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]); |
| 16670 |
} |
| 16671 |
} |
| 16672 |
} |
| 16673 |
tokens.push({ |
| 16674 |
string : words[i], |
| 16675 |
regex : new RegExp(regex, 'i') |
| 16676 |
}); |
| 16677 |
} |
| 16678 |
|
| 16679 |
return tokens; |
| 16680 |
}; |
| 16681 |
|
| 16682 |
/** |
| 16683 |
* Iterates over arrays and hashes. |
| 16684 |
* |
| 16685 |
* ``` |
| 16686 |
* this.iterator(this.items, function(item, id) { |
| 16687 |
* // invoked for each item |
| 16688 |
* }); |
| 16689 |
* ``` |
| 16690 |
* |
| 16691 |
* @param {array|object} object |
| 16692 |
*/ |
| 16693 |
Sifter.prototype.iterator = function(object, callback) { |
| 16694 |
var iterator; |
| 16695 |
if (is_array(object)) { |
| 16696 |
iterator = Array.prototype.forEach || function(callback) { |
| 16697 |
for (var i = 0, n = this.length; i < n; i++) { |
| 16698 |
callback(this[i], i, this); |
| 16699 |
} |
| 16700 |
}; |
| 16701 |
} else { |
| 16702 |
iterator = function(callback) { |
| 16703 |
for (var key in this) { |
| 16704 |
if (this.hasOwnProperty(key)) { |
| 16705 |
callback(this[key], key, this); |
| 16706 |
} |
| 16707 |
} |
| 16708 |
}; |
| 16709 |
} |
| 16710 |
|
| 16711 |
iterator.apply(object, [callback]); |
| 16712 |
}; |
| 16713 |
|
| 16714 |
/** |
| 16715 |
* Returns a function to be used to score individual results. |
| 16716 |
* |
| 16717 |
* Good matches will have a higher score than poor matches. |
| 16718 |
* If an item is not a match, 0 will be returned by the function. |
| 16719 |
* |
| 16720 |
* @param {object|string} search |
| 16721 |
* @param {object} options (optional) |
| 16722 |
* @returns {function} |
| 16723 |
*/ |
| 16724 |
Sifter.prototype.getScoreFunction = function(search, options) { |
| 16725 |
var self, fields, tokens, token_count, nesting; |
| 16726 |
|
| 16727 |
self = this; |
| 16728 |
search = self.prepareSearch(search, options); |
| 16729 |
tokens = search.tokens; |
| 16730 |
fields = search.options.fields; |
| 16731 |
token_count = tokens.length; |
| 16732 |
nesting = search.options.nesting; |
| 16733 |
|
| 16734 |
/** |
| 16735 |
* Calculates how close of a match the |
| 16736 |
* given value is against a search token. |
| 16737 |
* |
| 16738 |
* @param {mixed} value |
| 16739 |
* @param {object} token |
| 16740 |
* @return {number} |
| 16741 |
*/ |
| 16742 |
var scoreValue = function(value, token) { |
| 16743 |
var score, pos; |
| 16744 |
|
| 16745 |
if (!value) return 0; |
| 16746 |
value = String(value || ''); |
| 16747 |
pos = value.search(token.regex); |
| 16748 |
if (pos === -1) return 0; |
| 16749 |
score = token.string.length / value.length; |
| 16750 |
if (pos === 0) score += 0.5; |
| 16751 |
return score; |
| 16752 |
}; |
| 16753 |
|
| 16754 |
/** |
| 16755 |
* Calculates the score of an object |
| 16756 |
* against the search query. |
| 16757 |
* |
| 16758 |
* @param {object} token |
| 16759 |
* @param {object} data |
| 16760 |
* @return {number} |
| 16761 |
*/ |
| 16762 |
var scoreObject = (function() { |
| 16763 |
var field_count = fields.length; |
| 16764 |
if (!field_count) { |
| 16765 |
return function() { return 0; }; |
| 16766 |
} |
| 16767 |
if (field_count === 1) { |
| 16768 |
return function(token, data) { |
| 16769 |
return scoreValue(getattr(data, fields[0], nesting), token); |
| 16770 |
}; |
| 16771 |
} |
| 16772 |
return function(token, data) { |
| 16773 |
for (var i = 0, sum = 0; i < field_count; i++) { |
| 16774 |
sum += scoreValue(getattr(data, fields[i], nesting), token); |
| 16775 |
} |
| 16776 |
return sum / field_count; |
| 16777 |
}; |
| 16778 |
})(); |
| 16779 |
|
| 16780 |
if (!token_count) { |
| 16781 |
return function() { return 0; }; |
| 16782 |
} |
| 16783 |
if (token_count === 1) { |
| 16784 |
return function(data) { |
| 16785 |
return scoreObject(tokens[0], data); |
| 16786 |
}; |
| 16787 |
} |
| 16788 |
|
| 16789 |
if (search.options.conjunction === 'and') { |
| 16790 |
return function(data) { |
| 16791 |
var score; |
| 16792 |
for (var i = 0, sum = 0; i < token_count; i++) { |
| 16793 |
score = scoreObject(tokens[i], data); |
| 16794 |
if (score <= 0) return 0; |
| 16795 |
sum += score; |
| 16796 |
} |
| 16797 |
return sum / token_count; |
| 16798 |
}; |
| 16799 |
} else { |
| 16800 |
return function(data) { |
| 16801 |
for (var i = 0, sum = 0; i < token_count; i++) { |
| 16802 |
sum += scoreObject(tokens[i], data); |
| 16803 |
} |
| 16804 |
return sum / token_count; |
| 16805 |
}; |
| 16806 |
} |
| 16807 |
}; |
| 16808 |
|
| 16809 |
/** |
| 16810 |
* Returns a function that can be used to compare two |
| 16811 |
* results, for sorting purposes. If no sorting should |
| 16812 |
* be performed, `null` will be returned. |
| 16813 |
* |
| 16814 |
* @param {string|object} search |
| 16815 |
* @param {object} options |
| 16816 |
* @return function(a,b) |
| 16817 |
*/ |
| 16818 |
Sifter.prototype.getSortFunction = function(search, options) { |
| 16819 |
var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort; |
| 16820 |
|
| 16821 |
self = this; |
| 16822 |
search = self.prepareSearch(search, options); |
| 16823 |
sort = (!search.query && options.sort_empty) || options.sort; |
| 16824 |
|
| 16825 |
/** |
| 16826 |
* Fetches the specified sort field value |
| 16827 |
* from a search result item. |
| 16828 |
* |
| 16829 |
* @param {string} name |
| 16830 |
* @param {object} result |
| 16831 |
* @return {mixed} |
| 16832 |
*/ |
| 16833 |
get_field = function(name, result) { |
| 16834 |
if (name === '$score') return result.score; |
| 16835 |
return getattr(self.items[result.id], name, options.nesting); |
| 16836 |
}; |
| 16837 |
|
| 16838 |
// parse options |
| 16839 |
fields = []; |
| 16840 |
if (sort) { |
| 16841 |
for (i = 0, n = sort.length; i < n; i++) { |
| 16842 |
if (search.query || sort[i].field !== '$score') { |
| 16843 |
fields.push(sort[i]); |
| 16844 |
} |
| 16845 |
} |
| 16846 |
} |
| 16847 |
|
| 16848 |
// the "$score" field is implied to be the primary |
| 16849 |
// sort field, unless it's manually specified |
| 16850 |
if (search.query) { |
| 16851 |
implicit_score = true; |
| 16852 |
for (i = 0, n = fields.length; i < n; i++) { |
| 16853 |
if (fields[i].field === '$score') { |
| 16854 |
implicit_score = false; |
| 16855 |
break; |
| 16856 |
} |
| 16857 |
} |
| 16858 |
if (implicit_score) { |
| 16859 |
fields.unshift({field: '$score', direction: 'desc'}); |
| 16860 |
} |
| 16861 |
} else { |
| 16862 |
for (i = 0, n = fields.length; i < n; i++) { |
| 16863 |
if (fields[i].field === '$score') { |
| 16864 |
fields.splice(i, 1); |
| 16865 |
break; |
| 16866 |
} |
| 16867 |
} |
| 16868 |
} |
| 16869 |
|
| 16870 |
multipliers = []; |
| 16871 |
for (i = 0, n = fields.length; i < n; i++) { |
| 16872 |
multipliers.push(fields[i].direction === 'desc' ? -1 : 1); |
| 16873 |
} |
| 16874 |
|
| 16875 |
// build function |
| 16876 |
fields_count = fields.length; |
| 16877 |
if (!fields_count) { |
| 16878 |
return null; |
| 16879 |
} else if (fields_count === 1) { |
| 16880 |
field = fields[0].field; |
| 16881 |
multiplier = multipliers[0]; |
| 16882 |
return function(a, b) { |
| 16883 |
return multiplier * cmp( |
| 16884 |
get_field(field, a), |
| 16885 |
get_field(field, b) |
| 16886 |
); |
| 16887 |
}; |
| 16888 |
} else { |
| 16889 |
return function(a, b) { |
| 16890 |
var i, result, a_value, b_value, field; |
| 16891 |
for (i = 0; i < fields_count; i++) { |
| 16892 |
field = fields[i].field; |
| 16893 |
result = multipliers[i] * cmp( |
| 16894 |
get_field(field, a), |
| 16895 |
get_field(field, b) |
| 16896 |
); |
| 16897 |
if (result) return result; |
| 16898 |
} |
| 16899 |
return 0; |
| 16900 |
}; |
| 16901 |
} |
| 16902 |
}; |
| 16903 |
|
| 16904 |
/** |
| 16905 |
* Parses a search query and returns an object |
| 16906 |
* with tokens and fields ready to be populated |
| 16907 |
* with results. |
| 16908 |
* |
| 16909 |
* @param {string} query |
| 16910 |
* @param {object} options |
| 16911 |
* @returns {object} |
| 16912 |
*/ |
| 16913 |
Sifter.prototype.prepareSearch = function(query, options) { |
| 16914 |
if (typeof query === 'object') return query; |
| 16915 |
|
| 16916 |
options = extend({}, options); |
| 16917 |
|
| 16918 |
var option_fields = options.fields; |
| 16919 |
var option_sort = options.sort; |
| 16920 |
var option_sort_empty = options.sort_empty; |
| 16921 |
|
| 16922 |
if (option_fields && !is_array(option_fields)) options.fields = [option_fields]; |
| 16923 |
if (option_sort && !is_array(option_sort)) options.sort = [option_sort]; |
| 16924 |
if (option_sort_empty && !is_array(option_sort_empty)) options.sort_empty = [option_sort_empty]; |
| 16925 |
|
| 16926 |
return { |
| 16927 |
options : options, |
| 16928 |
query : String(query || '').toLowerCase(), |
| 16929 |
tokens : this.tokenize(query), |
| 16930 |
total : 0, |
| 16931 |
items : [] |
| 16932 |
}; |
| 16933 |
}; |
| 16934 |
|
| 16935 |
/** |
| 16936 |
* Searches through all items and returns a sorted array of matches. |
| 16937 |
* |
| 16938 |
* The `options` parameter can contain: |
| 16939 |
* |
| 16940 |
* - fields {string|array} |
| 16941 |
* - sort {array} |
| 16942 |
* - score {function} |
| 16943 |
* - filter {bool} |
| 16944 |
* - limit {integer} |
| 16945 |
* |
| 16946 |
* Returns an object containing: |
| 16947 |
* |
| 16948 |
* - options {object} |
| 16949 |
* - query {string} |
| 16950 |
* - tokens {array} |
| 16951 |
* - total {int} |
| 16952 |
* - items {array} |
| 16953 |
* |
| 16954 |
* @param {string} query |
| 16955 |
* @param {object} options |
| 16956 |
* @returns {object} |
| 16957 |
*/ |
| 16958 |
Sifter.prototype.search = function(query, options) { |
| 16959 |
var self = this, value, score, search, calculateScore; |
| 16960 |
var fn_sort; |
| 16961 |
var fn_score; |
| 16962 |
|
| 16963 |
search = this.prepareSearch(query, options); |
| 16964 |
options = search.options; |
| 16965 |
query = search.query; |
| 16966 |
|
| 16967 |
// generate result scoring function |
| 16968 |
fn_score = options.score || self.getScoreFunction(search); |
| 16969 |
|
| 16970 |
// perform search and sort |
| 16971 |
if (query.length) { |
| 16972 |
self.iterator(self.items, function(item, id) { |
| 16973 |
score = fn_score(item); |
| 16974 |
if (options.filter === false || score > 0) { |
| 16975 |
search.items.push({'score': score, 'id': id}); |
| 16976 |
} |
| 16977 |
}); |
| 16978 |
} else { |
| 16979 |
self.iterator(self.items, function(item, id) { |
| 16980 |
search.items.push({'score': 1, 'id': id}); |
| 16981 |
}); |
| 16982 |
} |
| 16983 |
|
| 16984 |
fn_sort = self.getSortFunction(search, options); |
| 16985 |
if (fn_sort) search.items.sort(fn_sort); |
| 16986 |
|
| 16987 |
// apply limits |
| 16988 |
search.total = search.items.length; |
| 16989 |
if (typeof options.limit === 'number') { |
| 16990 |
search.items = search.items.slice(0, options.limit); |
| 16991 |
} |
| 16992 |
|
| 16993 |
return search; |
| 16994 |
}; |
| 16995 |
|
| 16996 |
// utilities |
| 16997 |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 16998 |
|
| 16999 |
var cmp = function(a, b) { |
| 17000 |
if (typeof a === 'number' && typeof b === 'number') { |
| 17001 |
return a > b ? 1 : (a < b ? -1 : 0); |
| 17002 |
} |
| 17003 |
a = asciifold(String(a || '')); |
| 17004 |
b = asciifold(String(b || '')); |
| 17005 |
if (a > b) return 1; |
| 17006 |
if (b > a) return -1; |
| 17007 |
return 0; |
| 17008 |
}; |
| 17009 |
|
| 17010 |
var extend = function(a, b) { |
| 17011 |
var i, n, k, object; |
| 17012 |
for (i = 1, n = arguments.length; i < n; i++) { |
| 17013 |
object = arguments[i]; |
| 17014 |
if (!object) continue; |
| 17015 |
for (k in object) { |
| 17016 |
if (object.hasOwnProperty(k)) { |
| 17017 |
a[k] = object[k]; |
| 17018 |
} |
| 17019 |
} |
| 17020 |
} |
| 17021 |
return a; |
| 17022 |
}; |
| 17023 |
|
| 17024 |
/** |
| 17025 |
* A property getter resolving dot-notation |
| 17026 |
* @param {Object} obj The root object to fetch property on |
| 17027 |
* @param {String} name The optionally dotted property name to fetch |
| 17028 |
* @param {Boolean} nesting Handle nesting or not |
| 17029 |
* @return {Object} The resolved property value |
| 17030 |
*/ |
| 17031 |
var getattr = function(obj, name, nesting) { |
| 17032 |
if (!obj || !name) return; |
| 17033 |
if (!nesting) return obj[name]; |
| 17034 |
var names = name.split("."); |
| 17035 |
while(names.length && (obj = obj[names.shift()])); |
| 17036 |
return obj; |
| 17037 |
}; |
| 17038 |
|
| 17039 |
var trim = function(str) { |
| 17040 |
return (str + '').replace(/^\s+|\s+$|/g, ''); |
| 17041 |
}; |
| 17042 |
|
| 17043 |
var escape_regex = function(str) { |
| 17044 |
return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); |
| 17045 |
}; |
| 17046 |
|
| 17047 |
var is_array = Array.isArray || (typeof $ !== 'undefined' && $.isArray) || function(object) { |
| 17048 |
return Object.prototype.toString.call(object) === '[object Array]'; |
| 17049 |
}; |
| 17050 |
|
| 17051 |
var DIACRITICS = { |
| 17052 |
'a': '[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]', |
| 17053 |
'b': '[b␢βΒB฿𐌁ᛒ]', |
| 17054 |
'c': '[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]', |
| 17055 |
'd': '[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]', |
| 17056 |
'e': '[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]', |
| 17057 |
'f': '[fƑƒḞḟ]', |
| 17058 |
'g': '[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]', |
| 17059 |
'h': '[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]', |
| 17060 |
'i': '[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]', |
| 17061 |
'j': '[jȷĴĵɈɉʝɟʲ]', |
| 17062 |
'k': '[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]', |
| 17063 |
'l': '[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]', |
| 17064 |
'n': '[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]', |
| 17065 |
'o': '[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]', |
| 17066 |
'p': '[pṔṕṖṗⱣᵽƤƥᵱ]', |
| 17067 |
'q': '[qꝖꝗʠɊɋꝘꝙq̃]', |
| 17068 |
'r': '[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]', |
| 17069 |
's': '[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]', |
| 17070 |
't': '[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]', |
| 17071 |
'u': '[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]', |
| 17072 |
'v': '[vṼṽṾṿƲʋꝞꝟⱱʋ]', |
| 17073 |
'w': '[wẂẃẀẁŴŵẄẅẆẇẈẉ]', |
| 17074 |
'x': '[xẌẍẊẋχ]', |
| 17075 |
'y': '[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]', |
| 17076 |
'z': '[zŹźẐẑŽžŻżẒẓẔẕƵƶ]' |
| 17077 |
}; |
| 17078 |
|
| 17079 |
var asciifold = (function() { |
| 17080 |
var i, n, k, chunk; |
| 17081 |
var foreignletters = ''; |
| 17082 |
var lookup = {}; |
| 17083 |
for (k in DIACRITICS) { |
| 17084 |
if (DIACRITICS.hasOwnProperty(k)) { |
| 17085 |
chunk = DIACRITICS[k].substring(2, DIACRITICS[k].length - 1); |
| 17086 |
foreignletters += chunk; |
| 17087 |
for (i = 0, n = chunk.length; i < n; i++) { |
| 17088 |
lookup[chunk.charAt(i)] = k; |
| 17089 |
} |
| 17090 |
} |
| 17091 |
} |
| 17092 |
var regexp = new RegExp('[' + foreignletters + ']', 'g'); |
| 17093 |
return function(str) { |
| 17094 |
return str.replace(regexp, function(foreignletter) { |
| 17095 |
return lookup[foreignletter]; |
| 17096 |
}).toLowerCase(); |
| 17097 |
}; |
| 17098 |
})(); |
| 17099 |
|
| 17100 |
|
| 17101 |
// export |
| 17102 |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 17103 |
|
| 17104 |
return Sifter; |
| 17105 |
})); |
| 17106 |
|
| 17107 |
|
| 17108 |
|
| 17109 |
/** |
| 17110 |
* microplugin.js |
| 17111 |
* Copyright (c) 2013 Brian Reavis & contributors |
| 17112 |
* |
| 17113 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 17114 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 17115 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 17116 |
* |
| 17117 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 17118 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 17119 |
* ANY KIND, either express or implied. See the License for the specific language |
| 17120 |
* governing permissions and limitations under the License. |
| 17121 |
* |
| 17122 |
* @author Brian Reavis <brian@thirdroute.com> |
| 17123 |
*/ |
| 17124 |
|
| 17125 |
(function(root, factory) { |
| 17126 |
if (typeof define === 'function' && define.amd) { |
| 17127 |
define('microplugin', factory); |
| 17128 |
} else if (typeof exports === 'object') { |
| 17129 |
module.exports = factory(); |
| 17130 |
} else { |
| 17131 |
root.MicroPlugin = factory(); |
| 17132 |
} |
| 17133 |
}(this, function() { |
| 17134 |
var MicroPlugin = {}; |
| 17135 |
|
| 17136 |
MicroPlugin.mixin = function(Interface) { |
| 17137 |
Interface.plugins = {}; |
| 17138 |
|
| 17139 |
/** |
| 17140 |
* Initializes the listed plugins (with options). |
| 17141 |
* Acceptable formats: |
| 17142 |
* |
| 17143 |
* List (without options): |
| 17144 |
* ['a', 'b', 'c'] |
| 17145 |
* |
| 17146 |
* List (with options): |
| 17147 |
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}] |
| 17148 |
* |
| 17149 |
* Hash (with options): |
| 17150 |
* {'a': { ... }, 'b': { ... }, 'c': { ... }} |
| 17151 |
* |
| 17152 |
* @param {mixed} plugins |
| 17153 |
*/ |
| 17154 |
Interface.prototype.initializePlugins = function(plugins) { |
| 17155 |
var i, n, key; |
| 17156 |
var self = this; |
| 17157 |
var queue = []; |
| 17158 |
|
| 17159 |
self.plugins = { |
| 17160 |
names : [], |
| 17161 |
settings : {}, |
| 17162 |
requested : {}, |
| 17163 |
loaded : {} |
| 17164 |
}; |
| 17165 |
|
| 17166 |
if (utils.isArray(plugins)) { |
| 17167 |
for (i = 0, n = plugins.length; i < n; i++) { |
| 17168 |
if (typeof plugins[i] === 'string') { |
| 17169 |
queue.push(plugins[i]); |
| 17170 |
} else { |
| 17171 |
self.plugins.settings[plugins[i].name] = plugins[i].options; |
| 17172 |
queue.push(plugins[i].name); |
| 17173 |
} |
| 17174 |
} |
| 17175 |
} else if (plugins) { |
| 17176 |
for (key in plugins) { |
| 17177 |
if (plugins.hasOwnProperty(key)) { |
| 17178 |
self.plugins.settings[key] = plugins[key]; |
| 17179 |
queue.push(key); |
| 17180 |
} |
| 17181 |
} |
| 17182 |
} |
| 17183 |
|
| 17184 |
while (queue.length) { |
| 17185 |
self.require(queue.shift()); |
| 17186 |
} |
| 17187 |
}; |
| 17188 |
|
| 17189 |
Interface.prototype.loadPlugin = function(name) { |
| 17190 |
var self = this; |
| 17191 |
var plugins = self.plugins; |
| 17192 |
var plugin = Interface.plugins[name]; |
| 17193 |
|
| 17194 |
if (!Interface.plugins.hasOwnProperty(name)) { |
| 17195 |
throw new Error('Unable to find "' + name + '" plugin'); |
| 17196 |
} |
| 17197 |
|
| 17198 |
plugins.requested[name] = true; |
| 17199 |
plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]); |
| 17200 |
plugins.names.push(name); |
| 17201 |
}; |
| 17202 |
|
| 17203 |
/** |
| 17204 |
* Initializes a plugin. |
| 17205 |
* |
| 17206 |
* @param {string} name |
| 17207 |
*/ |
| 17208 |
Interface.prototype.require = function(name) { |
| 17209 |
var self = this; |
| 17210 |
var plugins = self.plugins; |
| 17211 |
|
| 17212 |
if (!self.plugins.loaded.hasOwnProperty(name)) { |
| 17213 |
if (plugins.requested[name]) { |
| 17214 |
throw new Error('Plugin has circular dependency ("' + name + '")'); |
| 17215 |
} |
| 17216 |
self.loadPlugin(name); |
| 17217 |
} |
| 17218 |
|
| 17219 |
return plugins.loaded[name]; |
| 17220 |
}; |
| 17221 |
|
| 17222 |
/** |
| 17223 |
* Registers a plugin. |
| 17224 |
* |
| 17225 |
* @param {string} name |
| 17226 |
* @param {function} fn |
| 17227 |
*/ |
| 17228 |
Interface.define = function(name, fn) { |
| 17229 |
Interface.plugins[name] = { |
| 17230 |
'name' : name, |
| 17231 |
'fn' : fn |
| 17232 |
}; |
| 17233 |
}; |
| 17234 |
}; |
| 17235 |
|
| 17236 |
var utils = { |
| 17237 |
isArray: Array.isArray || function(vArg) { |
| 17238 |
return Object.prototype.toString.call(vArg) === '[object Array]'; |
| 17239 |
} |
| 17240 |
}; |
| 17241 |
|
| 17242 |
return MicroPlugin; |
| 17243 |
})); |
| 17244 |
|
| 17245 |
/** |
| 17246 |
* selectize.js (v0.12.4) |
| 17247 |
* Copyright (c) 2013–2015 Brian Reavis & contributors |
| 17248 |
* |
| 17249 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 17250 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 17251 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 17252 |
* |
| 17253 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 17254 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 17255 |
* ANY KIND, either express or implied. See the License for the specific language |
| 17256 |
* governing permissions and limitations under the License. |
| 17257 |
* |
| 17258 |
* @author Brian Reavis <brian@thirdroute.com> |
| 17259 |
*/ |
| 17260 |
|
| 17261 |
/*jshint curly:false */ |
| 17262 |
/*jshint browser:true */ |
| 17263 |
|
| 17264 |
(function(root, factory) { |
| 17265 |
if (typeof define === 'function' && define.amd) { |
| 17266 |
define('selectize', ['jquery','sifter','microplugin'], factory); |
| 17267 |
} else if (typeof exports === 'object') { |
| 17268 |
module.exports = factory(require('jquery'), require('sifter'), require('microplugin')); |
| 17269 |
} else { |
| 17270 |
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin); |
| 17271 |
} |
| 17272 |
}(this, function($, Sifter, MicroPlugin) { |
| 17273 |
'use strict'; |
| 17274 |
|
| 17275 |
var highlight = function($element, pattern) { |
| 17276 |
if (typeof pattern === 'string' && !pattern.length) return; |
| 17277 |
var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern; |
| 17278 |
|
| 17279 |
var highlight = function(node) { |
| 17280 |
var skip = 0; |
| 17281 |
if (node.nodeType === 3) { |
| 17282 |
var pos = node.data.search(regex); |
| 17283 |
if (pos >= 0 && node.data.length > 0) { |
| 17284 |
var match = node.data.match(regex); |
| 17285 |
var spannode = document.createElement('span'); |
| 17286 |
spannode.className = 'highlight'; |
| 17287 |
var middlebit = node.splitText(pos); |
| 17288 |
var endbit = middlebit.splitText(match[0].length); |
| 17289 |
var middleclone = middlebit.cloneNode(true); |
| 17290 |
spannode.appendChild(middleclone); |
| 17291 |
middlebit.parentNode.replaceChild(spannode, middlebit); |
| 17292 |
skip = 1; |
| 17293 |
} |
| 17294 |
} else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { |
| 17295 |
for (var i = 0; i < node.childNodes.length; ++i) { |
| 17296 |
i += highlight(node.childNodes[i]); |
| 17297 |
} |
| 17298 |
} |
| 17299 |
return skip; |
| 17300 |
}; |
| 17301 |
|
| 17302 |
return $element.each(function() { |
| 17303 |
highlight(this); |
| 17304 |
}); |
| 17305 |
}; |
| 17306 |
|
| 17307 |
/** |
| 17308 |
* removeHighlight fn copied from highlight v5 and |
| 17309 |
* edited to remove with() and pass js strict mode |
| 17310 |
*/ |
| 17311 |
$.fn.removeHighlight = function() { |
| 17312 |
return this.find("span.highlight").each(function() { |
| 17313 |
this.parentNode.firstChild.nodeName; |
| 17314 |
var parent = this.parentNode; |
| 17315 |
parent.replaceChild(this.firstChild, this); |
| 17316 |
parent.normalize(); |
| 17317 |
}).end(); |
| 17318 |
}; |
| 17319 |
|
| 17320 |
|
| 17321 |
var MicroEvent = function() {}; |
| 17322 |
MicroEvent.prototype = { |
| 17323 |
on: function(event, fct){ |
| 17324 |
this._events = this._events || {}; |
| 17325 |
this._events[event] = this._events[event] || []; |
| 17326 |
this._events[event].push(fct); |
| 17327 |
}, |
| 17328 |
off: function(event, fct){ |
| 17329 |
var n = arguments.length; |
| 17330 |
if (n === 0) return delete this._events; |
| 17331 |
if (n === 1) return delete this._events[event]; |
| 17332 |
|
| 17333 |
this._events = this._events || {}; |
| 17334 |
if (event in this._events === false) return; |
| 17335 |
this._events[event].splice(this._events[event].indexOf(fct), 1); |
| 17336 |
}, |
| 17337 |
trigger: function(event /* , args... */){ |
| 17338 |
this._events = this._events || {}; |
| 17339 |
if (event in this._events === false) return; |
| 17340 |
for (var i = 0; i < this._events[event].length; i++){ |
| 17341 |
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1)); |
| 17342 |
} |
| 17343 |
} |
| 17344 |
}; |
| 17345 |
|
| 17346 |
/** |
| 17347 |
* Mixin will delegate all MicroEvent.js function in the destination object. |
| 17348 |
* |
| 17349 |
* - MicroEvent.mixin(Foobar) will make Foobar able to use MicroEvent |
| 17350 |
* |
| 17351 |
* @param {object} the object which will support MicroEvent |
| 17352 |
*/ |
| 17353 |
MicroEvent.mixin = function(destObject){ |
| 17354 |
var props = ['on', 'off', 'trigger']; |
| 17355 |
for (var i = 0; i < props.length; i++){ |
| 17356 |
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]]; |
| 17357 |
} |
| 17358 |
}; |
| 17359 |
|
| 17360 |
var IS_MAC = /Mac/.test(navigator.userAgent); |
| 17361 |
|
| 17362 |
var KEY_A = 65; |
| 17363 |
var KEY_COMMA = 188; |
| 17364 |
var KEY_RETURN = 13; |
| 17365 |
var KEY_ESC = 27; |
| 17366 |
var KEY_LEFT = 37; |
| 17367 |
var KEY_UP = 38; |
| 17368 |
var KEY_P = 80; |
| 17369 |
var KEY_RIGHT = 39; |
| 17370 |
var KEY_DOWN = 40; |
| 17371 |
var KEY_N = 78; |
| 17372 |
var KEY_BACKSPACE = 8; |
| 17373 |
var KEY_DELETE = 46; |
| 17374 |
var KEY_SHIFT = 16; |
| 17375 |
var KEY_CMD = IS_MAC ? 91 : 17; |
| 17376 |
var KEY_CTRL = IS_MAC ? 18 : 17; |
| 17377 |
var KEY_TAB = 9; |
| 17378 |
|
| 17379 |
var TAG_SELECT = 1; |
| 17380 |
var TAG_INPUT = 2; |
| 17381 |
|
| 17382 |
// for now, android support in general is too spotty to support validity |
| 17383 |
var SUPPORTS_VALIDITY_API = !/android/i.test(window.navigator.userAgent) && !!document.createElement('input').validity; |
| 17384 |
|
| 17385 |
|
| 17386 |
var isset = function(object) { |
| 17387 |
return typeof object !== 'undefined'; |
| 17388 |
}; |
| 17389 |
|
| 17390 |
/** |
| 17391 |
* Converts a scalar to its best string representation |
| 17392 |
* for hash keys and HTML attribute values. |
| 17393 |
* |
| 17394 |
* Transformations: |
| 17395 |
* 'str' -> 'str' |
| 17396 |
* null -> '' |
| 17397 |
* undefined -> '' |
| 17398 |
* true -> '1' |
| 17399 |
* false -> '0' |
| 17400 |
* 0 -> '0' |
| 17401 |
* 1 -> '1' |
| 17402 |
* |
| 17403 |
* @param {string} value |
| 17404 |
* @returns {string|null} |
| 17405 |
*/ |
| 17406 |
var hash_key = function(value) { |
| 17407 |
if (typeof value === 'undefined' || value === null) return null; |
| 17408 |
if (typeof value === 'boolean') return value ? '1' : '0'; |
| 17409 |
return value + ''; |
| 17410 |
}; |
| 17411 |
|
| 17412 |
/** |
| 17413 |
* Escapes a string for use within HTML. |
| 17414 |
* |
| 17415 |
* @param {string} str |
| 17416 |
* @returns {string} |
| 17417 |
*/ |
| 17418 |
var escape_html = function(str) { |
| 17419 |
return (str + '') |
| 17420 |
.replace(/&/g, '&') |
| 17421 |
.replace(/</g, '<') |
| 17422 |
.replace(/>/g, '>') |
| 17423 |
.replace(/"/g, '"'); |
| 17424 |
}; |
| 17425 |
|
| 17426 |
/** |
| 17427 |
* Escapes "$" characters in replacement strings. |
| 17428 |
* |
| 17429 |
* @param {string} str |
| 17430 |
* @returns {string} |
| 17431 |
*/ |
| 17432 |
var escape_replace = function(str) { |
| 17433 |
return (str + '').replace(/\$/g, '$$$$'); |
| 17434 |
}; |
| 17435 |
|
| 17436 |
var hook = {}; |
| 17437 |
|
| 17438 |
/** |
| 17439 |
* Wraps `method` on `self` so that `fn` |
| 17440 |
* is invoked before the original method. |
| 17441 |
* |
| 17442 |
* @param {object} self |
| 17443 |
* @param {string} method |
| 17444 |
* @param {function} fn |
| 17445 |
*/ |
| 17446 |
hook.before = function(self, method, fn) { |
| 17447 |
var original = self[method]; |
| 17448 |
self[method] = function() { |
| 17449 |
fn.apply(self, arguments); |
| 17450 |
return original.apply(self, arguments); |
| 17451 |
}; |
| 17452 |
}; |
| 17453 |
|
| 17454 |
/** |
| 17455 |
* Wraps `method` on `self` so that `fn` |
| 17456 |
* is invoked after the original method. |
| 17457 |
* |
| 17458 |
* @param {object} self |
| 17459 |
* @param {string} method |
| 17460 |
* @param {function} fn |
| 17461 |
*/ |
| 17462 |
hook.after = function(self, method, fn) { |
| 17463 |
var original = self[method]; |
| 17464 |
self[method] = function() { |
| 17465 |
var result = original.apply(self, arguments); |
| 17466 |
fn.apply(self, arguments); |
| 17467 |
return result; |
| 17468 |
}; |
| 17469 |
}; |
| 17470 |
|
| 17471 |
/** |
| 17472 |
* Wraps `fn` so that it can only be invoked once. |
| 17473 |
* |
| 17474 |
* @param {function} fn |
| 17475 |
* @returns {function} |
| 17476 |
*/ |
| 17477 |
var once = function(fn) { |
| 17478 |
var called = false; |
| 17479 |
return function() { |
| 17480 |
if (called) return; |
| 17481 |
called = true; |
| 17482 |
fn.apply(this, arguments); |
| 17483 |
}; |
| 17484 |
}; |
| 17485 |
|
| 17486 |
/** |
| 17487 |
* Wraps `fn` so that it can only be called once |
| 17488 |
* every `delay` milliseconds (invoked on the falling edge). |
| 17489 |
* |
| 17490 |
* @param {function} fn |
| 17491 |
* @param {int} delay |
| 17492 |
* @returns {function} |
| 17493 |
*/ |
| 17494 |
var debounce = function(fn, delay) { |
| 17495 |
var timeout; |
| 17496 |
return function() { |
| 17497 |
var self = this; |
| 17498 |
var args = arguments; |
| 17499 |
window.clearTimeout(timeout); |
| 17500 |
timeout = window.setTimeout(function() { |
| 17501 |
fn.apply(self, args); |
| 17502 |
}, delay); |
| 17503 |
}; |
| 17504 |
}; |
| 17505 |
|
| 17506 |
/** |
| 17507 |
* Debounce all fired events types listed in `types` |
| 17508 |
* while executing the provided `fn`. |
| 17509 |
* |
| 17510 |
* @param {object} self |
| 17511 |
* @param {array} types |
| 17512 |
* @param {function} fn |
| 17513 |
*/ |
| 17514 |
var debounce_events = function(self, types, fn) { |
| 17515 |
var type; |
| 17516 |
var trigger = self.trigger; |
| 17517 |
var event_args = {}; |
| 17518 |
|
| 17519 |
// override trigger method |
| 17520 |
self.trigger = function() { |
| 17521 |
var type = arguments[0]; |
| 17522 |
if (types.indexOf(type) !== -1) { |
| 17523 |
event_args[type] = arguments; |
| 17524 |
} else { |
| 17525 |
return trigger.apply(self, arguments); |
| 17526 |
} |
| 17527 |
}; |
| 17528 |
|
| 17529 |
// invoke provided function |
| 17530 |
fn.apply(self, []); |
| 17531 |
self.trigger = trigger; |
| 17532 |
|
| 17533 |
// trigger queued events |
| 17534 |
for (type in event_args) { |
| 17535 |
if (event_args.hasOwnProperty(type)) { |
| 17536 |
trigger.apply(self, event_args[type]); |
| 17537 |
} |
| 17538 |
} |
| 17539 |
}; |
| 17540 |
|
| 17541 |
/** |
| 17542 |
* A workaround for http://bugs.jquery.com/ticket/6696 |
| 17543 |
* |
| 17544 |
* @param {object} $parent - Parent element to listen on. |
| 17545 |
* @param {string} event - Event name. |
| 17546 |
* @param {string} selector - Descendant selector to filter by. |
| 17547 |
* @param {function} fn - Event handler. |
| 17548 |
*/ |
| 17549 |
var watchChildEvent = function($parent, event, selector, fn) { |
| 17550 |
$parent.on(event, selector, function(e) { |
| 17551 |
var child = e.target; |
| 17552 |
while (child && child.parentNode !== $parent[0]) { |
| 17553 |
child = child.parentNode; |
| 17554 |
} |
| 17555 |
e.currentTarget = child; |
| 17556 |
return fn.apply(this, [e]); |
| 17557 |
}); |
| 17558 |
}; |
| 17559 |
|
| 17560 |
/** |
| 17561 |
* Determines the current selection within a text input control. |
| 17562 |
* Returns an object containing: |
| 17563 |
* - start |
| 17564 |
* - length |
| 17565 |
* |
| 17566 |
* @param {object} input |
| 17567 |
* @returns {object} |
| 17568 |
*/ |
| 17569 |
var getSelection = function(input) { |
| 17570 |
var result = {}; |
| 17571 |
if ('selectionStart' in input) { |
| 17572 |
result.start = input.selectionStart; |
| 17573 |
result.length = input.selectionEnd - result.start; |
| 17574 |
} else if (document.selection) { |
| 17575 |
input.focus(); |
| 17576 |
var sel = document.selection.createRange(); |
| 17577 |
var selLen = document.selection.createRange().text.length; |
| 17578 |
sel.moveStart('character', -input.value.length); |
| 17579 |
result.start = sel.text.length - selLen; |
| 17580 |
result.length = selLen; |
| 17581 |
} |
| 17582 |
return result; |
| 17583 |
}; |
| 17584 |
|
| 17585 |
/** |
| 17586 |
* Copies CSS properties from one element to another. |
| 17587 |
* |
| 17588 |
* @param {object} $from |
| 17589 |
* @param {object} $to |
| 17590 |
* @param {array} properties |
| 17591 |
*/ |
| 17592 |
var transferStyles = function($from, $to, properties) { |
| 17593 |
var i, n, styles = {}; |
| 17594 |
if (properties) { |
| 17595 |
for (i = 0, n = properties.length; i < n; i++) { |
| 17596 |
styles[properties[i]] = $from.css(properties[i]); |
| 17597 |
} |
| 17598 |
} else { |
| 17599 |
styles = $from.css(); |
| 17600 |
} |
| 17601 |
$to.css(styles); |
| 17602 |
}; |
| 17603 |
|
| 17604 |
/** |
| 17605 |
* Measures the width of a string within a |
| 17606 |
* parent element (in pixels). |
| 17607 |
* |
| 17608 |
* @param {string} str |
| 17609 |
* @param {object} $parent |
| 17610 |
* @returns {int} |
| 17611 |
*/ |
| 17612 |
var measureString = function(str, $parent) { |
| 17613 |
if (!str) { |
| 17614 |
return 0; |
| 17615 |
} |
| 17616 |
|
| 17617 |
var $test = $('<test>').css({ |
| 17618 |
position: 'absolute', |
| 17619 |
top: -99999, |
| 17620 |
left: -99999, |
| 17621 |
width: 'auto', |
| 17622 |
padding: 0, |
| 17623 |
whiteSpace: 'pre' |
| 17624 |
}).text(str).appendTo('body'); |
| 17625 |
|
| 17626 |
transferStyles($parent, $test, [ |
| 17627 |
'letterSpacing', |
| 17628 |
'fontSize', |
| 17629 |
'fontFamily', |
| 17630 |
'fontWeight', |
| 17631 |
'textTransform' |
| 17632 |
]); |
| 17633 |
|
| 17634 |
var width = $test.width(); |
| 17635 |
$test.remove(); |
| 17636 |
|
| 17637 |
return width; |
| 17638 |
}; |
| 17639 |
|
| 17640 |
/** |
| 17641 |
* Sets up an input to grow horizontally as the user |
| 17642 |
* types. If the value is changed manually, you can |
| 17643 |
* trigger the "update" handler to resize: |
| 17644 |
* |
| 17645 |
* $input.trigger('update'); |
| 17646 |
* |
| 17647 |
* @param {object} $input |
| 17648 |
*/ |
| 17649 |
var autoGrow = function($input) { |
| 17650 |
var currentWidth = null; |
| 17651 |
|
| 17652 |
var update = function(e, options) { |
| 17653 |
var value, keyCode, printable, placeholder, width; |
| 17654 |
var shift, character, selection; |
| 17655 |
e = e || window.event || {}; |
| 17656 |
options = options || {}; |
| 17657 |
|
| 17658 |
if (e.metaKey || e.altKey) return; |
| 17659 |
if (!options.force && $input.data('grow') === false) return; |
| 17660 |
|
| 17661 |
value = $input.val(); |
| 17662 |
if (e.type && e.type.toLowerCase() === 'keydown') { |
| 17663 |
keyCode = e.keyCode; |
| 17664 |
printable = ( |
| 17665 |
(keyCode >= 97 && keyCode <= 122) || // a-z |
| 17666 |
(keyCode >= 65 && keyCode <= 90) || // A-Z |
| 17667 |
(keyCode >= 48 && keyCode <= 57) || // 0-9 |
| 17668 |
keyCode === 32 // space |
| 17669 |
); |
| 17670 |
|
| 17671 |
if (keyCode === KEY_DELETE || keyCode === KEY_BACKSPACE) { |
| 17672 |
selection = getSelection($input[0]); |
| 17673 |
if (selection.length) { |
| 17674 |
value = value.substring(0, selection.start) + value.substring(selection.start + selection.length); |
| 17675 |
} else if (keyCode === KEY_BACKSPACE && selection.start) { |
| 17676 |
value = value.substring(0, selection.start - 1) + value.substring(selection.start + 1); |
| 17677 |
} else if (keyCode === KEY_DELETE && typeof selection.start !== 'undefined') { |
| 17678 |
value = value.substring(0, selection.start) + value.substring(selection.start + 1); |
| 17679 |
} |
| 17680 |
} else if (printable) { |
| 17681 |
shift = e.shiftKey; |
| 17682 |
character = String.fromCharCode(e.keyCode); |
| 17683 |
if (shift) character = character.toUpperCase(); |
| 17684 |
else character = character.toLowerCase(); |
| 17685 |
value += character; |
| 17686 |
} |
| 17687 |
} |
| 17688 |
|
| 17689 |
placeholder = $input.attr('placeholder'); |
| 17690 |
if (!value && placeholder) { |
| 17691 |
value = placeholder; |
| 17692 |
} |
| 17693 |
|
| 17694 |
width = measureString(value, $input) + 4; |
| 17695 |
if (width !== currentWidth) { |
| 17696 |
currentWidth = width; |
| 17697 |
$input.width(width); |
| 17698 |
$input.triggerHandler('resize'); |
| 17699 |
} |
| 17700 |
}; |
| 17701 |
|
| 17702 |
$input.on('keydown keyup update blur', update); |
| 17703 |
update(); |
| 17704 |
}; |
| 17705 |
|
| 17706 |
var domToString = function(d) { |
| 17707 |
var tmp = document.createElement('div'); |
| 17708 |
|
| 17709 |
tmp.appendChild(d.cloneNode(true)); |
| 17710 |
|
| 17711 |
return tmp.innerHTML; |
| 17712 |
}; |
| 17713 |
|
| 17714 |
var logError = function(message, options){ |
| 17715 |
if(!options) options = {}; |
| 17716 |
var component = "Selectize"; |
| 17717 |
|
| 17718 |
console.error(component + ": " + message) |
| 17719 |
|
| 17720 |
if(options.explanation){ |
| 17721 |
// console.group is undefined in <IE11 |
| 17722 |
if(console.group) console.group(); |
| 17723 |
console.error(options.explanation); |
| 17724 |
if(console.group) console.groupEnd(); |
| 17725 |
} |
| 17726 |
} |
| 17727 |
|
| 17728 |
|
| 17729 |
var Selectize = function($input, settings) { |
| 17730 |
var key, i, n, dir, input, self = this; |
| 17731 |
input = $input[0]; |
| 17732 |
input.selectize = self; |
| 17733 |
|
| 17734 |
// detect rtl environment |
| 17735 |
var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null); |
| 17736 |
dir = computedStyle ? computedStyle.getPropertyValue('direction') : input.currentStyle && input.currentStyle.direction; |
| 17737 |
dir = dir || $input.parents('[dir]:first').attr('dir') || ''; |
| 17738 |
|
| 17739 |
// setup default state |
| 17740 |
$.extend(self, { |
| 17741 |
order : 0, |
| 17742 |
settings : settings, |
| 17743 |
$input : $input, |
| 17744 |
tabIndex : $input.attr('tabindex') || '', |
| 17745 |
tagType : input.tagName.toLowerCase() === 'select' ? TAG_SELECT : TAG_INPUT, |
| 17746 |
rtl : /rtl/i.test(dir), |
| 17747 |
|
| 17748 |
eventNS : '.selectize' + (++Selectize.count), |
| 17749 |
highlightedValue : null, |
| 17750 |
isOpen : false, |
| 17751 |
isDisabled : false, |
| 17752 |
isRequired : $input.is('[required]'), |
| 17753 |
isInvalid : false, |
| 17754 |
isLocked : false, |
| 17755 |
isFocused : false, |
| 17756 |
isInputHidden : false, |
| 17757 |
isSetup : false, |
| 17758 |
isShiftDown : false, |
| 17759 |
isCmdDown : false, |
| 17760 |
isCtrlDown : false, |
| 17761 |
ignoreFocus : false, |
| 17762 |
ignoreBlur : false, |
| 17763 |
ignoreHover : false, |
| 17764 |
hasOptions : false, |
| 17765 |
currentResults : null, |
| 17766 |
lastValue : '', |
| 17767 |
caretPos : 0, |
| 17768 |
loading : 0, |
| 17769 |
loadedSearches : {}, |
| 17770 |
|
| 17771 |
$activeOption : null, |
| 17772 |
$activeItems : [], |
| 17773 |
|
| 17774 |
optgroups : {}, |
| 17775 |
options : {}, |
| 17776 |
userOptions : {}, |
| 17777 |
items : [], |
| 17778 |
renderCache : {}, |
| 17779 |
onSearchChange : settings.loadThrottle === null ? self.onSearchChange : debounce(self.onSearchChange, settings.loadThrottle) |
| 17780 |
}); |
| 17781 |
|
| 17782 |
// search system |
| 17783 |
self.sifter = new Sifter(this.options, {diacritics: settings.diacritics}); |
| 17784 |
|
| 17785 |
// build options table |
| 17786 |
if (self.settings.options) { |
| 17787 |
for (i = 0, n = self.settings.options.length; i < n; i++) { |
| 17788 |
self.registerOption(self.settings.options[i]); |
| 17789 |
} |
| 17790 |
delete self.settings.options; |
| 17791 |
} |
| 17792 |
|
| 17793 |
// build optgroup table |
| 17794 |
if (self.settings.optgroups) { |
| 17795 |
for (i = 0, n = self.settings.optgroups.length; i < n; i++) { |
| 17796 |
self.registerOptionGroup(self.settings.optgroups[i]); |
| 17797 |
} |
| 17798 |
delete self.settings.optgroups; |
| 17799 |
} |
| 17800 |
|
| 17801 |
// option-dependent defaults |
| 17802 |
self.settings.mode = self.settings.mode || (self.settings.maxItems === 1 ? 'single' : 'multi'); |
| 17803 |
if (typeof self.settings.hideSelected !== 'boolean') { |
| 17804 |
self.settings.hideSelected = self.settings.mode === 'multi'; |
| 17805 |
} |
| 17806 |
|
| 17807 |
self.initializePlugins(self.settings.plugins); |
| 17808 |
self.setupCallbacks(); |
| 17809 |
self.setupTemplates(); |
| 17810 |
self.setup(); |
| 17811 |
}; |
| 17812 |
|
| 17813 |
// mixins |
| 17814 |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 17815 |
|
| 17816 |
MicroEvent.mixin(Selectize); |
| 17817 |
|
| 17818 |
if(typeof MicroPlugin !== "undefined"){ |
| 17819 |
MicroPlugin.mixin(Selectize); |
| 17820 |
}else{ |
| 17821 |
logError("Dependency MicroPlugin is missing", |
| 17822 |
{explanation: |
| 17823 |
"Make sure you either: (1) are using the \"standalone\" "+ |
| 17824 |
"version of Selectize, or (2) require MicroPlugin before you "+ |
| 17825 |
"load Selectize."} |
| 17826 |
); |
| 17827 |
} |
| 17828 |
|
| 17829 |
|
| 17830 |
// methods |
| 17831 |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 17832 |
|
| 17833 |
$.extend(Selectize.prototype, { |
| 17834 |
|
| 17835 |
/** |
| 17836 |
* Creates all elements and sets up event bindings. |
| 17837 |
*/ |
| 17838 |
setup: function() { |
| 17839 |
var self = this; |
| 17840 |
var settings = self.settings; |
| 17841 |
var eventNS = self.eventNS; |
| 17842 |
var $window = $(window); |
| 17843 |
var $document = $(document); |
| 17844 |
var $input = self.$input; |
| 17845 |
|
| 17846 |
var $wrapper; |
| 17847 |
var $control; |
| 17848 |
var $control_input; |
| 17849 |
var $dropdown; |
| 17850 |
var $dropdown_content; |
| 17851 |
var $dropdown_parent; |
| 17852 |
var inputMode; |
| 17853 |
var timeout_blur; |
| 17854 |
var timeout_focus; |
| 17855 |
var classes; |
| 17856 |
var classes_plugins; |
| 17857 |
var inputId; |
| 17858 |
|
| 17859 |
inputMode = self.settings.mode; |
| 17860 |
classes = $input.attr('class') || ''; |
| 17861 |
|
| 17862 |
$wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode); |
| 17863 |
$control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper); |
| 17864 |
$control_input = $('<input type="text" autocomplete="off" />').appendTo($control).attr('tabindex', $input.is(':disabled') ? '-1' : self.tabIndex); |
| 17865 |
$dropdown_parent = $(settings.dropdownParent || $wrapper); |
| 17866 |
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent); |
| 17867 |
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown); |
| 17868 |
|
| 17869 |
if(inputId = $input.attr('id')) { |
| 17870 |
$control_input.attr('id', inputId + '-selectized'); |
| 17871 |
$("label[for='"+inputId+"']").attr('for', inputId + '-selectized'); |
| 17872 |
} |
| 17873 |
|
| 17874 |
if(self.settings.copyClassesToDropdown) { |
| 17875 |
$dropdown.addClass(classes); |
| 17876 |
} |
| 17877 |
|
| 17878 |
$wrapper.css({ |
| 17879 |
width: $input[0].style.width |
| 17880 |
}); |
| 17881 |
|
| 17882 |
if (self.plugins.names.length) { |
| 17883 |
classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-'); |
| 17884 |
$wrapper.addClass(classes_plugins); |
| 17885 |
$dropdown.addClass(classes_plugins); |
| 17886 |
} |
| 17887 |
|
| 17888 |
if ((settings.maxItems === null || settings.maxItems > 1) && self.tagType === TAG_SELECT) { |
| 17889 |
$input.attr('multiple', 'multiple'); |
| 17890 |
} |
| 17891 |
|
| 17892 |
if (self.settings.placeholder) { |
| 17893 |
$control_input.attr('placeholder', settings.placeholder); |
| 17894 |
} |
| 17895 |
|
| 17896 |
// if splitOn was not passed in, construct it from the delimiter to allow pasting universally |
| 17897 |
if (!self.settings.splitOn && self.settings.delimiter) { |
| 17898 |
var delimiterEscaped = self.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 17899 |
self.settings.splitOn = new RegExp('\\s*' + delimiterEscaped + '+\\s*'); |
| 17900 |
} |
| 17901 |
|
| 17902 |
if ($input.attr('autocorrect')) { |
| 17903 |
$control_input.attr('autocorrect', $input.attr('autocorrect')); |
| 17904 |
} |
| 17905 |
|
| 17906 |
if ($input.attr('autocapitalize')) { |
| 17907 |
$control_input.attr('autocapitalize', $input.attr('autocapitalize')); |
| 17908 |
} |
| 17909 |
|
| 17910 |
self.$wrapper = $wrapper; |
| 17911 |
self.$control = $control; |
| 17912 |
self.$control_input = $control_input; |
| 17913 |
self.$dropdown = $dropdown; |
| 17914 |
self.$dropdown_content = $dropdown_content; |
| 17915 |
|
| 17916 |
$dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); }); |
| 17917 |
$dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); }); |
| 17918 |
watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); }); |
| 17919 |
autoGrow($control_input); |
| 17920 |
|
| 17921 |
$control.on({ |
| 17922 |
mousedown : function() { return self.onMouseDown.apply(self, arguments); }, |
| 17923 |
click : function() { return self.onClick.apply(self, arguments); } |
| 17924 |
}); |
| 17925 |
|
| 17926 |
$control_input.on({ |
| 17927 |
mousedown : function(e) { e.stopPropagation(); }, |
| 17928 |
keydown : function() { return self.onKeyDown.apply(self, arguments); }, |
| 17929 |
keyup : function() { return self.onKeyUp.apply(self, arguments); }, |
| 17930 |
keypress : function() { return self.onKeyPress.apply(self, arguments); }, |
| 17931 |
resize : function() { self.positionDropdown.apply(self, []); }, |
| 17932 |
blur : function() { return self.onBlur.apply(self, arguments); }, |
| 17933 |
focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); }, |
| 17934 |
paste : function() { return self.onPaste.apply(self, arguments); } |
| 17935 |
}); |
| 17936 |
|
| 17937 |
$document.on('keydown' + eventNS, function(e) { |
| 17938 |
self.isCmdDown = e[IS_MAC ? 'metaKey' : 'ctrlKey']; |
| 17939 |
self.isCtrlDown = e[IS_MAC ? 'altKey' : 'ctrlKey']; |
| 17940 |
self.isShiftDown = e.shiftKey; |
| 17941 |
}); |
| 17942 |
|
| 17943 |
$document.on('keyup' + eventNS, function(e) { |
| 17944 |
if (e.keyCode === KEY_CTRL) self.isCtrlDown = false; |
| 17945 |
if (e.keyCode === KEY_SHIFT) self.isShiftDown = false; |
| 17946 |
if (e.keyCode === KEY_CMD) self.isCmdDown = false; |
| 17947 |
}); |
| 17948 |
|
| 17949 |
$document.on('mousedown' + eventNS, function(e) { |
| 17950 |
if (self.isFocused) { |
| 17951 |
// prevent events on the dropdown scrollbar from causing the control to blur |
| 17952 |
if (e.target === self.$dropdown[0] || e.target.parentNode === self.$dropdown[0]) { |
| 17953 |
return false; |
| 17954 |
} |
| 17955 |
// blur on click outside |
| 17956 |
if (!self.$control.has(e.target).length && e.target !== self.$control[0]) { |
| 17957 |
self.blur(e.target); |
| 17958 |
} |
| 17959 |
} |
| 17960 |
}); |
| 17961 |
|
| 17962 |
$window.on(['scroll' + eventNS, 'resize' + eventNS].join(' '), function() { |
| 17963 |
if (self.isOpen) { |
| 17964 |
self.positionDropdown.apply(self, arguments); |
| 17965 |
} |
| 17966 |
}); |
| 17967 |
$window.on('mousemove' + eventNS, function() { |
| 17968 |
self.ignoreHover = false; |
| 17969 |
}); |
| 17970 |
|
| 17971 |
// store original children and tab index so that they can be |
| 17972 |
// restored when the destroy() method is called. |
| 17973 |
this.revertSettings = { |
| 17974 |
$children : $input.children().detach(), |
| 17975 |
tabindex : $input.attr('tabindex') |
| 17976 |
}; |
| 17977 |
|
| 17978 |
$input.attr('tabindex', -1).hide().after(self.$wrapper); |
| 17979 |
|
| 17980 |
if ($.isArray(settings.items)) { |
| 17981 |
self.setValue(settings.items); |
| 17982 |
delete settings.items; |
| 17983 |
} |
| 17984 |
|
| 17985 |
// feature detect for the validation API |
| 17986 |
if (SUPPORTS_VALIDITY_API) { |
| 17987 |
$input.on('invalid' + eventNS, function(e) { |
| 17988 |
e.preventDefault(); |
| 17989 |
self.isInvalid = true; |
| 17990 |
self.refreshState(); |
| 17991 |
}); |
| 17992 |
} |
| 17993 |
|
| 17994 |
self.updateOriginalInput(); |
| 17995 |
self.refreshItems(); |
| 17996 |
self.refreshState(); |
| 17997 |
self.updatePlaceholder(); |
| 17998 |
self.isSetup = true; |
| 17999 |
|
| 18000 |
if ($input.is(':disabled')) { |
| 18001 |
self.disable(); |
| 18002 |
} |
| 18003 |
|
| 18004 |
self.on('change', this.onChange); |
| 18005 |
|
| 18006 |
$input.data('selectize', self); |
| 18007 |
$input.addClass('selectized'); |
| 18008 |
self.trigger('initialize'); |
| 18009 |
|
| 18010 |
// preload options |
| 18011 |
if (settings.preload === true) { |
| 18012 |
self.onSearchChange(''); |
| 18013 |
} |
| 18014 |
|
| 18015 |
}, |
| 18016 |
|
| 18017 |
/** |
| 18018 |
* Sets up default rendering functions. |
| 18019 |
*/ |
| 18020 |
setupTemplates: function() { |
| 18021 |
var self = this; |
| 18022 |
var field_label = self.settings.labelField; |
| 18023 |
var field_optgroup = self.settings.optgroupLabelField; |
| 18024 |
|
| 18025 |
var templates = { |
| 18026 |
'optgroup': function(data) { |
| 18027 |
return '<div class="optgroup">' + data.html + '</div>'; |
| 18028 |
}, |
| 18029 |
'optgroup_header': function(data, escape) { |
| 18030 |
return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>'; |
| 18031 |
}, |
| 18032 |
'option': function(data, escape) { |
| 18033 |
return '<div class="option">' + escape(data[field_label]) + '</div>'; |
| 18034 |
}, |
| 18035 |
'item': function(data, escape) { |
| 18036 |
return '<div class="item">' + escape(data[field_label]) + '</div>'; |
| 18037 |
}, |
| 18038 |
'option_create': function(data, escape) { |
| 18039 |
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>'; |
| 18040 |
} |
| 18041 |
}; |
| 18042 |
|
| 18043 |
self.settings.render = $.extend({}, templates, self.settings.render); |
| 18044 |
}, |
| 18045 |
|
| 18046 |
/** |
| 18047 |
* Maps fired events to callbacks provided |
| 18048 |
* in the settings used when creating the control. |
| 18049 |
*/ |
| 18050 |
setupCallbacks: function() { |
| 18051 |
var key, fn, callbacks = { |
| 18052 |
'initialize' : 'onInitialize', |
| 18053 |
'change' : 'onChange', |
| 18054 |
'item_add' : 'onItemAdd', |
| 18055 |
'item_remove' : 'onItemRemove', |
| 18056 |
'clear' : 'onClear', |
| 18057 |
'option_add' : 'onOptionAdd', |
| 18058 |
'option_remove' : 'onOptionRemove', |
| 18059 |
'option_clear' : 'onOptionClear', |
| 18060 |
'optgroup_add' : 'onOptionGroupAdd', |
| 18061 |
'optgroup_remove' : 'onOptionGroupRemove', |
| 18062 |
'optgroup_clear' : 'onOptionGroupClear', |
| 18063 |
'dropdown_open' : 'onDropdownOpen', |
| 18064 |
'dropdown_close' : 'onDropdownClose', |
| 18065 |
'type' : 'onType', |
| 18066 |
'load' : 'onLoad', |
| 18067 |
'focus' : 'onFocus', |
| 18068 |
'blur' : 'onBlur' |
| 18069 |
}; |
| 18070 |
|
| 18071 |
for (key in callbacks) { |
| 18072 |
if (callbacks.hasOwnProperty(key)) { |
| 18073 |
fn = this.settings[callbacks[key]]; |
| 18074 |
if (fn) this.on(key, fn); |
| 18075 |
} |
| 18076 |
} |
| 18077 |
}, |
| 18078 |
|
| 18079 |
/** |
| 18080 |
* Triggered when the main control element |
| 18081 |
* has a click event. |
| 18082 |
* |
| 18083 |
* @param {object} e |
| 18084 |
* @return {boolean} |
| 18085 |
*/ |
| 18086 |
onClick: function(e) { |
| 18087 |
var self = this; |
| 18088 |
|
| 18089 |
// necessary for mobile webkit devices (manual focus triggering |
| 18090 |
// is ignored unless invoked within a click event) |
| 18091 |
if (!self.isFocused) { |
| 18092 |
self.focus(); |
| 18093 |
e.preventDefault(); |
| 18094 |
} |
| 18095 |
}, |
| 18096 |
|
| 18097 |
/** |
| 18098 |
* Triggered when the main control element |
| 18099 |
* has a mouse down event. |
| 18100 |
* |
| 18101 |
* @param {object} e |
| 18102 |
* @return {boolean} |
| 18103 |
*/ |
| 18104 |
onMouseDown: function(e) { |
| 18105 |
var self = this; |
| 18106 |
var defaultPrevented = e.isDefaultPrevented(); |
| 18107 |
var $target = $(e.target); |
| 18108 |
|
| 18109 |
if (self.isFocused) { |
| 18110 |
// retain focus by preventing native handling. if the |
| 18111 |
// event target is the input it should not be modified. |
| 18112 |
// otherwise, text selection within the input won't work. |
| 18113 |
if (e.target !== self.$control_input[0]) { |
| 18114 |
if (self.settings.mode === 'single') { |
| 18115 |
// toggle dropdown |
| 18116 |
self.isOpen ? self.close() : self.open(); |
| 18117 |
} else if (!defaultPrevented) { |
| 18118 |
self.setActiveItem(null); |
| 18119 |
} |
| 18120 |
return false; |
| 18121 |
} |
| 18122 |
} else { |
| 18123 |
// give control focus |
| 18124 |
if (!defaultPrevented) { |
| 18125 |
window.setTimeout(function() { |
| 18126 |
self.focus(); |
| 18127 |
}, 0); |
| 18128 |
} |
| 18129 |
} |
| 18130 |
}, |
| 18131 |
|
| 18132 |
/** |
| 18133 |
* Triggered when the value of the control has been changed. |
| 18134 |
* This should propagate the event to the original DOM |
| 18135 |
* input / select element. |
| 18136 |
*/ |
| 18137 |
onChange: function() { |
| 18138 |
this.$input.trigger('change'); |
| 18139 |
}, |
| 18140 |
|
| 18141 |
/** |
| 18142 |
* Triggered on <input> paste. |
| 18143 |
* |
| 18144 |
* @param {object} e |
| 18145 |
* @returns {boolean} |
| 18146 |
*/ |
| 18147 |
onPaste: function(e) { |
| 18148 |
var self = this; |
| 18149 |
|
| 18150 |
if (self.isFull() || self.isInputHidden || self.isLocked) { |
| 18151 |
e.preventDefault(); |
| 18152 |
return; |
| 18153 |
} |
| 18154 |
|
| 18155 |
// If a regex or string is included, this will split the pasted |
| 18156 |
// input and create Items for each separate value |
| 18157 |
if (self.settings.splitOn) { |
| 18158 |
|
| 18159 |
// Wait for pasted text to be recognized in value |
| 18160 |
setTimeout(function() { |
| 18161 |
var pastedText = self.$control_input.val(); |
| 18162 |
if(!pastedText.match(self.settings.splitOn)){ return } |
| 18163 |
|
| 18164 |
var splitInput = $.trim(pastedText).split(self.settings.splitOn); |
| 18165 |
for (var i = 0, n = splitInput.length; i < n; i++) { |
| 18166 |
self.createItem(splitInput[i]); |
| 18167 |
} |
| 18168 |
}, 0); |
| 18169 |
} |
| 18170 |
}, |
| 18171 |
|
| 18172 |
/** |
| 18173 |
* Triggered on <input> keypress. |
| 18174 |
* |
| 18175 |
* @param {object} e |
| 18176 |
* @returns {boolean} |
| 18177 |
*/ |
| 18178 |
onKeyPress: function(e) { |
| 18179 |
if (this.isLocked) return e && e.preventDefault(); |
| 18180 |
var character = String.fromCharCode(e.keyCode || e.which); |
| 18181 |
if (this.settings.create && this.settings.mode === 'multi' && character === this.settings.delimiter) { |
| 18182 |
this.createItem(); |
| 18183 |
e.preventDefault(); |
| 18184 |
return false; |
| 18185 |
} |
| 18186 |
}, |
| 18187 |
|
| 18188 |
/** |
| 18189 |
* Triggered on <input> keydown. |
| 18190 |
* |
| 18191 |
* @param {object} e |
| 18192 |
* @returns {boolean} |
| 18193 |
*/ |
| 18194 |
onKeyDown: function(e) { |
| 18195 |
var isInput = e.target === this.$control_input[0]; |
| 18196 |
var self = this; |
| 18197 |
|
| 18198 |
if (self.isLocked) { |
| 18199 |
if (e.keyCode !== KEY_TAB) { |
| 18200 |
e.preventDefault(); |
| 18201 |
} |
| 18202 |
return; |
| 18203 |
} |
| 18204 |
|
| 18205 |
switch (e.keyCode) { |
| 18206 |
case KEY_A: |
| 18207 |
if (self.isCmdDown) { |
| 18208 |
self.selectAll(); |
| 18209 |
return; |
| 18210 |
} |
| 18211 |
break; |
| 18212 |
case KEY_ESC: |
| 18213 |
if (self.isOpen) { |
| 18214 |
e.preventDefault(); |
| 18215 |
e.stopPropagation(); |
| 18216 |
self.close(); |
| 18217 |
} |
| 18218 |
return; |
| 18219 |
case KEY_N: |
| 18220 |
if (!e.ctrlKey || e.altKey) break; |
| 18221 |
case KEY_DOWN: |
| 18222 |
if (!self.isOpen && self.hasOptions) { |
| 18223 |
self.open(); |
| 18224 |
} else if (self.$activeOption) { |
| 18225 |
self.ignoreHover = true; |
| 18226 |
var $next = self.getAdjacentOption(self.$activeOption, 1); |
| 18227 |
if ($next.length) self.setActiveOption($next, true, true); |
| 18228 |
} |
| 18229 |
e.preventDefault(); |
| 18230 |
return; |
| 18231 |
case KEY_P: |
| 18232 |
if (!e.ctrlKey || e.altKey) break; |
| 18233 |
case KEY_UP: |
| 18234 |
if (self.$activeOption) { |
| 18235 |
self.ignoreHover = true; |
| 18236 |
var $prev = self.getAdjacentOption(self.$activeOption, -1); |
| 18237 |
if ($prev.length) self.setActiveOption($prev, true, true); |
| 18238 |
} |
| 18239 |
e.preventDefault(); |
| 18240 |
return; |
| 18241 |
case KEY_RETURN: |
| 18242 |
if (self.isOpen && self.$activeOption) { |
| 18243 |
self.onOptionSelect({currentTarget: self.$activeOption}); |
| 18244 |
e.preventDefault(); |
| 18245 |
} |
| 18246 |
return; |
| 18247 |
case KEY_LEFT: |
| 18248 |
self.advanceSelection(-1, e); |
| 18249 |
return; |
| 18250 |
case KEY_RIGHT: |
| 18251 |
self.advanceSelection(1, e); |
| 18252 |
return; |
| 18253 |
case KEY_TAB: |
| 18254 |
if (self.settings.selectOnTab && self.isOpen && self.$activeOption) { |
| 18255 |
self.onOptionSelect({currentTarget: self.$activeOption}); |
| 18256 |
|
| 18257 |
// Default behaviour is to jump to the next field, we only want this |
| 18258 |
// if the current field doesn't accept any more entries |
| 18259 |
if (!self.isFull()) { |
| 18260 |
e.preventDefault(); |
| 18261 |
} |
| 18262 |
} |
| 18263 |
if (self.settings.create && self.createItem()) { |
| 18264 |
e.preventDefault(); |
| 18265 |
} |
| 18266 |
return; |
| 18267 |
case KEY_BACKSPACE: |
| 18268 |
case KEY_DELETE: |
| 18269 |
self.deleteSelection(e); |
| 18270 |
return; |
| 18271 |
} |
| 18272 |
|
| 18273 |
if ((self.isFull() || self.isInputHidden) && !(IS_MAC ? e.metaKey : e.ctrlKey)) { |
| 18274 |
e.preventDefault(); |
| 18275 |
return; |
| 18276 |
} |
| 18277 |
}, |
| 18278 |
|
| 18279 |
/** |
| 18280 |
* Triggered on <input> keyup. |
| 18281 |
* |
| 18282 |
* @param {object} e |
| 18283 |
* @returns {boolean} |
| 18284 |
*/ |
| 18285 |
onKeyUp: function(e) { |
| 18286 |
var self = this; |
| 18287 |
|
| 18288 |
if (self.isLocked) return e && e.preventDefault(); |
| 18289 |
var value = self.$control_input.val() || ''; |
| 18290 |
if (self.lastValue !== value) { |
| 18291 |
self.lastValue = value; |
| 18292 |
self.onSearchChange(value); |
| 18293 |
self.refreshOptions(); |
| 18294 |
self.trigger('type', value); |
| 18295 |
} |
| 18296 |
}, |
| 18297 |
|
| 18298 |
/** |
| 18299 |
* Invokes the user-provide option provider / loader. |
| 18300 |
* |
| 18301 |
* Note: this function is debounced in the Selectize |
| 18302 |
* constructor (by `settings.loadThrottle` milliseconds) |
| 18303 |
* |
| 18304 |
* @param {string} value |
| 18305 |
*/ |
| 18306 |
onSearchChange: function(value) { |
| 18307 |
var self = this; |
| 18308 |
var fn = self.settings.load; |
| 18309 |
if (!fn) return; |
| 18310 |
if (self.loadedSearches.hasOwnProperty(value)) return; |
| 18311 |
self.loadedSearches[value] = true; |
| 18312 |
self.load(function(callback) { |
| 18313 |
fn.apply(self, [value, callback]); |
| 18314 |
}); |
| 18315 |
}, |
| 18316 |
|
| 18317 |
/** |
| 18318 |
* Triggered on <input> focus. |
| 18319 |
* |
| 18320 |
* @param {object} e (optional) |
| 18321 |
* @returns {boolean} |
| 18322 |
*/ |
| 18323 |
onFocus: function(e) { |
| 18324 |
var self = this; |
| 18325 |
var wasFocused = self.isFocused; |
| 18326 |
|
| 18327 |
if (self.isDisabled) { |
| 18328 |
self.blur(); |
| 18329 |
e && e.preventDefault(); |
| 18330 |
return false; |
| 18331 |
} |
| 18332 |
|
| 18333 |
if (self.ignoreFocus) return; |
| 18334 |
self.isFocused = true; |
| 18335 |
if (self.settings.preload === 'focus') self.onSearchChange(''); |
| 18336 |
|
| 18337 |
if (!wasFocused) self.trigger('focus'); |
| 18338 |
|
| 18339 |
if (!self.$activeItems.length) { |
| 18340 |
self.showInput(); |
| 18341 |
self.setActiveItem(null); |
| 18342 |
self.refreshOptions(!!self.settings.openOnFocus); |
| 18343 |
} |
| 18344 |
|
| 18345 |
self.refreshState(); |
| 18346 |
}, |
| 18347 |
|
| 18348 |
/** |
| 18349 |
* Triggered on <input> blur. |
| 18350 |
* |
| 18351 |
* @param {object} e |
| 18352 |
* @param {Element} dest |
| 18353 |
*/ |
| 18354 |
onBlur: function(e, dest) { |
| 18355 |
var self = this; |
| 18356 |
if (!self.isFocused) return; |
| 18357 |
self.isFocused = false; |
| 18358 |
|
| 18359 |
if (self.ignoreFocus) { |
| 18360 |
return; |
| 18361 |
} else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) { |
| 18362 |
// necessary to prevent IE closing the dropdown when the scrollbar is clicked |
| 18363 |
self.ignoreBlur = true; |
| 18364 |
self.onFocus(e); |
| 18365 |
return; |
| 18366 |
} |
| 18367 |
|
| 18368 |
var deactivate = function() { |
| 18369 |
self.close(); |
| 18370 |
self.setTextboxValue(''); |
| 18371 |
self.setActiveItem(null); |
| 18372 |
self.setActiveOption(null); |
| 18373 |
self.setCaret(self.items.length); |
| 18374 |
self.refreshState(); |
| 18375 |
|
| 18376 |
// IE11 bug: element still marked as active |
| 18377 |
dest && dest.focus && dest.focus(); |
| 18378 |
|
| 18379 |
self.ignoreFocus = false; |
| 18380 |
self.trigger('blur'); |
| 18381 |
}; |
| 18382 |
|
| 18383 |
self.ignoreFocus = true; |
| 18384 |
if (self.settings.create && self.settings.createOnBlur) { |
| 18385 |
self.createItem(null, false, deactivate); |
| 18386 |
} else { |
| 18387 |
deactivate(); |
| 18388 |
} |
| 18389 |
}, |
| 18390 |
|
| 18391 |
/** |
| 18392 |
* Triggered when the user rolls over |
| 18393 |
* an option in the autocomplete dropdown menu. |
| 18394 |
* |
| 18395 |
* @param {object} e |
| 18396 |
* @returns {boolean} |
| 18397 |
*/ |
| 18398 |
onOptionHover: function(e) { |
| 18399 |
if (this.ignoreHover) return; |
| 18400 |
this.setActiveOption(e.currentTarget, false); |
| 18401 |
}, |
| 18402 |
|
| 18403 |
/** |
| 18404 |
* Triggered when the user clicks on an option |
| 18405 |
* in the autocomplete dropdown menu. |
| 18406 |
* |
| 18407 |
* @param {object} e |
| 18408 |
* @returns {boolean} |
| 18409 |
*/ |
| 18410 |
onOptionSelect: function(e) { |
| 18411 |
var value, $target, $option, self = this; |
| 18412 |
|
| 18413 |
if (e.preventDefault) { |
| 18414 |
e.preventDefault(); |
| 18415 |
e.stopPropagation(); |
| 18416 |
} |
| 18417 |
|
| 18418 |
$target = $(e.currentTarget); |
| 18419 |
if ($target.hasClass('create')) { |
| 18420 |
self.createItem(null, function() { |
| 18421 |
if (self.settings.closeAfterSelect) { |
| 18422 |
self.close(); |
| 18423 |
} |
| 18424 |
}); |
| 18425 |
} else { |
| 18426 |
value = $target.attr('data-value'); |
| 18427 |
if (typeof value !== 'undefined') { |
| 18428 |
self.lastQuery = null; |
| 18429 |
self.setTextboxValue(''); |
| 18430 |
self.addItem(value); |
| 18431 |
if (self.settings.closeAfterSelect) { |
| 18432 |
self.close(); |
| 18433 |
} else if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) { |
| 18434 |
self.setActiveOption(self.getOption(value)); |
| 18435 |
} |
| 18436 |
} |
| 18437 |
} |
| 18438 |
}, |
| 18439 |
|
| 18440 |
/** |
| 18441 |
* Triggered when the user clicks on an item |
| 18442 |
* that has been selected. |
| 18443 |
* |
| 18444 |
* @param {object} e |
| 18445 |
* @returns {boolean} |
| 18446 |
*/ |
| 18447 |
onItemSelect: function(e) { |
| 18448 |
var self = this; |
| 18449 |
|
| 18450 |
if (self.isLocked) return; |
| 18451 |
if (self.settings.mode === 'multi') { |
| 18452 |
e.preventDefault(); |
| 18453 |
self.setActiveItem(e.currentTarget, e); |
| 18454 |
} |
| 18455 |
}, |
| 18456 |
|
| 18457 |
/** |
| 18458 |
* Invokes the provided method that provides |
| 18459 |
* results to a callback---which are then added |
| 18460 |
* as options to the control. |
| 18461 |
* |
| 18462 |
* @param {function} fn |
| 18463 |
*/ |
| 18464 |
load: function(fn) { |
| 18465 |
var self = this; |
| 18466 |
var $wrapper = self.$wrapper.addClass(self.settings.loadingClass); |
| 18467 |
|
| 18468 |
self.loading++; |
| 18469 |
fn.apply(self, [function(results) { |
| 18470 |
self.loading = Math.max(self.loading - 1, 0); |
| 18471 |
if (results && results.length) { |
| 18472 |
self.addOption(results); |
| 18473 |
self.refreshOptions(self.isFocused && !self.isInputHidden); |
| 18474 |
} |
| 18475 |
if (!self.loading) { |
| 18476 |
$wrapper.removeClass(self.settings.loadingClass); |
| 18477 |
} |
| 18478 |
self.trigger('load', results); |
| 18479 |
}]); |
| 18480 |
}, |
| 18481 |
|
| 18482 |
/** |
| 18483 |
* Sets the input field of the control to the specified value. |
| 18484 |
* |
| 18485 |
* @param {string} value |
| 18486 |
*/ |
| 18487 |
setTextboxValue: function(value) { |
| 18488 |
var $input = this.$control_input; |
| 18489 |
var changed = $input.val() !== value; |
| 18490 |
if (changed) { |
| 18491 |
$input.val(value).triggerHandler('update'); |
| 18492 |
this.lastValue = value; |
| 18493 |
} |
| 18494 |
}, |
| 18495 |
|
| 18496 |
/** |
| 18497 |
* Returns the value of the control. If multiple items |
| 18498 |
* can be selected (e.g. <select multiple>), this returns |
| 18499 |
* an array. If only one item can be selected, this |
| 18500 |
* returns a string. |
| 18501 |
* |
| 18502 |
* @returns {mixed} |
| 18503 |
*/ |
| 18504 |
getValue: function() { |
| 18505 |
if (this.tagType === TAG_SELECT && this.$input.attr('multiple')) { |
| 18506 |
return this.items; |
| 18507 |
} else { |
| 18508 |
return this.items.join(this.settings.delimiter); |
| 18509 |
} |
| 18510 |
}, |
| 18511 |
|
| 18512 |
/** |
| 18513 |
* Resets the selected items to the given value. |
| 18514 |
* |
| 18515 |
* @param {mixed} value |
| 18516 |
*/ |
| 18517 |
setValue: function(value, silent) { |
| 18518 |
var events = silent ? [] : ['change']; |
| 18519 |
|
| 18520 |
debounce_events(this, events, function() { |
| 18521 |
this.clear(silent); |
| 18522 |
this.addItems(value, silent); |
| 18523 |
}); |
| 18524 |
}, |
| 18525 |
|
| 18526 |
/** |
| 18527 |
* Sets the selected item. |
| 18528 |
* |
| 18529 |
* @param {object} $item |
| 18530 |
* @param {object} e (optional) |
| 18531 |
*/ |
| 18532 |
setActiveItem: function($item, e) { |
| 18533 |
var self = this; |
| 18534 |
var eventName; |
| 18535 |
var i, idx, begin, end, item, swap; |
| 18536 |
var $last; |
| 18537 |
|
| 18538 |
if (self.settings.mode === 'single') return; |
| 18539 |
$item = $($item); |
| 18540 |
|
| 18541 |
// clear the active selection |
| 18542 |
if (!$item.length) { |
| 18543 |
$(self.$activeItems).removeClass('active'); |
| 18544 |
self.$activeItems = []; |
| 18545 |
if (self.isFocused) { |
| 18546 |
self.showInput(); |
| 18547 |
} |
| 18548 |
return; |
| 18549 |
} |
| 18550 |
|
| 18551 |
// modify selection |
| 18552 |
eventName = e && e.type.toLowerCase(); |
| 18553 |
|
| 18554 |
if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) { |
| 18555 |
$last = self.$control.children('.active:last'); |
| 18556 |
begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]); |
| 18557 |
end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]); |
| 18558 |
if (begin > end) { |
| 18559 |
swap = begin; |
| 18560 |
begin = end; |
| 18561 |
end = swap; |
| 18562 |
} |
| 18563 |
for (i = begin; i <= end; i++) { |
| 18564 |
item = self.$control[0].childNodes[i]; |
| 18565 |
if (self.$activeItems.indexOf(item) === -1) { |
| 18566 |
$(item).addClass('active'); |
| 18567 |
self.$activeItems.push(item); |
| 18568 |
} |
| 18569 |
} |
| 18570 |
e.preventDefault(); |
| 18571 |
} else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) { |
| 18572 |
if ($item.hasClass('active')) { |
| 18573 |
idx = self.$activeItems.indexOf($item[0]); |
| 18574 |
self.$activeItems.splice(idx, 1); |
| 18575 |
$item.removeClass('active'); |
| 18576 |
} else { |
| 18577 |
self.$activeItems.push($item.addClass('active')[0]); |
| 18578 |
} |
| 18579 |
} else { |
| 18580 |
$(self.$activeItems).removeClass('active'); |
| 18581 |
self.$activeItems = [$item.addClass('active')[0]]; |
| 18582 |
} |
| 18583 |
|
| 18584 |
// ensure control has focus |
| 18585 |
self.hideInput(); |
| 18586 |
if (!this.isFocused) { |
| 18587 |
self.focus(); |
| 18588 |
} |
| 18589 |
}, |
| 18590 |
|
| 18591 |
/** |
| 18592 |
* Sets the selected item in the dropdown menu |
| 18593 |
* of available options. |
| 18594 |
* |
| 18595 |
* @param {object} $object |
| 18596 |
* @param {boolean} scroll |
| 18597 |
* @param {boolean} animate |
| 18598 |
*/ |
| 18599 |
setActiveOption: function($option, scroll, animate) { |
| 18600 |
var height_menu, height_item, y; |
| 18601 |
var scroll_top, scroll_bottom; |
| 18602 |
var self = this; |
| 18603 |
|
| 18604 |
if (self.$activeOption) self.$activeOption.removeClass('active'); |
| 18605 |
self.$activeOption = null; |
| 18606 |
|
| 18607 |
$option = $($option); |
| 18608 |
if (!$option.length) return; |
| 18609 |
|
| 18610 |
self.$activeOption = $option.addClass('active'); |
| 18611 |
|
| 18612 |
if (scroll || !isset(scroll)) { |
| 18613 |
|
| 18614 |
height_menu = self.$dropdown_content.height(); |
| 18615 |
height_item = self.$activeOption.outerHeight(true); |
| 18616 |
scroll = self.$dropdown_content.scrollTop() || 0; |
| 18617 |
y = self.$activeOption.offset().top - self.$dropdown_content.offset().top + scroll; |
| 18618 |
scroll_top = y; |
| 18619 |
scroll_bottom = y - height_menu + height_item; |
| 18620 |
|
| 18621 |
if (y + height_item > height_menu + scroll) { |
| 18622 |
self.$dropdown_content.stop().animate({scrollTop: scroll_bottom}, animate ? self.settings.scrollDuration : 0); |
| 18623 |
} else if (y < scroll) { |
| 18624 |
self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0); |
| 18625 |
} |
| 18626 |
|
| 18627 |
} |
| 18628 |
}, |
| 18629 |
|
| 18630 |
/** |
| 18631 |
* Selects all items (CTRL + A). |
| 18632 |
*/ |
| 18633 |
selectAll: function() { |
| 18634 |
var self = this; |
| 18635 |
if (self.settings.mode === 'single') return; |
| 18636 |
|
| 18637 |
self.$activeItems = Array.prototype.slice.apply(self.$control.children(':not(input)').addClass('active')); |
| 18638 |
if (self.$activeItems.length) { |
| 18639 |
self.hideInput(); |
| 18640 |
self.close(); |
| 18641 |
} |
| 18642 |
self.focus(); |
| 18643 |
}, |
| 18644 |
|
| 18645 |
/** |
| 18646 |
* Hides the input element out of view, while |
| 18647 |
* retaining its focus. |
| 18648 |
*/ |
| 18649 |
hideInput: function() { |
| 18650 |
var self = this; |
| 18651 |
|
| 18652 |
self.setTextboxValue(''); |
| 18653 |
self.$control_input.css({opacity: 0, position: 'absolute', left: self.rtl ? 10000 : -10000}); |
| 18654 |
self.isInputHidden = true; |
| 18655 |
}, |
| 18656 |
|
| 18657 |
/** |
| 18658 |
* Restores input visibility. |
| 18659 |
*/ |
| 18660 |
showInput: function() { |
| 18661 |
this.$control_input.css({opacity: 1, position: 'relative', left: 0}); |
| 18662 |
this.isInputHidden = false; |
| 18663 |
}, |
| 18664 |
|
| 18665 |
/** |
| 18666 |
* Gives the control focus. |
| 18667 |
*/ |
| 18668 |
focus: function() { |
| 18669 |
var self = this; |
| 18670 |
if (self.isDisabled) return; |
| 18671 |
|
| 18672 |
self.ignoreFocus = true; |
| 18673 |
self.$control_input[0].focus(); |
| 18674 |
window.setTimeout(function() { |
| 18675 |
self.ignoreFocus = false; |
| 18676 |
self.onFocus(); |
| 18677 |
}, 0); |
| 18678 |
}, |
| 18679 |
|
| 18680 |
/** |
| 18681 |
* Forces the control out of focus. |
| 18682 |
* |
| 18683 |
* @param {Element} dest |
| 18684 |
*/ |
| 18685 |
blur: function(dest) { |
| 18686 |
this.$control_input[0].blur(); |
| 18687 |
this.onBlur(null, dest); |
| 18688 |
}, |
| 18689 |
|
| 18690 |
/** |
| 18691 |
* Returns a function that scores an object |
| 18692 |
* to show how good of a match it is to the |
| 18693 |
* provided query. |
| 18694 |
* |
| 18695 |
* @param {string} query |
| 18696 |
* @param {object} options |
| 18697 |
* @return {function} |
| 18698 |
*/ |
| 18699 |
getScoreFunction: function(query) { |
| 18700 |
return this.sifter.getScoreFunction(query, this.getSearchOptions()); |
| 18701 |
}, |
| 18702 |
|
| 18703 |
/** |
| 18704 |
* Returns search options for sifter (the system |
| 18705 |
* for scoring and sorting results). |
| 18706 |
* |
| 18707 |
* @see https://github.com/brianreavis/sifter.js |
| 18708 |
* @return {object} |
| 18709 |
*/ |
| 18710 |
getSearchOptions: function() { |
| 18711 |
var settings = this.settings; |
| 18712 |
var sort = settings.sortField; |
| 18713 |
if (typeof sort === 'string') { |
| 18714 |
sort = [{field: sort}]; |
| 18715 |
} |
| 18716 |
|
| 18717 |
return { |
| 18718 |
fields : settings.searchField, |
| 18719 |
conjunction : settings.searchConjunction, |
| 18720 |
sort : sort |
| 18721 |
}; |
| 18722 |
}, |
| 18723 |
|
| 18724 |
/** |
| 18725 |
* Searches through available options and returns |
| 18726 |
* a sorted array of matches. |
| 18727 |
* |
| 18728 |
* Returns an object containing: |
| 18729 |
* |
| 18730 |
* - query {string} |
| 18731 |
* - tokens {array} |
| 18732 |
* - total {int} |
| 18733 |
* - items {array} |
| 18734 |
* |
| 18735 |
* @param {string} query |
| 18736 |
* @returns {object} |
| 18737 |
*/ |
| 18738 |
search: function(query) { |
| 18739 |
var i, value, score, result, calculateScore; |
| 18740 |
var self = this; |
| 18741 |
var settings = self.settings; |
| 18742 |
var options = this.getSearchOptions(); |
| 18743 |
|
| 18744 |
// validate user-provided result scoring function |
| 18745 |
if (settings.score) { |
| 18746 |
calculateScore = self.settings.score.apply(this, [query]); |
| 18747 |
if (typeof calculateScore !== 'function') { |
| 18748 |
throw new Error('Selectize "score" setting must be a function that returns a function'); |
| 18749 |
} |
| 18750 |
} |
| 18751 |
|
| 18752 |
// perform search |
| 18753 |
if (query !== self.lastQuery) { |
| 18754 |
self.lastQuery = query; |
| 18755 |
result = self.sifter.search(query, $.extend(options, {score: calculateScore})); |
| 18756 |
self.currentResults = result; |
| 18757 |
} else { |
| 18758 |
result = $.extend(true, {}, self.currentResults); |
| 18759 |
} |
| 18760 |
|
| 18761 |
// filter out selected items |
| 18762 |
if (settings.hideSelected) { |
| 18763 |
for (i = result.items.length - 1; i >= 0; i--) { |
| 18764 |
if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) { |
| 18765 |
result.items.splice(i, 1); |
| 18766 |
} |
| 18767 |
} |
| 18768 |
} |
| 18769 |
|
| 18770 |
return result; |
| 18771 |
}, |
| 18772 |
|
| 18773 |
/** |
| 18774 |
* Refreshes the list of available options shown |
| 18775 |
* in the autocomplete dropdown menu. |
| 18776 |
* |
| 18777 |
* @param {boolean} triggerDropdown |
| 18778 |
*/ |
| 18779 |
refreshOptions: function(triggerDropdown) { |
| 18780 |
var i, j, k, n, groups, groups_order, option, option_html, optgroup, optgroups, html, html_children, has_create_option; |
| 18781 |
var $active, $active_before, $create; |
| 18782 |
|
| 18783 |
if (typeof triggerDropdown === 'undefined') { |
| 18784 |
triggerDropdown = true; |
| 18785 |
} |
| 18786 |
|
| 18787 |
var self = this; |
| 18788 |
var query = $.trim(self.$control_input.val()); |
| 18789 |
var results = self.search(query); |
| 18790 |
var $dropdown_content = self.$dropdown_content; |
| 18791 |
var active_before = self.$activeOption && hash_key(self.$activeOption.attr('data-value')); |
| 18792 |
|
| 18793 |
// build markup |
| 18794 |
n = results.items.length; |
| 18795 |
if (typeof self.settings.maxOptions === 'number') { |
| 18796 |
n = Math.min(n, self.settings.maxOptions); |
| 18797 |
} |
| 18798 |
|
| 18799 |
// render and group available options individually |
| 18800 |
groups = {}; |
| 18801 |
groups_order = []; |
| 18802 |
|
| 18803 |
for (i = 0; i < n; i++) { |
| 18804 |
option = self.options[results.items[i].id]; |
| 18805 |
option_html = self.render('option', option); |
| 18806 |
optgroup = option[self.settings.optgroupField] || ''; |
| 18807 |
optgroups = $.isArray(optgroup) ? optgroup : [optgroup]; |
| 18808 |
|
| 18809 |
for (j = 0, k = optgroups && optgroups.length; j < k; j++) { |
| 18810 |
optgroup = optgroups[j]; |
| 18811 |
if (!self.optgroups.hasOwnProperty(optgroup)) { |
| 18812 |
optgroup = ''; |
| 18813 |
} |
| 18814 |
if (!groups.hasOwnProperty(optgroup)) { |
| 18815 |
groups[optgroup] = document.createDocumentFragment(); |
| 18816 |
groups_order.push(optgroup); |
| 18817 |
} |
| 18818 |
groups[optgroup].appendChild(option_html); |
| 18819 |
} |
| 18820 |
} |
| 18821 |
|
| 18822 |
// sort optgroups |
| 18823 |
if (this.settings.lockOptgroupOrder) { |
| 18824 |
groups_order.sort(function(a, b) { |
| 18825 |
var a_order = self.optgroups[a].$order || 0; |
| 18826 |
var b_order = self.optgroups[b].$order || 0; |
| 18827 |
return a_order - b_order; |
| 18828 |
}); |
| 18829 |
} |
| 18830 |
|
| 18831 |
// render optgroup headers & join groups |
| 18832 |
html = document.createDocumentFragment(); |
| 18833 |
for (i = 0, n = groups_order.length; i < n; i++) { |
| 18834 |
optgroup = groups_order[i]; |
| 18835 |
if (self.optgroups.hasOwnProperty(optgroup) && groups[optgroup].childNodes.length) { |
| 18836 |
// render the optgroup header and options within it, |
| 18837 |
// then pass it to the wrapper template |
| 18838 |
html_children = document.createDocumentFragment(); |
| 18839 |
html_children.appendChild(self.render('optgroup_header', self.optgroups[optgroup])); |
| 18840 |
html_children.appendChild(groups[optgroup]); |
| 18841 |
|
| 18842 |
html.appendChild(self.render('optgroup', $.extend({}, self.optgroups[optgroup], { |
| 18843 |
html: domToString(html_children), |
| 18844 |
dom: html_children |
| 18845 |
}))); |
| 18846 |
} else { |
| 18847 |
html.appendChild(groups[optgroup]); |
| 18848 |
} |
| 18849 |
} |
| 18850 |
|
| 18851 |
$dropdown_content.html(html); |
| 18852 |
|
| 18853 |
// highlight matching terms inline |
| 18854 |
if (self.settings.highlight && results.query.length && results.tokens.length) { |
| 18855 |
$dropdown_content.removeHighlight(); |
| 18856 |
for (i = 0, n = results.tokens.length; i < n; i++) { |
| 18857 |
highlight($dropdown_content, results.tokens[i].regex); |
| 18858 |
} |
| 18859 |
} |
| 18860 |
|
| 18861 |
// add "selected" class to selected options |
| 18862 |
if (!self.settings.hideSelected) { |
| 18863 |
for (i = 0, n = self.items.length; i < n; i++) { |
| 18864 |
self.getOption(self.items[i]).addClass('selected'); |
| 18865 |
} |
| 18866 |
} |
| 18867 |
|
| 18868 |
// add create option |
| 18869 |
has_create_option = self.canCreate(query); |
| 18870 |
if (has_create_option) { |
| 18871 |
$dropdown_content.prepend(self.render('option_create', {input: query})); |
| 18872 |
$create = $($dropdown_content[0].childNodes[0]); |
| 18873 |
} |
| 18874 |
|
| 18875 |
// activate |
| 18876 |
self.hasOptions = results.items.length > 0 || has_create_option; |
| 18877 |
if (self.hasOptions) { |
| 18878 |
if (results.items.length > 0) { |
| 18879 |
$active_before = active_before && self.getOption(active_before); |
| 18880 |
if ($active_before && $active_before.length) { |
| 18881 |
$active = $active_before; |
| 18882 |
} else if (self.settings.mode === 'single' && self.items.length) { |
| 18883 |
$active = self.getOption(self.items[0]); |
| 18884 |
} |
| 18885 |
if (!$active || !$active.length) { |
| 18886 |
if ($create && !self.settings.addPrecedence) { |
| 18887 |
$active = self.getAdjacentOption($create, 1); |
| 18888 |
} else { |
| 18889 |
$active = $dropdown_content.find('[data-selectable]:first'); |
| 18890 |
} |
| 18891 |
} |
| 18892 |
} else { |
| 18893 |
$active = $create; |
| 18894 |
} |
| 18895 |
self.setActiveOption($active); |
| 18896 |
if (triggerDropdown && !self.isOpen) { self.open(); } |
| 18897 |
} else { |
| 18898 |
self.setActiveOption(null); |
| 18899 |
if (triggerDropdown && self.isOpen) { self.close(); } |
| 18900 |
} |
| 18901 |
}, |
| 18902 |
|
| 18903 |
/** |
| 18904 |
* Adds an available option. If it already exists, |
| 18905 |
* nothing will happen. Note: this does not refresh |
| 18906 |
* the options list dropdown (use `refreshOptions` |
| 18907 |
* for that). |
| 18908 |
* |
| 18909 |
* Usage: |
| 18910 |
* |
| 18911 |
* this.addOption(data) |
| 18912 |
* |
| 18913 |
* @param {object|array} data |
| 18914 |
*/ |
| 18915 |
addOption: function(data) { |
| 18916 |
var i, n, value, self = this; |
| 18917 |
|
| 18918 |
if ($.isArray(data)) { |
| 18919 |
for (i = 0, n = data.length; i < n; i++) { |
| 18920 |
self.addOption(data[i]); |
| 18921 |
} |
| 18922 |
return; |
| 18923 |
} |
| 18924 |
|
| 18925 |
if (value = self.registerOption(data)) { |
| 18926 |
self.userOptions[value] = true; |
| 18927 |
self.lastQuery = null; |
| 18928 |
self.trigger('option_add', value, data); |
| 18929 |
} |
| 18930 |
}, |
| 18931 |
|
| 18932 |
/** |
| 18933 |
* Registers an option to the pool of options. |
| 18934 |
* |
| 18935 |
* @param {object} data |
| 18936 |
* @return {boolean|string} |
| 18937 |
*/ |
| 18938 |
registerOption: function(data) { |
| 18939 |
var key = hash_key(data[this.settings.valueField]); |
| 18940 |
if (typeof key === 'undefined' || key === null || this.options.hasOwnProperty(key)) return false; |
| 18941 |
data.$order = data.$order || ++this.order; |
| 18942 |
this.options[key] = data; |
| 18943 |
return key; |
| 18944 |
}, |
| 18945 |
|
| 18946 |
/** |
| 18947 |
* Registers an option group to the pool of option groups. |
| 18948 |
* |
| 18949 |
* @param {object} data |
| 18950 |
* @return {boolean|string} |
| 18951 |
*/ |
| 18952 |
registerOptionGroup: function(data) { |
| 18953 |
var key = hash_key(data[this.settings.optgroupValueField]); |
| 18954 |
if (!key) return false; |
| 18955 |
|
| 18956 |
data.$order = data.$order || ++this.order; |
| 18957 |
this.optgroups[key] = data; |
| 18958 |
return key; |
| 18959 |
}, |
| 18960 |
|
| 18961 |
/** |
| 18962 |
* Registers a new optgroup for options |
| 18963 |
* to be bucketed into. |
| 18964 |
* |
| 18965 |
* @param {string} id |
| 18966 |
* @param {object} data |
| 18967 |
*/ |
| 18968 |
addOptionGroup: function(id, data) { |
| 18969 |
data[this.settings.optgroupValueField] = id; |
| 18970 |
if (id = this.registerOptionGroup(data)) { |
| 18971 |
this.trigger('optgroup_add', id, data); |
| 18972 |
} |
| 18973 |
}, |
| 18974 |
|
| 18975 |
/** |
| 18976 |
* Removes an existing option group. |
| 18977 |
* |
| 18978 |
* @param {string} id |
| 18979 |
*/ |
| 18980 |
removeOptionGroup: function(id) { |
| 18981 |
if (this.optgroups.hasOwnProperty(id)) { |
| 18982 |
delete this.optgroups[id]; |
| 18983 |
this.renderCache = {}; |
| 18984 |
this.trigger('optgroup_remove', id); |
| 18985 |
} |
| 18986 |
}, |
| 18987 |
|
| 18988 |
/** |
| 18989 |
* Clears all existing option groups. |
| 18990 |
*/ |
| 18991 |
clearOptionGroups: function() { |
| 18992 |
this.optgroups = {}; |
| 18993 |
this.renderCache = {}; |
| 18994 |
this.trigger('optgroup_clear'); |
| 18995 |
}, |
| 18996 |
|
| 18997 |
/** |
| 18998 |
* Updates an option available for selection. If |
| 18999 |
* it is visible in the selected items or options |
| 19000 |
* dropdown, it will be re-rendered automatically. |
| 19001 |
* |
| 19002 |
* @param {string} value |
| 19003 |
* @param {object} data |
| 19004 |
*/ |
| 19005 |
updateOption: function(value, data) { |
| 19006 |
var self = this; |
| 19007 |
var $item, $item_new; |
| 19008 |
var value_new, index_item, cache_items, cache_options, order_old; |
| 19009 |
|
| 19010 |
value = hash_key(value); |
| 19011 |
value_new = hash_key(data[self.settings.valueField]); |
| 19012 |
|
| 19013 |
// sanity checks |
| 19014 |
if (value === null) return; |
| 19015 |
if (!self.options.hasOwnProperty(value)) return; |
| 19016 |
if (typeof value_new !== 'string') throw new Error('Value must be set in option data'); |
| 19017 |
|
| 19018 |
order_old = self.options[value].$order; |
| 19019 |
|
| 19020 |
// update references |
| 19021 |
if (value_new !== value) { |
| 19022 |
delete self.options[value]; |
| 19023 |
index_item = self.items.indexOf(value); |
| 19024 |
if (index_item !== -1) { |
| 19025 |
self.items.splice(index_item, 1, value_new); |
| 19026 |
} |
| 19027 |
} |
| 19028 |
data.$order = data.$order || order_old; |
| 19029 |
self.options[value_new] = data; |
| 19030 |
|
| 19031 |
// invalidate render cache |
| 19032 |
cache_items = self.renderCache['item']; |
| 19033 |
cache_options = self.renderCache['option']; |
| 19034 |
|
| 19035 |
if (cache_items) { |
| 19036 |
delete cache_items[value]; |
| 19037 |
delete cache_items[value_new]; |
| 19038 |
} |
| 19039 |
if (cache_options) { |
| 19040 |
delete cache_options[value]; |
| 19041 |
delete cache_options[value_new]; |
| 19042 |
} |
| 19043 |
|
| 19044 |
// update the item if it's selected |
| 19045 |
if (self.items.indexOf(value_new) !== -1) { |
| 19046 |
$item = self.getItem(value); |
| 19047 |
$item_new = $(self.render('item', data)); |
| 19048 |
if ($item.hasClass('active')) $item_new.addClass('active'); |
| 19049 |
$item.replaceWith($item_new); |
| 19050 |
} |
| 19051 |
|
| 19052 |
// invalidate last query because we might have updated the sortField |
| 19053 |
self.lastQuery = null; |
| 19054 |
|
| 19055 |
// update dropdown contents |
| 19056 |
if (self.isOpen) { |
| 19057 |
self.refreshOptions(false); |
| 19058 |
} |
| 19059 |
}, |
| 19060 |
|
| 19061 |
/** |
| 19062 |
* Removes a single option. |
| 19063 |
* |
| 19064 |
* @param {string} value |
| 19065 |
* @param {boolean} silent |
| 19066 |
*/ |
| 19067 |
removeOption: function(value, silent) { |
| 19068 |
var self = this; |
| 19069 |
value = hash_key(value); |
| 19070 |
|
| 19071 |
var cache_items = self.renderCache['item']; |
| 19072 |
var cache_options = self.renderCache['option']; |
| 19073 |
if (cache_items) delete cache_items[value]; |
| 19074 |
if (cache_options) delete cache_options[value]; |
| 19075 |
|
| 19076 |
delete self.userOptions[value]; |
| 19077 |
delete self.options[value]; |
| 19078 |
self.lastQuery = null; |
| 19079 |
self.trigger('option_remove', value); |
| 19080 |
self.removeItem(value, silent); |
| 19081 |
}, |
| 19082 |
|
| 19083 |
/** |
| 19084 |
* Clears all options. |
| 19085 |
*/ |
| 19086 |
clearOptions: function() { |
| 19087 |
var self = this; |
| 19088 |
|
| 19089 |
self.loadedSearches = {}; |
| 19090 |
self.userOptions = {}; |
| 19091 |
self.renderCache = {}; |
| 19092 |
self.options = self.sifter.items = {}; |
| 19093 |
self.lastQuery = null; |
| 19094 |
self.trigger('option_clear'); |
| 19095 |
self.clear(); |
| 19096 |
}, |
| 19097 |
|
| 19098 |
/** |
| 19099 |
* Returns the jQuery element of the option |
| 19100 |
* matching the given value. |
| 19101 |
* |
| 19102 |
* @param {string} value |
| 19103 |
* @returns {object} |
| 19104 |
*/ |
| 19105 |
getOption: function(value) { |
| 19106 |
return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]')); |
| 19107 |
}, |
| 19108 |
|
| 19109 |
/** |
| 19110 |
* Returns the jQuery element of the next or |
| 19111 |
* previous selectable option. |
| 19112 |
* |
| 19113 |
* @param {object} $option |
| 19114 |
* @param {int} direction can be 1 for next or -1 for previous |
| 19115 |
* @return {object} |
| 19116 |
*/ |
| 19117 |
getAdjacentOption: function($option, direction) { |
| 19118 |
var $options = this.$dropdown.find('[data-selectable]'); |
| 19119 |
var index = $options.index($option) + direction; |
| 19120 |
|
| 19121 |
return index >= 0 && index < $options.length ? $options.eq(index) : $(); |
| 19122 |
}, |
| 19123 |
|
| 19124 |
/** |
| 19125 |
* Finds the first element with a "data-value" attribute |
| 19126 |
* that matches the given value. |
| 19127 |
* |
| 19128 |
* @param {mixed} value |
| 19129 |
* @param {object} $els |
| 19130 |
* @return {object} |
| 19131 |
*/ |
| 19132 |
getElementWithValue: function(value, $els) { |
| 19133 |
value = hash_key(value); |
| 19134 |
|
| 19135 |
if (typeof value !== 'undefined' && value !== null) { |
| 19136 |
for (var i = 0, n = $els.length; i < n; i++) { |
| 19137 |
if ($els[i].getAttribute('data-value') === value) { |
| 19138 |
return $($els[i]); |
| 19139 |
} |
| 19140 |
} |
| 19141 |
} |
| 19142 |
|
| 19143 |
return $(); |
| 19144 |
}, |
| 19145 |
|
| 19146 |
/** |
| 19147 |
* Returns the jQuery element of the item |
| 19148 |
* matching the given value. |
| 19149 |
* |
| 19150 |
* @param {string} value |
| 19151 |
* @returns {object} |
| 19152 |
*/ |
| 19153 |
getItem: function(value) { |
| 19154 |
return this.getElementWithValue(value, this.$control.children()); |
| 19155 |
}, |
| 19156 |
|
| 19157 |
/** |
| 19158 |
* "Selects" multiple items at once. Adds them to the list |
| 19159 |
* at the current caret position. |
| 19160 |
* |
| 19161 |
* @param {string} value |
| 19162 |
* @param {boolean} silent |
| 19163 |
*/ |
| 19164 |
addItems: function(values, silent) { |
| 19165 |
var items = $.isArray(values) ? values : [values]; |
| 19166 |
for (var i = 0, n = items.length; i < n; i++) { |
| 19167 |
this.isPending = (i < n - 1); |
| 19168 |
this.addItem(items[i], silent); |
| 19169 |
} |
| 19170 |
}, |
| 19171 |
|
| 19172 |
/** |
| 19173 |
* "Selects" an item. Adds it to the list |
| 19174 |
* at the current caret position. |
| 19175 |
* |
| 19176 |
* @param {string} value |
| 19177 |
* @param {boolean} silent |
| 19178 |
*/ |
| 19179 |
addItem: function(value, silent) { |
| 19180 |
var events = silent ? [] : ['change']; |
| 19181 |
|
| 19182 |
debounce_events(this, events, function() { |
| 19183 |
var $item, $option, $options; |
| 19184 |
var self = this; |
| 19185 |
var inputMode = self.settings.mode; |
| 19186 |
var i, active, value_next, wasFull; |
| 19187 |
value = hash_key(value); |
| 19188 |
|
| 19189 |
if (self.items.indexOf(value) !== -1) { |
| 19190 |
if (inputMode === 'single') self.close(); |
| 19191 |
return; |
| 19192 |
} |
| 19193 |
|
| 19194 |
if (!self.options.hasOwnProperty(value)) return; |
| 19195 |
if (inputMode === 'single') self.clear(silent); |
| 19196 |
if (inputMode === 'multi' && self.isFull()) return; |
| 19197 |
|
| 19198 |
$item = $(self.render('item', self.options[value])); |
| 19199 |
wasFull = self.isFull(); |
| 19200 |
self.items.splice(self.caretPos, 0, value); |
| 19201 |
self.insertAtCaret($item); |
| 19202 |
if (!self.isPending || (!wasFull && self.isFull())) { |
| 19203 |
self.refreshState(); |
| 19204 |
} |
| 19205 |
|
| 19206 |
if (self.isSetup) { |
| 19207 |
$options = self.$dropdown_content.find('[data-selectable]'); |
| 19208 |
|
| 19209 |
// update menu / remove the option (if this is not one item being added as part of series) |
| 19210 |
if (!self.isPending) { |
| 19211 |
$option = self.getOption(value); |
| 19212 |
value_next = self.getAdjacentOption($option, 1).attr('data-value'); |
| 19213 |
self.refreshOptions(self.isFocused && inputMode !== 'single'); |
| 19214 |
if (value_next) { |
| 19215 |
self.setActiveOption(self.getOption(value_next)); |
| 19216 |
} |
| 19217 |
} |
| 19218 |
|
| 19219 |
// hide the menu if the maximum number of items have been selected or no options are left |
| 19220 |
if (!$options.length || self.isFull()) { |
| 19221 |
self.close(); |
| 19222 |
} else { |
| 19223 |
self.positionDropdown(); |
| 19224 |
} |
| 19225 |
|
| 19226 |
self.updatePlaceholder(); |
| 19227 |
self.trigger('item_add', value, $item); |
| 19228 |
self.updateOriginalInput({silent: silent}); |
| 19229 |
} |
| 19230 |
}); |
| 19231 |
}, |
| 19232 |
|
| 19233 |
/** |
| 19234 |
* Removes the selected item matching |
| 19235 |
* the provided value. |
| 19236 |
* |
| 19237 |
* @param {string} value |
| 19238 |
*/ |
| 19239 |
removeItem: function(value, silent) { |
| 19240 |
var self = this; |
| 19241 |
var $item, i, idx; |
| 19242 |
|
| 19243 |
$item = (value instanceof $) ? value : self.getItem(value); |
| 19244 |
value = hash_key($item.attr('data-value')); |
| 19245 |
i = self.items.indexOf(value); |
| 19246 |
|
| 19247 |
if (i !== -1) { |
| 19248 |
$item.remove(); |
| 19249 |
if ($item.hasClass('active')) { |
| 19250 |
idx = self.$activeItems.indexOf($item[0]); |
| 19251 |
self.$activeItems.splice(idx, 1); |
| 19252 |
} |
| 19253 |
|
| 19254 |
self.items.splice(i, 1); |
| 19255 |
self.lastQuery = null; |
| 19256 |
if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) { |
| 19257 |
self.removeOption(value, silent); |
| 19258 |
} |
| 19259 |
|
| 19260 |
if (i < self.caretPos) { |
| 19261 |
self.setCaret(self.caretPos - 1); |
| 19262 |
} |
| 19263 |
|
| 19264 |
self.refreshState(); |
| 19265 |
self.updatePlaceholder(); |
| 19266 |
self.updateOriginalInput({silent: silent}); |
| 19267 |
self.positionDropdown(); |
| 19268 |
self.trigger('item_remove', value, $item); |
| 19269 |
} |
| 19270 |
}, |
| 19271 |
|
| 19272 |
/** |
| 19273 |
* Invokes the `create` method provided in the |
| 19274 |
* selectize options that should provide the data |
| 19275 |
* for the new item, given the user input. |
| 19276 |
* |
| 19277 |
* Once this completes, it will be added |
| 19278 |
* to the item list. |
| 19279 |
* |
| 19280 |
* @param {string} value |
| 19281 |
* @param {boolean} [triggerDropdown] |
| 19282 |
* @param {function} [callback] |
| 19283 |
* @return {boolean} |
| 19284 |
*/ |
| 19285 |
createItem: function(input, triggerDropdown) { |
| 19286 |
var self = this; |
| 19287 |
var caret = self.caretPos; |
| 19288 |
input = input || $.trim(self.$control_input.val() || ''); |
| 19289 |
|
| 19290 |
var callback = arguments[arguments.length - 1]; |
| 19291 |
if (typeof callback !== 'function') callback = function() {}; |
| 19292 |
|
| 19293 |
if (typeof triggerDropdown !== 'boolean') { |
| 19294 |
triggerDropdown = true; |
| 19295 |
} |
| 19296 |
|
| 19297 |
if (!self.canCreate(input)) { |
| 19298 |
callback(); |
| 19299 |
return false; |
| 19300 |
} |
| 19301 |
|
| 19302 |
self.lock(); |
| 19303 |
|
| 19304 |
var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) { |
| 19305 |
var data = {}; |
| 19306 |
data[self.settings.labelField] = input; |
| 19307 |
data[self.settings.valueField] = input; |
| 19308 |
return data; |
| 19309 |
}; |
| 19310 |
|
| 19311 |
var create = once(function(data) { |
| 19312 |
self.unlock(); |
| 19313 |
|
| 19314 |
if (!data || typeof data !== 'object') return callback(); |
| 19315 |
var value = hash_key(data[self.settings.valueField]); |
| 19316 |
if (typeof value !== 'string') return callback(); |
| 19317 |
|
| 19318 |
self.setTextboxValue(''); |
| 19319 |
self.addOption(data); |
| 19320 |
self.setCaret(caret); |
| 19321 |
self.addItem(value); |
| 19322 |
self.refreshOptions(triggerDropdown && self.settings.mode !== 'single'); |
| 19323 |
callback(data); |
| 19324 |
}); |
| 19325 |
|
| 19326 |
var output = setup.apply(this, [input, create]); |
| 19327 |
if (typeof output !== 'undefined') { |
| 19328 |
create(output); |
| 19329 |
} |
| 19330 |
|
| 19331 |
return true; |
| 19332 |
}, |
| 19333 |
|
| 19334 |
/** |
| 19335 |
* Re-renders the selected item lists. |
| 19336 |
*/ |
| 19337 |
refreshItems: function() { |
| 19338 |
this.lastQuery = null; |
| 19339 |
|
| 19340 |
if (this.isSetup) { |
| 19341 |
this.addItem(this.items); |
| 19342 |
} |
| 19343 |
|
| 19344 |
this.refreshState(); |
| 19345 |
this.updateOriginalInput(); |
| 19346 |
}, |
| 19347 |
|
| 19348 |
/** |
| 19349 |
* Updates all state-dependent attributes |
| 19350 |
* and CSS classes. |
| 19351 |
*/ |
| 19352 |
refreshState: function() { |
| 19353 |
this.refreshValidityState(); |
| 19354 |
this.refreshClasses(); |
| 19355 |
}, |
| 19356 |
|
| 19357 |
/** |
| 19358 |
* Update the `required` attribute of both input and control input. |
| 19359 |
* |
| 19360 |
* The `required` property needs to be activated on the control input |
| 19361 |
* for the error to be displayed at the right place. `required` also |
| 19362 |
* needs to be temporarily deactivated on the input since the input is |
| 19363 |
* hidden and can't show errors. |
| 19364 |
*/ |
| 19365 |
refreshValidityState: function() { |
| 19366 |
if (!this.isRequired) return false; |
| 19367 |
|
| 19368 |
var invalid = !this.items.length; |
| 19369 |
|
| 19370 |
this.isInvalid = invalid; |
| 19371 |
this.$control_input.prop('required', invalid); |
| 19372 |
this.$input.prop('required', !invalid); |
| 19373 |
}, |
| 19374 |
|
| 19375 |
/** |
| 19376 |
* Updates all state-dependent CSS classes. |
| 19377 |
*/ |
| 19378 |
refreshClasses: function() { |
| 19379 |
var self = this; |
| 19380 |
var isFull = self.isFull(); |
| 19381 |
var isLocked = self.isLocked; |
| 19382 |
|
| 19383 |
self.$wrapper |
| 19384 |
.toggleClass('rtl', self.rtl); |
| 19385 |
|
| 19386 |
self.$control |
| 19387 |
.toggleClass('focus', self.isFocused) |
| 19388 |
.toggleClass('disabled', self.isDisabled) |
| 19389 |
.toggleClass('required', self.isRequired) |
| 19390 |
.toggleClass('invalid', self.isInvalid) |
| 19391 |
.toggleClass('locked', isLocked) |
| 19392 |
.toggleClass('full', isFull).toggleClass('not-full', !isFull) |
| 19393 |
.toggleClass('input-active', self.isFocused && !self.isInputHidden) |
| 19394 |
.toggleClass('dropdown-active', self.isOpen) |
| 19395 |
.toggleClass('has-options', !$.isEmptyObject(self.options)) |
| 19396 |
.toggleClass('has-items', self.items.length > 0); |
| 19397 |
|
| 19398 |
self.$control_input.data('grow', !isFull && !isLocked); |
| 19399 |
}, |
| 19400 |
|
| 19401 |
/** |
| 19402 |
* Determines whether or not more items can be added |
| 19403 |
* to the control without exceeding the user-defined maximum. |
| 19404 |
* |
| 19405 |
* @returns {boolean} |
| 19406 |
*/ |
| 19407 |
isFull: function() { |
| 19408 |
return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems; |
| 19409 |
}, |
| 19410 |
|
| 19411 |
/** |
| 19412 |
* Refreshes the original <select> or <input> |
| 19413 |
* element to reflect the current state. |
| 19414 |
*/ |
| 19415 |
updateOriginalInput: function(opts) { |
| 19416 |
var i, n, options, label, self = this; |
| 19417 |
opts = opts || {}; |
| 19418 |
|
| 19419 |
if (self.tagType === TAG_SELECT) { |
| 19420 |
options = []; |
| 19421 |
for (i = 0, n = self.items.length; i < n; i++) { |
| 19422 |
label = self.options[self.items[i]][self.settings.labelField] || ''; |
| 19423 |
options.push('<option value="' + escape_html(self.items[i]) + '" selected="selected">' + escape_html(label) + '</option>'); |
| 19424 |
} |
| 19425 |
if (!options.length && !this.$input.attr('multiple')) { |
| 19426 |
options.push('<option value="" selected="selected"></option>'); |
| 19427 |
} |
| 19428 |
self.$input.html(options.join('')); |
| 19429 |
} else { |
| 19430 |
self.$input.val(self.getValue()); |
| 19431 |
self.$input.attr('value',self.$input.val()); |
| 19432 |
} |
| 19433 |
|
| 19434 |
if (self.isSetup) { |
| 19435 |
if (!opts.silent) { |
| 19436 |
self.trigger('change', self.$input.val()); |
| 19437 |
} |
| 19438 |
} |
| 19439 |
}, |
| 19440 |
|
| 19441 |
/** |
| 19442 |
* Shows/hide the input placeholder depending |
| 19443 |
* on if there items in the list already. |
| 19444 |
*/ |
| 19445 |
updatePlaceholder: function() { |
| 19446 |
if (!this.settings.placeholder) return; |
| 19447 |
var $input = this.$control_input; |
| 19448 |
|
| 19449 |
if (this.items.length) { |
| 19450 |
$input.removeAttr('placeholder'); |
| 19451 |
} else { |
| 19452 |
$input.attr('placeholder', this.settings.placeholder); |
| 19453 |
} |
| 19454 |
$input.triggerHandler('update', {force: true}); |
| 19455 |
}, |
| 19456 |
|
| 19457 |
/** |
| 19458 |
* Shows the autocomplete dropdown containing |
| 19459 |
* the available options. |
| 19460 |
*/ |
| 19461 |
open: function() { |
| 19462 |
var self = this; |
| 19463 |
|
| 19464 |
if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return; |
| 19465 |
self.focus(); |
| 19466 |
self.isOpen = true; |
| 19467 |
self.refreshState(); |
| 19468 |
self.$dropdown.css({visibility: 'hidden', display: 'block'}); |
| 19469 |
self.positionDropdown(); |
| 19470 |
self.$dropdown.css({visibility: 'visible'}); |
| 19471 |
self.trigger('dropdown_open', self.$dropdown); |
| 19472 |
}, |
| 19473 |
|
| 19474 |
/** |
| 19475 |
* Closes the autocomplete dropdown menu. |
| 19476 |
*/ |
| 19477 |
close: function() { |
| 19478 |
var self = this; |
| 19479 |
var trigger = self.isOpen; |
| 19480 |
|
| 19481 |
if (self.settings.mode === 'single' && self.items.length) { |
| 19482 |
self.hideInput(); |
| 19483 |
self.$control_input.blur(); // close keyboard on iOS |
| 19484 |
} |
| 19485 |
|
| 19486 |
self.isOpen = false; |
| 19487 |
self.$dropdown.hide(); |
| 19488 |
self.setActiveOption(null); |
| 19489 |
self.refreshState(); |
| 19490 |
|
| 19491 |
if (trigger) self.trigger('dropdown_close', self.$dropdown); |
| 19492 |
}, |
| 19493 |
|
| 19494 |
/** |
| 19495 |
* Calculates and applies the appropriate |
| 19496 |
* position of the dropdown. |
| 19497 |
*/ |
| 19498 |
positionDropdown: function() { |
| 19499 |
var $control = this.$control; |
| 19500 |
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position(); |
| 19501 |
offset.top += $control.outerHeight(true); |
| 19502 |
|
| 19503 |
this.$dropdown.css({ |
| 19504 |
width : $control.outerWidth(), |
| 19505 |
top : offset.top, |
| 19506 |
left : offset.left |
| 19507 |
}); |
| 19508 |
}, |
| 19509 |
|
| 19510 |
/** |
| 19511 |
* Resets / clears all selected items |
| 19512 |
* from the control. |
| 19513 |
* |
| 19514 |
* @param {boolean} silent |
| 19515 |
*/ |
| 19516 |
clear: function(silent) { |
| 19517 |
var self = this; |
| 19518 |
|
| 19519 |
if (!self.items.length) return; |
| 19520 |
self.$control.children(':not(input)').remove(); |
| 19521 |
self.items = []; |
| 19522 |
self.lastQuery = null; |
| 19523 |
self.setCaret(0); |
| 19524 |
self.setActiveItem(null); |
| 19525 |
self.updatePlaceholder(); |
| 19526 |
self.updateOriginalInput({silent: silent}); |
| 19527 |
self.refreshState(); |
| 19528 |
self.showInput(); |
| 19529 |
self.trigger('clear'); |
| 19530 |
}, |
| 19531 |
|
| 19532 |
/** |
| 19533 |
* A helper method for inserting an element |
| 19534 |
* at the current caret position. |
| 19535 |
* |
| 19536 |
* @param {object} $el |
| 19537 |
*/ |
| 19538 |
insertAtCaret: function($el) { |
| 19539 |
var caret = Math.min(this.caretPos, this.items.length); |
| 19540 |
if (caret === 0) { |
| 19541 |
this.$control.prepend($el); |
| 19542 |
} else { |
| 19543 |
$(this.$control[0].childNodes[caret]).before($el); |
| 19544 |
} |
| 19545 |
this.setCaret(caret + 1); |
| 19546 |
}, |
| 19547 |
|
| 19548 |
/** |
| 19549 |
* Removes the current selected item(s). |
| 19550 |
* |
| 19551 |
* @param {object} e (optional) |
| 19552 |
* @returns {boolean} |
| 19553 |
*/ |
| 19554 |
deleteSelection: function(e) { |
| 19555 |
var i, n, direction, selection, values, caret, option_select, $option_select, $tail; |
| 19556 |
var self = this; |
| 19557 |
|
| 19558 |
direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1; |
| 19559 |
selection = getSelection(self.$control_input[0]); |
| 19560 |
|
| 19561 |
if (self.$activeOption && !self.settings.hideSelected) { |
| 19562 |
option_select = self.getAdjacentOption(self.$activeOption, -1).attr('data-value'); |
| 19563 |
} |
| 19564 |
|
| 19565 |
// determine items that will be removed |
| 19566 |
values = []; |
| 19567 |
|
| 19568 |
if (self.$activeItems.length) { |
| 19569 |
$tail = self.$control.children('.active:' + (direction > 0 ? 'last' : 'first')); |
| 19570 |
caret = self.$control.children(':not(input)').index($tail); |
| 19571 |
if (direction > 0) { caret++; } |
| 19572 |
|
| 19573 |
for (i = 0, n = self.$activeItems.length; i < n; i++) { |
| 19574 |
values.push($(self.$activeItems[i]).attr('data-value')); |
| 19575 |
} |
| 19576 |
if (e) { |
| 19577 |
e.preventDefault(); |
| 19578 |
e.stopPropagation(); |
| 19579 |
} |
| 19580 |
} else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) { |
| 19581 |
if (direction < 0 && selection.start === 0 && selection.length === 0) { |
| 19582 |
values.push(self.items[self.caretPos - 1]); |
| 19583 |
} else if (direction > 0 && selection.start === self.$control_input.val().length) { |
| 19584 |
values.push(self.items[self.caretPos]); |
| 19585 |
} |
| 19586 |
} |
| 19587 |
|
| 19588 |
// allow the callback to abort |
| 19589 |
if (!values.length || (typeof self.settings.onDelete === 'function' && self.settings.onDelete.apply(self, [values]) === false)) { |
| 19590 |
return false; |
| 19591 |
} |
| 19592 |
|
| 19593 |
// perform removal |
| 19594 |
if (typeof caret !== 'undefined') { |
| 19595 |
self.setCaret(caret); |
| 19596 |
} |
| 19597 |
while (values.length) { |
| 19598 |
self.removeItem(values.pop()); |
| 19599 |
} |
| 19600 |
|
| 19601 |
self.showInput(); |
| 19602 |
self.positionDropdown(); |
| 19603 |
self.refreshOptions(true); |
| 19604 |
|
| 19605 |
// select previous option |
| 19606 |
if (option_select) { |
| 19607 |
$option_select = self.getOption(option_select); |
| 19608 |
if ($option_select.length) { |
| 19609 |
self.setActiveOption($option_select); |
| 19610 |
} |
| 19611 |
} |
| 19612 |
|
| 19613 |
return true; |
| 19614 |
}, |
| 19615 |
|
| 19616 |
/** |
| 19617 |
* Selects the previous / next item (depending |
| 19618 |
* on the `direction` argument). |
| 19619 |
* |
| 19620 |
* > 0 - right |
| 19621 |
* < 0 - left |
| 19622 |
* |
| 19623 |
* @param {int} direction |
| 19624 |
* @param {object} e (optional) |
| 19625 |
*/ |
| 19626 |
advanceSelection: function(direction, e) { |
| 19627 |
var tail, selection, idx, valueLength, cursorAtEdge, $tail; |
| 19628 |
var self = this; |
| 19629 |
|
| 19630 |
if (direction === 0) return; |
| 19631 |
if (self.rtl) direction *= -1; |
| 19632 |
|
| 19633 |
tail = direction > 0 ? 'last' : 'first'; |
| 19634 |
selection = getSelection(self.$control_input[0]); |
| 19635 |
|
| 19636 |
if (self.isFocused && !self.isInputHidden) { |
| 19637 |
valueLength = self.$control_input.val().length; |
| 19638 |
cursorAtEdge = direction < 0 |
| 19639 |
? selection.start === 0 && selection.length === 0 |
| 19640 |
: selection.start === valueLength; |
| 19641 |
|
| 19642 |
if (cursorAtEdge && !valueLength) { |
| 19643 |
self.advanceCaret(direction, e); |
| 19644 |
} |
| 19645 |
} else { |
| 19646 |
$tail = self.$control.children('.active:' + tail); |
| 19647 |
if ($tail.length) { |
| 19648 |
idx = self.$control.children(':not(input)').index($tail); |
| 19649 |
self.setActiveItem(null); |
| 19650 |
self.setCaret(direction > 0 ? idx + 1 : idx); |
| 19651 |
} |
| 19652 |
} |
| 19653 |
}, |
| 19654 |
|
| 19655 |
/** |
| 19656 |
* Moves the caret left / right. |
| 19657 |
* |
| 19658 |
* @param {int} direction |
| 19659 |
* @param {object} e (optional) |
| 19660 |
*/ |
| 19661 |
advanceCaret: function(direction, e) { |
| 19662 |
var self = this, fn, $adj; |
| 19663 |
|
| 19664 |
if (direction === 0) return; |
| 19665 |
|
| 19666 |
fn = direction > 0 ? 'next' : 'prev'; |
| 19667 |
if (self.isShiftDown) { |
| 19668 |
$adj = self.$control_input[fn](); |
| 19669 |
if ($adj.length) { |
| 19670 |
self.hideInput(); |
| 19671 |
self.setActiveItem($adj); |
| 19672 |
e && e.preventDefault(); |
| 19673 |
} |
| 19674 |
} else { |
| 19675 |
self.setCaret(self.caretPos + direction); |
| 19676 |
} |
| 19677 |
}, |
| 19678 |
|
| 19679 |
/** |
| 19680 |
* Moves the caret to the specified index. |
| 19681 |
* |
| 19682 |
* @param {int} i |
| 19683 |
*/ |
| 19684 |
setCaret: function(i) { |
| 19685 |
var self = this; |
| 19686 |
|
| 19687 |
if (self.settings.mode === 'single') { |
| 19688 |
i = self.items.length; |
| 19689 |
} else { |
| 19690 |
i = Math.max(0, Math.min(self.items.length, i)); |
| 19691 |
} |
| 19692 |
|
| 19693 |
if(!self.isPending) { |
| 19694 |
// the input must be moved by leaving it in place and moving the |
| 19695 |
// siblings, due to the fact that focus cannot be restored once lost |
| 19696 |
// on mobile webkit devices |
| 19697 |
var j, n, fn, $children, $child; |
| 19698 |
$children = self.$control.children(':not(input)'); |
| 19699 |
for (j = 0, n = $children.length; j < n; j++) { |
| 19700 |
$child = $($children[j]).detach(); |
| 19701 |
if (j < i) { |
| 19702 |
self.$control_input.before($child); |
| 19703 |
} else { |
| 19704 |
self.$control.append($child); |
| 19705 |
} |
| 19706 |
} |
| 19707 |
} |
| 19708 |
|
| 19709 |
self.caretPos = i; |
| 19710 |
}, |
| 19711 |
|
| 19712 |
/** |
| 19713 |
* Disables user input on the control. Used while |
| 19714 |
* items are being asynchronously created. |
| 19715 |
*/ |
| 19716 |
lock: function() { |
| 19717 |
this.close(); |
| 19718 |
this.isLocked = true; |
| 19719 |
this.refreshState(); |
| 19720 |
}, |
| 19721 |
|
| 19722 |
/** |
| 19723 |
* Re-enables user input on the control. |
| 19724 |
*/ |
| 19725 |
unlock: function() { |
| 19726 |
this.isLocked = false; |
| 19727 |
this.refreshState(); |
| 19728 |
}, |
| 19729 |
|
| 19730 |
/** |
| 19731 |
* Disables user input on the control completely. |
| 19732 |
* While disabled, it cannot receive focus. |
| 19733 |
*/ |
| 19734 |
disable: function() { |
| 19735 |
var self = this; |
| 19736 |
self.$input.prop('disabled', true); |
| 19737 |
self.$control_input.prop('disabled', true).prop('tabindex', -1); |
| 19738 |
self.isDisabled = true; |
| 19739 |
self.lock(); |
| 19740 |
}, |
| 19741 |
|
| 19742 |
/** |
| 19743 |
* Enables the control so that it can respond |
| 19744 |
* to focus and user input. |
| 19745 |
*/ |
| 19746 |
enable: function() { |
| 19747 |
var self = this; |
| 19748 |
self.$input.prop('disabled', false); |
| 19749 |
self.$control_input.prop('disabled', false).prop('tabindex', self.tabIndex); |
| 19750 |
self.isDisabled = false; |
| 19751 |
self.unlock(); |
| 19752 |
}, |
| 19753 |
|
| 19754 |
/** |
| 19755 |
* Completely destroys the control and |
| 19756 |
* unbinds all event listeners so that it can |
| 19757 |
* be garbage collected. |
| 19758 |
*/ |
| 19759 |
destroy: function() { |
| 19760 |
var self = this; |
| 19761 |
var eventNS = self.eventNS; |
| 19762 |
var revertSettings = self.revertSettings; |
| 19763 |
|
| 19764 |
self.trigger('destroy'); |
| 19765 |
self.off(); |
| 19766 |
self.$wrapper.remove(); |
| 19767 |
self.$dropdown.remove(); |
| 19768 |
|
| 19769 |
self.$input |
| 19770 |
.html('') |
| 19771 |
.append(revertSettings.$children) |
| 19772 |
.removeAttr('tabindex') |
| 19773 |
.removeClass('selectized') |
| 19774 |
.attr({tabindex: revertSettings.tabindex}) |
| 19775 |
.show(); |
| 19776 |
|
| 19777 |
self.$control_input.removeData('grow'); |
| 19778 |
self.$input.removeData('selectize'); |
| 19779 |
|
| 19780 |
$(window).off(eventNS); |
| 19781 |
$(document).off(eventNS); |
| 19782 |
$(document.body).off(eventNS); |
| 19783 |
|
| 19784 |
delete self.$input[0].selectize; |
| 19785 |
}, |
| 19786 |
|
| 19787 |
/** |
| 19788 |
* A helper method for rendering "item" and |
| 19789 |
* "option" templates, given the data. |
| 19790 |
* |
| 19791 |
* @param {string} templateName |
| 19792 |
* @param {object} data |
| 19793 |
* @returns {string} |
| 19794 |
*/ |
| 19795 |
render: function(templateName, data) { |
| 19796 |
var value, id, label; |
| 19797 |
var html = ''; |
| 19798 |
var cache = false; |
| 19799 |
var self = this; |
| 19800 |
var regex_tag = /^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i; |
| 19801 |
|
| 19802 |
if (templateName === 'option' || templateName === 'item') { |
| 19803 |
value = hash_key(data[self.settings.valueField]); |
| 19804 |
cache = !!value; |
| 19805 |
} |
| 19806 |
|
| 19807 |
// pull markup from cache if it exists |
| 19808 |
if (cache) { |
| 19809 |
if (!isset(self.renderCache[templateName])) { |
| 19810 |
self.renderCache[templateName] = {}; |
| 19811 |
} |
| 19812 |
if (self.renderCache[templateName].hasOwnProperty(value)) { |
| 19813 |
return self.renderCache[templateName][value]; |
| 19814 |
} |
| 19815 |
} |
| 19816 |
|
| 19817 |
// render markup |
| 19818 |
html = $(self.settings.render[templateName].apply(this, [data, escape_html])); |
| 19819 |
|
| 19820 |
// add mandatory attributes |
| 19821 |
if (templateName === 'option' || templateName === 'option_create') { |
| 19822 |
html.attr('data-selectable', ''); |
| 19823 |
} |
| 19824 |
else if (templateName === 'optgroup') { |
| 19825 |
id = data[self.settings.optgroupValueField] || ''; |
| 19826 |
html.attr('data-group', id); |
| 19827 |
} |
| 19828 |
if (templateName === 'option' || templateName === 'item') { |
| 19829 |
html.attr('data-value', value || ''); |
| 19830 |
} |
| 19831 |
|
| 19832 |
// update cache |
| 19833 |
if (cache) { |
| 19834 |
self.renderCache[templateName][value] = html[0]; |
| 19835 |
} |
| 19836 |
|
| 19837 |
return html[0]; |
| 19838 |
}, |
| 19839 |
|
| 19840 |
/** |
| 19841 |
* Clears the render cache for a template. If |
| 19842 |
* no template is given, clears all render |
| 19843 |
* caches. |
| 19844 |
* |
| 19845 |
* @param {string} templateName |
| 19846 |
*/ |
| 19847 |
clearCache: function(templateName) { |
| 19848 |
var self = this; |
| 19849 |
if (typeof templateName === 'undefined') { |
| 19850 |
self.renderCache = {}; |
| 19851 |
} else { |
| 19852 |
delete self.renderCache[templateName]; |
| 19853 |
} |
| 19854 |
}, |
| 19855 |
|
| 19856 |
/** |
| 19857 |
* Determines whether or not to display the |
| 19858 |
* create item prompt, given a user input. |
| 19859 |
* |
| 19860 |
* @param {string} input |
| 19861 |
* @return {boolean} |
| 19862 |
*/ |
| 19863 |
canCreate: function(input) { |
| 19864 |
var self = this; |
| 19865 |
if (!self.settings.create) return false; |
| 19866 |
var filter = self.settings.createFilter; |
| 19867 |
return input.length |
| 19868 |
&& (typeof filter !== 'function' || filter.apply(self, [input])) |
| 19869 |
&& (typeof filter !== 'string' || new RegExp(filter).test(input)) |
| 19870 |
&& (!(filter instanceof RegExp) || filter.test(input)); |
| 19871 |
} |
| 19872 |
|
| 19873 |
}); |
| 19874 |
|
| 19875 |
|
| 19876 |
Selectize.count = 0; |
| 19877 |
Selectize.defaults = { |
| 19878 |
options: [], |
| 19879 |
optgroups: [], |
| 19880 |
|
| 19881 |
plugins: [], |
| 19882 |
delimiter: ',', |
| 19883 |
splitOn: null, // regexp or string for splitting up values from a paste command |
| 19884 |
persist: true, |
| 19885 |
diacritics: true, |
| 19886 |
create: false, |
| 19887 |
createOnBlur: false, |
| 19888 |
createFilter: null, |
| 19889 |
highlight: true, |
| 19890 |
openOnFocus: true, |
| 19891 |
maxOptions: 1000, |
| 19892 |
maxItems: null, |
| 19893 |
hideSelected: null, |
| 19894 |
addPrecedence: false, |
| 19895 |
selectOnTab: false, |
| 19896 |
preload: false, |
| 19897 |
allowEmptyOption: false, |
| 19898 |
closeAfterSelect: false, |
| 19899 |
|
| 19900 |
scrollDuration: 60, |
| 19901 |
loadThrottle: 300, |
| 19902 |
loadingClass: 'loading', |
| 19903 |
|
| 19904 |
dataAttr: 'data-data', |
| 19905 |
optgroupField: 'optgroup', |
| 19906 |
valueField: 'value', |
| 19907 |
labelField: 'text', |
| 19908 |
optgroupLabelField: 'label', |
| 19909 |
optgroupValueField: 'value', |
| 19910 |
lockOptgroupOrder: false, |
| 19911 |
|
| 19912 |
sortField: '$order', |
| 19913 |
searchField: ['text'], |
| 19914 |
searchConjunction: 'and', |
| 19915 |
|
| 19916 |
mode: null, |
| 19917 |
wrapperClass: 'selectize-control', |
| 19918 |
inputClass: 'selectize-input', |
| 19919 |
dropdownClass: 'selectize-dropdown', |
| 19920 |
dropdownContentClass: 'selectize-dropdown-content', |
| 19921 |
|
| 19922 |
dropdownParent: null, |
| 19923 |
|
| 19924 |
copyClassesToDropdown: true, |
| 19925 |
|
| 19926 |
/* |
| 19927 |
load : null, // function(query, callback) { ... } |
| 19928 |
score : null, // function(search) { ... } |
| 19929 |
onInitialize : null, // function() { ... } |
| 19930 |
onChange : null, // function(value) { ... } |
| 19931 |
onItemAdd : null, // function(value, $item) { ... } |
| 19932 |
onItemRemove : null, // function(value) { ... } |
| 19933 |
onClear : null, // function() { ... } |
| 19934 |
onOptionAdd : null, // function(value, data) { ... } |
| 19935 |
onOptionRemove : null, // function(value) { ... } |
| 19936 |
onOptionClear : null, // function() { ... } |
| 19937 |
onOptionGroupAdd : null, // function(id, data) { ... } |
| 19938 |
onOptionGroupRemove : null, // function(id) { ... } |
| 19939 |
onOptionGroupClear : null, // function() { ... } |
| 19940 |
onDropdownOpen : null, // function($dropdown) { ... } |
| 19941 |
onDropdownClose : null, // function($dropdown) { ... } |
| 19942 |
onType : null, // function(str) { ... } |
| 19943 |
onDelete : null, // function(values) { ... } |
| 19944 |
*/ |
| 19945 |
|
| 19946 |
render: { |
| 19947 |
/* |
| 19948 |
item: null, |
| 19949 |
optgroup: null, |
| 19950 |
optgroup_header: null, |
| 19951 |
option: null, |
| 19952 |
option_create: null |
| 19953 |
*/ |
| 19954 |
} |
| 19955 |
}; |
| 19956 |
|
| 19957 |
|
| 19958 |
$.fn.selectize = function(settings_user) { |
| 19959 |
var defaults = $.fn.selectize.defaults; |
| 19960 |
var settings = $.extend({}, defaults, settings_user); |
| 19961 |
var attr_data = settings.dataAttr; |
| 19962 |
var field_label = settings.labelField; |
| 19963 |
var field_value = settings.valueField; |
| 19964 |
var field_optgroup = settings.optgroupField; |
| 19965 |
var field_optgroup_label = settings.optgroupLabelField; |
| 19966 |
var field_optgroup_value = settings.optgroupValueField; |
| 19967 |
|
| 19968 |
/** |
| 19969 |
* Initializes selectize from a <input type="text"> element. |
| 19970 |
* |
| 19971 |
* @param {object} $input |
| 19972 |
* @param {object} settings_element |
| 19973 |
*/ |
| 19974 |
var init_textbox = function($input, settings_element) { |
| 19975 |
var i, n, values, option; |
| 19976 |
|
| 19977 |
var data_raw = $input.attr(attr_data); |
| 19978 |
|
| 19979 |
if (!data_raw) { |
| 19980 |
var value = $.trim($input.val() || ''); |
| 19981 |
if (!settings.allowEmptyOption && !value.length) return; |
| 19982 |
values = value.split(settings.delimiter); |
| 19983 |
for (i = 0, n = values.length; i < n; i++) { |
| 19984 |
option = {}; |
| 19985 |
option[field_label] = values[i]; |
| 19986 |
option[field_value] = values[i]; |
| 19987 |
settings_element.options.push(option); |
| 19988 |
} |
| 19989 |
settings_element.items = values; |
| 19990 |
} else { |
| 19991 |
settings_element.options = JSON.parse(data_raw); |
| 19992 |
for (i = 0, n = settings_element.options.length; i < n; i++) { |
| 19993 |
settings_element.items.push(settings_element.options[i][field_value]); |
| 19994 |
} |
| 19995 |
} |
| 19996 |
}; |
| 19997 |
|
| 19998 |
/** |
| 19999 |
* Initializes selectize from a <select> element. |
| 20000 |
* |
| 20001 |
* @param {object} $input |
| 20002 |
* @param {object} settings_element |
| 20003 |
*/ |
| 20004 |
var init_select = function($input, settings_element) { |
| 20005 |
var i, n, tagName, $children, order = 0; |
| 20006 |
var options = settings_element.options; |
| 20007 |
var optionsMap = {}; |
| 20008 |
|
| 20009 |
var readData = function($el) { |
| 20010 |
var data = attr_data && $el.attr(attr_data); |
| 20011 |
if (typeof data === 'string' && data.length) { |
| 20012 |
return JSON.parse(data); |
| 20013 |
} |
| 20014 |
return null; |
| 20015 |
}; |
| 20016 |
|
| 20017 |
var addOption = function($option, group) { |
| 20018 |
$option = $($option); |
| 20019 |
|
| 20020 |
var value = hash_key($option.val()); |
| 20021 |
if (!value && !settings.allowEmptyOption) return; |
| 20022 |
|
| 20023 |
// if the option already exists, it's probably been |
| 20024 |
// duplicated in another optgroup. in this case, push |
| 20025 |
// the current group to the "optgroup" property on the |
| 20026 |
// existing option so that it's rendered in both places. |
| 20027 |
if (optionsMap.hasOwnProperty(value)) { |
| 20028 |
if (group) { |
| 20029 |
var arr = optionsMap[value][field_optgroup]; |
| 20030 |
if (!arr) { |
| 20031 |
optionsMap[value][field_optgroup] = group; |
| 20032 |
} else if (!$.isArray(arr)) { |
| 20033 |
optionsMap[value][field_optgroup] = [arr, group]; |
| 20034 |
} else { |
| 20035 |
arr.push(group); |
| 20036 |
} |
| 20037 |
} |
| 20038 |
return; |
| 20039 |
} |
| 20040 |
|
| 20041 |
var option = readData($option) || {}; |
| 20042 |
option[field_label] = option[field_label] || $option.text(); |
| 20043 |
option[field_value] = option[field_value] || value; |
| 20044 |
option[field_optgroup] = option[field_optgroup] || group; |
| 20045 |
|
| 20046 |
optionsMap[value] = option; |
| 20047 |
options.push(option); |
| 20048 |
|
| 20049 |
if ($option.is(':selected')) { |
| 20050 |
settings_element.items.push(value); |
| 20051 |
} |
| 20052 |
}; |
| 20053 |
|
| 20054 |
var addGroup = function($optgroup) { |
| 20055 |
var i, n, id, optgroup, $options; |
| 20056 |
|
| 20057 |
$optgroup = $($optgroup); |
| 20058 |
id = $optgroup.attr('label'); |
| 20059 |
|
| 20060 |
if (id) { |
| 20061 |
optgroup = readData($optgroup) || {}; |
| 20062 |
optgroup[field_optgroup_label] = id; |
| 20063 |
optgroup[field_optgroup_value] = id; |
| 20064 |
settings_element.optgroups.push(optgroup); |
| 20065 |
} |
| 20066 |
|
| 20067 |
$options = $('option', $optgroup); |
| 20068 |
for (i = 0, n = $options.length; i < n; i++) { |
| 20069 |
addOption($options[i], id); |
| 20070 |
} |
| 20071 |
}; |
| 20072 |
|
| 20073 |
settings_element.maxItems = $input.attr('multiple') ? null : 1; |
| 20074 |
|
| 20075 |
$children = $input.children(); |
| 20076 |
for (i = 0, n = $children.length; i < n; i++) { |
| 20077 |
tagName = $children[i].tagName.toLowerCase(); |
| 20078 |
if (tagName === 'optgroup') { |
| 20079 |
addGroup($children[i]); |
| 20080 |
} else if (tagName === 'option') { |
| 20081 |
addOption($children[i]); |
| 20082 |
} |
| 20083 |
} |
| 20084 |
}; |
| 20085 |
|
| 20086 |
return this.each(function() { |
| 20087 |
if (this.selectize) return; |
| 20088 |
|
| 20089 |
var instance; |
| 20090 |
var $input = $(this); |
| 20091 |
var tag_name = this.tagName.toLowerCase(); |
| 20092 |
var placeholder = $input.attr('placeholder') || $input.attr('data-placeholder'); |
| 20093 |
if (!placeholder && !settings.allowEmptyOption) { |
| 20094 |
placeholder = $input.children('option[value=""]').text(); |
| 20095 |
} |
| 20096 |
|
| 20097 |
var settings_element = { |
| 20098 |
'placeholder' : placeholder, |
| 20099 |
'options' : [], |
| 20100 |
'optgroups' : [], |
| 20101 |
'items' : [] |
| 20102 |
}; |
| 20103 |
|
| 20104 |
if (tag_name === 'select') { |
| 20105 |
init_select($input, settings_element); |
| 20106 |
} else { |
| 20107 |
init_textbox($input, settings_element); |
| 20108 |
} |
| 20109 |
|
| 20110 |
instance = new Selectize($input, $.extend(true, {}, defaults, settings_element, settings_user)); |
| 20111 |
}); |
| 20112 |
}; |
| 20113 |
|
| 20114 |
$.fn.selectize.defaults = Selectize.defaults; |
| 20115 |
$.fn.selectize.support = { |
| 20116 |
validity: SUPPORTS_VALIDITY_API |
| 20117 |
}; |
| 20118 |
|
| 20119 |
|
| 20120 |
Selectize.define('drag_drop', function(options) { |
| 20121 |
if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".'); |
| 20122 |
if (this.settings.mode !== 'multi') return; |
| 20123 |
var self = this; |
| 20124 |
|
| 20125 |
self.lock = (function() { |
| 20126 |
var original = self.lock; |
| 20127 |
return function() { |
| 20128 |
var sortable = self.$control.data('sortable'); |
| 20129 |
if (sortable) sortable.disable(); |
| 20130 |
return original.apply(self, arguments); |
| 20131 |
}; |
| 20132 |
})(); |
| 20133 |
|
| 20134 |
self.unlock = (function() { |
| 20135 |
var original = self.unlock; |
| 20136 |
return function() { |
| 20137 |
var sortable = self.$control.data('sortable'); |
| 20138 |
if (sortable) sortable.enable(); |
| 20139 |
return original.apply(self, arguments); |
| 20140 |
}; |
| 20141 |
})(); |
| 20142 |
|
| 20143 |
self.setup = (function() { |
| 20144 |
var original = self.setup; |
| 20145 |
return function() { |
| 20146 |
original.apply(this, arguments); |
| 20147 |
|
| 20148 |
var $control = self.$control.sortable({ |
| 20149 |
items: '[data-value]', |
| 20150 |
forcePlaceholderSize: true, |
| 20151 |
disabled: self.isLocked, |
| 20152 |
start: function(e, ui) { |
| 20153 |
ui.placeholder.css('width', ui.helper.css('width')); |
| 20154 |
$control.css({overflow: 'visible'}); |
| 20155 |
}, |
| 20156 |
stop: function() { |
| 20157 |
$control.css({overflow: 'hidden'}); |
| 20158 |
var active = self.$activeItems ? self.$activeItems.slice() : null; |
| 20159 |
var values = []; |
| 20160 |
$control.children('[data-value]').each(function() { |
| 20161 |
values.push($(this).attr('data-value')); |
| 20162 |
}); |
| 20163 |
self.setValue(values); |
| 20164 |
self.setActiveItem(active); |
| 20165 |
} |
| 20166 |
}); |
| 20167 |
}; |
| 20168 |
})(); |
| 20169 |
|
| 20170 |
}); |
| 20171 |
|
| 20172 |
Selectize.define('dropdown_header', function(options) { |
| 20173 |
var self = this; |
| 20174 |
|
| 20175 |
options = $.extend({ |
| 20176 |
title : 'Untitled', |
| 20177 |
headerClass : 'selectize-dropdown-header', |
| 20178 |
titleRowClass : 'selectize-dropdown-header-title', |
| 20179 |
labelClass : 'selectize-dropdown-header-label', |
| 20180 |
closeClass : 'selectize-dropdown-header-close', |
| 20181 |
|
| 20182 |
html: function(data) { |
| 20183 |
return ( |
| 20184 |
'<div class="' + data.headerClass + '">' + |
| 20185 |
'<div class="' + data.titleRowClass + '">' + |
| 20186 |
'<span class="' + data.labelClass + '">' + data.title + '</span>' + |
| 20187 |
'<a href="javascript:void(0)" class="' + data.closeClass + '">×</a>' + |
| 20188 |
'</div>' + |
| 20189 |
'</div>' |
| 20190 |
); |
| 20191 |
} |
| 20192 |
}, options); |
| 20193 |
|
| 20194 |
self.setup = (function() { |
| 20195 |
var original = self.setup; |
| 20196 |
return function() { |
| 20197 |
original.apply(self, arguments); |
| 20198 |
self.$dropdown_header = $(options.html(options)); |
| 20199 |
self.$dropdown.prepend(self.$dropdown_header); |
| 20200 |
}; |
| 20201 |
})(); |
| 20202 |
|
| 20203 |
}); |
| 20204 |
|
| 20205 |
Selectize.define('optgroup_columns', function(options) { |
| 20206 |
var self = this; |
| 20207 |
|
| 20208 |
options = $.extend({ |
| 20209 |
equalizeWidth : true, |
| 20210 |
equalizeHeight : true |
| 20211 |
}, options); |
| 20212 |
|
| 20213 |
this.getAdjacentOption = function($option, direction) { |
| 20214 |
var $options = $option.closest('[data-group]').find('[data-selectable]'); |
| 20215 |
var index = $options.index($option) + direction; |
| 20216 |
|
| 20217 |
return index >= 0 && index < $options.length ? $options.eq(index) : $(); |
| 20218 |
}; |
| 20219 |
|
| 20220 |
this.onKeyDown = (function() { |
| 20221 |
var original = self.onKeyDown; |
| 20222 |
return function(e) { |
| 20223 |
var index, $option, $options, $optgroup; |
| 20224 |
|
| 20225 |
if (this.isOpen && (e.keyCode === KEY_LEFT || e.keyCode === KEY_RIGHT)) { |
| 20226 |
self.ignoreHover = true; |
| 20227 |
$optgroup = this.$activeOption.closest('[data-group]'); |
| 20228 |
index = $optgroup.find('[data-selectable]').index(this.$activeOption); |
| 20229 |
|
| 20230 |
if(e.keyCode === KEY_LEFT) { |
| 20231 |
$optgroup = $optgroup.prev('[data-group]'); |
| 20232 |
} else { |
| 20233 |
$optgroup = $optgroup.next('[data-group]'); |
| 20234 |
} |
| 20235 |
|
| 20236 |
$options = $optgroup.find('[data-selectable]'); |
| 20237 |
$option = $options.eq(Math.min($options.length - 1, index)); |
| 20238 |
if ($option.length) { |
| 20239 |
this.setActiveOption($option); |
| 20240 |
} |
| 20241 |
return; |
| 20242 |
} |
| 20243 |
|
| 20244 |
return original.apply(this, arguments); |
| 20245 |
}; |
| 20246 |
})(); |
| 20247 |
|
| 20248 |
var getScrollbarWidth = function() { |
| 20249 |
var div; |
| 20250 |
var width = getScrollbarWidth.width; |
| 20251 |
var doc = document; |
| 20252 |
|
| 20253 |
if (typeof width === 'undefined') { |
| 20254 |
div = doc.createElement('div'); |
| 20255 |
div.innerHTML = '<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>'; |
| 20256 |
div = div.firstChild; |
| 20257 |
doc.body.appendChild(div); |
| 20258 |
width = getScrollbarWidth.width = div.offsetWidth - div.clientWidth; |
| 20259 |
doc.body.removeChild(div); |
| 20260 |
} |
| 20261 |
return width; |
| 20262 |
}; |
| 20263 |
|
| 20264 |
var equalizeSizes = function() { |
| 20265 |
var i, n, height_max, width, width_last, width_parent, $optgroups; |
| 20266 |
|
| 20267 |
$optgroups = $('[data-group]', self.$dropdown_content); |
| 20268 |
n = $optgroups.length; |
| 20269 |
if (!n || !self.$dropdown_content.width()) return; |
| 20270 |
|
| 20271 |
if (options.equalizeHeight) { |
| 20272 |
height_max = 0; |
| 20273 |
for (i = 0; i < n; i++) { |
| 20274 |
height_max = Math.max(height_max, $optgroups.eq(i).height()); |
| 20275 |
} |
| 20276 |
$optgroups.css({height: height_max}); |
| 20277 |
} |
| 20278 |
|
| 20279 |
if (options.equalizeWidth) { |
| 20280 |
width_parent = self.$dropdown_content.innerWidth() - getScrollbarWidth(); |
| 20281 |
width = Math.round(width_parent / n); |
| 20282 |
$optgroups.css({width: width}); |
| 20283 |
if (n > 1) { |
| 20284 |
width_last = width_parent - width * (n - 1); |
| 20285 |
$optgroups.eq(n - 1).css({width: width_last}); |
| 20286 |
} |
| 20287 |
} |
| 20288 |
}; |
| 20289 |
|
| 20290 |
if (options.equalizeHeight || options.equalizeWidth) { |
| 20291 |
hook.after(this, 'positionDropdown', equalizeSizes); |
| 20292 |
hook.after(this, 'refreshOptions', equalizeSizes); |
| 20293 |
} |
| 20294 |
|
| 20295 |
|
| 20296 |
}); |
| 20297 |
|
| 20298 |
Selectize.define('remove_button', function(options) { |
| 20299 |
options = $.extend({ |
| 20300 |
label : '×', |
| 20301 |
title : 'Remove', |
| 20302 |
className : 'remove', |
| 20303 |
append : true |
| 20304 |
}, options); |
| 20305 |
|
| 20306 |
var singleClose = function(thisRef, options) { |
| 20307 |
|
| 20308 |
options.className = 'remove-single'; |
| 20309 |
|
| 20310 |
var self = thisRef; |
| 20311 |
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; |
| 20312 |
|
| 20313 |
/** |
| 20314 |
* Appends an element as a child (with raw HTML). |
| 20315 |
* |
| 20316 |
* @param {string} html_container |
| 20317 |
* @param {string} html_element |
| 20318 |
* @return {string} |
| 20319 |
*/ |
| 20320 |
var append = function(html_container, html_element) { |
| 20321 |
return html_container + html_element; |
| 20322 |
}; |
| 20323 |
|
| 20324 |
thisRef.setup = (function() { |
| 20325 |
var original = self.setup; |
| 20326 |
return function() { |
| 20327 |
// override the item rendering method to add the button to each |
| 20328 |
if (options.append) { |
| 20329 |
var id = $(self.$input.context).attr('id'); |
| 20330 |
var selectizer = $('#'+id); |
| 20331 |
|
| 20332 |
var render_item = self.settings.render.item; |
| 20333 |
self.settings.render.item = function(data) { |
| 20334 |
return append(render_item.apply(thisRef, arguments), html); |
| 20335 |
}; |
| 20336 |
} |
| 20337 |
|
| 20338 |
original.apply(thisRef, arguments); |
| 20339 |
|
| 20340 |
// add event listener |
| 20341 |
thisRef.$control.on('click', '.' + options.className, function(e) { |
| 20342 |
e.preventDefault(); |
| 20343 |
if (self.isLocked) return; |
| 20344 |
|
| 20345 |
self.clear(); |
| 20346 |
}); |
| 20347 |
|
| 20348 |
}; |
| 20349 |
})(); |
| 20350 |
}; |
| 20351 |
|
| 20352 |
var multiClose = function(thisRef, options) { |
| 20353 |
|
| 20354 |
var self = thisRef; |
| 20355 |
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; |
| 20356 |
|
| 20357 |
/** |
| 20358 |
* Appends an element as a child (with raw HTML). |
| 20359 |
* |
| 20360 |
* @param {string} html_container |
| 20361 |
* @param {string} html_element |
| 20362 |
* @return {string} |
| 20363 |
*/ |
| 20364 |
var append = function(html_container, html_element) { |
| 20365 |
var pos = html_container.search(/(<\/[^>]+>\s*)$/); |
| 20366 |
return html_container.substring(0, pos) + html_element + html_container.substring(pos); |
| 20367 |
}; |
| 20368 |
|
| 20369 |
thisRef.setup = (function() { |
| 20370 |
var original = self.setup; |
| 20371 |
return function() { |
| 20372 |
// override the item rendering method to add the button to each |
| 20373 |
if (options.append) { |
| 20374 |
var render_item = self.settings.render.item; |
| 20375 |
self.settings.render.item = function(data) { |
| 20376 |
return append(render_item.apply(thisRef, arguments), html); |
| 20377 |
}; |
| 20378 |
} |
| 20379 |
|
| 20380 |
original.apply(thisRef, arguments); |
| 20381 |
|
| 20382 |
// add event listener |
| 20383 |
thisRef.$control.on('click', '.' + options.className, function(e) { |
| 20384 |
e.preventDefault(); |
| 20385 |
if (self.isLocked) return; |
| 20386 |
|
| 20387 |
var $item = $(e.currentTarget).parent(); |
| 20388 |
self.setActiveItem($item); |
| 20389 |
if (self.deleteSelection()) { |
| 20390 |
self.setCaret(self.items.length); |
| 20391 |
} |
| 20392 |
}); |
| 20393 |
|
| 20394 |
}; |
| 20395 |
})(); |
| 20396 |
}; |
| 20397 |
|
| 20398 |
if (this.settings.mode === 'single') { |
| 20399 |
singleClose(this, options); |
| 20400 |
return; |
| 20401 |
} else { |
| 20402 |
multiClose(this, options); |
| 20403 |
} |
| 20404 |
}); |
| 20405 |
|
| 20406 |
|
| 20407 |
Selectize.define('restore_on_backspace', function(options) { |
| 20408 |
var self = this; |
| 20409 |
|
| 20410 |
options.text = options.text || function(option) { |
| 20411 |
return option[this.settings.labelField]; |
| 20412 |
}; |
| 20413 |
|
| 20414 |
this.onKeyDown = (function() { |
| 20415 |
var original = self.onKeyDown; |
| 20416 |
return function(e) { |
| 20417 |
var index, option; |
| 20418 |
if (e.keyCode === KEY_BACKSPACE && this.$control_input.val() === '' && !this.$activeItems.length) { |
| 20419 |
index = this.caretPos - 1; |
| 20420 |
if (index >= 0 && index < this.items.length) { |
| 20421 |
option = this.options[this.items[index]]; |
| 20422 |
if (this.deleteSelection(e)) { |
| 20423 |
this.setTextboxValue(options.text.apply(this, [option])); |
| 20424 |
this.refreshOptions(true); |
| 20425 |
} |
| 20426 |
e.preventDefault(); |
| 20427 |
return; |
| 20428 |
} |
| 20429 |
} |
| 20430 |
return original.apply(this, arguments); |
| 20431 |
}; |
| 20432 |
})(); |
| 20433 |
}); |
| 20434 |
|
| 20435 |
|
| 20436 |
return Selectize; |
| 20437 |
})); |
| 20438 |
/* assets/wpuf/vendor/toastr/toastr.js */ |
| 20439 |
/* |
| 20440 |
* Toastr |
| 20441 |
* Copyright 2012-2015 |
| 20442 |
* Authors: John Papa, Hans Fjällemark, and Tim Ferrell. |
| 20443 |
* All Rights Reserved. |
| 20444 |
* Use, reproduction, distribution, and modification of this code is subject to the terms and |
| 20445 |
* conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php |
| 20446 |
* |
| 20447 |
* ARIA Support: Greta Krafsig |
| 20448 |
* |
| 20449 |
* Project: https://github.com/CodeSeven/toastr |
| 20450 |
*/ |
| 20451 |
/* global define */ |
| 20452 |
(function (define) { |
| 20453 |
define(['jquery'], function ($) { |
| 20454 |
return (function () { |
| 20455 |
var $container; |
| 20456 |
var listener; |
| 20457 |
var toastId = 0; |
| 20458 |
var toastType = { |
| 20459 |
error: 'error', |
| 20460 |
info: 'info', |
| 20461 |
success: 'success', |
| 20462 |
warning: 'warning' |
| 20463 |
}; |
| 20464 |
|
| 20465 |
var toastr = { |
| 20466 |
clear: clear, |
| 20467 |
remove: remove, |
| 20468 |
error: error, |
| 20469 |
getContainer: getContainer, |
| 20470 |
info: info, |
| 20471 |
options: {}, |
| 20472 |
subscribe: subscribe, |
| 20473 |
success: success, |
| 20474 |
version: '2.1.3', |
| 20475 |
warning: warning |
| 20476 |
}; |
| 20477 |
|
| 20478 |
var previousToast; |
| 20479 |
|
| 20480 |
return toastr; |
| 20481 |
|
| 20482 |
//////////////// |
| 20483 |
|
| 20484 |
function error(message, title, optionsOverride) { |
| 20485 |
return notify({ |
| 20486 |
type: toastType.error, |
| 20487 |
iconClass: getOptions().iconClasses.error, |
| 20488 |
message: message, |
| 20489 |
optionsOverride: optionsOverride, |
| 20490 |
title: title |
| 20491 |
}); |
| 20492 |
} |
| 20493 |
|
| 20494 |
function getContainer(options, create) { |
| 20495 |
if (!options) { options = getOptions(); } |
| 20496 |
$container = $('#' + options.containerId); |
| 20497 |
if ($container.length) { |
| 20498 |
return $container; |
| 20499 |
} |
| 20500 |
if (create) { |
| 20501 |
$container = createContainer(options); |
| 20502 |
} |
| 20503 |
return $container; |
| 20504 |
} |
| 20505 |
|
| 20506 |
function info(message, title, optionsOverride) { |
| 20507 |
return notify({ |
| 20508 |
type: toastType.info, |
| 20509 |
iconClass: getOptions().iconClasses.info, |
| 20510 |
message: message, |
| 20511 |
optionsOverride: optionsOverride, |
| 20512 |
title: title |
| 20513 |
}); |
| 20514 |
} |
| 20515 |
|
| 20516 |
function subscribe(callback) { |
| 20517 |
listener = callback; |
| 20518 |
} |
| 20519 |
|
| 20520 |
function success(message, title, optionsOverride) { |
| 20521 |
return notify({ |
| 20522 |
type: toastType.success, |
| 20523 |
iconClass: getOptions().iconClasses.success, |
| 20524 |
message: message, |
| 20525 |
optionsOverride: optionsOverride, |
| 20526 |
title: title |
| 20527 |
}); |
| 20528 |
} |
| 20529 |
|
| 20530 |
function warning(message, title, optionsOverride) { |
| 20531 |
return notify({ |
| 20532 |
type: toastType.warning, |
| 20533 |
iconClass: getOptions().iconClasses.warning, |
| 20534 |
message: message, |
| 20535 |
optionsOverride: optionsOverride, |
| 20536 |
title: title |
| 20537 |
}); |
| 20538 |
} |
| 20539 |
|
| 20540 |
function clear($toastElement, clearOptions) { |
| 20541 |
var options = getOptions(); |
| 20542 |
if (!$container) { getContainer(options); } |
| 20543 |
if (!clearToast($toastElement, options, clearOptions)) { |
| 20544 |
clearContainer(options); |
| 20545 |
} |
| 20546 |
} |
| 20547 |
|
| 20548 |
function remove($toastElement) { |
| 20549 |
var options = getOptions(); |
| 20550 |
if (!$container) { getContainer(options); } |
| 20551 |
if ($toastElement && $(':focus', $toastElement).length === 0) { |
| 20552 |
removeToast($toastElement); |
| 20553 |
return; |
| 20554 |
} |
| 20555 |
if ($container.children().length) { |
| 20556 |
$container.remove(); |
| 20557 |
} |
| 20558 |
} |
| 20559 |
|
| 20560 |
// internal functions |
| 20561 |
|
| 20562 |
function clearContainer (options) { |
| 20563 |
var toastsToClear = $container.children(); |
| 20564 |
for (var i = toastsToClear.length - 1; i >= 0; i--) { |
| 20565 |
clearToast($(toastsToClear[i]), options); |
| 20566 |
} |
| 20567 |
} |
| 20568 |
|
| 20569 |
function clearToast ($toastElement, options, clearOptions) { |
| 20570 |
var force = clearOptions && clearOptions.force ? clearOptions.force : false; |
| 20571 |
if ($toastElement && (force || $(':focus', $toastElement).length === 0)) { |
| 20572 |
$toastElement[options.hideMethod]({ |
| 20573 |
duration: options.hideDuration, |
| 20574 |
easing: options.hideEasing, |
| 20575 |
complete: function () { removeToast($toastElement); } |
| 20576 |
}); |
| 20577 |
return true; |
| 20578 |
} |
| 20579 |
return false; |
| 20580 |
} |
| 20581 |
|
| 20582 |
function createContainer(options) { |
| 20583 |
$container = $('<div/>') |
| 20584 |
.attr('id', options.containerId) |
| 20585 |
.addClass(options.positionClass); |
| 20586 |
|
| 20587 |
$container.appendTo($(options.target)); |
| 20588 |
return $container; |
| 20589 |
} |
| 20590 |
|
| 20591 |
function getDefaults() { |
| 20592 |
return { |
| 20593 |
tapToDismiss: true, |
| 20594 |
toastClass: 'toast', |
| 20595 |
containerId: 'toast-container', |
| 20596 |
debug: false, |
| 20597 |
|
| 20598 |
showMethod: 'fadeIn', //fadeIn, slideDown, and show are built into jQuery |
| 20599 |
showDuration: 300, |
| 20600 |
showEasing: 'swing', //swing and linear are built into jQuery |
| 20601 |
onShown: undefined, |
| 20602 |
hideMethod: 'fadeOut', |
| 20603 |
hideDuration: 1000, |
| 20604 |
hideEasing: 'swing', |
| 20605 |
onHidden: undefined, |
| 20606 |
closeMethod: false, |
| 20607 |
closeDuration: false, |
| 20608 |
closeEasing: false, |
| 20609 |
closeOnHover: true, |
| 20610 |
|
| 20611 |
extendedTimeOut: 1000, |
| 20612 |
iconClasses: { |
| 20613 |
error: 'toast-error', |
| 20614 |
info: 'toast-info', |
| 20615 |
success: 'toast-success', |
| 20616 |
warning: 'toast-warning' |
| 20617 |
}, |
| 20618 |
iconClass: 'toast-info', |
| 20619 |
positionClass: 'toast-top-right', |
| 20620 |
timeOut: 5000, // Set timeOut and extendedTimeOut to 0 to make it sticky |
| 20621 |
titleClass: 'toast-title', |
| 20622 |
messageClass: 'toast-message', |
| 20623 |
escapeHtml: false, |
| 20624 |
target: 'body', |
| 20625 |
closeHtml: '<button type="button">×</button>', |
| 20626 |
closeClass: 'toast-close-button', |
| 20627 |
newestOnTop: true, |
| 20628 |
preventDuplicates: false, |
| 20629 |
progressBar: false, |
| 20630 |
progressClass: 'toast-progress', |
| 20631 |
rtl: false |
| 20632 |
}; |
| 20633 |
} |
| 20634 |
|
| 20635 |
function publish(args) { |
| 20636 |
if (!listener) { return; } |
| 20637 |
listener(args); |
| 20638 |
} |
| 20639 |
|
| 20640 |
function notify(map) { |
| 20641 |
var options = getOptions(); |
| 20642 |
var iconClass = map.iconClass || options.iconClass; |
| 20643 |
|
| 20644 |
if (typeof (map.optionsOverride) !== 'undefined') { |
| 20645 |
options = $.extend(options, map.optionsOverride); |
| 20646 |
iconClass = map.optionsOverride.iconClass || iconClass; |
| 20647 |
} |
| 20648 |
|
| 20649 |
if (shouldExit(options, map)) { return; } |
| 20650 |
|
| 20651 |
toastId++; |
| 20652 |
|
| 20653 |
$container = getContainer(options, true); |
| 20654 |
|
| 20655 |
var intervalId = null; |
| 20656 |
var $toastElement = $('<div/>'); |
| 20657 |
var $titleElement = $('<div/>'); |
| 20658 |
var $messageElement = $('<div/>'); |
| 20659 |
var $progressElement = $('<div/>'); |
| 20660 |
var $closeElement = $(options.closeHtml); |
| 20661 |
var progressBar = { |
| 20662 |
intervalId: null, |
| 20663 |
hideEta: null, |
| 20664 |
maxHideTime: null |
| 20665 |
}; |
| 20666 |
var response = { |
| 20667 |
toastId: toastId, |
| 20668 |
state: 'visible', |
| 20669 |
startTime: new Date(), |
| 20670 |
options: options, |
| 20671 |
map: map |
| 20672 |
}; |
| 20673 |
|
| 20674 |
personalizeToast(); |
| 20675 |
|
| 20676 |
displayToast(); |
| 20677 |
|
| 20678 |
handleEvents(); |
| 20679 |
|
| 20680 |
publish(response); |
| 20681 |
|
| 20682 |
if (options.debug && console) { |
| 20683 |
console.log(response); |
| 20684 |
} |
| 20685 |
|
| 20686 |
return $toastElement; |
| 20687 |
|
| 20688 |
function escapeHtml(source) { |
| 20689 |
if (source == null) { |
| 20690 |
source = ''; |
| 20691 |
} |
| 20692 |
|
| 20693 |
return source |
| 20694 |
.replace(/&/g, '&') |
| 20695 |
.replace(/"/g, '"') |
| 20696 |
.replace(/'/g, ''') |
| 20697 |
.replace(/</g, '<') |
| 20698 |
.replace(/>/g, '>'); |
| 20699 |
} |
| 20700 |
|
| 20701 |
function personalizeToast() { |
| 20702 |
setIcon(); |
| 20703 |
setTitle(); |
| 20704 |
setMessage(); |
| 20705 |
setCloseButton(); |
| 20706 |
setProgressBar(); |
| 20707 |
setRTL(); |
| 20708 |
setSequence(); |
| 20709 |
setAria(); |
| 20710 |
} |
| 20711 |
|
| 20712 |
function setAria() { |
| 20713 |
var ariaValue = ''; |
| 20714 |
switch (map.iconClass) { |
| 20715 |
case 'toast-success': |
| 20716 |
case 'toast-info': |
| 20717 |
ariaValue = 'polite'; |
| 20718 |
break; |
| 20719 |
default: |
| 20720 |
ariaValue = 'assertive'; |
| 20721 |
} |
| 20722 |
$toastElement.attr('aria-live', ariaValue); |
| 20723 |
} |
| 20724 |
|
| 20725 |
function handleEvents() { |
| 20726 |
if (options.closeOnHover) { |
| 20727 |
$toastElement.hover(stickAround, delayedHideToast); |
| 20728 |
} |
| 20729 |
|
| 20730 |
if (!options.onclick && options.tapToDismiss) { |
| 20731 |
$toastElement.click(hideToast); |
| 20732 |
} |
| 20733 |
|
| 20734 |
if (options.closeButton && $closeElement) { |
| 20735 |
$closeElement.click(function (event) { |
| 20736 |
if (event.stopPropagation) { |
| 20737 |
event.stopPropagation(); |
| 20738 |
} else if (event.cancelBubble !== undefined && event.cancelBubble !== true) { |
| 20739 |
event.cancelBubble = true; |
| 20740 |
} |
| 20741 |
|
| 20742 |
if (options.onCloseClick) { |
| 20743 |
options.onCloseClick(event); |
| 20744 |
} |
| 20745 |
|
| 20746 |
hideToast(true); |
| 20747 |
}); |
| 20748 |
} |
| 20749 |
|
| 20750 |
if (options.onclick) { |
| 20751 |
$toastElement.click(function (event) { |
| 20752 |
options.onclick(event); |
| 20753 |
hideToast(); |
| 20754 |
}); |
| 20755 |
} |
| 20756 |
} |
| 20757 |
|
| 20758 |
function displayToast() { |
| 20759 |
$toastElement.hide(); |
| 20760 |
|
| 20761 |
$toastElement[options.showMethod]( |
| 20762 |
{duration: options.showDuration, easing: options.showEasing, complete: options.onShown} |
| 20763 |
); |
| 20764 |
|
| 20765 |
if (options.timeOut > 0) { |
| 20766 |
intervalId = setTimeout(hideToast, options.timeOut); |
| 20767 |
progressBar.maxHideTime = parseFloat(options.timeOut); |
| 20768 |
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime; |
| 20769 |
if (options.progressBar) { |
| 20770 |
progressBar.intervalId = setInterval(updateProgress, 10); |
| 20771 |
} |
| 20772 |
} |
| 20773 |
} |
| 20774 |
|
| 20775 |
function setIcon() { |
| 20776 |
if (map.iconClass) { |
| 20777 |
$toastElement.addClass(options.toastClass).addClass(iconClass); |
| 20778 |
} |
| 20779 |
} |
| 20780 |
|
| 20781 |
function setSequence() { |
| 20782 |
if (options.newestOnTop) { |
| 20783 |
$container.prepend($toastElement); |
| 20784 |
} else { |
| 20785 |
$container.append($toastElement); |
| 20786 |
} |
| 20787 |
} |
| 20788 |
|
| 20789 |
function setTitle() { |
| 20790 |
if (map.title) { |
| 20791 |
var suffix = map.title; |
| 20792 |
if (options.escapeHtml) { |
| 20793 |
suffix = escapeHtml(map.title); |
| 20794 |
} |
| 20795 |
$titleElement.append(suffix).addClass(options.titleClass); |
| 20796 |
$toastElement.append($titleElement); |
| 20797 |
} |
| 20798 |
} |
| 20799 |
|
| 20800 |
function setMessage() { |
| 20801 |
if (map.message) { |
| 20802 |
var suffix = map.message; |
| 20803 |
if (options.escapeHtml) { |
| 20804 |
suffix = escapeHtml(map.message); |
| 20805 |
} |
| 20806 |
$messageElement.append(suffix).addClass(options.messageClass); |
| 20807 |
$toastElement.append($messageElement); |
| 20808 |
} |
| 20809 |
} |
| 20810 |
|
| 20811 |
function setCloseButton() { |
| 20812 |
if (options.closeButton) { |
| 20813 |
$closeElement.addClass(options.closeClass).attr('role', 'button'); |
| 20814 |
$toastElement.prepend($closeElement); |
| 20815 |
} |
| 20816 |
} |
| 20817 |
|
| 20818 |
function setProgressBar() { |
| 20819 |
if (options.progressBar) { |
| 20820 |
$progressElement.addClass(options.progressClass); |
| 20821 |
$toastElement.prepend($progressElement); |
| 20822 |
} |
| 20823 |
} |
| 20824 |
|
| 20825 |
function setRTL() { |
| 20826 |
if (options.rtl) { |
| 20827 |
$toastElement.addClass('rtl'); |
| 20828 |
} |
| 20829 |
} |
| 20830 |
|
| 20831 |
function shouldExit(options, map) { |
| 20832 |
if (options.preventDuplicates) { |
| 20833 |
if (map.message === previousToast) { |
| 20834 |
return true; |
| 20835 |
} else { |
| 20836 |
previousToast = map.message; |
| 20837 |
} |
| 20838 |
} |
| 20839 |
return false; |
| 20840 |
} |
| 20841 |
|
| 20842 |
function hideToast(override) { |
| 20843 |
var method = override && options.closeMethod !== false ? options.closeMethod : options.hideMethod; |
| 20844 |
var duration = override && options.closeDuration !== false ? |
| 20845 |
options.closeDuration : options.hideDuration; |
| 20846 |
var easing = override && options.closeEasing !== false ? options.closeEasing : options.hideEasing; |
| 20847 |
if ($(':focus', $toastElement).length && !override) { |
| 20848 |
return; |
| 20849 |
} |
| 20850 |
clearTimeout(progressBar.intervalId); |
| 20851 |
return $toastElement[method]({ |
| 20852 |
duration: duration, |
| 20853 |
easing: easing, |
| 20854 |
complete: function () { |
| 20855 |
removeToast($toastElement); |
| 20856 |
clearTimeout(intervalId); |
| 20857 |
if (options.onHidden && response.state !== 'hidden') { |
| 20858 |
options.onHidden(); |
| 20859 |
} |
| 20860 |
response.state = 'hidden'; |
| 20861 |
response.endTime = new Date(); |
| 20862 |
publish(response); |
| 20863 |
} |
| 20864 |
}); |
| 20865 |
} |
| 20866 |
|
| 20867 |
function delayedHideToast() { |
| 20868 |
if (options.timeOut > 0 || options.extendedTimeOut > 0) { |
| 20869 |
intervalId = setTimeout(hideToast, options.extendedTimeOut); |
| 20870 |
progressBar.maxHideTime = parseFloat(options.extendedTimeOut); |
| 20871 |
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime; |
| 20872 |
} |
| 20873 |
} |
| 20874 |
|
| 20875 |
function stickAround() { |
| 20876 |
clearTimeout(intervalId); |
| 20877 |
progressBar.hideEta = 0; |
| 20878 |
$toastElement.stop(true, true)[options.showMethod]( |
| 20879 |
{duration: options.showDuration, easing: options.showEasing} |
| 20880 |
); |
| 20881 |
} |
| 20882 |
|
| 20883 |
function updateProgress() { |
| 20884 |
var percentage = ((progressBar.hideEta - (new Date().getTime())) / progressBar.maxHideTime) * 100; |
| 20885 |
$progressElement.width(percentage + '%'); |
| 20886 |
} |
| 20887 |
} |
| 20888 |
|
| 20889 |
function getOptions() { |
| 20890 |
return $.extend({}, getDefaults(), toastr.options); |
| 20891 |
} |
| 20892 |
|
| 20893 |
function removeToast($toastElement) { |
| 20894 |
if (!$container) { $container = getContainer(); } |
| 20895 |
if ($toastElement.is(':visible')) { |
| 20896 |
return; |
| 20897 |
} |
| 20898 |
$toastElement.remove(); |
| 20899 |
$toastElement = null; |
| 20900 |
if ($container.children().length === 0) { |
| 20901 |
$container.remove(); |
| 20902 |
previousToast = undefined; |
| 20903 |
} |
| 20904 |
} |
| 20905 |
|
| 20906 |
})(); |
| 20907 |
}); |
| 20908 |
}(typeof define === 'function' && define.amd ? define : function (deps, factory) { |
| 20909 |
if (typeof module !== 'undefined' && module.exports) { //Node |
| 20910 |
module.exports = factory(require('jquery')); |
| 20911 |
} else { |
| 20912 |
window.toastr = factory(window.jQuery); |
| 20913 |
} |
| 20914 |
})); |
| 20915 |
|
| 20916 |
/* assets/wpuf/vendor/clipboard/clipboard.js */ |
| 20917 |
/*! |
| 20918 |
* clipboard.js v1.6.0 |
| 20919 |
* https://zenorocha.github.io/clipboard.js |
| 20920 |
* |
| 20921 |
* Licensed MIT © Zeno Rocha |
| 20922 |
*/ |
| 20923 |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (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){ |
| 20924 |
var DOCUMENT_NODE_TYPE = 9; |
| 20925 |
|
| 20926 |
/** |
| 20927 |
* A polyfill for Element.matches() |
| 20928 |
*/ |
| 20929 |
if (Element && !Element.prototype.matches) { |
| 20930 |
var proto = Element.prototype; |
| 20931 |
|
| 20932 |
proto.matches = proto.matchesSelector || |
| 20933 |
proto.mozMatchesSelector || |
| 20934 |
proto.msMatchesSelector || |
| 20935 |
proto.oMatchesSelector || |
| 20936 |
proto.webkitMatchesSelector; |
| 20937 |
} |
| 20938 |
|
| 20939 |
/** |
| 20940 |
* Finds the closest parent that matches a selector. |
| 20941 |
* |
| 20942 |
* @param {Element} element |
| 20943 |
* @param {String} selector |
| 20944 |
* @return {Function} |
| 20945 |
*/ |
| 20946 |
function closest (element, selector) { |
| 20947 |
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
| 20948 |
if (element.matches(selector)) return element; |
| 20949 |
element = element.parentNode; |
| 20950 |
} |
| 20951 |
} |
| 20952 |
|
| 20953 |
module.exports = closest; |
| 20954 |
|
| 20955 |
},{}],2:[function(require,module,exports){ |
| 20956 |
var closest = require('./closest'); |
| 20957 |
|
| 20958 |
/** |
| 20959 |
* Delegates event to a selector. |
| 20960 |
* |
| 20961 |
* @param {Element} element |
| 20962 |
* @param {String} selector |
| 20963 |
* @param {String} type |
| 20964 |
* @param {Function} callback |
| 20965 |
* @param {Boolean} useCapture |
| 20966 |
* @return {Object} |
| 20967 |
*/ |
| 20968 |
function delegate(element, selector, type, callback, useCapture) { |
| 20969 |
var listenerFn = listener.apply(this, arguments); |
| 20970 |
|
| 20971 |
element.addEventListener(type, listenerFn, useCapture); |
| 20972 |
|
| 20973 |
return { |
| 20974 |
destroy: function() { |
| 20975 |
element.removeEventListener(type, listenerFn, useCapture); |
| 20976 |
} |
| 20977 |
} |
| 20978 |
} |
| 20979 |
|
| 20980 |
/** |
| 20981 |
* Finds closest match and invokes callback. |
| 20982 |
* |
| 20983 |
* @param {Element} element |
| 20984 |
* @param {String} selector |
| 20985 |
* @param {String} type |
| 20986 |
* @param {Function} callback |
| 20987 |
* @return {Function} |
| 20988 |
*/ |
| 20989 |
function listener(element, selector, type, callback) { |
| 20990 |
return function(e) { |
| 20991 |
e.delegateTarget = closest(e.target, selector); |
| 20992 |
|
| 20993 |
if (e.delegateTarget) { |
| 20994 |
callback.call(element, e); |
| 20995 |
} |
| 20996 |
} |
| 20997 |
} |
| 20998 |
|
| 20999 |
module.exports = delegate; |
| 21000 |
|
| 21001 |
},{"./closest":1}],3:[function(require,module,exports){ |
| 21002 |
/** |
| 21003 |
* Check if argument is a HTML element. |
| 21004 |
* |
| 21005 |
* @param {Object} value |
| 21006 |
* @return {Boolean} |
| 21007 |
*/ |
| 21008 |
exports.node = function(value) { |
| 21009 |
return value !== undefined |
| 21010 |
&& value instanceof HTMLElement |
| 21011 |
&& value.nodeType === 1; |
| 21012 |
}; |
| 21013 |
|
| 21014 |
/** |
| 21015 |
* Check if argument is a list of HTML elements. |
| 21016 |
* |
| 21017 |
* @param {Object} value |
| 21018 |
* @return {Boolean} |
| 21019 |
*/ |
| 21020 |
exports.nodeList = function(value) { |
| 21021 |
var type = Object.prototype.toString.call(value); |
| 21022 |
|
| 21023 |
return value !== undefined |
| 21024 |
&& (type === '[object NodeList]' || type === '[object HTMLCollection]') |
| 21025 |
&& ('length' in value) |
| 21026 |
&& (value.length === 0 || exports.node(value[0])); |
| 21027 |
}; |
| 21028 |
|
| 21029 |
/** |
| 21030 |
* Check if argument is a string. |
| 21031 |
* |
| 21032 |
* @param {Object} value |
| 21033 |
* @return {Boolean} |
| 21034 |
*/ |
| 21035 |
exports.string = function(value) { |
| 21036 |
return typeof value === 'string' |
| 21037 |
|| value instanceof String; |
| 21038 |
}; |
| 21039 |
|
| 21040 |
/** |
| 21041 |
* Check if argument is a function. |
| 21042 |
* |
| 21043 |
* @param {Object} value |
| 21044 |
* @return {Boolean} |
| 21045 |
*/ |
| 21046 |
exports.fn = function(value) { |
| 21047 |
var type = Object.prototype.toString.call(value); |
| 21048 |
|
| 21049 |
return type === '[object Function]'; |
| 21050 |
}; |
| 21051 |
|
| 21052 |
},{}],4:[function(require,module,exports){ |
| 21053 |
var is = require('./is'); |
| 21054 |
var delegate = require('delegate'); |
| 21055 |
|
| 21056 |
/** |
| 21057 |
* Validates all params and calls the right |
| 21058 |
* listener function based on its target type. |
| 21059 |
* |
| 21060 |
* @param {String|HTMLElement|HTMLCollection|NodeList} target |
| 21061 |
* @param {String} type |
| 21062 |
* @param {Function} callback |
| 21063 |
* @return {Object} |
| 21064 |
*/ |
| 21065 |
function listen(target, type, callback) { |
| 21066 |
if (!target && !type && !callback) { |
| 21067 |
throw new Error('Missing required arguments'); |
| 21068 |
} |
| 21069 |
|
| 21070 |
if (!is.string(type)) { |
| 21071 |
throw new TypeError('Second argument must be a String'); |
| 21072 |
} |
| 21073 |
|
| 21074 |
if (!is.fn(callback)) { |
| 21075 |
throw new TypeError('Third argument must be a Function'); |
| 21076 |
} |
| 21077 |
|
| 21078 |
if (is.node(target)) { |
| 21079 |
return listenNode(target, type, callback); |
| 21080 |
} |
| 21081 |
else if (is.nodeList(target)) { |
| 21082 |
return listenNodeList(target, type, callback); |
| 21083 |
} |
| 21084 |
else if (is.string(target)) { |
| 21085 |
return listenSelector(target, type, callback); |
| 21086 |
} |
| 21087 |
else { |
| 21088 |
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
| 21089 |
} |
| 21090 |
} |
| 21091 |
|
| 21092 |
/** |
| 21093 |
* Adds an event listener to a HTML element |
| 21094 |
* and returns a remove listener function. |
| 21095 |
* |
| 21096 |
* @param {HTMLElement} node |
| 21097 |
* @param {String} type |
| 21098 |
* @param {Function} callback |
| 21099 |
* @return {Object} |
| 21100 |
*/ |
| 21101 |
function listenNode(node, type, callback) { |
| 21102 |
node.addEventListener(type, callback); |
| 21103 |
|
| 21104 |
return { |
| 21105 |
destroy: function() { |
| 21106 |
node.removeEventListener(type, callback); |
| 21107 |
} |
| 21108 |
} |
| 21109 |
} |
| 21110 |
|
| 21111 |
/** |
| 21112 |
* Add an event listener to a list of HTML elements |
| 21113 |
* and returns a remove listener function. |
| 21114 |
* |
| 21115 |
* @param {NodeList|HTMLCollection} nodeList |
| 21116 |
* @param {String} type |
| 21117 |
* @param {Function} callback |
| 21118 |
* @return {Object} |
| 21119 |
*/ |
| 21120 |
function listenNodeList(nodeList, type, callback) { |
| 21121 |
Array.prototype.forEach.call(nodeList, function(node) { |
| 21122 |
node.addEventListener(type, callback); |
| 21123 |
}); |
| 21124 |
|
| 21125 |
return { |
| 21126 |
destroy: function() { |
| 21127 |
Array.prototype.forEach.call(nodeList, function(node) { |
| 21128 |
node.removeEventListener(type, callback); |
| 21129 |
}); |
| 21130 |
} |
| 21131 |
} |
| 21132 |
} |
| 21133 |
|
| 21134 |
/** |
| 21135 |
* Add an event listener to a selector |
| 21136 |
* and returns a remove listener function. |
| 21137 |
* |
| 21138 |
* @param {String} selector |
| 21139 |
* @param {String} type |
| 21140 |
* @param {Function} callback |
| 21141 |
* @return {Object} |
| 21142 |
*/ |
| 21143 |
function listenSelector(selector, type, callback) { |
| 21144 |
return delegate(document.body, selector, type, callback); |
| 21145 |
} |
| 21146 |
|
| 21147 |
module.exports = listen; |
| 21148 |
|
| 21149 |
},{"./is":3,"delegate":2}],5:[function(require,module,exports){ |
| 21150 |
function select(element) { |
| 21151 |
var selectedText; |
| 21152 |
|
| 21153 |
if (element.nodeName === 'SELECT') { |
| 21154 |
element.focus(); |
| 21155 |
|
| 21156 |
selectedText = element.value; |
| 21157 |
} |
| 21158 |
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
| 21159 |
var isReadOnly = element.hasAttribute('readonly'); |
| 21160 |
|
| 21161 |
if (!isReadOnly) { |
| 21162 |
element.setAttribute('readonly', ''); |
| 21163 |
} |
| 21164 |
|
| 21165 |
element.select(); |
| 21166 |
element.setSelectionRange(0, element.value.length); |
| 21167 |
|
| 21168 |
if (!isReadOnly) { |
| 21169 |
element.removeAttribute('readonly'); |
| 21170 |
} |
| 21171 |
|
| 21172 |
selectedText = element.value; |
| 21173 |
} |
| 21174 |
else { |
| 21175 |
if (element.hasAttribute('contenteditable')) { |
| 21176 |
element.focus(); |
| 21177 |
} |
| 21178 |
|
| 21179 |
var selection = window.getSelection(); |
| 21180 |
var range = document.createRange(); |
| 21181 |
|
| 21182 |
range.selectNodeContents(element); |
| 21183 |
selection.removeAllRanges(); |
| 21184 |
selection.addRange(range); |
| 21185 |
|
| 21186 |
selectedText = selection.toString(); |
| 21187 |
} |
| 21188 |
|
| 21189 |
return selectedText; |
| 21190 |
} |
| 21191 |
|
| 21192 |
module.exports = select; |
| 21193 |
|
| 21194 |
},{}],6:[function(require,module,exports){ |
| 21195 |
function E () { |
| 21196 |
// Keep this empty so it's easier to inherit from |
| 21197 |
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
| 21198 |
} |
| 21199 |
|
| 21200 |
E.prototype = { |
| 21201 |
on: function (name, callback, ctx) { |
| 21202 |
var e = this.e || (this.e = {}); |
| 21203 |
|
| 21204 |
(e[name] || (e[name] = [])).push({ |
| 21205 |
fn: callback, |
| 21206 |
ctx: ctx |
| 21207 |
}); |
| 21208 |
|
| 21209 |
return this; |
| 21210 |
}, |
| 21211 |
|
| 21212 |
once: function (name, callback, ctx) { |
| 21213 |
var self = this; |
| 21214 |
function listener () { |
| 21215 |
self.off(name, listener); |
| 21216 |
callback.apply(ctx, arguments); |
| 21217 |
}; |
| 21218 |
|
| 21219 |
listener._ = callback |
| 21220 |
return this.on(name, listener, ctx); |
| 21221 |
}, |
| 21222 |
|
| 21223 |
emit: function (name) { |
| 21224 |
var data = [].slice.call(arguments, 1); |
| 21225 |
var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
| 21226 |
var i = 0; |
| 21227 |
var len = evtArr.length; |
| 21228 |
|
| 21229 |
for (i; i < len; i++) { |
| 21230 |
evtArr[i].fn.apply(evtArr[i].ctx, data); |
| 21231 |
} |
| 21232 |
|
| 21233 |
return this; |
| 21234 |
}, |
| 21235 |
|
| 21236 |
off: function (name, callback) { |
| 21237 |
var e = this.e || (this.e = {}); |
| 21238 |
var evts = e[name]; |
| 21239 |
var liveEvents = []; |
| 21240 |
|
| 21241 |
if (evts && callback) { |
| 21242 |
for (var i = 0, len = evts.length; i < len; i++) { |
| 21243 |
if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
| 21244 |
liveEvents.push(evts[i]); |
| 21245 |
} |
| 21246 |
} |
| 21247 |
|
| 21248 |
// Remove event from queue to prevent memory leak |
| 21249 |
// Suggested by https://github.com/lazd |
| 21250 |
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
| 21251 |
|
| 21252 |
(liveEvents.length) |
| 21253 |
? e[name] = liveEvents |
| 21254 |
: delete e[name]; |
| 21255 |
|
| 21256 |
return this; |
| 21257 |
} |
| 21258 |
}; |
| 21259 |
|
| 21260 |
module.exports = E; |
| 21261 |
|
| 21262 |
},{}],7:[function(require,module,exports){ |
| 21263 |
(function (global, factory) { |
| 21264 |
if (typeof define === "function" && define.amd) { |
| 21265 |
define(['module', 'select'], factory); |
| 21266 |
} else if (typeof exports !== "undefined") { |
| 21267 |
factory(module, require('select')); |
| 21268 |
} else { |
| 21269 |
var mod = { |
| 21270 |
exports: {} |
| 21271 |
}; |
| 21272 |
factory(mod, global.select); |
| 21273 |
global.clipboardAction = mod.exports; |
| 21274 |
} |
| 21275 |
})(this, function (module, _select) { |
| 21276 |
'use strict'; |
| 21277 |
|
| 21278 |
var _select2 = _interopRequireDefault(_select); |
| 21279 |
|
| 21280 |
function _interopRequireDefault(obj) { |
| 21281 |
return obj && obj.__esModule ? obj : { |
| 21282 |
default: obj |
| 21283 |
}; |
| 21284 |
} |
| 21285 |
|
| 21286 |
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
| 21287 |
return typeof obj; |
| 21288 |
} : function (obj) { |
| 21289 |
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
| 21290 |
}; |
| 21291 |
|
| 21292 |
function _classCallCheck(instance, Constructor) { |
| 21293 |
if (!(instance instanceof Constructor)) { |
| 21294 |
throw new TypeError("Cannot call a class as a function"); |
| 21295 |
} |
| 21296 |
} |
| 21297 |
|
| 21298 |
var _createClass = function () { |
| 21299 |
function defineProperties(target, props) { |
| 21300 |
for (var i = 0; i < props.length; i++) { |
| 21301 |
var descriptor = props[i]; |
| 21302 |
descriptor.enumerable = descriptor.enumerable || false; |
| 21303 |
descriptor.configurable = true; |
| 21304 |
if ("value" in descriptor) descriptor.writable = true; |
| 21305 |
Object.defineProperty(target, descriptor.key, descriptor); |
| 21306 |
} |
| 21307 |
} |
| 21308 |
|
| 21309 |
return function (Constructor, protoProps, staticProps) { |
| 21310 |
if (protoProps) defineProperties(Constructor.prototype, protoProps); |
| 21311 |
if (staticProps) defineProperties(Constructor, staticProps); |
| 21312 |
return Constructor; |
| 21313 |
}; |
| 21314 |
}(); |
| 21315 |
|
| 21316 |
var ClipboardAction = function () { |
| 21317 |
/** |
| 21318 |
* @param {Object} options |
| 21319 |
*/ |
| 21320 |
function ClipboardAction(options) { |
| 21321 |
_classCallCheck(this, ClipboardAction); |
| 21322 |
|
| 21323 |
this.resolveOptions(options); |
| 21324 |
this.initSelection(); |
| 21325 |
} |
| 21326 |
|
| 21327 |
/** |
| 21328 |
* Defines base properties passed from constructor. |
| 21329 |
* @param {Object} options |
| 21330 |
*/ |
| 21331 |
|
| 21332 |
|
| 21333 |
_createClass(ClipboardAction, [{ |
| 21334 |
key: 'resolveOptions', |
| 21335 |
value: function resolveOptions() { |
| 21336 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 21337 |
|
| 21338 |
this.action = options.action; |
| 21339 |
this.emitter = options.emitter; |
| 21340 |
this.target = options.target; |
| 21341 |
this.text = options.text; |
| 21342 |
this.trigger = options.trigger; |
| 21343 |
|
| 21344 |
this.selectedText = ''; |
| 21345 |
} |
| 21346 |
}, { |
| 21347 |
key: 'initSelection', |
| 21348 |
value: function initSelection() { |
| 21349 |
if (this.text) { |
| 21350 |
this.selectFake(); |
| 21351 |
} else if (this.target) { |
| 21352 |
this.selectTarget(); |
| 21353 |
} |
| 21354 |
} |
| 21355 |
}, { |
| 21356 |
key: 'selectFake', |
| 21357 |
value: function selectFake() { |
| 21358 |
var _this = this; |
| 21359 |
|
| 21360 |
var isRTL = document.documentElement.getAttribute('dir') == 'rtl'; |
| 21361 |
|
| 21362 |
this.removeFake(); |
| 21363 |
|
| 21364 |
this.fakeHandlerCallback = function () { |
| 21365 |
return _this.removeFake(); |
| 21366 |
}; |
| 21367 |
this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true; |
| 21368 |
|
| 21369 |
this.fakeElem = document.createElement('textarea'); |
| 21370 |
// Prevent zooming on iOS |
| 21371 |
this.fakeElem.style.fontSize = '12pt'; |
| 21372 |
// Reset box model |
| 21373 |
this.fakeElem.style.border = '0'; |
| 21374 |
this.fakeElem.style.padding = '0'; |
| 21375 |
this.fakeElem.style.margin = '0'; |
| 21376 |
// Move element out of screen horizontally |
| 21377 |
this.fakeElem.style.position = 'absolute'; |
| 21378 |
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; |
| 21379 |
// Move element to the same position vertically |
| 21380 |
var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
| 21381 |
this.fakeElem.style.top = yPosition + 'px'; |
| 21382 |
|
| 21383 |
this.fakeElem.setAttribute('readonly', ''); |
| 21384 |
this.fakeElem.value = this.text; |
| 21385 |
|
| 21386 |
document.body.appendChild(this.fakeElem); |
| 21387 |
|
| 21388 |
this.selectedText = (0, _select2.default)(this.fakeElem); |
| 21389 |
this.copyText(); |
| 21390 |
} |
| 21391 |
}, { |
| 21392 |
key: 'removeFake', |
| 21393 |
value: function removeFake() { |
| 21394 |
if (this.fakeHandler) { |
| 21395 |
document.body.removeEventListener('click', this.fakeHandlerCallback); |
| 21396 |
this.fakeHandler = null; |
| 21397 |
this.fakeHandlerCallback = null; |
| 21398 |
} |
| 21399 |
|
| 21400 |
if (this.fakeElem) { |
| 21401 |
document.body.removeChild(this.fakeElem); |
| 21402 |
this.fakeElem = null; |
| 21403 |
} |
| 21404 |
} |
| 21405 |
}, { |
| 21406 |
key: 'selectTarget', |
| 21407 |
value: function selectTarget() { |
| 21408 |
this.selectedText = (0, _select2.default)(this.target); |
| 21409 |
this.copyText(); |
| 21410 |
} |
| 21411 |
}, { |
| 21412 |
key: 'copyText', |
| 21413 |
value: function copyText() { |
| 21414 |
var succeeded = void 0; |
| 21415 |
|
| 21416 |
try { |
| 21417 |
succeeded = document.execCommand(this.action); |
| 21418 |
} catch (err) { |
| 21419 |
succeeded = false; |
| 21420 |
} |
| 21421 |
|
| 21422 |
this.handleResult(succeeded); |
| 21423 |
} |
| 21424 |
}, { |
| 21425 |
key: 'handleResult', |
| 21426 |
value: function handleResult(succeeded) { |
| 21427 |
this.emitter.emit(succeeded ? 'success' : 'error', { |
| 21428 |
action: this.action, |
| 21429 |
text: this.selectedText, |
| 21430 |
trigger: this.trigger, |
| 21431 |
clearSelection: this.clearSelection.bind(this) |
| 21432 |
}); |
| 21433 |
} |
| 21434 |
}, { |
| 21435 |
key: 'clearSelection', |
| 21436 |
value: function clearSelection() { |
| 21437 |
if (this.target) { |
| 21438 |
this.target.blur(); |
| 21439 |
} |
| 21440 |
|
| 21441 |
window.getSelection().removeAllRanges(); |
| 21442 |
} |
| 21443 |
}, { |
| 21444 |
key: 'destroy', |
| 21445 |
value: function destroy() { |
| 21446 |
this.removeFake(); |
| 21447 |
} |
| 21448 |
}, { |
| 21449 |
key: 'action', |
| 21450 |
set: function set() { |
| 21451 |
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; |
| 21452 |
|
| 21453 |
this._action = action; |
| 21454 |
|
| 21455 |
if (this._action !== 'copy' && this._action !== 'cut') { |
| 21456 |
throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
| 21457 |
} |
| 21458 |
}, |
| 21459 |
get: function get() { |
| 21460 |
return this._action; |
| 21461 |
} |
| 21462 |
}, { |
| 21463 |
key: 'target', |
| 21464 |
set: function set(target) { |
| 21465 |
if (target !== undefined) { |
| 21466 |
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) { |
| 21467 |
if (this.action === 'copy' && target.hasAttribute('disabled')) { |
| 21468 |
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
| 21469 |
} |
| 21470 |
|
| 21471 |
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
| 21472 |
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
| 21473 |
} |
| 21474 |
|
| 21475 |
this._target = target; |
| 21476 |
} else { |
| 21477 |
throw new Error('Invalid "target" value, use a valid Element'); |
| 21478 |
} |
| 21479 |
} |
| 21480 |
}, |
| 21481 |
get: function get() { |
| 21482 |
return this._target; |
| 21483 |
} |
| 21484 |
}]); |
| 21485 |
|
| 21486 |
return ClipboardAction; |
| 21487 |
}(); |
| 21488 |
|
| 21489 |
module.exports = ClipboardAction; |
| 21490 |
}); |
| 21491 |
|
| 21492 |
},{"select":5}],8:[function(require,module,exports){ |
| 21493 |
(function (global, factory) { |
| 21494 |
if (typeof define === "function" && define.amd) { |
| 21495 |
define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory); |
| 21496 |
} else if (typeof exports !== "undefined") { |
| 21497 |
factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener')); |
| 21498 |
} else { |
| 21499 |
var mod = { |
| 21500 |
exports: {} |
| 21501 |
}; |
| 21502 |
factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener); |
| 21503 |
global.clipboard = mod.exports; |
| 21504 |
} |
| 21505 |
})(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) { |
| 21506 |
'use strict'; |
| 21507 |
|
| 21508 |
var _clipboardAction2 = _interopRequireDefault(_clipboardAction); |
| 21509 |
|
| 21510 |
var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter); |
| 21511 |
|
| 21512 |
var _goodListener2 = _interopRequireDefault(_goodListener); |
| 21513 |
|
| 21514 |
function _interopRequireDefault(obj) { |
| 21515 |
return obj && obj.__esModule ? obj : { |
| 21516 |
default: obj |
| 21517 |
}; |
| 21518 |
} |
| 21519 |
|
| 21520 |
function _classCallCheck(instance, Constructor) { |
| 21521 |
if (!(instance instanceof Constructor)) { |
| 21522 |
throw new TypeError("Cannot call a class as a function"); |
| 21523 |
} |
| 21524 |
} |
| 21525 |
|
| 21526 |
var _createClass = function () { |
| 21527 |
function defineProperties(target, props) { |
| 21528 |
for (var i = 0; i < props.length; i++) { |
| 21529 |
var descriptor = props[i]; |
| 21530 |
descriptor.enumerable = descriptor.enumerable || false; |
| 21531 |
descriptor.configurable = true; |
| 21532 |
if ("value" in descriptor) descriptor.writable = true; |
| 21533 |
Object.defineProperty(target, descriptor.key, descriptor); |
| 21534 |
} |
| 21535 |
} |
| 21536 |
|
| 21537 |
return function (Constructor, protoProps, staticProps) { |
| 21538 |
if (protoProps) defineProperties(Constructor.prototype, protoProps); |
| 21539 |
if (staticProps) defineProperties(Constructor, staticProps); |
| 21540 |
return Constructor; |
| 21541 |
}; |
| 21542 |
}(); |
| 21543 |
|
| 21544 |
function _possibleConstructorReturn(self, call) { |
| 21545 |
if (!self) { |
| 21546 |
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
| 21547 |
} |
| 21548 |
|
| 21549 |
return call && (typeof call === "object" || typeof call === "function") ? call : self; |
| 21550 |
} |
| 21551 |
|
| 21552 |
function _inherits(subClass, superClass) { |
| 21553 |
if (typeof superClass !== "function" && superClass !== null) { |
| 21554 |
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); |
| 21555 |
} |
| 21556 |
|
| 21557 |
subClass.prototype = Object.create(superClass && superClass.prototype, { |
| 21558 |
constructor: { |
| 21559 |
value: subClass, |
| 21560 |
enumerable: false, |
| 21561 |
writable: true, |
| 21562 |
configurable: true |
| 21563 |
} |
| 21564 |
}); |
| 21565 |
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; |
| 21566 |
} |
| 21567 |
|
| 21568 |
var Clipboard = function (_Emitter) { |
| 21569 |
_inherits(Clipboard, _Emitter); |
| 21570 |
|
| 21571 |
/** |
| 21572 |
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
| 21573 |
* @param {Object} options |
| 21574 |
*/ |
| 21575 |
function Clipboard(trigger, options) { |
| 21576 |
_classCallCheck(this, Clipboard); |
| 21577 |
|
| 21578 |
var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); |
| 21579 |
|
| 21580 |
_this.resolveOptions(options); |
| 21581 |
_this.listenClick(trigger); |
| 21582 |
return _this; |
| 21583 |
} |
| 21584 |
|
| 21585 |
/** |
| 21586 |
* Defines if attributes would be resolved using internal setter functions |
| 21587 |
* or custom functions that were passed in the constructor. |
| 21588 |
* @param {Object} options |
| 21589 |
*/ |
| 21590 |
|
| 21591 |
|
| 21592 |
_createClass(Clipboard, [{ |
| 21593 |
key: 'resolveOptions', |
| 21594 |
value: function resolveOptions() { |
| 21595 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 21596 |
|
| 21597 |
this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
| 21598 |
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
| 21599 |
this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
| 21600 |
} |
| 21601 |
}, { |
| 21602 |
key: 'listenClick', |
| 21603 |
value: function listenClick(trigger) { |
| 21604 |
var _this2 = this; |
| 21605 |
|
| 21606 |
this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { |
| 21607 |
return _this2.onClick(e); |
| 21608 |
}); |
| 21609 |
} |
| 21610 |
}, { |
| 21611 |
key: 'onClick', |
| 21612 |
value: function onClick(e) { |
| 21613 |
var trigger = e.delegateTarget || e.currentTarget; |
| 21614 |
|
| 21615 |
if (this.clipboardAction) { |
| 21616 |
this.clipboardAction = null; |
| 21617 |
} |
| 21618 |
|
| 21619 |
this.clipboardAction = new _clipboardAction2.default({ |
| 21620 |
action: this.action(trigger), |
| 21621 |
target: this.target(trigger), |
| 21622 |
text: this.text(trigger), |
| 21623 |
trigger: trigger, |
| 21624 |
emitter: this |
| 21625 |
}); |
| 21626 |
} |
| 21627 |
}, { |
| 21628 |
key: 'defaultAction', |
| 21629 |
value: function defaultAction(trigger) { |
| 21630 |
return getAttributeValue('action', trigger); |
| 21631 |
} |
| 21632 |
}, { |
| 21633 |
key: 'defaultTarget', |
| 21634 |
value: function defaultTarget(trigger) { |
| 21635 |
var selector = getAttributeValue('target', trigger); |
| 21636 |
|
| 21637 |
if (selector) { |
| 21638 |
return document.querySelector(selector); |
| 21639 |
} |
| 21640 |
} |
| 21641 |
}, { |
| 21642 |
key: 'defaultText', |
| 21643 |
value: function defaultText(trigger) { |
| 21644 |
return getAttributeValue('text', trigger); |
| 21645 |
} |
| 21646 |
}, { |
| 21647 |
key: 'destroy', |
| 21648 |
value: function destroy() { |
| 21649 |
this.listener.destroy(); |
| 21650 |
|
| 21651 |
if (this.clipboardAction) { |
| 21652 |
this.clipboardAction.destroy(); |
| 21653 |
this.clipboardAction = null; |
| 21654 |
} |
| 21655 |
} |
| 21656 |
}], [{ |
| 21657 |
key: 'isSupported', |
| 21658 |
value: function isSupported() { |
| 21659 |
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
| 21660 |
|
| 21661 |
var actions = typeof action === 'string' ? [action] : action; |
| 21662 |
var support = !!document.queryCommandSupported; |
| 21663 |
|
| 21664 |
actions.forEach(function (action) { |
| 21665 |
support = support && !!document.queryCommandSupported(action); |
| 21666 |
}); |
| 21667 |
|
| 21668 |
return support; |
| 21669 |
} |
| 21670 |
}]); |
| 21671 |
|
| 21672 |
return Clipboard; |
| 21673 |
}(_tinyEmitter2.default); |
| 21674 |
|
| 21675 |
/** |
| 21676 |
* Helper function to retrieve attribute value. |
| 21677 |
* @param {String} suffix |
| 21678 |
* @param {Element} element |
| 21679 |
*/ |
| 21680 |
function getAttributeValue(suffix, element) { |
| 21681 |
var attribute = 'data-clipboard-' + suffix; |
| 21682 |
|
| 21683 |
if (!element.hasAttribute(attribute)) { |
| 21684 |
return; |
| 21685 |
} |
| 21686 |
|
| 21687 |
return element.getAttribute(attribute); |
| 21688 |
} |
| 21689 |
|
| 21690 |
module.exports = Clipboard; |
| 21691 |
}); |
| 21692 |
|
| 21693 |
},{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8) |
| 21694 |
}); |
| 21695 |
/* assets/wpuf/vendor/tooltip/tooltip.js */ |
| 21696 |
/* ======================================================================== |
| 21697 |
* Bootstrap: tooltip.js v3.3.7 |
| 21698 |
* http://getbootstrap.com/javascript/#tooltip |
| 21699 |
* Inspired by the original jQuery.tipsy by Jason Frame |
| 21700 |
* ======================================================================== |
| 21701 |
* Copyright 2011-2016 Twitter, Inc. |
| 21702 |
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) |
| 21703 |
* ======================================================================== */ |
| 21704 |
|
| 21705 |
+function ($) { |
| 21706 |
'use strict'; |
| 21707 |
$.support.transition = false; |
| 21708 |
|
| 21709 |
// TOOLTIP PUBLIC CLASS DEFINITION |
| 21710 |
// =============================== |
| 21711 |
|
| 21712 |
var Tooltip = function (element, options) { |
| 21713 |
this.type = null |
| 21714 |
this.options = null |
| 21715 |
this.enabled = null |
| 21716 |
this.timeout = null |
| 21717 |
this.hoverState = null |
| 21718 |
this.$element = null |
| 21719 |
this.inState = null |
| 21720 |
|
| 21721 |
this.init('tooltip', element, options) |
| 21722 |
} |
| 21723 |
|
| 21724 |
Tooltip.VERSION = '3.3.7' |
| 21725 |
|
| 21726 |
Tooltip.TRANSITION_DURATION = 150 |
| 21727 |
|
| 21728 |
Tooltip.DEFAULTS = { |
| 21729 |
animation: true, |
| 21730 |
placement: 'top', |
| 21731 |
selector: false, |
| 21732 |
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', |
| 21733 |
trigger: 'hover focus', |
| 21734 |
title: '', |
| 21735 |
delay: 0, |
| 21736 |
html: false, |
| 21737 |
container: false, |
| 21738 |
viewport: { |
| 21739 |
selector: 'body', |
| 21740 |
padding: 0 |
| 21741 |
} |
| 21742 |
} |
| 21743 |
|
| 21744 |
Tooltip.prototype.init = function (type, element, options) { |
| 21745 |
this.enabled = true |
| 21746 |
this.type = type |
| 21747 |
this.$element = $(element) |
| 21748 |
this.options = this.getOptions(options) |
| 21749 |
this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport)) |
| 21750 |
this.inState = { click: false, hover: false, focus: false } |
| 21751 |
|
| 21752 |
if (this.$element[0] instanceof document.constructor && !this.options.selector) { |
| 21753 |
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!') |
| 21754 |
} |
| 21755 |
|
| 21756 |
var triggers = this.options.trigger.split(' ') |
| 21757 |
|
| 21758 |
for (var i = triggers.length; i--;) { |
| 21759 |
var trigger = triggers[i] |
| 21760 |
|
| 21761 |
if (trigger == 'click') { |
| 21762 |
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) |
| 21763 |
} else if (trigger != 'manual') { |
| 21764 |
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' |
| 21765 |
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' |
| 21766 |
|
| 21767 |
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) |
| 21768 |
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) |
| 21769 |
} |
| 21770 |
} |
| 21771 |
|
| 21772 |
this.options.selector ? |
| 21773 |
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : |
| 21774 |
this.fixTitle() |
| 21775 |
} |
| 21776 |
|
| 21777 |
Tooltip.prototype.getDefaults = function () { |
| 21778 |
return Tooltip.DEFAULTS |
| 21779 |
} |
| 21780 |
|
| 21781 |
Tooltip.prototype.getOptions = function (options) { |
| 21782 |
options = $.extend({}, this.getDefaults(), this.$element.data(), options) |
| 21783 |
|
| 21784 |
if (options.delay && typeof options.delay == 'number') { |
| 21785 |
options.delay = { |
| 21786 |
show: options.delay, |
| 21787 |
hide: options.delay |
| 21788 |
} |
| 21789 |
} |
| 21790 |
|
| 21791 |
return options |
| 21792 |
} |
| 21793 |
|
| 21794 |
Tooltip.prototype.getDelegateOptions = function () { |
| 21795 |
var options = {} |
| 21796 |
var defaults = this.getDefaults() |
| 21797 |
|
| 21798 |
this._options && $.each(this._options, function (key, value) { |
| 21799 |
if (defaults[key] != value) options[key] = value |
| 21800 |
}) |
| 21801 |
|
| 21802 |
return options |
| 21803 |
} |
| 21804 |
|
| 21805 |
Tooltip.prototype.enter = function (obj) { |
| 21806 |
var self = obj instanceof this.constructor ? |
| 21807 |
obj : $(obj.currentTarget).data('bs.' + this.type) |
| 21808 |
|
| 21809 |
if (!self) { |
| 21810 |
self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) |
| 21811 |
$(obj.currentTarget).data('bs.' + this.type, self) |
| 21812 |
} |
| 21813 |
|
| 21814 |
if (obj instanceof $.Event) { |
| 21815 |
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true |
| 21816 |
} |
| 21817 |
|
| 21818 |
if (self.tip().hasClass('in') || self.hoverState == 'in') { |
| 21819 |
self.hoverState = 'in' |
| 21820 |
return |
| 21821 |
} |
| 21822 |
|
| 21823 |
clearTimeout(self.timeout) |
| 21824 |
|
| 21825 |
self.hoverState = 'in' |
| 21826 |
|
| 21827 |
if (!self.options.delay || !self.options.delay.show) return self.show() |
| 21828 |
|
| 21829 |
self.timeout = setTimeout(function () { |
| 21830 |
if (self.hoverState == 'in') self.show() |
| 21831 |
}, self.options.delay.show) |
| 21832 |
} |
| 21833 |
|
| 21834 |
Tooltip.prototype.isInStateTrue = function () { |
| 21835 |
for (var key in this.inState) { |
| 21836 |
if (this.inState[key]) return true |
| 21837 |
} |
| 21838 |
|
| 21839 |
return false |
| 21840 |
} |
| 21841 |
|
| 21842 |
Tooltip.prototype.leave = function (obj) { |
| 21843 |
var self = obj instanceof this.constructor ? |
| 21844 |
obj : $(obj.currentTarget).data('bs.' + this.type) |
| 21845 |
|
| 21846 |
if (!self) { |
| 21847 |
self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) |
| 21848 |
$(obj.currentTarget).data('bs.' + this.type, self) |
| 21849 |
} |
| 21850 |
|
| 21851 |
if (obj instanceof $.Event) { |
| 21852 |
self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false |
| 21853 |
} |
| 21854 |
|
| 21855 |
if (self.isInStateTrue()) return |
| 21856 |
|
| 21857 |
clearTimeout(self.timeout) |
| 21858 |
|
| 21859 |
self.hoverState = 'out' |
| 21860 |
|
| 21861 |
if (!self.options.delay || !self.options.delay.hide) return self.hide() |
| 21862 |
|
| 21863 |
self.timeout = setTimeout(function () { |
| 21864 |
if (self.hoverState == 'out') self.hide() |
| 21865 |
}, self.options.delay.hide) |
| 21866 |
} |
| 21867 |
|
| 21868 |
Tooltip.prototype.show = function () { |
| 21869 |
var e = $.Event('show.bs.' + this.type) |
| 21870 |
|
| 21871 |
if (this.hasContent() && this.enabled) { |
| 21872 |
this.$element.trigger(e) |
| 21873 |
|
| 21874 |
var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]) |
| 21875 |
if (e.isDefaultPrevented() || !inDom) return |
| 21876 |
var that = this |
| 21877 |
|
| 21878 |
var $tip = this.tip() |
| 21879 |
|
| 21880 |
var tipId = this.getUID(this.type) |
| 21881 |
|
| 21882 |
this.setContent() |
| 21883 |
$tip.attr('id', tipId) |
| 21884 |
this.$element.attr('aria-describedby', tipId) |
| 21885 |
|
| 21886 |
if (this.options.animation) $tip.addClass('fade') |
| 21887 |
|
| 21888 |
var placement = typeof this.options.placement == 'function' ? |
| 21889 |
this.options.placement.call(this, $tip[0], this.$element[0]) : |
| 21890 |
this.options.placement |
| 21891 |
|
| 21892 |
var autoToken = /\s?auto?\s?/i |
| 21893 |
var autoPlace = autoToken.test(placement) |
| 21894 |
if (autoPlace) placement = placement.replace(autoToken, '') || 'top' |
| 21895 |
|
| 21896 |
$tip |
| 21897 |
.detach() |
| 21898 |
.css({ top: 0, left: 0, display: 'block' }) |
| 21899 |
.addClass(placement) |
| 21900 |
.data('bs.' + this.type, this) |
| 21901 |
|
| 21902 |
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) |
| 21903 |
this.$element.trigger('inserted.bs.' + this.type) |
| 21904 |
|
| 21905 |
var pos = this.getPosition() |
| 21906 |
var actualWidth = $tip[0].offsetWidth |
| 21907 |
var actualHeight = $tip[0].offsetHeight |
| 21908 |
|
| 21909 |
if (autoPlace) { |
| 21910 |
var orgPlacement = placement |
| 21911 |
var viewportDim = this.getPosition(this.$viewport) |
| 21912 |
|
| 21913 |
placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' : |
| 21914 |
placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' : |
| 21915 |
placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' : |
| 21916 |
placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' : |
| 21917 |
placement |
| 21918 |
|
| 21919 |
$tip |
| 21920 |
.removeClass(orgPlacement) |
| 21921 |
.addClass(placement) |
| 21922 |
} |
| 21923 |
|
| 21924 |
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) |
| 21925 |
|
| 21926 |
this.applyPlacement(calculatedOffset, placement) |
| 21927 |
|
| 21928 |
var complete = function () { |
| 21929 |
var prevHoverState = that.hoverState |
| 21930 |
that.$element.trigger('shown.bs.' + that.type) |
| 21931 |
that.hoverState = null |
| 21932 |
|
| 21933 |
if (prevHoverState == 'out') that.leave(that) |
| 21934 |
} |
| 21935 |
|
| 21936 |
$.support.transition && this.$tip.hasClass('fade') ? |
| 21937 |
$tip |
| 21938 |
.one('bsTransitionEnd', complete) |
| 21939 |
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : |
| 21940 |
complete() |
| 21941 |
} |
| 21942 |
} |
| 21943 |
|
| 21944 |
Tooltip.prototype.applyPlacement = function (offset, placement) { |
| 21945 |
var $tip = this.tip() |
| 21946 |
var width = $tip[0].offsetWidth |
| 21947 |
var height = $tip[0].offsetHeight |
| 21948 |
|
| 21949 |
// manually read margins because getBoundingClientRect includes difference |
| 21950 |
var marginTop = parseInt($tip.css('margin-top'), 10) |
| 21951 |
var marginLeft = parseInt($tip.css('margin-left'), 10) |
| 21952 |
|
| 21953 |
// we must check for NaN for ie 8/9 |
| 21954 |
if (isNaN(marginTop)) marginTop = 0 |
| 21955 |
if (isNaN(marginLeft)) marginLeft = 0 |
| 21956 |
|
| 21957 |
offset.top += marginTop |
| 21958 |
offset.left += marginLeft |
| 21959 |
|
| 21960 |
// $.fn.offset doesn't round pixel values |
| 21961 |
// so we use setOffset directly with our own function B-0 |
| 21962 |
$.offset.setOffset($tip[0], $.extend({ |
| 21963 |
using: function (props) { |
| 21964 |
$tip.css({ |
| 21965 |
top: Math.round(props.top), |
| 21966 |
left: Math.round(props.left) |
| 21967 |
}) |
| 21968 |
} |
| 21969 |
}, offset), 0) |
| 21970 |
|
| 21971 |
$tip.addClass('in') |
| 21972 |
|
| 21973 |
// check to see if placing tip in new offset caused the tip to resize itself |
| 21974 |
var actualWidth = $tip[0].offsetWidth |
| 21975 |
var actualHeight = $tip[0].offsetHeight |
| 21976 |
|
| 21977 |
if (placement == 'top' && actualHeight != height) { |
| 21978 |
offset.top = offset.top + height - actualHeight |
| 21979 |
} |
| 21980 |
|
| 21981 |
var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight) |
| 21982 |
|
| 21983 |
if (delta.left) offset.left += delta.left |
| 21984 |
else offset.top += delta.top |
| 21985 |
|
| 21986 |
var isVertical = /top|bottom/.test(placement) |
| 21987 |
var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight |
| 21988 |
var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight' |
| 21989 |
|
| 21990 |
$tip.offset(offset) |
| 21991 |
this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical) |
| 21992 |
} |
| 21993 |
|
| 21994 |
Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) { |
| 21995 |
this.arrow() |
| 21996 |
.css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%') |
| 21997 |
.css(isVertical ? 'top' : 'left', '') |
| 21998 |
} |
| 21999 |
|
| 22000 |
Tooltip.prototype.setContent = function () { |
| 22001 |
var $tip = this.tip() |
| 22002 |
var title = this.getTitle() |
| 22003 |
|
| 22004 |
$tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) |
| 22005 |
$tip.removeClass('fade in top bottom left right') |
| 22006 |
} |
| 22007 |
|
| 22008 |
Tooltip.prototype.hide = function (callback) { |
| 22009 |
var that = this |
| 22010 |
var $tip = $(this.$tip) |
| 22011 |
var e = $.Event('hide.bs.' + this.type) |
| 22012 |
|
| 22013 |
function complete() { |
| 22014 |
if (that.hoverState != 'in') $tip.detach() |
| 22015 |
if (that.$element) { // TODO: Check whether guarding this code with this `if` is really necessary. |
| 22016 |
that.$element |
| 22017 |
.removeAttr('aria-describedby') |
| 22018 |
.trigger('hidden.bs.' + that.type) |
| 22019 |
} |
| 22020 |
callback && callback() |
| 22021 |
} |
| 22022 |
|
| 22023 |
this.$element.trigger(e) |
| 22024 |
|
| 22025 |
if (e.isDefaultPrevented()) return |
| 22026 |
|
| 22027 |
$tip.removeClass('in') |
| 22028 |
|
| 22029 |
$.support.transition && $tip.hasClass('fade') ? |
| 22030 |
$tip |
| 22031 |
.one('bsTransitionEnd', complete) |
| 22032 |
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : |
| 22033 |
complete() |
| 22034 |
|
| 22035 |
this.hoverState = null |
| 22036 |
|
| 22037 |
return this |
| 22038 |
} |
| 22039 |
|
| 22040 |
Tooltip.prototype.fixTitle = function () { |
| 22041 |
var $e = this.$element |
| 22042 |
if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') { |
| 22043 |
$e.attr('data-original-title', $e.attr('title') || '').attr('title', '') |
| 22044 |
} |
| 22045 |
} |
| 22046 |
|
| 22047 |
Tooltip.prototype.hasContent = function () { |
| 22048 |
return this.getTitle() |
| 22049 |
} |
| 22050 |
|
| 22051 |
Tooltip.prototype.getPosition = function ($element) { |
| 22052 |
$element = $element || this.$element |
| 22053 |
|
| 22054 |
var el = $element[0] |
| 22055 |
var isBody = el.tagName == 'BODY' |
| 22056 |
|
| 22057 |
var elRect = el.getBoundingClientRect() |
| 22058 |
if (elRect.width == null) { |
| 22059 |
// width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093 |
| 22060 |
elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top }) |
| 22061 |
} |
| 22062 |
var isSvg = window.SVGElement && el instanceof window.SVGElement |
| 22063 |
// Avoid using $.offset() on SVGs since it gives incorrect results in jQuery 3. |
| 22064 |
// See https://github.com/twbs/bootstrap/issues/20280 |
| 22065 |
var elOffset = isBody ? { top: 0, left: 0 } : (isSvg ? null : $element.offset()) |
| 22066 |
var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() } |
| 22067 |
var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null |
| 22068 |
|
| 22069 |
return $.extend({}, elRect, scroll, outerDims, elOffset) |
| 22070 |
} |
| 22071 |
|
| 22072 |
Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { |
| 22073 |
return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : |
| 22074 |
placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : |
| 22075 |
placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : |
| 22076 |
/* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } |
| 22077 |
|
| 22078 |
} |
| 22079 |
|
| 22080 |
Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { |
| 22081 |
var delta = { top: 0, left: 0 } |
| 22082 |
if (!this.$viewport) return delta |
| 22083 |
|
| 22084 |
var viewportPadding = this.options.viewport && this.options.viewport.padding || 0 |
| 22085 |
var viewportDimensions = this.getPosition(this.$viewport) |
| 22086 |
|
| 22087 |
if (/right|left/.test(placement)) { |
| 22088 |
var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll |
| 22089 |
var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight |
| 22090 |
if (topEdgeOffset < viewportDimensions.top) { // top overflow |
| 22091 |
delta.top = viewportDimensions.top - topEdgeOffset |
| 22092 |
} else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow |
| 22093 |
delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset |
| 22094 |
} |
| 22095 |
} else { |
| 22096 |
var leftEdgeOffset = pos.left - viewportPadding |
| 22097 |
var rightEdgeOffset = pos.left + viewportPadding + actualWidth |
| 22098 |
if (leftEdgeOffset < viewportDimensions.left) { // left overflow |
| 22099 |
delta.left = viewportDimensions.left - leftEdgeOffset |
| 22100 |
} else if (rightEdgeOffset > viewportDimensions.right) { // right overflow |
| 22101 |
delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset |
| 22102 |
} |
| 22103 |
} |
| 22104 |
|
| 22105 |
return delta |
| 22106 |
} |
| 22107 |
|
| 22108 |
Tooltip.prototype.getTitle = function () { |
| 22109 |
var title |
| 22110 |
var $e = this.$element |
| 22111 |
var o = this.options |
| 22112 |
|
| 22113 |
title = $e.attr('data-original-title') |
| 22114 |
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) |
| 22115 |
|
| 22116 |
return title |
| 22117 |
} |
| 22118 |
|
| 22119 |
Tooltip.prototype.getUID = function (prefix) { |
| 22120 |
do prefix += ~~(Math.random() * 1000000) |
| 22121 |
while (document.getElementById(prefix)) |
| 22122 |
return prefix |
| 22123 |
} |
| 22124 |
|
| 22125 |
Tooltip.prototype.tip = function () { |
| 22126 |
if (!this.$tip) { |
| 22127 |
this.$tip = $(this.options.template) |
| 22128 |
if (this.$tip.length != 1) { |
| 22129 |
throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!') |
| 22130 |
} |
| 22131 |
} |
| 22132 |
return this.$tip |
| 22133 |
} |
| 22134 |
|
| 22135 |
Tooltip.prototype.arrow = function () { |
| 22136 |
return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) |
| 22137 |
} |
| 22138 |
|
| 22139 |
Tooltip.prototype.enable = function () { |
| 22140 |
this.enabled = true |
| 22141 |
} |
| 22142 |
|
| 22143 |
Tooltip.prototype.disable = function () { |
| 22144 |
this.enabled = false |
| 22145 |
} |
| 22146 |
|
| 22147 |
Tooltip.prototype.toggleEnabled = function () { |
| 22148 |
this.enabled = !this.enabled |
| 22149 |
} |
| 22150 |
|
| 22151 |
Tooltip.prototype.toggle = function (e) { |
| 22152 |
var self = this |
| 22153 |
if (e) { |
| 22154 |
self = $(e.currentTarget).data('bs.' + this.type) |
| 22155 |
if (!self) { |
| 22156 |
self = new this.constructor(e.currentTarget, this.getDelegateOptions()) |
| 22157 |
$(e.currentTarget).data('bs.' + this.type, self) |
| 22158 |
} |
| 22159 |
} |
| 22160 |
|
| 22161 |
if (e) { |
| 22162 |
self.inState.click = !self.inState.click |
| 22163 |
if (self.isInStateTrue()) self.enter(self) |
| 22164 |
else self.leave(self) |
| 22165 |
} else { |
| 22166 |
self.tip().hasClass('in') ? self.leave(self) : self.enter(self) |
| 22167 |
} |
| 22168 |
} |
| 22169 |
|
| 22170 |
Tooltip.prototype.destroy = function () { |
| 22171 |
var that = this |
| 22172 |
clearTimeout(this.timeout) |
| 22173 |
this.hide(function () { |
| 22174 |
that.$element.off('.' + that.type).removeData('bs.' + that.type) |
| 22175 |
if (that.$tip) { |
| 22176 |
that.$tip.detach() |
| 22177 |
} |
| 22178 |
that.$tip = null |
| 22179 |
that.$arrow = null |
| 22180 |
that.$viewport = null |
| 22181 |
that.$element = null |
| 22182 |
}) |
| 22183 |
} |
| 22184 |
|
| 22185 |
|
| 22186 |
// TOOLTIP PLUGIN DEFINITION |
| 22187 |
// ========================= |
| 22188 |
|
| 22189 |
function Plugin(option) { |
| 22190 |
return this.each(function () { |
| 22191 |
var $this = $(this) |
| 22192 |
var data = $this.data('bs.tooltip') |
| 22193 |
var options = typeof option == 'object' && option |
| 22194 |
|
| 22195 |
if (!data && /destroy|hide/.test(option)) return |
| 22196 |
if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) |
| 22197 |
if (typeof option == 'string') data[option]() |
| 22198 |
}) |
| 22199 |
} |
| 22200 |
|
| 22201 |
var old = $.fn.tooltip |
| 22202 |
|
| 22203 |
$.fn.tooltip = Plugin |
| 22204 |
$.fn.tooltip.Constructor = Tooltip |
| 22205 |
|
| 22206 |
|
| 22207 |
// TOOLTIP NO CONFLICT |
| 22208 |
// =================== |
| 22209 |
|
| 22210 |
$.fn.tooltip.noConflict = function () { |
| 22211 |
$.fn.tooltip = old |
| 22212 |
return this |
| 22213 |
} |
| 22214 |
|
| 22215 |
}(jQuery); |
| 22216 |
|
| 22217 |
/* assets/js/vendor/tinymce/plugins/code/plugin.min.js */ |
| 22218 |
tinymce.PluginManager.add("code",function(a){function b(){var b=a.windowManager.open({title:"Source code",body:{type:"textbox",name:"code",multiline:!0,minWidth:a.getParam("code_dialog_width",600),minHeight:a.getParam("code_dialog_height",Math.min(tinymce.DOM.getViewPort().h-200,500)),spellcheck:!1,style:"direction: ltr; text-align: left"},onSubmit:function(b){a.focus(),a.undoManager.transact(function(){a.setContent(b.data.code)}),a.selection.setCursorLocation(),a.nodeChanged()}});b.find("#code").value(a.getContent({source_view:!0}))}a.addCommand("mceCodeEditor",b),a.addButton("code",{icon:"code",tooltip:"Source code",onclick:b}),a.addMenuItem("code",{icon:"code",text:"Source code",context:"tools",onclick:b})}); |
| 22219 |
/* assets/js/vendor/tinymce/plugins/hr/plugin.min.js */ |
| 22220 |
tinymce.PluginManager.add("hr",function(a){a.addCommand("InsertHorizontalRule",function(){a.execCommand("mceInsertContent",!1,"<hr />")}),a.addButton("hr",{icon:"hr",tooltip:"Horizontal line",cmd:"InsertHorizontalRule"}),a.addMenuItem("hr",{icon:"hr",text:"Horizontal line",cmd:"InsertHorizontalRule",context:"insert"})}); |