mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-12 15:01:39 +08:00
添加Metronic(作为LFS)
This commit is contained in:
246
frontend/static/assets/global/scripts/datatable.js
Normal file
246
frontend/static/assets/global/scripts/datatable.js
Normal file
@@ -0,0 +1,246 @@
|
||||
/***
|
||||
Wrapper/Helper Class for datagrid based on jQuery Datatable Plugin
|
||||
***/
|
||||
|
||||
var Datatable = function () {
|
||||
|
||||
var tableOptions; // main options
|
||||
var dataTable; // datatable object
|
||||
var table; // actual table jquery object
|
||||
var tableContainer; // actual table container object
|
||||
var tableWrapper; // actual table wrapper jquery object
|
||||
var tableInitialized = false;
|
||||
var ajaxParams = []; // set filter mode
|
||||
|
||||
var countSelectedRecords = function() {
|
||||
var selected = $('tbody > tr > td:nth-child(1) input[type="checkbox"]:checked', table).size();
|
||||
var text = tableOptions.dataTable.oLanguage.sGroupActions;
|
||||
if (selected > 0) {
|
||||
$('.table-group-actions > span', tableWrapper).text(text.replace("_TOTAL_", selected));
|
||||
} else {
|
||||
$('.table-group-actions > span', tableWrapper).text("");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
//main function to initiate the module
|
||||
init: function (options) {
|
||||
|
||||
if (!$().dataTable) {
|
||||
return;
|
||||
}
|
||||
|
||||
var the = this;
|
||||
|
||||
// default settings
|
||||
options = $.extend(true, {
|
||||
src: "", // actual table
|
||||
filterApplyAction: "filter",
|
||||
filterCancelAction: "filter_cancel",
|
||||
resetGroupActionInputOnSuccess: true,
|
||||
dataTable: {
|
||||
"sDom" : "<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>r>>", // datatable layout
|
||||
|
||||
"aLengthMenu": [ // set available records per page
|
||||
[10, 25, 50, 100, -1],
|
||||
[10, 25, 50, 100, "All"]
|
||||
],
|
||||
"iDisplayLength": 10, // default records per page
|
||||
"oLanguage": { // language settings
|
||||
"sProcessing": '<img src="' + Metronic.getGlobalImgPath() + 'loading-spinner-grey.gif"/><span> Loading...</span>',
|
||||
"sLengthMenu": "<span class='seperator'>|</span>View _MENU_ records",
|
||||
"sInfo": "<span class='seperator'>|</span>Found total _TOTAL_ records",
|
||||
"sInfoEmpty": "No records found to show",
|
||||
"sGroupActions": "_TOTAL_ records selected: ",
|
||||
"sAjaxRequestGeneralError": "Could not complete request. Please check your internet connection",
|
||||
"sEmptyTable": "No data available in table",
|
||||
"sZeroRecords": "No matching records found",
|
||||
"oPaginate": {
|
||||
"sPrevious": "Prev",
|
||||
"sNext": "Next",
|
||||
"sPage": "Page",
|
||||
"sPageOf": "of"
|
||||
}
|
||||
},
|
||||
|
||||
"aoColumnDefs" : [{ // define columns sorting options(by default all columns are sortable extept the first checkbox column)
|
||||
'bSortable' : false,
|
||||
'aTargets' : [ 0 ]
|
||||
}],
|
||||
|
||||
"bAutoWidth": false, // disable fixed width and enable fluid table
|
||||
"bSortCellsTop": true, // make sortable only the first row in thead
|
||||
"sPaginationType": "bootstrap_extended", // pagination type(bootstrap, bootstrap_full_number or bootstrap_extended)
|
||||
"bProcessing": true, // enable/disable display message box on record load
|
||||
"bServerSide": true, // enable/disable server side ajax loading
|
||||
"sAjaxSource": "", // define ajax source URL
|
||||
"sServerMethod": "POST",
|
||||
|
||||
// handle ajax request
|
||||
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
|
||||
oSettings.jqXHR = $.ajax( {
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"success": function(res, textStatus, jqXHR) {
|
||||
if (res.sMessage) {
|
||||
Metronic.alert({type: (res.sStatus == 'OK' ? 'success' : 'danger'), icon: (res.sStatus == 'OK' ? 'check' : 'warning'), message: res.sMessage, container: tableWrapper, place: 'prepend'});
|
||||
}
|
||||
if (res.sStatus) {
|
||||
if (tableOptions.resetGroupActionInputOnSuccess) {
|
||||
$('.table-group-action-input', tableWrapper).val("");
|
||||
}
|
||||
}
|
||||
if ($('.group-checkable', table).size() === 1) {
|
||||
$('.group-checkable', table).attr("checked", false);
|
||||
$.uniform.update($('.group-checkable', table));
|
||||
}
|
||||
if (tableOptions.onSuccess) {
|
||||
tableOptions.onSuccess.call(undefined, the);
|
||||
}
|
||||
fnCallback(res, textStatus, jqXHR);
|
||||
},
|
||||
"error": function() {
|
||||
if (tableOptions.onError) {
|
||||
tableOptions.onError.call(undefined, the);
|
||||
}
|
||||
Metronic.alert({type: 'danger', icon: 'warning', message: tableOptions.dataTable.oLanguage.sAjaxRequestGeneralError, container: tableWrapper, place: 'prepend'});
|
||||
$('.dataTables_processing', tableWrapper).remove();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
// pass additional parameter
|
||||
"fnServerParams": function ( aoData ) {
|
||||
//here can be added an external ajax request parameters.
|
||||
for(var i in ajaxParams) {
|
||||
var param = ajaxParams[i];
|
||||
aoData.push({"name" : param.name, "value": param.value});
|
||||
}
|
||||
},
|
||||
|
||||
"fnDrawCallback": function( oSettings ) { // run some code on table redraw
|
||||
if (tableInitialized === false) { // check if table has been initialized
|
||||
tableInitialized = true; // set table initialized
|
||||
table.show(); // display table
|
||||
}
|
||||
Metronic.initUniform($('input[type="checkbox"]', table)); // reinitialize uniform checkboxes on each table reload
|
||||
countSelectedRecords(); // reset selected records indicator
|
||||
}
|
||||
}
|
||||
}, options);
|
||||
|
||||
tableOptions = options;
|
||||
|
||||
// create table's jquery object
|
||||
table = $(options.src);
|
||||
tableContainer = table.parents(".table-container");
|
||||
|
||||
// apply the special class that used to restyle the default datatable
|
||||
$.fn.dataTableExt.oStdClasses.sWrapper = $.fn.dataTableExt.oStdClasses.sWrapper + " dataTables_extended_wrapper";
|
||||
|
||||
// initialize a datatable
|
||||
dataTable = table.dataTable(options.dataTable);
|
||||
|
||||
tableWrapper = table.parents('.dataTables_wrapper');
|
||||
|
||||
// modify table per page dropdown input by appliying some classes
|
||||
$('.dataTables_length select', tableWrapper).addClass("form-control input-xsmall input-sm");
|
||||
|
||||
// build table group actions panel
|
||||
if ($('.table-actions-wrapper', tableContainer).size() === 1) {
|
||||
$('.table-group-actions', tableWrapper).html($('.table-actions-wrapper', tableContainer).html()); // place the panel inside the wrapper
|
||||
$('.table-actions-wrapper', tableContainer).remove(); // remove the template container
|
||||
}
|
||||
// handle group checkboxes check/uncheck
|
||||
$('.group-checkable', table).change(function () {
|
||||
var set = $('tbody > tr > td:nth-child(1) input[type="checkbox"]', table);
|
||||
var checked = $(this).is(":checked");
|
||||
$(set).each(function () {
|
||||
$(this).attr("checked", checked);
|
||||
});
|
||||
$.uniform.update(set);
|
||||
countSelectedRecords();
|
||||
});
|
||||
|
||||
// handle row's checkbox click
|
||||
table.on('change', 'tbody > tr > td:nth-child(1) input[type="checkbox"]', function(){
|
||||
countSelectedRecords();
|
||||
});
|
||||
|
||||
// handle filter submit button click
|
||||
table.on('click', '.filter-submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
the.addAjaxParam("sAction", tableOptions.filterApplyAction);
|
||||
|
||||
// get all typeable inputs
|
||||
$('textarea.form-filter, select.form-filter, input.form-filter:not([type="radio"],[type="checkbox"])', table).each(function(){
|
||||
the.addAjaxParam($(this).attr("name"), $(this).val());
|
||||
});
|
||||
|
||||
// get all checkable inputs
|
||||
$('input.form-filter[type="checkbox"]:checked, input.form-filter[type="radio"]:checked', table).each(function(){
|
||||
the.addAjaxParam($(this).attr("name"), $(this).val());
|
||||
});
|
||||
|
||||
dataTable.fnDraw();
|
||||
});
|
||||
|
||||
// handle filter cancel button click
|
||||
table.on('click', '.filter-cancel', function(e){
|
||||
e.preventDefault();
|
||||
$('textarea.form-filter, select.form-filter, input.form-filter', table).each(function(){
|
||||
$(this).val("");
|
||||
});
|
||||
$('input.form-filter[type="checkbox"]', table).each(function(){
|
||||
$(this).attr("checked", false);
|
||||
});
|
||||
the.clearAjaxParams();
|
||||
the.addAjaxParam("sAction", tableOptions.filterCancelAction);
|
||||
dataTable.fnDraw();
|
||||
});
|
||||
},
|
||||
|
||||
getSelectedRowsCount: function() {
|
||||
return $('tbody > tr > td:nth-child(1) input[type="checkbox"]:checked', table).size();
|
||||
},
|
||||
|
||||
getSelectedRows: function() {
|
||||
var rows = [];
|
||||
$('tbody > tr > td:nth-child(1) input[type="checkbox"]:checked', table).each(function(){
|
||||
rows.push({name: $(this).attr("name"), value: $(this).val()});
|
||||
});
|
||||
|
||||
return rows;
|
||||
},
|
||||
|
||||
addAjaxParam: function(name, value) {
|
||||
ajaxParams.push({"name": name, "value": value});
|
||||
},
|
||||
|
||||
clearAjaxParams: function(name, value) {
|
||||
ajaxParams = [];
|
||||
},
|
||||
|
||||
getDataTable: function() {
|
||||
return dataTable;
|
||||
},
|
||||
|
||||
getTableWrapper: function() {
|
||||
return tableWrapper;
|
||||
},
|
||||
|
||||
gettableContainer: function() {
|
||||
return tableContainer;
|
||||
},
|
||||
|
||||
getTable: function() {
|
||||
return table;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
641
frontend/static/assets/global/scripts/metronic.js
Normal file
641
frontend/static/assets/global/scripts/metronic.js
Normal file
@@ -0,0 +1,641 @@
|
||||
/**
|
||||
Core script to handle the entire theme and core functions
|
||||
**/
|
||||
var Metronic = function () {
|
||||
|
||||
// IE mode
|
||||
var isRTL = false;
|
||||
var isIE8 = false;
|
||||
var isIE9 = false;
|
||||
var isIE10 = false;
|
||||
|
||||
var resizeHandlers = [];
|
||||
|
||||
var globalImgPath = '../../assets/global/img/';
|
||||
|
||||
// theme layout color set
|
||||
|
||||
var brandColors = {
|
||||
'blue': '#89C4F4',
|
||||
'red': '#F3565D',
|
||||
'green': '#1bbc9b',
|
||||
'purple': '#9b59b6',
|
||||
'grey': '#95a5a6',
|
||||
'yellow': '#F8CB00'
|
||||
};
|
||||
|
||||
// initializes main settings
|
||||
var handleInit = function () {
|
||||
|
||||
if ($('body').css('direction') === 'rtl') {
|
||||
isRTL = true;
|
||||
}
|
||||
|
||||
isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
|
||||
isIE9 = !! navigator.userAgent.match(/MSIE 9.0/);
|
||||
isIE10 = !! navigator.userAgent.match(/MSIE 10.0/);
|
||||
|
||||
if (isIE10) {
|
||||
jQuery('html').addClass('ie10'); // detect IE10 version
|
||||
}
|
||||
|
||||
if (isIE10 || isIE9 || isIE8) {
|
||||
jQuery('html').addClass('ie'); // detect IE10 version
|
||||
}
|
||||
}
|
||||
|
||||
// runs callback functions set by Metronic.addResponsiveHandler().
|
||||
var _runResizeHandlers = function () {
|
||||
// reinitialize other subscribed elements
|
||||
for (var i = 0; i < resizeHandlers.length; i++) {
|
||||
var each = resizeHandlers[i];
|
||||
each.call();
|
||||
}
|
||||
}
|
||||
|
||||
// handle the layout reinitialization on window resize
|
||||
var handleOnResize = function () {
|
||||
var resize;
|
||||
if (isIE8) {
|
||||
var currheight;
|
||||
$(window).resize(function () {
|
||||
if (currheight == document.documentElement.clientHeight) {
|
||||
return; //quite event since only body resized not window.
|
||||
}
|
||||
if (resize) {
|
||||
clearTimeout(resize);
|
||||
}
|
||||
resize = setTimeout(function () {
|
||||
_runResizeHandlers();
|
||||
}, 50); // wait 50ms until window resize finishes.
|
||||
currheight = document.documentElement.clientHeight; // store last body client height
|
||||
});
|
||||
} else {
|
||||
$(window).resize(function () {
|
||||
if (resize) {
|
||||
clearTimeout(resize);
|
||||
}
|
||||
resize = setTimeout(function () {
|
||||
_runResizeHandlers();
|
||||
}, 50); // wait 50ms until window resize finishes.
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Handles portlet tools & actions
|
||||
var handlePortletTools = function () {
|
||||
jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.remove', function (e) {
|
||||
e.preventDefault();
|
||||
jQuery(this).closest(".portlet").remove();
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.reload', function (e) {
|
||||
e.preventDefault();
|
||||
var el = jQuery(this).closest(".portlet").children(".portlet-body");
|
||||
var url = jQuery(this).attr("data-url");
|
||||
var error = $(this).attr("data-error-display");
|
||||
if (url) {
|
||||
Metronic.blockUI({target: el, iconOnly: true});
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
cache: false,
|
||||
url: url,
|
||||
dataType: "html",
|
||||
success: function(res)
|
||||
{
|
||||
Metronic.unblockUI(el);
|
||||
el.html(res);
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError)
|
||||
{
|
||||
Metronic.unblockUI(el);
|
||||
var msg = 'Error on reloading the content. Please check your connection and try again.';
|
||||
if (error == "toastr" && toastr) {
|
||||
toastr.error(msg);
|
||||
} else if (error == "notific8" && $.notific8) {
|
||||
$.notific8('zindex', 11500);
|
||||
$.notific8(msg, {theme: 'ruby', life: 3000});
|
||||
} else {
|
||||
alert(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// for demo purpose
|
||||
Metronic.blockUI({target: el, iconOnly: true});
|
||||
window.setTimeout(function () {
|
||||
Metronic.unblockUI(el);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
// load ajax data on page init
|
||||
$('.portlet .portlet-title a.reload[data-load="true"]').click();
|
||||
|
||||
jQuery('body').on('click', '.portlet > .portlet-title > .tools > .collapse, .portlet .portlet-title > .tools > .expand', function (e) {
|
||||
e.preventDefault();
|
||||
var el = jQuery(this).closest(".portlet").children(".portlet-body");
|
||||
if (jQuery(this).hasClass("collapse")) {
|
||||
jQuery(this).removeClass("collapse").addClass("expand");
|
||||
el.slideUp(200);
|
||||
} else {
|
||||
jQuery(this).removeClass("expand").addClass("collapse");
|
||||
el.slideDown(200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handles custom checkboxes & radios using jQuery Uniform plugin
|
||||
var handleUniform = function () {
|
||||
if (!jQuery().uniform) {
|
||||
return;
|
||||
}
|
||||
var test = $("input[type=checkbox]:not(.toggle, .make-switch), input[type=radio]:not(.toggle, .star, .make-switch)");
|
||||
if (test.size() > 0) {
|
||||
test.each(function () {
|
||||
if ($(this).parents(".checker").size() == 0) {
|
||||
$(this).show();
|
||||
$(this).uniform();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var handleBootstrapSwitch = function () {
|
||||
if (!jQuery().bootstrapSwitch) {
|
||||
return;
|
||||
}
|
||||
$('.make-switch').bootstrapSwitch();
|
||||
}
|
||||
|
||||
// Handles Bootstrap Accordions.
|
||||
var handleAccordions = function () {
|
||||
jQuery('body').on('shown.bs.collapse', '.accordion.scrollable', function (e) {
|
||||
Metronic.scrollTo($(e.target));
|
||||
});
|
||||
}
|
||||
|
||||
// Handles Bootstrap Tabs.
|
||||
var handleTabs = function () {
|
||||
//activate tab if tab id provided in the URL
|
||||
if (location.hash) {
|
||||
var tabid = location.hash.substr(1);
|
||||
$('a[href="#' + tabid + '"]').parents('.tab-pane:hidden').each(function(){
|
||||
var tabid = $(this).attr("id");
|
||||
$('a[href="#' + tabid + '"]').click();
|
||||
});
|
||||
$('a[href="#' + tabid + '"]').click();
|
||||
}
|
||||
}
|
||||
|
||||
// Handles Bootstrap Modals.
|
||||
var handleModals = function () {
|
||||
// fix stackable modal issue: when 2 or more modals opened, closing one of modal will remove .modal-open class.
|
||||
$('body').on('hide.bs.modal', function () {
|
||||
if ($('.modal:visible').size() > 1 && $('html').hasClass('modal-open') == false) {
|
||||
$('html').addClass('modal-open');
|
||||
} else if ($('.modal:visible').size() <= 1) {
|
||||
$('html').removeClass('modal-open');
|
||||
}
|
||||
});
|
||||
|
||||
$('body').on('show.bs.modal', '.modal', function () {
|
||||
if ($(this).hasClass("modal-scroll")) {
|
||||
$('body').addClass("modal-open-noscroll");
|
||||
}
|
||||
});
|
||||
|
||||
$('body').on('hide.bs.modal', '.modal', function () {
|
||||
$('body').removeClass("modal-open-noscroll");
|
||||
});
|
||||
}
|
||||
|
||||
// Handles Bootstrap Tooltips.
|
||||
var handleTooltips = function () {
|
||||
jQuery('.tooltips').tooltip();
|
||||
}
|
||||
|
||||
// Handles Bootstrap Dropdowns
|
||||
var handleDropdowns = function () {
|
||||
/*
|
||||
Hold dropdown on click
|
||||
*/
|
||||
$('body').on('click', '.dropdown-menu.hold-on-click', function (e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
||||
var handleAlerts = function () {
|
||||
$('body').on('click', '[data-close="alert"]', function(e){
|
||||
$(this).parent('.alert').hide();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
// Handle Hower Dropdowns
|
||||
var handleDropdownHover = function () {
|
||||
$('[data-hover="dropdown"]').dropdownHover();
|
||||
}
|
||||
|
||||
// Handles Bootstrap Popovers
|
||||
|
||||
// last popep popover
|
||||
var lastPopedPopover;
|
||||
|
||||
var handlePopovers = function () {
|
||||
jQuery('.popovers').popover();
|
||||
|
||||
// close last displayed popover
|
||||
|
||||
$(document).on('click.bs.popover.data-api', function (e) {
|
||||
if (lastPopedPopover) {
|
||||
lastPopedPopover.popover('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handles scrollable contents using jQuery SlimScroll plugin.
|
||||
var handleScrollers = function () {
|
||||
$('.scroller').each(function () {
|
||||
if ($(this).attr("data-initialized")) {
|
||||
return; // exit
|
||||
}
|
||||
var height;
|
||||
if ($(this).attr("data-height")) {
|
||||
height = $(this).attr("data-height");
|
||||
} else {
|
||||
height = $(this).css('height');
|
||||
}
|
||||
$(this).slimScroll({
|
||||
allowPageScroll: true, // allow page scroll when the element scroll is ended
|
||||
size: '7px',
|
||||
color: ($(this).attr("data-handle-color") ? $(this).attr("data-handle-color") : '#bbb'),
|
||||
railColor: ($(this).attr("data-rail-color") ? $(this).attr("data-rail-color") : '#eaeaea'),
|
||||
position: isRTL ? 'left' : 'right',
|
||||
height: height,
|
||||
alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false),
|
||||
railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
|
||||
disableFadeOut: true
|
||||
});
|
||||
$(this).attr("data-initialized", true);
|
||||
});
|
||||
}
|
||||
|
||||
// Handles Image Preview using jQuery Fancybox plugin
|
||||
var handleFancybox = function () {
|
||||
if (!jQuery.fancybox) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jQuery(".fancybox-button").size() > 0) {
|
||||
jQuery(".fancybox-button").fancybox({
|
||||
groupAttr: 'data-rel',
|
||||
prevEffect: 'none',
|
||||
nextEffect: 'none',
|
||||
closeBtn: true,
|
||||
helpers: {
|
||||
title: {
|
||||
type: 'inside'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fix input placeholder issue for IE8 and IE9
|
||||
var handleFixInputPlaceholderForIE = function () {
|
||||
//fix html5 placeholder attribute for ie7 & ie8
|
||||
if (isIE8 || isIE9) { // ie8 & ie9
|
||||
// this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
|
||||
jQuery('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () {
|
||||
|
||||
var input = jQuery(this);
|
||||
|
||||
if (input.val() == '' && input.attr("placeholder") != '') {
|
||||
input.addClass("placeholder").val(input.attr('placeholder'));
|
||||
}
|
||||
|
||||
input.focus(function () {
|
||||
if (input.val() == input.attr('placeholder')) {
|
||||
input.val('');
|
||||
}
|
||||
});
|
||||
|
||||
input.blur(function () {
|
||||
if (input.val() == '' || input.val() == input.attr('placeholder')) {
|
||||
input.val(input.attr('placeholder'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Select2 Dropdowns
|
||||
var handleSelect2 = function() {
|
||||
if (jQuery().select2) {
|
||||
$('.select2me').select2({
|
||||
placeholder: "Select",
|
||||
allowClear: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//* END:CORE HANDLERS *//
|
||||
|
||||
return {
|
||||
|
||||
//main function to initiate the theme
|
||||
init: function () {
|
||||
//IMPORTANT!!!: Do not modify the core handlers call order.
|
||||
|
||||
//Core handlers
|
||||
handleInit(); // initialize core variables
|
||||
handleOnResize(); // set and handle responsive
|
||||
|
||||
//UI Component handlers
|
||||
handleUniform(); // hanfle custom radio & checkboxes
|
||||
handleBootstrapSwitch(); // handle bootstrap switch plugin
|
||||
handleScrollers(); // handles slim scrolling contents
|
||||
handleFancybox() // handle fancy box
|
||||
handleSelect2(); // handle custom Select2 dropdowns
|
||||
handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove)
|
||||
handleAlerts(); //handle closabled alerts
|
||||
handleDropdowns(); // handle dropdowns
|
||||
handleTabs(); // handle tabs
|
||||
handleTooltips(); // handle bootstrap tooltips
|
||||
handlePopovers(); // handles bootstrap popovers
|
||||
handleAccordions(); //handles accordions
|
||||
handleModals(); // handle modals
|
||||
},
|
||||
|
||||
//main function to initiate core javascript after ajax complete
|
||||
initAjax: function () {
|
||||
handleScrollers(); // handles slim scrolling contents
|
||||
handleSelect2(); // handle custom Select2 dropdowns
|
||||
handleDropdowns(); // handle dropdowns
|
||||
handleTooltips(); // handle bootstrap tooltips
|
||||
handlePopovers(); // handles bootstrap popovers
|
||||
handleAccordions(); //handles accordions
|
||||
handleUniform(); // hanfle custom radio & checkboxes
|
||||
handleBootstrapSwitch(); // handle bootstrap switch plugin
|
||||
handleDropdownHover() // handles dropdown hover
|
||||
},
|
||||
|
||||
//public function to remember last opened popover that needs to be closed on click
|
||||
setLastPopedPopover: function (el) {
|
||||
lastPopedPopover = el;
|
||||
},
|
||||
|
||||
//public function to add callback a function which will be called on window resize
|
||||
addResizeHandler: function (func) {
|
||||
resizeHandlers.push(func);
|
||||
},
|
||||
|
||||
//public functon to call _runresizeHandlers
|
||||
runResizeHandlers: function() {
|
||||
_runResizeHandlers();
|
||||
},
|
||||
|
||||
// wrMetronicer function to scroll(focus) to an element
|
||||
scrollTo: function (el, offeset) {
|
||||
var pos = (el && el.size() > 0) ? el.offset().top : 0;
|
||||
|
||||
if (el) {
|
||||
if ($('body').hasClass('page-header-fixed')) {
|
||||
pos = pos - $('.page-header').height();
|
||||
}
|
||||
pos = pos + (offeset ? offeset : -1 * el.height());
|
||||
}
|
||||
|
||||
jQuery('html,body').animate({
|
||||
scrollTop: pos
|
||||
}, 'slow');
|
||||
},
|
||||
|
||||
// function to scroll to the top
|
||||
scrollTop: function () {
|
||||
Metronic.scrollTo();
|
||||
},
|
||||
|
||||
// wrMetronicer function to block element(indicate loading)
|
||||
blockUI: function (options) {
|
||||
var options = $.extend(true, {}, options);
|
||||
var html = '';
|
||||
if (options.iconOnly) {
|
||||
html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""></div>';
|
||||
} else if (options.textOnly) {
|
||||
html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><span> ' + (options.message ? options.message : 'LOADING...') + '</span></div>';
|
||||
} else {
|
||||
html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""><span> ' + (options.message ? options.message : 'LOADING...') + '</span></div>';
|
||||
}
|
||||
|
||||
if (options.target) { // element blocking
|
||||
var el = jQuery(options.target);
|
||||
if (el.height() <= ($(window).height())) {
|
||||
options.cenrerY = true;
|
||||
}
|
||||
el.block({
|
||||
message: html,
|
||||
baseZ: options.zIndex ? options.zIndex : 1000,
|
||||
centerY: options.cenrerY != undefined ? options.cenrerY : false,
|
||||
css: {
|
||||
top: '10%',
|
||||
border: '0',
|
||||
padding: '0',
|
||||
backgroundColor: 'none'
|
||||
},
|
||||
overlayCSS: {
|
||||
backgroundColor: options.overlayColor ? options.overlayColor : '#000',
|
||||
opacity: options.boxed ? 0.05 : 0.1,
|
||||
cursor: 'wait'
|
||||
}
|
||||
});
|
||||
} else { // page blocking
|
||||
$.blockUI({
|
||||
message: html,
|
||||
baseZ: options.zIndex ? options.zIndex : 1000,
|
||||
css: {
|
||||
border: '0',
|
||||
padding: '0',
|
||||
backgroundColor: 'none'
|
||||
},
|
||||
overlayCSS: {
|
||||
backgroundColor: options.overlayColor ? options.overlayColor : '#000',
|
||||
opacity: options.boxed ? 0.05 : 0.1,
|
||||
cursor: 'wait'
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// wrMetronicer function to un-block element(finish loading)
|
||||
unblockUI: function (target) {
|
||||
if (target) {
|
||||
jQuery(target).unblock({
|
||||
onUnblock: function () {
|
||||
jQuery(target).css('position', '');
|
||||
jQuery(target).css('zoom', '');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$.unblockUI();
|
||||
}
|
||||
},
|
||||
|
||||
startPageLoading: function(message) {
|
||||
$('.page-loading').remove();
|
||||
$('body').append('<div class="page-loading"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif"/> <span>' + (message ? message : 'Loading...') + '</span></div>');
|
||||
},
|
||||
|
||||
stopPageLoading: function() {
|
||||
$('.page-loading').remove();
|
||||
},
|
||||
|
||||
alert: function(options) {
|
||||
|
||||
options = $.extend(true, {
|
||||
container: "", // alerts parent container(by default placed after the page breadcrumbs)
|
||||
place: "append", // append or prepent in container
|
||||
type: 'success', // alert's type
|
||||
message: "", // alert's message
|
||||
close: true, // make alert closable
|
||||
reset: true, // close all previouse alerts first
|
||||
focus: true, // auto scroll to the alert after shown
|
||||
closeInSeconds: 0, // auto close after defined seconds
|
||||
icon: "" // put icon before the message
|
||||
}, options);
|
||||
|
||||
var id = Metronic.getUniqueID("Metronic_alert");
|
||||
|
||||
var html = '<div id="'+id+'" class="Metronic-alerts alert alert-'+options.type+' fade in">' + (options.close ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>' : '' ) + (options.icon != "" ? '<i class="fa-lg fa fa-'+options.icon + '"></i> ' : '') + options.message+'</div>'
|
||||
|
||||
if (options.reset) {0
|
||||
$('.Metronic-alerts').remove();
|
||||
}
|
||||
|
||||
if (!options.container) {
|
||||
$('.page-breadcrumb').after(html);
|
||||
} else {
|
||||
if (options.place == "append") {
|
||||
$(options.container).append(html);
|
||||
} else {
|
||||
$(options.container).prepend(html);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.focus) {
|
||||
Metronic.scrollTo($('#' + id));
|
||||
}
|
||||
|
||||
if (options.closeInSeconds > 0) {
|
||||
setTimeout(function(){
|
||||
$('#' + id).remove();
|
||||
}, options.closeInSeconds * 1000);
|
||||
}
|
||||
},
|
||||
|
||||
// initializes uniform elements
|
||||
initUniform: function (els) {
|
||||
if (els) {
|
||||
jQuery(els).each(function () {
|
||||
if ($(this).parents(".checker").size() == 0) {
|
||||
$(this).show();
|
||||
$(this).uniform();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleUniform();
|
||||
}
|
||||
},
|
||||
|
||||
//wrMetronicer function to update/sync jquery uniform checkbox & radios
|
||||
updateUniform: function (els) {
|
||||
$.uniform.update(els); // update the uniform checkbox & radios UI after the actual input control state changed
|
||||
},
|
||||
|
||||
//public function to initialize the fancybox plugin
|
||||
initFancybox: function () {
|
||||
handleFancybox();
|
||||
},
|
||||
|
||||
//public helper function to get actual input value(used in IE9 and IE8 due to placeholder attribute not supported)
|
||||
getActualVal: function (el) {
|
||||
var el = jQuery(el);
|
||||
if (el.val() === el.attr("placeholder")) {
|
||||
return "";
|
||||
}
|
||||
return el.val();
|
||||
},
|
||||
|
||||
//public function to get a paremeter by name from URL
|
||||
getURLParameter: function (paramName) {
|
||||
var searchString = window.location.search.substring(1),
|
||||
i, val, params = searchString.split("&");
|
||||
|
||||
for (i = 0; i < params.length; i++) {
|
||||
val = params[i].split("=");
|
||||
if (val[0] == paramName) {
|
||||
return unescape(val[1]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// check for device touch support
|
||||
isTouchDevice: function () {
|
||||
try {
|
||||
document.createEvent("TouchEvent");
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// To get the correct viewport width based on http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
|
||||
getViewPort: function () {
|
||||
var e = window, a = 'inner';
|
||||
if (!('innerWidth' in window)) {
|
||||
a = 'client';
|
||||
e = document.documentElement || document.body;
|
||||
}
|
||||
return {
|
||||
width: e[a + 'Width'],
|
||||
height: e[a + 'Height']
|
||||
}
|
||||
},
|
||||
|
||||
getUniqueID: function(prefix) {
|
||||
return 'prefix_' + Math.floor(Math.random() * (new Date()).getTime());
|
||||
},
|
||||
|
||||
// check IE8 mode
|
||||
isIE8: function () {
|
||||
return isIE8;
|
||||
},
|
||||
|
||||
// check IE9 mode
|
||||
isIE9: function () {
|
||||
return isIE9;
|
||||
},
|
||||
|
||||
//check RTL mode
|
||||
isRTL: function () {
|
||||
return isRTL;
|
||||
},
|
||||
|
||||
getGlobalImgPath: function () {
|
||||
return globalImgPath;
|
||||
},
|
||||
|
||||
// get layout color code by color name
|
||||
getBrandColor: function (name) {
|
||||
if (brandColors[name]) {
|
||||
return brandColors[name];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}();
|
88
frontend/static/assets/global/scripts/pagination.js
Normal file
88
frontend/static/assets/global/scripts/pagination.js
Normal file
@@ -0,0 +1,88 @@
|
||||
//container 容器,count 总页数 pageindex 当前页数
|
||||
var paging_url;
|
||||
function setUrl (urlstring) {
|
||||
paging_url = urlstring;
|
||||
}
|
||||
function setPage(container, count, pageindex) {
|
||||
var container = container;
|
||||
var count = count;
|
||||
var pageindex = pageindex;
|
||||
var a = [];
|
||||
//总页数少于10 全部显示,大于10 显示前3 后3 中间3 其余....
|
||||
if (pageindex == 1) {
|
||||
a[a.length] = "<li class=\"disabled\"><a href=\"#\">上一页</a></li>";
|
||||
} else {
|
||||
a[a.length] = "<li><a href=\"#\">上一页</a></li>";
|
||||
}
|
||||
function setPageList() {
|
||||
if (pageindex == i) {
|
||||
a[a.length] = "<li class=\"disabled\"><a href=\"#\">" + i + "</a></li>";
|
||||
} else {
|
||||
a[a.length] = "<li><a href=\"#\">" + i + "</a></li>";
|
||||
}
|
||||
}
|
||||
//总页数小于10
|
||||
if (count <= 10) {
|
||||
for (var i = 1; i <= count; i++) {
|
||||
setPageList();
|
||||
}
|
||||
}
|
||||
//总页数大于10页
|
||||
else {
|
||||
if (pageindex <= 4) {
|
||||
for (var i = 1; i <= 5; i++) {
|
||||
setPageList();
|
||||
}
|
||||
a[a.length] = "<li><span>...</span></li><li><a href=\"#\">" + count + "</a></li>";
|
||||
} else if (pageindex >= count - 3) {
|
||||
a[a.length] = "<li><a href=\"#\"> 1 </a></li><li><span>...</span></li>";
|
||||
for (var i = count - 4; i <= count; i++) {
|
||||
setPageList();
|
||||
}
|
||||
}
|
||||
else { //当前页在中间部分
|
||||
a[a.length] = "<li><a href=\"#\"> 1 </a></li><li><span>...</span></li>";
|
||||
for (var i = pageindex - 2; i <= pageindex + 2; i++) {
|
||||
setPageList();
|
||||
}
|
||||
a[a.length] = "<li><span>...</span></li><li><a href=\"#\">" + count + " </a></li>";
|
||||
}
|
||||
}
|
||||
if (pageindex == count) {
|
||||
a[a.length] = "<li class=\"disabled\"><a href=\"#\">下一页</a></li>";
|
||||
} else {
|
||||
a[a.length] = "<li><a href=\"#\">下一页</a></li>";
|
||||
}
|
||||
container.innerHTML = a.join("");
|
||||
//事件点击
|
||||
var pageClick = function() {
|
||||
var oAlink = container.getElementsByTagName("a");
|
||||
var inx = pageindex; //初始的页码
|
||||
oAlink[0].onclick = function() { //点击上一页
|
||||
if (inx == 1) {
|
||||
return false;
|
||||
}
|
||||
inx--;
|
||||
//setPage(container, count, inx);
|
||||
window.location.href=paging_url+inx;
|
||||
return false;
|
||||
}
|
||||
for (var i = 1; i < oAlink.length - 1; i++) { //点击页码
|
||||
oAlink[i].onclick = function() {
|
||||
inx = parseInt(this.innerHTML);
|
||||
//setPage(container, count, inx);
|
||||
window.location.href=paging_url+inx;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
oAlink[oAlink.length - 1].onclick = function() { //点击下一页
|
||||
if (inx == count) {
|
||||
return false;
|
||||
}
|
||||
inx++;
|
||||
//setPage(container, count, inx);
|
||||
window.location.href=paging_url+inx;
|
||||
return false;
|
||||
}
|
||||
} ()
|
||||
}
|
Reference in New Issue
Block a user