!function($){var t;return t={},$.widget("webfont.wfselect",{options:{fonts:{google:{families:["Droid Sans","Signika"]}},merge_list:!1},_create:function(){var t,n,e,i;e=this,n=this.options,t=this.element,i=n.fonts||this.options.fonts,t.addClass("webfont-input").attr("readonly","readonly").wrap($("<div/>").addClass("webfont-wrapper")),this.wrapper=t.closest(".webfont-wrappers"),t.after(e._createFontList(i,this.options.merge_list).hide()),e._selectFontByName(t.val()),e.toggle=$("<div/>").addClass("ui-icon ui-icon-triangle-1-s").insertAfter(t),e._bindHandlers()},_createFontList:function(t,n){var e,i;return null==n&&(n=!1),this.fontList=$("<ul/>").addClass("webfont-list"),i=this,e=this._createFontObjects(t,n),$.each(e,function(t,n){$("<li/>").html(n.font).data("font_name",n.font).data("font_type",n.type).css(i._fontToStyle(n.font)).appendTo(i.fontList)}),this.fontList},_createFontObjects:function(t,n){var e;return null==n&&(n=!1),e=[],$.each(t,function(t,n){var i;i=n.families.map(function(n){return{font:n,type:t}}),e=e.concat(i)}),n&&(e=e.sort(function(t,n){return t.font>n.font})),e},_fontToStyle:function(t){var n;return n=t.split(":"),{"font-family":this._readableFontName(n[0]),"font-weight":n[1]||400}},_readableFontName:function(t){return t.replace(/[\+|:]/g," ")},_selectFontByName:function(t){var n,e;return n=this.fontList.find("li"),e=$.grep(n,function(n,e){return $(n).data("font_name")===t}),!!e.length&&(this._selectFontListItem($(e).first()),!0)},_selectFontListItem:function(t){var n,e,i;return t.hasClass("selected")?null:(this.fontList.find("li.selected").removeClass("selected"),t=$(t).addClass("selected"),n=t.data("font_name"),e=t.data("font_type"),i=this._fontToStyle(n),this.element.css(i),this.element.val()!==n&&this.element.val(n).trigger("change"),this._trigger("change",null,i),this._loadFonts([{font:n,type:e}]),void this._toggleFontList(!1))},_loadFonts:function(n){var e,i;return e=$.grep(n,function(e){return t[n.font]},!0),e.length?(i={},$.each(e,function(n,e){t[e.font]=!0,Object.keys(i).indexOf(e.type)===-1&&(i[e.type]={}),Object.keys(i[e.type]).indexOf("families")===-1&&(i[e.type].families=[]),i[e.type].families.push(e.font)}),void WebFont.load(i)):null},_loadVisibleFonts:function(){var t,n,e,i,o,s;return this.fontList.is(":visible")?(s=this,o=this.fontList.scrollTop(),i=this.fontList.height(),e=o+i,t=this.fontList.find("li"),n=[],$.each(t,function(t,e){var o,s;e=$(e),s=e.position().top,o=s+e.outerHeight(),o>=0&&s<i&&n.push({font:e.data("font_name"),type:e.data("font_type")})}),void this._loadFonts(n)):null},_toggleFontList:function(t){var n;t?(this.wrapper.css({"z-index":999999}),this.fontList.show(),this._loadVisibleFonts(),n=this.fontList.find("li.selected"),n.length&&this.fontList.scrollTop(n.position().top)):(this.wrapper.css({"z-index":"auto"}),this.fontList.hide())},_bindHandlers:function(){var t,n,e;e=this,t=null,$("html").bind("click.webfont",function(t){e._toggleFontList(!1)}),n=function(t){e._toggleFontList(!0),t.stopPropagation()},this.element.bind("click.webfont",n),this.toggle.bind("click.webfont",n),this.fontList.bind("scroll.webfont",function(n){window.clearTimeout(t),t=window.setTimeout(function(){e._loadVisibleFonts()},250)}).bind("click.webfont",function(t){var n;return n=$(t.target),n.is("li")?void e._selectFontListItem(n):null})},destory:function(){this.fontList.remove(),this.toggle.remove(),this.element.removeClass("webfont-input").removeAttr("readonly").unbind("click.webfont").unwrap(),$("html").unbind("click.webfont"),$.Widget.prototype.destory.call(this)}})}(jQuery);
//# sourceMappingURL=./webfont.select.js.map