]> git.0d.be Git - panikweb.git/commitdiff
make it possible to set initially enabled toggles with a ?q parameter
authorFrédéric Péters <fpeters@0d.be>
Thu, 12 Sep 2013 13:00:07 +0000 (15:00 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 12 Sep 2013 13:00:07 +0000 (15:00 +0200)
panikweb_templates/static/js/specifics.js

index bfb607d9ff1ed35f0012fed69d514d96942b4bb5..50b224c1f2264d32d8e3193f6fe9c5e52341ac11 100644 (file)
@@ -1,3 +1,16 @@
+var urlParams;
+(window.onpopstate = function () {
+    var match,
+        pl     = /\+/g,  // Regex for replacing addition symbol with a space
+        search = /([^&=]+)=?([^&]*)/g,
+        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
+        query  = window.location.search.substring(1);
+
+    urlParams = {};
+    while (match = search.exec(query))
+       urlParams[decode(match[1])] = decode(match[2]);
+})();
+
 $(function() {
 
        doLog = function(aTextToLog, type){
@@ -335,6 +348,17 @@ $(function() {
                $('[data-toggle].icon-check-empty').each(function(){
                        $(this).trigger('uncheck');
                });
+
+               initial_enabled_toggles = {};
+               if (typeof(urlParams.q) == 'string') {
+                       urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
+               }
+               $('[data-toggle]').each(function() {
+                       if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
+                               $(this).trigger('click');
+                       }
+               });
+
                if ($('input#id_q').val() == '') {
                        $('input#id_q').focus();
                }