/** * jQuery fontIconPicker - v2.0.0 * * An icon picker built on top of font icons and jQuery * * http://codeb.it/fontIconPicker * * Made by Alessandro Benoit & Swashata * Under MIT License * * {@link https://github.com/micc83/fontIconPicker} */ !(function(a) { "use strict"; function c(c, d) { (this.element = a(c)), (this.settings = a.extend({}, b, d)), this.settings.emptyIcon && this.settings.iconsPerPage--, (this.iconPicker = a("
", { class: "icons-selector", style: "position: relative", html: '
", })), (this.iconContainer = this.iconPicker.find(".fip-icons-container")), (this.searchIcon = this.iconPicker.find(".selector-search i")), (this.iconsSearched = []), (this.isSearch = !1), (this.totalPage = 1), (this.currentPage = 1), (this.currentIcon = !1), (this.iconsCount = 0), (this.open = !1), (this.searchValues = []), (this.availableCategoriesSearch = []), (this.triggerEvent = null), (this.backupSource = []), (this.backupSearch = []), (this.isCategorized = !1), (this.selectCategory = this.iconPicker.find(".icon-category-select")), (this.selectedCategory = !1), (this.availableCategories = []), (this.unCategorizedKey = null), this.init(); } var b = { theme: "fip-grey", source: !1, emptyIcon: !0, emptyIconValue: "", iconsPerPage: 20, hasSearch: !0, searchSource: !1, useAttribute: !1, attributeName: "data-icon", convertToHex: !0, allCategoryText: "From all categories", unCategorizedText: "Uncategorized", }; (c.prototype = { init: function() { this.iconPicker.addClass(this.settings.theme), this.iconPicker.css({ left: -9999 }).appendTo("body"); var b = this.iconPicker.outerHeight(), c = this.iconPicker.outerWidth(); if ( (this.iconPicker.css({ left: "" }), this.element.before(this.iconPicker), this.element.css({ visibility: "hidden", top: 0, position: "relative", zIndex: "-1", left: "-" + c + "px", display: "inline-block", height: b + "px", width: c + "px", padding: "0", margin: "0 -" + c + "px 0 0", border: "0 none", verticalAlign: "top", }), !this.element.is("select")) ) { var d = (function() { for (var a = 3, b = document.createElement("div"), c = b.all || []; (b.innerHTML = ""), c[0];); return a > 4 ? a : !a; })(), e = document.createElement("div"); this.triggerEvent = 9 !== d && "oninput" in e ? ["input", "keyup"] : ["keyup"]; }!this.settings.source && this.element.is("select") ? ((this.settings.source = []), (this.settings.searchSource = []), this.element.find("optgroup").length ? ((this.isCategorized = !0), this.element.find("optgroup").each( a.proxy(function(b, c) { var d = this.availableCategories.length, e = a("").prependTo(this.selectCategory), this.selectCategory.show().val("all").trigger("change")); }, loadIcons: function() { this.iconContainer.html(''), this.settings.source instanceof Array && this.renderIconContainer(); }, renderIconContainer: function() { var b, c = []; if ( ((c = this.isSearch ? this.iconsSearched : this.settings.source), (this.iconsCount = c.length), (this.totalPage = Math.ceil(this.iconsCount / this.settings.iconsPerPage)), this.totalPage > 1 ? this.iconPicker.find(".selector-footer").show() : this.iconPicker.find(".selector-footer").hide(), this.iconPicker.find(".selector-pages").html(this.currentPage + "/" + this.totalPage + " (" + this.iconsCount + ")"), (b = (this.currentPage - 1) * this.settings.iconsPerPage), this.settings.emptyIcon) ) this.iconContainer.html(''); else { if (c.length < 1) return this.iconContainer.html(''), void 0; this.iconContainer.html(""); } c = c.slice(b, b + this.settings.iconsPerPage); for (var e, d = 0; (e = c[d++]);) { var f = e; a.grep( this.settings.source, a.proxy(function(a, b) { return a === e ? ((f = this.searchValues[b]), !0) : !1; }, this) ), a("", { html: '", class: "fip-box", title: f, }).appendTo(this.iconContainer); } this.settings.emptyIcon || (this.element.val() && -1 !== a.inArray(this.element.val(), this.settings.source)) ? -1 === a.inArray(this.element.val(), this.settings.source) ? this.setSelectedIcon() : this.setSelectedIcon(this.element.val()) : this.setSelectedIcon(c[0]); }, setHighlightedIcon: function() { this.iconContainer.find(".current-icon").removeClass("current-icon"), this.currentIcon && this.iconContainer .find('[data-fip-value="' + this.currentIcon + '"]') .parent("span") .addClass("current-icon"); }, setSelectedIcon: function(a) { if ( ("fa-times-circle" === a && (a = ""), this.settings.useAttribute ? a ? this.iconPicker.find(".selected-icon").html("') : this.iconPicker.find(".selected-icon").html('') : this.iconPicker.find(".selected-icon").html(''), this.element.val("" === a ? this.settings.emptyIconValue : a).trigger("change"), null !== this.triggerEvent) ) for (var b in this.triggerEvent) this.element.trigger(this.triggerEvent[b]); (this.currentIcon = a), this.setHighlightedIcon(); }, toggleIconSelector: function() { (this.open = this.open ? 0 : 1), this.iconPicker.find(".selector-popup").slideToggle(300), this.iconPicker.find(".selector-button i").toggleClass("fip-icon-down-dir"), this.iconPicker.find(".selector-button i").toggleClass("fip-icon-up-dir"), this.open && this.iconPicker.find(".icons-search-input").focus().select(); }, resetSearch: function() { this.iconPicker.find(".icons-search-input").val(""), this.searchIcon.removeClass("fip-icon-cancel"), this.searchIcon.addClass("fip-icon-search"), this.iconPicker.find(".selector-arrow-left").hide(), (this.currentPage = 1), (this.isSearch = !1), this.renderIconContainer(), this.totalPage > 1 && this.iconPicker.find(".selector-arrow-right").show(); }, }), (a.fn.fontIconPicker = function(b) { return ( this.each(function() { a.data(this, "fontIconPicker") || a.data(this, "fontIconPicker", new c(this, b)); }), (this.setIcons = a.proxy(function(b, c) { void 0 === b && (b = !1), void 0 === c && (c = !1), this.each(function() { (a.data(this, "fontIconPicker").settings.source = b), (a.data(this, "fontIconPicker").settings.searchSource = c), a.data(this, "fontIconPicker").initSourceIndex(), a.data(this, "fontIconPicker").resetSearch(), a.data(this, "fontIconPicker").loadIcons(); }); }, this)), (this.destroyPicker = a.proxy(function() { this.each(function() { a.data(this, "fontIconPicker") && (a.data(this, "fontIconPicker").iconPicker.remove(), a.data(this, "fontIconPicker").element.css({ visibility: "", top: "", position: "", zIndex: "", left: "", display: "", height: "", width: "", padding: "", margin: "", border: "", verticalAlign: "" }), a.removeData(this, "fontIconPicker")); }); }, this)), (this.refreshPicker = a.proxy(function(d) { d || (d = b), this.destroyPicker(), this.each(function() { a.data(this, "fontIconPicker") || a.data(this, "fontIconPicker", new c(this, d)); }); }, this)), this ); }); })(jQuery);