rename init-all-plugin.js into plain plugin.js that has additional features for toggling
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 25 Mar 2013 08:05:59 +0000 (09:05 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 25 Mar 2013 08:05:59 +0000 (09:05 +0100)
expose both jquery.js and jquery.min.js and let the templates explicitly decide

Makefile
third-party/jquery-html5storage/jquery.html5storage.js [new file with mode: 0644]
third-party/jquery-html5storage/jquery.html5storage.min.js [new file with mode: 0644]
third-party/jquery-html5storage/jquery.html5storage.url [new file with mode: 0644]
third-party/jquery/js/jquery.js
third-party/jquery/js/jquery.min.js [new symlink]
unfold/js/init-all-plugins.js [deleted file]
unfold/js/plugin.js [new file with mode: 0644]
views/templates/layout-unfold1.html
views/templates/layout-unfold2.html

index 38fde28..9f56f86 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,9 @@ THIRD-PARTY-RESOURCES += $(shell ls third-party/bootstrap/*/*)
 # just the single js as identified with a symlink
 THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/js/dataTables.js)
 # likewise
-THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery.js)
+THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery{,.min}.js)
+# for storing the visible status of plugins
+THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-html5storage/jquery.html5storage{,.min}.js)
 # used in hazelnut
 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-ui/themes/base/jquery-ui.css)
 # spin comes in plain or min, + the jquery plugin, and our own settings
diff --git a/third-party/jquery-html5storage/jquery.html5storage.js b/third-party/jquery-html5storage/jquery.html5storage.js
new file mode 100644 (file)
index 0000000..e1139f4
--- /dev/null
@@ -0,0 +1,108 @@
+/*!
+* jQuery Plugin to use Local Storage or Session Storage without worrying
+* about HTML5 support. It uses Cookies for backward compatibility.
+*
+* @author Alberto Varela Sánchez (http://www.berriart.com)
+* @version 1.0 (17th January 2013)
+*
+* Released under the MIT License (http://opensource.org/licenses/MIT)
+*
+* Copyright (c) 2013 Alberto Varela Sánchez (alberto@berriart.com)
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
+;(function(window, $ ) {
+    "use strict";
+
+    var types = ['localStorage','sessionStorage'],
+        support = [];
+
+    $.each(types, function( i, type ) {
+        try {
+            support[type] = type in window && window[type] !== null;
+        } catch (e) {
+            support[type] = false;
+        }
+
+        $[type] = {
+            settings : {
+                cookiePrefix : 'html5fallback:' + type + ':',
+                cookieOptions : {
+                    path : '/',
+                    domain : document.domain,
+                    expires : ('localStorage' === type) ? { expires: 365 } : undefined
+                }
+            },
+            
+            getItem : function( key ) {
+                var response;
+                if(support[type]) {
+                    response = window[type].getItem(key);
+                }
+                else {
+                    response = $.cookie(this.settings.cookiePrefix + key);
+                }
+                
+                return response;
+            },
+            
+            setItem : function( key, value ) {
+                if(support[type]) {
+                    return window[type].setItem(key, value);
+                }
+                else {
+                    return $.cookie(this.settings.cookiePrefix + key, value, this.settings.cookieOptions);
+                }
+            },
+
+            removeItem : function( key ) {
+                if(support[type]) {
+                    return window[type].removeItem(key);
+                }
+                else {
+                    var options = $.extend(this.settings.cookieOptions, {
+                        expires: -1
+                    });
+                    return $.cookie(this.settings.cookiePrefix + key, null, options);
+                }
+            },
+
+            clear : function() {
+                if(support[type]) {
+                    return window[type].clear();
+                }
+                else {
+                    var reg = new RegExp('^' + this.settings.cookiePrefix, ''),
+                        options = $.extend(this.settings.cookieOptions, {
+                            expires: -1
+                        });
+
+                    if(document.cookie && document.cookie !== ''){
+                        $.each(document.cookie.split(';'), function( i, cookie ){
+                            if(reg.test(cookie = $.trim(cookie))) {
+                                 $.cookie( cookie.substr(0,cookie.indexOf('=')), null, options);
+                            }
+                        });
+                    }
+                }
+            }
+        };
+    });
+})(window, jQuery);
\ No newline at end of file
diff --git a/third-party/jquery-html5storage/jquery.html5storage.min.js b/third-party/jquery-html5storage/jquery.html5storage.min.js
new file mode 100644 (file)
index 0000000..9f1cc35
--- /dev/null
@@ -0,0 +1,4 @@
+/*! Html5 Storage jQuery Plugin - v1.0 - 2013-01-19
+* https://github.com/artberri/jquery-html5storage
+* Copyright (c) 2013 Alberto Varela; Licensed MIT */
+(function(e,t){"use strict";var n=["localStorage","sessionStorage"],r=[];t.each(n,function(n,i){try{r[i]=i in e&&e[i]!==null}catch(s){r[i]=!1}t[i]={settings:{cookiePrefix:"html5fallback:"+i+":",cookieOptions:{path:"/",domain:document.domain,expires:"localStorage"===i?{expires:365}:undefined}},getItem:function(n){var s;return r[i]?s=e[i].getItem(n):s=t.cookie(this.settings.cookiePrefix+n),s},setItem:function(n,s){return r[i]?e[i].setItem(n,s):t.cookie(this.settings.cookiePrefix+n,s,this.settings.cookieOptions)},removeItem:function(n){if(r[i])return e[i].removeItem(n);var s=t.extend(this.settings.cookieOptions,{expires:-1});return t.cookie(this.settings.cookiePrefix+n,null,s)},clear:function(){if(r[i])return e[i].clear();var n=new RegExp("^"+this.settings.cookiePrefix,""),s=t.extend(this.settings.cookieOptions,{expires:-1});document.cookie&&document.cookie!==""&&t.each(document.cookie.split(";"),function(e,r){n.test(r=t.trim(r))&&t.cookie(r.substr(0,r.indexOf("=")),null,s)})}}})})(window,jQuery);
\ No newline at end of file
diff --git a/third-party/jquery-html5storage/jquery.html5storage.url b/third-party/jquery-html5storage/jquery.html5storage.url
new file mode 100644 (file)
index 0000000..d9156e6
--- /dev/null
@@ -0,0 +1 @@
+https://github.com/artberri/jquery-html5storage.git@8188a60f5207db8aee4320c5fbc05db910d9ba4b
index d8aad83..4aee055 120000 (symlink)
@@ -1 +1 @@
-jquery-1.9.1.min.js
\ No newline at end of file
+jquery-1.9.1.js
\ No newline at end of file
diff --git a/third-party/jquery/js/jquery.min.js b/third-party/jquery/js/jquery.min.js
new file mode 120000 (symlink)
index 0000000..d8aad83
--- /dev/null
@@ -0,0 +1 @@
+jquery-1.9.1.min.js
\ No newline at end of file
diff --git a/unfold/js/init-all-plugins.js b/unfold/js/init-all-plugins.js
deleted file mode 100644 (file)
index 735abba..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* upon document completion, we locate all the hide and show areas, 
- * and configure their behaviour 
- */
-$(document).ready(function() {
-    $('.plugin-hide').each(function() {
-       $(this).click(function () { 
-           var plugin='#'+$(this).attr('id').replace('hide-',''); 
-           var show='#'+$(this).attr('id').replace('hide-','show-'); 
-           $(plugin).slideUp(); $(show).show(); $(this).hide();});
-    });
-    $('.plugin-show').each(function() {
-       $(this).click(function () { 
-           var plugin='#'+$(this).attr('id').replace('show-',''); 
-           var hide='#'+$(this).attr('id').replace('show-','hide-'); 
-           $(plugin).slideDown(); $(hide).show(); $(this).hide();});
-    });
-    $('.plugin-tooltip').each(function(){ $(this).tooltip({'selector':'','placement':'right'}); });
-})
diff --git a/unfold/js/plugin.js b/unfold/js/plugin.js
new file mode 100644 (file)
index 0000000..b03b737
--- /dev/null
@@ -0,0 +1,65 @@
+var plugin = {
+
+    debug:true,
+
+    ////////// use local storage to remember open/closed toggles
+    store_status : function (domid) {
+       var plugin=$('#'+domid);
+       key='toggle.'+domid;
+       if (debug) console.log('storing toggle status for '+domid);
+       $.localStorage.setItem(key,plugin.visible());
+    },
+    // restore last status
+    restore_last_status : function (domid) {
+       key='toggle.'+domid;
+       // don't do anything if nothing stored
+       var retrieved=$.localStorage.getItem(key,undefined);
+       if (retrieved===null) return;
+       if (debug) console.log ("Applying retrieved status " + retrieved +  " to " + domid);
+       set_visible(domid,retrieved);
+    },
+    // triggered upon $(document).ready
+    init_all_plugins: function() {
+       $('.plugin-hide').each(function() {
+           $(this).click(function () { 
+               var plugin='#'+$(this).attr('id').replace('hide-',''); 
+               var show='#'+$(this).attr('id').replace('hide-','show-'); 
+               $(plugin).slideUp(); $(show).show(); $(this).hide();});
+       });
+       $('.plugin-show').each(function() {
+           $(this).click(function () { 
+               var plugin='#'+$(this).attr('id').replace('show-',''); 
+               var hide='#'+$(this).attr('id').replace('show-','hide-'); 
+               $(plugin).slideDown(); $(hide).show(); $(this).hide();});
+       });
+       $('.plugin-tooltip').each(function(){ $(this).tooltip({'selector':'','placement':'right'}); });
+    },
+    toggle : function (domid) {
+       var plugin=$('#'+domid);
+       plugin.toggle();
+       var showbtn=$('#show-'+domid);
+       var hidebtn=$('#hide-'+domid);
+       if (plugin.visible()) {
+           hidebtn.show();
+           showbtn.hide();
+       } else {
+           hidebtn.hide();
+           showbtn.show();
+       }
+       plugin.store_status(domid);
+    },
+    // 'target' is retrieved from storage so essentially a string 'true' or 'false'
+    set_visible : function (domid, target) {
+       var plugin=$('#'+domid);
+       if (plugin.visible()!=target) {
+           if (debug) console.log('set_visible: toggling ' + domid);
+           plugin.toggle (domid);
+       }
+    },
+} // global unfold
+
+/* upon document completion, we locate all the hide and show areas, 
+ * and configure their behaviour 
+ */
+$(document).ready(plugin.init_all_plugins)
+
index 8ce6cdc..1afb575 100644 (file)
@@ -8,8 +8,9 @@
 {{ header_prelude }}
 </head>{# let's add these ones no matter what #}
 {# not yet needed {% insert_str prelude "css/layout-unfold1.css" %} #}
-{% insert_str prelude "js/jquery.js" %}
-{% insert_str prelude "js/init-all-plugins.js" %}
+{% insert_str prelude "js/jquery.min.js" %}
+{% insert_str prelude "js/jquery.html5storage.min.js" %}
+{% insert_str prelude "js/plugin.js" %}
 <body>
 {% block container %}
 <div id="container">
index 75c3087..ed7a488 100644 (file)
@@ -8,8 +8,9 @@
 {{ header_prelude }}
 </head>{# let's add these ones no matter what #}
 {% insert_str prelude "css/layout-unfold2.css" %}
-{% insert_str prelude "js/jquery.js" %}
-{% insert_str prelude "js/init-all-plugins.js" %}
+{% insert_str prelude "js/jquery.min.js" %}
+{% insert_str prelude "js/jquery.html5storage.min.js" %}
+{% insert_str prelude "js/plugin.js" %}
 <body>
 {% block container %}
 <div id="container">