(function(c){redux.field_objects=redux.field_objects||{};redux.field_objects.typography=redux.field_objects.typography||{};var d=[];var a=false;var b={width:"resolve",triggerChange:true,allowClear:true};redux.field_objects.typography.init=function(e,f){if(!e){e=c(document).find(".redux-group-tab:visible").find(".redux-container-typography:visible")}c(e).each(function(){var i=c(this);var h=i;if(!i.hasClass("redux-field-container")){h=i.parents(".redux-field-container:first")}if(h.is(":hidden")){return}if(h.hasClass("redux-field-init")){h.removeClass("redux-field-init")}else{return}var g;i.each(function(){c(this).find(".redux-typography-container").each(function(){var n=c(this).find(".redux-typography-family");if(n.data("value")===undefined){n=c(this)}else{if(n.data("value")!==""){c(n).val(n.data("value"))}}var l=c(this).find(".select2_params");if(l.size()>0){var m=l.val();m=JSON.parse(m);b=c.extend({},b,m)}g=Boolean(c(this).find(".redux-font-clear").val());redux.field_objects.typography.select(n,true);window.onbeforeunload=null});c(this).find(".redux-typography").on("change",function(){redux.field_objects.typography.select(c(this))});c(this).find(".redux-typography-size, .redux-typography-height, .redux-typography-word, .redux-typography-letter, .redux-typography-align, .redux-typography-transform, .redux-typography-font-variant, .redux-typography-decoration").keyup(function(){redux.field_objects.typography.select(c(this).parents(".redux-container-typography:first"))});c(this).find(".redux-typography-color").wpColorPicker({change:function(m,l){c(this).val(l.color.toString());redux.field_objects.typography.select(c(this))}});c(this).find(".redux-typography-size").numeric({allowMinus:false});c(this).find(".redux-typography-height, .redux-typography-word, .redux-typography-letter").numeric({allowMinus:true});var j=[{id:"none",text:"none"}];c(this).find(".redux-typography-family").select2({matcher:function(l,m){return m.toUpperCase().indexOf(l.toUpperCase())===0},query:function(l){return window.Select2.query.local(j)(l)},initSelection:function(l,n){var m={id:l.val(),text:l.val()};n(m)},allowClear:g}).on("select2-opening",function(r){var u=c(this).parents(".redux-container-typography:first").attr("data-id");var n=c("#"+u+" .redux-typography-font-family").data("user-fonts");n=n?1:0;var o=c("#"+u+" .redux-typography-google").val();o=o?1:0;var s=[];if(redux.customfonts!==undefined){s.push(redux.customfonts)}if(redux.stdfonts!==undefined&&n===0){s.push(redux.stdfonts)}if(n==1){var m=[];for(var v in redux.typography[u]){var q=redux.typography[u].std_font;for(var l in q){if(q.hasOwnProperty(l)){m.push({id:l,text:l,"data-google":"false"})}}}var p={text:"Standard Fonts",children:m};s.push(p)}if(o==1||o===true&&redux.googlefonts!==undefined){s.push(redux.googlefonts)}j=s;var t=c("#"+u+" #"+u+"-family").attr("placeholder");if(!t){t=null}c("#"+u+" .redux-typography-family").select2("val",t)}).on("select2-selecting",function(n,l){var m=n.object.text;var o=c(this).parents(".redux-container-typography:first").attr("data-id");c("#"+o+" #"+o+"-family").data("value",m);c("#"+o+" #"+o+"-family").attr("placeholder",m);d=n;a=true;redux.field_objects.typography.select(c(this).parents(".redux-container-typography:first"))}).on("select2-clearing",function(m,l){var n=c(this).parents(".redux-container-typography:first").attr("data-id");c("#"+n+" #"+n+"-family").attr("data-value","");c("#"+n+" #"+n+"-family").attr("placeholder","Font Family");c("#"+n+" #"+n+"-google-font").val("false");redux.field_objects.typography.select(c(this).parents(".redux-container-typography:first"))});var k=i.find(".redux-typography-family");if(!k.hasClass("redux-typography-family")){i.find(".redux-typography-style").select2(b)}i.find(".redux-typography-family-backup, .redux-typography-align, .redux-typography-transform, .redux-typography-font-variant, .redux-typography-decoration").select2(b)})})};redux.field_objects.typography.size=function(g){var f=0,e;for(e in g){if(g.hasOwnProperty(e)){f++}}return f};redux.field_objects.typography.makeBool=function(e){if(e=="false"||e=="0"||e===false||e===0){return false}else{if(e=="true"||e=="1"||e===true||e==1){return true}}};redux.field_objects.typography.contrastColour=function(j){var k="#444444";if(j!==""){j=j.replace("#","");var i=parseInt(j.substr(0,2),16);var h=parseInt(j.substr(2,2),16);var e=parseInt(j.substr(4,2),16);var f=((i*299)+(h*587)+(e*114))/1000;k=(f>=128)?"#444444":"#ffffff"}return k};redux.field_objects.typography.select=function(w,k){var e;e=c(w).parents(".redux-container-typography:first").attr("data-id");if(e===undefined){e=c(w).attr("data-id")}var m=c(w).parents(".redux-container-typography:first");var E=[];var B=c("#"+e+" #"+e+"-family").val();if(!B){B=null}var f=c("#"+e+" select.redux-typography-family-backup").val();var q=c("#"+e+" .redux-typography-size").val();var r=c("#"+e+" .redux-typography-height").val();var z=c("#"+e+" .redux-typography-word").val();var D=c("#"+e+" .redux-typography-letter").val();var v=c("#"+e+" select.redux-typography-align").val();var p=c("#"+e+" select.redux-typography-transform").val();var i=c("#"+e+" select.redux-typography-font-variant").val();var l=c("#"+e+" select.redux-typography-decoration").val();var y=c("#"+e+" select.redux-typography-style").val();var C=c("#"+e+" select.redux-typography-subsets").val();var u=c("#"+e+" .redux-typography-color").val();var t=c("#"+e).data("units");var g;if(a===true){g=redux.field_objects.typography.makeBool(d.object["data-google"]);c("#"+e+" .redux-typography-google-font").val(g)}else{g=redux.field_objects.typography.makeBool(c("#"+e+" .redux-typography-google-font").val())}if(!c("#"+e).hasClass("typography-initialized")){y=c("#"+e+" select.redux-typography-style").data("value");C=c("#"+e+" select.redux-typography-subsets").data("value");if(y!==""){y=String(y)}if(typeof(C)!==undefined){C=String(C)}}if(redux.fonts.google===undefined){g=false}var A="";if(g===true&&(B in redux.fonts.google)){A=redux.fonts.google[B]}else{A={"400":"Normal 400","700":"Bold 700","400italic":"Normal 400 Italic","700italic":"Bold 700 Italic"}}if(c(w).hasClass("redux-typography-subsets")){c("#"+e+" input.typography-subsets").val(C)}if(c(w).hasClass("redux-typography-family")){var o='';if(g===true){var s="";c.each(A.variants,function(F,G){if(G.id===y||redux.field_objects.typography.size(A.variants)===1){s=' selected="selected"';y=G.id}else{s=""}o+='"});c("#"+e+" .redux-typography-style").select2("destroy");c("#"+e+" .redux-typography-style").html(o);c("#"+e+" .redux-typography-style").select2(b);s="";o='';c.each(A.subsets,function(F,G){if(G.id===C||redux.field_objects.typography.size(A.subsets)===1){s=' selected="selected"';C=G.id;c("#"+e+" input.typography-subsets").val(C)}else{s=""}o+='"});c("#"+e+" .redux-typography-subsets").select2("destroy");c("#"+e+" .redux-typography-subsets").html(o);c("#"+e+" .redux-typography-subsets").select2(b);c("#"+e+" .redux-typography-subsets").parent().fadeIn("fast");c("#"+e+" .typography-family-backup").fadeIn("fast")}else{if(A){c.each(A,function(F,G){if(F===y||F==="normal"){s=' selected="selected"';c("#"+e+" .typography-style .select2-chosen").text(G)}else{s=""}o+='"});c("#"+e+" .redux-typography-style").select2("destroy");c("#"+e+" .redux-typography-style").html(o);c("#"+e+" .redux-typography-style").select2(b);c("#"+e+" .redux-typography-subsets").parent().fadeOut("fast");c("#"+e+" .typography-family-backup").fadeOut("fast")}}c("#"+e+" .redux-typography-font-family").val(B)}else{if(c(w).hasClass("redux-typography-family-backup")&&f!==""){c("#"+e+" .redux-typography-font-family-backup").val(f)}}if(c("#"+e+" select.redux-typography-style option[value='"+y+"']").length===0){y="";c("#"+e+" select.redux-typography-style").select2("val","")}else{if(y==="400"){c("#"+e+" select.redux-typography-style").select2("val",y)}}if(c("#"+e+" select.redux-typography-subsets option[value='"+C+"']").length===0){C="";c("#"+e+" select.redux-typography-subsets").select2("val","");c("#"+e+" input.typography-subsets").val(C)}var x="style_link_"+e;c("."+x).remove();if(B!==null&&B!=="inherit"&&c("#"+e).hasClass("typography-initialized")){var h=B.replace(/\s+/g,"+");if(g===true){var j=h;if(y&&y!==""){j+=":"+y.replace(/\-/g," ")}if(C&&C!==""){j+="&subset="+C}if(a===false){if(typeof(WebFont)!=="undefined"&&WebFont){WebFont.load({google:{families:[j]}})}}c("#"+e+" .redux-typography-google").val(true)}else{c("#"+e+" .redux-typography-google").val(false)}}if(y.indexOf("italic")!==-1){c("#"+e+" .typography-preview").css("font-style","italic");c("#"+e+" .typography-font-style").val("italic");y=y.replace("italic","")}else{c("#"+e+" .typography-preview").css("font-style","normal");c("#"+e+" .typography-font-style").val("")}c("#"+e+" .typography-font-weight").val(y);if(!r){r=q}if(q===""||q===undefined){c("#"+e+" .typography-font-size").val("")}else{c("#"+e+" .typography-font-size").val(q+t)}if(r===""||r===undefined){c("#"+e+" .typography-line-height").val("")}else{c("#"+e+" .typography-line-height").val(r+t)}if(z===""||z===undefined){c("#"+e+" .typography-word-spacing").val("")}else{c("#"+e+" .typography-word-spacing").val(z+t)}if(D===""||D===undefined){c("#"+e+" .typography-letter-spacing").val("")}else{c("#"+e+" .typography-letter-spacing").val(D+t)}if(c("#"+e).hasClass("typography-initialized")){var n=c("#"+e+" .typography-preview").data("preview-size");if(n=="0"){c("#"+e+" .typography-preview").css("font-size",q+t)}c("#"+e+" .typography-preview").css("font-weight",y);c("#"+e+" .typography-preview").css("font-family",B+", sans-serif");if(B==="none"&&B===""){c("#"+e+" .typography-preview").css("font-family","inherit")}c("#"+e+" .typography-preview").css("line-height",r+t);c("#"+e+" .typography-preview").css("word-spacing",z+t);c("#"+e+" .typography-preview").css("letter-spacing",D+t);if(u){c("#"+e+" .typography-preview").css("color",u);c("#"+e+" .typography-preview").css("background-color",redux.field_objects.typography.contrastColour(u))}c("#"+e+" .typography-style .select2-chosen").text(c("#"+e+" .redux-typography-style option:selected").text());c("#"+e+" .typography-script .select2-chosen").text(c("#"+e+" .redux-typography-subsets option:selected").text());if(v){c("#"+e+" .typography-preview").css("text-align",v)}if(p){c("#"+e+" .typography-preview").css("text-transform",p)}if(i){c("#"+e+" .typography-preview").css("font-variant",i)}if(l){c("#"+e+" .typography-preview").css("text-decoration",l)}c("#"+e+" .typography-preview").slideDown()}if(!c("#"+e).hasClass("typography-initialized")){c("#"+e).addClass("typography-initialized")}a=false;if(!k){redux_change(w)}}})(jQuery);