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