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

(function(a,k,h){a(function(){var d=a("#config"),e=Joomla.submitbutton;Joomla.submitbutton=function(a){"style.save"==a?g.save("save",a):"style.save2copy"==a?g.save("save-copy",a):"style.apply"==a?g.save("apply",a):e(a)};var c=a("#element-box"),b=a('<div style="padding: 0 10px;">                <ul class="uk-tab" style="font-size: 14px;" data-uk-tab="{connect: \'#warp-tabs\'}">                    <li><a href="#details">Details</a></li>                    <li class="uk-active"><a href="#options">Options</a></li>                </ul>                <ul id="warp-tabs" class="uk-switcher uk-margin">                    <li id="details"></li>                    <li id="options"></li>                </ul>            </div>').insertBefore(c);
a("#details").append(a("div.width-60",c));a("#options").append(d);b.wrap(a("form",c).empty());c.remove();b.on("click",".uk-tab a",function(){h._tab=a(this).attr("href")});setTimeout(function(){h._tab&&a(".uk-tab [href='"+h._tab+"']",b).trigger("click")},1)});var g={save:function(d,e){var c={},b=a('form[name="adminForm"]'),f=b.find("#jform_template").val(),j=a("#toolbar-"+d);j.addClass("saving");parse_str(a(":input","#config").serialize(),c);a.ajax({url:b.attr("action"),type:"post",data:{option:"com_templates",
template:f,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(c){}submitbutton(e)}})},saveFiles:function(d){var e=a.Deferred(),c=a('form[name="adminForm"]'),b=c.find("#jform_template").val(),f=new FormData;f.append("option","com_templates");f.append("template",b);f.append("callback","files");f.append("tmpl","warp-ajax");f.append("files",new Blob([JSON.stringify(d)],
{type:"application/json"}));a.ajax({url:c.attr("action"),type:"POST",data:f,processData:!1,contentType:!1}).always(function(b,c,f){var d=!1;if("error"==c)d=f;else try{b=a.parseJSON(b),"success"!=b.message&&(d=b.message)}catch(g){d="Saving failed!"}e[d?"reject":"resolve"](d)});return e.promise()},data:function(){var d=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"}}).always(function(b,
c,e){var g=!1;if("error"==c)g=e;else try{if(b=a.parseJSON(b),"error"==b.message)g=b.message;else{d.resolve(b);return}}catch(h){g="Retrieving styles data failed!"}d.reject(g)});return d.promise()}};k.System=g})(jQuery,this,window.sessionStorage||{});
