123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623 |
- (function($){
- /**
- * Helper class for dealing with the builder's admin
- * settings page.
- *
- * @class FLBuilderAdminSettings
- * @since 1.0
- */
- FLBuilderAdminSettings = {
- /**
- * An instance of wp.media used for uploading icons.
- *
- * @since 1.4.6
- * @access private
- * @property {Object} _iconUploader
- */
- _iconUploader: null,
- /**
- * Initializes the builder's admin settings page.
- *
- * @since 1.0
- * @method init
- */
- init: function()
- {
- this._bind();
- //this._maybeShowWelcome();
- this._initNav();
- this._initNetworkOverrides();
- this._initLicenseSettings();
- this._initMultiSelects();
- this._initUserAccessSelects();
- this._initUserAccessNetworkOverrides();
- this._templatesOverrideChange();
- this._iconPro();
- this._alphaSettings();
- },
- /**
- * Binds events for the builder's admin settings page.
- *
- * @since 1.0
- * @access private
- * @method _bind
- */
- _bind: function()
- {
- $('.fl-settings-nav a').on('click', FLBuilderAdminSettings._navClicked);
- $('.fl-override-ms-cb').on('click', FLBuilderAdminSettings._overrideCheckboxClicked);
- $('.fl-ua-override-ms-cb').on('click', FLBuilderAdminSettings._overrideUserAccessCheckboxClicked);
- $('.fl-module-all-cb').on('click', FLBuilderAdminSettings._moduleAllCheckboxClicked);
- $('.fl-module-cb').on('click', FLBuilderAdminSettings._moduleCheckboxClicked);
- $('input[name=fl-templates-override]').on('keyup click', FLBuilderAdminSettings._templatesOverrideChange);
- $('input[name=fl-upload-icon]').on('click', FLBuilderAdminSettings._showIconUploader);
- $('.fl-delete-icon-set').on('click', FLBuilderAdminSettings._deleteCustomIconSet);
- $('#uninstall-form').on('submit', FLBuilderAdminSettings._uninstallFormSubmit);
- $( '.fl-settings-form .dashicons-editor-help' ).tipTip();
- $( '.subscription-form .subscribe-button' ).on( 'click', FLBuilderAdminSettings._welcomeSubscribe);
- $( '.advanced-group input[type=checkbox]').on('change', FLBuilderAdminSettings._advancedToggle );
- $( '.advanced-group input[type=text]').on('keyup', FLBuilderAdminSettings._advancedText );
- $( '.advanced-group h3' ).on('click', FLBuilderAdminSettings._advancedShowHide );
- $( '.advanced-group button' ).on('click', FLBuilderAdminSettings._advancedTextSave );
- },
- _welcomeSubscribe: function()
- {
- form = $('.subscription-form')
- var error = form.find('.error')
- var spinner = form.find('.dashicons')
- if( error.css('display') != 'none' ) {
- error.hide()
- }
- name = form.find( '.input-group-field.name').val()
- email = form.find( '.input-group-field.email').val()
- nonce = form.find( '#_wpnonce' ).val()
- if ( ! email || ! name ) {
- error.html('Please enter required fields').fadeIn()
- return false;
- }
- spinner.css('color', '#fff')
- spinner.addClass('spin')
- data = {
- 'action' : 'fl_welcome_submit',
- 'name' : name,
- 'email' : email,
- '_wpnonce': nonce
- }
- console.log(data)
- $.post(ajaxurl, data, function(response) {
- spinner.css( 'color', '#0a3c4b' );
- spinner.removeClass( 'spin' );
- if( response.success ) {
- $('.subscribe-button').hide()
- $('.input-group').remove()
- spinner.remove()
- $( error ).html( '<h2>' + response.data.message + '</h2>' ).fadeIn()
- } else {
- $( error ).html(response.data.message).fadeIn()
- }
- });
- },
- _advancedText: function() {
- button = $(this).parent().find('.save-button');
- button.css('display', 'contents')
- },
- _advancedTextSave: function(e) {
- e.preventDefault();
- var buttonwrap = $(this).parent()
- id = $(this).data('id');
- value = $('#' + id).val();
- data = {
- 'action' : 'fl_advanced_submit',
- 'setting' : id,
- 'type' : 'text',
- 'value' : value,
- '_wpnonce': $('#fl-advanced-nonce').val()
- }
- $.post(ajaxurl, data, function(response) {
- if ( response.success ) {
- buttonwrap.fadeOut();
- new Notify({
- status: 'success',
- title: 'Saved',
- autoclose: true,
- autotimeout: 1000,
- distance: 20,
- });
- } else {
- new Notify({
- status: 'error',
- title: 'Save Error',
- autoclose: false,
- distance: 20,
- });
- }
- })
- .fail( function(){
- new Notify({
- status: 'error',
- title: 'Save Error',
- autoclose: false,
- distance: 20,
- });
- });
- },
- _advancedToggle: function(event) {
- checkbox = $(this);
- var depend = $(this).data('depend') || false;
- data = {
- 'action' : 'fl_advanced_submit',
- 'setting' : checkbox.attr('name'),
- 'value' : checkbox.is(':checked'),
- '_wpnonce': $('#fl-advanced-nonce').val()
- }
- $.post(ajaxurl, data, function(response) {
- if ( response.success ) {
- $.when(
- new Notify({
- status: 'success',
- title: 'Saved',
- autoclose: true,
- autotimeout: 1000,
- distance: 20,
- })
- ).done(function(){
- if ( depend ) {
- location.reload()
- }
- });
- } else {
- new Notify({
- status: 'error',
- title: 'Save Error',
- autoclose: false,
- distance: 20,
- });
- }
- })
- .fail( function(){
- new Notify({
- status: 'error',
- title: 'Save Error',
- autoclose: false,
- distance: 20,
- });
- });
- },
- _advancedShowHide: function() {
- $(this).parent().find('.advanced-option').toggle('fast');
- },
- /**
- * Show the welcome page after the license has been saved.
- *
- * @since 1.7.4
- * @access private
- * @method _maybeShowWelcome
- */
- _maybeShowWelcome: function()
- {
- var onLicense = 'license' == window.location.hash.replace( '#', '' ),
- isUpdated = $( '.wrap .updated' ).length,
- licenseError = $( '.fl-license-error' ).length;
- if ( onLicense && isUpdated && ! licenseError ) {
- window.location.hash = 'welcome';
- }
- },
- /**
- * Initializes the nav for the builder's admin settings page.
- *
- * @since 1.0
- * @access private
- * @method _initNav
- */
- _initNav: function()
- {
- var links = $('.fl-settings-nav a'),
- hash = window.location.hash,
- active = hash === '' ? [] : links.filter('[href~="'+ hash +'"]');
- $('a.fl-active').removeClass('fl-active');
- $('.fl-settings-form').hide();
- if(hash === '' || active.length === 0) {
- active = links.eq(0);
- }
- active.addClass('fl-active');
- $('#fl-'+ active.attr('href').split('#').pop() +'-form').fadeIn();
- },
- /**
- * Fires when a nav item is clicked.
- *
- * @since 1.0
- * @access private
- * @method _navClicked
- */
- _navClicked: function()
- {
- if($(this).attr('href').indexOf('#') > -1) {
- $('a.fl-active').removeClass('fl-active');
- $('.fl-settings-form').hide();
- $(this).addClass('fl-active');
- $('#fl-'+ $(this).attr('href').split('#').pop() +'-form').fadeIn();
- }
- },
- /**
- * Initializes the checkboxes for overriding network settings.
- *
- * @since 1.0
- * @access private
- * @method _initNetworkOverrides
- */
- _initNetworkOverrides: function()
- {
- $('.fl-override-ms-cb').each(FLBuilderAdminSettings._initNetworkOverride);
- },
- /**
- * Initializes a checkbox for overriding network settings.
- *
- * @since 1.0
- * @access private
- * @method _initNetworkOverride
- */
- _initNetworkOverride: function()
- {
- var cb = $(this),
- content = cb.closest('.fl-settings-form').find('.fl-settings-form-content');
- if(this.checked) {
- content.show();
- }
- else {
- content.hide();
- }
- },
- /**
- * Fired when a network override checkbox is clicked.
- *
- * @since 1.0
- * @access private
- * @method _overrideCheckboxClicked
- */
- _overrideCheckboxClicked: function()
- {
- var cb = $(this),
- content = cb.closest('.fl-settings-form').find('.fl-settings-form-content');
- if(this.checked) {
- content.show();
- }
- else {
- content.hide();
- }
- },
- /**
- * Initializes custom multi-selects.
- *
- * @since 1.10
- * @access private
- * @method _initMultiSelects
- */
- _initMultiSelects: function()
- {
- $( 'select[multiple]' ).multiselect( {
- selectAll: true,
- texts: {
- deselectAll : FLBuilderAdminSettingsStrings.deselectAll,
- noneSelected : FLBuilderAdminSettingsStrings.noneSelected,
- placeholder : FLBuilderAdminSettingsStrings.select,
- selectAll : FLBuilderAdminSettingsStrings.selectAll,
- selectedOptions : FLBuilderAdminSettingsStrings.selected
- }
- } );
- },
- /**
- * Initializes user access select options.
- *
- * @since 1.10
- * @access private
- * @method _initUserAccessSelects
- */
- _initUserAccessSelects: function()
- {
- var config = FLBuilderAdminSettingsConfig,
- options = null,
- role = null,
- select = null,
- key = null,
- hidden = null;
- $( '.fl-user-access-select' ).each( function() {
- options = [];
- select = $( this );
- key = select.attr( 'name' ).replace( 'fl_user_access[', '' ).replace( '][]', '' );
- for( role in config.roles ) {
- options.push( {
- name : config.roles[ role ],
- value : role,
- checked : 'undefined' == typeof config.userAccess[ key ] ? false : config.userAccess[ key ][ role ]
- } );
- }
- select.multiselect( 'loadOptions', options );
- } );
- },
- /**
- * Initializes the checkboxes for overriding user access
- * network settings.
- *
- * @since 1.0
- * @access private
- * @method _initUserAccessNetworkOverrides
- */
- _initUserAccessNetworkOverrides: function()
- {
- $('.fl-ua-override-ms-cb').each(FLBuilderAdminSettings._initUserAccessNetworkOverride);
- },
- /**
- * Initializes a checkbox for overriding user access
- * network settings.
- *
- * @since 1.0
- * @access private
- * @method _initUserAccessNetworkOverride
- */
- _initUserAccessNetworkOverride: function()
- {
- var cb = $(this),
- select = cb.closest('.fl-user-access-setting').find('.ms-options-wrap');
- if(this.checked) {
- select.show();
- }
- else {
- select.hide();
- }
- },
- /**
- * Fired when a network override checkbox is clicked.
- *
- * @since 1.0
- * @access private
- * @method _overrideCheckboxClicked
- */
- _overrideUserAccessCheckboxClicked: function()
- {
- var cb = $(this),
- select = cb.closest('.fl-user-access-setting').find('.ms-options-wrap');
- if(this.checked) {
- select.show();
- }
- else {
- select.hide();
- }
- },
- /**
- * Fires when the "all" checkbox in the list of enabled
- * modules is clicked.
- *
- * @since 1.0
- * @access private
- * @method _moduleAllCheckboxClicked
- */
- _moduleAllCheckboxClicked: function()
- {
- if($(this).is(':checked')) {
- $('.fl-module-cb').prop('checked', true);
- } else {
- $('.fl-module-cb').prop('checked', false);
- }
- },
- /**
- * Fires when a checkbox in the list of enabled
- * modules is clicked.
- *
- * @since 1.0
- * @access private
- * @method _moduleCheckboxClicked
- */
- _moduleCheckboxClicked: function()
- {
- var allChecked = true;
- $('.fl-module-cb').each(function() {
- if(!$(this).is(':checked')) {
- allChecked = false;
- }
- });
- if(allChecked) {
- $('.fl-module-all-cb').prop('checked', true);
- }
- else {
- $('.fl-module-all-cb').prop('checked', false);
- }
- },
- /**
- * @since 1.7.4
- * @access private
- * @method _initLicenseSettings
- */
- _initLicenseSettings: function()
- {
- $( '.fl-new-license-form .button' ).on( 'click', FLBuilderAdminSettings._newLicenseButtonClick );
- },
- /**
- * @since 1.7.4
- * @access private
- * @method _newLicenseButtonClick
- */
- _newLicenseButtonClick: function()
- {
- $( '.fl-new-license-form' ).hide();
- $( '.fl-license-form' ).show();
- },
- /**
- * Fires when the templates override setting is changed.
- *
- * @since 1.6.3
- * @access private
- * @method _templatesOverrideChange
- */
- _templatesOverrideChange: function()
- {
- var input = $('input[name=fl-templates-override]'),
- val = input.val(),
- overrideNodes = $( '.fl-templates-override-nodes' ),
- toggle = false;
- if ( 'checkbox' == input.attr( 'type' ) ) {
- toggle = input.is( ':checked' );
- }
- else {
- toggle = '' !== val;
- }
- overrideNodes.toggle( toggle );
- },
- /**
- * Shows the media library lightbox for uploading icons.
- *
- * @since 1.4.6
- * @access private
- * @method _showIconUploader
- */
- _showIconUploader: function()
- {
- if(FLBuilderAdminSettings._iconUploader === null) {
- FLBuilderAdminSettings._iconUploader = wp.media({
- title: FLBuilderAdminSettingsStrings.selectFile,
- button: { text: FLBuilderAdminSettingsStrings.selectFile },
- library : { type : 'application/zip' },
- multiple: false
- });
- }
- FLBuilderAdminSettings._iconUploader.once('select', $.proxy(FLBuilderAdminSettings._iconFileSelected, this));
- FLBuilderAdminSettings._iconUploader.open();
- },
- /**
- * Callback for when an icon set file is selected.
- *
- * @since 1.4.6
- * @access private
- * @method _iconFileSelected
- */
- _iconFileSelected: function()
- {
- var file = FLBuilderAdminSettings._iconUploader.state().get('selection').first().toJSON();
- $( 'input[name=fl-new-icon-set]' ).val( file.id );
- $( '#icons-form' ).submit();
- },
- /**
- * Fires when the delete link for an icon set is clicked.
- *
- * @since 1.4.6
- * @access private
- * @method _deleteCustomIconSet
- */
- _deleteCustomIconSet: function()
- {
- var set = $( this ).data( 'set' );
- $( 'input[name=fl-delete-icon-set]' ).val( set );
- $( '#icons-form' ).submit();
- },
- /**
- * Fires when the uninstall button is clicked.
- *
- * @since 1.0
- * @access private
- * @method _uninstallFormSubmit
- * @return {Boolean}
- */
- _uninstallFormSubmit: function()
- {
- var result = prompt(FLBuilderAdminSettingsStrings.uninstall.replace(/"/g, '"'), '');
- if(result == 'uninstall') {
- return true;
- }
- return false;
- },
- _iconPro: function() {
- form = $('#icons-form')
- checkbox = form.find('input[name=fl-enable-fa-pro]').prop('checked')
- light = form.find('input[value=font-awesome-5-light]').parent()
- duo = form.find('input[value=font-awesome-5-duotone]').parent()
- if ( true === checkbox ) {
- light.css('font-weight', '800')
- // light.css('color', '#0E5A71')
- duo.css('font-weight', '800')
- // duo.css('color', '#0E5A71')
- }
- },
- _alphaSettings: function() {
- form = $('#beta-form');
- form.find('.alpha-checkbox').on('click', function(){
- console.log('checked?')
- if ( true === $(this).prop('checked') ) {
- if ( confirm( 'Are you sure you want to enable Alpha releases?') ) {
- // do nothing
- } else {
- $(this).prop('checked',false);
- }
- }
- })
- },
- };
- /* Initializes the builder's admin settings. */
- $(function(){
- FLBuilderAdminSettings.init();
- });
- })(jQuery);
|