Created
January 24, 2018 17:54
-
-
Save peteristhegreat/bbccf7f8be1f722a364d2cccfd58ac01 to your computer and use it in GitHub Desktop.
CssSelectorGenerator (css-selector-generator.js) with JQuery to save/load all textfields and all checkboxes to Cookies (js.cookie.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Views = {}; | |
Views.save = function(){ | |
var CssPath = new CssSelectorGenerator; | |
var text_fields = {}; | |
var checkboxes = {}; | |
$(":checkbox").each(function(index, element){ | |
var checked = element.checked; | |
var css_path = CssPath.getSelector(element); | |
checkboxes[css_path] = checked; | |
}); | |
$(":text").each(function(index, element){ | |
var text = $(this).val(); | |
var css_path = CssPath.getSelector(element); | |
text_fields[css_path] = text; | |
}); | |
Cookies.set("text_fields", text_fields); | |
Cookies.set("checkboxes", checkboxes); | |
}; | |
Views.loaded = false; | |
Views.load = function(){ | |
if(Views.loaded){ | |
return; | |
} | |
Views.loaded = true; | |
//var CssPath = new CssSelectorGenerator; | |
var checkboxes = Cookies.getJSON("checkboxes");// details buttons | |
var text_fields = Cookies.getJSON("text_fields"); | |
// Iterate thru checkboxes and click on them | |
_.each(checkboxes, function(value, key, list){ | |
//console.log(key, value); | |
var element = $(key); | |
if(value != element.is(':checked')){ | |
// make the number of columns change | |
element.trigger('click'); | |
// wait for the column count to change | |
} | |
}); | |
var e = jQuery.Event("keyup", { which: $.ui.keyCode.ENTER }); | |
_.each(text_fields, function(value, key, list){ | |
//console.log(key, value); | |
var element = $(key); | |
if(value != element.text()){ | |
element.val(value); | |
element.trigger(e); | |
} | |
}); | |
}; | |
$(window).bind('beforeunload', function(){ | |
// Views.save(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment