|
@@ -1,29 +1,41 @@
|
|
|
var $ = require('jquery');
|
|
|
|
|
|
-var initCheckboxesWithoutLabel = function () {
|
|
|
- var uniqueCheckboxIdCounter = 0;
|
|
|
- var uniqueCheckboxIdPrefix = 'unique_checkbox_id_';
|
|
|
+var Checkboxes = function() { };
|
|
|
|
|
|
- var addLabelToCheckbox = function($checkbox) {
|
|
|
- var checkboxId = $checkbox.attr('id') ? $checkbox.attr('id') : uniqueCheckboxIdPrefix + uniqueCheckboxIdCounter++;
|
|
|
- var $label = $('<label>').attr('for', checkboxId);
|
|
|
+Checkboxes.prototype = {
|
|
|
+ uniqueCheckboxIdCounter: 0,
|
|
|
+ uniqueCheckboxIdPrefix: 'unique_checkbox_id_',
|
|
|
+ addLabelToCheckbox: function($checkbox) {
|
|
|
+ var checkboxId = $checkbox.attr('id')
|
|
|
+ ? $checkbox.attr('id')
|
|
|
+ : this.uniqueCheckboxIdPrefix + this.uniqueCheckboxIdCounter++;
|
|
|
|
|
|
- $checkbox.hide().attr('id', checkboxId);
|
|
|
- $label.insertAfter($checkbox);
|
|
|
- };
|
|
|
-
|
|
|
- var addLabelToCheckboxes = function() {
|
|
|
- var $containers = $('.action-checkbox, .action-checkbox-column').add('.tabular.inline-related .form-row');
|
|
|
- var $checkboxes = $containers.find('input[type="checkbox"]').add('.checkbox-without-label').add('label > input[type="checkbox"]');
|
|
|
+ $checkbox.attr('id', checkboxId);
|
|
|
+ $('<label>')
|
|
|
+ .attr('for', checkboxId)
|
|
|
+ .insertAfter($checkbox);
|
|
|
+ },
|
|
|
+ addLabelToCheckboxes: function() {
|
|
|
+ var self = this;
|
|
|
+ var $containers = $('.action-checkbox, .action-checkbox-column, .tabular.inline-related .form-row');
|
|
|
+ var $checkboxes = $containers
|
|
|
+ .find('input[type="checkbox"]')
|
|
|
+ .add('.checkbox-without-label')
|
|
|
+ .add('label > input[type="checkbox"]');
|
|
|
|
|
|
$checkboxes.each(function() {
|
|
|
- addLabelToCheckbox($(this));
|
|
|
+ self.addLabelToCheckbox($(this));
|
|
|
});
|
|
|
- };
|
|
|
-
|
|
|
- addLabelToCheckboxes();
|
|
|
+ },
|
|
|
+ run: function() {
|
|
|
+ try {
|
|
|
+ this.addLabelToCheckboxes();
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e, e.stack);
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
- initCheckboxesWithoutLabel();
|
|
|
+ new Checkboxes().run();
|
|
|
});
|