/* ========================================================================
 * Bootstrap: bootstrap-iconpicker.js v1.6.0 by @recktoner
 * https://victor-valencia.github.com/bootstrap-iconpicker
 * ========================================================================
 * Copyright 2013-2014 Victor Valencia Rico.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ======================================================================== */
!function(t){"use strict";var e=function(o,s){this.$element=t(o),this.options=t.extend({},e.DEFAULTS,this.$element.data()),this.options=t.extend({},this.options,s)};e.ICONSET_EMPTY={iconClass:"",iconClassFix:"",icons:[]},e.ICONSET={_custom:null,elusiveicon:t.iconset_elusiveicon||e.ICONSET_EMPTY,fontawesome:t.iconset_fontawesome||e.ICONSET_EMPTY,ionicon:t.iconset_ionicon||e.ICONSET_EMPTY,glyphicon:t.iconset_glyphicon||e.ICONSET_EMPTY,mapicon:t.iconset_mapicon||e.ICONSET_EMPTY,octicon:t.iconset_octicon||e.ICONSET_EMPTY,typicon:t.iconset_typicon||e.ICONSET_EMPTY,weathericon:t.iconset_weathericon||e.ICONSET_EMPTY},e.DEFAULTS={arrowClass:"btn-primary",arrowNextIconClass:"glyphicon glyphicon-arrow-right",arrowPrevIconClass:"glyphicon glyphicon-arrow-left",cols:4,icon:"",iconset:"glyphicon",labelHeader:"{0} / {1}",labelFooter:"{0} - {1} of {2}",placement:"bottom",rows:4,search:!0,searchText:"Search icon",selectedClass:"btn-warning",unselectedClass:"btn-default"},e.prototype.bindEvents=function(){var e=this.options,o=this;e.table.find(".btn-previous, .btn-next").off("click").on("click",function(){var s=parseInt(t(this).val(),10);o.changeList(e.page+s)}),e.table.find(".btn-icon").off("click").on("click",function(){o.select(t(this).val()),o.$element.popover("destroy")}),e.table.find(".search-control").off("keyup").on("keyup",function(){o.changeList(1)})},e.prototype.changeList=function(t){this.filterIcons(),this.updateLabels(t),this.updateIcons(t),this.options.page=t,this.bindEvents()},e.prototype.filterIcons=function(){var o=this.options,s=o.table.find(".search-control").val();if(""===s)o.icons=e.ICONSET[o.iconset].icons;else{var n=[];t.each(e.ICONSET[o.iconset].icons,function(t,e){e.indexOf(s)>-1&&n.push(e)}),o.icons=n}},e.prototype.removeAddClass=function(t,e,o){return this.options.table.find(t).removeClass(e).addClass(o),o},e.prototype.reset=function(){this.updatePicker(),this.changeList(1)},e.prototype.select=function(e){var o=this.options,s=this.$element;o.selected=t.inArray(e.replace(o.iconClassFix,""),o.icons),-1===o.selected&&(o.selected=0,e=o.iconClassFix+o.icons[o.selected]),""!==e&&o.selected>=0&&(o.icon=e,s.find("input").val(e),s.find("i").attr("class","").addClass(o.iconClass).addClass(e),s.trigger({type:"change",icon:e}),o.table.find("button."+o.selectedClass).removeClass(o.selectedClass))},e.prototype.switchPage=function(e){var o=this.options;if(o.selected=t.inArray(e.replace(o.iconClassFix,""),o.icons),""!==e&&o.selected>=0){var s=Math.ceil((o.selected+1)/this.totalIconsPerPage());this.changeList(s)}o.table.find("i."+e).parent().addClass(o.selectedClass)},e.prototype.totalPages=function(){return Math.ceil(this.totalIcons()/this.totalIconsPerPage())},e.prototype.totalIcons=function(){return this.options.icons.length},e.prototype.totalIconsPerPage=function(){return this.options.cols*this.options.rows},e.prototype.updateArrows=function(t){var e=this.options,o=this.totalPages();1===t?e.table.find(".btn-previous").addClass("disabled"):e.table.find(".btn-previous").removeClass("disabled"),t===o||0===o?e.table.find(".btn-next").addClass("disabled"):e.table.find(".btn-next").removeClass("disabled")},e.prototype.updateIcons=function(e){for(var o=this.options,s=o.table.find("tbody").empty(),n=(e-1)*this.totalIconsPerPage(),i=0;i<o.rows;i++){for(var a=t("<tr></tr>"),c=0;c<o.cols;c++){var r=n+i*o.cols+c,p=t('<button class="btn '+o.unselectedClass+' btn-icon"></button>').hide();if(r<o.icons.length){var l=o.iconClassFix+o.icons[r];p.val(l).attr("title",l).append('<i class="'+o.iconClass+" "+l+'"></i>').show(),o.icon===l&&p.addClass(o.selectedClass).addClass("btn-icon-selected")}a.append(t("<td></td>").append(p))}s.append(a)}},e.prototype.updateIconsCount=function(){var t=this.options,e=["<tr>",'   <td colspan="'+t.cols+'" class="text-center">','       <span class="icons-count"></span>',"   </td>","</tr>"];t.table.find("tfoot").empty().append(e.join(""))},e.prototype.updateLabels=function(t){var e=this.options,o=this.totalIcons(),s=this.totalPages();e.table.find(".page-count").html(e.labelHeader.replace("{0}",0===s?0:t).replace("{1}",s));var n=(t-1)*this.totalIconsPerPage(),i=t*this.totalIconsPerPage();e.table.find(".icons-count").html(e.labelFooter.replace("{0}",n+1).replace("{1}",o>i?i:o).replace("{2}",o)),this.updateArrows(t)},e.prototype.updatePagesCount=function(){for(var e=this.options,o=t("<tr></tr>"),s=0;s<e.cols;s++){var n=t('<td class="text-center"></td>');if(0===s||s===e.cols-1){var i=['<button class="btn btn-arrow '+(0===s?"btn-previous":"btn-next")+" "+e.arrowClass+'" value="'+(0===s?-1:1)+'">','<span class="'+(0===s?e.arrowPrevIconClass:e.arrowNextIconClass)+'"></span>',"</button>"];n.append(i.join("")),o.append(n)}else 0===o.find(".page-count").length&&(n.attr("colspan",e.cols-2).append('<span class="page-count"></span>'),o.append(n))}e.table.find("thead").empty().append(o)},e.prototype.updatePicker=function(){var t=this.options;if(t.cols<4)throw"Iconpicker => The number of columns must be greater than or equal to 4. [option.cols = "+t.cols+"]";if(t.rows<1)throw"Iconpicker => The number of rows must be greater than or equal to 1. [option.rows = "+t.rows+"]";this.updatePagesCount(),this.updateSearch(),this.updateIconsCount()},e.prototype.updateSearch=function(){var e=this.options,o=["<tr>",'   <td colspan="'+e.cols+'">','       <input type="text" class="form-control search-control" style="width: '+39*e.cols+'px;" placeholder="'+e.searchText+'">',"   </td>","</tr>"];o=t(o.join("")),e.search===!0?o.show():o.hide(),e.table.find("thead").append(o)},e.prototype.setArrowClass=function(t){this.options.arrowClass=this.removeAddClass(".btn-arrow",this.options.arrowClass,t)},e.prototype.setArrowNextIconClass=function(t){this.options.arrowNextIconClass=this.removeAddClass(".btn-next > span",this.options.arrowNextIconClass,t)},e.prototype.setArrowPrevIconClass=function(t){this.options.arrowPrevIconClass=this.removeAddClass(".btn-previous > span",this.options.arrowPrevIconClass,t)},e.prototype.setCols=function(t){this.options.cols=t,this.reset()},e.prototype.setIcon=function(t){this.select(t)},e.prototype.setIconset=function(o){var s=this.options;t.isPlainObject(o)?(e.ICONSET._custom=t.extend(e.ICONSET_EMPTY,o),s.iconset="_custom"):s.iconset=e.ICONSET.hasOwnProperty(o)?o:e.DEFAULTS.iconset,s=t.extend(s,e.ICONSET[s.iconset]),this.reset(),this.select(s.icon)},e.prototype.setLabelHeader=function(t){this.options.labelHeader=t,this.updateLabels(this.options.page)},e.prototype.setLabelFooter=function(t){this.options.labelFooter=t,this.updateLabels(this.options.page)},e.prototype.setPlacement=function(t){this.options.placement=t},e.prototype.setRows=function(t){this.options.rows=t,this.reset()},e.prototype.setSearch=function(t){var e=this.options.table.find(".search-control");t===!0?e.show():e.hide(),e.val(""),this.changeList(1),this.options.search=t},e.prototype.setSearchText=function(t){this.options.table.find(".search-control").attr("placeholder",t),this.options.searchText=t},e.prototype.setSelectedClass=function(t){this.options.selectedClass=this.removeAddClass(".btn-icon-selected",this.options.selectedClass,t)},e.prototype.setUnselectedClass=function(t){this.options.unselectedClass=this.removeAddClass(".btn-icon",this.options.unselectedClass,t)};var o=t.fn.iconpicker;t.fn.iconpicker=function(o,s){return this.each(function(){var n=t(this),i=n.data("bs.iconpicker"),a="object"==typeof o&&o;if(i||n.data("bs.iconpicker",i=new e(this,a)),"string"==typeof o){if("undefined"==typeof i[o])throw'Iconpicker => The "'+o+'" method does not exists.';i[o](s)}else{var c=i.options;c=t.extend(c,{page:1,selected:-1,table:t('<table class="table-icons"><thead></thead><tbody></tbody><tfoot></tfoot></table>')});var r="undefined"!=typeof n.attr("name")?'name="'+n.attr("name")+'"':"";n.empty().append("<i></i>").append('<input type="hidden" '+r+"></input>").append('<span class="caret"></span>'),n.addClass("iconpicker"),i.setIconset(c.iconset),n.on("click",function(t){t.preventDefault(),n.popover({animation:!1,trigger:"manual",html:!0,content:c.table,container:"body",placement:c.placement}).on("shown.bs.popover",function(){i.switchPage(c.icon),i.bindEvents()}),n.data("bs.popover").tip().addClass("iconpicker-popover"),n.popover("show")})}})},t.fn.iconpicker.Constructor=e,t.fn.iconpicker.noConflict=function(){return t.fn.iconpicker=o,this},t(document).on("click","body",function(e){t(".iconpicker").each(function(){t(this).is(e.target)||0!==t(this).has(e.target).length||0!==t(".popover").has(e.target).length||t(this).popover("destroy")})}),t('button[role="iconpicker"]').iconpicker()}(jQuery);