gentelella/production/js/custom.js

324 lines
10 KiB
JavaScript
Raw Normal View History

2015-05-19 08:25:00 +02:00
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/** ****** left menu *********************** **/
$(function () {
$('#sidebar-menu li ul').slideUp();
$('#sidebar-menu li').removeClass('active');
$('#sidebar-menu li').on('click', function() {
2015-11-18 10:26:41 +01:00
var link = $('a', this).attr('href');
if(link) {
window.location.href = link;
2015-05-19 08:25:00 +02:00
} else {
2015-11-18 10:26:41 +01:00
if ($(this).is('.active')) {
$(this).removeClass('active');
$('ul', this).slideUp();
} else {
$('#sidebar-menu li').removeClass('active');
$('#sidebar-menu li ul').slideUp();
$(this).addClass('active');
$('ul', this).slideDown();
}
2015-05-19 08:25:00 +02:00
}
});
$('#menu_toggle').click(function () {
if ($('body').hasClass('nav-md')) {
2015-11-18 10:26:41 +01:00
$('body').removeClass('nav-md').addClass('nav-sm');
$('.left_col').removeClass('scroll-view').removeAttr('style');
2015-05-19 08:25:00 +02:00
$('.sidebar-footer').hide();
if ($('#sidebar-menu li').hasClass('active')) {
2015-11-18 10:26:41 +01:00
$('#sidebar-menu li.active').addClass('active-sm').removeClass('active');
2015-05-19 08:25:00 +02:00
}
} else {
2015-11-18 10:26:41 +01:00
$('body').removeClass('nav-sm').addClass('nav-md');
2015-05-19 08:25:00 +02:00
$('.sidebar-footer').show();
if ($('#sidebar-menu li').hasClass('active-sm')) {
2015-11-18 10:26:41 +01:00
$('#sidebar-menu li.active-sm').addClass('active').removeClass('active-sm');
2015-05-19 08:25:00 +02:00
}
}
});
});
/* Sidebar Menu active class */
$(function () {
var url = window.location;
$('#sidebar-menu a[href="' + url + '"]').parent('li').addClass('current-page');
$('#sidebar-menu a').filter(function () {
return this.href == url;
}).parent('li').addClass('current-page').parent('ul').slideDown().parent().addClass('active');
});
/** ****** /left menu *********************** **/
2015-10-19 08:09:21 +02:00
/** ****** right_col height flexible *********************** **/
$(".right_col").css("min-height", $(window).height());
$(window).resize(function () {
$(".right_col").css("min-height", $(window).height());
});
/** ****** /right_col height flexible *********************** **/
2015-05-19 08:25:00 +02:00
/** ****** tooltip *********************** **/
$(function () {
2015-10-19 08:09:21 +02:00
$('[data-toggle="tooltip"]').tooltip()
})
/** ****** /tooltip *********************** **/
/** ****** progressbar *********************** **/
2015-05-19 08:25:00 +02:00
if ($(".progress .progress-bar")[0]) {
$('.progress .progress-bar').progressbar(); // bootstrap 3
}
/** ****** /progressbar *********************** **/
/** ****** switchery *********************** **/
if ($(".js-switch")[0]) {
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function (html) {
var switchery = new Switchery(html, {
color: '#26B99A'
});
});
}
/** ****** /switcher *********************** **/
/** ****** collapse panel *********************** **/
// Close ibox function
$('.close-link').click(function () {
var content = $(this).closest('div.x_panel');
content.remove();
});
// Collapse ibox function
$('.collapse-link').click(function () {
var x_panel = $(this).closest('div.x_panel');
var button = $(this).find('i');
var content = x_panel.find('div.x_content');
content.slideToggle(200);
(x_panel.hasClass('fixed_height_390') ? x_panel.toggleClass('').toggleClass('fixed_height_390') : '');
(x_panel.hasClass('fixed_height_320') ? x_panel.toggleClass('').toggleClass('fixed_height_320') : '');
button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
setTimeout(function () {
x_panel.resize();
}, 50);
});
/** ****** /collapse panel *********************** **/
/** ****** iswitch *********************** **/
if ($("input.flat")[0]) {
$(document).ready(function () {
$('input.flat').iCheck({
checkboxClass: 'icheckbox_flat-green',
radioClass: 'iradio_flat-green'
});
});
}
/** ****** /iswitch *********************** **/
/** ****** star rating *********************** **/
// Starrr plugin (https://github.com/dobtco/starrr)
var __slice = [].slice;
(function ($, window) {
var Starrr;
Starrr = (function () {
Starrr.prototype.defaults = {
rating: void 0,
numStars: 5,
2015-10-19 08:09:21 +02:00
change: function (e, value) {
}
2015-05-19 08:25:00 +02:00
};
function Starrr($el, options) {
var i, _, _ref,
2015-10-19 08:09:21 +02:00
_this = this;
2015-05-19 08:25:00 +02:00
this.options = $.extend({}, this.defaults, options);
this.$el = $el;
_ref = this.defaults;
for (i in _ref) {
_ = _ref[i];
if (this.$el.data(i) != null) {
this.options[i] = this.$el.data(i);
}
}
this.createStars();
this.syncRating();
this.$el.on('mouseover.starrr', 'span', function (e) {
return _this.syncRating(_this.$el.find('span').index(e.currentTarget) + 1);
});
this.$el.on('mouseout.starrr', function () {
return _this.syncRating();
});
this.$el.on('click.starrr', 'span', function (e) {
return _this.setRating(_this.$el.find('span').index(e.currentTarget) + 1);
});
this.$el.on('starrr:change', this.options.change);
}
Starrr.prototype.createStars = function () {
var _i, _ref, _results;
_results = [];
for (_i = 1, _ref = this.options.numStars; 1 <= _ref ? _i <= _ref : _i >= _ref; 1 <= _ref ? _i++ : _i--) {
_results.push(this.$el.append("<span class='glyphicon .glyphicon-star-empty'></span>"));
}
return _results;
};
Starrr.prototype.setRating = function (rating) {
if (this.options.rating === rating) {
rating = void 0;
}
this.options.rating = rating;
this.syncRating();
return this.$el.trigger('starrr:change', rating);
};
Starrr.prototype.syncRating = function (rating) {
var i, _i, _j, _ref;
rating || (rating = this.options.rating);
if (rating) {
for (i = _i = 0, _ref = rating - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
this.$el.find('span').eq(i).removeClass('glyphicon-star-empty').addClass('glyphicon-star');
}
}
if (rating && rating < 5) {
for (i = _j = rating; rating <= 4 ? _j <= 4 : _j >= 4; i = rating <= 4 ? ++_j : --_j) {
this.$el.find('span').eq(i).removeClass('glyphicon-star').addClass('glyphicon-star-empty');
}
}
if (!rating) {
return this.$el.find('span').removeClass('glyphicon-star').addClass('glyphicon-star-empty');
}
};
return Starrr;
})();
return $.fn.extend({
starrr: function () {
var args, option;
option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return this.each(function () {
var data;
data = $(this).data('star-rating');
if (!data) {
$(this).data('star-rating', (data = new Starrr($(this), option)));
}
if (typeof option === 'string') {
return data[option].apply(data, args);
}
});
}
});
})(window.jQuery, window);
$(function () {
return $(".starrr").starrr();
});
$(document).ready(function () {
$('#stars').on('starrr:change', function (e, value) {
$('#count').html(value);
});
$('#stars-existing').on('starrr:change', function (e, value) {
$('#count-existing').html(value);
});
});
/** ****** /star rating *********************** **/
/** ****** table *********************** **/
$('table input').on('ifChecked', function () {
check_state = '';
$(this).parent().parent().parent().addClass('selected');
countChecked();
});
$('table input').on('ifUnchecked', function () {
check_state = '';
$(this).parent().parent().parent().removeClass('selected');
countChecked();
});
var check_state = '';
$('.bulk_action input').on('ifChecked', function () {
check_state = '';
$(this).parent().parent().parent().addClass('selected');
countChecked();
});
$('.bulk_action input').on('ifUnchecked', function () {
check_state = '';
$(this).parent().parent().parent().removeClass('selected');
countChecked();
});
$('.bulk_action input#check-all').on('ifChecked', function () {
check_state = 'check_all';
countChecked();
});
$('.bulk_action input#check-all').on('ifUnchecked', function () {
check_state = 'uncheck_all';
countChecked();
});
function countChecked() {
2015-10-19 08:09:21 +02:00
if (check_state == 'check_all') {
$(".bulk_action input[name='table_records']").iCheck('check');
}
if (check_state == 'uncheck_all') {
$(".bulk_action input[name='table_records']").iCheck('uncheck');
2015-05-19 08:25:00 +02:00
}
2015-10-19 08:09:21 +02:00
var n = $(".bulk_action input[name='table_records']:checked").length;
if (n > 0) {
$('.column-title').hide();
$('.bulk-actions').show();
$('.action-cnt').html(n + ' Records Selected');
} else {
$('.column-title').show();
$('.bulk-actions').hide();
}
}
/** ****** /table *********************** **/
/** ****** *********************** **/
/** ****** *********************** **/
/** ****** *********************** **/
/** ****** *********************** **/
/** ****** *********************** **/
/** ****** *********************** **/
/** ****** Accordion *********************** **/
2015-05-19 08:25:00 +02:00
$(function () {
$(".expand").on("click", function () {
$(this).next().slideToggle(200);
$expand = $(this).find(">:first-child");
if ($expand.text() == "+") {
$expand.text("-");
} else {
$expand.text("+");
}
});
});
/** ****** Accordion *********************** **/
/** ****** NProgress *********************** **/
if (typeof NProgress != 'undefined') {
$(document).ready(function () {
NProgress.start();
});
$(window).load(function () {
NProgress.done();
});
}
/** ****** NProgress *********************** **/