var $doc = jQuery(document), $window = jQuery(window); function attachAllDynamicPostsSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-posts-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_posts' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text[0], text: text[1] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-posts-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Posts sortable and They are using AJAX calls to extract info */ } function attachAllDynamicPostTitlesSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-post-titles-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_posts_titles' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-post-titles-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Posts sortable and They are using AJAX calls to extract info */ } function attachAllDynamicPostIDsSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-post-ids-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_posts_ids' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, //minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-post-ids-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Posts sortable and They are using AJAX calls to extract info */ } function attachAllDynamicPostTypes() { jQuery('.wsal-custom-post-selector input:not([type=hidden])').autocomplete({ source: function (request, response) { jQuery.ajax({ url: ajaxurl, dataType: "json", data: { q: request.term, // search query action: 'wsal_settings_get_posts', // AJAX action for admin-ajax.php type: 'input' }, success: function (data) { console.log(data); response(data); } }); }, select: function (event, ui) { console.log(jQuery(this)); jQuery(this).parent().find('input:hidden:first').val(ui.item.id); }, minLength: 3, }); } function attachAllDynamicUsersSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-users-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_users' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-users-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Posts sortable and They are using AJAX calls to extract info */ } function attachAllDynamicSitesSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-sites-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_sites' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-users-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Posts sortable and They are using AJAX calls to extract info */ } function attachAllDynamicUserTypes() { jQuery('.wsal-custom-user-selector input:not([type=hidden])').autocomplete({ source: function (request, response) { jQuery.ajax({ url: ajaxurl, dataType: "json", data: { q: request.term, // search query action: 'wsal_get_users', // AJAX action for admin-ajax.php type: 'input' }, success: function (data) { console.log(data); response(data); } }); }, select: function (event, ui) { console.log(jQuery(this)); jQuery(this).parent().find('input:hidden:first').val(ui.item.id); }, minLength: 3, }); } function attachAllDynamicRolesSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-roles-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_roles' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-roles-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Roles sortable and They are using AJAX calls to extract info */ } function attachAllDynamicIPsSelects() { /** Make Custom Posts sortable and They are using AJAX calls to extract info */ jQuery('.wsal-custom-ips-selector select').select2({ width: 'resolve', containerCssClass: "s24wp-wrapper", ajax: { url: ajaxurl, // AJAX URL is predefined in WordPress admin dataType: 'json', delay: 250, // delay in ms while typing when to perform a AJAX search data: function (params) { return { q: params.term, // search query action: 'wsal_settings_get_ips' // AJAX action for admin-ajax.php }; }, processResults: function (data) { var options = []; if (data) { // data is the array of arrays, and each of them contains ID and the Label of the option jQuery.each(data, function (index, text) { // do not forget that "index" is just auto incremented value options.push({ id: text['id'], text: text['label'] }); }); } return { results: options }; }, cache: true }, minimumInputLength: 3 // the minimum of symbols to input before perform a search }); jQuery('.wsal-custom-ips-selector select').each(function (index) { var selectEl = jQuery(this); selectEl.next().children().children().children().sortable({ containment: 'parent', stop: function (event, ui) { ui.item.parent().children('[title]').each(function () { var title = jQuery(this).attr('title'); var original = jQuery('option:contains(' + title + ')', selectEl).first(); original.detach(); selectEl.append(original) }); selectEl.change(); } }); }); /** End Custom Roles sortable and They are using AJAX calls to extract info */ } $doc.ready(function () { var $wsalBody = jQuery('body'); /* DASHBORED COLOR ------------------------------------------------------------------------------------------ */ var brandColor = '#d54e21'; if ($wsalBody.hasClass('admin-color-blue')) { brandColor = '#e1a948'; } else if ($wsalBody.hasClass('admin-color-coffee')) { brandColor = '#9ea476'; } else if ($wsalBody.hasClass('admin-color-ectoplasm')) { brandColor = '#d46f15'; } else if ($wsalBody.hasClass('admin-color-midnight')) { brandColor = '#69a8bb'; } else if ($wsalBody.hasClass('admin-color-ocean')) { brandColor = '#aa9d88'; } else if ($wsalBody.hasClass('admin-color-sunrise')) { brandColor = '#ccaf0b'; } attachAllDynamicPostsSelects(); attachAllDynamicPostTitlesSelects(); attachAllDynamicPostIDsSelects(); attachAllDynamicUsersSelects(); attachAllDynamicSitesSelects(); attachAllDynamicPostTypes(); attachAllDynamicUserTypes(); attachAllDynamicRolesSelects(); attachAllDynamicIPsSelects(); jQuery('.wsal-toggle-option').each(function () { var $thisElement = jQuery(this), elementType = $thisElement.attr('type'), toggleItems = $thisElement.data('wsal-toggle'); toggleItems = jQuery(toggleItems).hide(); if (elementType = 'checkbox') { if ($thisElement.is(':checked')) { toggleItems.slideDown(); }; $thisElement.change(function () { toggleItems.slideToggle('fast'); // CodeMirror toggleItems.find('.CodeMirror').each(function (i, el) { el.CodeMirror.refresh(); }); }); } }); /* Reset button message ------------------------------------------------------------------------------------------ */ jQuery('#wsal-reset-settings').click(function () { var message = jQuery(this).data('message'), reset = confirm(message); if (!reset) { return false; } }); /* Sticky Bottom Save Button */ var lastScrollTop = 0, $topSaveButton = jQuery('.wsal-panel-content'), $bottomSaveButton = jQuery('.wsal-footer .wsal-save-button'); stickySaveButton = function () { var topSaveOffset = $topSaveButton.offset().top, scrollTop = $window.scrollTop(), scrollBottom = $doc.height() - scrollTop - $window.height(), st = scrollTop; if (scrollTop > topSaveOffset && scrollBottom > 105 - $bottomSaveButton.height()) { if (st > lastScrollTop) { $bottomSaveButton.addClass('sticky-on-down').removeClass('sticky-on-up'); if (scrollTop > topSaveOffset) { $bottomSaveButton.addClass('sticky-on-down-appear').removeClass('sticky-on-up-disappear'); } } else { $bottomSaveButton.addClass('sticky-on-up').removeClass('sticky-on-down'); if (scrollTop < topSaveOffset) { $bottomSaveButton.addClass('sticky-on-up-disappear').removeClass('sticky-on-up-appear'); } } } else { $bottomSaveButton.removeClass('sticky-on-down sticky-on-up sticky-on-down-appear sticky-on-up-disappear'); } lastScrollTop = st; } if (0 !== $topSaveButton.length) { stickySaveButton(); $window.scroll(function () { stickySaveButton(); }); } /* Blocks Color Picker */ var wsalBlocksColorsOptions = { change: function (event, ui) { var newColor = ui.color.toString(); jQuery(this).closest('.block-item').find('.wsal-block-head').attr('style', 'background-color: ' + newColor).removeClass('block-head-light block-head-dark').addClass('block-head-' + getContrastColor(newColor)); }, clear: function () { jQuery(this).closest('.block-item').find('.wsal-block-head').attr('style', '').removeClass('block-head-light block-head-dark'); } }; if (jQuery().wpColorPicker) { jQuery('.wsalBlocksColor').wpColorPicker(wsalBlocksColorsOptions); } /* Toggle open/Close */ $doc.on('click', '.toggle-section', function () { var $thisElement = jQuery(this).closest('.wsal-builder-container'); $thisElement.find('.wsal-builder-section-inner').slideToggle('fast'); $thisElement.toggleClass('wsal-section-open'); return false; }); /* COLOR PICKER */ if (jQuery().wpColorPicker) { wsal_color_picker(); } /* IMAGE UPLOADER PREVIEW */ jQuery('.wsal-img-path').each(function () { wsal_image_uploader_trigger(jQuery(this)); }); /* CHECKBOXES */ var checkInputs = Array.prototype.slice.call(document.querySelectorAll('.wsal-js-switch')); checkInputs.forEach(function (html) { new Switchery(html, { color: brandColor }); }); /* Sortable */ jQuery('.tab-sortable').each(function () { wsal_sortable_tabs_trigger(jQuery(this)); }); /* DISMISS NOTICES */ $doc.on('click', '.wsal-notice .notice-dismiss', function () { jQuery('#wsal-page-overlay').hide(); jQuery.ajax({ url: ajaxurl, type: 'post', data: { pointer: jQuery(this).closest('.wsal-notice').attr('id'), action: 'dismiss-wp-pointer', }, }); }); /* SAVE PLUGIN SETTINGS ------------------------------------------------------------------------------------------ */ /** * On the periodic reports whene there are no records in the report we are generating error message. * That error message is using hte same HTML element - so that code checks for existance and if there is * such - it doesn't run this logic. * Search the code base for $genAlert (JS variable) */ if ( typeof $genAlert === 'undefined' ) { var $saveAlert = jQuery('#wsal-saving-settings'); } jQuery('#wsal_form').submit(function (evt) { $saveAlert.fadeIn(); if ( jQuery('#wsal-import-file').length ) { // Check if the import field has a file var importSettings = jQuery('#wsal-import-file').val(); if (importSettings.length > 0) { return true; } } // Disable all blank fields to reduce the size of the data jQuery('form#wsal_form input, form#wsal_form textarea, form#wsal_form select').each(function () { if (!jQuery(this).val()) { jQuery(this).attr('disabled', true); } }); // Serialize the data array var data = jQuery(this).serialize(); // Re-activate the disabled options jQuery('form#wsal_form input:disabled, form#wsal_form textarea:disabled, form#wsal_form select:disabled').attr('disabled', false); // Add the Overlay layer and reset the saving spinner $wsalBody.addClass('has-overlay'); $saveAlert.removeClass('is-success is-failed'); jQuery.ajax({ url : ajaxurl, type: 'post', data: data, error: function( xhr, status, error ){ if( 'undefined' != typeof xhr.status && xhr.status != 200 ){ $saveAlert.addClass('is-failed').delay(900); $saveAlert.append('
'); jQuery('#wsal_remove_error').click(function(e) { $saveAlert.addClass('is-failed').delay(900).fadeOut(700); $wsalBody.removeClass('has-overlay'); jQuery('.wsal-error-message').remove(); }); } return false; }, success: function( response ){ if (response.data == 1) { $saveAlert.addClass('is-success').delay(900).fadeOut(700); setTimeout(function() { $wsalBody.removeClass('has-overlay'); },1200); } else if (response.data == 2) { location.reload(); } else if ( undefined !== response.data.redirect && response.data.redirect.length) { location.href = decodeURIComponent(response.data.redirect); } else { $saveAlert.addClass('is-failed').delay(900).fadeOut(700); setTimeout(function () { $wsalBody.removeClass('has-overlay'); }, 1200); } } }); // Send the Saving Ajax request // jQuery.post( // ajaxurl, // data, // function (response) { // console.log(response); // if (response.data == 1) { // $saveAlert.addClass('is-success').delay(900).fadeOut(700); // setTimeout(function () { $wsalBody.removeClass('has-overlay'); }, 1200); // } // else if (response.data == 2) { // location.reload(); // } // else if ( undefined !== response.data['redirect'] && response.data['redirect'].length) { // location.href = decodeURIComponent(response.data['redirect']); // } // else { // $saveAlert.addClass('is-failed').delay(900).fadeOut(700); // setTimeout(function () { $wsalBody.removeClass('has-overlay'); }, 1200); // } // } // ); return false; }); /* SAVE SETTINGS ALERT */ /** * On the periodic reports whene there are no records in the report we are generating error message. * That error message is using hte same HTML element - so that code checks for existance and if there is * such - it doesn't run this logic. * Search the code base for $genAlert (JS variable) */ if ( typeof $genAlert === 'undefined' ) { $saveAlert.fadeOut(); } // jQuery('.wsal-save-button').click(function (evt) { // // jQuery("input:hidden, textarea:hidden, select:hidden").attr("disabled", true); // jQuery('form#wsal_form input').on('invalid', function(e){ // alert("Error, please fill all required fields before submitting."); // $saveAlert.fadeOut(); // // evt.preventDefault(); // // evt.stopPropagation(); // // jQuery("input:hidden, textarea:hidden, select:hidden").attr("disabled", false); // return false; // }); // $saveAlert.fadeIn(); // }); /* SETTINGS PANEL ------------------------------------------------------------------------------------------ */ jQuery('.wsal-panel, .wsal-notice').css({ 'opacity': 1, 'visibility': 'visible' }); var tabsHeight = jQuery('.wsal-panel-tabs').outerHeight(); jQuery('.tabs-wrap').hide(); jQuery('.wsal-panel-tabs ul li:first').addClass('active').show(); jQuery('.tabs-wrap:first').show(); jQuery('.wsal-panel-content').css({ minHeight: tabsHeight }); jQuery('li.wsal-tabs:not(.wsal-not-tab)').click(function () { jQuery('.wsal-panel-tabs ul li').removeClass('active'); jQuery(this).addClass('active'); jQuery('.tabs-wrap').hide(); var activeTab = jQuery(this).find('a').attr('href'); jQuery(activeTab).show(); jQuery(activeTab).trigger('activated'); document.location.hash = activeTab + '-target'; // CodeMirror jQuery(activeTab).find('.CodeMirror').each(function (i, el) { el.CodeMirror.refresh(); }); }); /* GO TO THE OPENED TAB WITH LOAD */ var currentTab = window.location.hash.replace('-target', ''); currentTab = currentTab.replace(/\//g, ''); // avoid issues when the URL contains something like #/campaign/0/contacts if (jQuery(currentTab).parent('#wsal_form').length || jQuery(currentTab).parent('#periodic-report-viewer').length || jQuery(currentTab).parent('#saved-reports-viewer').length ) { var tabLinkClass = currentTab.replace('#', '.'); jQuery('.tabs-wrap').hide(); jQuery('.wsal-panel-tabs ul li').removeClass('active'); jQuery(currentTab).show(); jQuery(tabLinkClass).addClass('active'); jQuery(tabLinkClass).trigger('activated'); } /* DELETE SECTIONS ------------------------------------------------------------------------------------------ */ /* OPTION ITEM */ $doc.on('click', '.del-item', function () { var $thisButton = jQuery(this); if ($thisButton.hasClass('del-custom-sidebar')) { var option = $thisButton.parent().find('input').val(); jQuery('#custom-sidebars select').find('option[value="' + option + '"]').remove(); } if ($thisButton.hasClass('del-section')) { var widgets = $thisButton.closest('.parent-item').find('.wsal-manage-widgets').data('widgets'); jQuery('#wrap-' + widgets + ', #' + widgets + '-sidebar-options').remove(); } $thisButton.closest('.parent-item').addClass('removed').fadeOut(function () { $thisButton.closest('.parent-item').remove(); }); return false; }); /* DELETE PREVIEW IMAGE */ $doc.on('click', '.del-img', function () { var $img = jQuery(this).parent(); $img.fadeOut('fast', function () { $img.hide(); $img.closest('.option-item').find('.wsal-img-path').attr('value', ''); }); }); /* DELETE PREVIEW IMAGE */ $doc.on('click', '.del-img-all', function () { var $imgLi = jQuery(this).closest('li'); $imgLi.fadeOut('fast', function () { $imgLi.remove(); }); }); jQuery('ul.wsal-options').each(function (index) { jQuery(this).find('input:checked').parent().addClass('selected'); }); $doc.on('click', 'ul.wsal-options a', function () { var $thisBlock = jQuery(this), blockID = $thisBlock.closest('ul.wsal-options').attr('id'); jQuery('#' + blockID).find('li').removeClass('selected'); jQuery('#' + blockID).find(':radio').removeAttr('checked'); $thisBlock.parent().find(':radio').trigger('click'); $thisBlock.parent().addClass('selected'); $thisBlock.parent().find(':radio').attr('checked', 'checked'); return false; }); }); /* Fire Sortable on the Widgets Tabs ------------------------------------------------------------------------------------------ */ function wsal_sortable_tabs_trigger($thisTabs) { $thisTabs.sortable({ placeholder: 'wsal-state-highlight', stop: function (event, ui) { var data = ''; $thisTabs.find('li').each(function () { var type = jQuery(this).data('tab'); data += type + ','; }); $thisTabs.parent().find('.stored-tabs-order').val(data.slice(0, -1)); } }); } function wsal_image_uploader_trigger($thisElement) { var thisElementID = $thisElement.attr('id').replace('#', ''), $thisElementParent = $thisElement.closest('.option-item'), $thisElementImage = $thisElementParent.find('.img-preview'), uploaderTypeStyles = false; $thisElement.change(function () { $thisElementImage.show(); $thisElementImage.find('img').attr('src', $thisElement.val()); }); if ($thisElement.hasClass('wsal-background-path')) { thisElementID = thisElementID.replace('-img', ''); uploaderTypeStyles = true; } wsal_set_uploader(thisElementID, uploaderTypeStyles); } function wsal_set_uploader(field, styling) { var wsal_bg_uploader; $doc.on('click', '#upload_' + field + '_button', function (event) { event.preventDefault(); wsal_bg_uploader = wp.media.frames.wsal_bg_uploader = wp.media({ title: 'Choose Image', library: { type: 'image' }, button: { text: 'Select' }, multiple: false }); wsal_bg_uploader.on('select', function () { var selection = wsal_bg_uploader.state().get('selection'); selection.map(function (attachment) { attachment = attachment.toJSON(); if (styling) { jQuery('#' + field + '-img').val(attachment.url); } else { jQuery('#' + field).val(attachment.url); } jQuery('#' + field + '-preview').show(); jQuery('#' + field + '-preview img').attr('src', attachment.url); }); }); wsal_bg_uploader.open(); }); } function wsal_color_picker() { Color.prototype.toString = function (remove_alpha) { if (remove_alpha == 'no-alpha') { return this.toCSS('rgba', '1').replace(/\s+/g, ''); } if (this._alpha < 1) { return this.toCSS('rgba', this._alpha).replace(/\s+/g, ''); } var hex = parseInt(this._color, 10).toString(16); if (this.error) return ''; if (hex.length < 6) { for (var i = 6 - hex.length - 1; i >= 0; i--) { hex = '0' + hex; } } return '#' + hex; }; jQuery('.wsalColorSelector').each(function () { var $control = jQuery(this), value = $control.val().replace(/\s+/g, ''), palette_input = $control.attr('data-palette'); if (palette_input == 'false' || palette_input == false) { var palette = false; } else if (palette_input == 'true' || palette_input == true) { var palette = true; } else { var palette = $control.attr('data-palette').split(","); } $control.wpColorPicker({ // change some things with the color picker clear: function (event, ui) { // TODO reset Alpha Slider to 100 }, change: function (event, ui) { var $transparency = $control.parents('.wp-picker-container:first').find('.transparency'); $transparency.css('backgroundColor', ui.color.toString('no-alpha')); }, palettes: palette }); jQuery('