openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

checkbox.js (1019B)


      1 import $ from  '../../../../cms/ui/themes/default/script/jquery-global.js';
      2 import Workbench from "../../../../cms/ui/themes/default/script/openrat/workbench.js";
      3 
      4 
      5 export default function(element ) {
      6 
      7 	// Wrapper Checkboxes will control the "hidden checkbox".
      8 	// So unchecked checkboxes will posted too.
      9 	$(element).find('.or-form-checkbox').change(function(e) {
     10 		this.nextElementSibling.value = this.checked ? '1' : '0';
     11 	});
     12 
     13 	// Restore the remembered check flag
     14 	$(element).find('.or-form-checkbox.or-remember').each( function() {
     15 		let key = 'preset.'+Workbench.state.action+'.'+this.dataset['name'];
     16 		if   ( window.localStorage )
     17 			this.checked = !!localStorage.getItem(key);
     18 			this.nextElementSibling.value = this.checked ? '1' : '0';
     19 	});
     20 
     21 	// Store the check flag
     22 	$(element).find('.or-form-checkbox.or-remember').change(function() {
     23 		let key = 'preset.'+Workbench.state.action+'.'+this.dataset['name'];
     24 		if   ( window.localStorage )
     25 			window.localStorage.setItem(key,this.checked?'1':'');
     26 	});
     27 
     28 };
     29 
     30