1
|
|
|
!function(t,i){var e;void 0===i.Amarkal?(e={},i.Amarkal=e):e=i.Amarkal,e.settings={init:function(){t(".amarkal-ui-component").on("amarkal.change",function(t,i){e.settings.notifier.notice('Settings have changed, click "Save" to apply them.'),e.settings.sections.flag("notice",i.props.section)}),e.settings.search.init(),e.settings.sections.init()}},t(document).ready(function(){e.settings.init()}),e.settings.notifier={classes:["error","success","notice","info"],prefix:"amarkal-",timeout:null,$el:null,notify:function(t,i,s){clearTimeout(e.settings.notifier.timeout),e.settings.notifier.$el.removeAttr("class").addClass(e.settings.notifier.prefix+t).html("<p>"+i+"</p>"),void 0!==s&&(e.settings.notifier.timeout=setTimeout(function(){e.settings.notifier.$el.removeAttr("class").html("")},s))},error:function(t,i){e.settings.notifier.notify("error",t,i)},success:function(t,i){e.settings.notifier.notify("success",t,i)},notice:function(t,i){e.settings.notifier.notify("notice",t,i)},info:function(t,i){e.settings.notifier.notify("info",t,i)},init:function(){this.$el=t("#amarkal-settings-notices")}},t(document).ready(function(){e.settings.notifier.init()}),e.settings.search={$fields:null,$input:null,init:function(){this.$fields=t(".amarkal-settings-field"),this.$input=t("#settings-search"),this.$input.on("keyup",this.onKeyup.bind(this))},onKeyup:function(i){var s,n=this.$input.val().toLowerCase(),a=e.settings.sections.activeSection;n.length>0?(s=this.find(n),e.settings.sections.deactivate(),e.settings.header.setSectionTitle("Field Search Results"),e.settings.header.setSectionSubtitle(""),s.addClass("visible"),t("#settings-search-results").addClass("visible").text(s.length?s.length+" settings found":"Nothing found")):(t("#settings-search-results").removeClass("visible").text(""),e.settings.sections.activate(a))},find:function(i){var e=[];return this.$fields.each(function(){var s=t(this),n=s.find("h3").text().toLowerCase(),a=s.find(".help-content").text();description=s.find(".description").text(),(n.match(i)||description.match(i)||a.match(i))&&e.push(s)}),t(e).map(function(){return this.toArray()})}},e.settings.sections={$fields:null,$links:null,$loader:null,sections:null,activeSection:null,init:function(){this.sections=JSON.parse(t("#sections-config").text()),this.$fields=t(".amarkal-settings-field"),this.$links=t(".amarkal-settings-sections li"),this.$loader=t("#amarkal-settings-loader"),this.initSections()},initSections:function(){if("object"==typeof this.sections&&Object.keys(this.sections).length>0){var i=this;this.$links.on("click",function(){i.activate(t(this).attr("data-slug"))}),this.activateInitialSection(),this.$loader.hide()}else this.$fields.addClass("visible")},activateInitialSection:function(){""!==window.location.hash?this.activate(window.location.hash.substring(1)):this.activate(t(this.$links[0]).attr("data-slug"))},activate:function(i){this.$links.each(function(){t(this).removeClass("active"),t(this).attr("data-slug")===i&&t(this).addClass("active")}),this.$fields.removeClass("visible"),e.settings.header.setSectionTitle(this.getTitle(i)),e.settings.header.setSectionSubtitle(this.getSubtitle(i)),this.activeSection=i,t('.amarkal-settings-field[data-section="'+i+'"]').addClass("visible").find(".amarkal-ui-component").amarkalUIComponent("refresh"),window.location="#"+i},deactivate:function(){this.activeSection;this.$links.removeClass("active"),this.$fields.removeClass("visible")},flag:function(t,i){this.$links.filter('[data-slug="'+i+'"]').addClass("flag-"+t)},unflagAll:function(){this.$links.removeClass("flag-error flag-notice")},getTitle:function(t){return this.sections[t].title},getSubtitle:function(t){return this.sections[t].subtitle}},e.settings.header={setSectionTitle:function(i){t("#amarkal-settings-sec-title").text(i)},setSectionSubtitle:function(i){t("#amarkal-settings-sec-subtitle").text(i)}},t(document).ready(function(){t(".amarkal-settings-button").on("click",function(i){i.preventDefault();var s=t(this);s.data("disabled")||(t(".amarkal-settings-button").data("disabled",!0),s.addClass("processing"),e.settings[s.val()](function(){s.removeClass("processing"),t(".amarkal-settings-button").data("disabled",!1)}))})}),e.settings.save=function(i){e.settings._postData("save",function(s){if(e.settings._clearNotices(),t.isEmptyObject(s.errors))e.settings.notifier.success("Settings saved",3e3);else{for(var n in s.errors){var a=t('[amarkal-component-name="'+n+'"]'),o=a.amarkalUIComponent("instance");a.amarkalUIComponent("makeInvalid"),a.parent().children(".amarkal-settings-error").addClass("amarkal-visible").html(s.errors[n])}e.settings.notifier.error("Some errors have occured, see below for more information."),e.settings.sections.flag("error",o.props.section)}t("#amarkal-settings-form").amarkalUIForm("setData",s.values,s.errors),i()})},e.settings.resetAll=function(i){e.settings._postData("reset_all",function(s){e.settings._clearNotices(),e.settings.notifier.success("Default settings applied",3e3),t("#amarkal-settings-form").amarkalUIForm("setData",s.values,s.errors),i()})},e.settings.resetSection=function(i){e.settings._postData("reset_section",function(s){e.settings._clearNotices(),e.settings.notifier.success("Default settings applied for the section <strong>"+e.settings.sections.getTitle(e.settings.sections.activeSection)+"</strong>",3e3),t("#amarkal-settings-form").amarkalUIForm("setData",s.values,s.errors),i()})},e.settings._clearNotices=function(){t(".amarkal-ui-component").amarkalUIComponent("reset"),t(".amarkal-settings-error").removeClass("amarkal-visible").html(""),e.settings.sections.unflagAll()},e.settings._postData=function(i,s){var n=t("#amarkal-settings-form").amarkalUIForm("getData");t("#amarkal-settings-form").find('input[name^="_amarkal"]').each(function(){n[t(this).attr("name")]=t(this).val()}),n._amarkal_settings_section=e.settings.sections.activeSection,t.post(ajaxurl,{action:"amarkal_settings_"+i,data:n},s)}}(jQuery,window); |