');
for (var j = 0; j < op.cols; j++) {
var pos = offset + (i * op.cols) + j;
var btn = $('').hide();
if (pos < op.icons.length) {
var v = op.iconClassFix + op.icons[pos];
btn.val(v).attr('title', v).append('').show();
if (op.icon === v) {
btn.addClass(op.selectedClass).addClass('btn-icon-selected');
}
}
tr.append($('
').append(btn));
}
tbody.append(tr);
}
};
Iconpicker.prototype.updateIconsCount = function () {
var op = this.options;
if(op.footer === true){
var icons_count = [
'
',
'
',
' ',
'
',
'
'
];
op.table.find('tfoot').empty().append(icons_count.join(''));
}
};
Iconpicker.prototype.updateLabels = function (page) {
var op = this.options;
var total_icons = this.totalIcons();
var total_pages = this.totalPages();
op.table.find('.page-count').html(op.labelHeader.replace('{0}', (total_pages === 0 ) ? 0 : page).replace('{1}', total_pages));
var offset = (page - 1) * this.totalIconsPerPage();
var total = page * this.totalIconsPerPage();
op.table.find('.icons-count').html(op.labelFooter.replace('{0}', total_icons ? offset + 1 : 0).replace('{1}', (total < total_icons) ? total: total_icons).replace('{2}', total_icons));
this.updateArrows(page);
};
Iconpicker.prototype.updatePagesCount = function () {
var op = this.options;
if(op.header === true){
var tr = $('
');
for (var i = 0; i < op.cols; i++) {
var td = $('
');
if (i === 0 || i === op.cols - 1) {
var arrow = [
''
];
td.append(arrow.join(''));
tr.append(td);
}
else if (tr.find('.page-count').length === 0) {
td.attr('colspan', op.cols - 2).append('');
tr.append(td);
}
}
op.table.find('thead').empty().append(tr);
}
};
Iconpicker.prototype.updatePicker = function () {
var op = this.options;
if (op.cols < 4) {
throw 'Iconpicker => The number of columns must be greater than or equal to 4. [option.cols = ' + op.cols + ']';
}
else if (op.rows < 0) {
throw 'Iconpicker => The number of rows must be greater than or equal to 0. [option.rows = ' + op.rows + ']';
}
else {
this.updatePagesCount();
this.updateSearch();
this.updateIconsCount();
}
};
Iconpicker.prototype.updateSearch = function () {
var op = this.options;
var search = [
'
',
'
',
' ',
'
',
'
'
];
search = $(search.join(''));
if (op.search === true) {
search.show();
}
else {
search.hide();
}
op.table.find('thead').append(search);
};
// ICONPICKER PUBLIC METHODS
// ==============================
Iconpicker.prototype.setAlign = function (value) {
this.$element.removeClass(this.options.align).addClass(value);
this.options.align = value;
};
Iconpicker.prototype.setArrowClass = function (value) {
this.options.arrowClass = this.removeAddClass('.btn-arrow', this.options.arrowClass, value);
};
Iconpicker.prototype.setArrowNextIconClass = function (value) {
this.options.arrowNextIconClass = this.removeAddClass('.btn-next > span', this.options.arrowNextIconClass, value);
};
Iconpicker.prototype.setArrowPrevIconClass = function (value) {
this.options.arrowPrevIconClass = this.removeAddClass('.btn-previous > span', this.options.arrowPrevIconClass, value);
};
Iconpicker.prototype.setCols = function (value) {
this.options.cols = value;
this.reset();
};
Iconpicker.prototype.setFooter = function (value) {
var footer = this.options.table.find('tfoot');
if (value === true) {
footer.show();
}
else {
footer.hide();
}
this.options.footer = value;
};
Iconpicker.prototype.setHeader = function (value) {
var header = this.options.table.find('thead');
if (value === true) {
header.show();
}
else {
header.hide();
}
this.options.header = value;
};
Iconpicker.prototype.setIcon = function (value) {
this.select(value);
};
Iconpicker.prototype.setIconset = function (value) {
var op = this.options;
if ($.isPlainObject(value)) {
Iconpicker.ICONSET._custom = $.extend(Iconpicker.ICONSET_EMPTY, value);
op.iconset = '_custom';
}
else if (!Iconpicker.ICONSET.hasOwnProperty(value)) {
op.iconset = Iconpicker.DEFAULTS.iconset;
}
else {
op.iconset = value;
}
op = $.extend(op, Iconpicker.ICONSET[op.iconset]);
this.reset();
this.select(op.icon);
};
Iconpicker.prototype.setLabelHeader = function (value) {
this.options.labelHeader = value;
this.updateLabels(this.options.page);
};
Iconpicker.prototype.setLabelFooter = function (value) {
this.options.labelFooter = value;
this.updateLabels(this.options.page);
};
Iconpicker.prototype.setPlacement = function (value) {
this.options.placement = value;
};
Iconpicker.prototype.setRows = function (value) {
this.options.rows = value;
this.reset();
};
Iconpicker.prototype.setSearch = function (value) {
var search = this.options.table.find('.search-control');
if (value === true) {
search.show();
}
else {
search.hide();
}
search.val('');
this.changeList(1);
this.options.search = value;
};
Iconpicker.prototype.setSearchText = function (value) {
this.options.table.find('.search-control').attr('placeholder', value);
this.options.searchText = value;
};
Iconpicker.prototype.setSelectedClass = function (value) {
this.options.selectedClass = this.removeAddClass('.btn-icon-selected', this.options.selectedClass, value);
};
Iconpicker.prototype.setUnselectedClass = function (value) {
this.options.unselectedClass = this.removeAddClass('.btn-icon', this.options.unselectedClass, value);
};
// ICONPICKER PLUGIN DEFINITION
// ========================
var old = $.fn.iconpicker;
$.fn.iconpicker = function (option, params) {
return this.each(function () {
var $this = $(this);
var data = $this.data('bs.iconpicker');
var options = typeof option === 'object' && option;
if (!data) {
$this.data('bs.iconpicker', (data = new Iconpicker(this, options)));
}
if (typeof option === 'string') {
if (typeof data[option] === 'undefined') {
throw 'Iconpicker => The "' + option + '" method does not exists.';
}
else {
data[option](params);
}
}
else{
var op = data.options;
op = $.extend(op, {
inline: false,
page: 1,
selected: -1,
table: $('
')
});
var name = (typeof $this.attr('name') !== 'undefined') ? 'name="' + $this.attr('name') + '"' : '';
if($this.prop('tagName') === 'BUTTON'){
$this.empty()
.append('')
.append('')
.append('')
.addClass('iconpicker ' + (($.fn.bsVersion() === '3.x') ? '' : 'dropdown-toggle'));
data.setIconset(op.iconset);
$this.on('click', function(e) {
e.preventDefault();
$this.popover({
animation: false,
trigger: 'manual',
html: true,
content: op.table,
container: 'body',
placement: op.placement
}).on('inserted.bs.popover', function() {
var el = $this.data('bs.popover');
var tip = ($.fn.bsVersion() === '3.x') ? el.tip() : $(el.getTipElement())
tip.addClass('iconpicker-popover');
}).on('shown.bs.popover', function () {
data.switchPage(op.icon);
data.bindEvents();
});
//console.log($.fn.bsVersion());
$this.popover('show');
});
}
else{
op.inline = true;
data.setIconset(op.iconset);
$this.empty()
.append('')
.append(op.table)
.addClass('iconpicker')
.addClass(op.align);
data.switchPage(op.icon);
data.bindEvents();
}
}
});
};
$.fn.iconpicker.Constructor = Iconpicker;
// ICONPICKER NO CONFLICT
// ==================
$.fn.iconpicker.noConflict = function () {
$.fn.iconpicker = old;
return this;
};
$.fn.bsVersion = function() {
return $.fn.popover.Constructor.VERSION.substr(0,2) + 'x';
};
// ICONPICKER DATA-API
// ===============
$(document).on('click', 'body', function (e) {
$('.iconpicker').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover(($.fn.bsVersion() === '3.x') ? 'destroy' : 'dispose');
}
});
});
$('button[role="iconpicker"],div[role="iconpicker"]').iconpicker();
})(jQuery);