/* Copyright (C) YOOtheme GmbH, http://www.gnu.org/licenses/gpl.html GNU/GPL */

(function(a,k,h){a(function(){var b=a("#config"),e=Joomla.submitbutton;a(".nav-tabs").on("click","[data-toggle]",function(){h._tab=a(this).attr("href")});setTimeout(function(){h._tab&&a(".nav-tabs [href='"+h._tab+"']").trigger("click")},1);Joomla.submitbutton=function(a){"style.save"==a?f.save("save",a):"style.save2copy"==a?f.save("save-copy",a):"style.apply"==a?f.save("apply",a):e(a)};a("#templatestyleOptions").length?b.closest("#templatestyleOptions").before(b).remove():b.closest("#attrib-options").find("div:first").before(b).hide();
setTimeout(function(){b.find(".chzn-container").each(function(){a(this).prev().show().end().remove()})},200)});var f={save:function(b,e){var c={},g=a('form[name="adminForm"]'),d=g.find("#jform_template").val(),j=a("#toolbar-"+b);j.addClass("saving");parse_str(a(":input","#config").serialize(),c);a.ajax({url:g.attr("action"),type:"post",data:{option:"com_templates",template:d,callback:"config",tmpl:"warp-ajax",config:JSON.stringify(c,null,"\t")},success:function(b){j.removeClass("saving");try{if(b=
a.parseJSON(b),"success"!=b.message){alert("Save failed!");return}}catch(d){}submitbutton(e)}})},saveFiles:function(b){var e=a.Deferred(),c=a('form[name="adminForm"]'),g=c.find("#jform_template").val(),d=new FormData;d.append("option","com_templates");d.append("template",g);d.append("callback","files");d.append("tmpl","warp-ajax");d.append("no_html",1);d.append("files",new Blob([JSON.stringify(b)],{type:"application/json"}));a.ajax({url:c.attr("action"),type:"POST",data:d,processData:!1,contentType:!1}).always(function(b,
d,g){var c=!1;if("error"==d)c=g;else try{b=a.parseJSON(b),"success"!=b.message&&(c=b.message)}catch(f){c="Saving failed!"}e[c?"reject":"resolve"](c)});return e.promise()},data:function(){var b=a.Deferred(),e=a('form[name="adminForm"]'),c=e.find("#jform_template").val();a.ajax({url:e.attr("action"),type:"post",data:{option:"com_templates",template:c,callback:"styles",tmpl:"warp-ajax",no_html:1}}).always(function(c,d,e){var f=!1;if("error"==d)f=e;else try{if(c=a.parseJSON(c),"error"==c.message)f=c.message;
else{b.resolve(c);return}}catch(h){f="Retrieving styles data failed!"}b.reject(f)});return b.promise()}};k.System=f})(jQuery,this,window.sessionStorage||{});
