浏览代码

修改插件js,新增cache配置

笔下光年 6 年之前
父节点
当前提交
b3b5aee960
共有 2 个文件被更改,包括 16 次插入12 次删除
  1. 4 1
      README.md
  2. 12 11
      js/bootstrap-multitabs/multitabs.js

+ 4 - 1
README.md

@@ -19,7 +19,7 @@
 - 相对于Light Year Admin的项目,去掉了暗黑和半透明的两个主题
 - 所有需要的链接加上`class="multitabs"`
 - 因为插件做了一些修改,在顶部的下拉菜单(dropdown-menu)中,不要把链接写在href里面,放到data-url里
-- 插件用到了HTML5的会话存储,因此在修改了init里的默认地址后,可以再浏览器控制台执行下sessionStorage.clear();
+- 插件用到了HTML5的会话存储,因此在修改了init里的默认地址后,可以再浏览器控制台执行下sessionStorage.clear(); // cache配置为true时
 
 #### 特别感谢
 - Bootstrap(去掉了自带的字体图标)
@@ -37,6 +37,9 @@
 - Bootstrap-Multitabs
 
 ### 更新记录
+2019.05.05
+修改Bootstrap-Multitabs插件js,新增缓存配置cache,默认为false,如果需要缓存,可以在index.min.js增加配置cache : true
+
 2019.04.24
 新增文档示例页面增加多图上传样式(只有样式),调整标签插件样式和js的默认提示
 新增步骤条样式和向导插件,修改消息方法(新增自定义消失时间),增加错误页面(404),增加通知消息页面说明,调整设置页样式

+ 12 - 11
js/bootstrap-multitabs/multitabs.js

@@ -59,8 +59,8 @@ if (typeof jQuery === "undefined") {
         return t;
     };
 
-    supportStorage = function () {
-        return !(sessionStorage === undefined);
+    supportStorage = function (is_cache) {
+        return !(sessionStorage === undefined) && is_cache;
     }
 
     /**
@@ -572,12 +572,12 @@ if (typeof jQuery === "undefined") {
                 options = self.options,
                 storage, init = options.init,
                 param;
-            if (supportStorage) {
-                //storage = self._storage();
-                //self._resetStorage({});
-                //$.each(storage, function (k, v) {
-                //    self.create(v, false);
-                //})
+            if (supportStorage(options.cache)) {
+                storage = self._storage();
+                self._resetStorage({});
+                $.each(storage, function (k, v) {
+                    self.create(v, false);
+                })
             }
             if ($.isEmptyObject(storage)) {
                 init = (!$.isEmptyObject(init) && init instanceof Array) ? init : defaultInit;
@@ -786,7 +786,7 @@ if (typeof jQuery === "undefined") {
          * @private
          */
         _storage: function (key, param) {
-            if (supportStorage()) {
+            if (supportStorage(this.options.cache)) {
                 var storage = JSON.parse(sessionStorage.multitabs || '{}');
                 if (!key) {
                     return storage;
@@ -807,7 +807,7 @@ if (typeof jQuery === "undefined") {
          * @private
          */
         _delStorage: function (key) {
-            if (supportStorage()) {
+            if (supportStorage(this.options.cache)) {
                 var storage = JSON.parse(sessionStorage.multitabs || '{}');
                 if (!key) {
                     return storage;
@@ -825,7 +825,7 @@ if (typeof jQuery === "undefined") {
          * @private
          */
         _resetStorage: function (storage) {
-            if (supportStorage() && typeof storage === "object") {
+            if (supportStorage(this.options.cache) && typeof storage === "object") {
                 sessionStorage.multitabs = JSON.stringify(storage);
             }
         },
@@ -1006,6 +1006,7 @@ if (typeof jQuery === "undefined") {
     $.fn.multitabs.defaults = {
         selector: '.multitabs', //selector text to trigger multitabs.
         iframe: false, //Global iframe mode, default is false, is the auto mode (for the self page, use ajax, and the external, use iframe)
+        cache: false,
         class: '', //class for whole multitabs
         type: 'info', //change the info content name, is not necessary to change.
         init: [],