!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,f){e||(e=a(document).find(".redux-group-tab:visible").find(".redux-container-typography:visible")),a(e).each(function(){var e=a(this),f=e;if(e.hasClass("redux-field-container")||(f=e.parents(".redux-field-container:first")),!f.is(":hidden")&&f.hasClass("redux-field-init")){f.removeClass("redux-field-init");var g;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)}g=Boolean(a(this).find(".redux-font-clear").val()),redux.field_objects.typography.select(b,!0),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){a(this).val(c.color.toString()),redux.field_objects.typography.select(a(this).parents(".redux-container-typography:first"))}}),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)},allowClear:g}).on("select2-opening",function(b){var c=a(this).parents(".redux-container-typography:first").attr("data-id"),d=a("#"+c+" .redux-typography-font-family").data("user-fonts");d=d?1:0;var e=a("#"+c+" .redux-typography-google").val();e=e?1:0;var g=[];if(void 0!==redux.customfonts&&g.push(redux.customfonts),void 0!==redux.stdfonts&&0===d&&g.push(redux.stdfonts),1==d){var h=[];for(var i in redux.typography[c]){var j=redux.typography[c].std_font;for(var k in j)j.hasOwnProperty(k)&&h.push({id:k,text:k,"data-google":"false"})}var l={text:"Standard Fonts",children:h};g.push(l)}(1==e||e===!0&&void 0!==redux.googlefonts)&&g.push(redux.googlefonts),f=g;var m=a("#"+c+" #"+c+"-family").attr("placeholder");m||(m=null),a("#"+c+" .redux-typography-family").select2("val",m)}).on("select2-selecting",function(d,e){var f=d.object.text,g=a(this).parents(".redux-container-typography:first").attr("data-id");a("#"+g+" #"+g+"-family").data("value",f),a("#"+g+" #"+g+"-family").attr("placeholder",f),b=d,c=!0,redux.field_objects.typography.select(a(this).parents(".redux-container-typography:first"))}).on("select2-clearing",function(b,c){var d=a(this).parents(".redux-container-typography:first").attr("data-id");a("#"+d+" #"+d+"-family").attr("data-value",""),a("#"+d+" #"+d+"-family").attr("placeholder","Font Family"),a("#"+d+" #"+d+"-google-font").val("false"),redux.field_objects.typography.select(a(this).parents(".redux-container-typography:first"))});var h=e.find(".redux-typography-family");h.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,f){var g;g=a(e).parents(".redux-container-typography:first").attr("data-id"),void 0===g&&(g=a(e).attr("data-id"));var h=(a(e).parents(".redux-container-typography:first"),a("#"+g+" #"+g+"-family").val());h||(h=null);var i,j=a("#"+g+" select.redux-typography-family-backup").val(),k=a("#"+g+" .redux-typography-size").val(),l=a("#"+g+" .redux-typography-height").val(),m=a("#"+g+" .redux-typography-word").val(),n=a("#"+g+" .redux-typography-letter").val(),o=a("#"+g+" select.redux-typography-align").val(),p=a("#"+g+" select.redux-typography-transform").val(),q=a("#"+g+" select.redux-typography-font-variant").val(),r=a("#"+g+" select.redux-typography-decoration").val(),s=a("#"+g+" select.redux-typography-style").val(),t=a("#"+g+" select.redux-typography-subsets").val(),u=a("#"+g+" .redux-typography-color").val(),v=a("#"+g).data("units");c===!0?(i=redux.field_objects.typography.makeBool(b.object["data-google"]),a("#"+g+" .redux-typography-google-font").val(i)):i=redux.field_objects.typography.makeBool(a("#"+g+" .redux-typography-google-font").val()),a("#"+g).hasClass("typography-initialized")||(s=a("#"+g+" select.redux-typography-style").data("value"),t=a("#"+g+" select.redux-typography-subsets").data("value"),""!==s&&(s=String(s)),void 0!==typeof t&&(t=String(t))),void 0===redux.fonts.google&&(i=!1);var w="";if(w=i===!0&&h in redux.fonts.google?redux.fonts.google[h]:{400:"Normal 400",700:"Bold 700","400italic":"Normal 400 Italic","700italic":"Bold 700 Italic"},a(e).hasClass("redux-typography-subsets")&&a("#"+g+" input.typography-subsets").val(t),a(e).hasClass("redux-typography-family")){var x='';if(i===!0){var y="";a.each(w.variants,function(a,b){b.id===s||1===redux.field_objects.typography.size(w.variants)?(y=' selected="selected"',s=b.id):y="",x+='"}),a("#"+g+" .redux-typography-style").select2("destroy"),a("#"+g+" .redux-typography-style").html(x),a("#"+g+" .redux-typography-style").select2(d),y="",x='',a.each(w.subsets,function(b,c){c.id===t||1===redux.field_objects.typography.size(w.subsets)?(y=' selected="selected"',t=c.id,a("#"+g+" input.typography-subsets").val(t)):y="",x+='"}),a("#"+g+" .redux-typography-subsets").select2("destroy"),a("#"+g+" .redux-typography-subsets").html(x),a("#"+g+" .redux-typography-subsets").select2(d),a("#"+g+" .redux-typography-subsets").parent().fadeIn("fast"),a("#"+g+" .typography-family-backup").fadeIn("fast")}else w&&(a.each(w,function(b,c){b===s||"normal"===b?(y=' selected="selected"',a("#"+g+" .typography-style .select2-chosen").text(c)):y="",x+='"}),a("#"+g+" .redux-typography-style").select2("destroy"),a("#"+g+" .redux-typography-style").html(x),a("#"+g+" .redux-typography-style").select2(d),a("#"+g+" .redux-typography-subsets").parent().fadeOut("fast"),a("#"+g+" .typography-family-backup").fadeOut("fast"));a("#"+g+" .redux-typography-font-family").val(h)}else a(e).hasClass("redux-typography-family-backup")&&""!==j&&a("#"+g+" .redux-typography-font-family-backup").val(j);0===a("#"+g+" select.redux-typography-style option[value='"+s+"']").length?(s="",a("#"+g+" select.redux-typography-style").select2("val","")):"400"===s&&a("#"+g+" select.redux-typography-style").select2("val",s),0===a("#"+g+" select.redux-typography-subsets option[value='"+t+"']").length&&(t="",a("#"+g+" select.redux-typography-subsets").select2("val",""),a("#"+g+" input.typography-subsets").val(t));var z="style_link_"+g;if(a("."+z).remove(),null!==h&&"inherit"!==h&&a("#"+g).hasClass("typography-initialized")){var A=h.replace(/\s+/g,"+");if(i===!0){var B=A;s&&""!==s&&(B+=":"+s.replace(/\-/g," ")),t&&""!==t&&(B+="&subset="+t),c===!1&&"undefined"!=typeof WebFont&&WebFont&&WebFont.load({google:{families:[B]}}),a("#"+g+" .redux-typography-google").val(!0)}else a("#"+g+" .redux-typography-google").val(!1)}if(-1!==s.indexOf("italic")?(a("#"+g+" .typography-preview").css("font-style","italic"),a("#"+g+" .typography-font-style").val("italic"),s=s.replace("italic","")):(a("#"+g+" .typography-preview").css("font-style","normal"),a("#"+g+" .typography-font-style").val("")),a("#"+g+" .typography-font-weight").val(s),l||(l=k),""===k||void 0===k?a("#"+g+" .typography-font-size").val(""):a("#"+g+" .typography-font-size").val(k+v),""===l||void 0===l?a("#"+g+" .typography-line-height").val(""):a("#"+g+" .typography-line-height").val(l+v),""===m||void 0===m?a("#"+g+" .typography-word-spacing").val(""):a("#"+g+" .typography-word-spacing").val(m+v),""===n||void 0===n?a("#"+g+" .typography-letter-spacing").val(""):a("#"+g+" .typography-letter-spacing").val(n+v),a("#"+g).hasClass("typography-initialized")){var C=a("#"+g+" .typography-preview").data("preview-size");"0"==C&&a("#"+g+" .typography-preview").css("font-size",k+v),a("#"+g+" .typography-preview").css("font-weight",s),a("#"+g+" .typography-preview").css("font-family",h+", sans-serif"),"none"===h&&""===h&&a("#"+g+" .typography-preview").css("font-family","inherit"),a("#"+g+" .typography-preview").css("line-height",l+v),a("#"+g+" .typography-preview").css("word-spacing",m+v),a("#"+g+" .typography-preview").css("letter-spacing",n+v),u&&(a("#"+g+" .typography-preview").css("color",u),a("#"+g+" .typography-preview").css("background-color",redux.field_objects.typography.contrastColour(u))),a("#"+g+" .typography-style .select2-chosen").text(a("#"+g+" .redux-typography-style option:selected").text()),a("#"+g+" .typography-script .select2-chosen").text(a("#"+g+" .redux-typography-subsets option:selected").text()),o&&a("#"+g+" .typography-preview").css("text-align",o),p&&a("#"+g+" .typography-preview").css("text-transform",p),q&&a("#"+g+" .typography-preview").css("font-variant",q),r&&a("#"+g+" .typography-preview").css("text-decoration",r),a("#"+g+" .typography-preview").slideDown()}a("#"+g).hasClass("typography-initialized")||a("#"+g).addClass("typography-initialized"),c=!1,f||redux_change(e)}}(jQuery);