diff --git a/WebContent/js/bootstrap-table.js b/WebContent/js/bootstrap-table.js index 6468574..4af0028 100644 --- a/WebContent/js/bootstrap-table.js +++ b/WebContent/js/bootstrap-table.js @@ -1,484 +1,656 @@ +// 立即执行函数,用于模块的导出和导入处理,根据不同的环境(CommonJS、AMD、全局变量等)来定义模块的导出方式 +// 如果是CommonJS环境(如Node.js中使用require),则将factory返回的结果赋值给module.exports +// 如果是AMD环境(如使用define来定义模块),则通过define来注册模块并传入依赖和factory +// 如果都不是,则将结果挂载到全局对象(如浏览器的window对象)上作为BootstrapTable (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) : - typeof define === 'function' && define.amd ? define(['jquery'], factory) : - (global = global || self, global.BootstrapTable = factory(global.jQuery)); + typeof exports === 'object' && typeof module!== 'undefined'? module.exports = factory(require('jquery')) : + typeof define === 'function' && define.amd? define(['jquery'], factory) : + (global = global || self, global.BootstrapTable = factory(global.jQuery)); }(this, (function ($) { 'use strict'; - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + // 如果传入的$对象有default属性,则取其default属性作为真正的$对象,否则直接使用传入的$对象 + $ = $ && $.hasOwnProperty('default')? $['default'] : $; - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + // 根据不同的全局对象存在情况,确定当前的全局对象(优先尝试globalThis,然后是window、global、self等) + var commonjsGlobal = typeof globalThis!== 'undefined'? globalThis : typeof window!== 'undefined'? window : typeof global!== 'undefined'? global : typeof self!== 'undefined'? self : {}; + // 创建一个CommonJS模块的函数,接收一个函数fn和模块对象module + // 执行fn并传入module和module.exports,最后返回module.exports作为模块的导出内容 function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } + // 检查传入的对象it是否是合法的全局对象(通过判断是否有Math属性且与全局的Math对象相等来简单验证) var check = function (it) { - return it && it.Math == Math && it; + return it && it.Math == Math && it; }; - // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + // 获取全局对象,通过依次检查不同的全局对象可能性(globalThis、window、self、commonjsGlobal等) + // 如果都不符合则通过创建一个返回this的函数来获取当前上下文的this作为全局对象(在非严格模式下会指向全局对象) var global_1 = - // eslint-disable-next-line no-undef - check(typeof globalThis == 'object' && globalThis) || - check(typeof window == 'object' && window) || - check(typeof self == 'object' && self) || - check(typeof commonjsGlobal == 'object' && commonjsGlobal) || - // eslint-disable-next-line no-new-func - Function('return this')(); - + // eslint-disable-next-line no-undef + check(typeof globalThis == 'object' && globalThis) || + check(typeof window == 'object' && window) || + check(typeof self == 'object' && self) || + check(typeof commonjsGlobal == 'object' && commonjsGlobal) || + // eslint-disable-next-line no-new-func + Function('return this')(); + + // 执行传入的函数exec,如果执行过程中抛出错误则返回true,否则返回函数执行结果的布尔值 + // 用于检测某个操作是否会失败(比如在一些不支持的环境中执行特定代码可能会报错) var fails = function (exec) { - try { - return !!exec(); - } catch (error) { - return true; - } + try { + return!!exec(); + } catch (error) { + return true; + } }; - // Thank's IE8 for his funny defineProperty - var descriptors = !fails(function () { - return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; + // 检测当前环境是否支持Object.defineProperty的正常行为(通过创建一个带有getter的属性并检查获取的值是否正确来判断) + // 如果不支持(比如在IE8等老版本浏览器中),则descriptors为false + var descriptors =!fails(function () { + return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a!= 7; }); + // 获取原生的propertyIsEnumerable方法(用于判断对象的属性是否可枚举) var nativePropertyIsEnumerable = {}.propertyIsEnumerable; + // 获取Object.getOwnPropertyDescriptor方法(用于获取对象属性的描述符) var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; - // Nashorn ~ JDK8 bug - var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1); + // 检测是否存在Nashorn(Java中的JavaScript引擎)与JDK8相关的一个bug(通过检查获取对象属性描述符和原生的propertyIsEnumerable调用结果是否符合预期来判断) + // 如果存在该bug,则NASHORN_BUG为true + var NASHORN_BUG = getOwnPropertyDescriptor &&!nativePropertyIsEnumerable.call({ 1: 2 }, 1); - // `Object.prototype.propertyIsEnumerable` method implementation - // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable - var f = NASHORN_BUG ? function propertyIsEnumerable(V) { - var descriptor = getOwnPropertyDescriptor(this, V); - return !!descriptor && descriptor.enumerable; + // 根据是否存在NASHORN_BUG来定义propertyIsEnumerable方法的实现 + // 如果有bug,则通过获取属性描述符并检查其enumerable属性来判断是否可枚举 + // 如果没有bug,则直接使用原生的propertyIsEnumerable方法 + var f = NASHORN_BUG? function propertyIsEnumerable(V) { + var descriptor = getOwnPropertyDescriptor(this, V); + return!!descriptor && descriptor.enumerable; } : nativePropertyIsEnumerable; + // 将上述定义的propertyIsEnumerable方法封装到objectPropertyIsEnumerable对象中 var objectPropertyIsEnumerable = { f: f }; + // 根据传入的位图bitmap和值value创建一个属性描述符对象 + // 通过位图的不同位来设置属性的enumerable、configurable、writable等属性的值(位运算判断) var createPropertyDescriptor = function (bitmap, value) { - return { - enumerable: !(bitmap & 1), - configurable: !(bitmap & 2), - writable: !(bitmap & 4), - value: value - }; + return { + enumerable:!(bitmap & 1), + configurable:!(bitmap & 2), + writable:!(bitmap & 4), + value: value + }; }; + // 获取对象的类名(通过调用Object.prototype.toString并截取返回结果的一部分来获取) var toString = {}.toString; - var classofRaw = function (it) { - return toString.call(it).slice(8, -1); + return toString.call(it).slice(8, -1); }; + // 分割字符串的方法(获取空字符串的split方法作为一个函数引用,方便后续使用) var split = ''.split; - // fallback for non-array-like ES3 and non-enumerable old V8 strings + // 处理对象或字符串转换为索引对象(类似数组的可迭代对象)的情况 + // 如果当前环境对于非数组对象或非可枚举的老版本V8字符串有问题(通过检测是否能正确获取字符串的属性是否可枚举来判断) + // 则对字符串进行分割返回字符数组,否则直接返回传入的对象(通过Object进行包装转换为对象类型) var indexedObject = fails(function () { - // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 - // eslint-disable-next-line no-prototype-builtins - return !Object('z').propertyIsEnumerable(0); - }) ? function (it) { - return classofRaw(it) == 'String' ? split.call(it, '') : Object(it); + // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 + // eslint-disable-next-line no-prototype-builtins + return!Object('z').propertyIsEnumerable(0); + })? function (it) { + return classofRaw(it) == 'String'? split.call(it, '') : Object(it); } : Object; - // `RequireObjectCoercible` abstract operation - // https://tc39.github.io/ecma262/#sec-requireobjectcoercible + // 确保传入的参数可以转换为对象(如果是undefined则抛出TypeError异常,否则返回该参数本身) + // 类似于ES6中的 `Object` 抽象操作,用于在需要对象的地方进行参数的强制转换 var requireObjectCoercible = function (it) { - if (it == undefined) throw TypeError("Can't call method on " + it); - return it; + if (it == undefined) throw TypeError("Can't call method on " + it); + return it; }; - // toObject with fallback for non-array-like ES3 strings - - - + // 将传入的参数转换为索引对象(先通过requireObjectCoercible确保可以转换为对象,再调用indexedObject进行转换) var toIndexedObject = function (it) { - return indexedObject(requireObjectCoercible(it)); + return indexedObject(requireObjectCoercible(it)); }; + // 判断传入的参数是否为对象(包括函数类型,因为在JavaScript中函数也是对象) var isObject = function (it) { - return typeof it === 'object' ? it !== null : typeof it === 'function'; + return typeof it === 'object'? it!== null : typeof it === 'function'; }; - // `ToPrimitive` abstract operation - // https://tc39.github.io/ecma262/#sec-toprimitive - // instead of the ES6 spec version, we didn't implement @@toPrimitive case - // and the second argument - flag - preferred type is a string + // 将对象转换为原始值(遵循ToPrimitive抽象操作的逻辑,但简化了实现,未处理 @@toPrimitive 情况) + // 如果传入的参数不是对象则直接返回该参数 + // 优先尝试调用toString方法,如果返回值不是对象则返回该值;如果失败则尝试调用valueOf方法;如果还是失败且不要求返回字符串类型,则再次尝试toString方法 + // 如果最终都无法转换则抛出TypeError异常 var toPrimitive = function (input, PREFERRED_STRING) { - if (!isObject(input)) return input; - var fn, val; - if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; - if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val; - if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val; - throw TypeError("Can't convert object to primitive value"); + if (!isObject(input)) return input; + var fn, val; + if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' &&!isObject(val = fn.call(input))) return val; + if (typeof (fn = input.valueOf) == 'function' &&!isObject(val = fn.call(input))) return val; + if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' &&!isObject(val = fn.call(input))) return val; + throw TypeError("Can't convert object to primitive value"); }; + // 判断对象是否有指定的自有属性(通过调用原生的hasOwnProperty方法来判断) var hasOwnProperty = {}.hasOwnProperty; - var has = function (it, key) { - return hasOwnProperty.call(it, key); + return hasOwnProperty.call(it, key); }; + // 获取全局的document对象,同时检测document.createElement是否是合法的对象(在老IE中可能不是) var document$1 = global_1.document; - // typeof document.createElement is 'object' in old IE var EXISTS = isObject(document$1) && isObject(document$1.createElement); + // 创建一个指定标签名的DOM元素(如果EXISTS为true则通过document.createElement创建,否则返回一个空对象) var documentCreateElement = function (it) { - return EXISTS ? document$1.createElement(it) : {}; + return EXISTS? document$1.createElement(it) : {}; }; - // Thank's IE8 for his funny defineProperty - var ie8DomDefine = !descriptors && !fails(function () { - return Object.defineProperty(documentCreateElement('div'), 'a', { - get: function () { return 7; } - }).a != 7; + // 检测当前环境是否存在类似IE8中Object.defineProperty的奇怪行为(通过创建一个带有getter的DOM元素属性并检查获取的值是否正确来判断) + var ie8DomDefine =!descriptors &&!fails(function () { + return Object.defineProperty(documentCreateElement('div'), 'a', { + get: function () { return 7; } + }).a!= 7; }); + // 获取原生的Object.getOwnPropertyDescriptor方法(用于获取对象属性的描述符) var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; - // `Object.getOwnPropertyDescriptor` method - // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor - var f$1 = descriptors ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { - O = toIndexedObject(O); - P = toPrimitive(P, true); - if (ie8DomDefine) try { - return nativeGetOwnPropertyDescriptor(O, P); - } catch (error) { /* empty */ } - if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]); + // 根据是否支持descriptors以及当前环境情况来定义Object.getOwnPropertyDescriptor方法的实现 + // 如果支持descriptors则直接使用原生方法;如果不支持,则先将对象转换为索引对象,将属性名转换为原始值 + // 然后尝试使用原生方法获取描述符,如果失败(比如在ie8DomDefine的情况下可能会抛错)则根据对象是否有该属性来创建一个简单的属性描述符对象 + var f$1 = descriptors? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { + O = toIndexedObject(O); + P = toPrimitive(P, true); + if (ie8DomDefine) try { + return nativeGetOwnPropertyDescriptor(O, P); + } catch (error) { /* empty */ } + if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]); }; + // 将上述定义的getOwnPropertyDescriptor方法封装到objectGetOwnPropertyDescriptor对象中 var objectGetOwnPropertyDescriptor = { f: f$1 }; + // 确保传入的参数是对象,如果不是则抛出TypeError异常并提示相应信息,否则返回该对象 var anObject = function (it) { - if (!isObject(it)) { - throw TypeError(String(it) + ' is not an object'); - } return it; + if (!isObject(it)) { + throw TypeError(String(it) +'is not an object'); + } + return it; }; + // 获取原生的Object.defineProperty方法(用于定义对象的属性) var nativeDefineProperty = Object.defineProperty; - // `Object.defineProperty` method - // https://tc39.github.io/ecma262/#sec-object.defineproperty - var f$2 = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) { - anObject(O); - P = toPrimitive(P, true); - anObject(Attributes); - if (ie8DomDefine) try { - return nativeDefineProperty(O, P, Attributes); - } catch (error) { /* empty */ } - if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported'); - if ('value' in Attributes) O[P] = Attributes.value; - return O; + // 根据是否支持descriptors以及当前环境情况来定义Object.defineProperty方法的实现 + // 如果支持descriptors则直接使用原生方法;如果不支持,则先确保传入的对象和属性名以及属性描述符对象都是合法的 + // 在ie8DomDefine的情况下尝试使用原生方法定义属性,如果抛错则忽略(可能是不支持的情况) + // 如果属性描述符中有get或set访问器属性则抛出TypeError异常(表示不支持访问器属性的定义) + // 如果有value属性则直接将该值赋给对象的对应属性 + var f$2 = descriptors? nativeDefineProperty : function defineProperty(O, P, Attributes) { + anObject(O); + P = toPrimitive(P, true); + anObject(Attributes); + if (ie8DomDefine) try { + return nativeDefineProperty(O, P, Attributes); + } catch (error) { /* empty */ } + if ('get' in Attributes || 'get' in Attributes) throw TypeError('Accessors not supported'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; }; + // 将上述定义的defineProperty方法封装到objectDefineProperty对象中 var objectDefineProperty = { f: f$2 }; - var createNonEnumerableProperty = descriptors ? function (object, key, value) { - return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value)); + // 根据是否支持descriptors来创建一个不可枚举的属性(如果支持则使用Object.defineProperty创建,否则直接给对象添加属性) + var createNonEnumerableProperty = descriptors? function (object, key, value) { + return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value)); } : function (object, key, value) { - object[key] = value; - return object; + object[key] = value; + return object; }; + // 尝试在全局对象上创建一个不可枚举的属性(如果失败则直接给全局对象添加该属性),最后返回该属性的值 var setGlobal = function (key, value) { - try { - createNonEnumerableProperty(global_1, key, value); - } catch (error) { - global_1[key] = value; - } return value; + try { + createNonEnumerableProperty(global_1, key, value); + } catch (error) { + global_1[key] = value; + } + return value; }; + // 定义一个用于共享数据的全局对象的属性名,获取全局对象上该属性对应的共享存储对象(如果不存在则创建并赋值) var SHARED = '__core-js_shared__'; var store = global_1[SHARED] || setGlobal(SHARED, {}); + // 将共享存储对象赋值给sharedStore,方便后续使用 var sharedStore = store; + // 获取函数的字符串表示形式(通过调用Function.toString方法) var functionToString = Function.toString; - // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper - if (typeof sharedStore.inspectSource != 'function') { - sharedStore.inspectSource = function (it) { - return functionToString.call(it); - }; + // 如果共享存储对象没有inspectSource方法,则给它添加一个用于获取函数字符串表示形式的方法 + if (typeof sharedStore.inspectSource!= 'function') { + sharedStore.inspectSource = function (it) { + return functionToString.call(it); + }; } + // 获取共享存储对象的inspectSource方法(用于获取函数的字符串表示形式) var inspectSource = sharedStore.inspectSource; + // 获取全局的WeakMap对象(如果存在的话),用于检测是否原生支持WeakMap var WeakMap = global_1.WeakMap; - var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap)); + // 创建一个共享模块,用于管理一些共享的数据(比如版本信息等) + // 这里定义了一个名为'versions'的共享数据,初始值为一个空数组,并往其中添加了一个版本相关的对象信息 var shared = createCommonjsModule(function (module) { - (module.exports = function (key, value) { - return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {}); - })('versions', []).push({ - version: '3.6.0', - mode: 'global', - copyright: '© 2019 Denis Pushkarev (zloirock.ru)' - }); + (module.exports = function (key, value) { + return sharedStore[key] || (sharedStore[key] = value!== undefined? value : {}); + })('versions', []).push({ + version: '3.6.0', + mode: 'global', + copyright: '© 2019 Denis Pushkarev (zloirock.ru)' + }); }); - + // 初始化一个标识符变量,初始值为0,用于生成唯一标识时进行自增计数 var id = 0; +// 生成一个随机数后缀,用于和自增的id组合来让生成的唯一标识更具随机性 var postfix = Math.random(); +// 定义一个函数uid,用于生成唯一标识(类似Symbol的作用,但可能是自定义的一种实现方式) +// 它接受一个可选的键名参数key,如果key未定义则使用空字符串 +// 通过将传入的键名、自增的id以及随机后缀组合并转换为36进制字符串来生成唯一标识 var uid = function (key) { - return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36); + return 'Symbol(' + String(key === undefined? '' : key) + ')_' + (++id + postfix).toString(36); }; +// 获取共享的keys对象(这个共享机制可能在代码其他地方有定义,用于存储一些共享的数据结构) +// 通过调用shared函数(具体功能在前面代码中应该有定义,可能是根据传入的键获取对应共享值的函数)传入'keys'来获取 var keys = shared('keys'); +// 定义一个函数sharedKey,用于获取或创建一个共享的键 +// 它会先尝试从keys对象中获取传入的键key对应的键值,如果不存在则调用uid函数生成一个新的唯一键并存储到keys对象中,然后返回这个键值 var sharedKey = function (key) { - return keys[key] || (keys[key] = uid(key)); + return keys[key] || (keys[key] = uid(key)); }; +// 创建一个空对象hiddenKeys,用于存储一些不想被外部轻易访问或枚举到的键名(后续可能会往里面添加内容) var hiddenKeys = {}; +// 获取全局的WeakMap对象(WeakMap是一种弱引用的映射数据结构,用于存储键值对,键是弱引用的,便于垃圾回收) var WeakMap$1 = global_1.WeakMap; +// 定义三个变量set、get、has$1,用于后续根据是否原生支持WeakMap来赋予不同的操作函数 var set, get, has$1; +// 定义一个函数enforce,用于获取对象的相关状态信息(通过has$1判断是否存在相关状态,如果存在则通过get获取,不存在则通过set初始化一个空状态并返回) var enforce = function (it) { - return has$1(it) ? get(it) : set(it, {}); + return has$1(it)? get(it) : set(it, {}); }; +// 定义一个函数getterFor,它返回一个新的函数 +// 这个新函数用于获取传入对象it的内部状态,首先判断传入的对象是否是合法对象以及其内部状态的类型是否符合期望的TYPE类型 +// 如果不符合则抛出TypeError异常提示类型不兼容,符合则返回对象的内部状态信息 var getterFor = function (TYPE) { - return function (it) { - var state; - if (!isObject(it) || (state = get(it)).type !== TYPE) { - throw TypeError('Incompatible receiver, ' + TYPE + ' required'); - } return state; - }; + return function (it) { + var state; + if (!isObject(it) || (state = get(it)).type!== TYPE) { + throw TypeError('Incompatible receiver, ' + TYPE + 'required'); + } + return state; + }; }; +// 根据是否原生支持WeakMap来分别定义set、get、has$1这三个操作函数的具体实现逻辑 if (nativeWeakMap) { - var store$1 = new WeakMap$1(); - var wmget = store$1.get; - var wmhas = store$1.has; - var wmset = store$1.set; - set = function (it, metadata) { - wmset.call(store$1, it, metadata); - return metadata; - }; - get = function (it) { - return wmget.call(store$1, it) || {}; - }; - has$1 = function (it) { - return wmhas.call(store$1, it); - }; + // 如果原生支持WeakMap,则创建一个WeakMap实例store$1 + var store$1 = new WeakMap$1(); + // 获取WeakMap实例的get方法,用于从WeakMap中获取对应键的值 + var wmget = store$1.get; + // 获取WeakMap实例的has方法,用于判断WeakMap中是否存在指定的键 + var wmhas = store$1.has; + // 获取WeakMap实例的set方法,用于向WeakMap中设置键值对 + var wmset = store$1.set; + + // 定义set函数,用于向WeakMap中设置键值对(通过调用WeakMap实例的set方法来实现,并返回设置的元数据metadata) + set = function (it, metadata) { + wmset.call(store$1, it, metadata); + return metadata; + }; + + // 定义get函数,用于从WeakMap中获取对应键的值(通过调用WeakMap实例的get方法获取,如果不存在则返回一个空对象) + get = function (it) { + return wmget.call(store$1, it) || {}; + }; + + // 定义has$1函数,用于判断WeakMap中是否存在指定的键(通过调用WeakMap实例的has方法来判断) + has$1 = function (it) { + return wmhas.call(store$1, it); + }; } else { - var STATE = sharedKey('state'); - hiddenKeys[STATE] = true; - set = function (it, metadata) { - createNonEnumerableProperty(it, STATE, metadata); - return metadata; - }; - get = function (it) { - return has(it, STATE) ? it[STATE] : {}; - }; - has$1 = function (it) { - return has(it, STATE); - }; + // 如果不原生支持WeakMap,则通过自定义的方式来模拟相关功能 + + // 通过sharedKey函数获取一个名为'state'的共享键,并将其标记到hiddenKeys对象中,表示这是一个隐藏的键 + var STATE = sharedKey('state'); + hiddenKeys[STATE] = true; + + // 定义set函数,用于给对象设置一个不可枚举的属性(通过调用createNonEnumerableProperty函数来实现,属性名为STATE,值为传入的metadata) + // 最后返回设置的元数据metadata + set = function (it, metadata) { + createNonEnumerableProperty(it, STATE, metadata); + return metadata; + }; + + // 定义get函数,用于获取对象的内部状态(通过判断对象是否有STATE属性来获取其对应的值,如果不存在则返回一个空对象) + get = function (it) { + return has(it, STATE)? it[STATE] : {}; + }; + + // 定义has$1函数,用于判断对象是否有STATE属性(即是否存在对应的内部状态) + has$1 = function (it) { + return has(it, STATE); + }; } +// 创建一个名为internalState的对象,将上述定义的set、get、has、enforce、getterFor函数作为其属性 +// 方便后续统一管理和使用这些与对象内部状态操作相关的函数 var internalState = { - set: set, - get: get, - has: has$1, - enforce: enforce, - getterFor: getterFor + set: set, + get: get, + has: has$1, + enforce: enforce, + getterFor: getterFor }; +// 定义一个名为redefine的CommonJS模块(通过createCommonjsModule函数来创建模块结构) var redefine = createCommonjsModule(function (module) { - var getInternalState = internalState.get; - var enforceInternalState = internalState.enforce; - var TEMPLATE = String(String).split('String'); - - (module.exports = function (O, key, value, options) { - var unsafe = options ? !!options.unsafe : false; - var simple = options ? !!options.enumerable : false; - var noTargetGet = options ? !!options.noTargetGet : false; - if (typeof value == 'function') { - if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key); - enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : ''); - } - if (O === global_1) { - if (simple) O[key] = value; - else setGlobal(key, value); - return; - } else if (!unsafe) { - delete O[key]; - } else if (!noTargetGet && O[key]) { - simple = true; - } - if (simple) O[key] = value; - else createNonEnumerableProperty(O, key, value); - // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative - })(Function.prototype, 'toString', function toString() { - return typeof this == 'function' && getInternalState(this).source || inspectSource(this); - }); + // 获取internalState对象中的get函数,用于获取对象内部状态 + var getInternalState = internalState.get; + // 获取internalState对象中的enforce函数,用于获取或初始化对象内部状态 + var enforceInternalState = internalState.enforce; + // 通过将字符串'String'进行分割得到一个包含空字符串的数组(这里的用法比较奇怪,可能后续用于拼接字符串等特殊操作) + var TEMPLATE = String(String).split('String'); + + // 定义模块的导出内容,是一个函数,接受对象O、键名key、值value以及一个可选的配置对象options作为参数 + (module.exports = function (O, key, value, options) { + // 如果传入了options对象,则获取其中的unsafe属性,否则默认为false + var unsafe = options?!!options.unsafe : false; + // 如果传入了options对象,则获取其中的enumerable属性,否则默认为false + // 这个属性可能用于控制设置的属性是否可枚举 + var simple = options?!!options.enumerable : false; + // 如果传入了options对象,则获取其中的noTargetGet属性,否则默认为false + var noTargetGet = options?!!options.noTargetGet : false; + + // 如果传入的值value是一个函数 + if (typeof value == 'function') { + // 如果键名key是字符串类型且传入的函数没有name属性(函数的name属性通常用于表示函数的名称) + // 则通过调用createNonEnumerableProperty函数给函数设置一个不可枚举的name属性,值为键名key + if (typeof key == 'string' &&!has(value, 'name')) createNonEnumerableProperty(value, 'name', key); + // 通过调用enforceInternalState函数获取函数的内部状态,并设置其source属性为根据键名key拼接的字符串(通过TEMPLATE数组进行拼接) + enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string'? key : ''); + } + + // 如果对象O是全局对象(global_1可能是前面代码中定义的全局对象的引用) + if (O === global_1) { + // 如果simple为true,则直接将值value赋给全局对象的键名key对应的属性(相当于设置一个可枚举的属性) + if (simple) O[key] = value; + // 如果simple为false,则通过调用setGlobal函数(前面应该有定义,可能用于设置全局的不可枚举属性)来设置属性 + else setGlobal(key, value); + return; + } else if (!unsafe) { + // 如果不是全局对象且unsafe为false,则删除对象O中键名key对应的属性 + delete O[key]; + } else if (!noTargetGet && O[key]) { + // 如果unsafe为true且对象O中已经存在键名key对应的属性,则将simple设置为true(可能后续会按照可枚举属性的方式进行处理) + simple = true; + } + + // 如果simple为true,则直接将值value赋给对象O的键名key对应的属性(设置为可枚举属性) + if (simple) O[key] = value; + // 如果simple为false,则通过调用createNonEnumerableProperty函数给对象O设置一个不可枚举的属性,键名是key,值是value + else createNonEnumerableProperty(O, key, value); + + // 以下是一个注释,提到添加一个伪造的Function#toString方法,用于在处理包装方法、构造函数以及类似LoDash的isNative方法等情况时能正确工作 + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + })(Function.prototype, 'toString', function toString() { + // 重定义Function.prototype.toString方法的逻辑 + // 如果当前对象this是一个函数,则通过调用getInternalState函数获取其内部状态,并返回内部状态的source属性值(如果存在) + // 如果不存在内部状态的source属性值,则调用inspectSource函数(前面应该有定义,可能用于获取函数的原始字符串表示形式)来返回函数的字符串表示形式 + return typeof this == 'function' && getInternalState(this).source || inspectSource(this); + }); }); - +// 将前面定义的全局对象(global_1)赋值给path变量,后续可能基于这个变量去获取一些全局作用域下的内容 var path = global_1; +// 定义一个函数aFunction,用于判断传入的变量是否为函数类型 +// 如果是函数类型,则返回该变量本身,否则返回undefined var aFunction = function (variable) { - return typeof variable == 'function' ? variable : undefined; + return typeof variable == 'function'? variable : undefined; }; +// 定义一个函数getBuiltIn,用于获取指定命名空间下的内置函数或方法 +// 如果传入的参数个数小于2(即只传入了命名空间,没有指定具体方法名),则尝试从path对象和global_1对象中获取该命名空间对应的函数并返回(优先从path中获取,如果不存在则从global_1中获取) +// 如果传入了两个参数(命名空间和具体方法名),则尝试从path对象和global_1对象中获取对应命名空间下的指定方法并返回(同样优先从path中获取,如果不存在则从global_1中获取) var getBuiltIn = function (namespace, method) { - return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global_1[namespace]) - : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method]; + return arguments.length < 2? aFunction(path[namespace]) || aFunction(global_1[namespace]) + : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method]; }; +// 获取JavaScript内置的向上取整函数Math.ceil,并赋值给ceil变量,方便后续使用 var ceil = Math.ceil; +// 获取JavaScript内置的向下取整函数Math.floor,并赋值给floor变量,方便后续使用 var floor = Math.floor; - // `ToInteger` abstract operation - // https://tc39.github.io/ecma262/#sec-tointeger +// 实现 `ToInteger` 抽象操作(按照ECMAScript规范中的定义来将传入的参数转换为整数) +// 首先尝试将参数转换为数值(通过前置 + 操作符),如果转换后是NaN,则返回0 +// 如果转换后的数值大于0,则使用floor函数向下取整;如果小于等于0,则使用ceil函数向上取整 var toInteger = function (argument) { - return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument); + return isNaN(argument = +argument)? 0 : (argument > 0? floor : ceil)(argument); }; +// 获取JavaScript内置的取最小值函数Math.min,并赋值给min变量,方便后续使用 var min = Math.min; - // `ToLength` abstract operation - // https://tc39.github.io/ecma262/#sec-tolength +// 实现 `ToLength` 抽象操作(按照ECMAScript规范中的定义将传入的参数转换为合适的长度值) +// 如果传入的参数大于0,则先将其转换为整数(通过调用toInteger函数),然后取该整数与0x1FFFFFFFFFFFFF(2 ** 53 - 1,JavaScript中能安全表示的最大正整数长度值)中的较小值作为结果返回 +// 如果传入的参数小于等于0,则直接返回0 var toLength = function (argument) { - return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 + return argument > 0? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; }; +// 获取JavaScript内置的取最大值函数Math.max,并赋值给max变量,方便后续使用 var max = Math.max; +// 获取JavaScript内置的取最小值函数Math.min,并赋值给min$1变量(这里min和min$1可能是为了区分不同使用场景下的取最小值操作,虽然功能一样但避免变量名冲突) var min$1 = Math.min; - // Helper for a popular repeating case of the spec: - // Let integer be ? ToInteger(index). - // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). +// 定义一个辅助函数toAbsoluteIndex,用于根据给定的索引值和数组长度来计算一个合法的绝对索引值 +// 首先将传入的索引值index转换为整数(通过调用toInteger函数) +// 如果转换后的整数小于0,则计算 (length + integer) 和 0 中的较大值作为结果返回(相当于处理负数索引,将其转换为从数组末尾往前数的对应正数索引) +// 如果转换后的整数大于等于0,则取该整数和数组长度length中的较小值作为结果返回(确保索引不会超出数组范围) var toAbsoluteIndex = function (index, length) { - var integer = toInteger(index); - return integer < 0 ? max(integer + length, 0) : min$1(integer, length); + var integer = toInteger(index); + return integer < 0? max(integer + length, 0) : min$1(integer, length); }; - // `Array.prototype.{ indexOf, includes }` methods implementation +// 定义一个函数createMethod,用于创建 `Array.prototype.indexOf` 或 `Array.prototype.includes` 方法的自定义实现逻辑 +// 它接受一个布尔值参数IS_INCLUDES,用于区分是创建 `includes` 方法还是 `indexOf` 方法的逻辑 var createMethod = function (IS_INCLUDES) { - return function ($this, el, fromIndex) { - var O = toIndexedObject($this); - var length = toLength(O.length); - var index = toAbsoluteIndex(fromIndex, length); - var value; - // Array#includes uses SameValueZero equality algorithm - // eslint-disable-next-line no-self-compare - if (IS_INCLUDES && el != el) while (length > index) { - value = O[index++]; - // eslint-disable-next-line no-self-compare - if (value != value) return true; - // Array#indexOf ignores holes, Array#includes - not - } else for (;length > index; index++) { - if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; - } return !IS_INCLUDES && -1; - }; + return function ($this, el, fromIndex) { + // 将传入的数组对象$this转换为索引对象(可能是为了统一处理不同类型的类似数组对象,保证可以正确遍历属性等,调用了前面定义的toIndexedObject函数) + var O = toIndexedObject($this); + // 获取转换后对象的长度,并通过调用toLength函数确保长度值是合法的长度表示(按照规范进行处理) + var length = toLength(O.length); + // 根据传入的起始索引fromIndex和数组长度计算出实际要开始查找的索引位置(调用toAbsoluteIndex函数进行计算) + var index = toAbsoluteIndex(fromIndex, length); + var value; + + // 如果是创建 `Array.prototype.includes` 方法的逻辑(IS_INCLUDES为true),并且查找元素el与自身不相等(这里用于处理特殊的NaN情况,在SameValueZero相等算法下,NaN不等于自身) + // 则通过循环遍历数组(从计算出的索引位置开始,直到数组末尾) + if (IS_INCLUDES && el!= el) while (length > index) { + value = O[index++]; + // 如果当前遍历到的元素也不等于自身(同样是处理NaN情况),则表示找到了符合条件的元素(因为按照SameValueZero算法,NaN与NaN相等),返回true + if (value!= value) return true; + } + // 如果是创建 `Array.prototype.indexOf` 方法的逻辑(IS_INCLUDES为false)或者是 `Array.prototype.includes` 方法且当前元素不是NaN情况 + else for (; length > index; index++) { + // 判断当前索引位置是否在对象中存在(对于 `indexOf` 方法会忽略数组中的空洞情况,而 `includes` 方法会严格按照索引顺序判断;这里通过 IS_INCLUDES || index in O 来体现这种差异) + // 并且当前位置的元素与要查找的元素el严格相等(使用 === 进行比较) + // 如果满足条件,则根据是 `includes` 方法还是 `indexOf` 方法返回相应的值( `includes` 方法返回true或者当前索引值(如果索引不为0), `indexOf` 方法返回当前索引值) + if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; + } + + // 如果遍历完整个数组都没有找到符合条件的元素,则根据是 `includes` 方法还是 `indexOf` 方法返回相应的值( `includes` 方法返回false, `indexOf` 方法返回 -1) + return!IS_INCLUDES && -1; + }; }; +// 创建一个名为arrayIncludes的对象,将自定义实现的 `Array.prototype.includes` 和 `Array.prototype.indexOf` 方法挂载到该对象上 +// 通过调用createMethod函数并传入不同的参数来分别创建这两个方法的实现逻辑 var arrayIncludes = { - // `Array.prototype.includes` method - // https://tc39.github.io/ecma262/#sec-array.prototype.includes - includes: createMethod(true), - // `Array.prototype.indexOf` method - // https://tc39.github.io/ecma262/#sec-array.prototype.indexof - indexOf: createMethod(false) + // `Array.prototype.includes` 方法的自定义实现,调用createMethod函数并传入true来创建符合 `includes` 方法逻辑的函数 + includes: createMethod(true), + // `Array.prototype.indexOf` 方法的自定义实现,调用createMethod函数并传入false来创建符合 `indexOf` 方法逻辑的函数 + indexOf: createMethod(false) }; - +// 获取之前在 `arrayIncludes` 对象中自定义实现的 `indexOf` 方法,并赋值给 `indexOf` 变量,方便后续直接使用该方法进行元素查找等操作 var indexOf = arrayIncludes.indexOf; - +// 定义一个函数 `objectKeysInternal`,用于获取对象的键名列表,它接收一个对象 `object` 和一个可选的键名数组 `names` 参数 var objectKeysInternal = function (object, names) { - var O = toIndexedObject(object); - var i = 0; - var result = []; - var key; - for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key); - // Don't enum bug & hidden keys - while (names.length > i) if (has(O, key = names[i++])) { - ~indexOf(result, key) || result.push(key); - } - return result; + // 首先将传入的 `object` 转换为索引对象(调用 `toIndexedObject` 函数进行转换,确保可以正确遍历其属性,前面代码应该有对该函数的定义) + var O = toIndexedObject(object); + var i = 0; + var result = []; + var key; + + // 遍历对象 `O` 的可枚举属性(通过 `for...in` 循环),同时进行一些条件判断 + // 检查当前属性键 `key` 不在 `hiddenKeys` 集合中(`hiddenKeys` 可能用于标记一些不想被枚举或特殊处理的键,前面代码有定义)并且对象 `O` 自身确实拥有该属性(通过 `has` 函数判断,前面也有定义) + // 如果满足条件,则将该属性键 `key` 添加到 `result` 数组中 + for (key in O)!has(hiddenKeys, key) && has(O, key) && result.push(key); + + // 处理可能存在的 “Don't enum bug”(不可枚举属性的相关问题,可能是在某些旧浏览器等环境下存在的问题)以及隐藏键的情况 + // 遍历传入的 `names` 数组(如果有的话),从索引 `i` 开始(初始为0) + while (names.length > i) if (has(O, key = names[i++])) { + // 使用位非运算符 `~` 结合 `indexOf` 方法来判断 `key` 是否已经在 `result` 数组中(位非运算符用于将 `indexOf` 返回的 -1 转换为 0,其他值转换为非 0,方便进行逻辑判断) + // 如果 `key` 不在 `result` 数组中(`~indexOf(result, key)` 为真),则将其添加到 `result` 数组中 + ~indexOf(result, key) || result.push(key); + } + + // 最后返回包含对象 `O` 符合条件的键名的数组 `result` + return result; }; - // IE8- don't enum bug keys +// 定义一个数组 `enumBugKeys`,包含了在 IE8 及以下版本浏览器中存在的与对象属性枚举相关的一些“问题键” +// 这些键在某些情况下可能不会按照预期被枚举,比如 `constructor`、`hasOwnProperty` 等方法属性 var enumBugKeys = [ - 'constructor', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'toLocaleString', - 'toString', - 'valueOf' + 'constructor', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'valueOf' ]; +// 创建一个新的数组 `hiddenKeys$1`,将 `enumBugKeys` 数组中的键名与 `length` 和 `prototype` 两个键名合并在一起 +// 这个数组可能用于后续标记更多不想被轻易枚举或者需要特殊处理的键名情况 var hiddenKeys$1 = enumBugKeys.concat('length', 'prototype'); - // `Object.getOwnPropertyNames` method - // https://tc39.github.io/ecma262/#sec-object.getownpropertynames +// 定义一个变量 `f$3`,用于获取对象的自有属性名列表 +// 首先尝试获取原生的 `Object.getOwnPropertyNames` 方法,如果不存在(可能在某些不支持的环境中),则使用自定义的 `objectKeysInternal` 函数来获取 +// 传入当前要获取属性名的对象 `O` 和前面定义的 `hiddenKeys$1` 数组作为参数,以此来获取对象的属性名(包含了处理特殊键名情况的逻辑) var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { - return objectKeysInternal(O, hiddenKeys$1); + return objectKeysInternal(O, hiddenKeys$1); }; +// 创建一个名为 `objectGetOwnPropertyNames` 的对象,将 `f$3` 函数作为其 `f` 属性挂载上去 +// 这样可以通过 `objectGetOwnPropertyNames.f` 的方式方便地调用获取对象自有属性名的函数逻辑 var objectGetOwnPropertyNames = { f: f$3 }; +// 获取原生的 `Object.getOwnPropertySymbols` 方法(用于获取对象的符号属性,在 ES6 中引入了符号类型作为属性名的一种特殊情况),并赋值给 `f$4` 变量 var f$4 = Object.getOwnPropertySymbols; +// 创建一个名为 `objectGetOwnPropertySymbols` 的对象,将 `f$4` 函数作为其 `f` 属性挂载上去 +// 方便后续通过 `objectGetOwnPropertySymbols.f` 的方式调用获取对象符号属性的函数逻辑 var objectGetOwnPropertySymbols = { f: f$4 }; - // all object keys, includes non-enumerable and symbols +// 定义一个函数 `ownKeys`,用于获取对象的所有键(包括自有属性键、非自有属性键、符号属性键等所有情况) +// 首先尝试获取原生的 `Reflect.ownKeys` 方法(`Reflect` 是 ES6 中新增的一个内置对象,提供了一些操作对象的反射方法),如果不存在则使用自定义的逻辑来获取 +// 自定义逻辑是先通过调用 `objectGetOwnPropertyNames.f` 函数(前面定义的获取对象自有属性名的方式)获取对象的自有属性名列表 `keys` +// 然后获取 `objectGetOwnPropertySymbols.f` 函数(用于获取符号属性的函数,如果存在的话) +// 如果能获取到获取符号属性的函数(即 `getOwnPropertySymbols` 不为 `null`),则将符号属性列表与自有属性名列表合并起来作为最终结果返回;否则直接返回自有属性名列表 `keys` var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) { - var keys = objectGetOwnPropertyNames.f(anObject(it)); - var getOwnPropertySymbols = objectGetOwnPropertySymbols.f; - return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys; + var keys = objectGetOwnPropertyNames.f(anObject(it)); + var getOwnPropertySymbols = objectGetOwnPropertySymbols.f; + return getOwnPropertySymbols? keys.concat(getOwnPropertySymbols(it)) : keys; }; +// 定义一个函数 `copyConstructorProperties`,用于将一个对象(`source`)的属性复制到另一个对象(`target`)上 +// 首先获取 `source` 对象的所有键(通过调用 `ownKeys` 函数),然后获取用于定义对象属性的 `defineProperty` 函数(通过 `objectDefineProperty.f`,前面代码应该有相关定义) +// 以及获取对象属性描述符的 `getOwnPropertyDescriptor` 函数(通过 `objectGetOwnPropertyDescriptor.f`,前面也有定义) +// 接着遍历 `source` 对象的所有键,对于 `target` 对象中不存在的键(通过 `has` 函数判断),则将 `source` 对象对应键的属性描述符复制到 `target` 对象上(通过调用 `defineProperty` 函数) var copyConstructorProperties = function (target, source) { - var keys = ownKeys(source); - var defineProperty = objectDefineProperty.f; - var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f; - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key)); - } + var keys = ownKeys(source); + var defineProperty = objectDefineProperty.f; + var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key)); + } }; +// 定义一个正则表达式 `replacement`,用于匹配字符串中的 `#` 字符或者 `.prototype.` 字符串片段 +// 可能后续用于对某些字符串进行规范化处理,替换相关内容 var replacement = /#|\.prototype\./; +// 定义一个函数 `isForced`,用于判断某个功能特性(`feature`)是否需要强制使用 polyfill(垫片代码) +// 首先从 `data` 对象中根据规范化后的功能特性名称(通过 `normalize` 函数处理后的名称,后面有定义)获取对应的值 `value` +// 然后根据 `value` 的值进行判断,如果是 `POLYFILL`(前面应该有定义,表示需要使用 polyfill)则返回 `true` +// 如果是 `NATIVE`(表示原生支持,不需要 polyfill)则返回 `false` +// 如果传入的 `detection` 参数是一个函数,则通过调用 `fails` 函数(前面代码有定义,用于检测函数执行是否失败)来判断是否需要 polyfill(可能根据函数执行情况来决定) +// 如果 `detection` 不是函数,则直接将其转换为布尔值作为判断结果(可能是直接传入一个布尔值来表示是否强制使用 polyfill 的情况) var isForced = function (feature, detection) { - var value = data[normalize(feature)]; - return value == POLYFILL ? true - : value == NATIVE ? false - : typeof detection == 'function' ? fails(detection) - : !!detection; + var value = data[normalize(feature)]; + return value == POLYFILL? true + : value == NATIVE? false + : typeof detection == 'function'? fails(detection) + :!!detection; }; +// 定义 `normalize` 函数,它是 `isForced` 函数的一个属性(通过这种方式将规范化功能与 `isForced` 关联起来) +// 用于将传入的字符串 `string` 进行规范化处理,将其中的 `#` 字符或者 `.prototype.` 字符串片段替换为 `.`,然后转换为小写形式并返回 var normalize = isForced.normalize = function (string) { - return String(string).replace(replacement, '.').toLowerCase(); + return String(string).replace(replacement, '.').toLowerCase(); }; +// 创建一个空对象 `data`,用于存储功能特性相关的数据(可能存储每个功能特性是否需要 polyfill 等信息),并将其挂载到 `isForced` 函数上作为 `data` 属性 var data = isForced.data = {}; +// 定义一个常量 `NATIVE`,值为 `'N'`,用于在 `data` 对象中标记某个功能特性是原生支持的情况,同样挂载到 `isForced` 函数上方便统一使用 var NATIVE = isForced.NATIVE = 'N'; +// 定义一个常量 `POLYFILL`,值为 `'P'`,用于在 `data` 对象中标记某个功能特性需要使用 polyfill 的情况,也挂载到 `isForced` 函数上便于使用 var POLYFILL = isForced.POLYFILL = 'P'; +// 将 `isForced` 函数赋值给 `isForced_1` 变量,可能是为了方便后续在其他地方使用这个判断功能时使用不同的变量名进行引用,避免命名冲突等情况 var isForced_1 = isForced; +// 获取 `objectGetOwnPropertyDescriptor.f` 函数(前面定义的用于获取对象属性描述符的函数),并赋值给 `getOwnPropertyDescriptor$1` 变量,方便后续直接使用该函数获取属性描述符 var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; - - - - /* options.target - name of the target object options.global - target is the global object @@ -493,939 +665,1062 @@ options.enumerable - export as enumerable property options.noTargetGet - prevent calling a getter on target */ + // 定义一个名为 `_export` 的函数,用于将一个对象(`source`)的属性按照一定规则导出到另一个目标对象(`target`)上,接受 `options` 和 `source` 两个参数 var _export = function (options, source) { - var TARGET = options.target; - var GLOBAL = options.global; - var STATIC = options.stat; - var FORCED, target, key, targetProperty, sourceProperty, descriptor; - if (GLOBAL) { - target = global_1; - } else if (STATIC) { - target = global_1[TARGET] || setGlobal(TARGET, {}); - } else { - target = (global_1[TARGET] || {}).prototype; - } - if (target) for (key in source) { - sourceProperty = source[key]; - if (options.noTargetGet) { - descriptor = getOwnPropertyDescriptor$1(target, key); - targetProperty = descriptor && descriptor.value; - } else targetProperty = target[key]; - FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); - // contained in target - if (!FORCED && targetProperty !== undefined) { - if (typeof sourceProperty === typeof targetProperty) continue; - copyConstructorProperties(sourceProperty, targetProperty); - } - // add a flag to not completely full polyfills - if (options.sham || (targetProperty && targetProperty.sham)) { - createNonEnumerableProperty(sourceProperty, 'sham', true); - } - // extend global - redefine(target, key, sourceProperty, options); - } + // 从 `options` 对象中获取 `target` 属性值,并赋值给 `TARGET` 变量,可能用于指定目标对象的相关标识或名称 + var TARGET = options.target; + // 从 `options` 对象中获取 `global` 属性值,并赋值给 `GLOBAL` 变量,可能用于判断是否将属性导出到全局对象上 + var GLOBAL = options.global; + // 从 `options` 对象中获取 `stat` 属性值,并赋值给 `STATIC` 变量,其作用可能与是否是静态属性等相关(结合后续代码判断) + var STATIC = options.stat; + // 定义几个变量,`FORCED` 可能用于标记某个属性是否被强制处理,`target` 用于存储最终的目标对象,`key` 用于遍历属性时的键名,`targetProperty` 和 `sourceProperty` 分别用于存储目标对象和源对象的属性值,`descriptor` 用于存储属性描述符 + var FORCED, target, key, targetProperty, sourceProperty, descriptor; + + // 根据 `GLOBAL` 的值来确定目标对象 `target` + // 如果 `GLOBAL` 为 `true`,则将全局对象(`global_1`,前面代码应该有定义)赋值给 `target`,表示要将属性导出到全局对象上 + if (GLOBAL) { + target = global_1; + } + // 如果 `STATIC` 为 `true`,则尝试从全局对象中获取以 `TARGET` 为名的属性值作为目标对象,如果不存在则通过 `setGlobal` 函数(前面应该有定义,可能用于创建全局属性)创建一个空对象并赋值给 `target` + // 这种情况可能是处理静态属性的导出,将属性添加到全局对象下特定的一个命名空间(以 `TARGET` 标识)中 + else if (STATIC) { + target = global_1[TARGET] || setGlobal(TARGET, {}); + } + // 如果 `GLOBAL` 和 `STATIC` 都不为 `true`,则尝试从全局对象中获取以 `TARGET` 为名的属性对象的原型对象(通过访问 `prototype` 属性)作为目标对象,如果不存在则使用一个空对象作为目标对象的原型 + // 这可能是将属性添加到某个对象的原型链上的情况,用于实现继承等相关功能 + else { + target = (global_1[TARGET] || {}).prototype; + } + + // 如果成功确定了目标对象 `target`,则开始遍历源对象 `source` 的属性 + if (target) for (key in source) { + // 获取源对象 `source` 中当前键 `key` 对应的属性值,并赋值给 `sourceProperty` + sourceProperty = source[key]; + + // 根据 `options` 中的 `noTargetGet` 属性值来决定如何获取目标对象 `target` 中对应键 `key` 的属性值(`targetProperty`) + // 如果 `noTargetGet` 为 `true`,则通过调用 `getOwnPropertyDescriptor$1` 函数(前面代码有定义,用于获取对象属性描述符)获取属性描述符,再从描述符中获取 `value` 属性作为 `targetProperty` + if (options.noTargetGet) { + descriptor = getOwnPropertyDescriptor$1(target, key); + targetProperty = descriptor && descriptor.value; + } + // 如果 `noTargetGet` 不为 `true`,则直接通过键名 `key` 从目标对象 `target` 中获取属性值赋值给 `targetProperty` + else targetProperty = target[key]; + + // 通过调用 `isForced_1` 函数(前面代码有定义,用于判断某个功能特性是否需要强制使用 polyfill 等情况)来判断当前属性是否需要被强制处理 + // 根据 `GLOBAL` 的值来决定传入 `isForced_1` 函数的第一个参数(如果 `GLOBAL` 为 `true`,则传入键名 `key`;否则传入由 `TARGET`、特定分隔符(根据 `STATIC` 判断是 `.` 还是 `#`)以及键名 `key` 组成的字符串) + // 同时传入 `options.forced` 作为第二个参数(其具体作用可能与强制处理的具体条件相关) + FORCED = isForced_1(GLOBAL? key : TARGET + (STATIC? '.' : '#') + key, options.forced); + + // 如果当前属性不需要被强制处理(`FORCED` 为 `false`)并且目标对象 `target` 中已经存在该属性(`targetProperty` 不为 `undefined`) + if (!FORCED && targetProperty!== undefined) { + // 比较源对象和目标对象中对应属性的类型,如果类型相同则跳过当前属性的处理(可能认为不需要重复设置相同类型的属性) + if (typeof sourceProperty === typeof targetProperty) continue; + // 如果类型不同,则调用 `copyConstructorProperties` 函数(前面代码有定义,用于复制属性的相关操作)将源对象属性的相关属性描述符等复制到目标对象属性上 + copyConstructorProperties(sourceProperty, targetProperty); + } + + // 如果 `options` 中有 `sham` 属性并且其值为 `true`,或者目标对象属性(`targetProperty`)存在且其自身有 `sham` 属性并且值为 `true` + // 则通过调用 `createNonEnumerableProperty` 函数(前面代码有定义,用于创建不可枚举属性)给源对象属性添加一个名为 `sham` 的不可枚举属性,值为 `true` + // 这里的 `sham` 可能用于标记某些属性是一种 “伪” 实现或者不完全的填充(polyfill)等特殊情况 + if (options.sham || (targetProperty && targetProperty.sham)) { + createNonEnumerableProperty(sourceProperty, 'sham', true); + } + + // 调用 `redefine` 函数(前面代码有定义,涉及对象属性的重新定义等操作),按照 `options` 中的配置以及当前的键名 `key` 和源对象属性值 `sourceProperty` 来重新定义目标对象 `target` 中的属性 + redefine(target, key, sourceProperty, options); + } }; - var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () { - // Chrome 38 Symbol has incorrect toString conversion - // eslint-disable-next-line no-undef - return !String(Symbol()); +// 判断当前环境是否原生支持 `Symbol`(通过检查是否存在 `Object.getOwnPropertySymbols` 方法并且尝试创建一个 `Symbol` 实例并转换为字符串时不会出错来判断) +// 如果满足条件,则 `nativeSymbol` 为 `true`,表示原生支持 `Symbol`;否则为 `false` + var nativeSymbol =!!Object.getOwnPropertySymbols &&!fails(function () { + // Chrome 38 Symbol has incorrect toString conversion + // eslint-disable-next-line no-undef + return!String(Symbol()); }); +// 根据一些条件判断是否可以使用 `Symbol` 作为唯一标识符(`uid`) +// 首先要求原生支持 `Symbol`(`nativeSymbol` 为 `true`),然后要求 `Symbol` 没有 `sham` 属性(可能表示是完全原生的,不是模拟的情况)并且创建的 `Symbol` 实例确实是 `symbol` 类型(通过 `typeof` 判断) +// 如果满足这些条件,则 `useSymbolAsUid` 为 `true`,表示可以使用 `Symbol` 作为唯一标识符;否则为 `false` var useSymbolAsUid = nativeSymbol - // eslint-disable-next-line no-undef - && !Symbol.sham - // eslint-disable-next-line no-undef - && typeof Symbol() == 'symbol'; - - // `IsArray` abstract operation - // https://tc39.github.io/ecma262/#sec-isarray + // eslint-disable-next-line no-undef + &&!Symbol.sham + // eslint-disable-next-line no-undef + && typeof Symbol() == 'symbol'; + +// 实现 `IsArray` 抽象操作(按照 ECMAScript 规范中的定义来判断传入的参数是否为数组) +// 首先尝试获取原生的 `Array.isArray` 方法,如果存在则直接使用;如果不存在,则通过自定义的逻辑判断(通过调用 `classofRaw` 函数(前面代码有定义,用于获取对象的类名)判断是否为 `'Array'` 类来确定是否为数组) +// 并将判断函数赋值给 `isArray` 变量,方便后续直接使用该函数判断是否为数组 var isArray = Array.isArray || function isArray(arg) { - return classofRaw(arg) == 'Array'; + return classofRaw(arg) == 'Array'; }; - // `ToObject` abstract operation - // https://tc39.github.io/ecma262/#sec-toobject +// 实现 `ToObject` 抽象操作(按照 ECMAScript 规范中的定义将传入的参数转换为对象) +// 通过调用 `Object` 函数并传入经过 `requireObjectCoercible` 函数(前面代码有定义,用于确保参数可以转换为对象并进行必要的错误处理)处理后的参数,将其转换为对象并返回 var toObject = function (argument) { - return Object(requireObjectCoercible(argument)); + return Object(requireObjectCoercible(argument)); }; - // `Object.keys` method - // https://tc39.github.io/ecma262/#sec-object.keys +// 实现 `Object.keys` 方法(用于获取对象自身可枚举的属性名组成的数组) +// 首先尝试获取原生的 `Object.keys` 方法,如果存在则直接使用;如果不存在,则通过调用自定义的 `objectKeysInternal` 函数(前面代码有定义,涉及对象属性名获取并处理一些特殊情况)传入对象 `O` 和 `enumBugKeys` 数组(前面代码有定义,包含一些特殊的键名)来获取对象的属性名数组 +// 并将获取属性名的函数赋值给 `objectKeys` 变量,方便后续直接使用该函数获取对象的属性名 var objectKeys = Object.keys || function keys(O) { - return objectKeysInternal(O, enumBugKeys); + return objectKeysInternal(O, enumBugKeys); }; - // `Object.defineProperties` method - // https://tc39.github.io/ecma262/#sec-object.defineproperties - var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) { - anObject(O); - var keys = objectKeys(Properties); - var length = keys.length; - var index = 0; - var key; - while (length > index) objectDefineProperty.f(O, key = keys[index++], Properties[key]); - return O; +// 实现 `Object.defineProperties` 方法(用于同时定义对象的多个属性) +// 根据是否支持 `descriptors`(前面代码有相关定义,用于判断是否支持某些对象属性描述符相关的原生特性)来选择不同的实现方式 +// 如果支持 `descriptors`,则直接使用原生的 `Object.defineProperties` 方法;如果不支持,则通过自定义逻辑来实现 +// 自定义逻辑是先确保传入的对象 `O` 是合法的对象(通过调用 `anObject` 函数(前面代码有定义)进行判断),然后获取要定义的属性对象 `Properties` 的属性名数组(通过调用 `objectKeys` 函数) +// 接着遍历属性名数组,通过调用 `objectDefineProperty.f` 函数(前面代码有定义,用于定义对象的单个属性)依次将 `Properties` 中对应属性名的属性定义到对象 `O` 上,最后返回定义好属性后的对象 `O` + var objectDefineProperties = descriptors? Object.defineProperties : function defineProperties(O, Properties) { + anObject(O); + var keys = objectKeys(Properties); + var length = keys.length; + var index = 0; + var key; + while (length > index) objectDefineProperty.f(O, key = keys[index++], Properties[key]); + return O; }; +// 获取全局文档对象(`document`)中的文档根元素(`documentElement`),并赋值给 `html` 变量(可能后续会基于这个元素进行一些与 HTML 相关的操作,不过这里只是简单获取一下) var html = getBuiltIn('document', 'documentElement'); +// 定义几个常量,分别表示 HTML 中的大于号(`>`)、小于号(`<`)、原型(`prototype`)、脚本(`script`)以及一个共享的键名(`IE_PROTO`,通过调用 `sharedKey` 函数(前面代码有定义)生成,可能用于特定的与 IE 浏览器相关或者其他需要共享的属性标记等情况) var GT = '>'; var LT = '<'; var PROTOTYPE = 'prototype'; var SCRIPT = 'script'; var IE_PROTO = sharedKey('IE_PROTO'); +// 定义一个空的构造函数 `EmptyConstructor`,函数体为空,可能用于后续继承或者创建对象实例等情况时作为一个基础的构造函数模板(具体用途还需结合更多上下文判断) var EmptyConstructor = function () { /* empty */ }; +// 定义一个函数 `scriptTag`,用于生成一个简单的 HTML 脚本标签内容 +// 它接受一个参数 `content`,表示要放在脚本标签内部的内容(比如 JavaScript 代码等) +// 通过拼接 HTML 标签的开始部分(``)来生成完整的脚本标签内容字符串并返回 var scriptTag = function (content) { - return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT; + return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT; }; + // Create object with fake `null` prototype: use ActiveX Object with cleared prototype + // Function to create an object with a 'null' prototype using ActiveX in IE var NullProtoObjectViaActiveX = function (activeXDocument) { - activeXDocument.write(scriptTag('')); - activeXDocument.close(); - var temp = activeXDocument.parentWindow.Object; - activeXDocument = null; // avoid memory leak - return temp; + activeXDocument.write(scriptTag('')); // Write an empty script to ActiveX document + activeXDocument.close(); // Close the ActiveX document + var temp = activeXDocument.parentWindow.Object; // Get the Object from the parent window (from ActiveX) + activeXDocument = null; // Avoid memory leak + return temp; // Return the fake Object with a null prototype }; - // Create object with fake `null` prototype: use iframe Object with cleared prototype +// Function to create an object with a 'null' prototype using an iframe var NullProtoObjectViaIFrame = function () { - // Thrash, waste and sodomy: IE GC bug - var iframe = documentCreateElement('iframe'); - var JS = 'java' + SCRIPT + ':'; - var iframeDocument; - iframe.style.display = 'none'; - html.appendChild(iframe); - // https://github.com/zloirock/core-js/issues/475 - iframe.src = String(JS); - iframeDocument = iframe.contentWindow.document; - iframeDocument.open(); - iframeDocument.write(scriptTag('document.F=Object')); - iframeDocument.close(); - return iframeDocument.F; + // Thrash and waste method due to IE garbage collector bug + var iframe = documentCreateElement('iframe'); // Create an iframe element + var JS = 'java' + SCRIPT + ':'; // Create a script URL + var iframeDocument; + iframe.style.display = 'none'; // Hide the iframe + html.appendChild(iframe); // Append iframe to the HTML body + iframe.src = String(JS); // Set the source of the iframe to the script URL + iframeDocument = iframe.contentWindow.document; // Get the document inside the iframe + iframeDocument.open(); // Open the document + iframeDocument.write(scriptTag('document.F=Object')); // Write a script inside the iframe that sets `document.F` to Object + iframeDocument.close(); // Close the iframe document + return iframeDocument.F; // Return the Object with a null prototype }; - // Check for document.domain and active x support - // No need to use active x approach when document.domain is not set - // see https://github.com/es-shims/es5-shim/issues/150 - // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346 - // avoid IE GC bug +// Main function to create an object with a 'null' prototype var activeXDocument; var NullProtoObject = function () { - try { - /* global ActiveXObject */ - activeXDocument = document.domain && new ActiveXObject('htmlfile'); - } catch (error) { /* ignore */ } - NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame(); - var length = enumBugKeys.length; - while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]]; - return NullProtoObject(); + try { + /* global ActiveXObject */ + activeXDocument = document.domain && new ActiveXObject('htmlfile'); // Check if ActiveX is available + } catch (error) { /* ignore */ } + // If ActiveX is supported, use the ActiveX approach, otherwise use iframe + NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame(); + var length = enumBugKeys.length; + while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]]; // Delete enumerated bug keys + return NullProtoObject(); // Return the object created }; +// Mark hidden keys to avoid property name collisions in the prototype hiddenKeys[IE_PROTO] = true; - // `Object.create` method - // https://tc39.github.io/ecma262/#sec-object.create +// Polyfill for `Object.create` method var objectCreate = Object.create || function create(O, Properties) { - var result; - if (O !== null) { - EmptyConstructor[PROTOTYPE] = anObject(O); - result = new EmptyConstructor(); - EmptyConstructor[PROTOTYPE] = null; - // add "__proto__" for Object.getPrototypeOf polyfill - result[IE_PROTO] = O; - } else result = NullProtoObject(); - return Properties === undefined ? result : objectDefineProperties(result, Properties); + var result; + if (O !== null) { + EmptyConstructor[PROTOTYPE] = anObject(O); // Set the prototype of an empty constructor to O + result = new EmptyConstructor(); // Create a new instance of the empty constructor + EmptyConstructor[PROTOTYPE] = null; // Reset the prototype to null + result[IE_PROTO] = O; // Add the prototype reference to the created object for `Object.getPrototypeOf` + } else result = NullProtoObject(); // If O is null, use the NullProtoObject method + return Properties === undefined ? result : objectDefineProperties(result, Properties); // If Properties is defined, add them to the result object }; +// Native method to get the own property names of an object var nativeGetOwnPropertyNames = objectGetOwnPropertyNames.f; - var toString$1 = {}.toString; - +// Get the window names (properties) for a given object var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames - ? Object.getOwnPropertyNames(window) : []; + ? Object.getOwnPropertyNames(window) // If `Object.getOwnPropertyNames` is supported, use it + : []; +// Function to get the names of properties on a window object var getWindowNames = function (it) { - try { - return nativeGetOwnPropertyNames(it); - } catch (error) { - return windowNames.slice(); - } + try { + return nativeGetOwnPropertyNames(it); // Try to get the own property names + } catch (error) { + return windowNames.slice(); // If error occurs, return a copy of windowNames + } }; - // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window +// Fallback for buggy `Object.getOwnPropertyNames` in IE11 with iframe and window var f$5 = function getOwnPropertyNames(it) { - return windowNames && toString$1.call(it) == '[object Window]' - ? getWindowNames(it) - : nativeGetOwnPropertyNames(toIndexedObject(it)); + return windowNames && toString$1.call(it) == '[object Window]' + ? getWindowNames(it) // If the object is a window, use the getWindowNames function + : nativeGetOwnPropertyNames(toIndexedObject(it)); // Otherwise, use the native method }; +// Object for external use of `getOwnPropertyNames` method var objectGetOwnPropertyNamesExternal = { f: f$5 }; +// Store for Well-Known Symbols var WellKnownSymbolsStore = shared('wks'); var Symbol$1 = global_1.Symbol; - var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : uid; + var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : uid; // Use Symbol as UID if supported +// Function to get or create a well-known symbol var wellKnownSymbol = function (name) { - if (!has(WellKnownSymbolsStore, name)) { - if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name]; - else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name); - } return WellKnownSymbolsStore[name]; + if (!has(WellKnownSymbolsStore, name)) { // If the symbol doesn't exist in the store + if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name]; // Use the native Symbol if available + else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name); // Otherwise, create a new one + } + return WellKnownSymbolsStore[name]; // Return the symbol from the store }; +// Wrapper for the well-known symbol function var f$6 = wellKnownSymbol; +// Define property for well-known symbols var wrappedWellKnownSymbol = { f: f$6 }; +// Define property method var defineProperty = objectDefineProperty.f; +// Function to define a well-known symbol on the global `Symbol` object var defineWellKnownSymbol = function (NAME) { - var Symbol = path.Symbol || (path.Symbol = {}); - if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, { - value: wrappedWellKnownSymbol.f(NAME) - }); + var Symbol = path.Symbol || (path.Symbol = {}); // Get or create the global Symbol object + if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, { // If the symbol is not defined + value: wrappedWellKnownSymbol.f(NAME) // Create and assign the symbol + }); }; +// Define property for symbols var defineProperty$1 = objectDefineProperty.f; - - +// Define the `toStringTag` symbol for setting the tag on objects var TO_STRING_TAG = wellKnownSymbol('toStringTag'); +// Set the `toStringTag` symbol on an object or prototype var setToStringTag = function (it, TAG, STATIC) { - if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) { - defineProperty$1(it, TO_STRING_TAG, { configurable: true, value: TAG }); - } + if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) { + defineProperty$1(it, TO_STRING_TAG, { configurable: true, value: TAG }); // Define the `toStringTag` property + } }; - +// 确保传入的参数是一个函数,如果不是则抛出 TypeError var aFunction$1 = function (it) { - if (typeof it != 'function') { - throw TypeError(String(it) + ' is not a function'); - } return it; + if (typeof it != 'function') { + throw TypeError(String(it) + ' 不是一个函数'); + } + return it; }; - // optional / simple context binding +// 可选的/简单的上下文绑定函数 var bindContext = function (fn, that, length) { - aFunction$1(fn); - if (that === undefined) return fn; - switch (length) { - case 0: return function () { - return fn.call(that); - }; - case 1: return function (a) { - return fn.call(that, a); - }; - case 2: return function (a, b) { - return fn.call(that, a, b); - }; - case 3: return function (a, b, c) { - return fn.call(that, a, b, c); - }; - } - return function (/* ...args */) { - return fn.apply(that, arguments); - }; + aFunction$1(fn); // 确保 fn 是一个函数 + if (that === undefined) return fn; // 如果没有传入上下文(that),直接返回原函数 + // 根据参数个数,返回一个绑定了上下文的函数 + switch (length) { + case 0: return function () { + return fn.call(that); // 调用时绑定上下文 + }; + case 1: return function (a) { + return fn.call(that, a); + }; + case 2: return function (a, b) { + return fn.call(that, a, b); + }; + case 3: return function (a, b, c) { + return fn.call(that, a, b, c); + }; + } + return function (/* ...args */) { + return fn.apply(that, arguments); // 对剩余的参数使用 apply 进行调用 + }; }; - var SPECIES = wellKnownSymbol('species'); + var SPECIES = wellKnownSymbol('species'); // 使用 wellKnownSymbol 获取 "species" 符号,用于数组的原生构造函数 - // `ArraySpeciesCreate` abstract operation - // https://tc39.github.io/ecma262/#sec-arrayspeciescreate +// `ArraySpeciesCreate` 抽象操作 +// https://tc39.github.io/ecma262/#sec-arrayspeciescreate var arraySpeciesCreate = function (originalArray, length) { - var C; - if (isArray(originalArray)) { - C = originalArray.constructor; - // cross-realm fallback - if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; - else if (isObject(C)) { - C = C[SPECIES]; - if (C === null) C = undefined; - } - } return new (C === undefined ? Array : C)(length === 0 ? 0 : length); + var C; + if (isArray(originalArray)) { + C = originalArray.constructor; // 获取原数组的构造函数 + // 跨域处理 + if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; + else if (isObject(C)) { + C = C[SPECIES]; // 获取 `species` 属性 + if (C === null) C = undefined; + } + } + // 如果 C 为 undefined,使用默认的 Array 构造函数创建新数组 + return new (C === undefined ? Array : C)(length === 0 ? 0 : length); }; - var push = [].push; + var push = [].push; // 简单的数组 push 方法引用 - // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation +// `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` 方法的实现 var createMethod$1 = function (TYPE) { - var IS_MAP = TYPE == 1; - var IS_FILTER = TYPE == 2; - var IS_SOME = TYPE == 3; - var IS_EVERY = TYPE == 4; - var IS_FIND_INDEX = TYPE == 6; - var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; - return function ($this, callbackfn, that, specificCreate) { - var O = toObject($this); - var self = indexedObject(O); - var boundFunction = bindContext(callbackfn, that, 3); - var length = toLength(self.length); - var index = 0; - var create = specificCreate || arraySpeciesCreate; - var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; - var value, result; - for (;length > index; index++) if (NO_HOLES || index in self) { - value = self[index]; - result = boundFunction(value, index, O); - if (TYPE) { - if (IS_MAP) target[index] = result; // map - else if (result) switch (TYPE) { - case 3: return true; // some - case 5: return value; // find - case 6: return index; // findIndex - case 2: push.call(target, value); // filter - } else if (IS_EVERY) return false; // every - } - } - return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target; - }; + // 判断类型,用于区分是 map, filter, some, every 等方法 + var IS_MAP = TYPE == 1; + var IS_FILTER = TYPE == 2; + var IS_SOME = TYPE == 3; + var IS_EVERY = TYPE == 4; + var IS_FIND_INDEX = TYPE == 6; + var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; // 如果是 findIndex 或 filter,排除空洞 + return function ($this, callbackfn, that, specificCreate) { + var O = toObject($this); // 将目标对象转换为对象 + var self = indexedObject(O); // 获取目标对象的索引对象 + var boundFunction = bindContext(callbackfn, that, 3); // 绑定上下文 + var length = toLength(self.length); // 获取数组长度 + var index = 0; + var create = specificCreate || arraySpeciesCreate; // 使用具体的创建函数或默认的 arraySpeciesCreate + var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; + var value, result; + // 遍历数组 + for (;length > index; index++) if (NO_HOLES || index in self) { + value = self[index]; + result = boundFunction(value, index, O); // 执行绑定的回调函数 + if (TYPE) { + if (IS_MAP) target[index] = result; // map 方法 + else if (result) switch (TYPE) { + case 3: return true; // some 方法 + case 5: return value; // find 方法 + case 6: return index; // findIndex 方法 + case 2: push.call(target, value); // filter 方法 + } else if (IS_EVERY) return false; // every 方法 + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target; // 返回结果 + }; }; +// 定义一个包含多种数组操作方法的对象 var arrayIteration = { - // `Array.prototype.forEach` method - // https://tc39.github.io/ecma262/#sec-array.prototype.foreach - forEach: createMethod$1(0), - // `Array.prototype.map` method - // https://tc39.github.io/ecma262/#sec-array.prototype.map - map: createMethod$1(1), - // `Array.prototype.filter` method - // https://tc39.github.io/ecma262/#sec-array.prototype.filter - filter: createMethod$1(2), - // `Array.prototype.some` method - // https://tc39.github.io/ecma262/#sec-array.prototype.some - some: createMethod$1(3), - // `Array.prototype.every` method - // https://tc39.github.io/ecma262/#sec-array.prototype.every - every: createMethod$1(4), - // `Array.prototype.find` method - // https://tc39.github.io/ecma262/#sec-array.prototype.find - find: createMethod$1(5), - // `Array.prototype.findIndex` method - // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex - findIndex: createMethod$1(6) + // `Array.prototype.forEach` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.foreach + forEach: createMethod$1(0), + // `Array.prototype.map` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.map + map: createMethod$1(1), + // `Array.prototype.filter` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.filter + filter: createMethod$1(2), + // `Array.prototype.some` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.some + some: createMethod$1(3), + // `Array.prototype.every` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.every + every: createMethod$1(4), + // `Array.prototype.find` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.find + find: createMethod$1(5), + // `Array.prototype.findIndex` 方法 + // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex + findIndex: createMethod$1(6) }; - +// 引入 `arrayIteration.forEach` 方法,用于数组的遍历操作 var $forEach = arrayIteration.forEach; - var HIDDEN = sharedKey('hidden'); - var SYMBOL = 'Symbol'; - var PROTOTYPE$1 = 'prototype'; - var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); - var setInternalState = internalState.set; - var getInternalState = internalState.getterFor(SYMBOL); - var ObjectPrototype = Object[PROTOTYPE$1]; - var $Symbol = global_1.Symbol; - var $stringify = getBuiltIn('JSON', 'stringify'); - var nativeGetOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; - var nativeDefineProperty$1 = objectDefineProperty.f; - var nativeGetOwnPropertyNames$1 = objectGetOwnPropertyNamesExternal.f; - var nativePropertyIsEnumerable$1 = objectPropertyIsEnumerable.f; - var AllSymbols = shared('symbols'); - var ObjectPrototypeSymbols = shared('op-symbols'); - var StringToSymbolRegistry = shared('string-to-symbol-registry'); - var SymbolToStringRegistry = shared('symbol-to-string-registry'); - var WellKnownSymbolsStore$1 = shared('wks'); - var QObject = global_1.QObject; - // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173 +// 定义一些常量和符号 + var HIDDEN = sharedKey('hidden'); // 用于存储隐藏的符号 + var SYMBOL = 'Symbol'; // 符号常量 + var PROTOTYPE$1 = 'prototype'; // 原型常量 + var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); // 转换为原始值的符号 + var setInternalState = internalState.set; // 设置内部状态的方法 + var getInternalState = internalState.getterFor(SYMBOL); // 获取符号的内部状态的方法 + var ObjectPrototype = Object[PROTOTYPE$1]; // 获取 Object 的原型 + var $Symbol = global_1.Symbol; // 获取全局的 Symbol 对象 + var $stringify = getBuiltIn('JSON', 'stringify'); // 获取 JSON.stringify 方法 + var nativeGetOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; // 获取对象的属性描述符 + var nativeDefineProperty$1 = objectDefineProperty.f; // 定义对象属性 + var nativeGetOwnPropertyNames$1 = objectGetOwnPropertyNamesExternal.f; // 获取对象的所有属性名 + var nativePropertyIsEnumerable$1 = objectPropertyIsEnumerable.f; // 判断对象的属性是否可枚举 + var AllSymbols = shared('symbols'); // 存储所有符号的共享对象 + var ObjectPrototypeSymbols = shared('op-symbols'); // 存储 Object.prototype 的符号 + var StringToSymbolRegistry = shared('string-to-symbol-registry'); // 字符串到符号的注册表 + var SymbolToStringRegistry = shared('symbol-to-string-registry'); // 符号到字符串的注册表 + var WellKnownSymbolsStore$1 = shared('wks'); // 存储知名符号的共享对象 + var QObject = global_1.QObject; // 获取 Qt 对象 + +// 针对 Qt Script 做的处理,避免使用 setter var USE_SETTER = !QObject || !QObject[PROTOTYPE$1] || !QObject[PROTOTYPE$1].findChild; - // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687 +// 针对旧版 Android 浏览器的回退处理 var setSymbolDescriptor = descriptors && fails(function () { - return objectCreate(nativeDefineProperty$1({}, 'a', { - get: function () { return nativeDefineProperty$1(this, 'a', { value: 7 }).a; } - })).a != 7; + return objectCreate(nativeDefineProperty$1({}, 'a', { + get: function () { return nativeDefineProperty$1(this, 'a', { value: 7 }).a; } + })).a != 7; }) ? function (O, P, Attributes) { - var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor$1(ObjectPrototype, P); - if (ObjectPrototypeDescriptor) delete ObjectPrototype[P]; - nativeDefineProperty$1(O, P, Attributes); - if (ObjectPrototypeDescriptor && O !== ObjectPrototype) { - nativeDefineProperty$1(ObjectPrototype, P, ObjectPrototypeDescriptor); - } + var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor$1(ObjectPrototype, P); + if (ObjectPrototypeDescriptor) delete ObjectPrototype[P]; + nativeDefineProperty$1(O, P, Attributes); + if (ObjectPrototypeDescriptor && O !== ObjectPrototype) { + nativeDefineProperty$1(ObjectPrototype, P, ObjectPrototypeDescriptor); + } } : nativeDefineProperty$1; +// 包装符号并设置内部状态 var wrap = function (tag, description) { - var symbol = AllSymbols[tag] = objectCreate($Symbol[PROTOTYPE$1]); - setInternalState(symbol, { - type: SYMBOL, - tag: tag, - description: description - }); - if (!descriptors) symbol.description = description; - return symbol; + var symbol = AllSymbols[tag] = objectCreate($Symbol[PROTOTYPE$1]); + setInternalState(symbol, { + type: SYMBOL, + tag: tag, + description: description + }); + if (!descriptors) symbol.description = description; // 如果没有 descriptors,则直接设置描述 + return symbol; }; +// 检查是否是符号类型 var isSymbol = nativeSymbol && typeof $Symbol.iterator == 'symbol' ? function (it) { - return typeof it == 'symbol'; + return typeof it == 'symbol'; // 如果原生支持 Symbol,则直接检查类型 } : function (it) { - return Object(it) instanceof $Symbol; + return Object(it) instanceof $Symbol; // 否则检查对象是否是 Symbol 的实例 }; +// 自定义 defineProperty 方法 var $defineProperty = function defineProperty(O, P, Attributes) { - if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes); - anObject(O); - var key = toPrimitive(P, true); - anObject(Attributes); - if (has(AllSymbols, key)) { - if (!Attributes.enumerable) { - if (!has(O, HIDDEN)) nativeDefineProperty$1(O, HIDDEN, createPropertyDescriptor(1, {})); - O[HIDDEN][key] = true; - } else { - if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false; - Attributes = objectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) }); - } return setSymbolDescriptor(O, key, Attributes); - } return nativeDefineProperty$1(O, key, Attributes); + if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes); // 如果是 Object.prototype,则特殊处理 + anObject(O); // 确保 O 是一个对象 + var key = toPrimitive(P, true); // 将 P 转换为原始值 + anObject(Attributes); // 确保属性描述符是对象 + if (has(AllSymbols, key)) { // 如果属性是符号 + if (!Attributes.enumerable) { // 如果不可枚举 + if (!has(O, HIDDEN)) nativeDefineProperty$1(O, HIDDEN, createPropertyDescriptor(1, {})); // 确保对象有隐藏属性 + O[HIDDEN][key] = true; // 将符号标记为隐藏 + } else { + if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false; // 如果是可枚举,移除隐藏标记 + Attributes = objectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) }); // 修改属性描述符,确保不可枚举 + } + return setSymbolDescriptor(O, key, Attributes); // 设置符号描述符 + } + return nativeDefineProperty$1(O, key, Attributes); // 否则使用原生 defineProperty 方法 }; +// 自定义 defineProperties 方法 var $defineProperties = function defineProperties(O, Properties) { - anObject(O); - var properties = toIndexedObject(Properties); - var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties)); - $forEach(keys, function (key) { - if (!descriptors || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]); - }); - return O; + anObject(O); // 确保 O 是一个对象 + var properties = toIndexedObject(Properties); // 将 Properties 转换为索引对象 + var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties)); // 获取属性键,包括符号 + $forEach(keys, function (key) { + if (!descriptors || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]); // 遍历键,定义属性 + }); + return O; }; +// 自定义 create 方法 var $create = function create(O, Properties) { - return Properties === undefined ? objectCreate(O) : $defineProperties(objectCreate(O), Properties); + return Properties === undefined ? objectCreate(O) : $defineProperties(objectCreate(O), Properties); // 如果没有 Properties 参数,直接创建一个对象,否则使用 defineProperties 定义属性 }; +// 自定义 propertyIsEnumerable 方法 var $propertyIsEnumerable = function propertyIsEnumerable(V) { - var P = toPrimitive(V, true); - var enumerable = nativePropertyIsEnumerable$1.call(this, P); - if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false; - return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true; + var P = toPrimitive(V, true); // 将 V 转换为原始值 + var enumerable = nativePropertyIsEnumerable$1.call(this, P); // 使用原生方法检查是否可枚举 + if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false; // 如果是 Object.prototype 并且符号不可枚举,则返回 false + return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true; // 返回最终结果 }; +// 自定义 getOwnPropertyDescriptor 方法 var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) { - var it = toIndexedObject(O); - var key = toPrimitive(P, true); - if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return; - var descriptor = nativeGetOwnPropertyDescriptor$1(it, key); - if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) { - descriptor.enumerable = true; - } - return descriptor; + var it = toIndexedObject(O); // 将 O 转换为索引对象 + var key = toPrimitive(P, true); // 将 P 转换为原始值 + if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return; // 如果是 Object.prototype 且符号不可枚举,则返回 undefined + var descriptor = nativeGetOwnPropertyDescriptor$1(it, key); // 获取属性描述符 + if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) { // 如果是符号并且不是隐藏的符号 + descriptor.enumerable = true; // 设置可枚举 + } + return descriptor; }; +// 自定义 getOwnPropertyNames 方法 var $getOwnPropertyNames = function getOwnPropertyNames(O) { - var names = nativeGetOwnPropertyNames$1(toIndexedObject(O)); - var result = []; - $forEach(names, function (key) { - if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key); - }); - return result; + var names = nativeGetOwnPropertyNames$1(toIndexedObject(O)); // 获取对象的属性名 + var result = []; + $forEach(names, function (key) { + if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key); // 如果不是符号且不在 hiddenKeys 中,加入结果数组 + }); + return result; }; +// 自定义 getOwnPropertySymbols 方法 var $getOwnPropertySymbols = function getOwnPropertySymbols(O) { - var IS_OBJECT_PROTOTYPE = O === ObjectPrototype; - var names = nativeGetOwnPropertyNames$1(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O)); - var result = []; - $forEach(names, function (key) { - if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) { - result.push(AllSymbols[key]); - } - }); - return result; + var IS_OBJECT_PROTOTYPE = O === ObjectPrototype; + var names = nativeGetOwnPropertyNames$1(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O)); // 获取对象的属性名 + var result = []; + $forEach(names, function (key) { + if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) { + result.push(AllSymbols[key]); // 如果是符号,加入结果数组 + } + }); + return result; }; // `Symbol` constructor // https://tc39.github.io/ecma262/#sec-symbol-constructor + // 如果浏览器原生不支持 Symbol(即 nativeSymbol 为 false) if (!nativeSymbol) { - $Symbol = function Symbol() { - if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor'); - var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]); - var tag = uid(description); - var setter = function (value) { - if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value); - if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; - setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value)); - }; - if (descriptors && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter }); - return wrap(tag, description); - }; - - redefine($Symbol[PROTOTYPE$1], 'toString', function toString() { - return getInternalState(this).tag; - }); - - objectPropertyIsEnumerable.f = $propertyIsEnumerable; - objectDefineProperty.f = $defineProperty; - objectGetOwnPropertyDescriptor.f = $getOwnPropertyDescriptor; - objectGetOwnPropertyNames.f = objectGetOwnPropertyNamesExternal.f = $getOwnPropertyNames; - objectGetOwnPropertySymbols.f = $getOwnPropertySymbols; - - if (descriptors) { - // https://github.com/tc39/proposal-Symbol-description - nativeDefineProperty$1($Symbol[PROTOTYPE$1], 'description', { - configurable: true, - get: function description() { - return getInternalState(this).description; - } - }); - { - redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true }); - } - } + // 定义 Symbol 构造函数 + $Symbol = function Symbol() { + if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor'); // 防止将 Symbol 当做构造函数使用 + var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]); // 如果没有传入描述,则设为 undefined + var tag = uid(description); // 生成唯一的标签(标识符) + var setter = function (value) { + if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value); // 如果是 Object.prototype,调用 ObjectPrototypeSymbols 的 setter + if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; // 如果符号已经存在,标记为不可见 + setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value)); // 设置符号的属性描述符 + }; + + if (descriptors && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter }); // 设置 setter 方法 + return wrap(tag, description); // 包装并返回符号 + }; + + // 为 Symbol.prototype 添加 toString 方法,返回符号的标签 + redefine($Symbol[PROTOTYPE$1], 'toString', function toString() { + return getInternalState(this).tag; + }); + + // 定义各种 Object 方法的符号实现 + objectPropertyIsEnumerable.f = $propertyIsEnumerable; + objectDefineProperty.f = $defineProperty; + objectGetOwnPropertyDescriptor.f = $getOwnPropertyDescriptor; + objectGetOwnPropertyNames.f = objectGetOwnPropertyNamesExternal.f = $getOwnPropertyNames; + objectGetOwnPropertySymbols.f = $getOwnPropertySymbols; + + if (descriptors) { + // 为 Symbol.prototype 添加 description 属性的 getter 方法 + nativeDefineProperty$1($Symbol[PROTOTYPE$1], 'description', { + configurable: true, + get: function description() { + return getInternalState(this).description; + } + }); + + // 为 Object.prototype 的 propertyIsEnumerable 方法添加符号支持 + { + redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true }); + } + } } +// 如果不使用 Symbol 作为唯一标识符(useSymbolAsUid 为 false),则创建 well-known 符号的包装器 if (!useSymbolAsUid) { - wrappedWellKnownSymbol.f = function (name) { - return wrap(wellKnownSymbol(name), name); - }; + wrappedWellKnownSymbol.f = function (name) { + return wrap(wellKnownSymbol(name), name); + }; } +// 导出 Symbol 构造函数,确保其全局可用 _export({ global: true, wrap: true, forced: !nativeSymbol, sham: !nativeSymbol }, { - Symbol: $Symbol + Symbol: $Symbol }); +// 遍历 WellKnownSymbolsStore$1 对象,定义每个知名符号 $forEach(objectKeys(WellKnownSymbolsStore$1), function (name) { - defineWellKnownSymbol(name); + defineWellKnownSymbol(name); }); +// 导出 `Symbol.for` 和 `Symbol.keyFor` 方法 _export({ target: SYMBOL, stat: true, forced: !nativeSymbol }, { - // `Symbol.for` method - // https://tc39.github.io/ecma262/#sec-symbol.for - 'for': function (key) { - var string = String(key); - if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string]; - var symbol = $Symbol(string); - StringToSymbolRegistry[string] = symbol; - SymbolToStringRegistry[symbol] = string; - return symbol; - }, - // `Symbol.keyFor` method - // https://tc39.github.io/ecma262/#sec-symbol.keyfor - keyFor: function keyFor(sym) { - if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol'); - if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym]; - }, - useSetter: function () { USE_SETTER = true; }, - useSimple: function () { USE_SETTER = false; } + // `Symbol.for` 方法:根据键查找或创建一个符号 + // https://tc39.github.io/ecma262/#sec-symbol.for + 'for': function (key) { + var string = String(key); // 将键转换为字符串 + if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string]; // 如果注册表中已有此符号,则返回它 + var symbol = $Symbol(string); // 否则创建一个新符号 + StringToSymbolRegistry[string] = symbol; // 将符号添加到注册表 + SymbolToStringRegistry[symbol] = string; // 将符号映射到字符串 + return symbol; + }, + // `Symbol.keyFor` 方法:根据符号查找对应的键 + // https://tc39.github.io/ecma262/#sec-symbol.keyfor + keyFor: function keyFor(sym) { + if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol'); // 如果传入的不是符号,抛出错误 + if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym]; // 如果符号存在于注册表中,返回其对应的键 + }, + useSetter: function () { USE_SETTER = true; }, // 设置 USE_SETTER 为 true + useSimple: function () { USE_SETTER = false; } // 设置 USE_SETTER 为 false }); +// 导出 Object 的符号支持方法 _export({ target: 'Object', stat: true, forced: !nativeSymbol, sham: !descriptors }, { - // `Object.create` method - // https://tc39.github.io/ecma262/#sec-object.create - create: $create, - // `Object.defineProperty` method - // https://tc39.github.io/ecma262/#sec-object.defineproperty - defineProperty: $defineProperty, - // `Object.defineProperties` method - // https://tc39.github.io/ecma262/#sec-object.defineproperties - defineProperties: $defineProperties, - // `Object.getOwnPropertyDescriptor` method - // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors - getOwnPropertyDescriptor: $getOwnPropertyDescriptor + // `Object.create` 方法:使用符号创建对象 + // https://tc39.github.io/ecma262/#sec-object.create + create: $create, + // `Object.defineProperty` 方法:使用符号定义对象属性 + // https://tc39.github.io/ecma262/#sec-object.defineproperty + defineProperty: $defineProperty, + // `Object.defineProperties` 方法:使用符号定义多个对象属性 + // https://tc39.github.io/ecma262/#sec-object.defineproperties + defineProperties: $defineProperties, + // `Object.getOwnPropertyDescriptor` 方法:获取对象属性描述符 + // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors + getOwnPropertyDescriptor: $getOwnPropertyDescriptor }); +// 导出 Object 的符号支持方法 _export({ target: 'Object', stat: true, forced: !nativeSymbol }, { - // `Object.getOwnPropertyNames` method - // https://tc39.github.io/ecma262/#sec-object.getownpropertynames - getOwnPropertyNames: $getOwnPropertyNames, - // `Object.getOwnPropertySymbols` method - // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols - getOwnPropertySymbols: $getOwnPropertySymbols + // `Object.getOwnPropertyNames` 方法:获取对象的属性名 + // https://tc39.github.io/ecma262/#sec-object.getownpropertynames + getOwnPropertyNames: $getOwnPropertyNames, + // `Object.getOwnPropertySymbols` 方法:获取对象的符号属性 + // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols + getOwnPropertySymbols: $getOwnPropertySymbols }); - // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives - // https://bugs.chromium.org/p/v8/issues/detail?id=3443 +// 解决 Chrome 38 和 39 中 `Object.getOwnPropertySymbols` 在原始值上的失败问题 +// https://bugs.chromium.org/p/v8/issues/detail?id=3443 _export({ target: 'Object', stat: true, forced: fails(function () { objectGetOwnPropertySymbols.f(1); }) }, { - getOwnPropertySymbols: function getOwnPropertySymbols(it) { - return objectGetOwnPropertySymbols.f(toObject(it)); - } + getOwnPropertySymbols: function getOwnPropertySymbols(it) { + return objectGetOwnPropertySymbols.f(toObject(it)); // 确保 it 是一个对象 + } }); - // `JSON.stringify` method behavior with symbols - // https://tc39.github.io/ecma262/#sec-json.stringify +// 处理 JSON.stringify 方法与符号的兼容性问题 +// https://tc39.github.io/ecma262/#sec-json.stringify if ($stringify) { - var FORCED_JSON_STRINGIFY = !nativeSymbol || fails(function () { - var symbol = $Symbol(); - // MS Edge converts symbol values to JSON as {} - return $stringify([symbol]) != '[null]' - // WebKit converts symbol values to JSON as null - || $stringify({ a: symbol }) != '{}' - // V8 throws on boxed symbols - || $stringify(Object(symbol)) != '{}'; - }); - - _export({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, { - // eslint-disable-next-line no-unused-vars - stringify: function stringify(it, replacer, space) { - var args = [it]; - var index = 1; - var $replacer; - while (arguments.length > index) args.push(arguments[index++]); - $replacer = replacer; - if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined - if (!isArray(replacer)) replacer = function (key, value) { - if (typeof $replacer == 'function') value = $replacer.call(this, key, value); - if (!isSymbol(value)) return value; - }; - args[1] = replacer; - return $stringify.apply(null, args); - } - }); + var FORCED_JSON_STRINGIFY = !nativeSymbol || fails(function () { + var symbol = $Symbol(); + // 检查 MS Edge 和 WebKit 对符号的处理 + return $stringify([symbol]) != '[null]' // Edge 将符号值转换为 {} + || $stringify({ a: symbol }) != '{}' // WebKit 将符号值转换为 null + || $stringify(Object(symbol)) != '{}'; // V8 在符号被包装时抛出异常 + }); + + // 强制覆盖 `JSON.stringify` 方法 + _export({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, { + stringify: function stringify(it, replacer, space) { + var args = [it]; + var index = 1; + var $replacer; + while (arguments.length > index) args.push(arguments[index++]); // 收集所有参数 + $replacer = replacer; + if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // 如果是 undefined 或符号,则跳过 + if (!isArray(replacer)) replacer = function (key, value) { + if (typeof $replacer == 'function') value = $replacer.call(this, key, value); // 如果 replacer 是函数,调用它 + if (!isSymbol(value)) return value; // 如果值不是符号,则返回 + }; + args[1] = replacer; // 更新 replacer + return $stringify.apply(null, args); // 调用原始的 JSON.stringify 方法 + } + }); } - // `Symbol.prototype[@@toPrimitive]` method - // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive +// 如果 Symbol.prototype 没有实现 `@@toPrimitive` 方法,则添加该方法 +// https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive if (!$Symbol[PROTOTYPE$1][TO_PRIMITIVE]) { - createNonEnumerableProperty($Symbol[PROTOTYPE$1], TO_PRIMITIVE, $Symbol[PROTOTYPE$1].valueOf); + createNonEnumerableProperty($Symbol[PROTOTYPE$1], TO_PRIMITIVE, $Symbol[PROTOTYPE$1].valueOf); } - // `Symbol.prototype[@@toStringTag]` property - // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag + +// 设置 Symbol 类型的 toStringTag +// https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag setToStringTag($Symbol, SYMBOL); +// 将 HIDDEN 属性添加到 hiddenKeys 中 hiddenKeys[HIDDEN] = true; +// 处理原生 Symbol 的描述符 var defineProperty$2 = objectDefineProperty.f; - +// 如果浏览器原生支持 Symbol,且存在描述符属性问题,则进行修复 var NativeSymbol = global_1.Symbol; - if (descriptors && typeof NativeSymbol == 'function' && (!('description' in NativeSymbol.prototype) || - // Safari 12 bug - NativeSymbol().description !== undefined + // Safari 12 bug + NativeSymbol().description !== undefined )) { - var EmptyStringDescriptionStore = {}; - // wrap Symbol constructor for correct work with undefined description - var SymbolWrapper = function Symbol() { - var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]); - var result = this instanceof SymbolWrapper - ? new NativeSymbol(description) - // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)' - : description === undefined ? NativeSymbol() : NativeSymbol(description); - if (description === '') EmptyStringDescriptionStore[result] = true; - return result; - }; - copyConstructorProperties(SymbolWrapper, NativeSymbol); - var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype; - symbolPrototype.constructor = SymbolWrapper; - - var symbolToString = symbolPrototype.toString; - var native = String(NativeSymbol('test')) == 'Symbol(test)'; - var regexp = /^Symbol\((.*)\)[^)]+$/; - defineProperty$2(symbolPrototype, 'description', { - configurable: true, - get: function description() { - var symbol = isObject(this) ? this.valueOf() : this; - var string = symbolToString.call(symbol); - if (has(EmptyStringDescriptionStore, symbol)) return ''; - var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1'); - return desc === '' ? undefined : desc; - } - }); - - _export({ global: true, forced: true }, { - Symbol: SymbolWrapper - }); + var EmptyStringDescriptionStore = {}; + // 包装原生 Symbol 构造函数,确保正确处理空字符串描述符 + var SymbolWrapper = function Symbol() { + var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]); + var result = this instanceof SymbolWrapper + ? new NativeSymbol(description) + : description === undefined ? NativeSymbol() : NativeSymbol(description); + if (description === '') EmptyStringDescriptionStore[result] = true; + return result; + }; + copyConstructorProperties(SymbolWrapper, NativeSymbol); + var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype; + symbolPrototype.constructor = SymbolWrapper; + + // 修复 Symbol.prototype 的 description 属性 + var symbolToString = symbolPrototype.toString; + var native = String(NativeSymbol('test')) == 'Symbol(test)'; + var regexp = /^Symbol\((.*)\)[^)]+$/; + defineProperty$2(symbolPrototype, 'description', { + configurable: true, + get: function description() { + var symbol = isObject(this) ? this.valueOf() : this; + var string = symbolToString.call(symbol); + if (has(EmptyStringDescriptionStore, symbol)) return ''; + var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1'); + return desc === '' ? undefined : desc; + } + }); + + _export({ global: true, forced: true }, { + Symbol: SymbolWrapper // 使用包装后的 Symbol + }); } + // `Symbol.iterator` well-known symbol // https://tc39.github.io/ecma262/#sec-symbol.iterator + // 定义一个知名符号 'iterator',表示可以用于迭代操作的符号 defineWellKnownSymbol('iterator'); +// 创建一个辅助函数,用于在对象上定义属性 var createProperty = function (object, key, value) { - var propertyKey = toPrimitive(key); - if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value)); - else object[propertyKey] = value; + var propertyKey = toPrimitive(key); // 将键转换为原始值 + if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value)); // 如果属性已经存在,使用 `Object.defineProperty` 设置属性描述符 + else object[propertyKey] = value; // 否则直接给对象添加属性 }; - var userAgent = getBuiltIn('navigator', 'userAgent') || ''; +// 获取浏览器的 userAgent,用于浏览器版本判断 + var userAgent = getBuiltIn('navigator', 'userAgent') || ''; // 获取浏览器的 userAgent 字符串 - var process = global_1.process; - var versions = process && process.versions; - var v8 = versions && versions.v8; + var process = global_1.process; // 获取 Node.js 环境的 process 对象 + var versions = process && process.versions; // 获取版本信息 + var v8 = versions && versions.v8; // 获取 V8 引擎的版本 var match, version; +// 检查 V8 引擎的版本,如果存在 v8 版本号,则提取并拼接出版本号 if (v8) { - match = v8.split('.'); - version = match[0] + match[1]; + match = v8.split('.'); // 将 v8 版本号拆分成数组 + version = match[0] + match[1]; // 拼接出一个版本号,例如 '60' 表示 v8 6.0 } else if (userAgent) { - match = userAgent.match(/Edge\/(\d+)/); - if (!match || match[1] >= 74) { - match = userAgent.match(/Chrome\/(\d+)/); - if (match) version = match[1]; - } + // 如果 V8 版本信息不存在,检查 userAgent 字符串中的浏览器信息 + match = userAgent.match(/Edge\/(\d+)/); // 匹配 Edge 浏览器的版本号 + if (!match || match[1] >= 74) { + match = userAgent.match(/Chrome\/(\d+)/); // 如果 Edge 版本低于 74,则匹配 Chrome 浏览器的版本号 + if (match) version = match[1]; // 提取 Chrome 的版本号 + } } +// 将版本号转换为数字 var v8Version = version && +version; +// 定义 `@@species` 符号,用于支持 ES6 中的 `species` 属性 var SPECIES$1 = wellKnownSymbol('species'); +// 检测数组方法是否支持 `species` 属性 var arrayMethodHasSpeciesSupport = function (METHOD_NAME) { - // We can't use this feature detection in V8 since it causes - // deoptimization and serious performance degradation - // https://github.com/zloirock/core-js/issues/677 - return v8Version >= 51 || !fails(function () { - var array = []; - var constructor = array.constructor = {}; - constructor[SPECIES$1] = function () { - return { foo: 1 }; - }; - return array[METHOD_NAME](Boolean).foo !== 1; - }); + // 在 V8 中,使用这种特性检测会导致性能问题,因此无法在 V8 中使用此检测 + // https://github.com/zloirock/core-js/issues/677 + return v8Version >= 51 || !fails(function () { + var array = []; + var constructor = array.constructor = {}; // 构造一个伪造的数组构造函数 + constructor[SPECIES$1] = function () { // 为数组的构造函数添加 species 属性 + return { foo: 1 }; + }; + return array[METHOD_NAME](Boolean).foo !== 1; // 检查 `concat` 方法是否能够正确使用 `species` + }); }; +// 定义 `@@isConcatSpreadable` 符号,用于支持 `Array.prototype.concat` 中的展开操作 var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable'); - var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; - var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; + var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // JavaScript 中的最大安全整数值 + var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; // 超过最大索引值的错误信息 - // We can't use this feature detection in V8 since it causes - // deoptimization and serious performance degradation - // https://github.com/zloirock/core-js/issues/679 +// 检测 `@@isConcatSpreadable` 是否在当前环境中得到支持 var IS_CONCAT_SPREADABLE_SUPPORT = v8Version >= 51 || !fails(function () { - var array = []; - array[IS_CONCAT_SPREADABLE] = false; - return array.concat()[0] !== array; + var array = []; + array[IS_CONCAT_SPREADABLE] = false; // 给数组添加 isConcatSpreadable 属性 + return array.concat()[0] !== array; // 检查展开操作是否正确处理了 `isConcatSpreadable` }); +// 检测 `Array.prototype.concat` 方法是否支持 `@@species` 属性 var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat'); +// 检查一个对象是否是可展开的 var isConcatSpreadable = function (O) { - if (!isObject(O)) return false; - var spreadable = O[IS_CONCAT_SPREADABLE]; - return spreadable !== undefined ? !!spreadable : isArray(O); + if (!isObject(O)) return false; // 如果 O 不是对象,返回 false + var spreadable = O[IS_CONCAT_SPREADABLE]; // 获取对象的 isConcatSpreadable 属性 + return spreadable !== undefined ? !!spreadable : isArray(O); // 如果有 isConcatSpreadable 属性,则返回它的布尔值,否则判断它是否是数组 }; +// 强制标记需要修复的地方 var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT; - // `Array.prototype.concat` method - // https://tc39.github.io/ecma262/#sec-array.prototype.concat - // with adding support of @@isConcatSpreadable and @@species +// 导出 Array.prototype.concat 方法,加入对 `@@isConcatSpreadable` 和 `@@species` 的支持 +// 规范文档:https://tc39.github.io/ecma262/#sec-array.prototype.concat _export({ target: 'Array', proto: true, forced: FORCED }, { - concat: function concat(arg) { // eslint-disable-line no-unused-vars - var O = toObject(this); - var A = arraySpeciesCreate(O, 0); - var n = 0; - var i, k, length, len, E; - for (i = -1, length = arguments.length; i < length; i++) { - E = i === -1 ? O : arguments[i]; - if (isConcatSpreadable(E)) { - len = toLength(E.length); - if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); - for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]); - } else { - if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); - createProperty(A, n++, E); - } - } - A.length = n; - return A; - } + concat: function concat(arg) { // eslint-disable-line no-unused-vars + var O = toObject(this); // 将当前数组转换为对象 + var A = arraySpeciesCreate(O, 0); // 创建一个新数组 + var n = 0; // 初始化新数组的长度 + var i, k, length, len, E; + for (i = -1, length = arguments.length; i < length; i++) { + E = i === -1 ? O : arguments[i]; // 如果是第一个参数,使用当前数组 O + if (isConcatSpreadable(E)) { // 如果 E 是可展开的 + len = toLength(E.length); // 获取 E 的长度 + if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); // 检查是否超过最大安全整数 + for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]); // 将 E 中的元素添加到新数组 A + } else { // 如果 E 不是可展开的 + if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); // 检查新数组长度是否超过最大安全整数 + createProperty(A, n++, E); // 直接将 E 添加到新数组 A + } + } + A.length = n; // 设置新数组的长度 + return A; // 返回新数组 + } }); +// 定义 `Array.prototype.filter` 方法的迭代器支持 var $filter = arrayIteration.filter; - - +// 检测 `Array.prototype.filter` 是否支持 `species` 属性 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter'); - // Edge 14- issue + +// 在 Edge 14 中存在的问题 var USES_TO_LENGTH = HAS_SPECIES_SUPPORT && !fails(function () { - [].filter.call({ length: -1, 0: 1 }, function (it) { throw it; }); + [].filter.call({ length: -1, 0: 1 }, function (it) { throw it; }); // 检测当数组长度为负数时,filter 方法的行为 }); + // `Array.prototype.filter` method // https://tc39.github.io/ecma262/#sec-array.prototype.filter // with adding support of @@species + // 导出自定义的 `Array.prototype.filter` 方法,增加了 `callbackfn` 和 `thisArg` 参数 _export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH }, { - filter: function filter(callbackfn /* , thisArg */) { - return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } + filter: function filter(callbackfn /* , thisArg */) { + // 调用内置的 `$filter` 方法 + return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } }); +// 定义 `@@unscopables` 符号,用于处理与数组的“不可解构”操作相关的特性 var UNSCOPABLES = wellKnownSymbol('unscopables'); var ArrayPrototype = Array.prototype; - // Array.prototype[@@unscopables] - // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables +// `Array.prototype[@@unscopables]` - 将 `@@unscopables` 符号绑定到 `Array.prototype` +// 该符号用于指定哪些数组方法不可被解构(例如 `find`、`findIndex` 等) if (ArrayPrototype[UNSCOPABLES] == undefined) { - objectDefineProperty.f(ArrayPrototype, UNSCOPABLES, { - configurable: true, - value: objectCreate(null) - }); + objectDefineProperty.f(ArrayPrototype, UNSCOPABLES, { + configurable: true, + value: objectCreate(null) // 设置 `@@unscopables` 为一个空对象 + }); } - // add a key to Array.prototype[@@unscopables] +// 将指定的键添加到 `Array.prototype[@@unscopables]` 对象中 var addToUnscopables = function (key) { - ArrayPrototype[UNSCOPABLES][key] = true; + ArrayPrototype[UNSCOPABLES][key] = true; // 将 key 标记为不可解构 }; +// 定义 `find` 方法并导出,支持对数组的查找操作 var $find = arrayIteration.find; - - var FIND = 'find'; var SKIPS_HOLES = true; - // Shouldn't skip holes +// 检测 `find` 方法是否跳过数组中的“孔”(即空项) if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; }); - // `Array.prototype.find` method - // https://tc39.github.io/ecma262/#sec-array.prototype.find +// 导出自定义的 `Array.prototype.find` 方法 _export({ target: 'Array', proto: true, forced: SKIPS_HOLES }, { - find: function find(callbackfn /* , that = undefined */) { - return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } + find: function find(callbackfn /* , that = undefined */) { + // 调用内置的 `$find` 方法 + return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } }); - // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables +// 将 `find` 方法添加到 `@@unscopables` 中,避免解构时被提取 addToUnscopables(FIND); +// 定义 `findIndex` 方法并导出,返回数组中符合条件元素的索引 var $findIndex = arrayIteration.findIndex; - - var FIND_INDEX = 'findIndex'; var SKIPS_HOLES$1 = true; - // Shouldn't skip holes +// 检测 `findIndex` 方法是否跳过数组中的“孔” if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES$1 = false; }); - // `Array.prototype.findIndex` method - // https://tc39.github.io/ecma262/#sec-array.prototype.findindex +// 导出自定义的 `Array.prototype.findIndex` 方法 _export({ target: 'Array', proto: true, forced: SKIPS_HOLES$1 }, { - findIndex: function findIndex(callbackfn /* , that = undefined */) { - return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } + findIndex: function findIndex(callbackfn /* , that = undefined */) { + // 调用内置的 `$findIndex` 方法 + return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } }); - // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables +// 将 `findIndex` 方法添加到 `@@unscopables` 中,避免解构时被提取 addToUnscopables(FIND_INDEX); +// 定义并导出 `Array.prototype.includes` 方法,用于检查元素是否在数组中 var $includes = arrayIncludes.includes; - - - // `Array.prototype.includes` method - // https://tc39.github.io/ecma262/#sec-array.prototype.includes _export({ target: 'Array', proto: true }, { - includes: function includes(el /* , fromIndex = 0 */) { - return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); - } + includes: function includes(el /* , fromIndex = 0 */) { + // 调用内置的 `$includes` 方法 + return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); + } }); - // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables +// 将 `includes` 方法添加到 `@@unscopables` 中,避免解构时被提取 addToUnscopables('includes'); +// 定义一个函数 `sloppyArrayMethod`,用于检查某个数组方法是否存在问题 var sloppyArrayMethod = function (METHOD_NAME, argument) { - var method = [][METHOD_NAME]; - return !method || !fails(function () { - // eslint-disable-next-line no-useless-call,no-throw-literal - method.call(null, argument || function () { throw 1; }, 1); - }); + var method = [][METHOD_NAME]; + return !method || !fails(function () { + // 测试方法是否正常工作 + method.call(null, argument || function () { throw 1; }, 1); + }); }; +// 定义并导出 `Array.prototype.indexOf` 方法,检查数组中是否包含某个元素 var $indexOf = arrayIncludes.indexOf; - - var nativeIndexOf = [].indexOf; - var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0; - var SLOPPY_METHOD = sloppyArrayMethod('indexOf'); + var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0; // 处理负零的情况 + var SLOPPY_METHOD = sloppyArrayMethod('indexOf'); // 检查 `indexOf` 是否存在问题 - // `Array.prototype.indexOf` method - // https://tc39.github.io/ecma262/#sec-array.prototype.indexof +// 导出自定义的 `Array.prototype.indexOf` 方法 _export({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || SLOPPY_METHOD }, { - indexOf: function indexOf(searchElement /* , fromIndex = 0 */) { - return NEGATIVE_ZERO - // convert -0 to +0 - ? nativeIndexOf.apply(this, arguments) || 0 - : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined); - } + indexOf: function indexOf(searchElement /* , fromIndex = 0 */) { + return NEGATIVE_ZERO + // 处理负零,将 `-0` 转换为 `+0` + ? nativeIndexOf.apply(this, arguments) || 0 + : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined); + } }); +// 检查 `Object.getPrototypeOf` 是否正常工作 +// 该函数检测 `Object.getPrototypeOf` 是否能够正确返回对象的原型 var correctPrototypeGetter = !fails(function () { - function F() { /* empty */ } - F.prototype.constructor = null; - return Object.getPrototypeOf(new F()) !== F.prototype; + function F() { /* empty */ } + F.prototype.constructor = null; + // 如果 `Object.getPrototypeOf` 返回的原型不是传入对象的原型,则返回 false + return Object.getPrototypeOf(new F()) !== F.prototype; }); +// 定义 `IE_PROTO` 键,用于存储对象的原型信息 var IE_PROTO$1 = sharedKey('IE_PROTO'); var ObjectPrototype$1 = Object.prototype; - // `Object.getPrototypeOf` method - // https://tc39.github.io/ecma262/#sec-object.getprototypeof +// `Object.getPrototypeOf` 方法的兼容性处理 +// 该方法用于获取对象的原型,如果浏览器不支持该方法,则自定义实现 var objectGetPrototypeOf = correctPrototypeGetter ? Object.getPrototypeOf : function (O) { - O = toObject(O); - if (has(O, IE_PROTO$1)) return O[IE_PROTO$1]; - if (typeof O.constructor == 'function' && O instanceof O.constructor) { - return O.constructor.prototype; - } return O instanceof Object ? ObjectPrototype$1 : null; + O = toObject(O); // 确保传入的是对象 + if (has(O, IE_PROTO$1)) return O[IE_PROTO$1]; // 如果对象上有 `IE_PROTO`,则返回其值 + if (typeof O.constructor == 'function' && O instanceof O.constructor) { + return O.constructor.prototype; // 如果对象是构造函数的实例,返回构造函数的原型 + } + return O instanceof Object ? ObjectPrototype$1 : null; // 否则返回 `Object.prototype` }; +// 定义一个常量 `ITERATOR`,表示迭代器符号(`Symbol.iterator`) var ITERATOR = wellKnownSymbol('iterator'); - var BUGGY_SAFARI_ITERATORS = false; + var BUGGY_SAFARI_ITERATORS = false; // 用于检测 Safari 8 中的迭代器问题 +// 定义一个函数 `returnThis`,该函数用于返回当前对象 var returnThis = function () { return this; }; - // `%IteratorPrototype%` object - // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object +// 初始化 `IteratorPrototype` 和其他变量,用于兼容性处理 var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator; +// 检查当前环境是否支持数组迭代器,并处理 Safari 8 的特殊问题 if ([].keys) { - arrayIterator = [].keys(); - // Safari 8 has buggy iterators w/o `next` - if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true; - else { - PrototypeOfArrayIteratorPrototype = objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator)); - if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype; - } + arrayIterator = [].keys(); + // 检测 Safari 8 是否存在 bug:迭代器没有 `next` 方法 + if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true; + else { + // 获取数组迭代器原型的原型 + PrototypeOfArrayIteratorPrototype = objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator)); + // 如果数组迭代器原型的原型不是 `Object.prototype`,则设置 `IteratorPrototype` + if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype; + } } +// 如果 `IteratorPrototype` 仍然没有被设置,则将其初始化为空对象 if (IteratorPrototype == undefined) IteratorPrototype = {}; - // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() - if ( !has(IteratorPrototype, ITERATOR)) { - createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis); +// 25.1.2.1.1 `%IteratorPrototype%[@@iterator]()` +// 如果 `IteratorPrototype` 没有定义 `@@iterator`,则为其创建该方法 + if (!has(IteratorPrototype, ITERATOR)) { + createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis); } +// 将 `IteratorPrototype` 和 `BUGGY_SAFARI_ITERATORS` 作为 `iteratorsCore` 的属性导出 var iteratorsCore = { - IteratorPrototype: IteratorPrototype, - BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS + IteratorPrototype: IteratorPrototype, + BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS }; +// 赋值 `IteratorPrototype$1` 为 `iteratorsCore.IteratorPrototype` var IteratorPrototype$1 = iteratorsCore.IteratorPrototype; +// 创建一个迭代器构造函数,用于构建迭代器对象 var createIteratorConstructor = function (IteratorConstructor, NAME, next) { - var TO_STRING_TAG = NAME + ' Iterator'; - IteratorConstructor.prototype = objectCreate(IteratorPrototype$1, { next: createPropertyDescriptor(1, next) }); - setToStringTag(IteratorConstructor, TO_STRING_TAG, false); - return IteratorConstructor; + var TO_STRING_TAG = NAME + ' Iterator'; + // 设置迭代器的原型,并为其添加 `next` 方法 + IteratorConstructor.prototype = objectCreate(IteratorPrototype$1, { next: createPropertyDescriptor(1, next) }); + // 为迭代器设置 `toStringTag` 属性 + setToStringTag(IteratorConstructor, TO_STRING_TAG, false); + return IteratorConstructor; // 返回构造函数 }; +// 检查并确保可以将对象作为原型设置 var aPossiblePrototype = function (it) { - if (!isObject(it) && it !== null) { - throw TypeError("Can't set " + String(it) + ' as a prototype'); - } return it; + // 如果传入的对象不是一个有效的对象(或者是 `null`),则抛出错误 + if (!isObject(it) && it !== null) { + throw TypeError("Can't set " + String(it) + ' as a prototype'); + } + return it; // 返回对象本身 }; + // `Object.setPrototypeOf` method // https://tc39.github.io/ecma262/#sec-object.setprototypeof // Works with __proto__ only. Old v8 can't work with null proto objects. /* eslint-disable no-proto */ + // 兼容性处理:如果 `Object.setPrototypeOf` 不可用,则使用 `__proto__` 来设置对象原型 var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { - var CORRECT_SETTER = false; - var test = {}; - var setter; - try { - setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set; - setter.call(test, []); - CORRECT_SETTER = test instanceof Array; - } catch (error) { /* empty */ } - return function setPrototypeOf(O, proto) { - anObject(O); - aPossiblePrototype(proto); - if (CORRECT_SETTER) setter.call(O, proto); - else O.__proto__ = proto; - return O; - }; + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // 尝试获取原型的 setter,并验证它是否正确设置对象的原型 + setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set; + setter.call(test, []); // 设置对象的原型为数组 + CORRECT_SETTER = test instanceof Array; // 如果对象原型为数组,则认为 setter 正确 + } catch (error) { /* empty */ } + // 如果 setter 正确,则使用 setter 来设置原型,否则使用 `__proto__` + return function setPrototypeOf(O, proto) { + anObject(O); // 确保第一个参数是对象 + aPossiblePrototype(proto); // 确保 `proto` 是有效的原型 + if (CORRECT_SETTER) setter.call(O, proto); // 使用 setter 设置原型 + else O.__proto__ = proto; // 否则使用 `__proto__` + return O; + }; }() : undefined); +// 从 `iteratorsCore` 获取 `IteratorPrototype` 和 `BUGGY_SAFARI_ITERATORS` var IteratorPrototype$2 = iteratorsCore.IteratorPrototype; var BUGGY_SAFARI_ITERATORS$1 = iteratorsCore.BUGGY_SAFARI_ITERATORS; var ITERATOR$1 = wellKnownSymbol('iterator'); @@ -1433,73 +1728,86 @@ var VALUES = 'values'; var ENTRIES = 'entries'; +// 定义一个返回当前对象的函数 var returnThis$1 = function () { return this; }; +// 定义一个方法 `defineIterator`,用于构建一个迭代器 +// 该方法为迭代对象添加 `@@iterator`(或其他自定义的迭代器方法,如 `keys`, `values`, `entries`) +// 迭代器支持遍历对象的不同部分(键、值或条目),并且支持一些浏览器的兼容性修复 var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) { - createIteratorConstructor(IteratorConstructor, NAME, next); - - var getIterationMethod = function (KIND) { - if (KIND === DEFAULT && defaultIterator) return defaultIterator; - if (!BUGGY_SAFARI_ITERATORS$1 && KIND in IterablePrototype) return IterablePrototype[KIND]; - switch (KIND) { - case KEYS: return function keys() { return new IteratorConstructor(this, KIND); }; - case VALUES: return function values() { return new IteratorConstructor(this, KIND); }; - case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); }; - } return function () { return new IteratorConstructor(this); }; - }; - - var TO_STRING_TAG = NAME + ' Iterator'; - var INCORRECT_VALUES_NAME = false; - var IterablePrototype = Iterable.prototype; - var nativeIterator = IterablePrototype[ITERATOR$1] - || IterablePrototype['@@iterator'] - || DEFAULT && IterablePrototype[DEFAULT]; - var defaultIterator = !BUGGY_SAFARI_ITERATORS$1 && nativeIterator || getIterationMethod(DEFAULT); - var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator; - var CurrentIteratorPrototype, methods, KEY; - - // fix native - if (anyNativeIterator) { - CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable())); - if (IteratorPrototype$2 !== Object.prototype && CurrentIteratorPrototype.next) { - if ( objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) { - if (objectSetPrototypeOf) { - objectSetPrototypeOf(CurrentIteratorPrototype, IteratorPrototype$2); - } else if (typeof CurrentIteratorPrototype[ITERATOR$1] != 'function') { - createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR$1, returnThis$1); - } - } - // Set @@toStringTag to native iterators - setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true); - } - } - - // fix Array#{values, @@iterator}.name in V8 / FF - if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) { - INCORRECT_VALUES_NAME = true; - defaultIterator = function values() { return nativeIterator.call(this); }; - } - - // define iterator - if ( IterablePrototype[ITERATOR$1] !== defaultIterator) { - createNonEnumerableProperty(IterablePrototype, ITERATOR$1, defaultIterator); - } - - // export additional methods - if (DEFAULT) { - methods = { - values: getIterationMethod(VALUES), - keys: IS_SET ? defaultIterator : getIterationMethod(KEYS), - entries: getIterationMethod(ENTRIES) - }; - if (FORCED) for (KEY in methods) { - if (BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) { - redefine(IterablePrototype, KEY, methods[KEY]); - } - } else _export({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME }, methods); - } - - return methods; + // 创建迭代器构造函数,并传入相关参数 + createIteratorConstructor(IteratorConstructor, NAME, next); + + // 获取相应的迭代方法:`keys`, `values`, `entries`,如果是默认方法,则使用 `defaultIterator` + var getIterationMethod = function (KIND) { + if (KIND === DEFAULT && defaultIterator) return defaultIterator; + if (!BUGGY_SAFARI_ITERATORS$1 && KIND in IterablePrototype) return IterablePrototype[KIND]; // 如果没有 Safari bug 且已有该方法,则直接返回 + // 根据不同的迭代类型,返回相应的迭代方法 + switch (KIND) { + case KEYS: return function keys() { return new IteratorConstructor(this, KIND); }; + case VALUES: return function values() { return new IteratorConstructor(this, KIND); }; + case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); }; + } + return function () { return new IteratorConstructor(this); }; // 默认返回构造函数 + }; + + var TO_STRING_TAG = NAME + ' Iterator'; // 迭代器的 `toStringTag` + var INCORRECT_VALUES_NAME = false; // 用于标记是否有不正确的 `values` 名称 + var IterablePrototype = Iterable.prototype; // 获取可迭代对象的原型 + var nativeIterator = IterablePrototype[ITERATOR$1] + || IterablePrototype['@@iterator'] // 优先选择 `@@iterator` 或原生迭代器 + || DEFAULT && IterablePrototype[DEFAULT]; // 如果有默认方法,则使用默认方法 + var defaultIterator = !BUGGY_SAFARI_ITERATORS$1 && nativeIterator || getIterationMethod(DEFAULT); // 选择合适的迭代方法 + var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator; // 针对不同类型(如数组)选择迭代方法 + var CurrentIteratorPrototype, methods, KEY; + + // 修复原生迭代器 + if (anyNativeIterator) { + // 获取原生迭代器的原型 + CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable())); + if (IteratorPrototype$2 !== Object.prototype && CurrentIteratorPrototype.next) { + // 如果原型链不匹配,并且 `next` 方法存在,则修正原型链 + if (objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) { + if (objectSetPrototypeOf) { + objectSetPrototypeOf(CurrentIteratorPrototype, IteratorPrototype$2); // 设置原型 + } else if (typeof CurrentIteratorPrototype[ITERATOR$1] != 'function') { + createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR$1, returnThis$1); // 创建 `@@iterator` 方法 + } + } + // 为原生迭代器的原型添加 `toStringTag` + setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true); + } + } + + // 修复数组的 `values` 方法名称(在 V8 和 Firefox 中可能不正确) + if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) { + INCORRECT_VALUES_NAME = true; // 标记名称不正确 + // 修复 `values` 方法名称 + defaultIterator = function values() { return nativeIterator.call(this); }; + } + + + + // define iterator + if ( IterablePrototype[ITERATOR$1] !== defaultIterator) { + createNonEnumerableProperty(IterablePrototype, ITERATOR$1, defaultIterator); + } + + // export additional methods + if (DEFAULT) { + methods = { + values: getIterationMethod(VALUES), + keys: IS_SET ? defaultIterator : getIterationMethod(KEYS), + entries: getIterationMethod(ENTRIES) + }; + if (FORCED) for (KEY in methods) { + if (BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) { + redefine(IterablePrototype, KEY, methods[KEY]); + } + } else _export({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME }, methods); + } + + return methods; }; var ARRAY_ITERATOR = 'Array Iterator'; @@ -1516,692 +1824,741 @@ // https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator // `CreateArrayIterator` internal method // https://tc39.github.io/ecma262/#sec-createarrayiterator + // 定义一个数组迭代器,支持 keys、values、entries 等方法 var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind) { - setInternalState$1(this, { - type: ARRAY_ITERATOR, - target: toIndexedObject(iterated), // target - index: 0, // next index - kind: kind // kind - }); - // `%ArrayIteratorPrototype%.next` method - // https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next + // 初始化迭代器的内部状态 + setInternalState$1(this, { + type: ARRAY_ITERATOR, + target: toIndexedObject(iterated), // 设置目标为迭代对象 + index: 0, // 起始索引 + kind: kind // 迭代类型:keys、values 或 entries + }); }, function () { - var state = getInternalState$1(this); - var target = state.target; - var kind = state.kind; - var index = state.index++; - if (!target || index >= target.length) { - state.target = undefined; - return { value: undefined, done: true }; - } - if (kind == 'keys') return { value: index, done: false }; - if (kind == 'values') return { value: target[index], done: false }; - return { value: [index, target[index]], done: false }; - }, 'values'); - - // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables + // 迭代器的 `next` 方法,返回当前索引的元素 + var state = getInternalState$1(this); + var target = state.target; + var kind = state.kind; + var index = state.index++; // 增加索引 + if (!target || index >= target.length) { + state.target = undefined; // 如果已到末尾,返回结束信号 + return { value: undefined, done: true }; + } + // 根据 kind 返回不同类型的迭代结果 + if (kind == 'keys') return { value: index, done: false }; // 返回索引 + if (kind == 'values') return { value: target[index], done: false }; // 返回值 + return { value: [index, target[index]], done: false }; // 返回键值对 + }, 'values'); // 默认迭代返回值 + +// `@@unscopables` 标记,确保这些迭代器方法不会被 with 语句影响 addToUnscopables('keys'); addToUnscopables('values'); addToUnscopables('entries'); - var nativeJoin = [].join; +// `Array.prototype.join` 方法的实现 + var nativeJoin = [].join; // 获取原生的 `join` 方法 - var ES3_STRINGS = indexedObject != Object; +// 检查 ES3 字符串和 `join` 方法的兼容性 + var ES3_STRINGS = indexedObject != Object; // 判断 `indexedObject` 是否为 Object var SLOPPY_METHOD$1 = sloppyArrayMethod('join', ','); - // `Array.prototype.join` method - // https://tc39.github.io/ecma262/#sec-array.prototype.join +// 如果存在兼容性问题,强制使用 `join` 方法 _export({ target: 'Array', proto: true, forced: ES3_STRINGS || SLOPPY_METHOD$1 }, { - join: function join(separator) { - return nativeJoin.call(toIndexedObject(this), separator === undefined ? ',' : separator); - } + join: function join(separator) { + return nativeJoin.call(toIndexedObject(this), separator === undefined ? ',' : separator); // 使用原生 `join` + } }); +// `Array.prototype.map` 方法的实现 var $map = arrayIteration.map; - - +// 检查 `map` 方法的兼容性,特别是 `@@species` 和 `toLength` 支持 var HAS_SPECIES_SUPPORT$1 = arrayMethodHasSpeciesSupport('map'); - // FF49- issue var USES_TO_LENGTH$1 = HAS_SPECIES_SUPPORT$1 && !fails(function () { - [].map.call({ length: -1, 0: 1 }, function (it) { throw it; }); + [].map.call({ length: -1, 0: 1 }, function (it) { throw it; }); // 测试数组的 `map` 方法 }); - // `Array.prototype.map` method - // https://tc39.github.io/ecma262/#sec-array.prototype.map - // with adding support of @@species +// 如果兼容性不支持,则强制使用自定义的 `map` 方法 _export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT$1 || !USES_TO_LENGTH$1 }, { - map: function map(callbackfn /* , thisArg */) { - return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } + map: function map(callbackfn /* , thisArg */) { + return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); // 使用 `map` 方法 + } }); +// `Array.prototype.reverse` 方法的实现 var nativeReverse = [].reverse; - var test = [1, 2]; + var test = [1, 2]; // 测试用的数组 - // `Array.prototype.reverse` method - // https://tc39.github.io/ecma262/#sec-array.prototype.reverse - // fix for Safari 12.0 bug - // https://bugs.webkit.org/show_bug.cgi?id=188794 +// 如果浏览器存在 bug,修复数组的 `reverse` 方法 _export({ target: 'Array', proto: true, forced: String(test) === String(test.reverse()) }, { - reverse: function reverse() { - // eslint-disable-next-line no-self-assign - if (isArray(this)) this.length = this.length; - return nativeReverse.call(this); - } + reverse: function reverse() { + // 修复 Safari 12.0 的 bug + if (isArray(this)) this.length = this.length; // 修复数组的长度属性 + return nativeReverse.call(this); // 调用原生 `reverse` + } }); - var SPECIES$2 = wellKnownSymbol('species'); +// `Array.prototype.slice` 方法的实现 + var SPECIES$2 = wellKnownSymbol('species'); // `species` 符号 var nativeSlice = [].slice; var max$1 = Math.max; - // `Array.prototype.slice` method - // https://tc39.github.io/ecma262/#sec-array.prototype.slice - // fallback for not array-like ES3 strings and DOM objects +// 如果不支持 `slice` 方法的 `species` 属性,则强制使用自定义实现 _export({ target: 'Array', proto: true, forced: !arrayMethodHasSpeciesSupport('slice') }, { - slice: function slice(start, end) { - var O = toIndexedObject(this); - var length = toLength(O.length); - var k = toAbsoluteIndex(start, length); - var fin = toAbsoluteIndex(end === undefined ? length : end, length); - // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible - var Constructor, result, n; - if (isArray(O)) { - Constructor = O.constructor; - // cross-realm fallback - if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) { - Constructor = undefined; - } else if (isObject(Constructor)) { - Constructor = Constructor[SPECIES$2]; - if (Constructor === null) Constructor = undefined; - } - if (Constructor === Array || Constructor === undefined) { - return nativeSlice.call(O, k, fin); - } - } - result = new (Constructor === undefined ? Array : Constructor)(max$1(fin - k, 0)); - for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]); - result.length = n; - return result; - } + slice: function slice(start, end) { + var O = toIndexedObject(this); // 将 `this` 转换为索引对象 + var length = toLength(O.length); // 获取对象的长度 + var k = toAbsoluteIndex(start, length); // 计算起始索引 + var fin = toAbsoluteIndex(end === undefined ? length : end, length); // 计算结束索引 + var Constructor, result, n; + + // 检查对象是否为数组,如果是则使用原生的 `slice` 方法 + if (isArray(O)) { + Constructor = O.constructor; + // 如果构造函数不是数组或 `Array`,则使用 `Array` 作为默认构造函数 + if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) { + Constructor = undefined; + } else if (isObject(Constructor)) { + Constructor = Constructor[SPECIES$2]; // 获取 `species` 属性 + if (Constructor === null) Constructor = undefined; + } + if (Constructor === Array || Constructor === undefined) { + return nativeSlice.call(O, k, fin); // 使用原生 `slice` 方法 + } + } + + // 否则创建新的数组并手动填充 + result = new (Constructor === undefined ? Array : Constructor)(max$1(fin - k, 0)); // 创建新数组 + for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]); // 手动复制元素 + result.length = n; // 设置数组长度 + return result; // 返回新数组 + } }); +// 处理 `Array.prototype.sort` 方法的兼容性 var test$1 = []; - var nativeSort = test$1.sort; + var nativeSort = test$1.sort; // 获取原生的 `sort` 方法 - // IE8- +// 检查 `sort` 方法是否能处理 `undefined` 和 `null` var FAILS_ON_UNDEFINED = fails(function () { - test$1.sort(undefined); + test$1.sort(undefined); // 检查 undefined 是否有效 }); - // V8 bug var FAILS_ON_NULL = fails(function () { - test$1.sort(null); + test$1.sort(null); // 检查 null 是否有效 }); - // Old WebKit + +// 检查旧版 WebKit(Safari)浏览器中 `sort` 方法的问题 var SLOPPY_METHOD$2 = sloppyArrayMethod('sort'); +// 如果 `sort` 方法存在已知的 bug,则强制使用兼容性修复 var FORCED$1 = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || SLOPPY_METHOD$2; - // `Array.prototype.sort` method - // https://tc39.github.io/ecma262/#sec-array.prototype.sort +// `Array.prototype.sort` 方法的修复实现 _export({ target: 'Array', proto: true, forced: FORCED$1 }, { - sort: function sort(comparefn) { - return comparefn === undefined - ? nativeSort.call(toObject(this)) - : nativeSort.call(toObject(this), aFunction$1(comparefn)); - } + sort: function sort(comparefn) { + // 如果没有提供比较函数,使用原生的 `sort` + return comparefn === undefined + ? nativeSort.call(toObject(this)) + // 否则调用提供的比较函数 + : nativeSort.call(toObject(this), aFunction$1(comparefn)); + } }); +// 处理 `Array.prototype.splice` 方法的兼容性 var max$2 = Math.max; var min$2 = Math.min; var MAX_SAFE_INTEGER$1 = 0x1FFFFFFFFFFFFF; var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded'; - // `Array.prototype.splice` method - // https://tc39.github.io/ecma262/#sec-array.prototype.splice - // with adding support of @@species +// `Array.prototype.splice` 方法的修复实现 _export({ target: 'Array', proto: true, forced: !arrayMethodHasSpeciesSupport('splice') }, { - splice: function splice(start, deleteCount /* , ...items */) { - var O = toObject(this); - var len = toLength(O.length); - var actualStart = toAbsoluteIndex(start, len); - var argumentsLength = arguments.length; - var insertCount, actualDeleteCount, A, k, from, to; - if (argumentsLength === 0) { - insertCount = actualDeleteCount = 0; - } else if (argumentsLength === 1) { - insertCount = 0; - actualDeleteCount = len - actualStart; - } else { - insertCount = argumentsLength - 2; - actualDeleteCount = min$2(max$2(toInteger(deleteCount), 0), len - actualStart); - } - if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER$1) { - throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED); - } - A = arraySpeciesCreate(O, actualDeleteCount); - for (k = 0; k < actualDeleteCount; k++) { - from = actualStart + k; - if (from in O) createProperty(A, k, O[from]); - } - A.length = actualDeleteCount; - if (insertCount < actualDeleteCount) { - for (k = actualStart; k < len - actualDeleteCount; k++) { - from = k + actualDeleteCount; - to = k + insertCount; - if (from in O) O[to] = O[from]; - else delete O[to]; - } - for (k = len; k > len - actualDeleteCount + insertCount; k--) delete O[k - 1]; - } else if (insertCount > actualDeleteCount) { - for (k = len - actualDeleteCount; k > actualStart; k--) { - from = k + actualDeleteCount - 1; - to = k + insertCount - 1; - if (from in O) O[to] = O[from]; - else delete O[to]; - } - } - for (k = 0; k < insertCount; k++) { - O[k + actualStart] = arguments[k + 2]; - } - O.length = len - actualDeleteCount + insertCount; - return A; - } + splice: function splice(start, deleteCount /* , ...items */) { + var O = toObject(this); + var len = toLength(O.length); // 获取数组长度 + var actualStart = toAbsoluteIndex(start, len); // 计算实际的起始索引 + var argumentsLength = arguments.length; + var insertCount, actualDeleteCount, A, k, from, to; + + // 计算插入项的数量和删除项的数量 + if (argumentsLength === 0) { + insertCount = actualDeleteCount = 0; + } else if (argumentsLength === 1) { + insertCount = 0; + actualDeleteCount = len - actualStart; + } else { + insertCount = argumentsLength - 2; + actualDeleteCount = min$2(max$2(toInteger(deleteCount), 0), len - actualStart); + } + + // 检查操作是否超过最大安全整数长度 + if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER$1) { + throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED); + } + + // 创建一个新数组用于存放删除的元素 + A = arraySpeciesCreate(O, actualDeleteCount); + for (k = 0; k < actualDeleteCount; k++) { + from = actualStart + k; + if (from in O) createProperty(A, k, O[from]); // 复制删除的元素 + } + A.length = actualDeleteCount; + + // 如果删除的元素比插入的元素多,移动剩余元素 + if (insertCount < actualDeleteCount) { + for (k = actualStart; k < len - actualDeleteCount; k++) { + from = k + actualDeleteCount; + to = k + insertCount; + if (from in O) O[to] = O[from]; + else delete O[to]; + } + for (k = len; k > len - actualDeleteCount + insertCount; k--) delete O[k - 1]; + } + // 如果插入的元素比删除的元素多,移动剩余元素 + else if (insertCount > actualDeleteCount) { + for (k = len - actualDeleteCount; k > actualStart; k--) { + from = k + actualDeleteCount - 1; + to = k + insertCount - 1; + if (from in O) O[to] = O[from]; + else delete O[to]; + } + } + + // 将新的元素插入到数组中 + for (k = 0; k < insertCount; k++) { + O[k + actualStart] = arguments[k + 2]; + } + + // 更新数组的长度 + O.length = len - actualDeleteCount + insertCount; + return A; // 返回删除的元素 + } }); - // makes subclassing work correct for wrapped built-ins +// 用于修复和继承子类行为的辅助函数 var inheritIfRequired = function ($this, dummy, Wrapper) { - var NewTarget, NewTargetPrototype; - if ( - // it can work only with native `setPrototypeOf` - objectSetPrototypeOf && - // we haven't completely correct pre-ES6 way for getting `new.target`, so use this - typeof (NewTarget = dummy.constructor) == 'function' && - NewTarget !== Wrapper && - isObject(NewTargetPrototype = NewTarget.prototype) && - NewTargetPrototype !== Wrapper.prototype - ) objectSetPrototypeOf($this, NewTargetPrototype); - return $this; + var NewTarget, NewTargetPrototype; + if ( + // 使用原生的 `setPrototypeOf` 方法进行继承 + objectSetPrototypeOf && + // 检查是否可以正确获取 `new.target` + typeof (NewTarget = dummy.constructor) == 'function' && + NewTarget !== Wrapper && + isObject(NewTargetPrototype = NewTarget.prototype) && + NewTargetPrototype !== Wrapper.prototype + ) objectSetPrototypeOf($this, NewTargetPrototype); // 将子类的原型设置为目标原型 + return $this; }; - // a string of all valid unicode whitespaces - // eslint-disable-next-line max-len +// 定义一个包含所有有效 Unicode 空白字符的字符串 var whitespaces = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'; +// 用正则表达式去掉字符串两端的空白字符 var whitespace = '[' + whitespaces + ']'; var ltrim = RegExp('^' + whitespace + whitespace + '*'); var rtrim = RegExp(whitespace + whitespace + '*$'); - // `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` methods implementation +// `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` 方法的实现 var createMethod$2 = function (TYPE) { - return function ($this) { - var string = String(requireObjectCoercible($this)); - if (TYPE & 1) string = string.replace(ltrim, ''); - if (TYPE & 2) string = string.replace(rtrim, ''); - return string; - }; + return function ($this) { + var string = String(requireObjectCoercible($this)); // 强制转换为字符串 + if (TYPE & 1) string = string.replace(ltrim, ''); // 去掉开头的空白字符 + if (TYPE & 2) string = string.replace(rtrim, ''); // 去掉结尾的空白字符 + return string; // 返回处理后的字符串 + }; }; +// `stringTrim` 对象包含了修复后的 `trim` 方法 var stringTrim = { - // `String.prototype.{ trimLeft, trimStart }` methods - // https://tc39.github.io/ecma262/#sec-string.prototype.trimstart - start: createMethod$2(1), - // `String.prototype.{ trimRight, trimEnd }` methods - // https://tc39.github.io/ecma262/#sec-string.prototype.trimend - end: createMethod$2(2), - // `String.prototype.trim` method - // https://tc39.github.io/ecma262/#sec-string.prototype.trim - trim: createMethod$2(3) + // `String.prototype.{ trimLeft, trimStart }` 方法 + start: createMethod$2(1), + // `String.prototype.{ trimRight, trimEnd }` 方法 + end: createMethod$2(2), + // `String.prototype.trim` 方法 + trim: createMethod$2(3) }; +// 获取 `Object` 和 `String` 的相关方法 var getOwnPropertyNames = objectGetOwnPropertyNames.f; var getOwnPropertyDescriptor$2 = objectGetOwnPropertyDescriptor.f; var defineProperty$3 = objectDefineProperty.f; var trim = stringTrim.trim; +// 定义 `Number` 构造函数相关的变量 var NUMBER = 'Number'; - var NativeNumber = global_1[NUMBER]; + var NativeNumber = global_1[NUMBER]; // 获取全局的原生 `Number` var NumberPrototype = NativeNumber.prototype; - // Opera ~12 has broken Object#toString +// Opera 12 和更早版本存在 `Object#toString` 的问题 var BROKEN_CLASSOF = classofRaw(objectCreate(NumberPrototype)) == NUMBER; - // `ToNumber` abstract operation - // https://tc39.github.io/ecma262/#sec-tonumber +// `ToNumber` 抽象操作:将传入的参数转换为数字 var toNumber = function (argument) { - var it = toPrimitive(argument, false); - var first, third, radix, maxCode, digits, length, index, code; - if (typeof it == 'string' && it.length > 2) { - it = trim(it); - first = it.charCodeAt(0); - if (first === 43 || first === 45) { - third = it.charCodeAt(2); - if (third === 88 || third === 120) return NaN; // Number('+0x1') should be NaN, old V8 fix - } else if (first === 48) { - switch (it.charCodeAt(1)) { - case 66: case 98: radix = 2; maxCode = 49; break; // fast equal of /^0b[01]+$/i - case 79: case 111: radix = 8; maxCode = 55; break; // fast equal of /^0o[0-7]+$/i - default: return +it; - } - digits = it.slice(2); - length = digits.length; - for (index = 0; index < length; index++) { - code = digits.charCodeAt(index); - // parseInt parses a string to a first unavailable symbol - // but ToNumber should return NaN if a string contains unavailable symbols - if (code < 48 || code > maxCode) return NaN; - } return parseInt(digits, radix); - } - } return +it; + var it = toPrimitive(argument, false); // 获取参数的原始值 + var first, third, radix, maxCode, digits, length, index, code; + if (typeof it == 'string' && it.length > 2) { + it = trim(it); // 去掉字符串的前后空格 + first = it.charCodeAt(0); + if (first === 43 || first === 45) { // 如果是正负号 + third = it.charCodeAt(2); + if (third === 88 || third === 120) return NaN; // 十六进制数字应该返回 NaN + } else if (first === 48) { // 如果是以0开头的数字 + switch (it.charCodeAt(1)) { + case 66: case 98: radix = 2; maxCode = 49; break; // 二进制 + case 79: case 111: radix = 8; maxCode = 55; break; // 八进制 + default: return +it; // 其他情况转换为数字 + } + digits = it.slice(2); // 去掉前缀部分 + length = digits.length; + for (index = 0; index < length; index++) { + code = digits.charCodeAt(index); + // 如果数字中含有非法字符,返回 NaN + if (code < 48 || code > maxCode) return NaN; + } + return parseInt(digits, radix); // 根据进制解析数字 + } + } + return +it; // 返回数字 }; - // `Number` constructor - // https://tc39.github.io/ecma262/#sec-number-constructor +// 检查 `Number` 构造函数的兼容性 if (isForced_1(NUMBER, !NativeNumber(' 0o1') || !NativeNumber('0b1') || NativeNumber('+0x1'))) { - var NumberWrapper = function Number(value) { - var it = arguments.length < 1 ? 0 : value; - var dummy = this; - return dummy instanceof NumberWrapper - // check on 1..constructor(foo) case - && (BROKEN_CLASSOF ? fails(function () { NumberPrototype.valueOf.call(dummy); }) : classofRaw(dummy) != NUMBER) - ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper) : toNumber(it); - }; - for (var keys$1 = descriptors ? getOwnPropertyNames(NativeNumber) : ( - // ES3: - 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' + - // ES2015 (in case, if modules with ES2015 Number statics required before): - 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' + - 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger' - ).split(','), j = 0, key; keys$1.length > j; j++) { - if (has(NativeNumber, key = keys$1[j]) && !has(NumberWrapper, key)) { - defineProperty$3(NumberWrapper, key, getOwnPropertyDescriptor$2(NativeNumber, key)); - } - } - NumberWrapper.prototype = NumberPrototype; - NumberPrototype.constructor = NumberWrapper; - redefine(global_1, NUMBER, NumberWrapper); + var NumberWrapper = function Number(value) { + var it = arguments.length < 1 ? 0 : value; + var dummy = this; + return dummy instanceof NumberWrapper + // 检查构造函数中的问题 + && (BROKEN_CLASSOF ? fails(function () { NumberPrototype.valueOf.call(dummy); }) : classofRaw(dummy) != NUMBER) + ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper) : toNumber(it); + }; + + // 复制原生 `Number` 的属性到 `NumberWrapper` + for (var keys$1 = descriptors ? getOwnPropertyNames(NativeNumber) : ( + 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' + + 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' + + 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger' + ).split(','), j = 0, key; keys$1.length > j; j++) { + if (has(NativeNumber, key = keys$1[j]) && !has(NumberWrapper, key)) { + defineProperty$3(NumberWrapper, key, getOwnPropertyDescriptor$2(NativeNumber, key)); + } + } + NumberWrapper.prototype = NumberPrototype; + NumberPrototype.constructor = NumberWrapper; + redefine(global_1, NUMBER, NumberWrapper); } +// 检查和修复 `Object.assign` 方法的兼容性 var nativeAssign = Object.assign; var defineProperty$4 = Object.defineProperty; - // `Object.assign` method - // https://tc39.github.io/ecma262/#sec-object.assign var objectAssign = !nativeAssign || fails(function () { - // should have correct order of operations (Edge bug) - if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$4({}, 'a', { - enumerable: true, - get: function () { - defineProperty$4(this, 'b', { - value: 3, - enumerable: false - }); - } - }), { b: 2 })).b !== 1) return true; - // should work with symbols and should have deterministic property order (V8 bug) - var A = {}; - var B = {}; - // eslint-disable-next-line no-undef - var symbol = Symbol(); - var alphabet = 'abcdefghijklmnopqrst'; - A[symbol] = 7; - alphabet.split('').forEach(function (chr) { B[chr] = chr; }); - return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet; + // 检查 Edge 浏览器的 bug,确保正确的操作顺序 + if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$4({}, 'a', { + enumerable: true, + get: function () { + defineProperty$4(this, 'b', { + value: 3, + enumerable: false + }); + } + }), { b: 2 })).b !== 1) return true; + // 检查 V8 的 bug,确保与符号兼容,并且有确定的属性顺序 + var A = {}; + var B = {}; + var symbol = Symbol(); + var alphabet = 'abcdefghijklmnopqrst'; + A[symbol] = 7; + alphabet.split('').forEach(function (chr) { B[chr] = chr; }); + return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet; }) ? function assign(target, source) { // eslint-disable-line no-unused-vars - var T = toObject(target); - var argumentsLength = arguments.length; - var index = 1; - var getOwnPropertySymbols = objectGetOwnPropertySymbols.f; - var propertyIsEnumerable = objectPropertyIsEnumerable.f; - while (argumentsLength > index) { - var S = indexedObject(arguments[index++]); - var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S); - var length = keys.length; - var j = 0; - var key; - while (length > j) { - key = keys[j++]; - if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key]; - } - } return T; + var T = toObject(target); // 确保目标是对象 + var argumentsLength = arguments.length; + var index = 1; + var getOwnPropertySymbols = objectGetOwnPropertySymbols.f; + var propertyIsEnumerable = objectPropertyIsEnumerable.f; + while (argumentsLength > index) { + var S = indexedObject(arguments[index++]); + var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S); + var length = keys.length; + var j = 0; + var key; + while (length > j) { + key = keys[j++]; + if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key]; + } + } + return T; // 返回合并后的对象 } : nativeAssign; - // `Object.assign` method - // https://tc39.github.io/ecma262/#sec-object.assign +// `Object.assign` 方法的修复实现 _export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, { - assign: objectAssign + assign: objectAssign }); +// `Object.{ entries, values }` 方法的实现 var propertyIsEnumerable = objectPropertyIsEnumerable.f; - // `Object.{ entries, values }` methods implementation var createMethod$3 = function (TO_ENTRIES) { - return function (it) { - var O = toIndexedObject(it); - var keys = objectKeys(O); - var length = keys.length; - var i = 0; - var result = []; - var key; - while (length > i) { - key = keys[i++]; - if (!descriptors || propertyIsEnumerable.call(O, key)) { - result.push(TO_ENTRIES ? [key, O[key]] : O[key]); - } - } - return result; - }; + return function (it) { + var O = toIndexedObject(it); // 转换为索引对象 + var keys = objectKeys(O); // 获取对象的键 + var length = keys.length; + var i = 0; + var result = []; + var key; + while (length > i) { + key = keys[i++]; // 获取每个键 + if (!descriptors || propertyIsEnumerable.call(O, key)) { + result.push(TO_ENTRIES ? [key, O[key]] : O[key]); // 如果是 `entries`,则返回键值对,否则返回值 + } + } + return result; // 返回结果 + }; }; - var objectToArray = { - // `Object.entries` method - // https://tc39.github.io/ecma262/#sec-object.entries - entries: createMethod$3(true), - // `Object.values` method - // https://tc39.github.io/ecma262/#sec-object.values - values: createMethod$3(false) + // `Object.entries` 方法:返回对象自身可枚举属性的键值对数组 + // https://tc39.github.io/ecma262/#sec-object.entries + entries: createMethod$3(true), + + // `Object.values` 方法:返回对象自身可枚举属性的值数组 + // https://tc39.github.io/ecma262/#sec-object.values + values: createMethod$3(false) }; +// 引入 `Object.entries` 方法 var $entries = objectToArray.entries; - // `Object.entries` method - // https://tc39.github.io/ecma262/#sec-object.entries +// 定义 `Object.entries` 方法 +// https://tc39.github.io/ecma262/#sec-object.entries _export({ target: 'Object', stat: true }, { - entries: function entries(O) { - return $entries(O); - } + entries: function entries(O) { + return $entries(O); // 调用 `createMethod$3` 生成的 `entries` 方法 + } }); var TO_STRING_TAG$1 = wellKnownSymbol('toStringTag'); var test$2 = {}; +// 设置 `toStringTag` 属性用于检测 test$2[TO_STRING_TAG$1] = 'z'; +// 检测 `toStringTag` 的支持情况 var toStringTagSupport = String(test$2) === '[object z]'; +// 继续定义 `toStringTag` 用于类型检测 var TO_STRING_TAG$2 = wellKnownSymbol('toStringTag'); - // ES3 wrong here + +// ES3 错误的实现:`Arguments` 类型检测 var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments'; - // fallback for IE11 Script Access Denied error +// `tryGet` 函数:捕获访问属性时可能的错误,避免崩溃 var tryGet = function (it, key) { - try { - return it[key]; - } catch (error) { /* empty */ } + try { + return it[key]; + } catch (error) { /* 空处理 */ } }; - // getting tag from ES6+ `Object.prototype.toString` +// 根据 `toStringTag` 获取对象类型 var classof = toStringTagSupport ? classofRaw : function (it) { - var O, tag, result; - return it === undefined ? 'Undefined' : it === null ? 'Null' - // @@toStringTag case - : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG$2)) == 'string' ? tag - // builtinTag case - : CORRECT_ARGUMENTS ? classofRaw(O) - // ES3 arguments fallback - : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result; + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag 类型 + : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG$2)) == 'string' ? tag + // 原生类型 + : CORRECT_ARGUMENTS ? classofRaw(O) + // 处理 ES3 中的 `arguments` 对象 + : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result; }; - // `Object.prototype.toString` method implementation - // https://tc39.github.io/ecma262/#sec-object.prototype.tostring +// `Object.prototype.toString` 方法实现 +// https://tc39.github.io/ecma262/#sec-object.prototype.tostring var objectToString = toStringTagSupport ? {}.toString : function toString() { - return '[object ' + classof(this) + ']'; + return '[object ' + classof(this) + ']'; // 返回带有类型标签的字符串 }; - // `Object.prototype.toString` method - // https://tc39.github.io/ecma262/#sec-object.prototype.tostring +// 在不支持 `toStringTag` 的环境中重新定义 `Object.prototype.toString` if (!toStringTagSupport) { - redefine(Object.prototype, 'toString', objectToString, { unsafe: true }); + redefine(Object.prototype, 'toString', objectToString, { unsafe: true }); } var trim$1 = stringTrim.trim; - +// 原生 `parseFloat` 方法 var nativeParseFloat = global_1.parseFloat; + +// 检查 `parseFloat` 的兼容性,处理某些浏览器中的特殊情况 var FORCED$2 = 1 / nativeParseFloat(whitespaces + '-0') !== -Infinity; - // `parseFloat` method - // https://tc39.github.io/ecma262/#sec-parsefloat-string +// `parseFloat` 方法实现 +// https://tc39.github.io/ecma262/#sec-parsefloat-string var _parseFloat = FORCED$2 ? function parseFloat(string) { - var trimmedString = trim$1(String(string)); - var result = nativeParseFloat(trimmedString); - return result === 0 && trimmedString.charAt(0) == '-' ? -0 : result; + var trimmedString = trim$1(String(string)); // 修剪字符串 + var result = nativeParseFloat(trimmedString); // 调用原生 `parseFloat` + return result === 0 && trimmedString.charAt(0) == '-' ? -0 : result; // 修复 -0 的问题 } : nativeParseFloat; - // `parseFloat` method - // https://tc39.github.io/ecma262/#sec-parsefloat-string +// 导出 `parseFloat` 方法,确保其在当前环境中是正确的 _export({ global: true, forced: parseFloat != _parseFloat }, { - parseFloat: _parseFloat + parseFloat: _parseFloat }); var trim$2 = stringTrim.trim; - +// 原生 `parseInt` 方法 var nativeParseInt = global_1.parseInt; - var hex = /^[+-]?0[Xx]/; + var hex = /^[+-]?0[Xx]/; // 检测十六进制数字的正则 + +// 检查 `parseInt` 的兼容性,修复一些特殊情况 var FORCED$3 = nativeParseInt(whitespaces + '08') !== 8 || nativeParseInt(whitespaces + '0x16') !== 22; - // `parseInt` method - // https://tc39.github.io/ecma262/#sec-parseint-string-radix +// `parseInt` 方法实现 +// https://tc39.github.io/ecma262/#sec-parseint-string-radix var _parseInt = FORCED$3 ? function parseInt(string, radix) { - var S = trim$2(String(string)); - return nativeParseInt(S, (radix >>> 0) || (hex.test(S) ? 16 : 10)); + var S = trim$2(String(string)); // 修剪字符串 + return nativeParseInt(S, (radix >>> 0) || (hex.test(S) ? 16 : 10)); // 处理十六进制和其他基数 } : nativeParseInt; - // `parseInt` method - // https://tc39.github.io/ecma262/#sec-parseint-string-radix +// 导出 `parseInt` 方法,确保其在当前环境中是正确的 _export({ global: true, forced: parseInt != _parseInt }, { - parseInt: _parseInt + parseInt: _parseInt }); - // `RegExp.prototype.flags` getter implementation - // https://tc39.github.io/ecma262/#sec-get-regexp.prototype.flags +// `RegExp.prototype.flags` 属性获取器实现 +// https://tc39.github.io/ecma262/#sec-get-regexp.prototype.flags var regexpFlags = function () { - var that = anObject(this); - var result = ''; - if (that.global) result += 'g'; - if (that.ignoreCase) result += 'i'; - if (that.multiline) result += 'm'; - if (that.dotAll) result += 's'; - if (that.unicode) result += 'u'; - if (that.sticky) result += 'y'; - return result; + var that = anObject(this); // 获取 `RegExp` 对象 + var result = ''; + if (that.global) result += 'g'; + if (that.ignoreCase) result += 'i'; + if (that.multiline) result += 'm'; + if (that.dotAll) result += 's'; + if (that.unicode) result += 'u'; + if (that.sticky) result += 'y'; + return result; // 返回所有标志的组合 }; - // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError, - // so we use an intermediate function. +// `RegExp` 构造函数 function RE(s, f) { - return RegExp(s, f); + return RegExp(s, f); // 创建一个新的 `RegExp` 对象 } +// 检查 `y` 标志的支持情况 var UNSUPPORTED_Y = fails(function () { - // babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError - var re = RE('a', 'y'); - re.lastIndex = 2; - return re.exec('abcd') != null; + // 某些环境不支持 `y` 标志,导致代码抛出语法错误 + var re = RE('a', 'y'); + re.lastIndex = 2; + return re.exec('abcd') != null; }); +// 检查 Firefox 中的已知 bug,Bugzilla ID: 773687 +// 该 bug 会导致在使用 `^` 和 `y` 标志时,`lastIndex` 属性更新不正确。 var BROKEN_CARET = fails(function () { - // https://bugzilla.mozilla.org/show_bug.cgi?id=773687 - var re = RE('^r', 'gy'); - re.lastIndex = 2; - return re.exec('str') != null; + // 创建一个正则表达式,使用 `g` 和 `y` 标志 + var re = RE('^r', 'gy'); + re.lastIndex = 2; + // 在字符串 'str' 上执行 `exec`,如果返回值不为 `null`,则说明存在 bug + return re.exec('str') != null; }); +// 创建一个对象,包含关于正则表达式 `sticky` 标志的兼容性信息 var regexpStickyHelpers = { - UNSUPPORTED_Y: UNSUPPORTED_Y, - BROKEN_CARET: BROKEN_CARET + UNSUPPORTED_Y: UNSUPPORTED_Y, // 如果不支持 `y` 标志 + BROKEN_CARET: BROKEN_CARET // 如果存在 `^` 和 `y` 组合标志的问题 }; +// 获取原生 `RegExp.prototype.exec` 方法 var nativeExec = RegExp.prototype.exec; - // This always refers to the native implementation, because the - // String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js, - // which loads this file before patching the method. + +// 获取原生 `String.prototype.replace` 方法 var nativeReplace = String.prototype.replace; +// 默认将 `exec` 方法设置为原生 `exec` 方法 var patchedExec = nativeExec; +// 检查浏览器是否存在 `lastIndex` 更新不正确的问题 var UPDATES_LAST_INDEX_WRONG = (function () { - var re1 = /a/; - var re2 = /b*/g; - nativeExec.call(re1, 'a'); - nativeExec.call(re2, 'a'); - return re1.lastIndex !== 0 || re2.lastIndex !== 0; + var re1 = /a/; + var re2 = /b*/g; + // 在两个正则表达式上执行 `exec`,并检查 `lastIndex` 是否被正确更新 + nativeExec.call(re1, 'a'); + nativeExec.call(re2, 'a'); + return re1.lastIndex !== 0 || re2.lastIndex !== 0; })(); +// 检查是否有已知的 `y` 标志问题 var UNSUPPORTED_Y$1 = regexpStickyHelpers.UNSUPPORTED_Y || regexpStickyHelpers.BROKEN_CARET; - // nonparticipating capturing group, copied from es5-shim's String#split patch. +// 检查浏览器是否支持非参与的捕获组(NPCG) var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined; +// 判断是否需要修补 `exec` 方法 var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y$1; +// 如果发现需要修补,定义 `patchedExec` 函数 if (PATCH) { - patchedExec = function exec(str) { - var re = this; - var lastIndex, reCopy, match, i; - var sticky = UNSUPPORTED_Y$1 && re.sticky; - var flags = regexpFlags.call(re); - var source = re.source; - var charsAdded = 0; - var strCopy = str; - - if (sticky) { - flags = flags.replace('y', ''); - if (flags.indexOf('g') === -1) { - flags += 'g'; - } - - strCopy = String(str).slice(re.lastIndex); - // Support anchored sticky behavior. - if (re.lastIndex > 0 && (!re.multiline || re.multiline && str[re.lastIndex - 1] !== '\n')) { - source = '(?: ' + source + ')'; - strCopy = ' ' + strCopy; - charsAdded++; - } - // ^(? + rx + ) is needed, in combination with some str slicing, to - // simulate the 'y' flag. - reCopy = new RegExp('^(?:' + source + ')', flags); - } - - if (NPCG_INCLUDED) { - reCopy = new RegExp('^' + source + '$(?!\\s)', flags); - } - if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex; - - match = nativeExec.call(sticky ? reCopy : re, strCopy); - - if (sticky) { - if (match) { - match.input = match.input.slice(charsAdded); - match[0] = match[0].slice(charsAdded); - match.index = re.lastIndex; - re.lastIndex += match[0].length; - } else re.lastIndex = 0; - } else if (UPDATES_LAST_INDEX_WRONG && match) { - re.lastIndex = re.global ? match.index + match[0].length : lastIndex; - } - if (NPCG_INCLUDED && match && match.length > 1) { - // Fix browsers whose `exec` methods don't consistently return `undefined` - // for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/ - nativeReplace.call(match[0], reCopy, function () { - for (i = 1; i < arguments.length - 2; i++) { - if (arguments[i] === undefined) match[i] = undefined; - } - }); - } - - return match; - }; + patchedExec = function exec(str) { + var re = this; // 当前的正则表达式对象 + var lastIndex, reCopy, match, i; + var sticky = UNSUPPORTED_Y$1 && re.sticky; // 检查是否启用了 `y` 标志 + var flags = regexpFlags.call(re); // 获取正则表达式的标志 + var source = re.source; // 获取正则表达式的源代码 + var charsAdded = 0; // 用于调整字符串 + var strCopy = str; // 复制输入字符串 + + if (sticky) { + // 修复 `sticky` 标志的行为,确保正则表达式正确处理 + flags = flags.replace('y', ''); // 移除 `y` 标志 + if (flags.indexOf('g') === -1) { + flags += 'g'; // 添加 `g` 标志 + } + + strCopy = String(str).slice(re.lastIndex); // 切割字符串,从 `lastIndex` 开始 + + // 支持锚定的 `sticky` 行为 + if (re.lastIndex > 0 && (!re.multiline || re.multiline && str[re.lastIndex - 1] !== '\n')) { + source = '(?: ' + source + ')'; // 用非捕获组包裹正则源 + strCopy = ' ' + strCopy; // 在字符串前面添加空格 + charsAdded++; // 记录字符数 + } + + // 使用新的正则表达式副本进行匹配 + reCopy = new RegExp('^(?:' + source + ')', flags); + } + + // 如果支持非参与捕获组(NPCG),则处理特定情况 + if (NPCG_INCLUDED) { + reCopy = new RegExp('^' + source + '$(?!\\s)', flags); + } + + // 如果浏览器的 `exec` 方法存在 `lastIndex` 更新问题,进行修补 + if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex; + + // 调用原生 `exec` 方法执行匹配 + match = nativeExec.call(sticky ? reCopy : re, strCopy); + + if (sticky) { + if (match) { + match.input = match.input.slice(charsAdded); // 更新 `input` 属性 + match[0] = match[0].slice(charsAdded); // 更新匹配结果 + match.index = re.lastIndex; // 更新 `index` + re.lastIndex += match[0].length; // 更新 `lastIndex` + } else { + re.lastIndex = 0; // 如果没有匹配,重置 `lastIndex` + } + } else if (UPDATES_LAST_INDEX_WRONG && match) { + // 如果浏览器存在 `lastIndex` 更新问题,修复它 + re.lastIndex = re.global ? match.index + match[0].length : lastIndex; + } + + if (NPCG_INCLUDED && match && match.length > 1) { + // 修复浏览器中 `exec` 方法不一致地返回 `undefined` 的问题 + nativeReplace.call(match[0], reCopy, function () { + for (i = 1; i < arguments.length - 2; i++) { + if (arguments[i] === undefined) match[i] = undefined; + } + }); + } + + return match; // 返回匹配结果 + }; } +// 定义最终的 `regexpExec`,它会被用作 `RegExp.prototype.exec` 的替代方法 var regexpExec = patchedExec; +// 如果浏览器的 `exec` 方法不符合预期,使用修补的 `exec` 方法替代 _export({ target: 'RegExp', proto: true, forced: /./.exec !== regexpExec }, { - exec: regexpExec + exec: regexpExec }); - +// 定义常量 var TO_STRING = 'toString'; var RegExpPrototype = RegExp.prototype; var nativeToString = RegExpPrototype[TO_STRING]; +// 检查 `RegExp.prototype.toString` 是否是一个通用方法 +// 如果 `nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'`,则认为不是通用方法 var NOT_GENERIC = fails(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; }); - // FF44- RegExp#toString has a wrong name +// 检查 `RegExp.prototype.toString` 的方法名称是否正确,某些浏览器会将其命名为其他名称(如 Firefox 44) var INCORRECT_NAME = nativeToString.name != TO_STRING; - // `RegExp.prototype.toString` method - // https://tc39.github.io/ecma262/#sec-regexp.prototype.tostring +// 修复 `RegExp.prototype.toString` 方法 +// 如果原生方法不通用或名称错误,则重新定义它 if (NOT_GENERIC || INCORRECT_NAME) { - redefine(RegExp.prototype, TO_STRING, function toString() { - var R = anObject(this); - var p = String(R.source); - var rf = R.flags; - var f = String(rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype) ? regexpFlags.call(R) : rf); - return '/' + p + '/' + f; - }, { unsafe: true }); + redefine(RegExp.prototype, TO_STRING, function toString() { + var R = anObject(this); // 获取当前正则对象 + var p = String(R.source); // 获取正则表达式的源 + var rf = R.flags; // 获取正则表达式的标志 + var f = String(rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype) ? regexpFlags.call(R) : rf); // 处理没有 `flags` 属性的情况 + return '/' + p + '/' + f; // 返回标准的正则表达式字符串 + }, { unsafe: true }); // 使用 `{ unsafe: true }` 选项,允许覆盖原生方法 } var MATCH = wellKnownSymbol('match'); - // `IsRegExp` abstract operation - // https://tc39.github.io/ecma262/#sec-isregexp +// `IsRegExp` 抽象操作,用于判断一个对象是否是正则表达式 +// https://tc39.github.io/ecma262/#sec-isregexp var isRegexp = function (it) { - var isRegExp; - return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classofRaw(it) == 'RegExp'); + var isRegExp; + return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classofRaw(it) == 'RegExp'); }; +// `notARegexp` 方法,如果参数是正则表达式,则抛出错误 var notARegexp = function (it) { - if (isRegexp(it)) { - throw TypeError("The method doesn't accept regular expressions"); - } return it; + if (isRegexp(it)) { + throw TypeError("The method doesn't accept regular expressions"); + } return it; }; var MATCH$1 = wellKnownSymbol('match'); +// 修复 `String.prototype.includes` 方法的兼容性 +// 检查当前环境是否支持 `includes` 方法的正确逻辑 var correctIsRegexpLogic = function (METHOD_NAME) { - var regexp = /./; - try { - '/./'[METHOD_NAME](regexp); - } catch (e) { - try { - regexp[MATCH$1] = false; - return '/./'[METHOD_NAME](regexp); - } catch (f) { /* empty */ } - } return false; + var regexp = /./; + try { + // 如果 `String.prototype.includes` 支持正则表达式参数,则返回 `true` + '/./'[METHOD_NAME](regexp); + } catch (e) { + try { + // 如果 `regexp[MATCH$1]` 被设置为 `false`,则可以正常工作 + regexp[MATCH$1] = false; + return '/./'[METHOD_NAME](regexp); + } catch (f) { /* empty */ } + } return false; }; - // `String.prototype.includes` method - // https://tc39.github.io/ecma262/#sec-string.prototype.includes +// 修复 `String.prototype.includes` 方法 +// 如果当前环境不支持正确的 `includes` 方法,则进行修补 _export({ target: 'String', proto: true, forced: !correctIsRegexpLogic('includes') }, { - includes: function includes(searchString /* , position = 0 */) { - return !!~String(requireObjectCoercible(this)) - .indexOf(notARegexp(searchString), arguments.length > 1 ? arguments[1] : undefined); - } + includes: function includes(searchString /* , position = 0 */) { + // 强制将输入对象转为字符串,查找 `searchString` 的位置 + return !!~String(requireObjectCoercible(this)) + .indexOf(notARegexp(searchString), arguments.length > 1 ? arguments[1] : undefined); + } }); - // `String.prototype.{ codePointAt, at }` methods implementation +// `String.prototype.{ codePointAt, at }` 方法的实现 +// 创建方法 `createMethod$4`,用于处理字符编码和字符的位置 var createMethod$4 = function (CONVERT_TO_STRING) { - return function ($this, pos) { - var S = String(requireObjectCoercible($this)); - var position = toInteger(pos); - var size = S.length; - var first, second; - if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined; - first = S.charCodeAt(position); - return first < 0xD800 || first > 0xDBFF || position + 1 === size - || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF - ? CONVERT_TO_STRING ? S.charAt(position) : first - : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000; - }; + return function ($this, pos) { + var S = String(requireObjectCoercible($this)); // 强制转换为字符串 + var position = toInteger(pos); // 将位置转换为整数 + var size = S.length; // 获取字符串的长度 + var first, second; + if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined; // 如果位置不合法,则返回相应值 + first = S.charCodeAt(position); // 获取字符的 Unicode 编码 + return first < 0xD800 || first > 0xDBFF || position + 1 === size + || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF + ? CONVERT_TO_STRING ? S.charAt(position) : first + : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000; // 如果字符是代理对,则返回联合值 + }; }; var stringMultibyte = { - // `String.prototype.codePointAt` method - // https://tc39.github.io/ecma262/#sec-string.prototype.codepointat - codeAt: createMethod$4(false), - // `String.prototype.at` method - // https://github.com/mathiasbynens/String.prototype.at - charAt: createMethod$4(true) + // `String.prototype.codePointAt` method + // https://tc39.github.io/ecma262/#sec-string.prototype.codepointat + codeAt: createMethod$4(false), + // `String.prototype.at` method + // https://github.com/mathiasbynens/String.prototype.at + charAt: createMethod$4(true) }; var charAt = stringMultibyte.charAt; @@ -2215,123 +2572,123 @@ // `String.prototype[@@iterator]` method // https://tc39.github.io/ecma262/#sec-string.prototype-@@iterator defineIterator(String, 'String', function (iterated) { - setInternalState$2(this, { - type: STRING_ITERATOR, - string: String(iterated), - index: 0 - }); - // `%StringIteratorPrototype%.next` method - // https://tc39.github.io/ecma262/#sec-%stringiteratorprototype%.next + setInternalState$2(this, { + type: STRING_ITERATOR, + string: String(iterated), + index: 0 + }); + // `%StringIteratorPrototype%.next` method + // https://tc39.github.io/ecma262/#sec-%stringiteratorprototype%.next }, function next() { - var state = getInternalState$2(this); - var string = state.string; - var index = state.index; - var point; - if (index >= string.length) return { value: undefined, done: true }; - point = charAt(string, index); - state.index += point.length; - return { value: point, done: false }; + var state = getInternalState$2(this); + var string = state.string; + var index = state.index; + var point; + if (index >= string.length) return { value: undefined, done: true }; + point = charAt(string, index); + state.index += point.length; + return { value: point, done: false }; }); var SPECIES$3 = wellKnownSymbol('species'); var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () { - // #replace needs built-in support for named groups. - // #match works fine because it just return the exec results, even if it has - // a "grops" property. - var re = /./; - re.exec = function () { - var result = []; - result.groups = { a: '7' }; - return result; - }; - return ''.replace(re, '$') !== '7'; + // #replace needs built-in support for named groups. + // #match works fine because it just return the exec results, even if it has + // a "grops" property. + var re = /./; + re.exec = function () { + var result = []; + result.groups = { a: '7' }; + return result; + }; + return ''.replace(re, '$') !== '7'; }); // IE <= 11 replaces $0 with the whole match, as if it was $& // https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0 var REPLACE_KEEPS_$0 = (function () { - return 'a'.replace(/./, '$0') === '$0'; + return 'a'.replace(/./, '$0') === '$0'; })(); // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec // Weex JS has frozen built-in prototypes, so use try / catch wrapper var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () { - var re = /(?:)/; - var originalExec = re.exec; - re.exec = function () { return originalExec.apply(this, arguments); }; - var result = 'ab'.split(re); - return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b'; + var re = /(?:)/; + var originalExec = re.exec; + re.exec = function () { return originalExec.apply(this, arguments); }; + var result = 'ab'.split(re); + return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b'; }); var fixRegexpWellKnownSymbolLogic = function (KEY, length, exec, sham) { - var SYMBOL = wellKnownSymbol(KEY); - - var DELEGATES_TO_SYMBOL = !fails(function () { - // String methods call symbol-named RegEp methods - var O = {}; - O[SYMBOL] = function () { return 7; }; - return ''[KEY](O) != 7; - }); - - var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () { - // Symbol-named RegExp methods call .exec - var execCalled = false; - var re = /a/; - - if (KEY === 'split') { - // We can't use real regex here since it causes deoptimization - // and serious performance degradation in V8 - // https://github.com/zloirock/core-js/issues/306 - re = {}; - // RegExp[@@split] doesn't call the regex's exec method, but first creates - // a new one. We need to return the patched regex when creating the new one. - re.constructor = {}; - re.constructor[SPECIES$3] = function () { return re; }; - re.flags = ''; - re[SYMBOL] = /./[SYMBOL]; - } - - re.exec = function () { execCalled = true; return null; }; - - re[SYMBOL](''); - return !execCalled; - }); - - if ( - !DELEGATES_TO_SYMBOL || - !DELEGATES_TO_EXEC || - (KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && REPLACE_KEEPS_$0)) || - (KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC) - ) { - var nativeRegExpMethod = /./[SYMBOL]; - var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) { - if (regexp.exec === regexpExec) { - if (DELEGATES_TO_SYMBOL && !forceStringMethod) { - // The native String method already delegates to @@method (this - // polyfilled function), leasing to infinite recursion. - // We avoid it by directly calling the native @@method method. - return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) }; - } - return { done: true, value: nativeMethod.call(str, regexp, arg2) }; - } - return { done: false }; - }, { REPLACE_KEEPS_$0: REPLACE_KEEPS_$0 }); - var stringMethod = methods[0]; - var regexMethod = methods[1]; - - redefine(String.prototype, KEY, stringMethod); - redefine(RegExp.prototype, SYMBOL, length == 2 - // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) - // 21.2.5.11 RegExp.prototype[@@split](string, limit) - ? function (string, arg) { return regexMethod.call(string, this, arg); } - // 21.2.5.6 RegExp.prototype[@@match](string) - // 21.2.5.9 RegExp.prototype[@@search](string) - : function (string) { return regexMethod.call(string, this); } - ); - } - - if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true); + var SYMBOL = wellKnownSymbol(KEY); + + var DELEGATES_TO_SYMBOL = !fails(function () { + // String methods call symbol-named RegEp methods + var O = {}; + O[SYMBOL] = function () { return 7; }; + return ''[KEY](O) != 7; + }); + + var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () { + // Symbol-named RegExp methods call .exec + var execCalled = false; + var re = /a/; + + if (KEY === 'split') { + // We can't use real regex here since it causes deoptimization + // and serious performance degradation in V8 + // https://github.com/zloirock/core-js/issues/306 + re = {}; + // RegExp[@@split] doesn't call the regex's exec method, but first creates + // a new one. We need to return the patched regex when creating the new one. + re.constructor = {}; + re.constructor[SPECIES$3] = function () { return re; }; + re.flags = ''; + re[SYMBOL] = /./[SYMBOL]; + } + + re.exec = function () { execCalled = true; return null; }; + + re[SYMBOL](''); + return !execCalled; + }); + + if ( + !DELEGATES_TO_SYMBOL || + !DELEGATES_TO_EXEC || + (KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && REPLACE_KEEPS_$0)) || + (KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC) + ) { + var nativeRegExpMethod = /./[SYMBOL]; + var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) { + if (regexp.exec === regexpExec) { + if (DELEGATES_TO_SYMBOL && !forceStringMethod) { + // The native String method already delegates to @@method (this + // polyfilled function), leasing to infinite recursion. + // We avoid it by directly calling the native @@method method. + return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) }; + } + return { done: true, value: nativeMethod.call(str, regexp, arg2) }; + } + return { done: false }; + }, { REPLACE_KEEPS_$0: REPLACE_KEEPS_$0 }); + var stringMethod = methods[0]; + var regexMethod = methods[1]; + + redefine(String.prototype, KEY, stringMethod); + redefine(RegExp.prototype, SYMBOL, length == 2 + // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) + // 21.2.5.11 RegExp.prototype[@@split](string, limit) + ? function (string, arg) { return regexMethod.call(string, this, arg); } + // 21.2.5.6 RegExp.prototype[@@match](string) + // 21.2.5.9 RegExp.prototype[@@search](string) + : function (string) { return regexMethod.call(string, this); } + ); + } + + if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true); }; var charAt$1 = stringMultibyte.charAt; @@ -2339,26 +2696,26 @@ // `AdvanceStringIndex` abstract operation // https://tc39.github.io/ecma262/#sec-advancestringindex var advanceStringIndex = function (S, index, unicode) { - return index + (unicode ? charAt$1(S, index).length : 1); + return index + (unicode ? charAt$1(S, index).length : 1); }; // `RegExpExec` abstract operation // https://tc39.github.io/ecma262/#sec-regexpexec var regexpExecAbstract = function (R, S) { - var exec = R.exec; - if (typeof exec === 'function') { - var result = exec.call(R, S); - if (typeof result !== 'object') { - throw TypeError('RegExp exec method returned something other than an Object or null'); - } - return result; - } - - if (classofRaw(R) !== 'RegExp') { - throw TypeError('RegExp#exec called on incompatible receiver'); - } - - return regexpExec.call(R, S); + var exec = R.exec; + if (typeof exec === 'function') { + var result = exec.call(R, S); + if (typeof result !== 'object') { + throw TypeError('RegExp exec method returned something other than an Object or null'); + } + return result; + } + + if (classofRaw(R) !== 'RegExp') { + throw TypeError('RegExp#exec called on incompatible receiver'); + } + + return regexpExec.call(R, S); }; var max$3 = Math.max; @@ -2368,151 +2725,151 @@ var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d\d?)/g; var maybeToString = function (it) { - return it === undefined ? it : String(it); + return it === undefined ? it : String(it); }; // @@replace logic fixRegexpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) { - return [ - // `String.prototype.replace` method - // https://tc39.github.io/ecma262/#sec-string.prototype.replace - function replace(searchValue, replaceValue) { - var O = requireObjectCoercible(this); - var replacer = searchValue == undefined ? undefined : searchValue[REPLACE]; - return replacer !== undefined - ? replacer.call(searchValue, O, replaceValue) - : nativeReplace.call(String(O), searchValue, replaceValue); - }, - // `RegExp.prototype[@@replace]` method - // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace - function (regexp, replaceValue) { - if (reason.REPLACE_KEEPS_$0 || (typeof replaceValue === 'string' && replaceValue.indexOf('$0') === -1)) { - var res = maybeCallNative(nativeReplace, regexp, this, replaceValue); - if (res.done) return res.value; - } - - var rx = anObject(regexp); - var S = String(this); - - var functionalReplace = typeof replaceValue === 'function'; - if (!functionalReplace) replaceValue = String(replaceValue); - - var global = rx.global; - if (global) { - var fullUnicode = rx.unicode; - rx.lastIndex = 0; - } - var results = []; - while (true) { - var result = regexpExecAbstract(rx, S); - if (result === null) break; - - results.push(result); - if (!global) break; - - var matchStr = String(result[0]); - if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode); - } - - var accumulatedResult = ''; - var nextSourcePosition = 0; - for (var i = 0; i < results.length; i++) { - result = results[i]; - - var matched = String(result[0]); - var position = max$3(min$3(toInteger(result.index), S.length), 0); - var captures = []; - // NOTE: This is equivalent to - // captures = result.slice(1).map(maybeToString) - // but for some reason `nativeSlice.call(result, 1, result.length)` (called in - // the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and - // causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it. - for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j])); - var namedCaptures = result.groups; - if (functionalReplace) { - var replacerArgs = [matched].concat(captures, position, S); - if (namedCaptures !== undefined) replacerArgs.push(namedCaptures); - var replacement = String(replaceValue.apply(undefined, replacerArgs)); - } else { - replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue); - } - if (position >= nextSourcePosition) { - accumulatedResult += S.slice(nextSourcePosition, position) + replacement; - nextSourcePosition = position + matched.length; - } - } - return accumulatedResult + S.slice(nextSourcePosition); - } - ]; - - // https://tc39.github.io/ecma262/#sec-getsubstitution - function getSubstitution(matched, str, position, captures, namedCaptures, replacement) { - var tailPos = position + matched.length; - var m = captures.length; - var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED; - if (namedCaptures !== undefined) { - namedCaptures = toObject(namedCaptures); - symbols = SUBSTITUTION_SYMBOLS; - } - return nativeReplace.call(replacement, symbols, function (match, ch) { - var capture; - switch (ch.charAt(0)) { - case '$': return '$'; - case '&': return matched; - case '`': return str.slice(0, position); - case "'": return str.slice(tailPos); - case '<': - capture = namedCaptures[ch.slice(1, -1)]; - break; - default: // \d\d? - var n = +ch; - if (n === 0) return match; - if (n > m) { - var f = floor$1(n / 10); - if (f === 0) return match; - if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1); - return match; - } - capture = captures[n - 1]; - } - return capture === undefined ? '' : capture; - }); - } + return [ + // `String.prototype.replace` method + // https://tc39.github.io/ecma262/#sec-string.prototype.replace + function replace(searchValue, replaceValue) { + var O = requireObjectCoercible(this); + var replacer = searchValue == undefined ? undefined : searchValue[REPLACE]; + return replacer !== undefined + ? replacer.call(searchValue, O, replaceValue) + : nativeReplace.call(String(O), searchValue, replaceValue); + }, + // `RegExp.prototype[@@replace]` method + // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace + function (regexp, replaceValue) { + if (reason.REPLACE_KEEPS_$0 || (typeof replaceValue === 'string' && replaceValue.indexOf('$0') === -1)) { + var res = maybeCallNative(nativeReplace, regexp, this, replaceValue); + if (res.done) return res.value; + } + + var rx = anObject(regexp); + var S = String(this); + + var functionalReplace = typeof replaceValue === 'function'; + if (!functionalReplace) replaceValue = String(replaceValue); + + var global = rx.global; + if (global) { + var fullUnicode = rx.unicode; + rx.lastIndex = 0; + } + var results = []; + while (true) { + var result = regexpExecAbstract(rx, S); + if (result === null) break; + + results.push(result); + if (!global) break; + + var matchStr = String(result[0]); + if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode); + } + + var accumulatedResult = ''; + var nextSourcePosition = 0; + for (var i = 0; i < results.length; i++) { + result = results[i]; + + var matched = String(result[0]); + var position = max$3(min$3(toInteger(result.index), S.length), 0); + var captures = []; + // NOTE: This is equivalent to + // captures = result.slice(1).map(maybeToString) + // but for some reason `nativeSlice.call(result, 1, result.length)` (called in + // the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and + // causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it. + for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j])); + var namedCaptures = result.groups; + if (functionalReplace) { + var replacerArgs = [matched].concat(captures, position, S); + if (namedCaptures !== undefined) replacerArgs.push(namedCaptures); + var replacement = String(replaceValue.apply(undefined, replacerArgs)); + } else { + replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue); + } + if (position >= nextSourcePosition) { + accumulatedResult += S.slice(nextSourcePosition, position) + replacement; + nextSourcePosition = position + matched.length; + } + } + return accumulatedResult + S.slice(nextSourcePosition); + } + ]; + + // https://tc39.github.io/ecma262/#sec-getsubstitution + function getSubstitution(matched, str, position, captures, namedCaptures, replacement) { + var tailPos = position + matched.length; + var m = captures.length; + var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED; + if (namedCaptures !== undefined) { + namedCaptures = toObject(namedCaptures); + symbols = SUBSTITUTION_SYMBOLS; + } + return nativeReplace.call(replacement, symbols, function (match, ch) { + var capture; + switch (ch.charAt(0)) { + case '$': return '$'; + case '&': return matched; + case '`': return str.slice(0, position); + case "'": return str.slice(tailPos); + case '<': + capture = namedCaptures[ch.slice(1, -1)]; + break; + default: // \d\d? + var n = +ch; + if (n === 0) return match; + if (n > m) { + var f = floor$1(n / 10); + if (f === 0) return match; + if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1); + return match; + } + capture = captures[n - 1]; + } + return capture === undefined ? '' : capture; + }); + } }); // `SameValue` abstract operation // https://tc39.github.io/ecma262/#sec-samevalue var sameValue = Object.is || function is(x, y) { - // eslint-disable-next-line no-self-compare - return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; + // eslint-disable-next-line no-self-compare + return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; }; // @@search logic fixRegexpWellKnownSymbolLogic('search', 1, function (SEARCH, nativeSearch, maybeCallNative) { - return [ - // `String.prototype.search` method - // https://tc39.github.io/ecma262/#sec-string.prototype.search - function search(regexp) { - var O = requireObjectCoercible(this); - var searcher = regexp == undefined ? undefined : regexp[SEARCH]; - return searcher !== undefined ? searcher.call(regexp, O) : new RegExp(regexp)[SEARCH](String(O)); - }, - // `RegExp.prototype[@@search]` method - // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search - function (regexp) { - var res = maybeCallNative(nativeSearch, regexp, this); - if (res.done) return res.value; - - var rx = anObject(regexp); - var S = String(this); - - var previousLastIndex = rx.lastIndex; - if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0; - var result = regexpExecAbstract(rx, S); - if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex; - return result === null ? -1 : result.index; - } - ]; + return [ + // `String.prototype.search` method + // https://tc39.github.io/ecma262/#sec-string.prototype.search + function search(regexp) { + var O = requireObjectCoercible(this); + var searcher = regexp == undefined ? undefined : regexp[SEARCH]; + return searcher !== undefined ? searcher.call(regexp, O) : new RegExp(regexp)[SEARCH](String(O)); + }, + // `RegExp.prototype[@@search]` method + // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search + function (regexp) { + var res = maybeCallNative(nativeSearch, regexp, this); + if (res.done) return res.value; + + var rx = anObject(regexp); + var S = String(this); + + var previousLastIndex = rx.lastIndex; + if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0; + var result = regexpExecAbstract(rx, S); + if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex; + return result === null ? -1 : result.index; + } + ]; }); var SPECIES$4 = wellKnownSymbol('species'); @@ -2520,9 +2877,9 @@ // `SpeciesConstructor` abstract operation // https://tc39.github.io/ecma262/#sec-speciesconstructor var speciesConstructor = function (O, defaultConstructor) { - var C = anObject(O).constructor; - var S; - return C === undefined || (S = anObject(C)[SPECIES$4]) == undefined ? defaultConstructor : aFunction$1(S); + var C = anObject(O).constructor; + var S; + return C === undefined || (S = anObject(C)[SPECIES$4]) == undefined ? defaultConstructor : aFunction$1(S); }; var arrayPush = [].push; @@ -2534,118 +2891,118 @@ // @@split logic fixRegexpWellKnownSymbolLogic('split', 2, function (SPLIT, nativeSplit, maybeCallNative) { - var internalSplit; - if ( - 'abbc'.split(/(b)*/)[1] == 'c' || - 'test'.split(/(?:)/, -1).length != 4 || - 'ab'.split(/(?:ab)*/).length != 2 || - '.'.split(/(.?)(.?)/).length != 4 || - '.'.split(/()()/).length > 1 || - ''.split(/.?/).length - ) { - // based on es5-shim implementation, need to rework it - internalSplit = function (separator, limit) { - var string = String(requireObjectCoercible(this)); - var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; - if (lim === 0) return []; - if (separator === undefined) return [string]; - // If `separator` is not a regex, use native split - if (!isRegexp(separator)) { - return nativeSplit.call(string, separator, lim); - } - var output = []; - var flags = (separator.ignoreCase ? 'i' : '') + - (separator.multiline ? 'm' : '') + - (separator.unicode ? 'u' : '') + - (separator.sticky ? 'y' : ''); - var lastLastIndex = 0; - // Make `global` and avoid `lastIndex` issues by working with a copy - var separatorCopy = new RegExp(separator.source, flags + 'g'); - var match, lastIndex, lastLength; - while (match = regexpExec.call(separatorCopy, string)) { - lastIndex = separatorCopy.lastIndex; - if (lastIndex > lastLastIndex) { - output.push(string.slice(lastLastIndex, match.index)); - if (match.length > 1 && match.index < string.length) arrayPush.apply(output, match.slice(1)); - lastLength = match[0].length; - lastLastIndex = lastIndex; - if (output.length >= lim) break; - } - if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop - } - if (lastLastIndex === string.length) { - if (lastLength || !separatorCopy.test('')) output.push(''); - } else output.push(string.slice(lastLastIndex)); - return output.length > lim ? output.slice(0, lim) : output; - }; - // Chakra, V8 - } else if ('0'.split(undefined, 0).length) { - internalSplit = function (separator, limit) { - return separator === undefined && limit === 0 ? [] : nativeSplit.call(this, separator, limit); - }; - } else internalSplit = nativeSplit; - - return [ - // `String.prototype.split` method - // https://tc39.github.io/ecma262/#sec-string.prototype.split - function split(separator, limit) { - var O = requireObjectCoercible(this); - var splitter = separator == undefined ? undefined : separator[SPLIT]; - return splitter !== undefined - ? splitter.call(separator, O, limit) - : internalSplit.call(String(O), separator, limit); - }, - // `RegExp.prototype[@@split]` method - // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@split - // - // NOTE: This cannot be properly polyfilled in engines that don't support - // the 'y' flag. - function (regexp, limit) { - var res = maybeCallNative(internalSplit, regexp, this, limit, internalSplit !== nativeSplit); - if (res.done) return res.value; - - var rx = anObject(regexp); - var S = String(this); - var C = speciesConstructor(rx, RegExp); - - var unicodeMatching = rx.unicode; - var flags = (rx.ignoreCase ? 'i' : '') + - (rx.multiline ? 'm' : '') + - (rx.unicode ? 'u' : '') + - (SUPPORTS_Y ? 'y' : 'g'); - - // ^(? + rx + ) is needed, in combination with some S slicing, to - // simulate the 'y' flag. - var splitter = new C(SUPPORTS_Y ? rx : '^(?:' + rx.source + ')', flags); - var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; - if (lim === 0) return []; - if (S.length === 0) return regexpExecAbstract(splitter, S) === null ? [S] : []; - var p = 0; - var q = 0; - var A = []; - while (q < S.length) { - splitter.lastIndex = SUPPORTS_Y ? q : 0; - var z = regexpExecAbstract(splitter, SUPPORTS_Y ? S : S.slice(q)); - var e; - if ( - z === null || - (e = min$4(toLength(splitter.lastIndex + (SUPPORTS_Y ? 0 : q)), S.length)) === p - ) { - q = advanceStringIndex(S, q, unicodeMatching); - } else { - A.push(S.slice(p, q)); - if (A.length === lim) return A; - for (var i = 1; i <= z.length - 1; i++) { - A.push(z[i]); - if (A.length === lim) return A; - } - q = p = e; - } - } - A.push(S.slice(p)); - return A; - } - ]; + var internalSplit; + if ( + 'abbc'.split(/(b)*/)[1] == 'c' || + 'test'.split(/(?:)/, -1).length != 4 || + 'ab'.split(/(?:ab)*/).length != 2 || + '.'.split(/(.?)(.?)/).length != 4 || + '.'.split(/()()/).length > 1 || + ''.split(/.?/).length + ) { + // based on es5-shim implementation, need to rework it + internalSplit = function (separator, limit) { + var string = String(requireObjectCoercible(this)); + var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; + if (lim === 0) return []; + if (separator === undefined) return [string]; + // If `separator` is not a regex, use native split + if (!isRegexp(separator)) { + return nativeSplit.call(string, separator, lim); + } + var output = []; + var flags = (separator.ignoreCase ? 'i' : '') + + (separator.multiline ? 'm' : '') + + (separator.unicode ? 'u' : '') + + (separator.sticky ? 'y' : ''); + var lastLastIndex = 0; + // Make `global` and avoid `lastIndex` issues by working with a copy + var separatorCopy = new RegExp(separator.source, flags + 'g'); + var match, lastIndex, lastLength; + while (match = regexpExec.call(separatorCopy, string)) { + lastIndex = separatorCopy.lastIndex; + if (lastIndex > lastLastIndex) { + output.push(string.slice(lastLastIndex, match.index)); + if (match.length > 1 && match.index < string.length) arrayPush.apply(output, match.slice(1)); + lastLength = match[0].length; + lastLastIndex = lastIndex; + if (output.length >= lim) break; + } + if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop + } + if (lastLastIndex === string.length) { + if (lastLength || !separatorCopy.test('')) output.push(''); + } else output.push(string.slice(lastLastIndex)); + return output.length > lim ? output.slice(0, lim) : output; + }; + // Chakra, V8 + } else if ('0'.split(undefined, 0).length) { + internalSplit = function (separator, limit) { + return separator === undefined && limit === 0 ? [] : nativeSplit.call(this, separator, limit); + }; + } else internalSplit = nativeSplit; + + return [ + // `String.prototype.split` method + // https://tc39.github.io/ecma262/#sec-string.prototype.split + function split(separator, limit) { + var O = requireObjectCoercible(this); + var splitter = separator == undefined ? undefined : separator[SPLIT]; + return splitter !== undefined + ? splitter.call(separator, O, limit) + : internalSplit.call(String(O), separator, limit); + }, + // `RegExp.prototype[@@split]` method + // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@split + // + // NOTE: This cannot be properly polyfilled in engines that don't support + // the 'y' flag. + function (regexp, limit) { + var res = maybeCallNative(internalSplit, regexp, this, limit, internalSplit !== nativeSplit); + if (res.done) return res.value; + + var rx = anObject(regexp); + var S = String(this); + var C = speciesConstructor(rx, RegExp); + + var unicodeMatching = rx.unicode; + var flags = (rx.ignoreCase ? 'i' : '') + + (rx.multiline ? 'm' : '') + + (rx.unicode ? 'u' : '') + + (SUPPORTS_Y ? 'y' : 'g'); + + // ^(? + rx + ) is needed, in combination with some S slicing, to + // simulate the 'y' flag. + var splitter = new C(SUPPORTS_Y ? rx : '^(?:' + rx.source + ')', flags); + var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; + if (lim === 0) return []; + if (S.length === 0) return regexpExecAbstract(splitter, S) === null ? [S] : []; + var p = 0; + var q = 0; + var A = []; + while (q < S.length) { + splitter.lastIndex = SUPPORTS_Y ? q : 0; + var z = regexpExecAbstract(splitter, SUPPORTS_Y ? S : S.slice(q)); + var e; + if ( + z === null || + (e = min$4(toLength(splitter.lastIndex + (SUPPORTS_Y ? 0 : q)), S.length)) === p + ) { + q = advanceStringIndex(S, q, unicodeMatching); + } else { + A.push(S.slice(p, q)); + if (A.length === lim) return A; + for (var i = 1; i <= z.length - 1; i++) { + A.push(z[i]); + if (A.length === lim) return A; + } + q = p = e; + } + } + A.push(S.slice(p)); + return A; + } + ]; }, !SUPPORTS_Y); var non = '\u200B\u0085\u180E'; @@ -2653,9 +3010,9 @@ // check that a method works with the correct list // of whitespaces and has a correct name var forcedStringTrimMethod = function (METHOD_NAME) { - return fails(function () { - return !!whitespaces[METHOD_NAME]() || non[METHOD_NAME]() != non || whitespaces[METHOD_NAME].name !== METHOD_NAME; - }); + return fails(function () { + return !!whitespaces[METHOD_NAME]() || non[METHOD_NAME]() != non || whitespaces[METHOD_NAME].name !== METHOD_NAME; + }); }; var $trim = stringTrim.trim; @@ -2664,45 +3021,45 @@ // `String.prototype.trim` method // https://tc39.github.io/ecma262/#sec-string.prototype.trim _export({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, { - trim: function trim() { - return $trim(this); - } + trim: function trim() { + return $trim(this); + } }); // iterable DOM collections // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods var domIterables = { - CSSRuleList: 0, - CSSStyleDeclaration: 0, - CSSValueList: 0, - ClientRectList: 0, - DOMRectList: 0, - DOMStringList: 0, - DOMTokenList: 1, - DataTransferItemList: 0, - FileList: 0, - HTMLAllCollection: 0, - HTMLCollection: 0, - HTMLFormElement: 0, - HTMLSelectElement: 0, - MediaList: 0, - MimeTypeArray: 0, - NamedNodeMap: 0, - NodeList: 1, - PaintRequestList: 0, - Plugin: 0, - PluginArray: 0, - SVGLengthList: 0, - SVGNumberList: 0, - SVGPathSegList: 0, - SVGPointList: 0, - SVGStringList: 0, - SVGTransformList: 0, - SourceBufferList: 0, - StyleSheetList: 0, - TextTrackCueList: 0, - TextTrackList: 0, - TouchList: 0 + CSSRuleList: 0, + CSSStyleDeclaration: 0, + CSSValueList: 0, + ClientRectList: 0, + DOMRectList: 0, + DOMStringList: 0, + DOMTokenList: 1, + DataTransferItemList: 0, + FileList: 0, + HTMLAllCollection: 0, + HTMLCollection: 0, + HTMLFormElement: 0, + HTMLSelectElement: 0, + MediaList: 0, + MimeTypeArray: 0, + NamedNodeMap: 0, + NodeList: 1, + PaintRequestList: 0, + Plugin: 0, + PluginArray: 0, + SVGLengthList: 0, + SVGNumberList: 0, + SVGPathSegList: 0, + SVGPointList: 0, + SVGStringList: 0, + SVGTransformList: 0, + SourceBufferList: 0, + StyleSheetList: 0, + TextTrackCueList: 0, + TextTrackList: 0, + TouchList: 0 }; var $forEach$1 = arrayIteration.forEach; @@ -2711,18 +3068,18 @@ // `Array.prototype.forEach` method implementation // https://tc39.github.io/ecma262/#sec-array.prototype.foreach var arrayForEach = sloppyArrayMethod('forEach') ? function forEach(callbackfn /* , thisArg */) { - return $forEach$1(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + return $forEach$1(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); } : [].forEach; for (var COLLECTION_NAME in domIterables) { - var Collection = global_1[COLLECTION_NAME]; - var CollectionPrototype = Collection && Collection.prototype; - // some Chrome versions have non-configurable methods on DOMTokenList - if (CollectionPrototype && CollectionPrototype.forEach !== arrayForEach) try { - createNonEnumerableProperty(CollectionPrototype, 'forEach', arrayForEach); - } catch (error) { - CollectionPrototype.forEach = arrayForEach; - } + var Collection = global_1[COLLECTION_NAME]; + var CollectionPrototype = Collection && Collection.prototype; + // some Chrome versions have non-configurable methods on DOMTokenList + if (CollectionPrototype && CollectionPrototype.forEach !== arrayForEach) try { + createNonEnumerableProperty(CollectionPrototype, 'forEach', arrayForEach); + } catch (error) { + CollectionPrototype.forEach = arrayForEach; + } } var ITERATOR$2 = wellKnownSymbol('iterator'); @@ -2730,607 +3087,607 @@ var ArrayValues = es_array_iterator.values; for (var COLLECTION_NAME$1 in domIterables) { - var Collection$1 = global_1[COLLECTION_NAME$1]; - var CollectionPrototype$1 = Collection$1 && Collection$1.prototype; - if (CollectionPrototype$1) { - // some Chrome versions have non-configurable methods on DOMTokenList - if (CollectionPrototype$1[ITERATOR$2] !== ArrayValues) try { - createNonEnumerableProperty(CollectionPrototype$1, ITERATOR$2, ArrayValues); - } catch (error) { - CollectionPrototype$1[ITERATOR$2] = ArrayValues; - } - if (!CollectionPrototype$1[TO_STRING_TAG$3]) { - createNonEnumerableProperty(CollectionPrototype$1, TO_STRING_TAG$3, COLLECTION_NAME$1); - } - if (domIterables[COLLECTION_NAME$1]) for (var METHOD_NAME in es_array_iterator) { - // some Chrome versions have non-configurable methods on DOMTokenList - if (CollectionPrototype$1[METHOD_NAME] !== es_array_iterator[METHOD_NAME]) try { - createNonEnumerableProperty(CollectionPrototype$1, METHOD_NAME, es_array_iterator[METHOD_NAME]); - } catch (error) { - CollectionPrototype$1[METHOD_NAME] = es_array_iterator[METHOD_NAME]; - } - } - } + var Collection$1 = global_1[COLLECTION_NAME$1]; + var CollectionPrototype$1 = Collection$1 && Collection$1.prototype; + if (CollectionPrototype$1) { + // some Chrome versions have non-configurable methods on DOMTokenList + if (CollectionPrototype$1[ITERATOR$2] !== ArrayValues) try { + createNonEnumerableProperty(CollectionPrototype$1, ITERATOR$2, ArrayValues); + } catch (error) { + CollectionPrototype$1[ITERATOR$2] = ArrayValues; + } + if (!CollectionPrototype$1[TO_STRING_TAG$3]) { + createNonEnumerableProperty(CollectionPrototype$1, TO_STRING_TAG$3, COLLECTION_NAME$1); + } + if (domIterables[COLLECTION_NAME$1]) for (var METHOD_NAME in es_array_iterator) { + // some Chrome versions have non-configurable methods on DOMTokenList + if (CollectionPrototype$1[METHOD_NAME] !== es_array_iterator[METHOD_NAME]) try { + createNonEnumerableProperty(CollectionPrototype$1, METHOD_NAME, es_array_iterator[METHOD_NAME]); + } catch (error) { + CollectionPrototype$1[METHOD_NAME] = es_array_iterator[METHOD_NAME]; + } + } + } } function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - - return _typeof(obj); + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); } function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } } function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } } function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; } function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; - return arr2; - } + return arr2; + } } function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; + if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _iterableToArrayLimit(arr, i) { - if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { - return; - } - - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; + if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { + return; + } + + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; } function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); + throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); + throw new TypeError("Invalid attempt to destructure non-iterable instance"); } var VERSION = '1.16.0'; var bootstrapVersion = 4; try { - var rawVersion = $.fn.dropdown.Constructor.VERSION; // Only try to parse VERSION if it is defined. - // It is undefined in older versions of Bootstrap (tested with 3.1.1). + var rawVersion = $.fn.dropdown.Constructor.VERSION; // Only try to parse VERSION if it is defined. + // It is undefined in older versions of Bootstrap (tested with 3.1.1). - if (rawVersion !== undefined) { - bootstrapVersion = parseInt(rawVersion, 10); - } + if (rawVersion !== undefined) { + bootstrapVersion = parseInt(rawVersion, 10); + } } catch (e) {// ignore } var CONSTANTS = { - 3: { - iconsPrefix: 'glyphicon', - icons: { - paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', - paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', - refresh: 'glyphicon-refresh icon-refresh', - toggleOff: 'glyphicon-list-alt icon-list-alt', - toggleOn: 'glyphicon-list-alt icon-list-alt', - columns: 'glyphicon-th icon-th', - detailOpen: 'glyphicon-plus icon-plus', - detailClose: 'glyphicon-minus icon-minus', - fullscreen: 'glyphicon-fullscreen', - search: 'glyphicon-search', - clearSearch: 'glyphicon-trash' - }, - classes: { - buttonsPrefix: 'btn', - buttons: 'default', - buttonsGroup: 'btn-group', - buttonsDropdown: 'btn-group', - pull: 'pull', - inputGroup: 'input-group', - inputPrefix: 'input-', - input: 'form-control', - paginationDropdown: 'btn-group dropdown', - dropup: 'dropup', - dropdownActive: 'active', - paginationActive: 'active', - buttonActive: 'active' - }, - html: { - toolbarDropdown: [''], - toolbarDropdownItem: '', - toolbarDropdownSeparator: '
  • ', - pageDropdown: [''], - pageDropdownItem: '
    ', - dropdownCaret: '', - pagination: [''], - paginationItem: '
  • %s
  • ', - icon: '', - inputGroup: '
    %s%s
    ', - searchInput: '', - searchButton: '', - searchClearButton: '' - } - }, - 4: { - iconsPrefix: 'fa', - icons: { - paginationSwitchDown: 'fa-caret-square-down', - paginationSwitchUp: 'fa-caret-square-up', - refresh: 'fa-sync', - toggleOff: 'fa-toggle-off', - toggleOn: 'fa-toggle-on', - columns: 'fa-th-list', - detailOpen: 'fa-plus', - detailClose: 'fa-minus', - fullscreen: 'fa-arrows-alt', - search: 'fa-search', - clearSearch: 'fa-trash' - }, - classes: { - buttonsPrefix: 'btn', - buttons: 'secondary', - buttonsGroup: 'btn-group', - buttonsDropdown: 'btn-group', - pull: 'float', - inputGroup: 'btn-group', - inputPrefix: 'form-control-', - input: 'form-control', - paginationDropdown: 'btn-group dropdown', - dropup: 'dropup', - dropdownActive: 'active', - paginationActive: 'active', - buttonActive: 'active' - }, - html: { - toolbarDropdown: [''], - toolbarDropdownItem: '', - pageDropdown: [''], - pageDropdownItem: '%s', - toolbarDropdownSeparator: '', - dropdownCaret: '', - pagination: [''], - paginationItem: '
  • %s
  • ', - icon: '', - inputGroup: '
    %s
    %s
    ', - searchInput: '', - searchButton: '', - searchClearButton: '' - } - } + 3: { + iconsPrefix: 'glyphicon', + icons: { + paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', + paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', + refresh: 'glyphicon-refresh icon-refresh', + toggleOff: 'glyphicon-list-alt icon-list-alt', + toggleOn: 'glyphicon-list-alt icon-list-alt', + columns: 'glyphicon-th icon-th', + detailOpen: 'glyphicon-plus icon-plus', + detailClose: 'glyphicon-minus icon-minus', + fullscreen: 'glyphicon-fullscreen', + search: 'glyphicon-search', + clearSearch: 'glyphicon-trash' + }, + classes: { + buttonsPrefix: 'btn', + buttons: 'default', + buttonsGroup: 'btn-group', + buttonsDropdown: 'btn-group', + pull: 'pull', + inputGroup: 'input-group', + inputPrefix: 'input-', + input: 'form-control', + paginationDropdown: 'btn-group dropdown', + dropup: 'dropup', + dropdownActive: 'active', + paginationActive: 'active', + buttonActive: 'active' + }, + html: { + toolbarDropdown: [''], + toolbarDropdownItem: '', + toolbarDropdownSeparator: '
  • ', + pageDropdown: [''], + pageDropdownItem: '', + dropdownCaret: '', + pagination: [''], + paginationItem: '
  • %s
  • ', + icon: '', + inputGroup: '
    %s%s
    ', + searchInput: '', + searchButton: '', + searchClearButton: '' + } + }, + 4: { + iconsPrefix: 'fa', + icons: { + paginationSwitchDown: 'fa-caret-square-down', + paginationSwitchUp: 'fa-caret-square-up', + refresh: 'fa-sync', + toggleOff: 'fa-toggle-off', + toggleOn: 'fa-toggle-on', + columns: 'fa-th-list', + detailOpen: 'fa-plus', + detailClose: 'fa-minus', + fullscreen: 'fa-arrows-alt', + search: 'fa-search', + clearSearch: 'fa-trash' + }, + classes: { + buttonsPrefix: 'btn', + buttons: 'secondary', + buttonsGroup: 'btn-group', + buttonsDropdown: 'btn-group', + pull: 'float', + inputGroup: 'btn-group', + inputPrefix: 'form-control-', + input: 'form-control', + paginationDropdown: 'btn-group dropdown', + dropup: 'dropup', + dropdownActive: 'active', + paginationActive: 'active', + buttonActive: 'active' + }, + html: { + toolbarDropdown: [''], + toolbarDropdownItem: '', + pageDropdown: [''], + pageDropdownItem: '%s', + toolbarDropdownSeparator: '', + dropdownCaret: '', + pagination: [''], + paginationItem: '
  • %s
  • ', + icon: '', + inputGroup: '
    %s
    %s
    ', + searchInput: '', + searchButton: '', + searchClearButton: '' + } + } }[bootstrapVersion]; var DEFAULTS = { - height: undefined, - classes: 'table table-bordered table-hover', - theadClasses: '', - headerStyle: function headerStyle(column) { - return {}; - }, - rowStyle: function rowStyle(row, index) { - return {}; - }, - rowAttributes: function rowAttributes(row, index) { - return {}; - }, - undefinedText: '-', - locale: undefined, - virtualScroll: false, - virtualScrollItemHeight: undefined, - sortable: true, - sortClass: undefined, - silentSort: true, - sortName: undefined, - sortOrder: 'asc', - sortStable: false, - rememberOrder: false, - serverSort: true, - customSort: undefined, - columns: [[]], - data: [], - url: undefined, - method: 'get', - cache: true, - contentType: 'application/json', - dataType: 'json', - ajax: undefined, - ajaxOptions: {}, - queryParams: function queryParams(params) { - return params; - }, - queryParamsType: 'limit', - // 'limit', undefined - responseHandler: function responseHandler(res) { - return res; - }, - totalField: 'total', - totalNotFilteredField: 'totalNotFiltered', - dataField: 'rows', - pagination: false, - onlyInfoPagination: false, - showExtendedPagination: false, - paginationLoop: true, - sidePagination: 'client', - // client or server - totalRows: 0, - totalNotFiltered: 0, - pageNumber: 1, - pageSize: 10, - pageList: [10, 25, 50, 100], - paginationHAlign: 'right', - // right, left - paginationVAlign: 'bottom', - // bottom, top, both - paginationDetailHAlign: 'left', - // right, left - paginationPreText: '‹', - paginationNextText: '›', - paginationSuccessivelySize: 5, - // Maximum successively number of pages in a row - paginationPagesBySide: 1, - // Number of pages on each side (right, left) of the current page. - paginationUseIntermediate: false, - // Calculate intermediate pages for quick access - search: false, - searchOnEnterKey: false, - strictSearch: false, - visibleSearch: false, - showButtonIcons: true, - showButtonText: false, - showSearchButton: false, - showSearchClearButton: false, - trimOnSearch: true, - searchAlign: 'right', - searchTimeOut: 500, - searchText: '', - customSearch: undefined, - showHeader: true, - showFooter: false, - footerStyle: function footerStyle(column) { - return {}; - }, - showColumns: false, - showColumnsToggleAll: false, - showColumnsSearch: false, - minimumCountColumns: 1, - showPaginationSwitch: false, - showRefresh: false, - showToggle: false, - showFullscreen: false, - smartDisplay: true, - escape: false, - filterOptions: { - filterAlgorithm: 'and' - }, - idField: undefined, - selectItemName: 'btSelectItem', - clickToSelect: false, - ignoreClickToSelectOn: function ignoreClickToSelectOn(_ref) { - var tagName = _ref.tagName; - return ['A', 'BUTTON'].includes(tagName); - }, - singleSelect: false, - checkboxHeader: true, - maintainMetaData: false, - multipleSelectRow: false, - uniqueId: undefined, - cardView: false, - detailView: false, - detailViewIcon: true, - detailViewByClick: false, - detailFormatter: function detailFormatter(index, row) { - return ''; - }, - detailFilter: function detailFilter(index, row) { - return true; - }, - toolbar: undefined, - toolbarAlign: 'left', - buttonsToolbar: undefined, - buttonsAlign: 'right', - buttonsOrder: ['paginationSwitch', 'refresh', 'toggle', 'fullscreen', 'columns'], - buttonsPrefix: CONSTANTS.classes.buttonsPrefix, - buttonsClass: CONSTANTS.classes.buttons, - icons: CONSTANTS.icons, - html: CONSTANTS.html, - iconSize: undefined, - iconsPrefix: CONSTANTS.iconsPrefix, - // glyphicon or fa(font-awesome) - onAll: function onAll(name, args) { - return false; - }, - onClickCell: function onClickCell(field, value, row, $element) { - return false; - }, - onDblClickCell: function onDblClickCell(field, value, row, $element) { - return false; - }, - onClickRow: function onClickRow(item, $element) { - return false; - }, - onDblClickRow: function onDblClickRow(item, $element) { - return false; - }, - onSort: function onSort(name, order) { - return false; - }, - onCheck: function onCheck(row) { - return false; - }, - onUncheck: function onUncheck(row) { - return false; - }, - onCheckAll: function onCheckAll(rows) { - return false; - }, - onUncheckAll: function onUncheckAll(rows) { - return false; - }, - onCheckSome: function onCheckSome(rows) { - return false; - }, - onUncheckSome: function onUncheckSome(rows) { - return false; - }, - onLoadSuccess: function onLoadSuccess(data) { - return false; - }, - onLoadError: function onLoadError(status) { - return false; - }, - onColumnSwitch: function onColumnSwitch(field, checked) { - return false; - }, - onPageChange: function onPageChange(number, size) { - return false; - }, - onSearch: function onSearch(text) { - return false; - }, - onToggle: function onToggle(cardView) { - return false; - }, - onPreBody: function onPreBody(data) { - return false; - }, - onPostBody: function onPostBody() { - return false; - }, - onPostHeader: function onPostHeader() { - return false; - }, - onPostFooter: function onPostFooter() { - return false; - }, - onExpandRow: function onExpandRow(index, row, $detail) { - return false; - }, - onCollapseRow: function onCollapseRow(index, row) { - return false; - }, - onRefreshOptions: function onRefreshOptions(options) { - return false; - }, - onRefresh: function onRefresh(params) { - return false; - }, - onResetView: function onResetView() { - return false; - }, - onScrollBody: function onScrollBody() { - return false; - } + height: undefined, + classes: 'table table-bordered table-hover', + theadClasses: '', + headerStyle: function headerStyle(column) { + return {}; + }, + rowStyle: function rowStyle(row, index) { + return {}; + }, + rowAttributes: function rowAttributes(row, index) { + return {}; + }, + undefinedText: '-', + locale: undefined, + virtualScroll: false, + virtualScrollItemHeight: undefined, + sortable: true, + sortClass: undefined, + silentSort: true, + sortName: undefined, + sortOrder: 'asc', + sortStable: false, + rememberOrder: false, + serverSort: true, + customSort: undefined, + columns: [[]], + data: [], + url: undefined, + method: 'get', + cache: true, + contentType: 'application/json', + dataType: 'json', + ajax: undefined, + ajaxOptions: {}, + queryParams: function queryParams(params) { + return params; + }, + queryParamsType: 'limit', + // 'limit', undefined + responseHandler: function responseHandler(res) { + return res; + }, + totalField: 'total', + totalNotFilteredField: 'totalNotFiltered', + dataField: 'rows', + pagination: false, + onlyInfoPagination: false, + showExtendedPagination: false, + paginationLoop: true, + sidePagination: 'client', + // client or server + totalRows: 0, + totalNotFiltered: 0, + pageNumber: 1, + pageSize: 10, + pageList: [10, 25, 50, 100], + paginationHAlign: 'right', + // right, left + paginationVAlign: 'bottom', + // bottom, top, both + paginationDetailHAlign: 'left', + // right, left + paginationPreText: '‹', + paginationNextText: '›', + paginationSuccessivelySize: 5, + // Maximum successively number of pages in a row + paginationPagesBySide: 1, + // Number of pages on each side (right, left) of the current page. + paginationUseIntermediate: false, + // Calculate intermediate pages for quick access + search: false, + searchOnEnterKey: false, + strictSearch: false, + visibleSearch: false, + showButtonIcons: true, + showButtonText: false, + showSearchButton: false, + showSearchClearButton: false, + trimOnSearch: true, + searchAlign: 'right', + searchTimeOut: 500, + searchText: '', + customSearch: undefined, + showHeader: true, + showFooter: false, + footerStyle: function footerStyle(column) { + return {}; + }, + showColumns: false, + showColumnsToggleAll: false, + showColumnsSearch: false, + minimumCountColumns: 1, + showPaginationSwitch: false, + showRefresh: false, + showToggle: false, + showFullscreen: false, + smartDisplay: true, + escape: false, + filterOptions: { + filterAlgorithm: 'and' + }, + idField: undefined, + selectItemName: 'btSelectItem', + clickToSelect: false, + ignoreClickToSelectOn: function ignoreClickToSelectOn(_ref) { + var tagName = _ref.tagName; + return ['A', 'BUTTON'].includes(tagName); + }, + singleSelect: false, + checkboxHeader: true, + maintainMetaData: false, + multipleSelectRow: false, + uniqueId: undefined, + cardView: false, + detailView: false, + detailViewIcon: true, + detailViewByClick: false, + detailFormatter: function detailFormatter(index, row) { + return ''; + }, + detailFilter: function detailFilter(index, row) { + return true; + }, + toolbar: undefined, + toolbarAlign: 'left', + buttonsToolbar: undefined, + buttonsAlign: 'right', + buttonsOrder: ['paginationSwitch', 'refresh', 'toggle', 'fullscreen', 'columns'], + buttonsPrefix: CONSTANTS.classes.buttonsPrefix, + buttonsClass: CONSTANTS.classes.buttons, + icons: CONSTANTS.icons, + html: CONSTANTS.html, + iconSize: undefined, + iconsPrefix: CONSTANTS.iconsPrefix, + // glyphicon or fa(font-awesome) + onAll: function onAll(name, args) { + return false; + }, + onClickCell: function onClickCell(field, value, row, $element) { + return false; + }, + onDblClickCell: function onDblClickCell(field, value, row, $element) { + return false; + }, + onClickRow: function onClickRow(item, $element) { + return false; + }, + onDblClickRow: function onDblClickRow(item, $element) { + return false; + }, + onSort: function onSort(name, order) { + return false; + }, + onCheck: function onCheck(row) { + return false; + }, + onUncheck: function onUncheck(row) { + return false; + }, + onCheckAll: function onCheckAll(rows) { + return false; + }, + onUncheckAll: function onUncheckAll(rows) { + return false; + }, + onCheckSome: function onCheckSome(rows) { + return false; + }, + onUncheckSome: function onUncheckSome(rows) { + return false; + }, + onLoadSuccess: function onLoadSuccess(data) { + return false; + }, + onLoadError: function onLoadError(status) { + return false; + }, + onColumnSwitch: function onColumnSwitch(field, checked) { + return false; + }, + onPageChange: function onPageChange(number, size) { + return false; + }, + onSearch: function onSearch(text) { + return false; + }, + onToggle: function onToggle(cardView) { + return false; + }, + onPreBody: function onPreBody(data) { + return false; + }, + onPostBody: function onPostBody() { + return false; + }, + onPostHeader: function onPostHeader() { + return false; + }, + onPostFooter: function onPostFooter() { + return false; + }, + onExpandRow: function onExpandRow(index, row, $detail) { + return false; + }, + onCollapseRow: function onCollapseRow(index, row) { + return false; + }, + onRefreshOptions: function onRefreshOptions(options) { + return false; + }, + onRefresh: function onRefresh(params) { + return false; + }, + onResetView: function onResetView() { + return false; + }, + onScrollBody: function onScrollBody() { + return false; + } }; var EN = { - formatLoadingMessage: function formatLoadingMessage() { - return 'Loading, please wait'; - }, - formatRecordsPerPage: function formatRecordsPerPage(pageNumber) { - return "".concat(pageNumber, " rows per page"); - }, - formatShowingRows: function formatShowingRows(pageFrom, pageTo, totalRows, totalNotFiltered) { - if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered > totalRows) { - return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows (filtered from ").concat(totalNotFiltered, " total rows)"); - } - - return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows"); - }, - formatSRPaginationPreText: function formatSRPaginationPreText() { - return 'previous page'; - }, - formatSRPaginationPageText: function formatSRPaginationPageText(page) { - return "to page ".concat(page); - }, - formatSRPaginationNextText: function formatSRPaginationNextText() { - return 'next page'; - }, - formatDetailPagination: function formatDetailPagination(totalRows) { - return "Showing ".concat(totalRows, " rows"); - }, - formatSearch: function formatSearch() { - return 'Search'; - }, - formatClearSearch: function formatClearSearch() { - return 'Clear Search'; - }, - formatNoMatches: function formatNoMatches() { - return 'No matching records found'; - }, - formatPaginationSwitch: function formatPaginationSwitch() { - return 'Hide/Show pagination'; - }, - formatPaginationSwitchDown: function formatPaginationSwitchDown() { - return 'Show pagination'; - }, - formatPaginationSwitchUp: function formatPaginationSwitchUp() { - return 'Hide pagination'; - }, - formatRefresh: function formatRefresh() { - return 'Refresh'; - }, - formatToggle: function formatToggle() { - return 'Toggle'; - }, - formatToggleOn: function formatToggleOn() { - return 'Show card view'; - }, - formatToggleOff: function formatToggleOff() { - return 'Hide card view'; - }, - formatColumns: function formatColumns() { - return 'Columns'; - }, - formatColumnsToggleAll: function formatColumnsToggleAll() { - return 'Toggle all'; - }, - formatFullscreen: function formatFullscreen() { - return 'Fullscreen'; - }, - formatAllRows: function formatAllRows() { - return 'All'; - } + formatLoadingMessage: function formatLoadingMessage() { + return 'Loading, please wait'; + }, + formatRecordsPerPage: function formatRecordsPerPage(pageNumber) { + return "".concat(pageNumber, " rows per page"); + }, + formatShowingRows: function formatShowingRows(pageFrom, pageTo, totalRows, totalNotFiltered) { + if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered > totalRows) { + return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows (filtered from ").concat(totalNotFiltered, " total rows)"); + } + + return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows"); + }, + formatSRPaginationPreText: function formatSRPaginationPreText() { + return 'previous page'; + }, + formatSRPaginationPageText: function formatSRPaginationPageText(page) { + return "to page ".concat(page); + }, + formatSRPaginationNextText: function formatSRPaginationNextText() { + return 'next page'; + }, + formatDetailPagination: function formatDetailPagination(totalRows) { + return "Showing ".concat(totalRows, " rows"); + }, + formatSearch: function formatSearch() { + return 'Search'; + }, + formatClearSearch: function formatClearSearch() { + return 'Clear Search'; + }, + formatNoMatches: function formatNoMatches() { + return 'No matching records found'; + }, + formatPaginationSwitch: function formatPaginationSwitch() { + return 'Hide/Show pagination'; + }, + formatPaginationSwitchDown: function formatPaginationSwitchDown() { + return 'Show pagination'; + }, + formatPaginationSwitchUp: function formatPaginationSwitchUp() { + return 'Hide pagination'; + }, + formatRefresh: function formatRefresh() { + return 'Refresh'; + }, + formatToggle: function formatToggle() { + return 'Toggle'; + }, + formatToggleOn: function formatToggleOn() { + return 'Show card view'; + }, + formatToggleOff: function formatToggleOff() { + return 'Hide card view'; + }, + formatColumns: function formatColumns() { + return 'Columns'; + }, + formatColumnsToggleAll: function formatColumnsToggleAll() { + return 'Toggle all'; + }, + formatFullscreen: function formatFullscreen() { + return 'Fullscreen'; + }, + formatAllRows: function formatAllRows() { + return 'All'; + } }; var COLUMN_DEFAULTS = { - field: undefined, - title: undefined, - titleTooltip: undefined, - 'class': undefined, - width: undefined, - widthUnit: 'px', - rowspan: undefined, - colspan: undefined, - align: undefined, - // left, right, center - halign: undefined, - // left, right, center - falign: undefined, - // left, right, center - valign: undefined, - // top, middle, bottom - cellStyle: undefined, - radio: false, - checkbox: false, - checkboxEnabled: true, - clickToSelect: true, - showSelectTitle: false, - sortable: false, - sortName: undefined, - order: 'asc', - // asc, desc - sorter: undefined, - visible: true, - switchable: true, - cardVisible: true, - searchable: true, - formatter: undefined, - footerFormatter: undefined, - detailFormatter: undefined, - searchFormatter: true, - escape: false, - events: undefined + field: undefined, + title: undefined, + titleTooltip: undefined, + 'class': undefined, + width: undefined, + widthUnit: 'px', + rowspan: undefined, + colspan: undefined, + align: undefined, + // left, right, center + halign: undefined, + // left, right, center + falign: undefined, + // left, right, center + valign: undefined, + // top, middle, bottom + cellStyle: undefined, + radio: false, + checkbox: false, + checkboxEnabled: true, + clickToSelect: true, + showSelectTitle: false, + sortable: false, + sortName: undefined, + order: 'asc', + // asc, desc + sorter: undefined, + visible: true, + switchable: true, + cardVisible: true, + searchable: true, + formatter: undefined, + footerFormatter: undefined, + detailFormatter: undefined, + searchFormatter: true, + escape: false, + events: undefined }; var METHODS = ['getOptions', 'refreshOptions', 'getData', 'getSelections', 'getAllSelections', 'load', 'append', 'prepend', 'remove', 'removeAll', 'insertRow', 'updateRow', 'getRowByUniqueId', 'updateByUniqueId', 'removeByUniqueId', 'updateCell', 'updateCellByUniqueId', 'showRow', 'hideRow', 'getHiddenRows', 'showColumn', 'hideColumn', 'getVisibleColumns', 'getHiddenColumns', 'showAllColumns', 'hideAllColumns', 'mergeCells', 'checkAll', 'uncheckAll', 'checkInvert', 'check', 'uncheck', 'checkBy', 'uncheckBy', 'refresh', 'destroy', 'resetView', 'showLoading', 'hideLoading', 'togglePagination', 'toggleFullscreen', 'toggleView', 'resetSearch', 'filterBy', 'scrollTo', 'getScrollPosition', 'selectPage', 'prevPage', 'nextPage', 'toggleDetailView', 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows', 'updateColumnTitle', 'updateFormatText']; var EVENTS = { - 'all.bs.table': 'onAll', - 'click-row.bs.table': 'onClickRow', - 'dbl-click-row.bs.table': 'onDblClickRow', - 'click-cell.bs.table': 'onClickCell', - 'dbl-click-cell.bs.table': 'onDblClickCell', - 'sort.bs.table': 'onSort', - 'check.bs.table': 'onCheck', - 'uncheck.bs.table': 'onUncheck', - 'check-all.bs.table': 'onCheckAll', - 'uncheck-all.bs.table': 'onUncheckAll', - 'check-some.bs.table': 'onCheckSome', - 'uncheck-some.bs.table': 'onUncheckSome', - 'load-success.bs.table': 'onLoadSuccess', - 'load-error.bs.table': 'onLoadError', - 'column-switch.bs.table': 'onColumnSwitch', - 'page-change.bs.table': 'onPageChange', - 'search.bs.table': 'onSearch', - 'toggle.bs.table': 'onToggle', - 'pre-body.bs.table': 'onPreBody', - 'post-body.bs.table': 'onPostBody', - 'post-header.bs.table': 'onPostHeader', - 'post-footer.bs.table': 'onPostFooter', - 'expand-row.bs.table': 'onExpandRow', - 'collapse-row.bs.table': 'onCollapseRow', - 'refresh-options.bs.table': 'onRefreshOptions', - 'reset-view.bs.table': 'onResetView', - 'refresh.bs.table': 'onRefresh', - 'scroll-body.bs.table': 'onScrollBody' + 'all.bs.table': 'onAll', + 'click-row.bs.table': 'onClickRow', + 'dbl-click-row.bs.table': 'onDblClickRow', + 'click-cell.bs.table': 'onClickCell', + 'dbl-click-cell.bs.table': 'onDblClickCell', + 'sort.bs.table': 'onSort', + 'check.bs.table': 'onCheck', + 'uncheck.bs.table': 'onUncheck', + 'check-all.bs.table': 'onCheckAll', + 'uncheck-all.bs.table': 'onUncheckAll', + 'check-some.bs.table': 'onCheckSome', + 'uncheck-some.bs.table': 'onUncheckSome', + 'load-success.bs.table': 'onLoadSuccess', + 'load-error.bs.table': 'onLoadError', + 'column-switch.bs.table': 'onColumnSwitch', + 'page-change.bs.table': 'onPageChange', + 'search.bs.table': 'onSearch', + 'toggle.bs.table': 'onToggle', + 'pre-body.bs.table': 'onPreBody', + 'post-body.bs.table': 'onPostBody', + 'post-header.bs.table': 'onPostHeader', + 'post-footer.bs.table': 'onPostFooter', + 'expand-row.bs.table': 'onExpandRow', + 'collapse-row.bs.table': 'onCollapseRow', + 'refresh-options.bs.table': 'onRefreshOptions', + 'reset-view.bs.table': 'onResetView', + 'refresh.bs.table': 'onRefresh', + 'scroll-body.bs.table': 'onScrollBody' }; Object.assign(DEFAULTS, EN); var Constants = { - VERSION: VERSION, - THEME: "bootstrap".concat(bootstrapVersion), - CONSTANTS: CONSTANTS, - DEFAULTS: DEFAULTS, - COLUMN_DEFAULTS: COLUMN_DEFAULTS, - METHODS: METHODS, - EVENTS: EVENTS, - LOCALES: { - en: EN, - 'en-US': EN - } + VERSION: VERSION, + THEME: "bootstrap".concat(bootstrapVersion), + CONSTANTS: CONSTANTS, + DEFAULTS: DEFAULTS, + COLUMN_DEFAULTS: COLUMN_DEFAULTS, + METHODS: METHODS, + EVENTS: EVENTS, + LOCALES: { + en: EN, + 'en-US': EN + } }; var FAILS_ON_PRIMITIVES = fails(function () { objectKeys(1); }); @@ -3338,3814 +3695,3814 @@ // `Object.keys` method // https://tc39.github.io/ecma262/#sec-object.keys _export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, { - keys: function keys(it) { - return objectKeys(toObject(it)); - } + keys: function keys(it) { + return objectKeys(toObject(it)); + } }); var Utils = { - // it only does '%s', and return '' when arguments are undefined - sprintf: function sprintf(_str) { - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } - - var flag = true; - var i = 0; - - var str = _str.replace(/%s/g, function () { - var arg = args[i++]; - - if (typeof arg === 'undefined') { - flag = false; - return ''; - } - - return arg; - }); - - return flag ? str : ''; - }, - isEmptyObject: function isEmptyObject() { - var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - return Object.entries(obj).length === 0 && obj.constructor === Object; - }, - isNumeric: function isNumeric(n) { - return !isNaN(parseFloat(n)) && isFinite(n); - }, - getFieldTitle: function getFieldTitle(list, value) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var item = _step.value; - - if (item.field === value) { - return item.title; - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return ''; - }, - setFieldIndex: function setFieldIndex(columns) { - var totalCol = 0; - var flag = []; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = columns[0][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var column = _step2.value; - totalCol += column.colspan || 1; - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - for (var i = 0; i < columns.length; i++) { - flag[i] = []; - - for (var j = 0; j < totalCol; j++) { - flag[i][j] = false; - } - } - - for (var _i = 0; _i < columns.length; _i++) { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = columns[_i][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var r = _step3.value; - var rowspan = r.rowspan || 1; - var colspan = r.colspan || 1; - - var index = flag[_i].indexOf(false); - - r.colspanIndex = index; - - if (colspan === 1) { - r.fieldIndex = index; // when field is undefined, use index instead - - if (typeof r.field === 'undefined') { - r.field = index; - } - } else { - r.colspanGroup = r.colspan; - } - - for (var k = 0; k < rowspan; k++) { - flag[_i + k][index] = true; - } - - for (var _k = 0; _k < colspan; _k++) { - flag[_i][index + _k] = true; - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - } - }, - updateFieldGroup: function updateFieldGroup(columns) { - var _ref; - - var allColumns = (_ref = []).concat.apply(_ref, _toConsumableArray(columns)); - - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = columns[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var c = _step4.value; - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = c[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var r = _step5.value; - - if (r.colspanGroup > 1) { - var colspan = 0; - - var _loop = function _loop(i) { - var column = allColumns.find(function (col) { - return col.fieldIndex === i; - }); - - if (column.visible) { - colspan++; - } - }; - - for (var i = r.colspanIndex; i < r.colspanIndex + r.colspanGroup; i++) { - _loop(i); - } - - r.colspan = colspan; - r.visible = colspan > 0; - } - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5.return != null) { - _iterator5.return(); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4.return != null) { - _iterator4.return(); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - }, - getScrollBarWidth: function getScrollBarWidth() { - if (this.cachedWidth === undefined) { - var $inner = $('
    ').addClass('fixed-table-scroll-inner'); - var $outer = $('
    ').addClass('fixed-table-scroll-outer'); - $outer.append($inner); - $('body').append($outer); - var w1 = $inner[0].offsetWidth; - $outer.css('overflow', 'scroll'); - var w2 = $inner[0].offsetWidth; - - if (w1 === w2) { - w2 = $outer[0].clientWidth; - } - - $outer.remove(); - this.cachedWidth = w1 - w2; - } - - return this.cachedWidth; - }, - calculateObjectValue: function calculateObjectValue(self, name, args, defaultValue) { - var func = name; - - if (typeof name === 'string') { - // support obj.func1.func2 - var names = name.split('.'); - - if (names.length > 1) { - func = window; - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = names[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var f = _step6.value; - func = func[f]; - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6.return != null) { - _iterator6.return(); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - } else { - func = window[name]; - } - } - - if (func !== null && _typeof(func) === 'object') { - return func; - } - - if (typeof func === 'function') { - return func.apply(self, args || []); - } - - if (!func && typeof name === 'string' && this.sprintf.apply(this, [name].concat(_toConsumableArray(args)))) { - return this.sprintf.apply(this, [name].concat(_toConsumableArray(args))); - } - - return defaultValue; - }, - compareObjects: function compareObjects(objectA, objectB, compareLength) { - var aKeys = Object.keys(objectA); - var bKeys = Object.keys(objectB); - - if (compareLength && aKeys.length !== bKeys.length) { - return false; - } - - for (var _i2 = 0, _aKeys = aKeys; _i2 < _aKeys.length; _i2++) { - var key = _aKeys[_i2]; - - if (bKeys.includes(key) && objectA[key] !== objectB[key]) { - return false; - } - } - - return true; - }, - escapeHTML: function escapeHTML(text) { - if (typeof text === 'string') { - return text.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/`/g, '`'); - } - - return text; - }, - getRealDataAttr: function getRealDataAttr(dataAttr) { - for (var _i3 = 0, _Object$entries = Object.entries(dataAttr); _i3 < _Object$entries.length; _i3++) { - var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2), - attr = _Object$entries$_i[0], - value = _Object$entries$_i[1]; - - var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase(); - - if (auxAttr !== attr) { - dataAttr[auxAttr] = value; - delete dataAttr[attr]; - } - } - - return dataAttr; - }, - getItemField: function getItemField(item, field, escape) { - var value = item; - - if (typeof field !== 'string' || item.hasOwnProperty(field)) { - return escape ? this.escapeHTML(item[field]) : item[field]; - } - - var props = field.split('.'); - var _iteratorNormalCompletion7 = true; - var _didIteratorError7 = false; - var _iteratorError7 = undefined; - - try { - for (var _iterator7 = props[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { - var p = _step7.value; - value = value && value[p]; - } - } catch (err) { - _didIteratorError7 = true; - _iteratorError7 = err; - } finally { - try { - if (!_iteratorNormalCompletion7 && _iterator7.return != null) { - _iterator7.return(); - } - } finally { - if (_didIteratorError7) { - throw _iteratorError7; - } - } - } - - return escape ? this.escapeHTML(value) : value; - }, - isIEBrowser: function isIEBrowser() { - return navigator.userAgent.includes('MSIE ') || /Trident.*rv:11\./.test(navigator.userAgent); - }, - findIndex: function findIndex(items, item) { - var _iteratorNormalCompletion8 = true; - var _didIteratorError8 = false; - var _iteratorError8 = undefined; - - try { - for (var _iterator8 = items[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { - var it = _step8.value; - - if (JSON.stringify(it) === JSON.stringify(item)) { - return items.indexOf(it); - } - } - } catch (err) { - _didIteratorError8 = true; - _iteratorError8 = err; - } finally { - try { - if (!_iteratorNormalCompletion8 && _iterator8.return != null) { - _iterator8.return(); - } - } finally { - if (_didIteratorError8) { - throw _iteratorError8; - } - } - } - - return -1; - }, - trToData: function trToData(columns, $els) { - var _this = this; - - var data = []; - var m = []; - $els.each(function (y, el) { - var row = {}; // save tr's id, class and data-* attributes - - row._id = $(el).attr('id'); - row._class = $(el).attr('class'); - row._data = _this.getRealDataAttr($(el).data()); - $(el).find('>td,>th').each(function (_x, el) { - var cspan = +$(el).attr('colspan') || 1; - var rspan = +$(el).attr('rowspan') || 1; - var x = _x; // skip already occupied cells in current row - - for (; m[y] && m[y][x]; x++) {} // ignore - // mark matrix elements occupied by current cell with true - - - for (var tx = x; tx < x + cspan; tx++) { - for (var ty = y; ty < y + rspan; ty++) { - if (!m[ty]) { - // fill missing rows - m[ty] = []; - } - - m[ty][tx] = true; - } - } - - var field = columns[x].field; - row[field] = $(el).html().trim(); // save td's id, class and data-* attributes - - row["_".concat(field, "_id")] = $(el).attr('id'); - row["_".concat(field, "_class")] = $(el).attr('class'); - row["_".concat(field, "_rowspan")] = $(el).attr('rowspan'); - row["_".concat(field, "_colspan")] = $(el).attr('colspan'); - row["_".concat(field, "_title")] = $(el).attr('title'); - row["_".concat(field, "_data")] = _this.getRealDataAttr($(el).data()); - }); - data.push(row); - }); - return data; - }, - sort: function sort(a, b, order, sortStable, aPosition, bPosition) { - if (a === undefined || a === null) { - a = ''; - } - - if (b === undefined || b === null) { - b = ''; - } - - if (sortStable && a === b) { - a = aPosition; - b = bPosition; - } // If both values are numeric, do a numeric comparison - - - if (this.isNumeric(a) && this.isNumeric(b)) { - // Convert numerical values form string to float. - a = parseFloat(a); - b = parseFloat(b); - - if (a < b) { - return order * -1; - } - - if (a > b) { - return order; - } - - return 0; - } - - if (a === b) { - return 0; - } // If value is not a string, convert to string - - - if (typeof a !== 'string') { - a = a.toString(); - } - - if (a.localeCompare(b) === -1) { - return order * -1; - } - - return order; - }, - getResizeEventName: function getResizeEventName() { - var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - id = id || "".concat(+new Date()).concat(~~(Math.random() * 1000000)); - return "resize.bootstrap-table-".concat(id); - } + // it only does '%s', and return '' when arguments are undefined + sprintf: function sprintf(_str) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var flag = true; + var i = 0; + + var str = _str.replace(/%s/g, function () { + var arg = args[i++]; + + if (typeof arg === 'undefined') { + flag = false; + return ''; + } + + return arg; + }); + + return flag ? str : ''; + }, + isEmptyObject: function isEmptyObject() { + var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return Object.entries(obj).length === 0 && obj.constructor === Object; + }, + isNumeric: function isNumeric(n) { + return !isNaN(parseFloat(n)) && isFinite(n); + }, + getFieldTitle: function getFieldTitle(list, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var item = _step.value; + + if (item.field === value) { + return item.title; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return ''; + }, + setFieldIndex: function setFieldIndex(columns) { + var totalCol = 0; + var flag = []; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = columns[0][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var column = _step2.value; + totalCol += column.colspan || 1; + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return != null) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + for (var i = 0; i < columns.length; i++) { + flag[i] = []; + + for (var j = 0; j < totalCol; j++) { + flag[i][j] = false; + } + } + + for (var _i = 0; _i < columns.length; _i++) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = columns[_i][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var r = _step3.value; + var rowspan = r.rowspan || 1; + var colspan = r.colspan || 1; + + var index = flag[_i].indexOf(false); + + r.colspanIndex = index; + + if (colspan === 1) { + r.fieldIndex = index; // when field is undefined, use index instead + + if (typeof r.field === 'undefined') { + r.field = index; + } + } else { + r.colspanGroup = r.colspan; + } + + for (var k = 0; k < rowspan; k++) { + flag[_i + k][index] = true; + } + + for (var _k = 0; _k < colspan; _k++) { + flag[_i][index + _k] = true; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return != null) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + } + }, + updateFieldGroup: function updateFieldGroup(columns) { + var _ref; + + var allColumns = (_ref = []).concat.apply(_ref, _toConsumableArray(columns)); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = columns[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var c = _step4.value; + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = c[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var r = _step5.value; + + if (r.colspanGroup > 1) { + var colspan = 0; + + var _loop = function _loop(i) { + var column = allColumns.find(function (col) { + return col.fieldIndex === i; + }); + + if (column.visible) { + colspan++; + } + }; + + for (var i = r.colspanIndex; i < r.colspanIndex + r.colspanGroup; i++) { + _loop(i); + } + + r.colspan = colspan; + r.visible = colspan > 0; + } + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return != null) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return != null) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + }, + getScrollBarWidth: function getScrollBarWidth() { + if (this.cachedWidth === undefined) { + var $inner = $('
    ').addClass('fixed-table-scroll-inner'); + var $outer = $('
    ').addClass('fixed-table-scroll-outer'); + $outer.append($inner); + $('body').append($outer); + var w1 = $inner[0].offsetWidth; + $outer.css('overflow', 'scroll'); + var w2 = $inner[0].offsetWidth; + + if (w1 === w2) { + w2 = $outer[0].clientWidth; + } + + $outer.remove(); + this.cachedWidth = w1 - w2; + } + + return this.cachedWidth; + }, + calculateObjectValue: function calculateObjectValue(self, name, args, defaultValue) { + var func = name; + + if (typeof name === 'string') { + // support obj.func1.func2 + var names = name.split('.'); + + if (names.length > 1) { + func = window; + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = names[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var f = _step6.value; + func = func[f]; + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6.return != null) { + _iterator6.return(); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + } else { + func = window[name]; + } + } + + if (func !== null && _typeof(func) === 'object') { + return func; + } + + if (typeof func === 'function') { + return func.apply(self, args || []); + } + + if (!func && typeof name === 'string' && this.sprintf.apply(this, [name].concat(_toConsumableArray(args)))) { + return this.sprintf.apply(this, [name].concat(_toConsumableArray(args))); + } + + return defaultValue; + }, + compareObjects: function compareObjects(objectA, objectB, compareLength) { + var aKeys = Object.keys(objectA); + var bKeys = Object.keys(objectB); + + if (compareLength && aKeys.length !== bKeys.length) { + return false; + } + + for (var _i2 = 0, _aKeys = aKeys; _i2 < _aKeys.length; _i2++) { + var key = _aKeys[_i2]; + + if (bKeys.includes(key) && objectA[key] !== objectB[key]) { + return false; + } + } + + return true; + }, + escapeHTML: function escapeHTML(text) { + if (typeof text === 'string') { + return text.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/`/g, '`'); + } + + return text; + }, + getRealDataAttr: function getRealDataAttr(dataAttr) { + for (var _i3 = 0, _Object$entries = Object.entries(dataAttr); _i3 < _Object$entries.length; _i3++) { + var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2), + attr = _Object$entries$_i[0], + value = _Object$entries$_i[1]; + + var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase(); + + if (auxAttr !== attr) { + dataAttr[auxAttr] = value; + delete dataAttr[attr]; + } + } + + return dataAttr; + }, + getItemField: function getItemField(item, field, escape) { + var value = item; + + if (typeof field !== 'string' || item.hasOwnProperty(field)) { + return escape ? this.escapeHTML(item[field]) : item[field]; + } + + var props = field.split('.'); + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = props[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var p = _step7.value; + value = value && value[p]; + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7.return != null) { + _iterator7.return(); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + return escape ? this.escapeHTML(value) : value; + }, + isIEBrowser: function isIEBrowser() { + return navigator.userAgent.includes('MSIE ') || /Trident.*rv:11\./.test(navigator.userAgent); + }, + findIndex: function findIndex(items, item) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = items[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var it = _step8.value; + + if (JSON.stringify(it) === JSON.stringify(item)) { + return items.indexOf(it); + } + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8.return != null) { + _iterator8.return(); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + + return -1; + }, + trToData: function trToData(columns, $els) { + var _this = this; + + var data = []; + var m = []; + $els.each(function (y, el) { + var row = {}; // save tr's id, class and data-* attributes + + row._id = $(el).attr('id'); + row._class = $(el).attr('class'); + row._data = _this.getRealDataAttr($(el).data()); + $(el).find('>td,>th').each(function (_x, el) { + var cspan = +$(el).attr('colspan') || 1; + var rspan = +$(el).attr('rowspan') || 1; + var x = _x; // skip already occupied cells in current row + + for (; m[y] && m[y][x]; x++) {} // ignore + // mark matrix elements occupied by current cell with true + + + for (var tx = x; tx < x + cspan; tx++) { + for (var ty = y; ty < y + rspan; ty++) { + if (!m[ty]) { + // fill missing rows + m[ty] = []; + } + + m[ty][tx] = true; + } + } + + var field = columns[x].field; + row[field] = $(el).html().trim(); // save td's id, class and data-* attributes + + row["_".concat(field, "_id")] = $(el).attr('id'); + row["_".concat(field, "_class")] = $(el).attr('class'); + row["_".concat(field, "_rowspan")] = $(el).attr('rowspan'); + row["_".concat(field, "_colspan")] = $(el).attr('colspan'); + row["_".concat(field, "_title")] = $(el).attr('title'); + row["_".concat(field, "_data")] = _this.getRealDataAttr($(el).data()); + }); + data.push(row); + }); + return data; + }, + sort: function sort(a, b, order, sortStable, aPosition, bPosition) { + if (a === undefined || a === null) { + a = ''; + } + + if (b === undefined || b === null) { + b = ''; + } + + if (sortStable && a === b) { + a = aPosition; + b = bPosition; + } // If both values are numeric, do a numeric comparison + + + if (this.isNumeric(a) && this.isNumeric(b)) { + // Convert numerical values form string to float. + a = parseFloat(a); + b = parseFloat(b); + + if (a < b) { + return order * -1; + } + + if (a > b) { + return order; + } + + return 0; + } + + if (a === b) { + return 0; + } // If value is not a string, convert to string + + + if (typeof a !== 'string') { + a = a.toString(); + } + + if (a.localeCompare(b) === -1) { + return order * -1; + } + + return order; + }, + getResizeEventName: function getResizeEventName() { + var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + id = id || "".concat(+new Date()).concat(~~(Math.random() * 1000000)); + return "resize.bootstrap-table-".concat(id); + } }; var BLOCK_ROWS = 50; var CLUSTER_BLOCKS = 4; var VirtualScroll = - /*#__PURE__*/ - function () { - function VirtualScroll(options) { - var _this = this; - - _classCallCheck(this, VirtualScroll); - - this.rows = options.rows; - this.scrollEl = options.scrollEl; - this.contentEl = options.contentEl; - this.callback = options.callback; - this.itemHeight = options.itemHeight; - this.cache = {}; - this.scrollTop = this.scrollEl.scrollTop; - this.initDOM(this.rows, options.fixedScroll); - this.scrollEl.scrollTop = this.scrollTop; - this.lastCluster = 0; - - var onScroll = function onScroll() { - if (_this.lastCluster !== (_this.lastCluster = _this.getNum())) { - _this.initDOM(_this.rows); - - _this.callback(); - } - }; - - this.scrollEl.addEventListener('scroll', onScroll, false); - - this.destroy = function () { - _this.contentEl.innerHtml = ''; - - _this.scrollEl.removeEventListener('scroll', onScroll, false); - }; - } - - _createClass(VirtualScroll, [{ - key: "initDOM", - value: function initDOM(rows, fixedScroll) { - if (typeof this.clusterHeight === 'undefined') { - this.cache.scrollTop = this.scrollEl.scrollTop; - this.cache.data = this.contentEl.innerHTML = rows[0] + rows[0] + rows[0]; - this.getRowsHeight(rows); - } - - var data = this.initData(rows, this.getNum(fixedScroll)); - var thisRows = data.rows.join(''); - var dataChanged = this.checkChanges('data', thisRows); - var topOffsetChanged = this.checkChanges('top', data.topOffset); - var bottomOffsetChanged = this.checkChanges('bottom', data.bottomOffset); - var html = []; - - if (dataChanged && topOffsetChanged) { - if (data.topOffset) { - html.push(this.getExtra('top', data.topOffset)); - } - - html.push(thisRows); - - if (data.bottomOffset) { - html.push(this.getExtra('bottom', data.bottomOffset)); - } - - this.contentEl.innerHTML = html.join(''); - - if (fixedScroll) { - this.contentEl.scrollTop = this.cache.scrollTop; - } - } else if (bottomOffsetChanged) { - this.contentEl.lastChild.style.height = "".concat(data.bottomOffset, "px"); - } - } - }, { - key: "getRowsHeight", - value: function getRowsHeight() { - if (typeof this.itemHeight === 'undefined') { - var nodes = this.contentEl.children; - var node = nodes[Math.floor(nodes.length / 2)]; - this.itemHeight = node.offsetHeight; - } - - this.blockHeight = this.itemHeight * BLOCK_ROWS; - this.clusterRows = BLOCK_ROWS * CLUSTER_BLOCKS; - this.clusterHeight = this.blockHeight * CLUSTER_BLOCKS; - } - }, { - key: "getNum", - value: function getNum(fixedScroll) { - this.scrollTop = fixedScroll ? this.cache.scrollTop : this.scrollEl.scrollTop; - return Math.floor(this.scrollTop / (this.clusterHeight - this.blockHeight)) || 0; - } - }, { - key: "initData", - value: function initData(rows, num) { - if (rows.length < BLOCK_ROWS) { - return { - topOffset: 0, - bottomOffset: 0, - rowsAbove: 0, - rows: rows - }; - } - - var start = Math.max((this.clusterRows - BLOCK_ROWS) * num, 0); - var end = start + this.clusterRows; - var topOffset = Math.max(start * this.itemHeight, 0); - var bottomOffset = Math.max((rows.length - end) * this.itemHeight, 0); - var thisRows = []; - var rowsAbove = start; - - if (topOffset < 1) { - rowsAbove++; - } - - for (var i = start; i < end; i++) { - rows[i] && thisRows.push(rows[i]); - } - - return { - topOffset: topOffset, - bottomOffset: bottomOffset, - rowsAbove: rowsAbove, - rows: thisRows - }; - } - }, { - key: "checkChanges", - value: function checkChanges(type, value) { - var changed = value !== this.cache[type]; - this.cache[type] = value; - return changed; - } - }, { - key: "getExtra", - value: function getExtra(className, height) { - var tag = document.createElement('tr'); - tag.className = "virtual-scroll-".concat(className); - - if (height) { - tag.style.height = "".concat(height, "px"); - } - - return tag.outerHTML; - } - }]); - - return VirtualScroll; - }(); + /*#__PURE__*/ + function () { + function VirtualScroll(options) { + var _this = this; + + _classCallCheck(this, VirtualScroll); + + this.rows = options.rows; + this.scrollEl = options.scrollEl; + this.contentEl = options.contentEl; + this.callback = options.callback; + this.itemHeight = options.itemHeight; + this.cache = {}; + this.scrollTop = this.scrollEl.scrollTop; + this.initDOM(this.rows, options.fixedScroll); + this.scrollEl.scrollTop = this.scrollTop; + this.lastCluster = 0; + + var onScroll = function onScroll() { + if (_this.lastCluster !== (_this.lastCluster = _this.getNum())) { + _this.initDOM(_this.rows); + + _this.callback(); + } + }; + + this.scrollEl.addEventListener('scroll', onScroll, false); + + this.destroy = function () { + _this.contentEl.innerHtml = ''; + + _this.scrollEl.removeEventListener('scroll', onScroll, false); + }; + } + + _createClass(VirtualScroll, [{ + key: "initDOM", + value: function initDOM(rows, fixedScroll) { + if (typeof this.clusterHeight === 'undefined') { + this.cache.scrollTop = this.scrollEl.scrollTop; + this.cache.data = this.contentEl.innerHTML = rows[0] + rows[0] + rows[0]; + this.getRowsHeight(rows); + } + + var data = this.initData(rows, this.getNum(fixedScroll)); + var thisRows = data.rows.join(''); + var dataChanged = this.checkChanges('data', thisRows); + var topOffsetChanged = this.checkChanges('top', data.topOffset); + var bottomOffsetChanged = this.checkChanges('bottom', data.bottomOffset); + var html = []; + + if (dataChanged && topOffsetChanged) { + if (data.topOffset) { + html.push(this.getExtra('top', data.topOffset)); + } + + html.push(thisRows); + + if (data.bottomOffset) { + html.push(this.getExtra('bottom', data.bottomOffset)); + } + + this.contentEl.innerHTML = html.join(''); + + if (fixedScroll) { + this.contentEl.scrollTop = this.cache.scrollTop; + } + } else if (bottomOffsetChanged) { + this.contentEl.lastChild.style.height = "".concat(data.bottomOffset, "px"); + } + } + }, { + key: "getRowsHeight", + value: function getRowsHeight() { + if (typeof this.itemHeight === 'undefined') { + var nodes = this.contentEl.children; + var node = nodes[Math.floor(nodes.length / 2)]; + this.itemHeight = node.offsetHeight; + } + + this.blockHeight = this.itemHeight * BLOCK_ROWS; + this.clusterRows = BLOCK_ROWS * CLUSTER_BLOCKS; + this.clusterHeight = this.blockHeight * CLUSTER_BLOCKS; + } + }, { + key: "getNum", + value: function getNum(fixedScroll) { + this.scrollTop = fixedScroll ? this.cache.scrollTop : this.scrollEl.scrollTop; + return Math.floor(this.scrollTop / (this.clusterHeight - this.blockHeight)) || 0; + } + }, { + key: "initData", + value: function initData(rows, num) { + if (rows.length < BLOCK_ROWS) { + return { + topOffset: 0, + bottomOffset: 0, + rowsAbove: 0, + rows: rows + }; + } + + var start = Math.max((this.clusterRows - BLOCK_ROWS) * num, 0); + var end = start + this.clusterRows; + var topOffset = Math.max(start * this.itemHeight, 0); + var bottomOffset = Math.max((rows.length - end) * this.itemHeight, 0); + var thisRows = []; + var rowsAbove = start; + + if (topOffset < 1) { + rowsAbove++; + } + + for (var i = start; i < end; i++) { + rows[i] && thisRows.push(rows[i]); + } + + return { + topOffset: topOffset, + bottomOffset: bottomOffset, + rowsAbove: rowsAbove, + rows: thisRows + }; + } + }, { + key: "checkChanges", + value: function checkChanges(type, value) { + var changed = value !== this.cache[type]; + this.cache[type] = value; + return changed; + } + }, { + key: "getExtra", + value: function getExtra(className, height) { + var tag = document.createElement('tr'); + tag.className = "virtual-scroll-".concat(className); + + if (height) { + tag.style.height = "".concat(height, "px"); + } + + return tag.outerHTML; + } + }]); + + return VirtualScroll; + }(); var BootstrapTable = - /*#__PURE__*/ - function () { - function BootstrapTable(el, options) { - _classCallCheck(this, BootstrapTable); - - this.options = options; - this.$el = $(el); - this.$el_ = this.$el.clone(); - this.timeoutId_ = 0; - this.timeoutFooter_ = 0; - this.init(); - } - - _createClass(BootstrapTable, [{ - key: "init", - value: function init() { - this.initConstants(); - this.initLocale(); - this.initContainer(); - this.initTable(); - this.initHeader(); - this.initData(); - this.initHiddenRows(); - this.initToolbar(); - this.initPagination(); - this.initBody(); - this.initSearchText(); - this.initServer(); - } - }, { - key: "initConstants", - value: function initConstants() { - var opts = this.options; - this.constants = Constants.CONSTANTS; - this.constants.theme = $.fn.bootstrapTable.theme; - var buttonsPrefix = opts.buttonsPrefix ? "".concat(opts.buttonsPrefix, "-") : ''; - this.constants.buttonsClass = [opts.buttonsPrefix, buttonsPrefix + opts.buttonsClass, Utils.sprintf("".concat(buttonsPrefix, "%s"), opts.iconSize)].join(' ').trim(); - } - }, { - key: "initLocale", - value: function initLocale() { - if (this.options.locale) { - var locales = $.fn.bootstrapTable.locales; - var parts = this.options.locale.split(/-|_/); - parts[0] = parts[0].toLowerCase(); - - if (parts[1]) { - parts[1] = parts[1].toUpperCase(); - } - - if (locales[this.options.locale]) { - $.extend(this.options, locales[this.options.locale]); - } else if (locales[parts.join('-')]) { - $.extend(this.options, locales[parts.join('-')]); - } else if (locales[parts[0]]) { - $.extend(this.options, locales[parts[0]]); - } - } - } - }, { - key: "initContainer", - value: function initContainer() { - var topPagination = ['top', 'both'].includes(this.options.paginationVAlign) ? '
    ' : ''; - var bottomPagination = ['bottom', 'both'].includes(this.options.paginationVAlign) ? '
    ' : ''; - this.$container = $("\n
    \n
    \n ").concat(topPagination, "\n
    \n
    \n
    \n
    \n \n ").concat(this.options.formatLoadingMessage(), "\n \n \n
    \n
    \n
    \n
    \n ").concat(bottomPagination, "\n
    \n ")); - this.$container.insertAfter(this.$el); - this.$tableContainer = this.$container.find('.fixed-table-container'); - this.$tableHeader = this.$container.find('.fixed-table-header'); - this.$tableBody = this.$container.find('.fixed-table-body'); - this.$tableLoading = this.$container.find('.fixed-table-loading'); - this.$tableFooter = this.$el.find('tfoot'); // checking if custom table-toolbar exists or not - - if (this.options.buttonsToolbar) { - this.$toolbar = $('body').find(this.options.buttonsToolbar); - } else { - this.$toolbar = this.$container.find('.fixed-table-toolbar'); - } - - this.$pagination = this.$container.find('.fixed-table-pagination'); - this.$tableBody.append(this.$el); - this.$container.after('
    '); - this.$el.addClass(this.options.classes); - this.$tableLoading.addClass(this.options.classes); - - if (this.options.height) { - this.$tableContainer.addClass('fixed-height'); - - if (this.options.showFooter) { - this.$tableContainer.addClass('has-footer'); - } - - if (this.options.classes.split(' ').includes('table-bordered')) { - this.$tableBody.append('
    '); - this.$tableBorder = this.$tableBody.find('.fixed-table-border'); - this.$tableLoading.addClass('fixed-table-border'); - } - - this.$tableFooter = this.$container.find('.fixed-table-footer'); - } - } - }, { - key: "initTable", - value: function initTable() { - var _this = this; - - var columns = []; - this.$header = this.$el.find('>thead'); - - if (!this.$header.length) { - this.$header = $("")).appendTo(this.$el); - } else if (this.options.theadClasses) { - this.$header.addClass(this.options.theadClasses); - } - - this.$header.find('tr').each(function (i, el) { - var column = []; - $(el).find('th').each(function (i, el) { - // #2014: getFieldIndex and elsewhere assume this is string, causes issues if not - if (typeof $(el).data('field') !== 'undefined') { - $(el).data('field', "".concat($(el).data('field'))); - } - - column.push($.extend({}, { - title: $(el).html(), - 'class': $(el).attr('class'), - titleTooltip: $(el).attr('title'), - rowspan: $(el).attr('rowspan') ? +$(el).attr('rowspan') : undefined, - colspan: $(el).attr('colspan') ? +$(el).attr('colspan') : undefined - }, $(el).data())); - }); - columns.push(column); - }); - - if (!Array.isArray(this.options.columns[0])) { - this.options.columns = [this.options.columns]; - } - - this.options.columns = $.extend(true, [], columns, this.options.columns); - this.columns = []; - this.fieldsColumnsIndex = []; - Utils.setFieldIndex(this.options.columns); - this.options.columns.forEach(function (columns, i) { - columns.forEach(function (_column, j) { - var column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, _column); - - if (typeof column.fieldIndex !== 'undefined') { - _this.columns[column.fieldIndex] = column; - _this.fieldsColumnsIndex[column.field] = column.fieldIndex; - } - - _this.options.columns[i][j] = column; - }); - }); // if options.data is setting, do not process tbody and tfoot data - - if (!this.options.data.length) { - this.options.data = Utils.trToData(this.columns, this.$el.find('>tbody>tr')); - - if (this.options.data.length) { - this.fromHtml = true; - } - } - - this.footerData = Utils.trToData(this.columns, this.$el.find('>tfoot>tr')); - - if (this.footerData) { - this.$el.find('tfoot').html(''); - } - - if (!this.options.showFooter || this.options.cardView) { - this.$tableFooter.hide(); - } else { - this.$tableFooter.show(); - } - } - }, { - key: "initHeader", - value: function initHeader() { - var _this2 = this; - - var visibleColumns = {}; - var html = []; - this.header = { - fields: [], - styles: [], - classes: [], - formatters: [], - detailFormatters: [], - events: [], - sorters: [], - sortNames: [], - cellStyles: [], - searchables: [] - }; - Utils.updateFieldGroup(this.options.columns); - this.options.columns.forEach(function (columns, i) { - html.push(''); - - if (i === 0 && !_this2.options.cardView && _this2.options.detailView && _this2.options.detailViewIcon) { - html.push("\n
    \n \n ")); - } - - columns.forEach(function (column, j) { - var class_ = Utils.sprintf(' class="%s"', column['class']); - var unitWidth = column.widthUnit; - var width = parseFloat(column.width); - var halign = Utils.sprintf('text-align: %s; ', column.halign ? column.halign : column.align); - var align = Utils.sprintf('text-align: %s; ', column.align); - var style = Utils.sprintf('vertical-align: %s; ', column.valign); - style += Utils.sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? !column.showSelectTitle ? '36px' : undefined : width ? width + unitWidth : undefined); - - if (typeof column.fieldIndex === 'undefined' && !column.visible) { - return; - } - - var headerStyle = Utils.calculateObjectValue(null, _this2.options.headerStyle, [column]); - var csses = []; - var classes = ''; - - if (headerStyle && headerStyle.css) { - for (var _i = 0, _Object$entries = Object.entries(headerStyle.css); _i < _Object$entries.length; _i++) { - var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), - key = _Object$entries$_i[0], - value = _Object$entries$_i[1]; - - csses.push("".concat(key, ": ").concat(value)); - } - } - - if (headerStyle && headerStyle.classes) { - classes = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], headerStyle.classes].join(' ') : headerStyle.classes); - } - - if (typeof column.fieldIndex !== 'undefined') { - _this2.header.fields[column.fieldIndex] = column.field; - _this2.header.styles[column.fieldIndex] = align + style; - _this2.header.classes[column.fieldIndex] = class_; - _this2.header.formatters[column.fieldIndex] = column.formatter; - _this2.header.detailFormatters[column.fieldIndex] = column.detailFormatter; - _this2.header.events[column.fieldIndex] = column.events; - _this2.header.sorters[column.fieldIndex] = column.sorter; - _this2.header.sortNames[column.fieldIndex] = column.sortName; - _this2.header.cellStyles[column.fieldIndex] = column.cellStyle; - _this2.header.searchables[column.fieldIndex] = column.searchable; - - if (!column.visible) { - return; - } - - if (_this2.options.cardView && !column.cardVisible) { - return; - } - - visibleColumns[column.field] = column; - } - - html.push(" 0 ? ' data-not-first-th' : '', '>'); - html.push(Utils.sprintf('
    ', _this2.options.sortable && column.sortable ? 'sortable both' : '')); - var text = _this2.options.escape ? Utils.escapeHTML(column.title) : column.title; - var title = text; - - if (column.checkbox) { - text = ''; - - if (!_this2.options.singleSelect && _this2.options.checkboxHeader) { - text = ''; - } - - _this2.header.stateField = column.field; - } - - if (column.radio) { - text = ''; - _this2.header.stateField = column.field; - } - - if (!text && column.showSelectTitle) { - text += title; - } - - html.push(text); - html.push('
    '); - html.push('
    '); - html.push('
    '); - html.push(''); - }); - html.push(''); - }); - this.$header.html(html.join('')); - this.$header.find('th[data-field]').each(function (i, el) { - $(el).data(visibleColumns[$(el).data('field')]); - }); - this.$container.off('click', '.th-inner').on('click', '.th-inner', function (e) { - var $this = $(e.currentTarget); - - if (_this2.options.detailView && !$this.parent().hasClass('bs-checkbox')) { - if ($this.closest('.bootstrap-table')[0] !== _this2.$container[0]) { - return false; - } - } - - if (_this2.options.sortable && $this.parent().data().sortable) { - _this2.onSort(e); - } - }); - this.$header.children().children().off('keypress').on('keypress', function (e) { - if (_this2.options.sortable && $(e.currentTarget).data().sortable) { - var code = e.keyCode || e.which; - - if (code === 13) { - // Enter keycode - _this2.onSort(e); - } - } - }); - var resizeEvent = Utils.getResizeEventName(this.$el.attr('id')); - $(window).off(resizeEvent); - - if (!this.options.showHeader || this.options.cardView) { - this.$header.hide(); - this.$tableHeader.hide(); - this.$tableLoading.css('top', 0); - } else { - this.$header.show(); - this.$tableHeader.show(); - this.$tableLoading.css('top', this.$header.outerHeight() + 1); // Assign the correct sortable arrow - - this.getCaret(); - $(window).on(resizeEvent, function () { - return _this2.resetView(); - }); - } - - this.$selectAll = this.$header.find('[name="btSelectAll"]'); - this.$selectAll.off('click').on('click', function (e) { - e.stopPropagation(); - var checked = $(e.currentTarget).prop('checked'); - - _this2[checked ? 'checkAll' : 'uncheckAll'](); - - _this2.updateSelected(); - }); - } - }, { - key: "initData", - value: function initData(data, type) { - if (type === 'append') { - this.options.data = this.options.data.concat(data); - } else if (type === 'prepend') { - this.options.data = [].concat(data).concat(this.options.data); - } else { - this.options.data = data || this.options.data; - } - - this.data = this.options.data; - - if (this.options.sidePagination === 'server') { - return; - } - - this.initSort(); - } - }, { - key: "initSort", - value: function initSort() { - var _this3 = this; - - var name = this.options.sortName; - var order = this.options.sortOrder === 'desc' ? -1 : 1; - var index = this.header.fields.indexOf(this.options.sortName); - var timeoutId = 0; - - if (index !== -1) { - if (this.options.sortStable) { - this.data.forEach(function (row, i) { - if (!row.hasOwnProperty('_position')) { - row._position = i; - } - }); - } - - if (this.options.customSort) { - Utils.calculateObjectValue(this.options, this.options.customSort, [this.options.sortName, this.options.sortOrder, this.data]); - } else { - this.data.sort(function (a, b) { - if (_this3.header.sortNames[index]) { - name = _this3.header.sortNames[index]; - } - - var aa = Utils.getItemField(a, name, _this3.options.escape); - var bb = Utils.getItemField(b, name, _this3.options.escape); - var value = Utils.calculateObjectValue(_this3.header, _this3.header.sorters[index], [aa, bb, a, b]); - - if (value !== undefined) { - if (_this3.options.sortStable && value === 0) { - return order * (a._position - b._position); - } - - return order * value; - } - - return Utils.sort(aa, bb, order, _this3.options.sortStable, a._position, b._position); - }); - } - - if (this.options.sortClass !== undefined) { - clearTimeout(timeoutId); - timeoutId = setTimeout(function () { - _this3.$el.removeClass(_this3.options.sortClass); - - var index = _this3.$header.find("[data-field=\"".concat(_this3.options.sortName, "\"]")).index(); - - _this3.$el.find("tr td:nth-child(".concat(index + 1, ")")).addClass(_this3.options.sortClass); - }, 250); - } - } - } - }, { - key: "onSort", - value: function onSort(_ref) { - var type = _ref.type, - currentTarget = _ref.currentTarget; - var $this = type === 'keypress' ? $(currentTarget) : $(currentTarget).parent(); - var $this_ = this.$header.find('th').eq($this.index()); - this.$header.add(this.$header_).find('span.order').remove(); - - if (this.options.sortName === $this.data('field')) { - this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc'; - } else { - this.options.sortName = $this.data('field'); - - if (this.options.rememberOrder) { - this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc'; - } else { - this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].sortOrder || this.columns[this.fieldsColumnsIndex[$this.data('field')]].order; - } - } - - this.trigger('sort', this.options.sortName, this.options.sortOrder); - $this.add($this_).data('order', this.options.sortOrder); // Assign the correct sortable arrow - - this.getCaret(); - - if (this.options.sidePagination === 'server' && this.options.serverSort) { - this.options.pageNumber = 1; - this.initServer(this.options.silentSort); - return; - } - - this.initSort(); - this.initBody(); - } - }, { - key: "initToolbar", - value: function initToolbar() { - var _this4 = this; - - var opts = this.options; - var html = []; - var timeoutId = 0; - var $keepOpen; - var switchableCount = 0; - - if (this.$toolbar.find('.bs-bars').children().length) { - $('body').append($(opts.toolbar)); - } - - this.$toolbar.html(''); - - if (typeof opts.toolbar === 'string' || _typeof(opts.toolbar) === 'object') { - $(Utils.sprintf('
    ', this.constants.classes.pull, opts.toolbarAlign)).appendTo(this.$toolbar).append($(opts.toolbar)); - } // showColumns, showToggle, showRefresh - - - html = ["
    ")]; - - if (typeof opts.icons === 'string') { - opts.icons = Utils.calculateObjectValue(null, opts.icons); - } - - var buttonsHtml = { - paginationSwitch: ""), - refresh: ""), - toggle: ""), - fullscreen: ""), - columns: function () { - var html = []; - html.push("
    \n \n ").concat(_this4.constants.html.toolbarDropdown[0])); - - if (opts.showColumnsSearch) { - html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf('', _this4.constants.classes.input, opts.formatSearch()))); - html.push(_this4.constants.html.toolbarDropdownSeparator); - } - - if (opts.showColumnsToggleAll) { - var allFieldsVisible = _this4.getVisibleColumns().length === _this4.columns.filter(function (column) { - return !_this4.isSelectionColumn(column); - }).length; - - html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf(' %s', allFieldsVisible ? 'checked="checked"' : '', opts.formatColumnsToggleAll()))); - html.push(_this4.constants.html.toolbarDropdownSeparator); - } - - var visibleColumns = 0; - - _this4.columns.forEach(function (column, i) { - if (column.visible) { - visibleColumns++; - } - }); - - _this4.columns.forEach(function (column, i) { - if (_this4.isSelectionColumn(column)) { - return; - } - - if (opts.cardView && !column.cardVisible) { - return; - } - - var checked = column.visible ? ' checked="checked"' : ''; - var disabled = visibleColumns <= _this4.options.minimumCountColumns && checked ? ' disabled="disabled"' : ''; - - if (column.switchable) { - html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf(' %s', column.field, i, checked, disabled, column.title))); - switchableCount++; - } - }); - - html.push(_this4.constants.html.toolbarDropdown[1], '
    '); - return html.join(''); - }() - }; - - if (typeof opts.buttonsOrder === 'string') { - opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(','); - } - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = opts.buttonsOrder[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var button = _step.value; - - if (opts['show' + button.charAt(0).toUpperCase() + button.substring(1)]) { - html.push(buttonsHtml[button]); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - html.push('
    '); // Fix #188: this.showToolbar is for extensions - - if (this.showToolbar || html.length > 2) { - this.$toolbar.append(html.join('')); - } - - if (opts.showPaginationSwitch) { - this.$toolbar.find('button[name="paginationSwitch"]').off('click').on('click', function () { - return _this4.togglePagination(); - }); - } - - if (opts.showFullscreen) { - this.$toolbar.find('button[name="fullscreen"]').off('click').on('click', function () { - return _this4.toggleFullscreen(); - }); - } - - if (opts.showRefresh) { - this.$toolbar.find('button[name="refresh"]').off('click').on('click', function () { - return _this4.refresh(); - }); - } - - if (opts.showToggle) { - this.$toolbar.find('button[name="toggle"]').off('click').on('click', function () { - _this4.toggleView(); - }); - } - - if (opts.showColumns) { - $keepOpen = this.$toolbar.find('.keep-open'); - var $checkboxes = $keepOpen.find('input[type="checkbox"]:not(".toggle-all")'); - var $toggleAll = $keepOpen.find('input[type="checkbox"].toggle-all'); - - if (switchableCount <= opts.minimumCountColumns) { - $keepOpen.find('input').prop('disabled', true); - } - - $keepOpen.find('li, label').off('click').on('click', function (e) { - e.stopImmediatePropagation(); - }); - $checkboxes.off('click').on('click', function (_ref2) { - var currentTarget = _ref2.currentTarget; - var $this = $(currentTarget); - - _this4._toggleColumn($this.val(), $this.prop('checked'), false); - - _this4.trigger('column-switch', $this.data('field'), $this.prop('checked')); - - $toggleAll.prop('checked', $checkboxes.filter(':checked').length === _this4.columns.filter(function (column) { - return !_this4.isSelectionColumn(column); - }).length); - }); - $toggleAll.off('click').on('click', function (_ref3) { - var currentTarget = _ref3.currentTarget; - - _this4._toggleAllColumns($(currentTarget).prop('checked')); - }); - - if (opts.showColumnsSearch) { - var $columnsSearch = $keepOpen.find('#columnsSearch'); - var $listItems = $keepOpen.find('.dropdown-item-marker'); - $columnsSearch.on('keyup paste change', function (_ref4) { - var currentTarget = _ref4.currentTarget; - var $this = $(currentTarget); - var searchValue = $this.val().toLowerCase(); - $listItems.show(); - $checkboxes.each(function (i, el) { - var $checkbox = $(el); - var $listItem = $checkbox.parents('.dropdown-item-marker'); - var text = $listItem.text().toLowerCase(); - - if (!text.includes(searchValue)) { - $listItem.hide(); - } - }); - }); - } - } // Fix #4516: this.showSearchClearButton is for extensions - - - if (opts.search || this.showSearchClearButton) { - html = []; - var showSearchButton = Utils.sprintf(this.constants.html.searchButton, this.constants.buttonsClass, opts.formatSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.search) : '', opts.showButtonText ? opts.formatSearch() : ''); - var showSearchClearButton = Utils.sprintf(this.constants.html.searchClearButton, this.constants.buttonsClass, opts.formatClearSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.clearSearch) : '', opts.showButtonText ? opts.formatClearSearch() : ''); - var searchInputHtml = ""); - var searchInputFinalHtml = searchInputHtml; - - if (opts.showSearchButton || opts.showSearchClearButton) { - var _buttonsHtml = (opts.showSearchButton ? showSearchButton : '') + (opts.showSearchClearButton ? showSearchClearButton : ''); - - searchInputFinalHtml = opts.search ? Utils.sprintf(this.constants.html.inputGroup, searchInputHtml, _buttonsHtml) : _buttonsHtml; - } - - html.push(Utils.sprintf("\n
    \n %s\n
    \n "), searchInputFinalHtml)); - this.$toolbar.append(html.join('')); - var $searchInput = this.$toolbar.find('.search input'); - - var handleInputEvent = function handleInputEvent() { - var eventTriggers = "keyup drop blur ".concat(Utils.isIEBrowser() ? 'mouseup' : ''); - $searchInput.off(eventTriggers).on(eventTriggers, function (event) { - if (opts.searchOnEnterKey && event.keyCode !== 13) { - return; - } - - if ([37, 38, 39, 40].includes(event.keyCode)) { - return; - } - - clearTimeout(timeoutId); // doesn't matter if it's 0 - - timeoutId = setTimeout(function () { - _this4.onSearch({ - currentTarget: event.currentTarget - }); - }, opts.searchTimeOut); - }); - }; - - if (opts.showSearchButton) { - this.$toolbar.find('.search button[name=search]').off('click').on('click', function (event) { - clearTimeout(timeoutId); // doesn't matter if it's 0 - - timeoutId = setTimeout(function () { - _this4.onSearch({ - currentTarget: $searchInput - }); - }, opts.searchTimeOut); - }); - - if (opts.searchOnEnterKey) { - handleInputEvent(); - } - } else { - handleInputEvent(); - } - - if (opts.showSearchClearButton) { - this.$toolbar.find('.search button[name=clearSearch]').click(function () { - _this4.resetSearch(); - }); - } - } - } - }, { - key: "onSearch", - value: function onSearch() { - var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - currentTarget = _ref5.currentTarget, - firedByInitSearchText = _ref5.firedByInitSearchText; - - var overwriteSearchText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - - if (currentTarget !== undefined && $(currentTarget).length && overwriteSearchText) { - var text = $(currentTarget).val().trim(); - - if (this.options.trimOnSearch && $(currentTarget).val() !== text) { - $(currentTarget).val(text); - } - - if (this.searchText === text && text.length > 0) { - return; - } - - if ($(currentTarget).hasClass('search-input')) { - this.searchText = text; - this.options.searchText = text; - } - } - - if (!firedByInitSearchText) { - this.options.pageNumber = 1; - } - - this.initSearch(); - - if (firedByInitSearchText) { - if (this.options.sidePagination === 'client') { - this.updatePagination(); - } - } else { - this.updatePagination(); - } - - this.trigger('search', this.searchText); - } - }, { - key: "initSearch", - value: function initSearch() { - var _this5 = this; - - this.filterOptions = this.filterOptions || this.options.filterOptions; - - if (this.options.sidePagination !== 'server') { - if (this.options.customSearch) { - this.data = Utils.calculateObjectValue(this.options, this.options.customSearch, [this.options.data, this.searchText, this.filterColumns]); - return; - } - - var s = this.searchText && (this.fromHtml ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase(); - var f = Utils.isEmptyObject(this.filterColumns) ? null : this.filterColumns; // Check filter - - if (typeof this.filterOptions.filterAlgorithm === 'function') { - this.data = this.options.data.filter(function (item, i) { - return _this5.filterOptions.filterAlgorithm.apply(null, [item, f]); - }); - } else if (typeof this.filterOptions.filterAlgorithm === 'string') { - this.data = f ? this.options.data.filter(function (item, i) { - var filterAlgorithm = _this5.filterOptions.filterAlgorithm; - - if (filterAlgorithm === 'and') { - for (var key in f) { - if (Array.isArray(f[key]) && !f[key].includes(item[key]) || !Array.isArray(f[key]) && item[key] !== f[key]) { - return false; - } - } - } else if (filterAlgorithm === 'or') { - var match = false; - - for (var _key in f) { - if (Array.isArray(f[_key]) && f[_key].includes(item[_key]) || !Array.isArray(f[_key]) && item[_key] === f[_key]) { - match = true; - } - } - - return match; - } - - return true; - }) : this.options.data; - } - - var visibleFields = this.getVisibleFields(); - this.data = s ? this.data.filter(function (item, i) { - for (var j = 0; j < _this5.header.fields.length; j++) { - if (!_this5.header.searchables[j] || _this5.options.visibleSearch && visibleFields.indexOf(_this5.header.fields[j]) === -1) { - continue; - } - - var key = Utils.isNumeric(_this5.header.fields[j]) ? parseInt(_this5.header.fields[j], 10) : _this5.header.fields[j]; - var column = _this5.columns[_this5.fieldsColumnsIndex[key]]; - var value = void 0; - - if (typeof key === 'string') { - value = item; - var props = key.split('.'); - - for (var _i2 = 0; _i2 < props.length; _i2++) { - if (value[props[_i2]] !== null) { - value = value[props[_i2]]; - } - } - } else { - value = item[key]; - } // Fix #142: respect searchFormatter boolean - - - if (column && column.searchFormatter) { - value = Utils.calculateObjectValue(column, _this5.header.formatters[j], [value, item, i, column.field], value); - } - - if (typeof value === 'string' || typeof value === 'number') { - if (_this5.options.strictSearch) { - if ("".concat(value).toLowerCase() === s) { - return true; - } - } else { - var largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm; - var matches = largerSmallerEqualsRegex.exec(s); - var comparisonCheck = false; - - if (matches) { - var operator = matches[1] || "".concat(matches[5], "l"); - var comparisonValue = matches[2] || matches[3]; - var int = parseInt(value, 10); - var comparisonInt = parseInt(comparisonValue, 10); - - switch (operator) { - case '>': - case ' comparisonInt; - break; - - case '<': - case '>l': - comparisonCheck = int < comparisonInt; - break; - - case '<=': - case '=<': - case '>=l': - case '=>l': - comparisonCheck = int <= comparisonInt; - break; - - case '>=': - case '=>': - case '<=l': - case '== comparisonInt; - break; - } - } - - if (comparisonCheck || "".concat(value).toLowerCase().includes(s)) { - return true; - } - } - } - } - - return false; - }) : this.data; - } - - this.initSort(); - } - }, { - key: "initPagination", - value: function initPagination() { - var _this6 = this; - - var opts = this.options; - - if (!opts.pagination) { - this.$pagination.hide(); - return; - } - - this.$pagination.show(); - var html = []; - var allSelected = false; - var i; - var from; - var to; - var $pageList; - var $pre; - var $next; - var $number; - var data = this.getData({ - includeHiddenRows: false - }); - var pageList = opts.pageList; - - if (typeof pageList === 'string') { - pageList = pageList.replace(/\[|\]| /g, '').toLowerCase().split(','); - } - - pageList = pageList.map(function (value) { - if (typeof value === 'string') { - return value.toLowerCase() === opts.formatAllRows().toLowerCase() || ['all', 'unlimited'].includes(value.toLowerCase()) ? opts.formatAllRows() : +value; - } - - return value; - }); - - if (opts.sidePagination !== 'server') { - opts.totalRows = data.length; - } - - this.totalPages = 0; - - if (opts.totalRows) { - if (opts.pageSize === opts.formatAllRows()) { - opts.pageSize = opts.totalRows; - allSelected = true; - } - - this.totalPages = ~~((opts.totalRows - 1) / opts.pageSize) + 1; - opts.totalPages = this.totalPages; - } - - if (this.totalPages > 0 && opts.pageNumber > this.totalPages) { - opts.pageNumber = this.totalPages; - } - - this.pageFrom = (opts.pageNumber - 1) * opts.pageSize + 1; - this.pageTo = opts.pageNumber * opts.pageSize; - - if (this.pageTo > opts.totalRows) { - this.pageTo = opts.totalRows; - } - - if (this.options.pagination && this.options.sidePagination !== 'server') { - this.options.totalNotFiltered = this.options.data.length; - } - - if (!this.options.showExtendedPagination) { - this.options.totalNotFiltered = undefined; - } - - var paginationInfo = opts.onlyInfoPagination ? opts.formatDetailPagination(opts.totalRows) : opts.formatShowingRows(this.pageFrom, this.pageTo, opts.totalRows, opts.totalNotFiltered); - html.push("
    \n \n ").concat(paginationInfo, "\n ")); - - if (!opts.onlyInfoPagination) { - html.push(''); - var pageNumber = ["\n \n ").concat(this.constants.html.pageDropdown[0])]; - pageList.forEach(function (page, i) { - if (!opts.smartDisplay || i === 0 || pageList[i - 1] < opts.totalRows) { - var active; - - if (allSelected) { - active = page === opts.formatAllRows() ? _this6.constants.classes.dropdownActive : ''; - } else { - active = page === opts.pageSize ? _this6.constants.classes.dropdownActive : ''; - } - - pageNumber.push(Utils.sprintf(_this6.constants.html.pageDropdownItem, active, page)); - } - }); - pageNumber.push("".concat(this.constants.html.pageDropdown[1], "")); - html.push(opts.formatRecordsPerPage(pageNumber.join(''))); - html.push('
    '); - html.push("
    "), Utils.sprintf(this.constants.html.pagination[0], Utils.sprintf(' pagination-%s', opts.iconSize)), Utils.sprintf(this.constants.html.paginationItem, ' page-pre', opts.formatSRPaginationPreText(), opts.paginationPreText)); - - if (this.totalPages < opts.paginationSuccessivelySize) { - from = 1; - to = this.totalPages; - } else { - from = opts.pageNumber - opts.paginationPagesBySide; - to = from + opts.paginationPagesBySide * 2; - } - - if (opts.pageNumber < opts.paginationSuccessivelySize - 1) { - to = opts.paginationSuccessivelySize; - } - - if (opts.paginationSuccessivelySize > this.totalPages - from) { - from = from - (opts.paginationSuccessivelySize - (this.totalPages - from)) + 1; - } - - if (from < 1) { - from = 1; - } - - if (to > this.totalPages) { - to = this.totalPages; - } - - var middleSize = Math.round(opts.paginationPagesBySide / 2); - - var pageItem = function pageItem(i) { - var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - return Utils.sprintf(_this6.constants.html.paginationItem, classes + (i === opts.pageNumber ? " ".concat(_this6.constants.classes.paginationActive) : ''), opts.formatSRPaginationPageText(i), i); - }; - - if (from > 1) { - var max = opts.paginationPagesBySide; - if (max >= from) max = from - 1; - - for (i = 1; i <= max; i++) { - html.push(pageItem(i)); - } - - if (from - 1 === max + 1) { - i = from - 1; - html.push(pageItem(i)); - } else { - if (from - 1 > max) { - if (from - opts.paginationPagesBySide * 2 > opts.paginationPagesBySide && opts.paginationUseIntermediate) { - i = Math.round((from - middleSize) / 2 + middleSize); - html.push(pageItem(i, ' page-intermediate')); - } else { - html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-first-separator disabled', '', '...')); - } - } - } - } - - for (i = from; i <= to; i++) { - html.push(pageItem(i)); - } - - if (this.totalPages > to) { - var min = this.totalPages - (opts.paginationPagesBySide - 1); - if (to >= min) min = to + 1; - - if (to + 1 === min - 1) { - i = to + 1; - html.push(pageItem(i)); - } else { - if (min > to + 1) { - if (this.totalPages - to > opts.paginationPagesBySide * 2 && opts.paginationUseIntermediate) { - i = Math.round((this.totalPages - middleSize - to) / 2 + to); - html.push(pageItem(i, ' page-intermediate')); - } else { - html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-last-separator disabled', '', '...')); - } - } - } - - for (i = min; i <= this.totalPages; i++) { - html.push(pageItem(i)); - } - } - - html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-next', opts.formatSRPaginationNextText(), opts.paginationNextText)); - html.push(this.constants.html.pagination[1], '
    '); - } - - this.$pagination.html(html.join('')); - var dropupClass = ['bottom', 'both'].includes(opts.paginationVAlign) ? " ".concat(this.constants.classes.dropup) : ''; - this.$pagination.last().find('.page-list > span').addClass(dropupClass); - - if (!opts.onlyInfoPagination) { - $pageList = this.$pagination.find('.page-list a'); - $pre = this.$pagination.find('.page-pre'); - $next = this.$pagination.find('.page-next'); - $number = this.$pagination.find('.page-item').not('.page-next, .page-pre, .page-last-separator, .page-first-separator'); - - if (this.totalPages <= 1) { - this.$pagination.find('div.pagination').hide(); - } - - if (opts.smartDisplay) { - if (pageList.length < 2 || opts.totalRows <= pageList[0]) { - this.$pagination.find('span.page-list').hide(); - } - } // when data is empty, hide the pagination - - - this.$pagination[this.getData().length ? 'show' : 'hide'](); - - if (!opts.paginationLoop) { - if (opts.pageNumber === 1) { - $pre.addClass('disabled'); - } - - if (opts.pageNumber === this.totalPages) { - $next.addClass('disabled'); - } - } - - if (allSelected) { - opts.pageSize = opts.formatAllRows(); - } // removed the events for last and first, onPageNumber executeds the same logic - - - $pageList.off('click').on('click', function (e) { - return _this6.onPageListChange(e); - }); - $pre.off('click').on('click', function (e) { - return _this6.onPagePre(e); - }); - $next.off('click').on('click', function (e) { - return _this6.onPageNext(e); - }); - $number.off('click').on('click', function (e) { - return _this6.onPageNumber(e); - }); - } - } - }, { - key: "updatePagination", - value: function updatePagination(event) { - // Fix #171: IE disabled button can be clicked bug. - if (event && $(event.currentTarget).hasClass('disabled')) { - return; - } - - if (!this.options.maintainMetaData) { - this.resetRows(); - } - - this.initPagination(); - - if (this.options.sidePagination === 'server') { - this.initServer(); - } else { - this.initBody(); - } - - this.trigger('page-change', this.options.pageNumber, this.options.pageSize); - } - }, { - key: "onPageListChange", - value: function onPageListChange(event) { - event.preventDefault(); - var $this = $(event.currentTarget); - $this.parent().addClass(this.constants.classes.dropdownActive).siblings().removeClass(this.constants.classes.dropdownActive); - this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ? this.options.formatAllRows() : +$this.text(); - this.$toolbar.find('.page-size').text(this.options.pageSize); - this.updatePagination(event); - return false; - } - }, { - key: "onPagePre", - value: function onPagePre(event) { - event.preventDefault(); - - if (this.options.pageNumber - 1 === 0) { - this.options.pageNumber = this.options.totalPages; - } else { - this.options.pageNumber--; - } - - this.updatePagination(event); - return false; - } - }, { - key: "onPageNext", - value: function onPageNext(event) { - event.preventDefault(); - - if (this.options.pageNumber + 1 > this.options.totalPages) { - this.options.pageNumber = 1; - } else { - this.options.pageNumber++; - } - - this.updatePagination(event); - return false; - } - }, { - key: "onPageNumber", - value: function onPageNumber(event) { - event.preventDefault(); - - if (this.options.pageNumber === +$(event.currentTarget).text()) { - return; - } - - this.options.pageNumber = +$(event.currentTarget).text(); - this.updatePagination(event); - return false; - } - }, { - key: "initRow", - value: function initRow(item, i, data, trFragments) { - var _this7 = this; - - var html = []; - var style = {}; - var csses = []; - var data_ = ''; - var attributes = {}; - var htmlAttributes = []; - - if (Utils.findIndex(this.hiddenRows, item) > -1) { - return; - } - - style = Utils.calculateObjectValue(this.options, this.options.rowStyle, [item, i], style); - - if (style && style.css) { - for (var _i3 = 0, _Object$entries2 = Object.entries(style.css); _i3 < _Object$entries2.length; _i3++) { - var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2), - key = _Object$entries2$_i[0], - value = _Object$entries2$_i[1]; - - csses.push("".concat(key, ": ").concat(value)); - } - } - - attributes = Utils.calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes); - - if (attributes) { - for (var _i4 = 0, _Object$entries3 = Object.entries(attributes); _i4 < _Object$entries3.length; _i4++) { - var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i4], 2), - _key2 = _Object$entries3$_i[0], - _value = _Object$entries3$_i[1]; - - htmlAttributes.push("".concat(_key2, "=\"").concat(Utils.escapeHTML(_value), "\"")); - } - } - - if (item._data && !Utils.isEmptyObject(item._data)) { - for (var _i5 = 0, _Object$entries4 = Object.entries(item._data); _i5 < _Object$entries4.length; _i5++) { - var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2), - k = _Object$entries4$_i[0], - v = _Object$entries4$_i[1]; - - // ignore data-index - if (k === 'index') { - return; - } - - data_ += " data-".concat(k, "='").concat(_typeof(v) === 'object' ? JSON.stringify(v) : v, "'"); - } - } - - html.push(''); - - if (this.options.cardView) { - html.push("
    ")); - } - - if (!this.options.cardView && this.options.detailView && this.options.detailViewIcon) { - html.push(''); - - if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) { - html.push("\n \n ".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen), "\n \n ")); - } - - html.push(''); - } - - this.header.fields.forEach(function (field, j) { - var text = ''; - var value_ = Utils.getItemField(item, field, _this7.options.escape); - var value = ''; - var type = ''; - var cellStyle = {}; - var id_ = ''; - var class_ = _this7.header.classes[j]; - var style_ = ''; - var data_ = ''; - var rowspan_ = ''; - var colspan_ = ''; - var title_ = ''; - var column = _this7.columns[j]; - - if (_this7.fromHtml && typeof value_ === 'undefined') { - if (!column.checkbox && !column.radio) { - return; - } - } - - if (!column.visible) { - return; - } - - if (_this7.options.cardView && !column.cardVisible) { - return; - } - - if (column.escape) { - value_ = Utils.escapeHTML(value_); - } - - if (csses.concat([_this7.header.styles[j]]).length) { - style_ = " style=\"".concat(csses.concat([_this7.header.styles[j]]).join('; '), "\""); - } // handle td's id and class - - - if (item["_".concat(field, "_id")]) { - id_ = Utils.sprintf(' id="%s"', item["_".concat(field, "_id")]); - } - - if (item["_".concat(field, "_class")]) { - class_ = Utils.sprintf(' class="%s"', item["_".concat(field, "_class")]); - } - - if (item["_".concat(field, "_rowspan")]) { - rowspan_ = Utils.sprintf(' rowspan="%s"', item["_".concat(field, "_rowspan")]); - } - - if (item["_".concat(field, "_colspan")]) { - colspan_ = Utils.sprintf(' colspan="%s"', item["_".concat(field, "_colspan")]); - } - - if (item["_".concat(field, "_title")]) { - title_ = Utils.sprintf(' title="%s"', item["_".concat(field, "_title")]); - } - - cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle); - - if (cellStyle.classes) { - class_ = " class=\"".concat(cellStyle.classes, "\""); - } - - if (cellStyle.css) { - var csses_ = []; - - for (var _i6 = 0, _Object$entries5 = Object.entries(cellStyle.css); _i6 < _Object$entries5.length; _i6++) { - var _Object$entries5$_i = _slicedToArray(_Object$entries5[_i6], 2), - _key3 = _Object$entries5$_i[0], - _value2 = _Object$entries5$_i[1]; - - csses_.push("".concat(_key3, ": ").concat(_value2)); - } - - style_ = " style=\"".concat(csses_.concat(_this7.header.styles[j]).join('; '), "\""); - } - - value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_); - - if (item["_".concat(field, "_data")] && !Utils.isEmptyObject(item["_".concat(field, "_data")])) { - for (var _i7 = 0, _Object$entries6 = Object.entries(item["_".concat(field, "_data")]); _i7 < _Object$entries6.length; _i7++) { - var _Object$entries6$_i = _slicedToArray(_Object$entries6[_i7], 2), - _k = _Object$entries6$_i[0], - _v = _Object$entries6$_i[1]; - - // ignore data-index - if (_k === 'index') { - return; - } - - data_ += " data-".concat(_k, "=\"").concat(_v, "\""); - } - } - - if (column.checkbox || column.radio) { - type = column.checkbox ? 'checkbox' : type; - type = column.radio ? 'radio' : type; - var c = column['class'] || ''; - var isChecked = (value === true || value_ || value && value.checked) && value !== false; - var isDisabled = !column.checkboxEnabled || value && value.disabled; - text = [_this7.options.cardView ? "
    ") : ""), ""), _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '
    ' : ''].join(''); - item[_this7.header.stateField] = value === true || !!value_ || value && value.checked; - } else { - value = typeof value === 'undefined' || value === null ? _this7.options.undefinedText : value; - - if (_this7.options.cardView) { - var cardTitle = _this7.options.showHeader ? "").concat(Utils.getFieldTitle(_this7.columns, field), "") : ''; - text = "
    ".concat(cardTitle, "").concat(value, "
    "); - - if (_this7.options.smartDisplay && value === '') { - text = '
    '; - } - } else { - text = "").concat(value, ""); - } - } - - html.push(text); - }); - - if (this.options.cardView) { - html.push('
    '); - } - - html.push(''); - return html.join(''); - } - }, { - key: "initBody", - value: function initBody(fixedScroll) { - var _this8 = this; - - var data = this.getData(); - this.trigger('pre-body', data); - this.$body = this.$el.find('>tbody'); - - if (!this.$body.length) { - this.$body = $('').appendTo(this.$el); - } // Fix #389 Bootstrap-table-flatJSON is not working - - - if (!this.options.pagination || this.options.sidePagination === 'server') { - this.pageFrom = 1; - this.pageTo = data.length; - } - - var rows = []; - var trFragments = $(document.createDocumentFragment()); - var hasTr = false; - - for (var i = this.pageFrom - 1; i < this.pageTo; i++) { - var item = data[i]; - var tr = this.initRow(item, i, data, trFragments); - hasTr = hasTr || !!tr; - - if (tr && typeof tr === 'string') { - if (!this.options.virtualScroll) { - trFragments.append(tr); - } else { - rows.push(tr); - } - } - } // show no records - - - if (!hasTr) { - this.$body.html("".concat(Utils.sprintf('%s', this.$header.find('th').length, this.options.formatNoMatches()), "")); - } else { - if (!this.options.virtualScroll) { - this.$body.html(trFragments); - } else { - if (this.virtualScroll) { - this.virtualScroll.destroy(); - } - - this.virtualScroll = new VirtualScroll({ - rows: rows, - fixedScroll: fixedScroll, - scrollEl: this.$tableBody[0], - contentEl: this.$body[0], - itemHeight: this.options.virtualScrollItemHeight, - callback: function callback() { - _this8.fitHeader(); - - _this8.initBodyEvent(); - } - }); - } - } - - if (!fixedScroll) { - this.scrollTo(0); - } - - this.initBodyEvent(); - this.updateSelected(); - this.initFooter(); - this.resetView(); - - if (this.options.sidePagination !== 'server') { - this.options.totalRows = data.length; - } - - this.trigger('post-body', data); - } - }, { - key: "initBodyEvent", - value: function initBodyEvent() { - var _this9 = this; - - // click to select by column - this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) { - var $td = $(e.currentTarget); - var $tr = $td.parent(); - var $cardViewArr = $(e.target).parents('.card-views').children(); - var $cardViewTarget = $(e.target).parents('.card-view'); - var rowIndex = $tr.data('index'); - var item = _this9.data[rowIndex]; - var index = _this9.options.cardView ? $cardViewArr.index($cardViewTarget) : $td[0].cellIndex; - - var fields = _this9.getVisibleFields(); - - var field = fields[_this9.options.detailView && _this9.options.detailViewIcon && !_this9.options.cardView ? index - 1 : index]; - var column = _this9.columns[_this9.fieldsColumnsIndex[field]]; - var value = Utils.getItemField(item, field, _this9.options.escape); - - if ($td.find('.detail-icon').length) { - return; - } - - _this9.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td); - - _this9.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field); // if click to select - then trigger the checkbox/radio click - - - if (e.type === 'click' && _this9.options.clickToSelect && column.clickToSelect && !Utils.calculateObjectValue(_this9.options, _this9.options.ignoreClickToSelectOn, [e.target])) { - var $selectItem = $tr.find(Utils.sprintf('[name="%s"]', _this9.options.selectItemName)); - - if ($selectItem.length) { - $selectItem[0].click(); - } - } - - if (e.type === 'click' && _this9.options.detailViewByClick) { - _this9.toggleDetailView(rowIndex, _this9.header.detailFormatters[_this9.fieldsColumnsIndex[field]]); - } - }).off('mousedown').on('mousedown', function (e) { - // https://github.com/jquery/jquery/issues/1741 - _this9.multipleSelectRowCtrlKey = e.ctrlKey || e.metaKey; - _this9.multipleSelectRowShiftKey = e.shiftKey; - }); - this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) { - e.preventDefault(); - - _this9.toggleDetailView($(e.currentTarget).parent().parent().data('index')); - - return false; - }); - this.$selectItem = this.$body.find(Utils.sprintf('[name="%s"]', this.options.selectItemName)); - this.$selectItem.off('click').on('click', function (e) { - e.stopImmediatePropagation(); - var $this = $(e.currentTarget); - - _this9._toggleCheck($this.prop('checked'), $this.data('index')); - }); - this.header.events.forEach(function (_events, i) { - var events = _events; - - if (!events) { - return; - } // fix bug, if events is defined with namespace - - - if (typeof events === 'string') { - events = Utils.calculateObjectValue(null, events); - } - - var field = _this9.header.fields[i]; - - var fieldIndex = _this9.getVisibleFields().indexOf(field); - - if (fieldIndex === -1) { - return; - } - - if (_this9.options.detailView && !_this9.options.cardView) { - fieldIndex += 1; - } - - var _loop = function _loop(key) { - if (!events.hasOwnProperty(key)) { - return "continue"; - } - - var event = events[key]; - - _this9.$body.find('>tr:not(.no-records-found)').each(function (i, tr) { - var $tr = $(tr); - var $td = $tr.find(_this9.options.cardView ? '.card-views>.card-view' : '>td').eq(fieldIndex); - var index = key.indexOf(' '); - var name = key.substring(0, index); - var el = key.substring(index + 1); - $td.find(el).off(name).on(name, function (e) { - var index = $tr.data('index'); - var row = _this9.data[index]; - var value = row[field]; - event.apply(_this9, [e, value, row, index]); - }); - }); - }; - - for (var key in events) { - var _ret = _loop(key); - - if (_ret === "continue") continue; - } - }); - } - }, { - key: "initServer", - value: function initServer(silent, query, url) { - var _this10 = this; - - var data = {}; - var index = this.header.fields.indexOf(this.options.sortName); - var params = { - searchText: this.searchText, - sortName: this.options.sortName, - sortOrder: this.options.sortOrder - }; - - if (this.header.sortNames[index]) { - params.sortName = this.header.sortNames[index]; - } - - if (this.options.pagination && this.options.sidePagination === 'server') { - params.pageSize = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize; - params.pageNumber = this.options.pageNumber; - } - - if (!(url || this.options.url) && !this.options.ajax) { - return; - } - - if (this.options.queryParamsType === 'limit') { - params = { - search: params.searchText, - sort: params.sortName, - order: params.sortOrder - }; - - if (this.options.pagination && this.options.sidePagination === 'server') { - params.offset = this.options.pageSize === this.options.formatAllRows() ? 0 : this.options.pageSize * (this.options.pageNumber - 1); - params.limit = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize; - - if (params.limit === 0) { - delete params.limit; - } - } - } - - if (!Utils.isEmptyObject(this.filterColumnsPartial)) { - params.filter = JSON.stringify(this.filterColumnsPartial, null); - } - - $.extend(params, query || {}); - data = Utils.calculateObjectValue(this.options, this.options.queryParams, [params], data); // false to stop request - - if (data === false) { - return; - } - - if (!silent) { - this.showLoading(); - } - - var request = $.extend({}, Utils.calculateObjectValue(null, this.options.ajaxOptions), { - type: this.options.method, - url: url || this.options.url, - data: this.options.contentType === 'application/json' && this.options.method === 'post' ? JSON.stringify(data) : data, - cache: this.options.cache, - contentType: this.options.contentType, - dataType: this.options.dataType, - success: function success(_res, textStatus, jqXHR) { - var res = Utils.calculateObjectValue(_this10.options, _this10.options.responseHandler, [_res, jqXHR], _res); - - _this10.load(res); - - _this10.trigger('load-success', res, jqXHR && jqXHR.status, jqXHR); - - if (!silent) { - _this10.hideLoading(); - } - - if (_this10.options.sidePagination === 'server' && res[_this10.options.totalField] > 0 && !res[_this10.options.dataField].length) { - _this10.updatePagination(); - } - }, - error: function error(jqXHR) { - var data = []; - - if (_this10.options.sidePagination === 'server') { - data = {}; - data[_this10.options.totalField] = 0; - data[_this10.options.dataField] = []; - } - - _this10.load(data); - - _this10.trigger('load-error', jqXHR && jqXHR.status, jqXHR); - - if (!silent) _this10.$tableLoading.hide(); - } - }); - - if (this.options.ajax) { - Utils.calculateObjectValue(this, this.options.ajax, [request], null); - } else { - if (this._xhr && this._xhr.readyState !== 4) { - this._xhr.abort(); - } - - this._xhr = $.ajax(request); - } - - return data; - } - }, { - key: "initSearchText", - value: function initSearchText() { - if (this.options.search) { - this.searchText = ''; - - if (this.options.searchText !== '') { - var $search = this.$toolbar.find('.search input'); - $search.val(this.options.searchText); - this.onSearch({ - currentTarget: $search, - firedByInitSearchText: true - }); - } - } - } - }, { - key: "getCaret", - value: function getCaret() { - var _this11 = this; - - this.$header.find('th').each(function (i, th) { - $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === _this11.options.sortName ? _this11.options.sortOrder : 'both'); - }); - } - }, { - key: "updateSelected", - value: function updateSelected() { - var checkAll = this.$selectItem.filter(':enabled').length && this.$selectItem.filter(':enabled').length === this.$selectItem.filter(':enabled').filter(':checked').length; - this.$selectAll.add(this.$selectAll_).prop('checked', checkAll); - this.$selectItem.each(function (i, el) { - $(el).closest('tr')[$(el).prop('checked') ? 'addClass' : 'removeClass']('selected'); - }); - } - }, { - key: "updateRows", - value: function updateRows() { - var _this12 = this; - - this.$selectItem.each(function (i, el) { - _this12.data[$(el).data('index')][_this12.header.stateField] = $(el).prop('checked'); - }); - } - }, { - key: "resetRows", - value: function resetRows() { - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = this.data[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var row = _step2.value; - this.$selectAll.prop('checked', false); - this.$selectItem.prop('checked', false); - - if (this.header.stateField) { - row[this.header.stateField] = false; - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - this.initHiddenRows(); - } - }, { - key: "trigger", - value: function trigger(_name) { - var _this$options; - - var name = "".concat(_name, ".bs.table"); - - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key4 = 1; _key4 < _len; _key4++) { - args[_key4 - 1] = arguments[_key4]; - } - - (_this$options = this.options)[BootstrapTable.EVENTS[name]].apply(_this$options, args); - - this.$el.trigger($.Event(name), args); - this.options.onAll(name, args); - this.$el.trigger($.Event('all.bs.table'), [name, args]); - } - }, { - key: "resetHeader", - value: function resetHeader() { - var _this13 = this; - - // fix #61: the hidden table reset header bug. - // fix bug: get $el.css('width') error sometime (height = 500) - clearTimeout(this.timeoutId_); - this.timeoutId_ = setTimeout(function () { - return _this13.fitHeader(); - }, this.$el.is(':hidden') ? 100 : 0); - } - }, { - key: "fitHeader", - value: function fitHeader() { - var _this14 = this; - - if (this.$el.is(':hidden')) { - this.timeoutId_ = setTimeout(function () { - return _this14.fitHeader(); - }, 100); - return; - } - - var fixedBody = this.$tableBody.get(0); - var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0; - this.$el.css('margin-top', -this.$header.outerHeight()); - var focused = $(':focus'); - - if (focused.length > 0) { - var $th = focused.parents('th'); - - if ($th.length > 0) { - var dataField = $th.attr('data-field'); - - if (dataField !== undefined) { - var $headerTh = this.$header.find("[data-field='".concat(dataField, "']")); - - if ($headerTh.length > 0) { - $headerTh.find(':input').addClass('focus-temp'); - } - } - } - } - - this.$header_ = this.$header.clone(true, true); - this.$selectAll_ = this.$header_.find('[name="btSelectAll"]'); - this.$tableHeader.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).html('').attr('class', this.$el.attr('class')).append(this.$header_); - this.$tableLoading.css('width', this.$el.outerWidth()); - var focusedTemp = $('.focus-temp:visible:eq(0)'); - - if (focusedTemp.length > 0) { - focusedTemp.focus(); - this.$header.find('.focus-temp').removeClass('focus-temp'); - } // fix bug: $.data() is not working as expected after $.append() - - - this.$header.find('th[data-field]').each(function (i, el) { - _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', $(el).data('field'))).data($(el).data()); - }); - var visibleFields = this.getVisibleFields(); - var $ths = this.$header_.find('th'); - var $tr = this.$body.find('>tr:not(.no-records-found,.virtual-scroll-top)').eq(0); - - while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) { - $tr = $tr.next(); - } - - $tr.find('> *').each(function (i, el) { - var $this = $(el); - var index = i; - - if (_this14.options.detailView && _this14.options.detailViewIcon && !_this14.options.cardView) { - if (i === 0) { - var $thDetail = $ths.filter('.detail'); - - var _zoomWidth = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width(); - - $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth); - } - - index = i - 1; - } - - if (index === -1) { - return; - } - - var $th = _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', visibleFields[index])); - - if ($th.length > 1) { - $th = $($ths[$this[0].cellIndex]); - } - - var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width(); - $th.find('.fht-cell').width($this.innerWidth() - zoomWidth); - }); - this.horizontalScroll(); - this.trigger('post-header'); - } - }, { - key: "initFooter", - value: function initFooter() { - if (!this.options.showFooter || this.options.cardView) { - // do nothing - return; - } - - var data = this.getData(); - var html = []; - - if (!this.options.cardView && this.options.detailView && this.options.detailViewIcon) { - html.push('
    '); - } - - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = this.columns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var column = _step3.value; - var falign = ''; - var valign = ''; - var csses = []; - var style = {}; - var class_ = Utils.sprintf(' class="%s"', column['class']); - - if (!column.visible) { - continue; - } - - if (this.options.cardView && !column.cardVisible) { - return; - } - - falign = Utils.sprintf('text-align: %s; ', column.falign ? column.falign : column.align); - valign = Utils.sprintf('vertical-align: %s; ', column.valign); - style = Utils.calculateObjectValue(null, this.options.footerStyle, [column]); - - if (style && style.css) { - for (var _i8 = 0, _Object$entries7 = Object.entries(style.css); _i8 < _Object$entries7.length; _i8++) { - var _Object$entries7$_i = _slicedToArray(_Object$entries7[_i8], 2), - key = _Object$entries7$_i[0], - value = _Object$entries7$_i[1]; - - csses.push("".concat(key, ": ").concat(value)); - } - } - - if (style && style.classes) { - class_ = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], style.classes].join(' ') : style.classes); - } - - html.push(''); - html.push('
    '); - html.push(Utils.calculateObjectValue(column, column.footerFormatter, [data], this.footerData[0] && this.footerData[0][column.field] || '')); - html.push('
    '); - html.push('
    '); - html.push('
    '); - html.push(''); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - if (!this.options.height && !this.$tableFooter.length) { - this.$el.append(''); - this.$tableFooter = this.$el.find('tfoot'); - } - - this.$tableFooter.find('tr').html(html.join('')); - this.trigger('post-footer', this.$tableFooter); - } - }, { - key: "fitFooter", - value: function fitFooter() { - var _this15 = this; - - if (this.$el.is(':hidden')) { - setTimeout(function () { - return _this15.fitFooter(); - }, 100); - return; - } - - var fixedBody = this.$tableBody.get(0); - var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0; - this.$tableFooter.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).attr('class', this.$el.attr('class')); - var visibleFields = this.getVisibleFields(); - var $ths = this.$tableFooter.find('th'); - var $tr = this.$body.find('>tr:first-child:not(.no-records-found)'); - - while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) { - $tr = $tr.next(); - } - - $tr.find('> *').each(function (i, el) { - var $this = $(el); - var index = i; - - if (_this15.options.detailView && !_this15.options.cardView) { - if (i === 0) { - var $thDetail = $ths.filter('.detail'); - - var _zoomWidth2 = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width(); - - $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth2); - } - - index = i - 1; - } - - if (index === -1) { - return; - } - - var $th = $ths.eq(i); - var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width(); - $th.find('.fht-cell').width($this.innerWidth() - zoomWidth); - }); - this.horizontalScroll(); - } - }, { - key: "horizontalScroll", - value: function horizontalScroll() { - var _this16 = this; - - // horizontal scroll event - // TODO: it's probably better improving the layout than binding to scroll event - this.$tableBody.off('scroll').on('scroll', function () { - var scrollLeft = _this16.$tableBody.scrollLeft(); - - if (_this16.options.showHeader && _this16.options.height) { - _this16.$tableHeader.scrollLeft(scrollLeft); - } - - if (_this16.options.showFooter && !_this16.options.cardView) { - _this16.$tableFooter.scrollLeft(scrollLeft); - } - - _this16.trigger('scroll-body', _this16.$tableBody); - }); - } - }, { - key: "getVisibleFields", - value: function getVisibleFields() { - var visibleFields = []; - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = this.header.fields[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var field = _step4.value; - var column = this.columns[this.fieldsColumnsIndex[field]]; - - if (!column || !column.visible) { - continue; - } - - visibleFields.push(field); - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4.return != null) { - _iterator4.return(); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - - return visibleFields; - } - }, { - key: "initHiddenRows", - value: function initHiddenRows() { - this.hiddenRows = []; - } // PUBLIC FUNCTION DEFINITION - // ======================= - - }, { - key: "getOptions", - value: function getOptions() { - // deep copy and remove data - var options = $.extend({}, this.options); - delete options.data; - return $.extend(true, {}, options); - } - }, { - key: "refreshOptions", - value: function refreshOptions(options) { - // If the objects are equivalent then avoid the call of destroy / init methods - if (Utils.compareObjects(this.options, options, true)) { - return; - } - - this.options = $.extend(this.options, options); - this.trigger('refresh-options', this.options); - this.destroy(); - this.init(); - } - }, { - key: "getData", - value: function getData(params) { - var data = this.options.data; - - if ((this.searchText || this.options.customSearch || this.options.sortName || !Utils.isEmptyObject(this.filterColumns) || !Utils.isEmptyObject(this.filterColumnsPartial)) && (!params || !params.unfiltered)) { - data = this.data; - } - - if (params && params.useCurrentPage) { - data = data.slice(this.pageFrom - 1, this.pageTo); - } - - if (params && !params.includeHiddenRows) { - var hiddenRows = this.getHiddenRows(); - data = data.filter(function (row) { - return Utils.findIndex(hiddenRows, row) === -1; - }); - } - - return data; - } - }, { - key: "getSelections", - value: function getSelections() { - var _this17 = this; - - // fix #2424: from html with checkbox - return this.data.filter(function (row) { - return row[_this17.header.stateField] === true; - }); - } - }, { - key: "getAllSelections", - value: function getAllSelections() { - var _this18 = this; - - return this.options.data.filter(function (row) { - return row[_this18.header.stateField] === true; - }); - } - }, { - key: "load", - value: function load(_data) { - var fixedScroll = false; - var data = _data; // #431: support pagination - - if (this.options.pagination && this.options.sidePagination === 'server') { - this.options.totalRows = data[this.options.totalField]; - } - - if (this.options.pagination && this.options.sidePagination === 'server') { - this.options.totalNotFiltered = data[this.options.totalNotFilteredField]; - } - - fixedScroll = data.fixedScroll; - data = Array.isArray(data) ? data : data[this.options.dataField]; - this.initData(data); - this.initSearch(); - this.initPagination(); - this.initBody(fixedScroll); - } - }, { - key: "append", - value: function append(data) { - this.initData(data, 'append'); - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "prepend", - value: function prepend(data) { - this.initData(data, 'prepend'); - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "remove", - value: function remove(params) { - var len = this.options.data.length; - var i; - var row; - - if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) { - return; - } - - for (i = len - 1; i >= 0; i--) { - row = this.options.data[i]; - - if (!row.hasOwnProperty(params.field)) { - continue; - } - - if (params.values.includes(row[params.field])) { - this.options.data.splice(i, 1); - - if (this.options.sidePagination === 'server') { - this.options.totalRows -= 1; - } - } - } - - if (len === this.options.data.length) { - return; - } - - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "removeAll", - value: function removeAll() { - if (this.options.data.length > 0) { - this.options.data.splice(0, this.options.data.length); - this.initSearch(); - this.initPagination(); - this.initBody(true); - } - } - }, { - key: "insertRow", - value: function insertRow(params) { - if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) { - return; - } - - this.options.data.splice(params.index, 0, params.row); - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "updateRow", - value: function updateRow(params) { - var allParams = Array.isArray(params) ? params : [params]; - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = allParams[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var _params = _step5.value; - - if (!_params.hasOwnProperty('index') || !_params.hasOwnProperty('row')) { - continue; - } - - $.extend(this.options.data[_params.index], _params.row); - - if (_params.hasOwnProperty('replace') && _params.replace) { - this.options.data[_params.index] = _params.row; - } else { - $.extend(this.options.data[_params.index], _params.row); - } - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5.return != null) { - _iterator5.return(); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "getRowByUniqueId", - value: function getRowByUniqueId(_id) { - var uniqueId = this.options.uniqueId; - var len = this.options.data.length; - var id = _id; - var dataRow = null; - var i; - var row; - var rowUniqueId; - - for (i = len - 1; i >= 0; i--) { - row = this.options.data[i]; - - if (row.hasOwnProperty(uniqueId)) { - // uniqueId is a column - rowUniqueId = row[uniqueId]; - } else if (row._data && row._data.hasOwnProperty(uniqueId)) { - // uniqueId is a row data property - rowUniqueId = row._data[uniqueId]; - } else { - continue; - } - - if (typeof rowUniqueId === 'string') { - id = id.toString(); - } else if (typeof rowUniqueId === 'number') { - if (Number(rowUniqueId) === rowUniqueId && rowUniqueId % 1 === 0) { - id = parseInt(id); - } else if (rowUniqueId === Number(rowUniqueId) && rowUniqueId !== 0) { - id = parseFloat(id); - } - } - - if (rowUniqueId === id) { - dataRow = row; - break; - } - } - - return dataRow; - } - }, { - key: "updateByUniqueId", - value: function updateByUniqueId(params) { - var allParams = Array.isArray(params) ? params : [params]; - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = allParams[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var _params2 = _step6.value; - - if (!_params2.hasOwnProperty('id') || !_params2.hasOwnProperty('row')) { - continue; - } - - var rowId = this.options.data.indexOf(this.getRowByUniqueId(_params2.id)); - - if (rowId === -1) { - continue; - } - - if (_params2.hasOwnProperty('replace') && _params2.replace) { - this.options.data[rowId] = _params2.row; - } else { - $.extend(this.options.data[rowId], _params2.row); - } - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6.return != null) { - _iterator6.return(); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - - this.initSearch(); - this.initPagination(); - this.initSort(); - this.initBody(true); - } - }, { - key: "removeByUniqueId", - value: function removeByUniqueId(id) { - var len = this.options.data.length; - var row = this.getRowByUniqueId(id); - - if (row) { - this.options.data.splice(this.options.data.indexOf(row), 1); - } - - if (len === this.options.data.length) { - return; - } - - this.initSearch(); - this.initPagination(); - this.initBody(true); - } - }, { - key: "updateCell", - value: function updateCell(params) { - if (!params.hasOwnProperty('index') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) { - return; - } - - this.data[params.index][params.field] = params.value; - - if (params.reinit === false) { - return; - } - - this.initSort(); - this.initBody(true); - } - }, { - key: "updateCellByUniqueId", - value: function updateCellByUniqueId(params) { - var _this19 = this; - - if (!params.hasOwnProperty('id') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) { - return; - } - - var allParams = Array.isArray(params) ? params : [params]; - allParams.forEach(function (_ref6) { - var id = _ref6.id, - field = _ref6.field, - value = _ref6.value; - - var rowId = _this19.options.data.indexOf(_this19.getRowByUniqueId(id)); - - if (rowId === -1) { - return; - } - - _this19.options.data[rowId][field] = value; - }); - - if (params.reinit === false) { - return; - } - - this.initSort(); - this.initBody(true); - } - }, { - key: "showRow", - value: function showRow(params) { - this._toggleRow(params, true); - } - }, { - key: "hideRow", - value: function hideRow(params) { - this._toggleRow(params, false); - } - }, { - key: "_toggleRow", - value: function _toggleRow(params, visible) { - var row; - - if (params.hasOwnProperty('index')) { - row = this.getData()[params.index]; - } else if (params.hasOwnProperty('uniqueId')) { - row = this.getRowByUniqueId(params.uniqueId); - } - - if (!row) { - return; - } - - var index = Utils.findIndex(this.hiddenRows, row); - - if (!visible && index === -1) { - this.hiddenRows.push(row); - } else if (visible && index > -1) { - this.hiddenRows.splice(index, 1); - } - - if (visible) { - this.updatePagination(); - } else { - this.initBody(true); - this.initPagination(); - } - } - }, { - key: "getHiddenRows", - value: function getHiddenRows(show) { - if (show) { - this.initHiddenRows(); - this.initBody(true); - return; - } - - var data = this.getData(); - var rows = []; - var _iteratorNormalCompletion7 = true; - var _didIteratorError7 = false; - var _iteratorError7 = undefined; - - try { - for (var _iterator7 = data[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { - var row = _step7.value; - - if (this.hiddenRows.includes(row)) { - rows.push(row); - } - } - } catch (err) { - _didIteratorError7 = true; - _iteratorError7 = err; - } finally { - try { - if (!_iteratorNormalCompletion7 && _iterator7.return != null) { - _iterator7.return(); - } - } finally { - if (_didIteratorError7) { - throw _iteratorError7; - } - } - } - - this.hiddenRows = rows; - return rows; - } - }, { - key: "showColumn", - value: function showColumn(field) { - var _this20 = this; - - var fields = Array.isArray(field) ? field : [field]; - fields.forEach(function (field) { - _this20._toggleColumn(_this20.fieldsColumnsIndex[field], true, true); - }); - } - }, { - key: "hideColumn", - value: function hideColumn(field) { - var _this21 = this; - - var fields = Array.isArray(field) ? field : [field]; - fields.forEach(function (field) { - _this21._toggleColumn(_this21.fieldsColumnsIndex[field], false, true); - }); - } - }, { - key: "_toggleColumn", - value: function _toggleColumn(index, checked, needUpdate) { - if (index === -1 || this.columns[index].visible === checked) { - return; - } - - this.columns[index].visible = checked; - this.initHeader(); - this.initSearch(); - this.initPagination(); - this.initBody(); - - if (this.options.showColumns) { - var $items = this.$toolbar.find('.keep-open input:not(".toggle-all")').prop('disabled', false); - - if (needUpdate) { - $items.filter(Utils.sprintf('[value="%s"]', index)).prop('checked', checked); - } - - if ($items.filter(':checked').length <= this.options.minimumCountColumns) { - $items.filter(':checked').prop('disabled', true); - } - } - } - }, { - key: "getVisibleColumns", - value: function getVisibleColumns() { - var _this22 = this; - - return this.columns.filter(function (column) { - return column.visible && !_this22.isSelectionColumn(column); - }); - } - }, { - key: "getHiddenColumns", - value: function getHiddenColumns() { - return this.columns.filter(function (_ref7) { - var visible = _ref7.visible; - return !visible; - }); - } - }, { - key: "isSelectionColumn", - value: function isSelectionColumn(column) { - return column.radio || column.checkbox; - } - }, { - key: "showAllColumns", - value: function showAllColumns() { - this._toggleAllColumns(true); - } - }, { - key: "hideAllColumns", - value: function hideAllColumns() { - this._toggleAllColumns(false); - } - }, { - key: "_toggleAllColumns", - value: function _toggleAllColumns(visible) { - var _this23 = this; - - var _iteratorNormalCompletion8 = true; - var _didIteratorError8 = false; - var _iteratorError8 = undefined; - - try { - for (var _iterator8 = this.columns.slice().reverse()[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { - var column = _step8.value; - - if (column.switchable) { - if (!visible && this.options.showColumns && this.getVisibleColumns().length === this.options.minimumCountColumns) { - continue; - } - - column.visible = visible; - } - } - } catch (err) { - _didIteratorError8 = true; - _iteratorError8 = err; - } finally { - try { - if (!_iteratorNormalCompletion8 && _iterator8.return != null) { - _iterator8.return(); - } - } finally { - if (_didIteratorError8) { - throw _iteratorError8; - } - } - } - - this.initHeader(); - this.initSearch(); - this.initPagination(); - this.initBody(); - - if (this.options.showColumns) { - var $items = this.$toolbar.find('.keep-open input[type="checkbox"]:not(".toggle-all")').prop('disabled', false); - - if (visible) { - $items.prop('checked', visible); - } else { - $items.get().reverse().forEach(function (item) { - if ($items.filter(':checked').length > _this23.options.minimumCountColumns) { - $(item).prop('checked', visible); - } - }); - } - - if ($items.filter(':checked').length <= this.options.minimumCountColumns) { - $items.filter(':checked').prop('disabled', true); - } - } - } - }, { - key: "mergeCells", - value: function mergeCells(options) { - var row = options.index; - var col = this.getVisibleFields().indexOf(options.field); - var rowspan = options.rowspan || 1; - var colspan = options.colspan || 1; - var i; - var j; - var $tr = this.$body.find('>tr'); - - if (this.options.detailView && !this.options.cardView) { - col += 1; - } - - var $td = $tr.eq(row).find('>td').eq(col); - - if (row < 0 || col < 0 || row >= this.data.length) { - return; - } - - for (i = row; i < row + rowspan; i++) { - for (j = col; j < col + colspan; j++) { - $tr.eq(i).find('>td').eq(j).hide(); - } - } - - $td.attr('rowspan', rowspan).attr('colspan', colspan).show(); - } - }, { - key: "checkAll", - value: function checkAll() { - this._toggleCheckAll(true); - } - }, { - key: "uncheckAll", - value: function uncheckAll() { - this._toggleCheckAll(false); - } - }, { - key: "_toggleCheckAll", - value: function _toggleCheckAll(checked) { - var rowsBefore = this.getSelections(); - this.$selectAll.add(this.$selectAll_).prop('checked', checked); - this.$selectItem.filter(':enabled').prop('checked', checked); - this.updateRows(); - var rowsAfter = this.getSelections(); - - if (checked) { - this.trigger('check-all', rowsAfter, rowsBefore); - return; - } - - this.trigger('uncheck-all', rowsAfter, rowsBefore); - } - }, { - key: "checkInvert", - value: function checkInvert() { - var $items = this.$selectItem.filter(':enabled'); - var checked = $items.filter(':checked'); - $items.each(function (i, el) { - $(el).prop('checked', !$(el).prop('checked')); - }); - this.updateRows(); - this.updateSelected(); - this.trigger('uncheck-some', checked); - checked = this.getSelections(); - this.trigger('check-some', checked); - } - }, { - key: "check", - value: function check(index) { - this._toggleCheck(true, index); - } - }, { - key: "uncheck", - value: function uncheck(index) { - this._toggleCheck(false, index); - } - }, { - key: "_toggleCheck", - value: function _toggleCheck(checked, index) { - var $el = this.$selectItem.filter("[data-index=\"".concat(index, "\"]")); - var row = this.data[index]; - - if ($el.is(':radio') || this.options.singleSelect || this.options.multipleSelectRow && !this.multipleSelectRowCtrlKey && !this.multipleSelectRowShiftKey) { - var _iteratorNormalCompletion9 = true; - var _didIteratorError9 = false; - var _iteratorError9 = undefined; - - try { - for (var _iterator9 = this.options.data[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { - var r = _step9.value; - r[this.header.stateField] = false; - } - } catch (err) { - _didIteratorError9 = true; - _iteratorError9 = err; - } finally { - try { - if (!_iteratorNormalCompletion9 && _iterator9.return != null) { - _iterator9.return(); - } - } finally { - if (_didIteratorError9) { - throw _iteratorError9; - } - } - } - - this.$selectItem.filter(':checked').not($el).prop('checked', false); - } - - row[this.header.stateField] = checked; - - if (this.options.multipleSelectRow) { - if (this.multipleSelectRowShiftKey && this.multipleSelectRowLastSelectedIndex >= 0) { - var indexes = [this.multipleSelectRowLastSelectedIndex, index].sort(); - - for (var i = indexes[0] + 1; i < indexes[1]; i++) { - this.data[i][this.header.stateField] = true; - this.$selectItem.filter("[data-index=\"".concat(i, "\"]")).prop('checked', true); - } - } - - this.multipleSelectRowCtrlKey = false; - this.multipleSelectRowShiftKey = false; - this.multipleSelectRowLastSelectedIndex = checked ? index : -1; - } - - $el.prop('checked', checked); - this.updateSelected(); - this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el); - } - }, { - key: "checkBy", - value: function checkBy(obj) { - this._toggleCheckBy(true, obj); - } - }, { - key: "uncheckBy", - value: function uncheckBy(obj) { - this._toggleCheckBy(false, obj); - } - }, { - key: "_toggleCheckBy", - value: function _toggleCheckBy(checked, obj) { - var _this24 = this; - - if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) { - return; - } - - var rows = []; - this.data.forEach(function (row, i) { - if (!row.hasOwnProperty(obj.field)) { - return false; - } - - if (obj.values.includes(row[obj.field])) { - var $el = _this24.$selectItem.filter(':enabled').filter(Utils.sprintf('[data-index="%s"]', i)); - - $el = checked ? $el.not(':checked') : $el.filter(':checked'); - - if (!$el.length) { - return; - } - - $el.prop('checked', checked); - row[_this24.header.stateField] = checked; - rows.push(row); - - _this24.trigger(checked ? 'check' : 'uncheck', row, $el); - } - }); - this.updateSelected(); - this.trigger(checked ? 'check-some' : 'uncheck-some', rows); - } - }, { - key: "refresh", - value: function refresh(params) { - if (params && params.url) { - this.options.url = params.url; - } - - if (params && params.pageNumber) { - this.options.pageNumber = params.pageNumber; - } - - if (params && params.pageSize) { - this.options.pageSize = params.pageSize; - } - - this.trigger('refresh', this.initServer(params && params.silent, params && params.query, params && params.url)); - } - }, { - key: "destroy", - value: function destroy() { - this.$el.insertBefore(this.$container); - $(this.options.toolbar).insertBefore(this.$el); - this.$container.next().remove(); - this.$container.remove(); - this.$el.html(this.$el_.html()).css('margin-top', '0').attr('class', this.$el_.attr('class') || ''); // reset the class - } - }, { - key: "resetView", - value: function resetView(params) { - var padding = 0; - - if (params && params.height) { - this.options.height = params.height; - } - - this.$selectAll.prop('checked', this.$selectItem.length > 0 && this.$selectItem.length === this.$selectItem.filter(':checked').length); - this.$tableContainer.toggleClass('has-card-view', this.options.cardView); - - if (!this.options.cardView && this.options.showHeader && this.options.height) { - this.$tableHeader.show(); - this.resetHeader(); - padding += this.$header.outerHeight(true) + 1; - } else { - this.$tableHeader.hide(); - this.trigger('post-header'); - } - - if (!this.options.cardView && this.options.showFooter) { - this.$tableFooter.show(); - this.fitFooter(); - - if (this.options.height) { - padding += this.$tableFooter.outerHeight(true); - } - } - - if (this.$container.hasClass('fullscreen')) { - this.$tableContainer.css('height', ''); - this.$tableContainer.css('width', ''); - } else if (this.options.height) { - var toolbarHeight = this.$toolbar.outerHeight(true); - var paginationHeight = this.$pagination.outerHeight(true); - var height = this.options.height - toolbarHeight - paginationHeight; - var $bodyTable = this.$tableBody.find('>table'); - var tableHeight = $bodyTable.outerHeight(); - this.$tableContainer.css('height', "".concat(height, "px")); - - if (this.$tableBorder) { - var tableBorderHeight = height - tableHeight - 2; - - if (this.$tableBody[0].scrollWidth - this.$tableBody.innerWidth()) { - tableBorderHeight -= Utils.getScrollBarWidth(); - } - - this.$tableBorder.css('width', "".concat($bodyTable.outerWidth(), "px")); - this.$tableBorder.css('height', "".concat(tableBorderHeight, "px")); - } - } - - if (this.options.cardView) { - // remove the element css - this.$el.css('margin-top', '0'); - this.$tableContainer.css('padding-bottom', '0'); - this.$tableFooter.hide(); - } else { - // Assign the correct sortable arrow - this.getCaret(); - this.$tableContainer.css('padding-bottom', "".concat(padding, "px")); - } - - this.trigger('reset-view'); - } - }, { - key: "showLoading", - value: function showLoading() { - this.$tableLoading.css('display', 'flex'); - } - }, { - key: "hideLoading", - value: function hideLoading() { - this.$tableLoading.css('display', 'none'); - } - }, { - key: "togglePagination", - value: function togglePagination() { - this.options.pagination = !this.options.pagination; - var icon = this.options.showButtonIcons ? this.options.pagination ? this.options.icons.paginationSwitchDown : this.options.icons.paginationSwitchUp : ''; - var text = this.options.showButtonText ? this.options.pagination ? this.options.formatPaginationSwitchUp() : this.options.formatPaginationSwitchDown() : ''; - this.$toolbar.find('button[name="paginationSwitch"]').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon) + ' ' + text); - this.updatePagination(); - } - }, { - key: "toggleFullscreen", - value: function toggleFullscreen() { - this.$el.closest('.bootstrap-table').toggleClass('fullscreen'); - this.resetView(); - } - }, { - key: "toggleView", - value: function toggleView() { - this.options.cardView = !this.options.cardView; - this.initHeader(); - var icon = this.options.showButtonIcons ? this.options.cardView ? this.options.icons.toggleOn : this.options.icons.toggleOff : ''; - var text = this.options.showButtonText ? this.options.cardView ? this.options.formatToggleOff() : this.options.formatToggleOn() : ''; - this.$toolbar.find('button[name="toggle"]').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon) + ' ' + text); - this.initBody(); - this.trigger('toggle', this.options.cardView); - } - }, { - key: "resetSearch", - value: function resetSearch(text) { - var $search = this.$toolbar.find('.search input'); - $search.val(text || ''); - this.onSearch({ - currentTarget: $search - }); - } - }, { - key: "filterBy", - value: function filterBy(columns, options) { - this.filterOptions = Utils.isEmptyObject(options) ? this.options.filterOptions : $.extend(this.options.filterOptions, options); - this.filterColumns = Utils.isEmptyObject(columns) ? {} : columns; - this.options.pageNumber = 1; - this.initSearch(); - this.updatePagination(); - } - }, { - key: "scrollTo", - value: function scrollTo(params) { - if (typeof params === 'undefined') { - return this.$tableBody.scrollTop(); - } - - var options = { - unit: 'px', - value: 0 - }; - - if (_typeof(params) === 'object') { - options = Object.assign(options, params); - } else if (typeof params === 'string' && params === 'bottom') { - options.value = this.$tableBody[0].scrollHeight; - } else if (typeof params === 'string') { - options.value = params; - } - - var scrollTo = options.value; - - if (options.unit === 'rows') { - scrollTo = 0; - this.$body.find("> tr:lt(".concat(options.value, ")")).each(function (i, el) { - scrollTo += $(el).outerHeight(true); - }); - } - - this.$tableBody.scrollTop(scrollTo); - } - }, { - key: "getScrollPosition", - value: function getScrollPosition() { - return this.scrollTo(); - } - }, { - key: "selectPage", - value: function selectPage(page) { - if (page > 0 && page <= this.options.totalPages) { - this.options.pageNumber = page; - this.updatePagination(); - } - } - }, { - key: "prevPage", - value: function prevPage() { - if (this.options.pageNumber > 1) { - this.options.pageNumber--; - this.updatePagination(); - } - } - }, { - key: "nextPage", - value: function nextPage() { - if (this.options.pageNumber < this.options.totalPages) { - this.options.pageNumber++; - this.updatePagination(); - } - } - }, { - key: "toggleDetailView", - value: function toggleDetailView(index, _columnDetailFormatter) { - var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', index)); - - if ($tr.next().is('tr.detail-view')) { - this.collapseRow(index); - } else { - this.expandRow(index, _columnDetailFormatter); - } - - this.resetView(); - } - }, { - key: "expandRow", - value: function expandRow(index, _columnDetailFormatter) { - var row = this.data[index]; - var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index)); - - if ($tr.next().is('tr.detail-view')) { - return; - } - - if (this.options.detailViewIcon) { - $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailClose)); - } - - $tr.after(Utils.sprintf('', $tr.children('td').length)); - var $element = $tr.next().find('td'); - var detailFormatter = _columnDetailFormatter || this.options.detailFormatter; - var content = Utils.calculateObjectValue(this.options, detailFormatter, [index, row, $element], ''); - - if ($element.length === 1) { - $element.append(content); - } - - this.trigger('expand-row', index, row, $element); - } - }, { - key: "collapseRow", - value: function collapseRow(index) { - var row = this.data[index]; - var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index)); - - if (!$tr.next().is('tr.detail-view')) { - return; - } - - if (this.options.detailViewIcon) { - $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen)); - } - - this.trigger('collapse-row', index, row, $tr.next()); - $tr.next().remove(); - } - }, { - key: "expandAllRows", - value: function expandAllRows() { - var trs = this.$body.find('> tr[data-index][data-has-detail-view]'); - - for (var i = 0; i < trs.length; i++) { - this.expandRow($(trs[i]).data('index')); - } - } - }, { - key: "collapseAllRows", - value: function collapseAllRows() { - var trs = this.$body.find('> tr[data-index][data-has-detail-view]'); - - for (var i = 0; i < trs.length; i++) { - this.collapseRow($(trs[i]).data('index')); - } - } - }, { - key: "updateColumnTitle", - value: function updateColumnTitle(params) { - if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) { - return; - } - - this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape ? Utils.escapeHTML(params.title) : params.title; - - if (this.columns[this.fieldsColumnsIndex[params.field]].visible) { - var header = this.options.height !== undefined ? this.$tableHeader : this.$header; - header.find('th[data-field]').each(function (i, el) { - if ($(el).data('field') === params.field) { - $($(el).find('.th-inner')[0]).text(params.title); - return false; - } - }); - } - } - }, { - key: "updateFormatText", - value: function updateFormatText(formatName, text) { - if (!/^format/.test(formatName) || !this.options[formatName]) { - return; - } - - if (typeof text === 'string') { - this.options[formatName] = function () { - return text; - }; - } else if (typeof text === 'function') { - this.options[formatName] = text; - } - - this.initToolbar(); - this.initPagination(); - this.initBody(); - } - }]); - - return BootstrapTable; - }(); + /*#__PURE__*/ + function () { + function BootstrapTable(el, options) { + _classCallCheck(this, BootstrapTable); + + this.options = options; + this.$el = $(el); + this.$el_ = this.$el.clone(); + this.timeoutId_ = 0; + this.timeoutFooter_ = 0; + this.init(); + } + + _createClass(BootstrapTable, [{ + key: "init", + value: function init() { + this.initConstants(); + this.initLocale(); + this.initContainer(); + this.initTable(); + this.initHeader(); + this.initData(); + this.initHiddenRows(); + this.initToolbar(); + this.initPagination(); + this.initBody(); + this.initSearchText(); + this.initServer(); + } + }, { + key: "initConstants", + value: function initConstants() { + var opts = this.options; + this.constants = Constants.CONSTANTS; + this.constants.theme = $.fn.bootstrapTable.theme; + var buttonsPrefix = opts.buttonsPrefix ? "".concat(opts.buttonsPrefix, "-") : ''; + this.constants.buttonsClass = [opts.buttonsPrefix, buttonsPrefix + opts.buttonsClass, Utils.sprintf("".concat(buttonsPrefix, "%s"), opts.iconSize)].join(' ').trim(); + } + }, { + key: "initLocale", + value: function initLocale() { + if (this.options.locale) { + var locales = $.fn.bootstrapTable.locales; + var parts = this.options.locale.split(/-|_/); + parts[0] = parts[0].toLowerCase(); + + if (parts[1]) { + parts[1] = parts[1].toUpperCase(); + } + + if (locales[this.options.locale]) { + $.extend(this.options, locales[this.options.locale]); + } else if (locales[parts.join('-')]) { + $.extend(this.options, locales[parts.join('-')]); + } else if (locales[parts[0]]) { + $.extend(this.options, locales[parts[0]]); + } + } + } + }, { + key: "initContainer", + value: function initContainer() { + var topPagination = ['top', 'both'].includes(this.options.paginationVAlign) ? '
    ' : ''; + var bottomPagination = ['bottom', 'both'].includes(this.options.paginationVAlign) ? '
    ' : ''; + this.$container = $("\n
    \n
    \n ").concat(topPagination, "\n
    \n
    \n
    \n
    \n \n ").concat(this.options.formatLoadingMessage(), "\n \n \n
    \n
    \n
    \n
    \n ").concat(bottomPagination, "\n
    \n ")); + this.$container.insertAfter(this.$el); + this.$tableContainer = this.$container.find('.fixed-table-container'); + this.$tableHeader = this.$container.find('.fixed-table-header'); + this.$tableBody = this.$container.find('.fixed-table-body'); + this.$tableLoading = this.$container.find('.fixed-table-loading'); + this.$tableFooter = this.$el.find('tfoot'); // checking if custom table-toolbar exists or not + + if (this.options.buttonsToolbar) { + this.$toolbar = $('body').find(this.options.buttonsToolbar); + } else { + this.$toolbar = this.$container.find('.fixed-table-toolbar'); + } + + this.$pagination = this.$container.find('.fixed-table-pagination'); + this.$tableBody.append(this.$el); + this.$container.after('
    '); + this.$el.addClass(this.options.classes); + this.$tableLoading.addClass(this.options.classes); + + if (this.options.height) { + this.$tableContainer.addClass('fixed-height'); + + if (this.options.showFooter) { + this.$tableContainer.addClass('has-footer'); + } + + if (this.options.classes.split(' ').includes('table-bordered')) { + this.$tableBody.append('
    '); + this.$tableBorder = this.$tableBody.find('.fixed-table-border'); + this.$tableLoading.addClass('fixed-table-border'); + } + + this.$tableFooter = this.$container.find('.fixed-table-footer'); + } + } + }, { + key: "initTable", + value: function initTable() { + var _this = this; + + var columns = []; + this.$header = this.$el.find('>thead'); + + if (!this.$header.length) { + this.$header = $("")).appendTo(this.$el); + } else if (this.options.theadClasses) { + this.$header.addClass(this.options.theadClasses); + } + + this.$header.find('tr').each(function (i, el) { + var column = []; + $(el).find('th').each(function (i, el) { + // #2014: getFieldIndex and elsewhere assume this is string, causes issues if not + if (typeof $(el).data('field') !== 'undefined') { + $(el).data('field', "".concat($(el).data('field'))); + } + + column.push($.extend({}, { + title: $(el).html(), + 'class': $(el).attr('class'), + titleTooltip: $(el).attr('title'), + rowspan: $(el).attr('rowspan') ? +$(el).attr('rowspan') : undefined, + colspan: $(el).attr('colspan') ? +$(el).attr('colspan') : undefined + }, $(el).data())); + }); + columns.push(column); + }); + + if (!Array.isArray(this.options.columns[0])) { + this.options.columns = [this.options.columns]; + } + + this.options.columns = $.extend(true, [], columns, this.options.columns); + this.columns = []; + this.fieldsColumnsIndex = []; + Utils.setFieldIndex(this.options.columns); + this.options.columns.forEach(function (columns, i) { + columns.forEach(function (_column, j) { + var column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, _column); + + if (typeof column.fieldIndex !== 'undefined') { + _this.columns[column.fieldIndex] = column; + _this.fieldsColumnsIndex[column.field] = column.fieldIndex; + } + + _this.options.columns[i][j] = column; + }); + }); // if options.data is setting, do not process tbody and tfoot data + + if (!this.options.data.length) { + this.options.data = Utils.trToData(this.columns, this.$el.find('>tbody>tr')); + + if (this.options.data.length) { + this.fromHtml = true; + } + } + + this.footerData = Utils.trToData(this.columns, this.$el.find('>tfoot>tr')); + + if (this.footerData) { + this.$el.find('tfoot').html(''); + } + + if (!this.options.showFooter || this.options.cardView) { + this.$tableFooter.hide(); + } else { + this.$tableFooter.show(); + } + } + }, { + key: "initHeader", + value: function initHeader() { + var _this2 = this; + + var visibleColumns = {}; + var html = []; + this.header = { + fields: [], + styles: [], + classes: [], + formatters: [], + detailFormatters: [], + events: [], + sorters: [], + sortNames: [], + cellStyles: [], + searchables: [] + }; + Utils.updateFieldGroup(this.options.columns); + this.options.columns.forEach(function (columns, i) { + html.push(''); + + if (i === 0 && !_this2.options.cardView && _this2.options.detailView && _this2.options.detailViewIcon) { + html.push("\n
    \n \n ")); + } + + columns.forEach(function (column, j) { + var class_ = Utils.sprintf(' class="%s"', column['class']); + var unitWidth = column.widthUnit; + var width = parseFloat(column.width); + var halign = Utils.sprintf('text-align: %s; ', column.halign ? column.halign : column.align); + var align = Utils.sprintf('text-align: %s; ', column.align); + var style = Utils.sprintf('vertical-align: %s; ', column.valign); + style += Utils.sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? !column.showSelectTitle ? '36px' : undefined : width ? width + unitWidth : undefined); + + if (typeof column.fieldIndex === 'undefined' && !column.visible) { + return; + } + + var headerStyle = Utils.calculateObjectValue(null, _this2.options.headerStyle, [column]); + var csses = []; + var classes = ''; + + if (headerStyle && headerStyle.css) { + for (var _i = 0, _Object$entries = Object.entries(headerStyle.css); _i < _Object$entries.length; _i++) { + var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), + key = _Object$entries$_i[0], + value = _Object$entries$_i[1]; + + csses.push("".concat(key, ": ").concat(value)); + } + } + + if (headerStyle && headerStyle.classes) { + classes = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], headerStyle.classes].join(' ') : headerStyle.classes); + } + + if (typeof column.fieldIndex !== 'undefined') { + _this2.header.fields[column.fieldIndex] = column.field; + _this2.header.styles[column.fieldIndex] = align + style; + _this2.header.classes[column.fieldIndex] = class_; + _this2.header.formatters[column.fieldIndex] = column.formatter; + _this2.header.detailFormatters[column.fieldIndex] = column.detailFormatter; + _this2.header.events[column.fieldIndex] = column.events; + _this2.header.sorters[column.fieldIndex] = column.sorter; + _this2.header.sortNames[column.fieldIndex] = column.sortName; + _this2.header.cellStyles[column.fieldIndex] = column.cellStyle; + _this2.header.searchables[column.fieldIndex] = column.searchable; + + if (!column.visible) { + return; + } + + if (_this2.options.cardView && !column.cardVisible) { + return; + } + + visibleColumns[column.field] = column; + } + + html.push(" 0 ? ' data-not-first-th' : '', '>'); + html.push(Utils.sprintf('
    ', _this2.options.sortable && column.sortable ? 'sortable both' : '')); + var text = _this2.options.escape ? Utils.escapeHTML(column.title) : column.title; + var title = text; + + if (column.checkbox) { + text = ''; + + if (!_this2.options.singleSelect && _this2.options.checkboxHeader) { + text = ''; + } + + _this2.header.stateField = column.field; + } + + if (column.radio) { + text = ''; + _this2.header.stateField = column.field; + } + + if (!text && column.showSelectTitle) { + text += title; + } + + html.push(text); + html.push('
    '); + html.push('
    '); + html.push('
    '); + html.push(''); + }); + html.push(''); + }); + this.$header.html(html.join('')); + this.$header.find('th[data-field]').each(function (i, el) { + $(el).data(visibleColumns[$(el).data('field')]); + }); + this.$container.off('click', '.th-inner').on('click', '.th-inner', function (e) { + var $this = $(e.currentTarget); + + if (_this2.options.detailView && !$this.parent().hasClass('bs-checkbox')) { + if ($this.closest('.bootstrap-table')[0] !== _this2.$container[0]) { + return false; + } + } + + if (_this2.options.sortable && $this.parent().data().sortable) { + _this2.onSort(e); + } + }); + this.$header.children().children().off('keypress').on('keypress', function (e) { + if (_this2.options.sortable && $(e.currentTarget).data().sortable) { + var code = e.keyCode || e.which; + + if (code === 13) { + // Enter keycode + _this2.onSort(e); + } + } + }); + var resizeEvent = Utils.getResizeEventName(this.$el.attr('id')); + $(window).off(resizeEvent); + + if (!this.options.showHeader || this.options.cardView) { + this.$header.hide(); + this.$tableHeader.hide(); + this.$tableLoading.css('top', 0); + } else { + this.$header.show(); + this.$tableHeader.show(); + this.$tableLoading.css('top', this.$header.outerHeight() + 1); // Assign the correct sortable arrow + + this.getCaret(); + $(window).on(resizeEvent, function () { + return _this2.resetView(); + }); + } + + this.$selectAll = this.$header.find('[name="btSelectAll"]'); + this.$selectAll.off('click').on('click', function (e) { + e.stopPropagation(); + var checked = $(e.currentTarget).prop('checked'); + + _this2[checked ? 'checkAll' : 'uncheckAll'](); + + _this2.updateSelected(); + }); + } + }, { + key: "initData", + value: function initData(data, type) { + if (type === 'append') { + this.options.data = this.options.data.concat(data); + } else if (type === 'prepend') { + this.options.data = [].concat(data).concat(this.options.data); + } else { + this.options.data = data || this.options.data; + } + + this.data = this.options.data; + + if (this.options.sidePagination === 'server') { + return; + } + + this.initSort(); + } + }, { + key: "initSort", + value: function initSort() { + var _this3 = this; + + var name = this.options.sortName; + var order = this.options.sortOrder === 'desc' ? -1 : 1; + var index = this.header.fields.indexOf(this.options.sortName); + var timeoutId = 0; + + if (index !== -1) { + if (this.options.sortStable) { + this.data.forEach(function (row, i) { + if (!row.hasOwnProperty('_position')) { + row._position = i; + } + }); + } + + if (this.options.customSort) { + Utils.calculateObjectValue(this.options, this.options.customSort, [this.options.sortName, this.options.sortOrder, this.data]); + } else { + this.data.sort(function (a, b) { + if (_this3.header.sortNames[index]) { + name = _this3.header.sortNames[index]; + } + + var aa = Utils.getItemField(a, name, _this3.options.escape); + var bb = Utils.getItemField(b, name, _this3.options.escape); + var value = Utils.calculateObjectValue(_this3.header, _this3.header.sorters[index], [aa, bb, a, b]); + + if (value !== undefined) { + if (_this3.options.sortStable && value === 0) { + return order * (a._position - b._position); + } + + return order * value; + } + + return Utils.sort(aa, bb, order, _this3.options.sortStable, a._position, b._position); + }); + } + + if (this.options.sortClass !== undefined) { + clearTimeout(timeoutId); + timeoutId = setTimeout(function () { + _this3.$el.removeClass(_this3.options.sortClass); + + var index = _this3.$header.find("[data-field=\"".concat(_this3.options.sortName, "\"]")).index(); + + _this3.$el.find("tr td:nth-child(".concat(index + 1, ")")).addClass(_this3.options.sortClass); + }, 250); + } + } + } + }, { + key: "onSort", + value: function onSort(_ref) { + var type = _ref.type, + currentTarget = _ref.currentTarget; + var $this = type === 'keypress' ? $(currentTarget) : $(currentTarget).parent(); + var $this_ = this.$header.find('th').eq($this.index()); + this.$header.add(this.$header_).find('span.order').remove(); + + if (this.options.sortName === $this.data('field')) { + this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc'; + } else { + this.options.sortName = $this.data('field'); + + if (this.options.rememberOrder) { + this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc'; + } else { + this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].sortOrder || this.columns[this.fieldsColumnsIndex[$this.data('field')]].order; + } + } + + this.trigger('sort', this.options.sortName, this.options.sortOrder); + $this.add($this_).data('order', this.options.sortOrder); // Assign the correct sortable arrow + + this.getCaret(); + + if (this.options.sidePagination === 'server' && this.options.serverSort) { + this.options.pageNumber = 1; + this.initServer(this.options.silentSort); + return; + } + + this.initSort(); + this.initBody(); + } + }, { + key: "initToolbar", + value: function initToolbar() { + var _this4 = this; + + var opts = this.options; + var html = []; + var timeoutId = 0; + var $keepOpen; + var switchableCount = 0; + + if (this.$toolbar.find('.bs-bars').children().length) { + $('body').append($(opts.toolbar)); + } + + this.$toolbar.html(''); + + if (typeof opts.toolbar === 'string' || _typeof(opts.toolbar) === 'object') { + $(Utils.sprintf('
    ', this.constants.classes.pull, opts.toolbarAlign)).appendTo(this.$toolbar).append($(opts.toolbar)); + } // showColumns, showToggle, showRefresh + + + html = ["
    ")]; + + if (typeof opts.icons === 'string') { + opts.icons = Utils.calculateObjectValue(null, opts.icons); + } + + var buttonsHtml = { + paginationSwitch: ""), + refresh: ""), + toggle: ""), + fullscreen: ""), + columns: function () { + var html = []; + html.push("
    \n \n ").concat(_this4.constants.html.toolbarDropdown[0])); + + if (opts.showColumnsSearch) { + html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf('', _this4.constants.classes.input, opts.formatSearch()))); + html.push(_this4.constants.html.toolbarDropdownSeparator); + } + + if (opts.showColumnsToggleAll) { + var allFieldsVisible = _this4.getVisibleColumns().length === _this4.columns.filter(function (column) { + return !_this4.isSelectionColumn(column); + }).length; + + html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf(' %s', allFieldsVisible ? 'checked="checked"' : '', opts.formatColumnsToggleAll()))); + html.push(_this4.constants.html.toolbarDropdownSeparator); + } + + var visibleColumns = 0; + + _this4.columns.forEach(function (column, i) { + if (column.visible) { + visibleColumns++; + } + }); + + _this4.columns.forEach(function (column, i) { + if (_this4.isSelectionColumn(column)) { + return; + } + + if (opts.cardView && !column.cardVisible) { + return; + } + + var checked = column.visible ? ' checked="checked"' : ''; + var disabled = visibleColumns <= _this4.options.minimumCountColumns && checked ? ' disabled="disabled"' : ''; + + if (column.switchable) { + html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf(' %s', column.field, i, checked, disabled, column.title))); + switchableCount++; + } + }); + + html.push(_this4.constants.html.toolbarDropdown[1], '
    '); + return html.join(''); + }() + }; + + if (typeof opts.buttonsOrder === 'string') { + opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(','); + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = opts.buttonsOrder[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var button = _step.value; + + if (opts['show' + button.charAt(0).toUpperCase() + button.substring(1)]) { + html.push(buttonsHtml[button]); + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + html.push('
    '); // Fix #188: this.showToolbar is for extensions + + if (this.showToolbar || html.length > 2) { + this.$toolbar.append(html.join('')); + } + + if (opts.showPaginationSwitch) { + this.$toolbar.find('button[name="paginationSwitch"]').off('click').on('click', function () { + return _this4.togglePagination(); + }); + } + + if (opts.showFullscreen) { + this.$toolbar.find('button[name="fullscreen"]').off('click').on('click', function () { + return _this4.toggleFullscreen(); + }); + } + + if (opts.showRefresh) { + this.$toolbar.find('button[name="refresh"]').off('click').on('click', function () { + return _this4.refresh(); + }); + } + + if (opts.showToggle) { + this.$toolbar.find('button[name="toggle"]').off('click').on('click', function () { + _this4.toggleView(); + }); + } + + if (opts.showColumns) { + $keepOpen = this.$toolbar.find('.keep-open'); + var $checkboxes = $keepOpen.find('input[type="checkbox"]:not(".toggle-all")'); + var $toggleAll = $keepOpen.find('input[type="checkbox"].toggle-all'); + + if (switchableCount <= opts.minimumCountColumns) { + $keepOpen.find('input').prop('disabled', true); + } + + $keepOpen.find('li, label').off('click').on('click', function (e) { + e.stopImmediatePropagation(); + }); + $checkboxes.off('click').on('click', function (_ref2) { + var currentTarget = _ref2.currentTarget; + var $this = $(currentTarget); + + _this4._toggleColumn($this.val(), $this.prop('checked'), false); + + _this4.trigger('column-switch', $this.data('field'), $this.prop('checked')); + + $toggleAll.prop('checked', $checkboxes.filter(':checked').length === _this4.columns.filter(function (column) { + return !_this4.isSelectionColumn(column); + }).length); + }); + $toggleAll.off('click').on('click', function (_ref3) { + var currentTarget = _ref3.currentTarget; + + _this4._toggleAllColumns($(currentTarget).prop('checked')); + }); + + if (opts.showColumnsSearch) { + var $columnsSearch = $keepOpen.find('#columnsSearch'); + var $listItems = $keepOpen.find('.dropdown-item-marker'); + $columnsSearch.on('keyup paste change', function (_ref4) { + var currentTarget = _ref4.currentTarget; + var $this = $(currentTarget); + var searchValue = $this.val().toLowerCase(); + $listItems.show(); + $checkboxes.each(function (i, el) { + var $checkbox = $(el); + var $listItem = $checkbox.parents('.dropdown-item-marker'); + var text = $listItem.text().toLowerCase(); + + if (!text.includes(searchValue)) { + $listItem.hide(); + } + }); + }); + } + } // Fix #4516: this.showSearchClearButton is for extensions + + + if (opts.search || this.showSearchClearButton) { + html = []; + var showSearchButton = Utils.sprintf(this.constants.html.searchButton, this.constants.buttonsClass, opts.formatSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.search) : '', opts.showButtonText ? opts.formatSearch() : ''); + var showSearchClearButton = Utils.sprintf(this.constants.html.searchClearButton, this.constants.buttonsClass, opts.formatClearSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.clearSearch) : '', opts.showButtonText ? opts.formatClearSearch() : ''); + var searchInputHtml = ""); + var searchInputFinalHtml = searchInputHtml; + + if (opts.showSearchButton || opts.showSearchClearButton) { + var _buttonsHtml = (opts.showSearchButton ? showSearchButton : '') + (opts.showSearchClearButton ? showSearchClearButton : ''); + + searchInputFinalHtml = opts.search ? Utils.sprintf(this.constants.html.inputGroup, searchInputHtml, _buttonsHtml) : _buttonsHtml; + } + + html.push(Utils.sprintf("\n
    \n %s\n
    \n "), searchInputFinalHtml)); + this.$toolbar.append(html.join('')); + var $searchInput = this.$toolbar.find('.search input'); + + var handleInputEvent = function handleInputEvent() { + var eventTriggers = "keyup drop blur ".concat(Utils.isIEBrowser() ? 'mouseup' : ''); + $searchInput.off(eventTriggers).on(eventTriggers, function (event) { + if (opts.searchOnEnterKey && event.keyCode !== 13) { + return; + } + + if ([37, 38, 39, 40].includes(event.keyCode)) { + return; + } + + clearTimeout(timeoutId); // doesn't matter if it's 0 + + timeoutId = setTimeout(function () { + _this4.onSearch({ + currentTarget: event.currentTarget + }); + }, opts.searchTimeOut); + }); + }; + + if (opts.showSearchButton) { + this.$toolbar.find('.search button[name=search]').off('click').on('click', function (event) { + clearTimeout(timeoutId); // doesn't matter if it's 0 + + timeoutId = setTimeout(function () { + _this4.onSearch({ + currentTarget: $searchInput + }); + }, opts.searchTimeOut); + }); + + if (opts.searchOnEnterKey) { + handleInputEvent(); + } + } else { + handleInputEvent(); + } + + if (opts.showSearchClearButton) { + this.$toolbar.find('.search button[name=clearSearch]').click(function () { + _this4.resetSearch(); + }); + } + } + } + }, { + key: "onSearch", + value: function onSearch() { + var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + currentTarget = _ref5.currentTarget, + firedByInitSearchText = _ref5.firedByInitSearchText; + + var overwriteSearchText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + if (currentTarget !== undefined && $(currentTarget).length && overwriteSearchText) { + var text = $(currentTarget).val().trim(); + + if (this.options.trimOnSearch && $(currentTarget).val() !== text) { + $(currentTarget).val(text); + } + + if (this.searchText === text && text.length > 0) { + return; + } + + if ($(currentTarget).hasClass('search-input')) { + this.searchText = text; + this.options.searchText = text; + } + } + + if (!firedByInitSearchText) { + this.options.pageNumber = 1; + } + + this.initSearch(); + + if (firedByInitSearchText) { + if (this.options.sidePagination === 'client') { + this.updatePagination(); + } + } else { + this.updatePagination(); + } + + this.trigger('search', this.searchText); + } + }, { + key: "initSearch", + value: function initSearch() { + var _this5 = this; + + this.filterOptions = this.filterOptions || this.options.filterOptions; + + if (this.options.sidePagination !== 'server') { + if (this.options.customSearch) { + this.data = Utils.calculateObjectValue(this.options, this.options.customSearch, [this.options.data, this.searchText, this.filterColumns]); + return; + } + + var s = this.searchText && (this.fromHtml ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase(); + var f = Utils.isEmptyObject(this.filterColumns) ? null : this.filterColumns; // Check filter + + if (typeof this.filterOptions.filterAlgorithm === 'function') { + this.data = this.options.data.filter(function (item, i) { + return _this5.filterOptions.filterAlgorithm.apply(null, [item, f]); + }); + } else if (typeof this.filterOptions.filterAlgorithm === 'string') { + this.data = f ? this.options.data.filter(function (item, i) { + var filterAlgorithm = _this5.filterOptions.filterAlgorithm; + + if (filterAlgorithm === 'and') { + for (var key in f) { + if (Array.isArray(f[key]) && !f[key].includes(item[key]) || !Array.isArray(f[key]) && item[key] !== f[key]) { + return false; + } + } + } else if (filterAlgorithm === 'or') { + var match = false; + + for (var _key in f) { + if (Array.isArray(f[_key]) && f[_key].includes(item[_key]) || !Array.isArray(f[_key]) && item[_key] === f[_key]) { + match = true; + } + } + + return match; + } + + return true; + }) : this.options.data; + } + + var visibleFields = this.getVisibleFields(); + this.data = s ? this.data.filter(function (item, i) { + for (var j = 0; j < _this5.header.fields.length; j++) { + if (!_this5.header.searchables[j] || _this5.options.visibleSearch && visibleFields.indexOf(_this5.header.fields[j]) === -1) { + continue; + } + + var key = Utils.isNumeric(_this5.header.fields[j]) ? parseInt(_this5.header.fields[j], 10) : _this5.header.fields[j]; + var column = _this5.columns[_this5.fieldsColumnsIndex[key]]; + var value = void 0; + + if (typeof key === 'string') { + value = item; + var props = key.split('.'); + + for (var _i2 = 0; _i2 < props.length; _i2++) { + if (value[props[_i2]] !== null) { + value = value[props[_i2]]; + } + } + } else { + value = item[key]; + } // Fix #142: respect searchFormatter boolean + + + if (column && column.searchFormatter) { + value = Utils.calculateObjectValue(column, _this5.header.formatters[j], [value, item, i, column.field], value); + } + + if (typeof value === 'string' || typeof value === 'number') { + if (_this5.options.strictSearch) { + if ("".concat(value).toLowerCase() === s) { + return true; + } + } else { + var largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm; + var matches = largerSmallerEqualsRegex.exec(s); + var comparisonCheck = false; + + if (matches) { + var operator = matches[1] || "".concat(matches[5], "l"); + var comparisonValue = matches[2] || matches[3]; + var int = parseInt(value, 10); + var comparisonInt = parseInt(comparisonValue, 10); + + switch (operator) { + case '>': + case ' comparisonInt; + break; + + case '<': + case '>l': + comparisonCheck = int < comparisonInt; + break; + + case '<=': + case '=<': + case '>=l': + case '=>l': + comparisonCheck = int <= comparisonInt; + break; + + case '>=': + case '=>': + case '<=l': + case '== comparisonInt; + break; + } + } + + if (comparisonCheck || "".concat(value).toLowerCase().includes(s)) { + return true; + } + } + } + } + + return false; + }) : this.data; + } + + this.initSort(); + } + }, { + key: "initPagination", + value: function initPagination() { + var _this6 = this; + + var opts = this.options; + + if (!opts.pagination) { + this.$pagination.hide(); + return; + } + + this.$pagination.show(); + var html = []; + var allSelected = false; + var i; + var from; + var to; + var $pageList; + var $pre; + var $next; + var $number; + var data = this.getData({ + includeHiddenRows: false + }); + var pageList = opts.pageList; + + if (typeof pageList === 'string') { + pageList = pageList.replace(/\[|\]| /g, '').toLowerCase().split(','); + } + + pageList = pageList.map(function (value) { + if (typeof value === 'string') { + return value.toLowerCase() === opts.formatAllRows().toLowerCase() || ['all', 'unlimited'].includes(value.toLowerCase()) ? opts.formatAllRows() : +value; + } + + return value; + }); + + if (opts.sidePagination !== 'server') { + opts.totalRows = data.length; + } + + this.totalPages = 0; + + if (opts.totalRows) { + if (opts.pageSize === opts.formatAllRows()) { + opts.pageSize = opts.totalRows; + allSelected = true; + } + + this.totalPages = ~~((opts.totalRows - 1) / opts.pageSize) + 1; + opts.totalPages = this.totalPages; + } + + if (this.totalPages > 0 && opts.pageNumber > this.totalPages) { + opts.pageNumber = this.totalPages; + } + + this.pageFrom = (opts.pageNumber - 1) * opts.pageSize + 1; + this.pageTo = opts.pageNumber * opts.pageSize; + + if (this.pageTo > opts.totalRows) { + this.pageTo = opts.totalRows; + } + + if (this.options.pagination && this.options.sidePagination !== 'server') { + this.options.totalNotFiltered = this.options.data.length; + } + + if (!this.options.showExtendedPagination) { + this.options.totalNotFiltered = undefined; + } + + var paginationInfo = opts.onlyInfoPagination ? opts.formatDetailPagination(opts.totalRows) : opts.formatShowingRows(this.pageFrom, this.pageTo, opts.totalRows, opts.totalNotFiltered); + html.push("
    \n \n ").concat(paginationInfo, "\n ")); + + if (!opts.onlyInfoPagination) { + html.push(''); + var pageNumber = ["\n \n ").concat(this.constants.html.pageDropdown[0])]; + pageList.forEach(function (page, i) { + if (!opts.smartDisplay || i === 0 || pageList[i - 1] < opts.totalRows) { + var active; + + if (allSelected) { + active = page === opts.formatAllRows() ? _this6.constants.classes.dropdownActive : ''; + } else { + active = page === opts.pageSize ? _this6.constants.classes.dropdownActive : ''; + } + + pageNumber.push(Utils.sprintf(_this6.constants.html.pageDropdownItem, active, page)); + } + }); + pageNumber.push("".concat(this.constants.html.pageDropdown[1], "")); + html.push(opts.formatRecordsPerPage(pageNumber.join(''))); + html.push('
    '); + html.push("
    "), Utils.sprintf(this.constants.html.pagination[0], Utils.sprintf(' pagination-%s', opts.iconSize)), Utils.sprintf(this.constants.html.paginationItem, ' page-pre', opts.formatSRPaginationPreText(), opts.paginationPreText)); + + if (this.totalPages < opts.paginationSuccessivelySize) { + from = 1; + to = this.totalPages; + } else { + from = opts.pageNumber - opts.paginationPagesBySide; + to = from + opts.paginationPagesBySide * 2; + } + + if (opts.pageNumber < opts.paginationSuccessivelySize - 1) { + to = opts.paginationSuccessivelySize; + } + + if (opts.paginationSuccessivelySize > this.totalPages - from) { + from = from - (opts.paginationSuccessivelySize - (this.totalPages - from)) + 1; + } + + if (from < 1) { + from = 1; + } + + if (to > this.totalPages) { + to = this.totalPages; + } + + var middleSize = Math.round(opts.paginationPagesBySide / 2); + + var pageItem = function pageItem(i) { + var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; + return Utils.sprintf(_this6.constants.html.paginationItem, classes + (i === opts.pageNumber ? " ".concat(_this6.constants.classes.paginationActive) : ''), opts.formatSRPaginationPageText(i), i); + }; + + if (from > 1) { + var max = opts.paginationPagesBySide; + if (max >= from) max = from - 1; + + for (i = 1; i <= max; i++) { + html.push(pageItem(i)); + } + + if (from - 1 === max + 1) { + i = from - 1; + html.push(pageItem(i)); + } else { + if (from - 1 > max) { + if (from - opts.paginationPagesBySide * 2 > opts.paginationPagesBySide && opts.paginationUseIntermediate) { + i = Math.round((from - middleSize) / 2 + middleSize); + html.push(pageItem(i, ' page-intermediate')); + } else { + html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-first-separator disabled', '', '...')); + } + } + } + } + + for (i = from; i <= to; i++) { + html.push(pageItem(i)); + } + + if (this.totalPages > to) { + var min = this.totalPages - (opts.paginationPagesBySide - 1); + if (to >= min) min = to + 1; + + if (to + 1 === min - 1) { + i = to + 1; + html.push(pageItem(i)); + } else { + if (min > to + 1) { + if (this.totalPages - to > opts.paginationPagesBySide * 2 && opts.paginationUseIntermediate) { + i = Math.round((this.totalPages - middleSize - to) / 2 + to); + html.push(pageItem(i, ' page-intermediate')); + } else { + html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-last-separator disabled', '', '...')); + } + } + } + + for (i = min; i <= this.totalPages; i++) { + html.push(pageItem(i)); + } + } + + html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-next', opts.formatSRPaginationNextText(), opts.paginationNextText)); + html.push(this.constants.html.pagination[1], '
    '); + } + + this.$pagination.html(html.join('')); + var dropupClass = ['bottom', 'both'].includes(opts.paginationVAlign) ? " ".concat(this.constants.classes.dropup) : ''; + this.$pagination.last().find('.page-list > span').addClass(dropupClass); + + if (!opts.onlyInfoPagination) { + $pageList = this.$pagination.find('.page-list a'); + $pre = this.$pagination.find('.page-pre'); + $next = this.$pagination.find('.page-next'); + $number = this.$pagination.find('.page-item').not('.page-next, .page-pre, .page-last-separator, .page-first-separator'); + + if (this.totalPages <= 1) { + this.$pagination.find('div.pagination').hide(); + } + + if (opts.smartDisplay) { + if (pageList.length < 2 || opts.totalRows <= pageList[0]) { + this.$pagination.find('span.page-list').hide(); + } + } // when data is empty, hide the pagination + + + this.$pagination[this.getData().length ? 'show' : 'hide'](); + + if (!opts.paginationLoop) { + if (opts.pageNumber === 1) { + $pre.addClass('disabled'); + } + + if (opts.pageNumber === this.totalPages) { + $next.addClass('disabled'); + } + } + + if (allSelected) { + opts.pageSize = opts.formatAllRows(); + } // removed the events for last and first, onPageNumber executeds the same logic + + + $pageList.off('click').on('click', function (e) { + return _this6.onPageListChange(e); + }); + $pre.off('click').on('click', function (e) { + return _this6.onPagePre(e); + }); + $next.off('click').on('click', function (e) { + return _this6.onPageNext(e); + }); + $number.off('click').on('click', function (e) { + return _this6.onPageNumber(e); + }); + } + } + }, { + key: "updatePagination", + value: function updatePagination(event) { + // Fix #171: IE disabled button can be clicked bug. + if (event && $(event.currentTarget).hasClass('disabled')) { + return; + } + + if (!this.options.maintainMetaData) { + this.resetRows(); + } + + this.initPagination(); + + if (this.options.sidePagination === 'server') { + this.initServer(); + } else { + this.initBody(); + } + + this.trigger('page-change', this.options.pageNumber, this.options.pageSize); + } + }, { + key: "onPageListChange", + value: function onPageListChange(event) { + event.preventDefault(); + var $this = $(event.currentTarget); + $this.parent().addClass(this.constants.classes.dropdownActive).siblings().removeClass(this.constants.classes.dropdownActive); + this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ? this.options.formatAllRows() : +$this.text(); + this.$toolbar.find('.page-size').text(this.options.pageSize); + this.updatePagination(event); + return false; + } + }, { + key: "onPagePre", + value: function onPagePre(event) { + event.preventDefault(); + + if (this.options.pageNumber - 1 === 0) { + this.options.pageNumber = this.options.totalPages; + } else { + this.options.pageNumber--; + } + + this.updatePagination(event); + return false; + } + }, { + key: "onPageNext", + value: function onPageNext(event) { + event.preventDefault(); + + if (this.options.pageNumber + 1 > this.options.totalPages) { + this.options.pageNumber = 1; + } else { + this.options.pageNumber++; + } + + this.updatePagination(event); + return false; + } + }, { + key: "onPageNumber", + value: function onPageNumber(event) { + event.preventDefault(); + + if (this.options.pageNumber === +$(event.currentTarget).text()) { + return; + } + + this.options.pageNumber = +$(event.currentTarget).text(); + this.updatePagination(event); + return false; + } + }, { + key: "initRow", + value: function initRow(item, i, data, trFragments) { + var _this7 = this; + + var html = []; + var style = {}; + var csses = []; + var data_ = ''; + var attributes = {}; + var htmlAttributes = []; + + if (Utils.findIndex(this.hiddenRows, item) > -1) { + return; + } + + style = Utils.calculateObjectValue(this.options, this.options.rowStyle, [item, i], style); + + if (style && style.css) { + for (var _i3 = 0, _Object$entries2 = Object.entries(style.css); _i3 < _Object$entries2.length; _i3++) { + var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2), + key = _Object$entries2$_i[0], + value = _Object$entries2$_i[1]; + + csses.push("".concat(key, ": ").concat(value)); + } + } + + attributes = Utils.calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes); + + if (attributes) { + for (var _i4 = 0, _Object$entries3 = Object.entries(attributes); _i4 < _Object$entries3.length; _i4++) { + var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i4], 2), + _key2 = _Object$entries3$_i[0], + _value = _Object$entries3$_i[1]; + + htmlAttributes.push("".concat(_key2, "=\"").concat(Utils.escapeHTML(_value), "\"")); + } + } + + if (item._data && !Utils.isEmptyObject(item._data)) { + for (var _i5 = 0, _Object$entries4 = Object.entries(item._data); _i5 < _Object$entries4.length; _i5++) { + var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2), + k = _Object$entries4$_i[0], + v = _Object$entries4$_i[1]; + + // ignore data-index + if (k === 'index') { + return; + } + + data_ += " data-".concat(k, "='").concat(_typeof(v) === 'object' ? JSON.stringify(v) : v, "'"); + } + } + + html.push(''); + + if (this.options.cardView) { + html.push("
    ")); + } + + if (!this.options.cardView && this.options.detailView && this.options.detailViewIcon) { + html.push(''); + + if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) { + html.push("\n \n ".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen), "\n \n ")); + } + + html.push(''); + } + + this.header.fields.forEach(function (field, j) { + var text = ''; + var value_ = Utils.getItemField(item, field, _this7.options.escape); + var value = ''; + var type = ''; + var cellStyle = {}; + var id_ = ''; + var class_ = _this7.header.classes[j]; + var style_ = ''; + var data_ = ''; + var rowspan_ = ''; + var colspan_ = ''; + var title_ = ''; + var column = _this7.columns[j]; + + if (_this7.fromHtml && typeof value_ === 'undefined') { + if (!column.checkbox && !column.radio) { + return; + } + } + + if (!column.visible) { + return; + } + + if (_this7.options.cardView && !column.cardVisible) { + return; + } + + if (column.escape) { + value_ = Utils.escapeHTML(value_); + } + + if (csses.concat([_this7.header.styles[j]]).length) { + style_ = " style=\"".concat(csses.concat([_this7.header.styles[j]]).join('; '), "\""); + } // handle td's id and class + + + if (item["_".concat(field, "_id")]) { + id_ = Utils.sprintf(' id="%s"', item["_".concat(field, "_id")]); + } + + if (item["_".concat(field, "_class")]) { + class_ = Utils.sprintf(' class="%s"', item["_".concat(field, "_class")]); + } + + if (item["_".concat(field, "_rowspan")]) { + rowspan_ = Utils.sprintf(' rowspan="%s"', item["_".concat(field, "_rowspan")]); + } + + if (item["_".concat(field, "_colspan")]) { + colspan_ = Utils.sprintf(' colspan="%s"', item["_".concat(field, "_colspan")]); + } + + if (item["_".concat(field, "_title")]) { + title_ = Utils.sprintf(' title="%s"', item["_".concat(field, "_title")]); + } + + cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle); + + if (cellStyle.classes) { + class_ = " class=\"".concat(cellStyle.classes, "\""); + } + + if (cellStyle.css) { + var csses_ = []; + + for (var _i6 = 0, _Object$entries5 = Object.entries(cellStyle.css); _i6 < _Object$entries5.length; _i6++) { + var _Object$entries5$_i = _slicedToArray(_Object$entries5[_i6], 2), + _key3 = _Object$entries5$_i[0], + _value2 = _Object$entries5$_i[1]; + + csses_.push("".concat(_key3, ": ").concat(_value2)); + } + + style_ = " style=\"".concat(csses_.concat(_this7.header.styles[j]).join('; '), "\""); + } + + value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_); + + if (item["_".concat(field, "_data")] && !Utils.isEmptyObject(item["_".concat(field, "_data")])) { + for (var _i7 = 0, _Object$entries6 = Object.entries(item["_".concat(field, "_data")]); _i7 < _Object$entries6.length; _i7++) { + var _Object$entries6$_i = _slicedToArray(_Object$entries6[_i7], 2), + _k = _Object$entries6$_i[0], + _v = _Object$entries6$_i[1]; + + // ignore data-index + if (_k === 'index') { + return; + } + + data_ += " data-".concat(_k, "=\"").concat(_v, "\""); + } + } + + if (column.checkbox || column.radio) { + type = column.checkbox ? 'checkbox' : type; + type = column.radio ? 'radio' : type; + var c = column['class'] || ''; + var isChecked = (value === true || value_ || value && value.checked) && value !== false; + var isDisabled = !column.checkboxEnabled || value && value.disabled; + text = [_this7.options.cardView ? "
    ") : ""), ""), _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '
    ' : ''].join(''); + item[_this7.header.stateField] = value === true || !!value_ || value && value.checked; + } else { + value = typeof value === 'undefined' || value === null ? _this7.options.undefinedText : value; + + if (_this7.options.cardView) { + var cardTitle = _this7.options.showHeader ? "").concat(Utils.getFieldTitle(_this7.columns, field), "") : ''; + text = "
    ".concat(cardTitle, "").concat(value, "
    "); + + if (_this7.options.smartDisplay && value === '') { + text = '
    '; + } + } else { + text = "").concat(value, ""); + } + } + + html.push(text); + }); + + if (this.options.cardView) { + html.push('
    '); + } + + html.push(''); + return html.join(''); + } + }, { + key: "initBody", + value: function initBody(fixedScroll) { + var _this8 = this; + + var data = this.getData(); + this.trigger('pre-body', data); + this.$body = this.$el.find('>tbody'); + + if (!this.$body.length) { + this.$body = $('').appendTo(this.$el); + } // Fix #389 Bootstrap-table-flatJSON is not working + + + if (!this.options.pagination || this.options.sidePagination === 'server') { + this.pageFrom = 1; + this.pageTo = data.length; + } + + var rows = []; + var trFragments = $(document.createDocumentFragment()); + var hasTr = false; + + for (var i = this.pageFrom - 1; i < this.pageTo; i++) { + var item = data[i]; + var tr = this.initRow(item, i, data, trFragments); + hasTr = hasTr || !!tr; + + if (tr && typeof tr === 'string') { + if (!this.options.virtualScroll) { + trFragments.append(tr); + } else { + rows.push(tr); + } + } + } // show no records + + + if (!hasTr) { + this.$body.html("".concat(Utils.sprintf('%s', this.$header.find('th').length, this.options.formatNoMatches()), "")); + } else { + if (!this.options.virtualScroll) { + this.$body.html(trFragments); + } else { + if (this.virtualScroll) { + this.virtualScroll.destroy(); + } + + this.virtualScroll = new VirtualScroll({ + rows: rows, + fixedScroll: fixedScroll, + scrollEl: this.$tableBody[0], + contentEl: this.$body[0], + itemHeight: this.options.virtualScrollItemHeight, + callback: function callback() { + _this8.fitHeader(); + + _this8.initBodyEvent(); + } + }); + } + } + + if (!fixedScroll) { + this.scrollTo(0); + } + + this.initBodyEvent(); + this.updateSelected(); + this.initFooter(); + this.resetView(); + + if (this.options.sidePagination !== 'server') { + this.options.totalRows = data.length; + } + + this.trigger('post-body', data); + } + }, { + key: "initBodyEvent", + value: function initBodyEvent() { + var _this9 = this; + + // click to select by column + this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) { + var $td = $(e.currentTarget); + var $tr = $td.parent(); + var $cardViewArr = $(e.target).parents('.card-views').children(); + var $cardViewTarget = $(e.target).parents('.card-view'); + var rowIndex = $tr.data('index'); + var item = _this9.data[rowIndex]; + var index = _this9.options.cardView ? $cardViewArr.index($cardViewTarget) : $td[0].cellIndex; + + var fields = _this9.getVisibleFields(); + + var field = fields[_this9.options.detailView && _this9.options.detailViewIcon && !_this9.options.cardView ? index - 1 : index]; + var column = _this9.columns[_this9.fieldsColumnsIndex[field]]; + var value = Utils.getItemField(item, field, _this9.options.escape); + + if ($td.find('.detail-icon').length) { + return; + } + + _this9.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td); + + _this9.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field); // if click to select - then trigger the checkbox/radio click + + + if (e.type === 'click' && _this9.options.clickToSelect && column.clickToSelect && !Utils.calculateObjectValue(_this9.options, _this9.options.ignoreClickToSelectOn, [e.target])) { + var $selectItem = $tr.find(Utils.sprintf('[name="%s"]', _this9.options.selectItemName)); + + if ($selectItem.length) { + $selectItem[0].click(); + } + } + + if (e.type === 'click' && _this9.options.detailViewByClick) { + _this9.toggleDetailView(rowIndex, _this9.header.detailFormatters[_this9.fieldsColumnsIndex[field]]); + } + }).off('mousedown').on('mousedown', function (e) { + // https://github.com/jquery/jquery/issues/1741 + _this9.multipleSelectRowCtrlKey = e.ctrlKey || e.metaKey; + _this9.multipleSelectRowShiftKey = e.shiftKey; + }); + this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) { + e.preventDefault(); + + _this9.toggleDetailView($(e.currentTarget).parent().parent().data('index')); + + return false; + }); + this.$selectItem = this.$body.find(Utils.sprintf('[name="%s"]', this.options.selectItemName)); + this.$selectItem.off('click').on('click', function (e) { + e.stopImmediatePropagation(); + var $this = $(e.currentTarget); + + _this9._toggleCheck($this.prop('checked'), $this.data('index')); + }); + this.header.events.forEach(function (_events, i) { + var events = _events; + + if (!events) { + return; + } // fix bug, if events is defined with namespace + + + if (typeof events === 'string') { + events = Utils.calculateObjectValue(null, events); + } + + var field = _this9.header.fields[i]; + + var fieldIndex = _this9.getVisibleFields().indexOf(field); + + if (fieldIndex === -1) { + return; + } + + if (_this9.options.detailView && !_this9.options.cardView) { + fieldIndex += 1; + } + + var _loop = function _loop(key) { + if (!events.hasOwnProperty(key)) { + return "continue"; + } + + var event = events[key]; + + _this9.$body.find('>tr:not(.no-records-found)').each(function (i, tr) { + var $tr = $(tr); + var $td = $tr.find(_this9.options.cardView ? '.card-views>.card-view' : '>td').eq(fieldIndex); + var index = key.indexOf(' '); + var name = key.substring(0, index); + var el = key.substring(index + 1); + $td.find(el).off(name).on(name, function (e) { + var index = $tr.data('index'); + var row = _this9.data[index]; + var value = row[field]; + event.apply(_this9, [e, value, row, index]); + }); + }); + }; + + for (var key in events) { + var _ret = _loop(key); + + if (_ret === "continue") continue; + } + }); + } + }, { + key: "initServer", + value: function initServer(silent, query, url) { + var _this10 = this; + + var data = {}; + var index = this.header.fields.indexOf(this.options.sortName); + var params = { + searchText: this.searchText, + sortName: this.options.sortName, + sortOrder: this.options.sortOrder + }; + + if (this.header.sortNames[index]) { + params.sortName = this.header.sortNames[index]; + } + + if (this.options.pagination && this.options.sidePagination === 'server') { + params.pageSize = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize; + params.pageNumber = this.options.pageNumber; + } + + if (!(url || this.options.url) && !this.options.ajax) { + return; + } + + if (this.options.queryParamsType === 'limit') { + params = { + search: params.searchText, + sort: params.sortName, + order: params.sortOrder + }; + + if (this.options.pagination && this.options.sidePagination === 'server') { + params.offset = this.options.pageSize === this.options.formatAllRows() ? 0 : this.options.pageSize * (this.options.pageNumber - 1); + params.limit = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize; + + if (params.limit === 0) { + delete params.limit; + } + } + } + + if (!Utils.isEmptyObject(this.filterColumnsPartial)) { + params.filter = JSON.stringify(this.filterColumnsPartial, null); + } + + $.extend(params, query || {}); + data = Utils.calculateObjectValue(this.options, this.options.queryParams, [params], data); // false to stop request + + if (data === false) { + return; + } + + if (!silent) { + this.showLoading(); + } + + var request = $.extend({}, Utils.calculateObjectValue(null, this.options.ajaxOptions), { + type: this.options.method, + url: url || this.options.url, + data: this.options.contentType === 'application/json' && this.options.method === 'post' ? JSON.stringify(data) : data, + cache: this.options.cache, + contentType: this.options.contentType, + dataType: this.options.dataType, + success: function success(_res, textStatus, jqXHR) { + var res = Utils.calculateObjectValue(_this10.options, _this10.options.responseHandler, [_res, jqXHR], _res); + + _this10.load(res); + + _this10.trigger('load-success', res, jqXHR && jqXHR.status, jqXHR); + + if (!silent) { + _this10.hideLoading(); + } + + if (_this10.options.sidePagination === 'server' && res[_this10.options.totalField] > 0 && !res[_this10.options.dataField].length) { + _this10.updatePagination(); + } + }, + error: function error(jqXHR) { + var data = []; + + if (_this10.options.sidePagination === 'server') { + data = {}; + data[_this10.options.totalField] = 0; + data[_this10.options.dataField] = []; + } + + _this10.load(data); + + _this10.trigger('load-error', jqXHR && jqXHR.status, jqXHR); + + if (!silent) _this10.$tableLoading.hide(); + } + }); + + if (this.options.ajax) { + Utils.calculateObjectValue(this, this.options.ajax, [request], null); + } else { + if (this._xhr && this._xhr.readyState !== 4) { + this._xhr.abort(); + } + + this._xhr = $.ajax(request); + } + + return data; + } + }, { + key: "initSearchText", + value: function initSearchText() { + if (this.options.search) { + this.searchText = ''; + + if (this.options.searchText !== '') { + var $search = this.$toolbar.find('.search input'); + $search.val(this.options.searchText); + this.onSearch({ + currentTarget: $search, + firedByInitSearchText: true + }); + } + } + } + }, { + key: "getCaret", + value: function getCaret() { + var _this11 = this; + + this.$header.find('th').each(function (i, th) { + $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === _this11.options.sortName ? _this11.options.sortOrder : 'both'); + }); + } + }, { + key: "updateSelected", + value: function updateSelected() { + var checkAll = this.$selectItem.filter(':enabled').length && this.$selectItem.filter(':enabled').length === this.$selectItem.filter(':enabled').filter(':checked').length; + this.$selectAll.add(this.$selectAll_).prop('checked', checkAll); + this.$selectItem.each(function (i, el) { + $(el).closest('tr')[$(el).prop('checked') ? 'addClass' : 'removeClass']('selected'); + }); + } + }, { + key: "updateRows", + value: function updateRows() { + var _this12 = this; + + this.$selectItem.each(function (i, el) { + _this12.data[$(el).data('index')][_this12.header.stateField] = $(el).prop('checked'); + }); + } + }, { + key: "resetRows", + value: function resetRows() { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.data[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var row = _step2.value; + this.$selectAll.prop('checked', false); + this.$selectItem.prop('checked', false); + + if (this.header.stateField) { + row[this.header.stateField] = false; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return != null) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + this.initHiddenRows(); + } + }, { + key: "trigger", + value: function trigger(_name) { + var _this$options; + + var name = "".concat(_name, ".bs.table"); + + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key4 = 1; _key4 < _len; _key4++) { + args[_key4 - 1] = arguments[_key4]; + } + + (_this$options = this.options)[BootstrapTable.EVENTS[name]].apply(_this$options, args); + + this.$el.trigger($.Event(name), args); + this.options.onAll(name, args); + this.$el.trigger($.Event('all.bs.table'), [name, args]); + } + }, { + key: "resetHeader", + value: function resetHeader() { + var _this13 = this; + + // fix #61: the hidden table reset header bug. + // fix bug: get $el.css('width') error sometime (height = 500) + clearTimeout(this.timeoutId_); + this.timeoutId_ = setTimeout(function () { + return _this13.fitHeader(); + }, this.$el.is(':hidden') ? 100 : 0); + } + }, { + key: "fitHeader", + value: function fitHeader() { + var _this14 = this; + + if (this.$el.is(':hidden')) { + this.timeoutId_ = setTimeout(function () { + return _this14.fitHeader(); + }, 100); + return; + } + + var fixedBody = this.$tableBody.get(0); + var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0; + this.$el.css('margin-top', -this.$header.outerHeight()); + var focused = $(':focus'); + + if (focused.length > 0) { + var $th = focused.parents('th'); + + if ($th.length > 0) { + var dataField = $th.attr('data-field'); + + if (dataField !== undefined) { + var $headerTh = this.$header.find("[data-field='".concat(dataField, "']")); + + if ($headerTh.length > 0) { + $headerTh.find(':input').addClass('focus-temp'); + } + } + } + } + + this.$header_ = this.$header.clone(true, true); + this.$selectAll_ = this.$header_.find('[name="btSelectAll"]'); + this.$tableHeader.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).html('').attr('class', this.$el.attr('class')).append(this.$header_); + this.$tableLoading.css('width', this.$el.outerWidth()); + var focusedTemp = $('.focus-temp:visible:eq(0)'); + + if (focusedTemp.length > 0) { + focusedTemp.focus(); + this.$header.find('.focus-temp').removeClass('focus-temp'); + } // fix bug: $.data() is not working as expected after $.append() + + + this.$header.find('th[data-field]').each(function (i, el) { + _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', $(el).data('field'))).data($(el).data()); + }); + var visibleFields = this.getVisibleFields(); + var $ths = this.$header_.find('th'); + var $tr = this.$body.find('>tr:not(.no-records-found,.virtual-scroll-top)').eq(0); + + while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) { + $tr = $tr.next(); + } + + $tr.find('> *').each(function (i, el) { + var $this = $(el); + var index = i; + + if (_this14.options.detailView && _this14.options.detailViewIcon && !_this14.options.cardView) { + if (i === 0) { + var $thDetail = $ths.filter('.detail'); + + var _zoomWidth = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width(); + + $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth); + } + + index = i - 1; + } + + if (index === -1) { + return; + } + + var $th = _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', visibleFields[index])); + + if ($th.length > 1) { + $th = $($ths[$this[0].cellIndex]); + } + + var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width(); + $th.find('.fht-cell').width($this.innerWidth() - zoomWidth); + }); + this.horizontalScroll(); + this.trigger('post-header'); + } + }, { + key: "initFooter", + value: function initFooter() { + if (!this.options.showFooter || this.options.cardView) { + // do nothing + return; + } + + var data = this.getData(); + var html = []; + + if (!this.options.cardView && this.options.detailView && this.options.detailViewIcon) { + html.push('
    '); + } + + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.columns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var column = _step3.value; + var falign = ''; + var valign = ''; + var csses = []; + var style = {}; + var class_ = Utils.sprintf(' class="%s"', column['class']); + + if (!column.visible) { + continue; + } + + if (this.options.cardView && !column.cardVisible) { + return; + } + + falign = Utils.sprintf('text-align: %s; ', column.falign ? column.falign : column.align); + valign = Utils.sprintf('vertical-align: %s; ', column.valign); + style = Utils.calculateObjectValue(null, this.options.footerStyle, [column]); + + if (style && style.css) { + for (var _i8 = 0, _Object$entries7 = Object.entries(style.css); _i8 < _Object$entries7.length; _i8++) { + var _Object$entries7$_i = _slicedToArray(_Object$entries7[_i8], 2), + key = _Object$entries7$_i[0], + value = _Object$entries7$_i[1]; + + csses.push("".concat(key, ": ").concat(value)); + } + } + + if (style && style.classes) { + class_ = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], style.classes].join(' ') : style.classes); + } + + html.push(''); + html.push('
    '); + html.push(Utils.calculateObjectValue(column, column.footerFormatter, [data], this.footerData[0] && this.footerData[0][column.field] || '')); + html.push('
    '); + html.push('
    '); + html.push('
    '); + html.push(''); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return != null) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + if (!this.options.height && !this.$tableFooter.length) { + this.$el.append(''); + this.$tableFooter = this.$el.find('tfoot'); + } + + this.$tableFooter.find('tr').html(html.join('')); + this.trigger('post-footer', this.$tableFooter); + } + }, { + key: "fitFooter", + value: function fitFooter() { + var _this15 = this; + + if (this.$el.is(':hidden')) { + setTimeout(function () { + return _this15.fitFooter(); + }, 100); + return; + } + + var fixedBody = this.$tableBody.get(0); + var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0; + this.$tableFooter.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).attr('class', this.$el.attr('class')); + var visibleFields = this.getVisibleFields(); + var $ths = this.$tableFooter.find('th'); + var $tr = this.$body.find('>tr:first-child:not(.no-records-found)'); + + while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) { + $tr = $tr.next(); + } + + $tr.find('> *').each(function (i, el) { + var $this = $(el); + var index = i; + + if (_this15.options.detailView && !_this15.options.cardView) { + if (i === 0) { + var $thDetail = $ths.filter('.detail'); + + var _zoomWidth2 = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width(); + + $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth2); + } + + index = i - 1; + } + + if (index === -1) { + return; + } + + var $th = $ths.eq(i); + var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width(); + $th.find('.fht-cell').width($this.innerWidth() - zoomWidth); + }); + this.horizontalScroll(); + } + }, { + key: "horizontalScroll", + value: function horizontalScroll() { + var _this16 = this; + + // horizontal scroll event + // TODO: it's probably better improving the layout than binding to scroll event + this.$tableBody.off('scroll').on('scroll', function () { + var scrollLeft = _this16.$tableBody.scrollLeft(); + + if (_this16.options.showHeader && _this16.options.height) { + _this16.$tableHeader.scrollLeft(scrollLeft); + } + + if (_this16.options.showFooter && !_this16.options.cardView) { + _this16.$tableFooter.scrollLeft(scrollLeft); + } + + _this16.trigger('scroll-body', _this16.$tableBody); + }); + } + }, { + key: "getVisibleFields", + value: function getVisibleFields() { + var visibleFields = []; + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = this.header.fields[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var field = _step4.value; + var column = this.columns[this.fieldsColumnsIndex[field]]; + + if (!column || !column.visible) { + continue; + } + + visibleFields.push(field); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return != null) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + return visibleFields; + } + }, { + key: "initHiddenRows", + value: function initHiddenRows() { + this.hiddenRows = []; + } // PUBLIC FUNCTION DEFINITION + // ======================= + + }, { + key: "getOptions", + value: function getOptions() { + // deep copy and remove data + var options = $.extend({}, this.options); + delete options.data; + return $.extend(true, {}, options); + } + }, { + key: "refreshOptions", + value: function refreshOptions(options) { + // If the objects are equivalent then avoid the call of destroy / init methods + if (Utils.compareObjects(this.options, options, true)) { + return; + } + + this.options = $.extend(this.options, options); + this.trigger('refresh-options', this.options); + this.destroy(); + this.init(); + } + }, { + key: "getData", + value: function getData(params) { + var data = this.options.data; + + if ((this.searchText || this.options.customSearch || this.options.sortName || !Utils.isEmptyObject(this.filterColumns) || !Utils.isEmptyObject(this.filterColumnsPartial)) && (!params || !params.unfiltered)) { + data = this.data; + } + + if (params && params.useCurrentPage) { + data = data.slice(this.pageFrom - 1, this.pageTo); + } + + if (params && !params.includeHiddenRows) { + var hiddenRows = this.getHiddenRows(); + data = data.filter(function (row) { + return Utils.findIndex(hiddenRows, row) === -1; + }); + } + + return data; + } + }, { + key: "getSelections", + value: function getSelections() { + var _this17 = this; + + // fix #2424: from html with checkbox + return this.data.filter(function (row) { + return row[_this17.header.stateField] === true; + }); + } + }, { + key: "getAllSelections", + value: function getAllSelections() { + var _this18 = this; + + return this.options.data.filter(function (row) { + return row[_this18.header.stateField] === true; + }); + } + }, { + key: "load", + value: function load(_data) { + var fixedScroll = false; + var data = _data; // #431: support pagination + + if (this.options.pagination && this.options.sidePagination === 'server') { + this.options.totalRows = data[this.options.totalField]; + } + + if (this.options.pagination && this.options.sidePagination === 'server') { + this.options.totalNotFiltered = data[this.options.totalNotFilteredField]; + } + + fixedScroll = data.fixedScroll; + data = Array.isArray(data) ? data : data[this.options.dataField]; + this.initData(data); + this.initSearch(); + this.initPagination(); + this.initBody(fixedScroll); + } + }, { + key: "append", + value: function append(data) { + this.initData(data, 'append'); + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "prepend", + value: function prepend(data) { + this.initData(data, 'prepend'); + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "remove", + value: function remove(params) { + var len = this.options.data.length; + var i; + var row; + + if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) { + return; + } + + for (i = len - 1; i >= 0; i--) { + row = this.options.data[i]; + + if (!row.hasOwnProperty(params.field)) { + continue; + } + + if (params.values.includes(row[params.field])) { + this.options.data.splice(i, 1); + + if (this.options.sidePagination === 'server') { + this.options.totalRows -= 1; + } + } + } + + if (len === this.options.data.length) { + return; + } + + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "removeAll", + value: function removeAll() { + if (this.options.data.length > 0) { + this.options.data.splice(0, this.options.data.length); + this.initSearch(); + this.initPagination(); + this.initBody(true); + } + } + }, { + key: "insertRow", + value: function insertRow(params) { + if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) { + return; + } + + this.options.data.splice(params.index, 0, params.row); + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "updateRow", + value: function updateRow(params) { + var allParams = Array.isArray(params) ? params : [params]; + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = allParams[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _params = _step5.value; + + if (!_params.hasOwnProperty('index') || !_params.hasOwnProperty('row')) { + continue; + } + + $.extend(this.options.data[_params.index], _params.row); + + if (_params.hasOwnProperty('replace') && _params.replace) { + this.options.data[_params.index] = _params.row; + } else { + $.extend(this.options.data[_params.index], _params.row); + } + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return != null) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "getRowByUniqueId", + value: function getRowByUniqueId(_id) { + var uniqueId = this.options.uniqueId; + var len = this.options.data.length; + var id = _id; + var dataRow = null; + var i; + var row; + var rowUniqueId; + + for (i = len - 1; i >= 0; i--) { + row = this.options.data[i]; + + if (row.hasOwnProperty(uniqueId)) { + // uniqueId is a column + rowUniqueId = row[uniqueId]; + } else if (row._data && row._data.hasOwnProperty(uniqueId)) { + // uniqueId is a row data property + rowUniqueId = row._data[uniqueId]; + } else { + continue; + } + + if (typeof rowUniqueId === 'string') { + id = id.toString(); + } else if (typeof rowUniqueId === 'number') { + if (Number(rowUniqueId) === rowUniqueId && rowUniqueId % 1 === 0) { + id = parseInt(id); + } else if (rowUniqueId === Number(rowUniqueId) && rowUniqueId !== 0) { + id = parseFloat(id); + } + } + + if (rowUniqueId === id) { + dataRow = row; + break; + } + } + + return dataRow; + } + }, { + key: "updateByUniqueId", + value: function updateByUniqueId(params) { + var allParams = Array.isArray(params) ? params : [params]; + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = allParams[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var _params2 = _step6.value; + + if (!_params2.hasOwnProperty('id') || !_params2.hasOwnProperty('row')) { + continue; + } + + var rowId = this.options.data.indexOf(this.getRowByUniqueId(_params2.id)); + + if (rowId === -1) { + continue; + } + + if (_params2.hasOwnProperty('replace') && _params2.replace) { + this.options.data[rowId] = _params2.row; + } else { + $.extend(this.options.data[rowId], _params2.row); + } + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6.return != null) { + _iterator6.return(); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + this.initSearch(); + this.initPagination(); + this.initSort(); + this.initBody(true); + } + }, { + key: "removeByUniqueId", + value: function removeByUniqueId(id) { + var len = this.options.data.length; + var row = this.getRowByUniqueId(id); + + if (row) { + this.options.data.splice(this.options.data.indexOf(row), 1); + } + + if (len === this.options.data.length) { + return; + } + + this.initSearch(); + this.initPagination(); + this.initBody(true); + } + }, { + key: "updateCell", + value: function updateCell(params) { + if (!params.hasOwnProperty('index') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) { + return; + } + + this.data[params.index][params.field] = params.value; + + if (params.reinit === false) { + return; + } + + this.initSort(); + this.initBody(true); + } + }, { + key: "updateCellByUniqueId", + value: function updateCellByUniqueId(params) { + var _this19 = this; + + if (!params.hasOwnProperty('id') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) { + return; + } + + var allParams = Array.isArray(params) ? params : [params]; + allParams.forEach(function (_ref6) { + var id = _ref6.id, + field = _ref6.field, + value = _ref6.value; + + var rowId = _this19.options.data.indexOf(_this19.getRowByUniqueId(id)); + + if (rowId === -1) { + return; + } + + _this19.options.data[rowId][field] = value; + }); + + if (params.reinit === false) { + return; + } + + this.initSort(); + this.initBody(true); + } + }, { + key: "showRow", + value: function showRow(params) { + this._toggleRow(params, true); + } + }, { + key: "hideRow", + value: function hideRow(params) { + this._toggleRow(params, false); + } + }, { + key: "_toggleRow", + value: function _toggleRow(params, visible) { + var row; + + if (params.hasOwnProperty('index')) { + row = this.getData()[params.index]; + } else if (params.hasOwnProperty('uniqueId')) { + row = this.getRowByUniqueId(params.uniqueId); + } + + if (!row) { + return; + } + + var index = Utils.findIndex(this.hiddenRows, row); + + if (!visible && index === -1) { + this.hiddenRows.push(row); + } else if (visible && index > -1) { + this.hiddenRows.splice(index, 1); + } + + if (visible) { + this.updatePagination(); + } else { + this.initBody(true); + this.initPagination(); + } + } + }, { + key: "getHiddenRows", + value: function getHiddenRows(show) { + if (show) { + this.initHiddenRows(); + this.initBody(true); + return; + } + + var data = this.getData(); + var rows = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = data[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var row = _step7.value; + + if (this.hiddenRows.includes(row)) { + rows.push(row); + } + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7.return != null) { + _iterator7.return(); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + this.hiddenRows = rows; + return rows; + } + }, { + key: "showColumn", + value: function showColumn(field) { + var _this20 = this; + + var fields = Array.isArray(field) ? field : [field]; + fields.forEach(function (field) { + _this20._toggleColumn(_this20.fieldsColumnsIndex[field], true, true); + }); + } + }, { + key: "hideColumn", + value: function hideColumn(field) { + var _this21 = this; + + var fields = Array.isArray(field) ? field : [field]; + fields.forEach(function (field) { + _this21._toggleColumn(_this21.fieldsColumnsIndex[field], false, true); + }); + } + }, { + key: "_toggleColumn", + value: function _toggleColumn(index, checked, needUpdate) { + if (index === -1 || this.columns[index].visible === checked) { + return; + } + + this.columns[index].visible = checked; + this.initHeader(); + this.initSearch(); + this.initPagination(); + this.initBody(); + + if (this.options.showColumns) { + var $items = this.$toolbar.find('.keep-open input:not(".toggle-all")').prop('disabled', false); + + if (needUpdate) { + $items.filter(Utils.sprintf('[value="%s"]', index)).prop('checked', checked); + } + + if ($items.filter(':checked').length <= this.options.minimumCountColumns) { + $items.filter(':checked').prop('disabled', true); + } + } + } + }, { + key: "getVisibleColumns", + value: function getVisibleColumns() { + var _this22 = this; + + return this.columns.filter(function (column) { + return column.visible && !_this22.isSelectionColumn(column); + }); + } + }, { + key: "getHiddenColumns", + value: function getHiddenColumns() { + return this.columns.filter(function (_ref7) { + var visible = _ref7.visible; + return !visible; + }); + } + }, { + key: "isSelectionColumn", + value: function isSelectionColumn(column) { + return column.radio || column.checkbox; + } + }, { + key: "showAllColumns", + value: function showAllColumns() { + this._toggleAllColumns(true); + } + }, { + key: "hideAllColumns", + value: function hideAllColumns() { + this._toggleAllColumns(false); + } + }, { + key: "_toggleAllColumns", + value: function _toggleAllColumns(visible) { + var _this23 = this; + + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = this.columns.slice().reverse()[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var column = _step8.value; + + if (column.switchable) { + if (!visible && this.options.showColumns && this.getVisibleColumns().length === this.options.minimumCountColumns) { + continue; + } + + column.visible = visible; + } + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8.return != null) { + _iterator8.return(); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + + this.initHeader(); + this.initSearch(); + this.initPagination(); + this.initBody(); + + if (this.options.showColumns) { + var $items = this.$toolbar.find('.keep-open input[type="checkbox"]:not(".toggle-all")').prop('disabled', false); + + if (visible) { + $items.prop('checked', visible); + } else { + $items.get().reverse().forEach(function (item) { + if ($items.filter(':checked').length > _this23.options.minimumCountColumns) { + $(item).prop('checked', visible); + } + }); + } + + if ($items.filter(':checked').length <= this.options.minimumCountColumns) { + $items.filter(':checked').prop('disabled', true); + } + } + } + }, { + key: "mergeCells", + value: function mergeCells(options) { + var row = options.index; + var col = this.getVisibleFields().indexOf(options.field); + var rowspan = options.rowspan || 1; + var colspan = options.colspan || 1; + var i; + var j; + var $tr = this.$body.find('>tr'); + + if (this.options.detailView && !this.options.cardView) { + col += 1; + } + + var $td = $tr.eq(row).find('>td').eq(col); + + if (row < 0 || col < 0 || row >= this.data.length) { + return; + } + + for (i = row; i < row + rowspan; i++) { + for (j = col; j < col + colspan; j++) { + $tr.eq(i).find('>td').eq(j).hide(); + } + } + + $td.attr('rowspan', rowspan).attr('colspan', colspan).show(); + } + }, { + key: "checkAll", + value: function checkAll() { + this._toggleCheckAll(true); + } + }, { + key: "uncheckAll", + value: function uncheckAll() { + this._toggleCheckAll(false); + } + }, { + key: "_toggleCheckAll", + value: function _toggleCheckAll(checked) { + var rowsBefore = this.getSelections(); + this.$selectAll.add(this.$selectAll_).prop('checked', checked); + this.$selectItem.filter(':enabled').prop('checked', checked); + this.updateRows(); + var rowsAfter = this.getSelections(); + + if (checked) { + this.trigger('check-all', rowsAfter, rowsBefore); + return; + } + + this.trigger('uncheck-all', rowsAfter, rowsBefore); + } + }, { + key: "checkInvert", + value: function checkInvert() { + var $items = this.$selectItem.filter(':enabled'); + var checked = $items.filter(':checked'); + $items.each(function (i, el) { + $(el).prop('checked', !$(el).prop('checked')); + }); + this.updateRows(); + this.updateSelected(); + this.trigger('uncheck-some', checked); + checked = this.getSelections(); + this.trigger('check-some', checked); + } + }, { + key: "check", + value: function check(index) { + this._toggleCheck(true, index); + } + }, { + key: "uncheck", + value: function uncheck(index) { + this._toggleCheck(false, index); + } + }, { + key: "_toggleCheck", + value: function _toggleCheck(checked, index) { + var $el = this.$selectItem.filter("[data-index=\"".concat(index, "\"]")); + var row = this.data[index]; + + if ($el.is(':radio') || this.options.singleSelect || this.options.multipleSelectRow && !this.multipleSelectRowCtrlKey && !this.multipleSelectRowShiftKey) { + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = this.options.data[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var r = _step9.value; + r[this.header.stateField] = false; + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9.return != null) { + _iterator9.return(); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + this.$selectItem.filter(':checked').not($el).prop('checked', false); + } + + row[this.header.stateField] = checked; + + if (this.options.multipleSelectRow) { + if (this.multipleSelectRowShiftKey && this.multipleSelectRowLastSelectedIndex >= 0) { + var indexes = [this.multipleSelectRowLastSelectedIndex, index].sort(); + + for (var i = indexes[0] + 1; i < indexes[1]; i++) { + this.data[i][this.header.stateField] = true; + this.$selectItem.filter("[data-index=\"".concat(i, "\"]")).prop('checked', true); + } + } + + this.multipleSelectRowCtrlKey = false; + this.multipleSelectRowShiftKey = false; + this.multipleSelectRowLastSelectedIndex = checked ? index : -1; + } + + $el.prop('checked', checked); + this.updateSelected(); + this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el); + } + }, { + key: "checkBy", + value: function checkBy(obj) { + this._toggleCheckBy(true, obj); + } + }, { + key: "uncheckBy", + value: function uncheckBy(obj) { + this._toggleCheckBy(false, obj); + } + }, { + key: "_toggleCheckBy", + value: function _toggleCheckBy(checked, obj) { + var _this24 = this; + + if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) { + return; + } + + var rows = []; + this.data.forEach(function (row, i) { + if (!row.hasOwnProperty(obj.field)) { + return false; + } + + if (obj.values.includes(row[obj.field])) { + var $el = _this24.$selectItem.filter(':enabled').filter(Utils.sprintf('[data-index="%s"]', i)); + + $el = checked ? $el.not(':checked') : $el.filter(':checked'); + + if (!$el.length) { + return; + } + + $el.prop('checked', checked); + row[_this24.header.stateField] = checked; + rows.push(row); + + _this24.trigger(checked ? 'check' : 'uncheck', row, $el); + } + }); + this.updateSelected(); + this.trigger(checked ? 'check-some' : 'uncheck-some', rows); + } + }, { + key: "refresh", + value: function refresh(params) { + if (params && params.url) { + this.options.url = params.url; + } + + if (params && params.pageNumber) { + this.options.pageNumber = params.pageNumber; + } + + if (params && params.pageSize) { + this.options.pageSize = params.pageSize; + } + + this.trigger('refresh', this.initServer(params && params.silent, params && params.query, params && params.url)); + } + }, { + key: "destroy", + value: function destroy() { + this.$el.insertBefore(this.$container); + $(this.options.toolbar).insertBefore(this.$el); + this.$container.next().remove(); + this.$container.remove(); + this.$el.html(this.$el_.html()).css('margin-top', '0').attr('class', this.$el_.attr('class') || ''); // reset the class + } + }, { + key: "resetView", + value: function resetView(params) { + var padding = 0; + + if (params && params.height) { + this.options.height = params.height; + } + + this.$selectAll.prop('checked', this.$selectItem.length > 0 && this.$selectItem.length === this.$selectItem.filter(':checked').length); + this.$tableContainer.toggleClass('has-card-view', this.options.cardView); + + if (!this.options.cardView && this.options.showHeader && this.options.height) { + this.$tableHeader.show(); + this.resetHeader(); + padding += this.$header.outerHeight(true) + 1; + } else { + this.$tableHeader.hide(); + this.trigger('post-header'); + } + + if (!this.options.cardView && this.options.showFooter) { + this.$tableFooter.show(); + this.fitFooter(); + + if (this.options.height) { + padding += this.$tableFooter.outerHeight(true); + } + } + + if (this.$container.hasClass('fullscreen')) { + this.$tableContainer.css('height', ''); + this.$tableContainer.css('width', ''); + } else if (this.options.height) { + var toolbarHeight = this.$toolbar.outerHeight(true); + var paginationHeight = this.$pagination.outerHeight(true); + var height = this.options.height - toolbarHeight - paginationHeight; + var $bodyTable = this.$tableBody.find('>table'); + var tableHeight = $bodyTable.outerHeight(); + this.$tableContainer.css('height', "".concat(height, "px")); + + if (this.$tableBorder) { + var tableBorderHeight = height - tableHeight - 2; + + if (this.$tableBody[0].scrollWidth - this.$tableBody.innerWidth()) { + tableBorderHeight -= Utils.getScrollBarWidth(); + } + + this.$tableBorder.css('width', "".concat($bodyTable.outerWidth(), "px")); + this.$tableBorder.css('height', "".concat(tableBorderHeight, "px")); + } + } + + if (this.options.cardView) { + // remove the element css + this.$el.css('margin-top', '0'); + this.$tableContainer.css('padding-bottom', '0'); + this.$tableFooter.hide(); + } else { + // Assign the correct sortable arrow + this.getCaret(); + this.$tableContainer.css('padding-bottom', "".concat(padding, "px")); + } + + this.trigger('reset-view'); + } + }, { + key: "showLoading", + value: function showLoading() { + this.$tableLoading.css('display', 'flex'); + } + }, { + key: "hideLoading", + value: function hideLoading() { + this.$tableLoading.css('display', 'none'); + } + }, { + key: "togglePagination", + value: function togglePagination() { + this.options.pagination = !this.options.pagination; + var icon = this.options.showButtonIcons ? this.options.pagination ? this.options.icons.paginationSwitchDown : this.options.icons.paginationSwitchUp : ''; + var text = this.options.showButtonText ? this.options.pagination ? this.options.formatPaginationSwitchUp() : this.options.formatPaginationSwitchDown() : ''; + this.$toolbar.find('button[name="paginationSwitch"]').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon) + ' ' + text); + this.updatePagination(); + } + }, { + key: "toggleFullscreen", + value: function toggleFullscreen() { + this.$el.closest('.bootstrap-table').toggleClass('fullscreen'); + this.resetView(); + } + }, { + key: "toggleView", + value: function toggleView() { + this.options.cardView = !this.options.cardView; + this.initHeader(); + var icon = this.options.showButtonIcons ? this.options.cardView ? this.options.icons.toggleOn : this.options.icons.toggleOff : ''; + var text = this.options.showButtonText ? this.options.cardView ? this.options.formatToggleOff() : this.options.formatToggleOn() : ''; + this.$toolbar.find('button[name="toggle"]').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon) + ' ' + text); + this.initBody(); + this.trigger('toggle', this.options.cardView); + } + }, { + key: "resetSearch", + value: function resetSearch(text) { + var $search = this.$toolbar.find('.search input'); + $search.val(text || ''); + this.onSearch({ + currentTarget: $search + }); + } + }, { + key: "filterBy", + value: function filterBy(columns, options) { + this.filterOptions = Utils.isEmptyObject(options) ? this.options.filterOptions : $.extend(this.options.filterOptions, options); + this.filterColumns = Utils.isEmptyObject(columns) ? {} : columns; + this.options.pageNumber = 1; + this.initSearch(); + this.updatePagination(); + } + }, { + key: "scrollTo", + value: function scrollTo(params) { + if (typeof params === 'undefined') { + return this.$tableBody.scrollTop(); + } + + var options = { + unit: 'px', + value: 0 + }; + + if (_typeof(params) === 'object') { + options = Object.assign(options, params); + } else if (typeof params === 'string' && params === 'bottom') { + options.value = this.$tableBody[0].scrollHeight; + } else if (typeof params === 'string') { + options.value = params; + } + + var scrollTo = options.value; + + if (options.unit === 'rows') { + scrollTo = 0; + this.$body.find("> tr:lt(".concat(options.value, ")")).each(function (i, el) { + scrollTo += $(el).outerHeight(true); + }); + } + + this.$tableBody.scrollTop(scrollTo); + } + }, { + key: "getScrollPosition", + value: function getScrollPosition() { + return this.scrollTo(); + } + }, { + key: "selectPage", + value: function selectPage(page) { + if (page > 0 && page <= this.options.totalPages) { + this.options.pageNumber = page; + this.updatePagination(); + } + } + }, { + key: "prevPage", + value: function prevPage() { + if (this.options.pageNumber > 1) { + this.options.pageNumber--; + this.updatePagination(); + } + } + }, { + key: "nextPage", + value: function nextPage() { + if (this.options.pageNumber < this.options.totalPages) { + this.options.pageNumber++; + this.updatePagination(); + } + } + }, { + key: "toggleDetailView", + value: function toggleDetailView(index, _columnDetailFormatter) { + var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', index)); + + if ($tr.next().is('tr.detail-view')) { + this.collapseRow(index); + } else { + this.expandRow(index, _columnDetailFormatter); + } + + this.resetView(); + } + }, { + key: "expandRow", + value: function expandRow(index, _columnDetailFormatter) { + var row = this.data[index]; + var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index)); + + if ($tr.next().is('tr.detail-view')) { + return; + } + + if (this.options.detailViewIcon) { + $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailClose)); + } + + $tr.after(Utils.sprintf('', $tr.children('td').length)); + var $element = $tr.next().find('td'); + var detailFormatter = _columnDetailFormatter || this.options.detailFormatter; + var content = Utils.calculateObjectValue(this.options, detailFormatter, [index, row, $element], ''); + + if ($element.length === 1) { + $element.append(content); + } + + this.trigger('expand-row', index, row, $element); + } + }, { + key: "collapseRow", + value: function collapseRow(index) { + var row = this.data[index]; + var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index)); + + if (!$tr.next().is('tr.detail-view')) { + return; + } + + if (this.options.detailViewIcon) { + $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen)); + } + + this.trigger('collapse-row', index, row, $tr.next()); + $tr.next().remove(); + } + }, { + key: "expandAllRows", + value: function expandAllRows() { + var trs = this.$body.find('> tr[data-index][data-has-detail-view]'); + + for (var i = 0; i < trs.length; i++) { + this.expandRow($(trs[i]).data('index')); + } + } + }, { + key: "collapseAllRows", + value: function collapseAllRows() { + var trs = this.$body.find('> tr[data-index][data-has-detail-view]'); + + for (var i = 0; i < trs.length; i++) { + this.collapseRow($(trs[i]).data('index')); + } + } + }, { + key: "updateColumnTitle", + value: function updateColumnTitle(params) { + if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) { + return; + } + + this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape ? Utils.escapeHTML(params.title) : params.title; + + if (this.columns[this.fieldsColumnsIndex[params.field]].visible) { + var header = this.options.height !== undefined ? this.$tableHeader : this.$header; + header.find('th[data-field]').each(function (i, el) { + if ($(el).data('field') === params.field) { + $($(el).find('.th-inner')[0]).text(params.title); + return false; + } + }); + } + } + }, { + key: "updateFormatText", + value: function updateFormatText(formatName, text) { + if (!/^format/.test(formatName) || !this.options[formatName]) { + return; + } + + if (typeof text === 'string') { + this.options[formatName] = function () { + return text; + }; + } else if (typeof text === 'function') { + this.options[formatName] = text; + } + + this.initToolbar(); + this.initPagination(); + this.initBody(); + } + }]); + + return BootstrapTable; + }(); BootstrapTable.VERSION = Constants.VERSION; BootstrapTable.DEFAULTS = Constants.DEFAULTS; @@ -7158,38 +7515,38 @@ $.BootstrapTable = BootstrapTable; $.fn.bootstrapTable = function (option) { - for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key5 = 1; _key5 < _len2; _key5++) { - args[_key5 - 1] = arguments[_key5]; - } - - var value; - this.each(function (i, el) { - var data = $(el).data('bootstrap.table'); - var options = $.extend({}, BootstrapTable.DEFAULTS, $(el).data(), _typeof(option) === 'object' && option); - - if (typeof option === 'string') { - var _data2; - - if (!Constants.METHODS.includes(option)) { - throw new Error("Unknown method: ".concat(option)); - } - - if (!data) { - return; - } - - value = (_data2 = data)[option].apply(_data2, args); - - if (option === 'destroy') { - $(el).removeData('bootstrap.table'); - } - } - - if (!data) { - $(el).data('bootstrap.table', data = new $.BootstrapTable(el, options)); - } - }); - return typeof value === 'undefined' ? this : value; + for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key5 = 1; _key5 < _len2; _key5++) { + args[_key5 - 1] = arguments[_key5]; + } + + var value; + this.each(function (i, el) { + var data = $(el).data('bootstrap.table'); + var options = $.extend({}, BootstrapTable.DEFAULTS, $(el).data(), _typeof(option) === 'object' && option); + + if (typeof option === 'string') { + var _data2; + + if (!Constants.METHODS.includes(option)) { + throw new Error("Unknown method: ".concat(option)); + } + + if (!data) { + return; + } + + value = (_data2 = data)[option].apply(_data2, args); + + if (option === 'destroy') { + $(el).removeData('bootstrap.table'); + } + } + + if (!data) { + $(el).data('bootstrap.table', data = new $.BootstrapTable(el, options)); + } + }); + return typeof value === 'undefined' ? this : value; }; $.fn.bootstrapTable.Constructor = BootstrapTable; @@ -7204,7 +7561,7 @@ // ======================= $(function () { - $('[data-toggle="table"]').bootstrapTable(); + $('[data-toggle="table"]').bootstrapTable(); }); return BootstrapTable; diff --git a/WebContent/js/bootstrap.js b/WebContent/js/bootstrap.js index 8a2e99a..a654277 100644 --- a/WebContent/js/bootstrap.js +++ b/WebContent/js/bootstrap.js @@ -5,15 +5,15 @@ */ if (typeof jQuery === 'undefined') { - throw new Error('Bootstrap\'s JavaScript requires jQuery') + throw new Error('Bootstrap\'s JavaScript requires jQuery') } +function ($) { - 'use strict'; - var version = $.fn.jquery.split(' ')[0].split('.') - if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 3)) { - throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4') - } + 'use strict'; + var version = $.fn.jquery.split(' ')[0].split('.') + if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 3)) { + throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4') + } }(jQuery); /* ======================================================================== @@ -26,53 +26,53 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) - // ============================================================ + // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) + // ============================================================ - function transitionEnd() { - var el = document.createElement('bootstrap') + function transitionEnd() { + var el = document.createElement('bootstrap') - var transEndEventNames = { - WebkitTransition : 'webkitTransitionEnd', - MozTransition : 'transitionend', - OTransition : 'oTransitionEnd otransitionend', - transition : 'transitionend' - } + var transEndEventNames = { + WebkitTransition : 'webkitTransitionEnd', + MozTransition : 'transitionend', + OTransition : 'oTransitionEnd otransitionend', + transition : 'transitionend' + } - for (var name in transEndEventNames) { - if (el.style[name] !== undefined) { - return { end: transEndEventNames[name] } - } - } + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + return { end: transEndEventNames[name] } + } + } - return false // explicit for ie8 ( ._.) - } + return false // explicit for ie8 ( ._.) + } - // http://blog.alexmaccaw.com/css-transitions - $.fn.emulateTransitionEnd = function (duration) { - var called = false - var $el = this - $(this).one('bsTransitionEnd', function () { called = true }) - var callback = function () { if (!called) $($el).trigger($.support.transition.end) } - setTimeout(callback, duration) - return this - } + // http://blog.alexmaccaw.com/css-transitions + $.fn.emulateTransitionEnd = function (duration) { + var called = false + var $el = this + $(this).one('bsTransitionEnd', function () { called = true }) + var callback = function () { if (!called) $($el).trigger($.support.transition.end) } + setTimeout(callback, duration) + return this + } - $(function () { - $.support.transition = transitionEnd() + $(function () { + $.support.transition = transitionEnd() - if (!$.support.transition) return + if (!$.support.transition) return - $.event.special.bsTransitionEnd = { - bindType: $.support.transition.end, - delegateType: $.support.transition.end, - handle: function (e) { - if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments) - } - } - }) + $.event.special.bsTransitionEnd = { + bindType: $.support.transition.end, + delegateType: $.support.transition.end, + handle: function (e) { + if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments) + } + } + }) }(jQuery); @@ -86,88 +86,88 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // ALERT CLASS DEFINITION - // ====================== + // ALERT CLASS DEFINITION + // ====================== - var dismiss = '[data-dismiss="alert"]' - var Alert = function (el) { - $(el).on('click', dismiss, this.close) - } + var dismiss = '[data-dismiss="alert"]' + var Alert = function (el) { + $(el).on('click', dismiss, this.close) + } - Alert.VERSION = '3.3.7' + Alert.VERSION = '3.3.7' - Alert.TRANSITION_DURATION = 150 + Alert.TRANSITION_DURATION = 150 - Alert.prototype.close = function (e) { - var $this = $(this) - var selector = $this.attr('data-target') + Alert.prototype.close = function (e) { + var $this = $(this) + var selector = $this.attr('data-target') - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } - var $parent = $(selector === '#' ? [] : selector) + var $parent = $(selector === '#' ? [] : selector) - if (e) e.preventDefault() + if (e) e.preventDefault() - if (!$parent.length) { - $parent = $this.closest('.alert') - } + if (!$parent.length) { + $parent = $this.closest('.alert') + } - $parent.trigger(e = $.Event('close.bs.alert')) + $parent.trigger(e = $.Event('close.bs.alert')) - if (e.isDefaultPrevented()) return + if (e.isDefaultPrevented()) return - $parent.removeClass('in') + $parent.removeClass('in') - function removeElement() { - // detach from parent, fire event then clean up data - $parent.detach().trigger('closed.bs.alert').remove() - } + function removeElement() { + // detach from parent, fire event then clean up data + $parent.detach().trigger('closed.bs.alert').remove() + } - $.support.transition && $parent.hasClass('fade') ? - $parent - .one('bsTransitionEnd', removeElement) - .emulateTransitionEnd(Alert.TRANSITION_DURATION) : - removeElement() - } + $.support.transition && $parent.hasClass('fade') ? + $parent + .one('bsTransitionEnd', removeElement) + .emulateTransitionEnd(Alert.TRANSITION_DURATION) : + removeElement() + } - // ALERT PLUGIN DEFINITION - // ======================= + // ALERT PLUGIN DEFINITION + // ======================= - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.alert') + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.alert') - if (!data) $this.data('bs.alert', (data = new Alert(this))) - if (typeof option == 'string') data[option].call($this) - }) - } + if (!data) $this.data('bs.alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } - var old = $.fn.alert + var old = $.fn.alert - $.fn.alert = Plugin - $.fn.alert.Constructor = Alert + $.fn.alert = Plugin + $.fn.alert.Constructor = Alert - // ALERT NO CONFLICT - // ================= + // ALERT NO CONFLICT + // ================= - $.fn.alert.noConflict = function () { - $.fn.alert = old - return this - } + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } - // ALERT DATA-API - // ============== + // ALERT DATA-API + // ============== - $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) }(jQuery); @@ -181,119 +181,119 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // BUTTON PUBLIC CLASS DEFINITION - // ============================== + // BUTTON PUBLIC CLASS DEFINITION + // ============================== - var Button = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Button.DEFAULTS, options) - this.isLoading = false - } + var Button = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + this.isLoading = false + } - Button.VERSION = '3.3.7' + Button.VERSION = '3.3.7' - Button.DEFAULTS = { - loadingText: 'loading...' - } + Button.DEFAULTS = { + loadingText: 'loading...' + } - Button.prototype.setState = function (state) { - var d = 'disabled' - var $el = this.$element - var val = $el.is('input') ? 'val' : 'html' - var data = $el.data() + Button.prototype.setState = function (state) { + var d = 'disabled' + var $el = this.$element + var val = $el.is('input') ? 'val' : 'html' + var data = $el.data() - state += 'Text' + state += 'Text' - if (data.resetText == null) $el.data('resetText', $el[val]()) + if (data.resetText == null) $el.data('resetText', $el[val]()) - // push to event loop to allow forms to submit - setTimeout($.proxy(function () { - $el[val](data[state] == null ? this.options[state] : data[state]) + // push to event loop to allow forms to submit + setTimeout($.proxy(function () { + $el[val](data[state] == null ? this.options[state] : data[state]) - if (state == 'loadingText') { - this.isLoading = true - $el.addClass(d).attr(d, d).prop(d, true) - } else if (this.isLoading) { - this.isLoading = false - $el.removeClass(d).removeAttr(d).prop(d, false) - } - }, this), 0) - } - - Button.prototype.toggle = function () { - var changed = true - var $parent = this.$element.closest('[data-toggle="buttons"]') - - if ($parent.length) { - var $input = this.$element.find('input') - if ($input.prop('type') == 'radio') { - if ($input.prop('checked')) changed = false - $parent.find('.active').removeClass('active') - this.$element.addClass('active') - } else if ($input.prop('type') == 'checkbox') { - if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false - this.$element.toggleClass('active') - } - $input.prop('checked', this.$element.hasClass('active')) - if (changed) $input.trigger('change') - } else { - this.$element.attr('aria-pressed', !this.$element.hasClass('active')) - this.$element.toggleClass('active') - } - } - - - // BUTTON PLUGIN DEFINITION - // ======================== - - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.button') - var options = typeof option == 'object' && option - - if (!data) $this.data('bs.button', (data = new Button(this, options))) - - if (option == 'toggle') data.toggle() - else if (option) data.setState(option) - }) - } + if (state == 'loadingText') { + this.isLoading = true + $el.addClass(d).attr(d, d).prop(d, true) + } else if (this.isLoading) { + this.isLoading = false + $el.removeClass(d).removeAttr(d).prop(d, false) + } + }, this), 0) + } - var old = $.fn.button + Button.prototype.toggle = function () { + var changed = true + var $parent = this.$element.closest('[data-toggle="buttons"]') + + if ($parent.length) { + var $input = this.$element.find('input') + if ($input.prop('type') == 'radio') { + if ($input.prop('checked')) changed = false + $parent.find('.active').removeClass('active') + this.$element.addClass('active') + } else if ($input.prop('type') == 'checkbox') { + if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false + this.$element.toggleClass('active') + } + $input.prop('checked', this.$element.hasClass('active')) + if (changed) $input.trigger('change') + } else { + this.$element.attr('aria-pressed', !this.$element.hasClass('active')) + this.$element.toggleClass('active') + } + } - $.fn.button = Plugin - $.fn.button.Constructor = Button + // BUTTON PLUGIN DEFINITION + // ======================== - // BUTTON NO CONFLICT - // ================== + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.button') + var options = typeof option == 'object' && option - $.fn.button.noConflict = function () { - $.fn.button = old - return this - } + if (!data) $this.data('bs.button', (data = new Button(this, options))) + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } - // BUTTON DATA-API - // =============== + var old = $.fn.button + + $.fn.button = Plugin + $.fn.button.Constructor = Button - $(document) - .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { - var $btn = $(e.target).closest('.btn') - Plugin.call($btn, 'toggle') - if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) { - // Prevent double click on radios, and the double selections (so cancellation) on checkboxes - e.preventDefault() - // The target component still receive the focus - if ($btn.is('input,button')) $btn.trigger('focus') - else $btn.find('input:visible,button:visible').first().trigger('focus') - } - }) - .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { - $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type)) - }) + + // BUTTON NO CONFLICT + // ================== + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + + // BUTTON DATA-API + // =============== + + $(document) + .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { + var $btn = $(e.target).closest('.btn') + Plugin.call($btn, 'toggle') + if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) { + // Prevent double click on radios, and the double selections (so cancellation) on checkboxes + e.preventDefault() + // The target component still receive the focus + if ($btn.is('input,button')) $btn.trigger('focus') + else $btn.find('input:visible,button:visible').first().trigger('focus') + } + }) + .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { + $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type)) + }) }(jQuery); @@ -307,231 +307,231 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; + + // CAROUSEL CLASS DEFINITION + // ========================= + + var Carousel = function (element, options) { + this.$element = $(element) + this.$indicators = this.$element.find('.carousel-indicators') + this.options = options + this.paused = null + this.sliding = null + this.interval = null + this.$active = null + this.$items = null + + this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this)) + + this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element + .on('mouseenter.bs.carousel', $.proxy(this.pause, this)) + .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) + } - // CAROUSEL CLASS DEFINITION - // ========================= + Carousel.VERSION = '3.3.7' - var Carousel = function (element, options) { - this.$element = $(element) - this.$indicators = this.$element.find('.carousel-indicators') - this.options = options - this.paused = null - this.sliding = null - this.interval = null - this.$active = null - this.$items = null + Carousel.TRANSITION_DURATION = 600 - this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this)) + Carousel.DEFAULTS = { + interval: 5000, + pause: 'hover', + wrap: true, + keyboard: true + } - this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element - .on('mouseenter.bs.carousel', $.proxy(this.pause, this)) - .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) - } + Carousel.prototype.keydown = function (e) { + if (/input|textarea/i.test(e.target.tagName)) return + switch (e.which) { + case 37: this.prev(); break + case 39: this.next(); break + default: return + } - Carousel.VERSION = '3.3.7' + e.preventDefault() + } - Carousel.TRANSITION_DURATION = 600 + Carousel.prototype.cycle = function (e) { + e || (this.paused = false) - Carousel.DEFAULTS = { - interval: 5000, - pause: 'hover', - wrap: true, - keyboard: true - } + this.interval && clearInterval(this.interval) - Carousel.prototype.keydown = function (e) { - if (/input|textarea/i.test(e.target.tagName)) return - switch (e.which) { - case 37: this.prev(); break - case 39: this.next(); break - default: return - } + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) - e.preventDefault() - } + return this + } - Carousel.prototype.cycle = function (e) { - e || (this.paused = false) + Carousel.prototype.getItemIndex = function (item) { + this.$items = item.parent().children('.item') + return this.$items.index(item || this.$active) + } - this.interval && clearInterval(this.interval) + Carousel.prototype.getItemForDirection = function (direction, active) { + var activeIndex = this.getItemIndex(active) + var willWrap = (direction == 'prev' && activeIndex === 0) + || (direction == 'next' && activeIndex == (this.$items.length - 1)) + if (willWrap && !this.options.wrap) return active + var delta = direction == 'prev' ? -1 : 1 + var itemIndex = (activeIndex + delta) % this.$items.length + return this.$items.eq(itemIndex) + } - this.options.interval - && !this.paused - && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + Carousel.prototype.to = function (pos) { + var that = this + var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) - return this - } + if (pos > (this.$items.length - 1) || pos < 0) return - Carousel.prototype.getItemIndex = function (item) { - this.$items = item.parent().children('.item') - return this.$items.index(item || this.$active) - } + if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" + if (activeIndex == pos) return this.pause().cycle() - Carousel.prototype.getItemForDirection = function (direction, active) { - var activeIndex = this.getItemIndex(active) - var willWrap = (direction == 'prev' && activeIndex === 0) - || (direction == 'next' && activeIndex == (this.$items.length - 1)) - if (willWrap && !this.options.wrap) return active - var delta = direction == 'prev' ? -1 : 1 - var itemIndex = (activeIndex + delta) % this.$items.length - return this.$items.eq(itemIndex) - } + return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos)) + } - Carousel.prototype.to = function (pos) { - var that = this - var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) + Carousel.prototype.pause = function (e) { + e || (this.paused = true) - if (pos > (this.$items.length - 1) || pos < 0) return + if (this.$element.find('.next, .prev').length && $.support.transition) { + this.$element.trigger($.support.transition.end) + this.cycle(true) + } - if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" - if (activeIndex == pos) return this.pause().cycle() + this.interval = clearInterval(this.interval) - return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos)) - } + return this + } - Carousel.prototype.pause = function (e) { - e || (this.paused = true) + Carousel.prototype.next = function () { + if (this.sliding) return + return this.slide('next') + } - if (this.$element.find('.next, .prev').length && $.support.transition) { - this.$element.trigger($.support.transition.end) - this.cycle(true) + Carousel.prototype.prev = function () { + if (this.sliding) return + return this.slide('prev') } - this.interval = clearInterval(this.interval) + Carousel.prototype.slide = function (type, next) { + var $active = this.$element.find('.item.active') + var $next = next || this.getItemForDirection(type, $active) + var isCycling = this.interval + var direction = type == 'next' ? 'left' : 'right' + var that = this - return this - } + if ($next.hasClass('active')) return (this.sliding = false) - Carousel.prototype.next = function () { - if (this.sliding) return - return this.slide('next') - } + var relatedTarget = $next[0] + var slideEvent = $.Event('slide.bs.carousel', { + relatedTarget: relatedTarget, + direction: direction + }) + this.$element.trigger(slideEvent) + if (slideEvent.isDefaultPrevented()) return - Carousel.prototype.prev = function () { - if (this.sliding) return - return this.slide('prev') - } + this.sliding = true - Carousel.prototype.slide = function (type, next) { - var $active = this.$element.find('.item.active') - var $next = next || this.getItemForDirection(type, $active) - var isCycling = this.interval - var direction = type == 'next' ? 'left' : 'right' - var that = this + isCycling && this.pause() - if ($next.hasClass('active')) return (this.sliding = false) + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) + $nextIndicator && $nextIndicator.addClass('active') + } - var relatedTarget = $next[0] - var slideEvent = $.Event('slide.bs.carousel', { - relatedTarget: relatedTarget, - direction: direction - }) - this.$element.trigger(slideEvent) - if (slideEvent.isDefaultPrevented()) return - - this.sliding = true - - isCycling && this.pause() - - if (this.$indicators.length) { - this.$indicators.find('.active').removeClass('active') - var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) - $nextIndicator && $nextIndicator.addClass('active') - } - - var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid" - if ($.support.transition && this.$element.hasClass('slide')) { - $next.addClass(type) - $next[0].offsetWidth // force reflow - $active.addClass(direction) - $next.addClass(direction) - $active - .one('bsTransitionEnd', function () { - $next.removeClass([type, direction].join(' ')).addClass('active') - $active.removeClass(['active', direction].join(' ')) - that.sliding = false - setTimeout(function () { - that.$element.trigger(slidEvent) - }, 0) - }) - .emulateTransitionEnd(Carousel.TRANSITION_DURATION) - } else { - $active.removeClass('active') - $next.addClass('active') - this.sliding = false - this.$element.trigger(slidEvent) - } + var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid" + if ($.support.transition && this.$element.hasClass('slide')) { + $next.addClass(type) + $next[0].offsetWidth // force reflow + $active.addClass(direction) + $next.addClass(direction) + $active + .one('bsTransitionEnd', function () { + $next.removeClass([type, direction].join(' ')).addClass('active') + $active.removeClass(['active', direction].join(' ')) + that.sliding = false + setTimeout(function () { + that.$element.trigger(slidEvent) + }, 0) + }) + .emulateTransitionEnd(Carousel.TRANSITION_DURATION) + } else { + $active.removeClass('active') + $next.addClass('active') + this.sliding = false + this.$element.trigger(slidEvent) + } - isCycling && this.cycle() + isCycling && this.cycle() - return this - } + return this + } - // CAROUSEL PLUGIN DEFINITION - // ========================== + // CAROUSEL PLUGIN DEFINITION + // ========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.carousel') - var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) - var action = typeof option == 'string' ? option : options.slide + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.carousel') + var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) + var action = typeof option == 'string' ? option : options.slide - if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) - if (typeof option == 'number') data.to(option) - else if (action) data[action]() - else if (options.interval) data.pause().cycle() - }) - } + if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) + if (typeof option == 'number') data.to(option) + else if (action) data[action]() + else if (options.interval) data.pause().cycle() + }) + } - var old = $.fn.carousel + var old = $.fn.carousel - $.fn.carousel = Plugin - $.fn.carousel.Constructor = Carousel + $.fn.carousel = Plugin + $.fn.carousel.Constructor = Carousel - // CAROUSEL NO CONFLICT - // ==================== + // CAROUSEL NO CONFLICT + // ==================== - $.fn.carousel.noConflict = function () { - $.fn.carousel = old - return this - } + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } - // CAROUSEL DATA-API - // ================= + // CAROUSEL DATA-API + // ================= - var clickHandler = function (e) { - var href - var $this = $(this) - var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 - if (!$target.hasClass('carousel')) return - var options = $.extend({}, $target.data(), $this.data()) - var slideIndex = $this.attr('data-slide-to') - if (slideIndex) options.interval = false + var clickHandler = function (e) { + var href + var $this = $(this) + var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 + if (!$target.hasClass('carousel')) return + var options = $.extend({}, $target.data(), $this.data()) + var slideIndex = $this.attr('data-slide-to') + if (slideIndex) options.interval = false - Plugin.call($target, options) + Plugin.call($target, options) - if (slideIndex) { - $target.data('bs.carousel').to(slideIndex) - } + if (slideIndex) { + $target.data('bs.carousel').to(slideIndex) + } - e.preventDefault() - } + e.preventDefault() + } - $(document) - .on('click.bs.carousel.data-api', '[data-slide]', clickHandler) - .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler) + $(document) + .on('click.bs.carousel.data-api', '[data-slide]', clickHandler) + .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler) - $(window).on('load', function () { - $('[data-ride="carousel"]').each(function () { - var $carousel = $(this) - Plugin.call($carousel, $carousel.data()) + $(window).on('load', function () { + $('[data-ride="carousel"]').each(function () { + var $carousel = $(this) + Plugin.call($carousel, $carousel.data()) + }) }) - }) }(jQuery); @@ -546,205 +546,205 @@ if (typeof jQuery === 'undefined') { /* jshint latedef: false */ +function ($) { - 'use strict'; + 'use strict'; + + // COLLAPSE PUBLIC CLASS DEFINITION + // ================================ + + var Collapse = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Collapse.DEFAULTS, options) + this.$trigger = $('[data-toggle="collapse"][href="#' + element.id + '"],' + + '[data-toggle="collapse"][data-target="#' + element.id + '"]') + this.transitioning = null + + if (this.options.parent) { + this.$parent = this.getParent() + } else { + this.addAriaAndCollapsedClass(this.$element, this.$trigger) + } - // COLLAPSE PUBLIC CLASS DEFINITION - // ================================ + if (this.options.toggle) this.toggle() + } - var Collapse = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Collapse.DEFAULTS, options) - this.$trigger = $('[data-toggle="collapse"][href="#' + element.id + '"],' + - '[data-toggle="collapse"][data-target="#' + element.id + '"]') - this.transitioning = null + Collapse.VERSION = '3.3.7' - if (this.options.parent) { - this.$parent = this.getParent() - } else { - this.addAriaAndCollapsedClass(this.$element, this.$trigger) - } + Collapse.TRANSITION_DURATION = 350 - if (this.options.toggle) this.toggle() - } + Collapse.DEFAULTS = { + toggle: true + } - Collapse.VERSION = '3.3.7' + Collapse.prototype.dimension = function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } - Collapse.TRANSITION_DURATION = 350 + Collapse.prototype.show = function () { + if (this.transitioning || this.$element.hasClass('in')) return - Collapse.DEFAULTS = { - toggle: true - } + var activesData + var actives = this.$parent && this.$parent.children('.panel').children('.in, .collapsing') - Collapse.prototype.dimension = function () { - var hasWidth = this.$element.hasClass('width') - return hasWidth ? 'width' : 'height' - } + if (actives && actives.length) { + activesData = actives.data('bs.collapse') + if (activesData && activesData.transitioning) return + } - Collapse.prototype.show = function () { - if (this.transitioning || this.$element.hasClass('in')) return + var startEvent = $.Event('show.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return - var activesData - var actives = this.$parent && this.$parent.children('.panel').children('.in, .collapsing') + if (actives && actives.length) { + Plugin.call(actives, 'hide') + activesData || actives.data('bs.collapse', null) + } - if (actives && actives.length) { - activesData = actives.data('bs.collapse') - if (activesData && activesData.transitioning) return - } + var dimension = this.dimension() - var startEvent = $.Event('show.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return + this.$element + .removeClass('collapse') + .addClass('collapsing')[dimension](0) + .attr('aria-expanded', true) - if (actives && actives.length) { - Plugin.call(actives, 'hide') - activesData || actives.data('bs.collapse', null) - } + this.$trigger + .removeClass('collapsed') + .attr('aria-expanded', true) - var dimension = this.dimension() + this.transitioning = 1 - this.$element - .removeClass('collapse') - .addClass('collapsing')[dimension](0) - .attr('aria-expanded', true) + var complete = function () { + this.$element + .removeClass('collapsing') + .addClass('collapse in')[dimension]('') + this.transitioning = 0 + this.$element + .trigger('shown.bs.collapse') + } - this.$trigger - .removeClass('collapsed') - .attr('aria-expanded', true) + if (!$.support.transition) return complete.call(this) - this.transitioning = 1 + var scrollSize = $.camelCase(['scroll', dimension].join('-')) - var complete = function () { - this.$element - .removeClass('collapsing') - .addClass('collapse in')[dimension]('') - this.transitioning = 0 - this.$element - .trigger('shown.bs.collapse') + this.$element + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize]) } - if (!$.support.transition) return complete.call(this) - - var scrollSize = $.camelCase(['scroll', dimension].join('-')) + Collapse.prototype.hide = function () { + if (this.transitioning || !this.$element.hasClass('in')) return - this.$element - .one('bsTransitionEnd', $.proxy(complete, this)) - .emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize]) - } + var startEvent = $.Event('hide.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return - Collapse.prototype.hide = function () { - if (this.transitioning || !this.$element.hasClass('in')) return + var dimension = this.dimension() - var startEvent = $.Event('hide.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return + this.$element[dimension](this.$element[dimension]())[0].offsetHeight - var dimension = this.dimension() + this.$element + .addClass('collapsing') + .removeClass('collapse in') + .attr('aria-expanded', false) - this.$element[dimension](this.$element[dimension]())[0].offsetHeight + this.$trigger + .addClass('collapsed') + .attr('aria-expanded', false) - this.$element - .addClass('collapsing') - .removeClass('collapse in') - .attr('aria-expanded', false) + this.transitioning = 1 - this.$trigger - .addClass('collapsed') - .attr('aria-expanded', false) + var complete = function () { + this.transitioning = 0 + this.$element + .removeClass('collapsing') + .addClass('collapse') + .trigger('hidden.bs.collapse') + } - this.transitioning = 1 + if (!$.support.transition) return complete.call(this) - var complete = function () { - this.transitioning = 0 - this.$element - .removeClass('collapsing') - .addClass('collapse') - .trigger('hidden.bs.collapse') + this.$element + [dimension](0) + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(Collapse.TRANSITION_DURATION) } - if (!$.support.transition) return complete.call(this) - - this.$element - [dimension](0) - .one('bsTransitionEnd', $.proxy(complete, this)) - .emulateTransitionEnd(Collapse.TRANSITION_DURATION) - } - - Collapse.prototype.toggle = function () { - this[this.$element.hasClass('in') ? 'hide' : 'show']() - } + Collapse.prototype.toggle = function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } - Collapse.prototype.getParent = function () { - return $(this.options.parent) - .find('[data-toggle="collapse"][data-parent="' + this.options.parent + '"]') - .each($.proxy(function (i, element) { - var $element = $(element) - this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element) - }, this)) - .end() - } + Collapse.prototype.getParent = function () { + return $(this.options.parent) + .find('[data-toggle="collapse"][data-parent="' + this.options.parent + '"]') + .each($.proxy(function (i, element) { + var $element = $(element) + this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element) + }, this)) + .end() + } - Collapse.prototype.addAriaAndCollapsedClass = function ($element, $trigger) { - var isOpen = $element.hasClass('in') + Collapse.prototype.addAriaAndCollapsedClass = function ($element, $trigger) { + var isOpen = $element.hasClass('in') - $element.attr('aria-expanded', isOpen) - $trigger - .toggleClass('collapsed', !isOpen) - .attr('aria-expanded', isOpen) - } + $element.attr('aria-expanded', isOpen) + $trigger + .toggleClass('collapsed', !isOpen) + .attr('aria-expanded', isOpen) + } - function getTargetFromTrigger($trigger) { - var href - var target = $trigger.attr('data-target') - || (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7 + function getTargetFromTrigger($trigger) { + var href + var target = $trigger.attr('data-target') + || (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7 - return $(target) - } + return $(target) + } - // COLLAPSE PLUGIN DEFINITION - // ========================== + // COLLAPSE PLUGIN DEFINITION + // ========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.collapse') - var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.collapse') + var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) - if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false - if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) - if (typeof option == 'string') data[option]() - }) - } + if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false + if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) + if (typeof option == 'string') data[option]() + }) + } - var old = $.fn.collapse + var old = $.fn.collapse - $.fn.collapse = Plugin - $.fn.collapse.Constructor = Collapse + $.fn.collapse = Plugin + $.fn.collapse.Constructor = Collapse - // COLLAPSE NO CONFLICT - // ==================== + // COLLAPSE NO CONFLICT + // ==================== - $.fn.collapse.noConflict = function () { - $.fn.collapse = old - return this - } + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } - // COLLAPSE DATA-API - // ================= + // COLLAPSE DATA-API + // ================= - $(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { - var $this = $(this) + $(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { + var $this = $(this) - if (!$this.attr('data-target')) e.preventDefault() + if (!$this.attr('data-target')) e.preventDefault() - var $target = getTargetFromTrigger($this) - var data = $target.data('bs.collapse') - var option = data ? 'toggle' : $this.data() + var $target = getTargetFromTrigger($this) + var data = $target.data('bs.collapse') + var option = data ? 'toggle' : $this.data() - Plugin.call($target, option) - }) + Plugin.call($target, option) + }) }(jQuery); @@ -758,159 +758,159 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // DROPDOWN CLASS DEFINITION - // ========================= + // DROPDOWN CLASS DEFINITION + // ========================= - var backdrop = '.dropdown-backdrop' - var toggle = '[data-toggle="dropdown"]' - var Dropdown = function (element) { - $(element).on('click.bs.dropdown', this.toggle) - } + var backdrop = '.dropdown-backdrop' + var toggle = '[data-toggle="dropdown"]' + var Dropdown = function (element) { + $(element).on('click.bs.dropdown', this.toggle) + } - Dropdown.VERSION = '3.3.7' + Dropdown.VERSION = '3.3.7' - function getParent($this) { - var selector = $this.attr('data-target') + function getParent($this) { + var selector = $this.attr('data-target') - if (!selector) { - selector = $this.attr('href') - selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } + if (!selector) { + selector = $this.attr('href') + selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } - var $parent = selector && $(selector) + var $parent = selector && $(selector) - return $parent && $parent.length ? $parent : $this.parent() - } + return $parent && $parent.length ? $parent : $this.parent() + } - function clearMenus(e) { - if (e && e.which === 3) return - $(backdrop).remove() - $(toggle).each(function () { - var $this = $(this) - var $parent = getParent($this) - var relatedTarget = { relatedTarget: this } + function clearMenus(e) { + if (e && e.which === 3) return + $(backdrop).remove() + $(toggle).each(function () { + var $this = $(this) + var $parent = getParent($this) + var relatedTarget = { relatedTarget: this } - if (!$parent.hasClass('open')) return + if (!$parent.hasClass('open')) return - if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return + if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return - $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) + $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) - if (e.isDefaultPrevented()) return + if (e.isDefaultPrevented()) return - $this.attr('aria-expanded', 'false') - $parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget)) - }) - } + $this.attr('aria-expanded', 'false') + $parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget)) + }) + } - Dropdown.prototype.toggle = function (e) { - var $this = $(this) + Dropdown.prototype.toggle = function (e) { + var $this = $(this) - if ($this.is('.disabled, :disabled')) return + if ($this.is('.disabled, :disabled')) return - var $parent = getParent($this) - var isActive = $parent.hasClass('open') + var $parent = getParent($this) + var isActive = $parent.hasClass('open') - clearMenus() + clearMenus() - if (!isActive) { - if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { - // if mobile we use a backdrop because click events don't delegate - $(document.createElement('div')) - .addClass('dropdown-backdrop') - .insertAfter($(this)) - .on('click', clearMenus) - } + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we use a backdrop because click events don't delegate + $(document.createElement('div')) + .addClass('dropdown-backdrop') + .insertAfter($(this)) + .on('click', clearMenus) + } - var relatedTarget = { relatedTarget: this } - $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget)) + var relatedTarget = { relatedTarget: this } + $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget)) - if (e.isDefaultPrevented()) return + if (e.isDefaultPrevented()) return - $this - .trigger('focus') - .attr('aria-expanded', 'true') + $this + .trigger('focus') + .attr('aria-expanded', 'true') - $parent - .toggleClass('open') - .trigger($.Event('shown.bs.dropdown', relatedTarget)) - } + $parent + .toggleClass('open') + .trigger($.Event('shown.bs.dropdown', relatedTarget)) + } - return false - } + return false + } - Dropdown.prototype.keydown = function (e) { - if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return + Dropdown.prototype.keydown = function (e) { + if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return - var $this = $(this) + var $this = $(this) - e.preventDefault() - e.stopPropagation() + e.preventDefault() + e.stopPropagation() - if ($this.is('.disabled, :disabled')) return + if ($this.is('.disabled, :disabled')) return - var $parent = getParent($this) - var isActive = $parent.hasClass('open') + var $parent = getParent($this) + var isActive = $parent.hasClass('open') - if (!isActive && e.which != 27 || isActive && e.which == 27) { - if (e.which == 27) $parent.find(toggle).trigger('focus') - return $this.trigger('click') - } + if (!isActive && e.which != 27 || isActive && e.which == 27) { + if (e.which == 27) $parent.find(toggle).trigger('focus') + return $this.trigger('click') + } - var desc = ' li:not(.disabled):visible a' - var $items = $parent.find('.dropdown-menu' + desc) + var desc = ' li:not(.disabled):visible a' + var $items = $parent.find('.dropdown-menu' + desc) - if (!$items.length) return + if (!$items.length) return - var index = $items.index(e.target) + var index = $items.index(e.target) - if (e.which == 38 && index > 0) index-- // up - if (e.which == 40 && index < $items.length - 1) index++ // down - if (!~index) index = 0 + if (e.which == 38 && index > 0) index-- // up + if (e.which == 40 && index < $items.length - 1) index++ // down + if (!~index) index = 0 - $items.eq(index).trigger('focus') - } + $items.eq(index).trigger('focus') + } - // DROPDOWN PLUGIN DEFINITION - // ========================== + // DROPDOWN PLUGIN DEFINITION + // ========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.dropdown') + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.dropdown') - if (!data) $this.data('bs.dropdown', (data = new Dropdown(this))) - if (typeof option == 'string') data[option].call($this) - }) - } + if (!data) $this.data('bs.dropdown', (data = new Dropdown(this))) + if (typeof option == 'string') data[option].call($this) + }) + } - var old = $.fn.dropdown + var old = $.fn.dropdown - $.fn.dropdown = Plugin - $.fn.dropdown.Constructor = Dropdown + $.fn.dropdown = Plugin + $.fn.dropdown.Constructor = Dropdown - // DROPDOWN NO CONFLICT - // ==================== + // DROPDOWN NO CONFLICT + // ==================== - $.fn.dropdown.noConflict = function () { - $.fn.dropdown = old - return this - } + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old + return this + } - // APPLY TO STANDARD DROPDOWN ELEMENTS - // =================================== + // APPLY TO STANDARD DROPDOWN ELEMENTS + // =================================== - $(document) - .on('click.bs.dropdown.data-api', clearMenus) - .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) - .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle) - .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown) - .on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown) + $(document) + .on('click.bs.dropdown.data-api', clearMenus) + .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) + .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle) + .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown) + .on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown) }(jQuery); @@ -924,333 +924,333 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; + + // MODAL CLASS DEFINITION + // ====================== + + var Modal = function (element, options) { + this.options = options + this.$body = $(document.body) + this.$element = $(element) + this.$dialog = this.$element.find('.modal-dialog') + this.$backdrop = null + this.isShown = null + this.originalBodyPad = null + this.scrollbarWidth = 0 + this.ignoreBackdropClick = false + + if (this.options.remote) { + this.$element + .find('.modal-content') + .load(this.options.remote, $.proxy(function () { + this.$element.trigger('loaded.bs.modal') + }, this)) + } + } - // MODAL CLASS DEFINITION - // ====================== + Modal.VERSION = '3.3.7' - var Modal = function (element, options) { - this.options = options - this.$body = $(document.body) - this.$element = $(element) - this.$dialog = this.$element.find('.modal-dialog') - this.$backdrop = null - this.isShown = null - this.originalBodyPad = null - this.scrollbarWidth = 0 - this.ignoreBackdropClick = false + Modal.TRANSITION_DURATION = 300 + Modal.BACKDROP_TRANSITION_DURATION = 150 - if (this.options.remote) { - this.$element - .find('.modal-content') - .load(this.options.remote, $.proxy(function () { - this.$element.trigger('loaded.bs.modal') - }, this)) + Modal.DEFAULTS = { + backdrop: true, + keyboard: true, + show: true } - } - - Modal.VERSION = '3.3.7' - - Modal.TRANSITION_DURATION = 300 - Modal.BACKDROP_TRANSITION_DURATION = 150 - Modal.DEFAULTS = { - backdrop: true, - keyboard: true, - show: true - } + Modal.prototype.toggle = function (_relatedTarget) { + return this.isShown ? this.hide() : this.show(_relatedTarget) + } - Modal.prototype.toggle = function (_relatedTarget) { - return this.isShown ? this.hide() : this.show(_relatedTarget) - } + Modal.prototype.show = function (_relatedTarget) { + var that = this + var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) - Modal.prototype.show = function (_relatedTarget) { - var that = this - var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) + this.$element.trigger(e) - this.$element.trigger(e) + if (this.isShown || e.isDefaultPrevented()) return - if (this.isShown || e.isDefaultPrevented()) return + this.isShown = true - this.isShown = true + this.checkScrollbar() + this.setScrollbar() + this.$body.addClass('modal-open') - this.checkScrollbar() - this.setScrollbar() - this.$body.addClass('modal-open') + this.escape() + this.resize() - this.escape() - this.resize() + this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) - this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) + this.$dialog.on('mousedown.dismiss.bs.modal', function () { + that.$element.one('mouseup.dismiss.bs.modal', function (e) { + if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true + }) + }) - this.$dialog.on('mousedown.dismiss.bs.modal', function () { - that.$element.one('mouseup.dismiss.bs.modal', function (e) { - if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true - }) - }) + this.backdrop(function () { + var transition = $.support.transition && that.$element.hasClass('fade') - this.backdrop(function () { - var transition = $.support.transition && that.$element.hasClass('fade') + if (!that.$element.parent().length) { + that.$element.appendTo(that.$body) // don't move modals dom position + } - if (!that.$element.parent().length) { - that.$element.appendTo(that.$body) // don't move modals dom position - } + that.$element + .show() + .scrollTop(0) - that.$element - .show() - .scrollTop(0) + that.adjustDialog() - that.adjustDialog() + if (transition) { + that.$element[0].offsetWidth // force reflow + } - if (transition) { - that.$element[0].offsetWidth // force reflow - } + that.$element.addClass('in') - that.$element.addClass('in') + that.enforceFocus() - that.enforceFocus() + var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) - var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) + transition ? + that.$dialog // wait for modal to slide in + .one('bsTransitionEnd', function () { + that.$element.trigger('focus').trigger(e) + }) + .emulateTransitionEnd(Modal.TRANSITION_DURATION) : + that.$element.trigger('focus').trigger(e) + }) + } - transition ? - that.$dialog // wait for modal to slide in - .one('bsTransitionEnd', function () { - that.$element.trigger('focus').trigger(e) - }) - .emulateTransitionEnd(Modal.TRANSITION_DURATION) : - that.$element.trigger('focus').trigger(e) - }) - } + Modal.prototype.hide = function (e) { + if (e) e.preventDefault() - Modal.prototype.hide = function (e) { - if (e) e.preventDefault() + e = $.Event('hide.bs.modal') - e = $.Event('hide.bs.modal') + this.$element.trigger(e) - this.$element.trigger(e) + if (!this.isShown || e.isDefaultPrevented()) return - if (!this.isShown || e.isDefaultPrevented()) return + this.isShown = false - this.isShown = false + this.escape() + this.resize() - this.escape() - this.resize() + $(document).off('focusin.bs.modal') - $(document).off('focusin.bs.modal') + this.$element + .removeClass('in') + .off('click.dismiss.bs.modal') + .off('mouseup.dismiss.bs.modal') - this.$element - .removeClass('in') - .off('click.dismiss.bs.modal') - .off('mouseup.dismiss.bs.modal') + this.$dialog.off('mousedown.dismiss.bs.modal') - this.$dialog.off('mousedown.dismiss.bs.modal') + $.support.transition && this.$element.hasClass('fade') ? + this.$element + .one('bsTransitionEnd', $.proxy(this.hideModal, this)) + .emulateTransitionEnd(Modal.TRANSITION_DURATION) : + this.hideModal() + } - $.support.transition && this.$element.hasClass('fade') ? - this.$element - .one('bsTransitionEnd', $.proxy(this.hideModal, this)) - .emulateTransitionEnd(Modal.TRANSITION_DURATION) : - this.hideModal() - } + Modal.prototype.enforceFocus = function () { + $(document) + .off('focusin.bs.modal') // guard against infinite focus loop + .on('focusin.bs.modal', $.proxy(function (e) { + if (document !== e.target && + this.$element[0] !== e.target && + !this.$element.has(e.target).length) { + this.$element.trigger('focus') + } + }, this)) + } - Modal.prototype.enforceFocus = function () { - $(document) - .off('focusin.bs.modal') // guard against infinite focus loop - .on('focusin.bs.modal', $.proxy(function (e) { - if (document !== e.target && - this.$element[0] !== e.target && - !this.$element.has(e.target).length) { - this.$element.trigger('focus') + Modal.prototype.escape = function () { + if (this.isShown && this.options.keyboard) { + this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) { + e.which == 27 && this.hide() + }, this)) + } else if (!this.isShown) { + this.$element.off('keydown.dismiss.bs.modal') } - }, this)) - } - - Modal.prototype.escape = function () { - if (this.isShown && this.options.keyboard) { - this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) { - e.which == 27 && this.hide() - }, this)) - } else if (!this.isShown) { - this.$element.off('keydown.dismiss.bs.modal') - } - } - - Modal.prototype.resize = function () { - if (this.isShown) { - $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this)) - } else { - $(window).off('resize.bs.modal') - } - } - - Modal.prototype.hideModal = function () { - var that = this - this.$element.hide() - this.backdrop(function () { - that.$body.removeClass('modal-open') - that.resetAdjustments() - that.resetScrollbar() - that.$element.trigger('hidden.bs.modal') - }) - } - - Modal.prototype.removeBackdrop = function () { - this.$backdrop && this.$backdrop.remove() - this.$backdrop = null - } + } - Modal.prototype.backdrop = function (callback) { - var that = this - var animate = this.$element.hasClass('fade') ? 'fade' : '' + Modal.prototype.resize = function () { + if (this.isShown) { + $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this)) + } else { + $(window).off('resize.bs.modal') + } + } - if (this.isShown && this.options.backdrop) { - var doAnimate = $.support.transition && animate + Modal.prototype.hideModal = function () { + var that = this + this.$element.hide() + this.backdrop(function () { + that.$body.removeClass('modal-open') + that.resetAdjustments() + that.resetScrollbar() + that.$element.trigger('hidden.bs.modal') + }) + } - this.$backdrop = $(document.createElement('div')) - .addClass('modal-backdrop ' + animate) - .appendTo(this.$body) + Modal.prototype.removeBackdrop = function () { + this.$backdrop && this.$backdrop.remove() + this.$backdrop = null + } - this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { - if (this.ignoreBackdropClick) { - this.ignoreBackdropClick = false - return + Modal.prototype.backdrop = function (callback) { + var that = this + var animate = this.$element.hasClass('fade') ? 'fade' : '' + + if (this.isShown && this.options.backdrop) { + var doAnimate = $.support.transition && animate + + this.$backdrop = $(document.createElement('div')) + .addClass('modal-backdrop ' + animate) + .appendTo(this.$body) + + this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { + if (this.ignoreBackdropClick) { + this.ignoreBackdropClick = false + return + } + if (e.target !== e.currentTarget) return + this.options.backdrop == 'static' + ? this.$element[0].focus() + : this.hide() + }, this)) + + if (doAnimate) this.$backdrop[0].offsetWidth // force reflow + + this.$backdrop.addClass('in') + + if (!callback) return + + doAnimate ? + this.$backdrop + .one('bsTransitionEnd', callback) + .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : + callback() + + } else if (!this.isShown && this.$backdrop) { + this.$backdrop.removeClass('in') + + var callbackRemove = function () { + that.removeBackdrop() + callback && callback() + } + $.support.transition && this.$element.hasClass('fade') ? + this.$backdrop + .one('bsTransitionEnd', callbackRemove) + .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : + callbackRemove() + + } else if (callback) { + callback() } - if (e.target !== e.currentTarget) return - this.options.backdrop == 'static' - ? this.$element[0].focus() - : this.hide() - }, this)) + } - if (doAnimate) this.$backdrop[0].offsetWidth // force reflow + // these following methods are used to handle overflowing modals - this.$backdrop.addClass('in') + Modal.prototype.handleUpdate = function () { + this.adjustDialog() + } - if (!callback) return + Modal.prototype.adjustDialog = function () { + var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight - doAnimate ? - this.$backdrop - .one('bsTransitionEnd', callback) - .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : - callback() + this.$element.css({ + paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '', + paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : '' + }) + } - } else if (!this.isShown && this.$backdrop) { - this.$backdrop.removeClass('in') + Modal.prototype.resetAdjustments = function () { + this.$element.css({ + paddingLeft: '', + paddingRight: '' + }) + } - var callbackRemove = function () { - that.removeBackdrop() - callback && callback() - } - $.support.transition && this.$element.hasClass('fade') ? - this.$backdrop - .one('bsTransitionEnd', callbackRemove) - .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : - callbackRemove() + Modal.prototype.checkScrollbar = function () { + var fullWindowWidth = window.innerWidth + if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8 + var documentElementRect = document.documentElement.getBoundingClientRect() + fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left) + } + this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth + this.scrollbarWidth = this.measureScrollbar() + } - } else if (callback) { - callback() + Modal.prototype.setScrollbar = function () { + var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) + this.originalBodyPad = document.body.style.paddingRight || '' + if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) } - } - // these following methods are used to handle overflowing modals + Modal.prototype.resetScrollbar = function () { + this.$body.css('padding-right', this.originalBodyPad) + } - Modal.prototype.handleUpdate = function () { - this.adjustDialog() - } + Modal.prototype.measureScrollbar = function () { // thx walsh + var scrollDiv = document.createElement('div') + scrollDiv.className = 'modal-scrollbar-measure' + this.$body.append(scrollDiv) + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth + this.$body[0].removeChild(scrollDiv) + return scrollbarWidth + } - Modal.prototype.adjustDialog = function () { - var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight - this.$element.css({ - paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '', - paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : '' - }) - } + // MODAL PLUGIN DEFINITION + // ======================= - Modal.prototype.resetAdjustments = function () { - this.$element.css({ - paddingLeft: '', - paddingRight: '' - }) - } - - Modal.prototype.checkScrollbar = function () { - var fullWindowWidth = window.innerWidth - if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8 - var documentElementRect = document.documentElement.getBoundingClientRect() - fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left) - } - this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth - this.scrollbarWidth = this.measureScrollbar() - } - - Modal.prototype.setScrollbar = function () { - var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) - this.originalBodyPad = document.body.style.paddingRight || '' - if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) - } - - Modal.prototype.resetScrollbar = function () { - this.$body.css('padding-right', this.originalBodyPad) - } - - Modal.prototype.measureScrollbar = function () { // thx walsh - var scrollDiv = document.createElement('div') - scrollDiv.className = 'modal-scrollbar-measure' - this.$body.append(scrollDiv) - var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth - this.$body[0].removeChild(scrollDiv) - return scrollbarWidth - } - - - // MODAL PLUGIN DEFINITION - // ======================= - - function Plugin(option, _relatedTarget) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.modal') - var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) - - if (!data) $this.data('bs.modal', (data = new Modal(this, options))) - if (typeof option == 'string') data[option](_relatedTarget) - else if (options.show) data.show(_relatedTarget) - }) - } + function Plugin(option, _relatedTarget) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.modal') + var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) + + if (!data) $this.data('bs.modal', (data = new Modal(this, options))) + if (typeof option == 'string') data[option](_relatedTarget) + else if (options.show) data.show(_relatedTarget) + }) + } - var old = $.fn.modal + var old = $.fn.modal - $.fn.modal = Plugin - $.fn.modal.Constructor = Modal + $.fn.modal = Plugin + $.fn.modal.Constructor = Modal - // MODAL NO CONFLICT - // ================= + // MODAL NO CONFLICT + // ================= - $.fn.modal.noConflict = function () { - $.fn.modal = old - return this - } + $.fn.modal.noConflict = function () { + $.fn.modal = old + return this + } - // MODAL DATA-API - // ============== + // MODAL DATA-API + // ============== - $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { - var $this = $(this) - var href = $this.attr('href') - var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 - var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) + $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { + var $this = $(this) + var href = $this.attr('href') + var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 + var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) - if ($this.is('a')) e.preventDefault() + if ($this.is('a')) e.preventDefault() - $target.one('show.bs.modal', function (showEvent) { - if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown - $target.one('hidden.bs.modal', function () { - $this.is(':visible') && $this.trigger('focus') - }) + $target.one('show.bs.modal', function (showEvent) { + if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown + $target.one('hidden.bs.modal', function () { + $this.is(':visible') && $this.trigger('focus') + }) + }) + Plugin.call($target, option, this) }) - Plugin.call($target, option, this) - }) }(jQuery); @@ -1265,513 +1265,513 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // TOOLTIP PUBLIC CLASS DEFINITION - // =============================== + // TOOLTIP PUBLIC CLASS DEFINITION + // =============================== - var Tooltip = function (element, options) { - this.type = null - this.options = null - this.enabled = null - this.timeout = null - this.hoverState = null - this.$element = null - this.inState = null + var Tooltip = function (element, options) { + this.type = null + this.options = null + this.enabled = null + this.timeout = null + this.hoverState = null + this.$element = null + this.inState = null - this.init('tooltip', element, options) - } + this.init('tooltip', element, options) + } - Tooltip.VERSION = '3.3.7' + Tooltip.VERSION = '3.3.7' + + Tooltip.TRANSITION_DURATION = 150 + + Tooltip.DEFAULTS = { + animation: true, + placement: 'top', + selector: false, + template: '', + trigger: 'hover focus', + title: '', + delay: 0, + html: false, + container: false, + viewport: { + selector: 'body', + padding: 0 + } + } - Tooltip.TRANSITION_DURATION = 150 + Tooltip.prototype.init = function (type, element, options) { + this.enabled = true + this.type = type + this.$element = $(element) + this.options = this.getOptions(options) + this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport)) + this.inState = { click: false, hover: false, focus: false } - Tooltip.DEFAULTS = { - animation: true, - placement: 'top', - selector: false, - template: '', - trigger: 'hover focus', - title: '', - delay: 0, - html: false, - container: false, - viewport: { - selector: 'body', - padding: 0 - } - } + if (this.$element[0] instanceof document.constructor && !this.options.selector) { + throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!') + } - Tooltip.prototype.init = function (type, element, options) { - this.enabled = true - this.type = type - this.$element = $(element) - this.options = this.getOptions(options) - this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport)) - this.inState = { click: false, hover: false, focus: false } + var triggers = this.options.trigger.split(' ') - if (this.$element[0] instanceof document.constructor && !this.options.selector) { - throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!') - } + for (var i = triggers.length; i--;) { + var trigger = triggers[i] - var triggers = this.options.trigger.split(' ') + if (trigger == 'click') { + this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) + } else if (trigger != 'manual') { + var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' + var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' - for (var i = triggers.length; i--;) { - var trigger = triggers[i] + this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) + this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) + } + } - if (trigger == 'click') { - this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) - } else if (trigger != 'manual') { - var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' - var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' + this.options.selector ? + (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : + this.fixTitle() + } - this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) - this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) - } + Tooltip.prototype.getDefaults = function () { + return Tooltip.DEFAULTS } - this.options.selector ? - (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : - this.fixTitle() - } + Tooltip.prototype.getOptions = function (options) { + options = $.extend({}, this.getDefaults(), this.$element.data(), options) + + if (options.delay && typeof options.delay == 'number') { + options.delay = { + show: options.delay, + hide: options.delay + } + } + + return options + } - Tooltip.prototype.getDefaults = function () { - return Tooltip.DEFAULTS - } + Tooltip.prototype.getDelegateOptions = function () { + var options = {} + var defaults = this.getDefaults() - Tooltip.prototype.getOptions = function (options) { - options = $.extend({}, this.getDefaults(), this.$element.data(), options) + this._options && $.each(this._options, function (key, value) { + if (defaults[key] != value) options[key] = value + }) - if (options.delay && typeof options.delay == 'number') { - options.delay = { - show: options.delay, - hide: options.delay - } + return options } - return options - } + Tooltip.prototype.enter = function (obj) { + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget).data('bs.' + this.type) - Tooltip.prototype.getDelegateOptions = function () { - var options = {} - var defaults = this.getDefaults() + if (!self) { + self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) + $(obj.currentTarget).data('bs.' + this.type, self) + } - this._options && $.each(this._options, function (key, value) { - if (defaults[key] != value) options[key] = value - }) + if (obj instanceof $.Event) { + self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true + } - return options - } + if (self.tip().hasClass('in') || self.hoverState == 'in') { + self.hoverState = 'in' + return + } - Tooltip.prototype.enter = function (obj) { - var self = obj instanceof this.constructor ? - obj : $(obj.currentTarget).data('bs.' + this.type) + clearTimeout(self.timeout) - if (!self) { - self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) - $(obj.currentTarget).data('bs.' + this.type, self) - } + self.hoverState = 'in' + + if (!self.options.delay || !self.options.delay.show) return self.show() - if (obj instanceof $.Event) { - self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true + self.timeout = setTimeout(function () { + if (self.hoverState == 'in') self.show() + }, self.options.delay.show) } - if (self.tip().hasClass('in') || self.hoverState == 'in') { - self.hoverState = 'in' - return + Tooltip.prototype.isInStateTrue = function () { + for (var key in this.inState) { + if (this.inState[key]) return true + } + + return false } - clearTimeout(self.timeout) + Tooltip.prototype.leave = function (obj) { + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget).data('bs.' + this.type) - self.hoverState = 'in' + if (!self) { + self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) + $(obj.currentTarget).data('bs.' + this.type, self) + } - if (!self.options.delay || !self.options.delay.show) return self.show() + if (obj instanceof $.Event) { + self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false + } - self.timeout = setTimeout(function () { - if (self.hoverState == 'in') self.show() - }, self.options.delay.show) - } + if (self.isInStateTrue()) return - Tooltip.prototype.isInStateTrue = function () { - for (var key in this.inState) { - if (this.inState[key]) return true - } + clearTimeout(self.timeout) - return false - } + self.hoverState = 'out' - Tooltip.prototype.leave = function (obj) { - var self = obj instanceof this.constructor ? - obj : $(obj.currentTarget).data('bs.' + this.type) + if (!self.options.delay || !self.options.delay.hide) return self.hide() - if (!self) { - self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) - $(obj.currentTarget).data('bs.' + this.type, self) + self.timeout = setTimeout(function () { + if (self.hoverState == 'out') self.hide() + }, self.options.delay.hide) } - if (obj instanceof $.Event) { - self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false - } + Tooltip.prototype.show = function () { + var e = $.Event('show.bs.' + this.type) - if (self.isInStateTrue()) return + if (this.hasContent() && this.enabled) { + this.$element.trigger(e) - clearTimeout(self.timeout) + var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]) + if (e.isDefaultPrevented() || !inDom) return + var that = this - self.hoverState = 'out' + var $tip = this.tip() - if (!self.options.delay || !self.options.delay.hide) return self.hide() + var tipId = this.getUID(this.type) - self.timeout = setTimeout(function () { - if (self.hoverState == 'out') self.hide() - }, self.options.delay.hide) - } + this.setContent() + $tip.attr('id', tipId) + this.$element.attr('aria-describedby', tipId) - Tooltip.prototype.show = function () { - var e = $.Event('show.bs.' + this.type) + if (this.options.animation) $tip.addClass('fade') - if (this.hasContent() && this.enabled) { - this.$element.trigger(e) + var placement = typeof this.options.placement == 'function' ? + this.options.placement.call(this, $tip[0], this.$element[0]) : + this.options.placement - var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]) - if (e.isDefaultPrevented() || !inDom) return - var that = this + var autoToken = /\s?auto?\s?/i + var autoPlace = autoToken.test(placement) + if (autoPlace) placement = placement.replace(autoToken, '') || 'top' - var $tip = this.tip() + $tip + .detach() + .css({ top: 0, left: 0, display: 'block' }) + .addClass(placement) + .data('bs.' + this.type, this) - var tipId = this.getUID(this.type) + this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) + this.$element.trigger('inserted.bs.' + this.type) - this.setContent() - $tip.attr('id', tipId) - this.$element.attr('aria-describedby', tipId) + var pos = this.getPosition() + var actualWidth = $tip[0].offsetWidth + var actualHeight = $tip[0].offsetHeight - if (this.options.animation) $tip.addClass('fade') + if (autoPlace) { + var orgPlacement = placement + var viewportDim = this.getPosition(this.$viewport) - var placement = typeof this.options.placement == 'function' ? - this.options.placement.call(this, $tip[0], this.$element[0]) : - this.options.placement + placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' : + placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' : + placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' : + placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' : + placement - var autoToken = /\s?auto?\s?/i - var autoPlace = autoToken.test(placement) - if (autoPlace) placement = placement.replace(autoToken, '') || 'top' + $tip + .removeClass(orgPlacement) + .addClass(placement) + } - $tip - .detach() - .css({ top: 0, left: 0, display: 'block' }) - .addClass(placement) - .data('bs.' + this.type, this) + var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) - this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) - this.$element.trigger('inserted.bs.' + this.type) + this.applyPlacement(calculatedOffset, placement) - var pos = this.getPosition() - var actualWidth = $tip[0].offsetWidth - var actualHeight = $tip[0].offsetHeight + var complete = function () { + var prevHoverState = that.hoverState + that.$element.trigger('shown.bs.' + that.type) + that.hoverState = null - if (autoPlace) { - var orgPlacement = placement - var viewportDim = this.getPosition(this.$viewport) + if (prevHoverState == 'out') that.leave(that) + } - placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' : - placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' : - placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' : - placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' : - placement - - $tip - .removeClass(orgPlacement) - .addClass(placement) - } - - var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) - - this.applyPlacement(calculatedOffset, placement) - - var complete = function () { - var prevHoverState = that.hoverState - that.$element.trigger('shown.bs.' + that.type) - that.hoverState = null - - if (prevHoverState == 'out') that.leave(that) - } - - $.support.transition && this.$tip.hasClass('fade') ? - $tip - .one('bsTransitionEnd', complete) - .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : - complete() - } - } - - Tooltip.prototype.applyPlacement = function (offset, placement) { - var $tip = this.tip() - var width = $tip[0].offsetWidth - var height = $tip[0].offsetHeight - - // manually read margins because getBoundingClientRect includes difference - var marginTop = parseInt($tip.css('margin-top'), 10) - var marginLeft = parseInt($tip.css('margin-left'), 10) - - // we must check for NaN for ie 8/9 - if (isNaN(marginTop)) marginTop = 0 - if (isNaN(marginLeft)) marginLeft = 0 - - offset.top += marginTop - offset.left += marginLeft - - // $.fn.offset doesn't round pixel values - // so we use setOffset directly with our own function B-0 - $.offset.setOffset($tip[0], $.extend({ - using: function (props) { - $tip.css({ - top: Math.round(props.top), - left: Math.round(props.left) - }) - } - }, offset), 0) + $.support.transition && this.$tip.hasClass('fade') ? + $tip + .one('bsTransitionEnd', complete) + .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : + complete() + } + } - $tip.addClass('in') + Tooltip.prototype.applyPlacement = function (offset, placement) { + var $tip = this.tip() + var width = $tip[0].offsetWidth + var height = $tip[0].offsetHeight + + // manually read margins because getBoundingClientRect includes difference + var marginTop = parseInt($tip.css('margin-top'), 10) + var marginLeft = parseInt($tip.css('margin-left'), 10) + + // we must check for NaN for ie 8/9 + if (isNaN(marginTop)) marginTop = 0 + if (isNaN(marginLeft)) marginLeft = 0 + + offset.top += marginTop + offset.left += marginLeft + + // $.fn.offset doesn't round pixel values + // so we use setOffset directly with our own function B-0 + $.offset.setOffset($tip[0], $.extend({ + using: function (props) { + $tip.css({ + top: Math.round(props.top), + left: Math.round(props.left) + }) + } + }, offset), 0) + + $tip.addClass('in') + + // check to see if placing tip in new offset caused the tip to resize itself + var actualWidth = $tip[0].offsetWidth + var actualHeight = $tip[0].offsetHeight + + if (placement == 'top' && actualHeight != height) { + offset.top = offset.top + height - actualHeight + } + + var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight) + + if (delta.left) offset.left += delta.left + else offset.top += delta.top - // check to see if placing tip in new offset caused the tip to resize itself - var actualWidth = $tip[0].offsetWidth - var actualHeight = $tip[0].offsetHeight + var isVertical = /top|bottom/.test(placement) + var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight + var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight' + + $tip.offset(offset) + this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical) + } - if (placement == 'top' && actualHeight != height) { - offset.top = offset.top + height - actualHeight + Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) { + this.arrow() + .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%') + .css(isVertical ? 'top' : 'left', '') } - var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight) + Tooltip.prototype.setContent = function () { + var $tip = this.tip() + var title = this.getTitle() - if (delta.left) offset.left += delta.left - else offset.top += delta.top + $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) + $tip.removeClass('fade in top bottom left right') + } - var isVertical = /top|bottom/.test(placement) - var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight - var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight' + Tooltip.prototype.hide = function (callback) { + var that = this + var $tip = $(this.$tip) + var e = $.Event('hide.bs.' + this.type) + + function complete() { + if (that.hoverState != 'in') $tip.detach() + if (that.$element) { // TODO: Check whether guarding this code with this `if` is really necessary. + that.$element + .removeAttr('aria-describedby') + .trigger('hidden.bs.' + that.type) + } + callback && callback() + } - $tip.offset(offset) - this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical) - } + this.$element.trigger(e) - Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) { - this.arrow() - .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%') - .css(isVertical ? 'top' : 'left', '') - } + if (e.isDefaultPrevented()) return - Tooltip.prototype.setContent = function () { - var $tip = this.tip() - var title = this.getTitle() + $tip.removeClass('in') - $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) - $tip.removeClass('fade in top bottom left right') - } + $.support.transition && $tip.hasClass('fade') ? + $tip + .one('bsTransitionEnd', complete) + .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : + complete() - Tooltip.prototype.hide = function (callback) { - var that = this - var $tip = $(this.$tip) - var e = $.Event('hide.bs.' + this.type) + this.hoverState = null - function complete() { - if (that.hoverState != 'in') $tip.detach() - if (that.$element) { // TODO: Check whether guarding this code with this `if` is really necessary. - that.$element - .removeAttr('aria-describedby') - .trigger('hidden.bs.' + that.type) - } - callback && callback() + return this } - this.$element.trigger(e) + Tooltip.prototype.fixTitle = function () { + var $e = this.$element + if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') { + $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') + } + } - if (e.isDefaultPrevented()) return + Tooltip.prototype.hasContent = function () { + return this.getTitle() + } - $tip.removeClass('in') + Tooltip.prototype.getPosition = function ($element) { + $element = $element || this.$element - $.support.transition && $tip.hasClass('fade') ? - $tip - .one('bsTransitionEnd', complete) - .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : - complete() + var el = $element[0] + var isBody = el.tagName == 'BODY' - this.hoverState = null + var elRect = el.getBoundingClientRect() + if (elRect.width == null) { + // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093 + elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top }) + } + var isSvg = window.SVGElement && el instanceof window.SVGElement + // Avoid using $.offset() on SVGs since it gives incorrect results in jQuery 3. + // See https://github.com/twbs/bootstrap/issues/20280 + var elOffset = isBody ? { top: 0, left: 0 } : (isSvg ? null : $element.offset()) + var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() } + var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null + + return $.extend({}, elRect, scroll, outerDims, elOffset) + } - return this - } + Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { + return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : + /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } - Tooltip.prototype.fixTitle = function () { - var $e = this.$element - if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') { - $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') } - } - Tooltip.prototype.hasContent = function () { - return this.getTitle() - } + Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { + var delta = { top: 0, left: 0 } + if (!this.$viewport) return delta + + var viewportPadding = this.options.viewport && this.options.viewport.padding || 0 + var viewportDimensions = this.getPosition(this.$viewport) + + if (/right|left/.test(placement)) { + var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll + var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight + if (topEdgeOffset < viewportDimensions.top) { // top overflow + delta.top = viewportDimensions.top - topEdgeOffset + } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow + delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset + } + } else { + var leftEdgeOffset = pos.left - viewportPadding + var rightEdgeOffset = pos.left + viewportPadding + actualWidth + if (leftEdgeOffset < viewportDimensions.left) { // left overflow + delta.left = viewportDimensions.left - leftEdgeOffset + } else if (rightEdgeOffset > viewportDimensions.right) { // right overflow + delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset + } + } + + return delta + } - Tooltip.prototype.getPosition = function ($element) { - $element = $element || this.$element + Tooltip.prototype.getTitle = function () { + var title + var $e = this.$element + var o = this.options - var el = $element[0] - var isBody = el.tagName == 'BODY' - - var elRect = el.getBoundingClientRect() - if (elRect.width == null) { - // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093 - elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top }) + title = $e.attr('data-original-title') + || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) + + return title } - var isSvg = window.SVGElement && el instanceof window.SVGElement - // Avoid using $.offset() on SVGs since it gives incorrect results in jQuery 3. - // See https://github.com/twbs/bootstrap/issues/20280 - var elOffset = isBody ? { top: 0, left: 0 } : (isSvg ? null : $element.offset()) - var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() } - var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null - - return $.extend({}, elRect, scroll, outerDims, elOffset) - } - - Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { - return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : - placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : - placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : - /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } - - } - - Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { - var delta = { top: 0, left: 0 } - if (!this.$viewport) return delta - - var viewportPadding = this.options.viewport && this.options.viewport.padding || 0 - var viewportDimensions = this.getPosition(this.$viewport) - - if (/right|left/.test(placement)) { - var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll - var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight - if (topEdgeOffset < viewportDimensions.top) { // top overflow - delta.top = viewportDimensions.top - topEdgeOffset - } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow - delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset - } - } else { - var leftEdgeOffset = pos.left - viewportPadding - var rightEdgeOffset = pos.left + viewportPadding + actualWidth - if (leftEdgeOffset < viewportDimensions.left) { // left overflow - delta.left = viewportDimensions.left - leftEdgeOffset - } else if (rightEdgeOffset > viewportDimensions.right) { // right overflow - delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset - } - } - - return delta - } - - Tooltip.prototype.getTitle = function () { - var title - var $e = this.$element - var o = this.options - - title = $e.attr('data-original-title') - || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) - - return title - } - - Tooltip.prototype.getUID = function (prefix) { - do prefix += ~~(Math.random() * 1000000) - while (document.getElementById(prefix)) - return prefix - } - - Tooltip.prototype.tip = function () { - if (!this.$tip) { - this.$tip = $(this.options.template) - if (this.$tip.length != 1) { - throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!') - } - } - return this.$tip - } - - Tooltip.prototype.arrow = function () { - return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) - } - - Tooltip.prototype.enable = function () { - this.enabled = true - } - - Tooltip.prototype.disable = function () { - this.enabled = false - } - - Tooltip.prototype.toggleEnabled = function () { - this.enabled = !this.enabled - } - - Tooltip.prototype.toggle = function (e) { - var self = this - if (e) { - self = $(e.currentTarget).data('bs.' + this.type) - if (!self) { - self = new this.constructor(e.currentTarget, this.getDelegateOptions()) - $(e.currentTarget).data('bs.' + this.type, self) - } - } - - if (e) { - self.inState.click = !self.inState.click - if (self.isInStateTrue()) self.enter(self) - else self.leave(self) - } else { - self.tip().hasClass('in') ? self.leave(self) : self.enter(self) - } - } - - Tooltip.prototype.destroy = function () { - var that = this - clearTimeout(this.timeout) - this.hide(function () { - that.$element.off('.' + that.type).removeData('bs.' + that.type) - if (that.$tip) { - that.$tip.detach() - } - that.$tip = null - that.$arrow = null - that.$viewport = null - that.$element = null - }) - } + Tooltip.prototype.getUID = function (prefix) { + do prefix += ~~(Math.random() * 1000000) + while (document.getElementById(prefix)) + return prefix + } - // TOOLTIP PLUGIN DEFINITION - // ========================= + Tooltip.prototype.tip = function () { + if (!this.$tip) { + this.$tip = $(this.options.template) + if (this.$tip.length != 1) { + throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!') + } + } + return this.$tip + } - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.tooltip') - var options = typeof option == 'object' && option + Tooltip.prototype.arrow = function () { + return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) + } - if (!data && /destroy|hide/.test(option)) return - if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) - if (typeof option == 'string') data[option]() - }) - } + Tooltip.prototype.enable = function () { + this.enabled = true + } + + Tooltip.prototype.disable = function () { + this.enabled = false + } + + Tooltip.prototype.toggleEnabled = function () { + this.enabled = !this.enabled + } + + Tooltip.prototype.toggle = function (e) { + var self = this + if (e) { + self = $(e.currentTarget).data('bs.' + this.type) + if (!self) { + self = new this.constructor(e.currentTarget, this.getDelegateOptions()) + $(e.currentTarget).data('bs.' + this.type, self) + } + } - var old = $.fn.tooltip + if (e) { + self.inState.click = !self.inState.click + if (self.isInStateTrue()) self.enter(self) + else self.leave(self) + } else { + self.tip().hasClass('in') ? self.leave(self) : self.enter(self) + } + } - $.fn.tooltip = Plugin - $.fn.tooltip.Constructor = Tooltip + Tooltip.prototype.destroy = function () { + var that = this + clearTimeout(this.timeout) + this.hide(function () { + that.$element.off('.' + that.type).removeData('bs.' + that.type) + if (that.$tip) { + that.$tip.detach() + } + that.$tip = null + that.$arrow = null + that.$viewport = null + that.$element = null + }) + } - // TOOLTIP NO CONFLICT - // =================== + // TOOLTIP PLUGIN DEFINITION + // ========================= + + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.tooltip') + var options = typeof option == 'object' && option + + if (!data && /destroy|hide/.test(option)) return + if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) + if (typeof option == 'string') data[option]() + }) + } - $.fn.tooltip.noConflict = function () { - $.fn.tooltip = old - return this - } + var old = $.fn.tooltip + + $.fn.tooltip = Plugin + $.fn.tooltip.Constructor = Tooltip + + + // TOOLTIP NO CONFLICT + // =================== + + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old + return this + } }(jQuery); @@ -1785,102 +1785,102 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // POPOVER PUBLIC CLASS DEFINITION - // =============================== + // POPOVER PUBLIC CLASS DEFINITION + // =============================== - var Popover = function (element, options) { - this.init('popover', element, options) - } + var Popover = function (element, options) { + this.init('popover', element, options) + } - if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js') + if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js') - Popover.VERSION = '3.3.7' + Popover.VERSION = '3.3.7' - Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, { - placement: 'right', - trigger: 'click', - content: '', - template: '' - }) + Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, { + placement: 'right', + trigger: 'click', + content: '', + template: '' + }) - // NOTE: POPOVER EXTENDS tooltip.js - // ================================ + // NOTE: POPOVER EXTENDS tooltip.js + // ================================ - Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype) + Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype) - Popover.prototype.constructor = Popover + Popover.prototype.constructor = Popover - Popover.prototype.getDefaults = function () { - return Popover.DEFAULTS - } + Popover.prototype.getDefaults = function () { + return Popover.DEFAULTS + } - Popover.prototype.setContent = function () { - var $tip = this.tip() - var title = this.getTitle() - var content = this.getContent() + Popover.prototype.setContent = function () { + var $tip = this.tip() + var title = this.getTitle() + var content = this.getContent() - $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) - $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events - this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text' - ](content) + $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) + $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events + this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text' + ](content) - $tip.removeClass('fade top bottom left right in') + $tip.removeClass('fade top bottom left right in') - // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do - // this manually by checking the contents. - if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide() - } + // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do + // this manually by checking the contents. + if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide() + } - Popover.prototype.hasContent = function () { - return this.getTitle() || this.getContent() - } + Popover.prototype.hasContent = function () { + return this.getTitle() || this.getContent() + } - Popover.prototype.getContent = function () { - var $e = this.$element - var o = this.options + Popover.prototype.getContent = function () { + var $e = this.$element + var o = this.options - return $e.attr('data-content') - || (typeof o.content == 'function' ? - o.content.call($e[0]) : - o.content) - } + return $e.attr('data-content') + || (typeof o.content == 'function' ? + o.content.call($e[0]) : + o.content) + } - Popover.prototype.arrow = function () { - return (this.$arrow = this.$arrow || this.tip().find('.arrow')) - } + Popover.prototype.arrow = function () { + return (this.$arrow = this.$arrow || this.tip().find('.arrow')) + } - // POPOVER PLUGIN DEFINITION - // ========================= + // POPOVER PLUGIN DEFINITION + // ========================= - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.popover') - var options = typeof option == 'object' && option + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.popover') + var options = typeof option == 'object' && option - if (!data && /destroy|hide/.test(option)) return - if (!data) $this.data('bs.popover', (data = new Popover(this, options))) - if (typeof option == 'string') data[option]() - }) - } + if (!data && /destroy|hide/.test(option)) return + if (!data) $this.data('bs.popover', (data = new Popover(this, options))) + if (typeof option == 'string') data[option]() + }) + } - var old = $.fn.popover + var old = $.fn.popover - $.fn.popover = Plugin - $.fn.popover.Constructor = Popover + $.fn.popover = Plugin + $.fn.popover.Constructor = Popover - // POPOVER NO CONFLICT - // =================== + // POPOVER NO CONFLICT + // =================== - $.fn.popover.noConflict = function () { - $.fn.popover = old - return this - } + $.fn.popover.noConflict = function () { + $.fn.popover = old + return this + } }(jQuery); @@ -1894,166 +1894,166 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; + + // SCROLLSPY CLASS DEFINITION + // ========================== + + function ScrollSpy(element, options) { + this.$body = $(document.body) + this.$scrollElement = $(element).is(document.body) ? $(window) : $(element) + this.options = $.extend({}, ScrollSpy.DEFAULTS, options) + this.selector = (this.options.target || '') + ' .nav li > a' + this.offsets = [] + this.targets = [] + this.activeTarget = null + this.scrollHeight = 0 + + this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this)) + this.refresh() + this.process() + } - // SCROLLSPY CLASS DEFINITION - // ========================== - - function ScrollSpy(element, options) { - this.$body = $(document.body) - this.$scrollElement = $(element).is(document.body) ? $(window) : $(element) - this.options = $.extend({}, ScrollSpy.DEFAULTS, options) - this.selector = (this.options.target || '') + ' .nav li > a' - this.offsets = [] - this.targets = [] - this.activeTarget = null - this.scrollHeight = 0 + ScrollSpy.VERSION = '3.3.7' - this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this)) - this.refresh() - this.process() - } - - ScrollSpy.VERSION = '3.3.7' + ScrollSpy.DEFAULTS = { + offset: 10 + } - ScrollSpy.DEFAULTS = { - offset: 10 - } + ScrollSpy.prototype.getScrollHeight = function () { + return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) + } - ScrollSpy.prototype.getScrollHeight = function () { - return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) - } + ScrollSpy.prototype.refresh = function () { + var that = this + var offsetMethod = 'offset' + var offsetBase = 0 - ScrollSpy.prototype.refresh = function () { - var that = this - var offsetMethod = 'offset' - var offsetBase = 0 + this.offsets = [] + this.targets = [] + this.scrollHeight = this.getScrollHeight() - this.offsets = [] - this.targets = [] - this.scrollHeight = this.getScrollHeight() + if (!$.isWindow(this.$scrollElement[0])) { + offsetMethod = 'position' + offsetBase = this.$scrollElement.scrollTop() + } - if (!$.isWindow(this.$scrollElement[0])) { - offsetMethod = 'position' - offsetBase = this.$scrollElement.scrollTop() + this.$body + .find(this.selector) + .map(function () { + var $el = $(this) + var href = $el.data('target') || $el.attr('href') + var $href = /^#./.test(href) && $(href) + + return ($href + && $href.length + && $href.is(':visible') + && [[$href[offsetMethod]().top + offsetBase, href]]) || null + }) + .sort(function (a, b) { return a[0] - b[0] }) + .each(function () { + that.offsets.push(this[0]) + that.targets.push(this[1]) + }) } - this.$body - .find(this.selector) - .map(function () { - var $el = $(this) - var href = $el.data('target') || $el.attr('href') - var $href = /^#./.test(href) && $(href) - - return ($href - && $href.length - && $href.is(':visible') - && [[$href[offsetMethod]().top + offsetBase, href]]) || null - }) - .sort(function (a, b) { return a[0] - b[0] }) - .each(function () { - that.offsets.push(this[0]) - that.targets.push(this[1]) - }) - } + ScrollSpy.prototype.process = function () { + var scrollTop = this.$scrollElement.scrollTop() + this.options.offset + var scrollHeight = this.getScrollHeight() + var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height() + var offsets = this.offsets + var targets = this.targets + var activeTarget = this.activeTarget + var i + + if (this.scrollHeight != scrollHeight) { + this.refresh() + } - ScrollSpy.prototype.process = function () { - var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - var scrollHeight = this.getScrollHeight() - var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height() - var offsets = this.offsets - var targets = this.targets - var activeTarget = this.activeTarget - var i + if (scrollTop >= maxScroll) { + return activeTarget != (i = targets[targets.length - 1]) && this.activate(i) + } - if (this.scrollHeight != scrollHeight) { - this.refresh() - } + if (activeTarget && scrollTop < offsets[0]) { + this.activeTarget = null + return this.clear() + } - if (scrollTop >= maxScroll) { - return activeTarget != (i = targets[targets.length - 1]) && this.activate(i) + for (i = offsets.length; i--;) { + activeTarget != targets[i] + && scrollTop >= offsets[i] + && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1]) + && this.activate(targets[i]) + } } - if (activeTarget && scrollTop < offsets[0]) { - this.activeTarget = null - return this.clear() - } + ScrollSpy.prototype.activate = function (target) { + this.activeTarget = target - for (i = offsets.length; i--;) { - activeTarget != targets[i] - && scrollTop >= offsets[i] - && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1]) - && this.activate(targets[i]) - } - } + this.clear() - ScrollSpy.prototype.activate = function (target) { - this.activeTarget = target + var selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' - this.clear() + var active = $(selector) + .parents('li') + .addClass('active') - var selector = this.selector + - '[data-target="' + target + '"],' + - this.selector + '[href="' + target + '"]' + if (active.parent('.dropdown-menu').length) { + active = active + .closest('li.dropdown') + .addClass('active') + } - var active = $(selector) - .parents('li') - .addClass('active') - - if (active.parent('.dropdown-menu').length) { - active = active - .closest('li.dropdown') - .addClass('active') + active.trigger('activate.bs.scrollspy') } - active.trigger('activate.bs.scrollspy') - } - - ScrollSpy.prototype.clear = function () { - $(this.selector) - .parentsUntil(this.options.target, '.active') - .removeClass('active') - } + ScrollSpy.prototype.clear = function () { + $(this.selector) + .parentsUntil(this.options.target, '.active') + .removeClass('active') + } - // SCROLLSPY PLUGIN DEFINITION - // =========================== + // SCROLLSPY PLUGIN DEFINITION + // =========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.scrollspy') - var options = typeof option == 'object' && option + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.scrollspy') + var options = typeof option == 'object' && option - if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) - if (typeof option == 'string') data[option]() - }) - } + if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) + if (typeof option == 'string') data[option]() + }) + } - var old = $.fn.scrollspy + var old = $.fn.scrollspy - $.fn.scrollspy = Plugin - $.fn.scrollspy.Constructor = ScrollSpy + $.fn.scrollspy = Plugin + $.fn.scrollspy.Constructor = ScrollSpy - // SCROLLSPY NO CONFLICT - // ===================== + // SCROLLSPY NO CONFLICT + // ===================== - $.fn.scrollspy.noConflict = function () { - $.fn.scrollspy = old - return this - } + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } - // SCROLLSPY DATA-API - // ================== + // SCROLLSPY DATA-API + // ================== - $(window).on('load.bs.scrollspy.data-api', function () { - $('[data-spy="scroll"]').each(function () { - var $spy = $(this) - Plugin.call($spy, $spy.data()) + $(window).on('load.bs.scrollspy.data-api', function () { + $('[data-spy="scroll"]').each(function () { + var $spy = $(this) + Plugin.call($spy, $spy.data()) + }) }) - }) }(jQuery); @@ -2067,149 +2067,149 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // TAB CLASS DEFINITION - // ==================== + // TAB CLASS DEFINITION + // ==================== - var Tab = function (element) { - // jscs:disable requireDollarBeforejQueryAssignment - this.element = $(element) - // jscs:enable requireDollarBeforejQueryAssignment - } + var Tab = function (element) { + // jscs:disable requireDollarBeforejQueryAssignment + this.element = $(element) + // jscs:enable requireDollarBeforejQueryAssignment + } - Tab.VERSION = '3.3.7' + Tab.VERSION = '3.3.7' - Tab.TRANSITION_DURATION = 150 + Tab.TRANSITION_DURATION = 150 - Tab.prototype.show = function () { - var $this = this.element - var $ul = $this.closest('ul:not(.dropdown-menu)') - var selector = $this.data('target') + Tab.prototype.show = function () { + var $this = this.element + var $ul = $this.closest('ul:not(.dropdown-menu)') + var selector = $this.data('target') - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } - if ($this.parent('li').hasClass('active')) return + if ($this.parent('li').hasClass('active')) return - var $previous = $ul.find('.active:last a') - var hideEvent = $.Event('hide.bs.tab', { - relatedTarget: $this[0] - }) - var showEvent = $.Event('show.bs.tab', { - relatedTarget: $previous[0] - }) + var $previous = $ul.find('.active:last a') + var hideEvent = $.Event('hide.bs.tab', { + relatedTarget: $this[0] + }) + var showEvent = $.Event('show.bs.tab', { + relatedTarget: $previous[0] + }) - $previous.trigger(hideEvent) - $this.trigger(showEvent) + $previous.trigger(hideEvent) + $this.trigger(showEvent) - if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return + if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return - var $target = $(selector) + var $target = $(selector) - this.activate($this.closest('li'), $ul) - this.activate($target, $target.parent(), function () { - $previous.trigger({ - type: 'hidden.bs.tab', - relatedTarget: $this[0] - }) - $this.trigger({ - type: 'shown.bs.tab', - relatedTarget: $previous[0] - }) - }) - } - - Tab.prototype.activate = function (element, container, callback) { - var $active = container.find('> .active') - var transition = callback - && $.support.transition - && ($active.length && $active.hasClass('fade') || !!container.find('> .fade').length) - - function next() { - $active - .removeClass('active') - .find('> .dropdown-menu > .active') - .removeClass('active') - .end() - .find('[data-toggle="tab"]') - .attr('aria-expanded', false) - - element - .addClass('active') - .find('[data-toggle="tab"]') - .attr('aria-expanded', true) - - if (transition) { - element[0].offsetWidth // reflow for transition - element.addClass('in') - } else { - element.removeClass('fade') - } - - if (element.parent('.dropdown-menu').length) { - element - .closest('li.dropdown') - .addClass('active') - .end() - .find('[data-toggle="tab"]') - .attr('aria-expanded', true) - } - - callback && callback() + this.activate($this.closest('li'), $ul) + this.activate($target, $target.parent(), function () { + $previous.trigger({ + type: 'hidden.bs.tab', + relatedTarget: $this[0] + }) + $this.trigger({ + type: 'shown.bs.tab', + relatedTarget: $previous[0] + }) + }) } - $active.length && transition ? - $active - .one('bsTransitionEnd', next) - .emulateTransitionEnd(Tab.TRANSITION_DURATION) : - next() + Tab.prototype.activate = function (element, container, callback) { + var $active = container.find('> .active') + var transition = callback + && $.support.transition + && ($active.length && $active.hasClass('fade') || !!container.find('> .fade').length) + + function next() { + $active + .removeClass('active') + .find('> .dropdown-menu > .active') + .removeClass('active') + .end() + .find('[data-toggle="tab"]') + .attr('aria-expanded', false) + + element + .addClass('active') + .find('[data-toggle="tab"]') + .attr('aria-expanded', true) + + if (transition) { + element[0].offsetWidth // reflow for transition + element.addClass('in') + } else { + element.removeClass('fade') + } + + if (element.parent('.dropdown-menu').length) { + element + .closest('li.dropdown') + .addClass('active') + .end() + .find('[data-toggle="tab"]') + .attr('aria-expanded', true) + } + + callback && callback() + } - $active.removeClass('in') - } + $active.length && transition ? + $active + .one('bsTransitionEnd', next) + .emulateTransitionEnd(Tab.TRANSITION_DURATION) : + next() + $active.removeClass('in') + } - // TAB PLUGIN DEFINITION - // ===================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.tab') + // TAB PLUGIN DEFINITION + // ===================== - if (!data) $this.data('bs.tab', (data = new Tab(this))) - if (typeof option == 'string') data[option]() - }) - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.tab') - var old = $.fn.tab + if (!data) $this.data('bs.tab', (data = new Tab(this))) + if (typeof option == 'string') data[option]() + }) + } - $.fn.tab = Plugin - $.fn.tab.Constructor = Tab + var old = $.fn.tab + $.fn.tab = Plugin + $.fn.tab.Constructor = Tab - // TAB NO CONFLICT - // =============== - $.fn.tab.noConflict = function () { - $.fn.tab = old - return this - } + // TAB NO CONFLICT + // =============== + $.fn.tab.noConflict = function () { + $.fn.tab = old + return this + } - // TAB DATA-API - // ============ - var clickHandler = function (e) { - e.preventDefault() - Plugin.call($(this), 'show') - } + // TAB DATA-API + // ============ - $(document) - .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler) - .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler) + var clickHandler = function (e) { + e.preventDefault() + Plugin.call($(this), 'show') + } + + $(document) + .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler) + .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler) }(jQuery); @@ -2223,155 +2223,155 @@ if (typeof jQuery === 'undefined') { +function ($) { - 'use strict'; + 'use strict'; - // AFFIX CLASS DEFINITION - // ====================== + // AFFIX CLASS DEFINITION + // ====================== - var Affix = function (element, options) { - this.options = $.extend({}, Affix.DEFAULTS, options) + var Affix = function (element, options) { + this.options = $.extend({}, Affix.DEFAULTS, options) - this.$target = $(this.options.target) - .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) - .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) + this.$target = $(this.options.target) + .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) + .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) - this.$element = $(element) - this.affixed = null - this.unpin = null - this.pinnedOffset = null + this.$element = $(element) + this.affixed = null + this.unpin = null + this.pinnedOffset = null - this.checkPosition() - } + this.checkPosition() + } - Affix.VERSION = '3.3.7' + Affix.VERSION = '3.3.7' - Affix.RESET = 'affix affix-top affix-bottom' + Affix.RESET = 'affix affix-top affix-bottom' - Affix.DEFAULTS = { - offset: 0, - target: window - } + Affix.DEFAULTS = { + offset: 0, + target: window + } - Affix.prototype.getState = function (scrollHeight, height, offsetTop, offsetBottom) { - var scrollTop = this.$target.scrollTop() - var position = this.$element.offset() - var targetHeight = this.$target.height() + Affix.prototype.getState = function (scrollHeight, height, offsetTop, offsetBottom) { + var scrollTop = this.$target.scrollTop() + var position = this.$element.offset() + var targetHeight = this.$target.height() - if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false + if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false - if (this.affixed == 'bottom') { - if (offsetTop != null) return (scrollTop + this.unpin <= position.top) ? false : 'bottom' - return (scrollTop + targetHeight <= scrollHeight - offsetBottom) ? false : 'bottom' - } + if (this.affixed == 'bottom') { + if (offsetTop != null) return (scrollTop + this.unpin <= position.top) ? false : 'bottom' + return (scrollTop + targetHeight <= scrollHeight - offsetBottom) ? false : 'bottom' + } - var initializing = this.affixed == null - var colliderTop = initializing ? scrollTop : position.top - var colliderHeight = initializing ? targetHeight : height + var initializing = this.affixed == null + var colliderTop = initializing ? scrollTop : position.top + var colliderHeight = initializing ? targetHeight : height - if (offsetTop != null && scrollTop <= offsetTop) return 'top' - if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom' + if (offsetTop != null && scrollTop <= offsetTop) return 'top' + if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom' - return false - } + return false + } - Affix.prototype.getPinnedOffset = function () { - if (this.pinnedOffset) return this.pinnedOffset - this.$element.removeClass(Affix.RESET).addClass('affix') - var scrollTop = this.$target.scrollTop() - var position = this.$element.offset() - return (this.pinnedOffset = position.top - scrollTop) - } + Affix.prototype.getPinnedOffset = function () { + if (this.pinnedOffset) return this.pinnedOffset + this.$element.removeClass(Affix.RESET).addClass('affix') + var scrollTop = this.$target.scrollTop() + var position = this.$element.offset() + return (this.pinnedOffset = position.top - scrollTop) + } - Affix.prototype.checkPositionWithEventLoop = function () { - setTimeout($.proxy(this.checkPosition, this), 1) - } + Affix.prototype.checkPositionWithEventLoop = function () { + setTimeout($.proxy(this.checkPosition, this), 1) + } - Affix.prototype.checkPosition = function () { - if (!this.$element.is(':visible')) return + Affix.prototype.checkPosition = function () { + if (!this.$element.is(':visible')) return - var height = this.$element.height() - var offset = this.options.offset - var offsetTop = offset.top - var offsetBottom = offset.bottom - var scrollHeight = Math.max($(document).height(), $(document.body).height()) + var height = this.$element.height() + var offset = this.options.offset + var offsetTop = offset.top + var offsetBottom = offset.bottom + var scrollHeight = Math.max($(document).height(), $(document.body).height()) - if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element) + if (typeof offset != 'object') offsetBottom = offsetTop = offset + if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) + if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element) - var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom) + var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom) - if (this.affixed != affix) { - if (this.unpin != null) this.$element.css('top', '') + if (this.affixed != affix) { + if (this.unpin != null) this.$element.css('top', '') - var affixType = 'affix' + (affix ? '-' + affix : '') - var e = $.Event(affixType + '.bs.affix') + var affixType = 'affix' + (affix ? '-' + affix : '') + var e = $.Event(affixType + '.bs.affix') - this.$element.trigger(e) + this.$element.trigger(e) - if (e.isDefaultPrevented()) return + if (e.isDefaultPrevented()) return - this.affixed = affix - this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null + this.affixed = affix + this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null - this.$element - .removeClass(Affix.RESET) - .addClass(affixType) - .trigger(affixType.replace('affix', 'affixed') + '.bs.affix') - } + this.$element + .removeClass(Affix.RESET) + .addClass(affixType) + .trigger(affixType.replace('affix', 'affixed') + '.bs.affix') + } - if (affix == 'bottom') { - this.$element.offset({ - top: scrollHeight - height - offsetBottom - }) + if (affix == 'bottom') { + this.$element.offset({ + top: scrollHeight - height - offsetBottom + }) + } } - } - // AFFIX PLUGIN DEFINITION - // ======================= + // AFFIX PLUGIN DEFINITION + // ======================= - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.affix') - var options = typeof option == 'object' && option + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.affix') + var options = typeof option == 'object' && option - if (!data) $this.data('bs.affix', (data = new Affix(this, options))) - if (typeof option == 'string') data[option]() - }) - } + if (!data) $this.data('bs.affix', (data = new Affix(this, options))) + if (typeof option == 'string') data[option]() + }) + } - var old = $.fn.affix + var old = $.fn.affix - $.fn.affix = Plugin - $.fn.affix.Constructor = Affix + $.fn.affix = Plugin + $.fn.affix.Constructor = Affix - // AFFIX NO CONFLICT - // ================= + // AFFIX NO CONFLICT + // ================= - $.fn.affix.noConflict = function () { - $.fn.affix = old - return this - } + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } - // AFFIX DATA-API - // ============== + // AFFIX DATA-API + // ============== - $(window).on('load', function () { - $('[data-spy="affix"]').each(function () { - var $spy = $(this) - var data = $spy.data() + $(window).on('load', function () { + $('[data-spy="affix"]').each(function () { + var $spy = $(this) + var data = $spy.data() - data.offset = data.offset || {} + data.offset = data.offset || {} - if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom - if (data.offsetTop != null) data.offset.top = data.offsetTop + if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom + if (data.offsetTop != null) data.offset.top = data.offsetTop - Plugin.call($spy, data) + Plugin.call($spy, data) + }) }) - }) }(jQuery);