Skip to content

Commit

Permalink
Update Exopite Simple Options Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSz committed May 9, 2019
1 parent 4b98ea9 commit 74f4d67
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 3 deletions.
117 changes: 117 additions & 0 deletions exopite-notificator/admin/exopite-simple-options/assets/dev/scripts.js
Expand Up @@ -1940,6 +1940,122 @@ jQuery.fn.findExclude = function (selector, mask, result) {

})(jQuery, window, document);


/**
* Exopite SOF - Manage empty checkboxes and selects (multiple)
*
* When checkbox is not checked or select with attribute multiple is empty,
* they are not sent in POST so create a hidden input before the element for that.
*
* This is only relevant for metabox, because in the options the POST can be
* check and add them before being sent.
*/
; (function ($, window, document, undefined) {

var pluginName = "exopitePrepareForm";

// The actual plugin constructor
function Plugin(element, options) {

this.element = element;
this._name = pluginName;
this.$element = $(element);
this.init();

}

Plugin.prototype = {

init: function () {

this.bindEvents();

},

// Bind events that trigger methods
bindEvents: function () {
var plugin = this;

plugin.$element.find('select[multiple]').not(':disabled').each(function (index, element) {

var $this = $(this),
selected_value = $this.val();

if (!selected_value) {
plugin.addHidden($this.attr('name'), $this);
}

});

plugin.$element.find('select[multiple]').on('change', function () {

var $this = $(this),
selected_value = $this.val();

if (selected_value) {
plugin.removeHidden($this);
} else {
plugin.addHidden($this.attr('name'), $this);
}

});

plugin.$element.find('input:checkbox:not(:checked):not([disabled])').each(function (index, element) {

var $this = $(this);
plugin.addHidden($this.attr('name'), $this);

});

plugin.$element.find('input[type="checkbox"]').on('change', function () {

var $this = $(this),
checked = $this.prop('checked');

if (checked) {
plugin.removeHidden($this);
} else {
plugin.addHidden($this.attr('name'), $this);
}

});

},

// Unbind events that trigger methods
unbindEvents: function () {
this.$element.off('.' + this._name);
},

addHidden: function ( name, $element ) {

$('<input>').attr({
'type': 'hidden',
'name': name,
'value': 'no'
}).insertBefore($element);

},

removeHidden: function ( $element ) {

$element.prev('input[type="hidden"]').remove();

},

};

$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName,
new Plugin(this, options));
}
});
};

})(jQuery, window, document);

/**
* ToDos:
* - sortable only if data-is-sortable is 1 || true
Expand Down Expand Up @@ -1983,6 +2099,7 @@ jQuery.fn.findExclude = function (selector, mask, result) {
$('.exopite-sof-field-backup').exopiteImportExportAJAX();
$('.exopite-sof-tabs').exopiteTabs();
$('.exopite-sof-gallery-field').exopiteSOFGallery();
$('.exopite-sof-wrapper-metabox').exopitePrepareForm();

});

Expand Down
Expand Up @@ -338,7 +338,9 @@

}
.exopite-sof-wrapper-metabox {
margin: -6px -12px -12px -12px;
/* margin: -6px -12px -12px -12px; */
margin: -6px -12px -12px -12px !important;
box-sizing: content-box;
}
.block-editor-page .exopite-sof-wrapper-metabox {
margin: 0;
Expand Down Expand Up @@ -2956,4 +2958,9 @@ input[type="color"] {
.edit-post-sidebar .exopite-sof-field-color input.minicolor,
.edit-post-sidebar .exopite-sof-field-color .minicolors-swatch {
border-color: #e5e5e5;
}
.minicolors,
.exopite-sof-form-field,
.exopite-sof-fieldset {
box-sizing: content-box;
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -68,6 +68,10 @@ public function output() {
$self->include_field_class( array( 'type' => $field['type'] ) );
$self->enqueue_field_class( array( 'type' => $field['type'] ) );

if ( is_serialized( $this->value ) ) {
$this->value = unserialize( $this->value );
}

$field_value = '';
if ( isset( $this->value[ $field['id'] ] ) ) {
$field_value = $this->value[ $field['id'] ];
Expand Down
Expand Up @@ -73,6 +73,10 @@ public function output() {
$self->include_field_class( array( 'type' => $field['type'] ) );
$self->enqueue_field_class( array( 'type' => $field['type'] ) );

if ( is_serialized( $this->value ) ) {
$this->value = unserialize( $this->value );
}

$field_value = '';
if ( isset( $this->value[ $field['id'] ] ) ) {
$field_value = $this->value[ $field['id'] ];
Expand Down

0 comments on commit 74f4d67

Please sign in to comment.