From ad3cef619563b263e12b96e39b565859d71a1b17 Mon Sep 17 00:00:00 2001 From: guy Date: Sun, 14 May 2017 11:46:17 +0800 Subject: [PATCH] =?UTF-8?q?polyfill=E7=A7=BB=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gruntfile.js | 43 +-- bi/core.js | 322 +----------------- docs/core.js | 322 +----------------- docs/index.html | 1 + src/core/proto/array.js | 259 +------------- src/core/proto/cache.js | 20 -- src/polyfill/array.js | 31 ++ src/polyfill/console.js | 12 + src/polyfill/localStorage.js | 21 ++ .../proto/special.js => polyfill/sort.js} | 14 - 10 files changed, 95 insertions(+), 950 deletions(-) create mode 100644 src/polyfill/array.js create mode 100644 src/polyfill/console.js create mode 100644 src/polyfill/localStorage.js rename src/{core/proto/special.js => polyfill/sort.js} (75%) diff --git a/Gruntfile.js b/Gruntfile.js index 664716e7a..ce4ad486c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,6 +7,10 @@ module.exports = function (grunt) { options: { separator: '' }, + polyfillJs: { + src: ['src/polyfill/**/*.js'], + dest: 'docs/polyfill.js' + }, coreJs: { src: [ 'src/core/jquery.js', @@ -30,41 +34,7 @@ module.exports = function (grunt) { ], dest: 'docs/core.js' }, - biCoreJs: { - src: [ - 'src/core/underscore.js', - 'src/core/foundation.js', - 'src/core/mvc/**/*.js', - 'src/core/base.js', - 'src/core/alias.js', - 'src/core/events.js', - 'src/core/var.js', - 'src/core/ob.js', - 'src/core/widget.js', - 'src/core/model.js', - 'src/core/view.js', - 'src/core/shortcut.js', - 'src/core/plugin.js', - 'src/core/controller.js', - 'src/core/proto/**/*.js', - 'src/core/utils/**/*.js', - 'src/core/behavior/behavior.js', - 'src/core/wrapper/layout.js', - 'src/core/action/**/*.js', - 'src/core/adapter/**/*.js', - 'src/core/controller/**/*.js', - 'src/core/event/**/*.js', - 'src/core/func/**/*.js', - 'src/core/listener/**/*.js', - 'src/core/loader/**/*.js', - 'src/core/logic/**/*.js', - 'src/data/data.js', - 'src/data/**/*.js', - 'src/config.js' - ], - dest: 'bi/core.js' - }, //最基础的控件 baseJs: { src: [ @@ -137,6 +107,11 @@ module.exports = function (grunt) { dest: 'docs/demo.css' }, + bi_polyfillJs: { + src: ['src/polyfill/**/*.js'], + dest: 'bi/polyfill.js' + }, + bi_coreJs: { src: [ 'src/core/foundation.js', diff --git a/bi/core.js b/bi/core.js index 5de694e03..95228d4cf 100644 --- a/bi/core.js +++ b/bi/core.js @@ -5843,34 +5843,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -5879,265 +5851,29 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); - } -});/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - - }, - clear: function () { - this.items = {}; } }); + BI.Cache = { _prefix: "bi", setUsername: function (username) { @@ -7094,50 +6830,6 @@ function accDiv(arg1, arg2) { Number.prototype.div = function (arg) { return accDiv(this, arg); };/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - -//修复ie9下sort方法的bug -!function (window) { - var ua = window.navigator.userAgent.toLowerCase(), - reg = /msie|applewebkit.+safari/; - if (reg.test(ua)) { - var _sort = Array.prototype.sort; - Array.prototype.sort = function (fn) { - if (!!fn && typeof fn === 'function') { - if (this.length < 2) { - return this; - } - var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; - for (; i < l; i++) { - for (j = i + 1; j < l; j++) { - t = fn.call(this, this[i], this[j]); - r = (typeof t === 'number' ? t : - !!t ? 1 : 0) > 0; - if (r === true) { - tmp = this[i]; - this[i] = this[j]; - this[j] = tmp; - } - } - } - return this; - } else { - return _sort.call(this); - } - }; - } -}(window);/** * 对字符串对象的扩展 * @class String */ diff --git a/docs/core.js b/docs/core.js index 49809986e..39cd1299f 100644 --- a/docs/core.js +++ b/docs/core.js @@ -23326,34 +23326,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -23362,265 +23334,29 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); - } -});/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - - }, - clear: function () { - this.items = {}; } }); + BI.Cache = { _prefix: "bi", setUsername: function (username) { @@ -24577,50 +24313,6 @@ function accDiv(arg1, arg2) { Number.prototype.div = function (arg) { return accDiv(this, arg); };/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - -//修复ie9下sort方法的bug -!function (window) { - var ua = window.navigator.userAgent.toLowerCase(), - reg = /msie|applewebkit.+safari/; - if (reg.test(ua)) { - var _sort = Array.prototype.sort; - Array.prototype.sort = function (fn) { - if (!!fn && typeof fn === 'function') { - if (this.length < 2) { - return this; - } - var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; - for (; i < l; i++) { - for (j = i + 1; j < l; j++) { - t = fn.call(this, this[i], this[j]); - r = (typeof t === 'number' ? t : - !!t ? 1 : 0) > 0; - if (r === true) { - tmp = this[i]; - this[i] = this[j]; - this[j] = tmp; - } - } - } - return this; - } else { - return _sort.call(this); - } - }; - } -}(window);/** * 对字符串对象的扩展 * @class String */ diff --git a/docs/index.html b/docs/index.html index c9c8367f8..0db30acc5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,6 +15,7 @@ + diff --git a/src/core/proto/array.js b/src/core/proto/array.js index fc1c3b977..5bf8cc3c3 100644 --- a/src/core/proto/array.js +++ b/src/core/proto/array.js @@ -6,34 +6,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -42,242 +14,25 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); } -}); \ No newline at end of file +}); diff --git a/src/core/proto/cache.js b/src/core/proto/cache.js index b529bfeee..5e0668138 100644 --- a/src/core/proto/cache.js +++ b/src/core/proto/cache.js @@ -1,24 +1,4 @@ -/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - }, - clear: function () { - this.items = {}; - } -}); BI.Cache = { _prefix: "bi", setUsername: function (username) { diff --git a/src/polyfill/array.js b/src/polyfill/array.js new file mode 100644 index 000000000..65f018588 --- /dev/null +++ b/src/polyfill/array.js @@ -0,0 +1,31 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} \ No newline at end of file diff --git a/src/polyfill/console.js b/src/polyfill/console.js new file mode 100644 index 000000000..a1c017c06 --- /dev/null +++ b/src/polyfill/console.js @@ -0,0 +1,12 @@ +/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); diff --git a/src/polyfill/localStorage.js b/src/polyfill/localStorage.js new file mode 100644 index 000000000..12036d743 --- /dev/null +++ b/src/polyfill/localStorage.js @@ -0,0 +1,21 @@ +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +}); \ No newline at end of file diff --git a/src/core/proto/special.js b/src/polyfill/sort.js similarity index 75% rename from src/core/proto/special.js rename to src/polyfill/sort.js index 2ea79ffb8..6ad73ba9c 100644 --- a/src/core/proto/special.js +++ b/src/polyfill/sort.js @@ -1,17 +1,3 @@ -/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - //修复ie9下sort方法的bug !function (window) { var ua = window.navigator.userAgent.toLowerCase(),