3997 lines
230 KiB
JavaScript
3997 lines
230 KiB
JavaScript
|
/*!
|
||
|
* Minified Utility Resources
|
||
|
* Theme Core resources.
|
||
|
*/
|
||
|
|
||
|
;
|
||
|
(function ($) {
|
||
|
var defaults = {
|
||
|
width: 400,
|
||
|
height: "65%",
|
||
|
minimizedWidth: 200,
|
||
|
gutter: 10,
|
||
|
poppedOutDistance: "6%",
|
||
|
title: function() {
|
||
|
return "";
|
||
|
},
|
||
|
dialogClass: "",
|
||
|
buttons: [], /* id, html, buttonClass, click */
|
||
|
animationSpeed: 400,
|
||
|
opacity: 1,
|
||
|
initialState: 'modal', /* "modal", "docked", "minimized" */
|
||
|
|
||
|
showClose: true,
|
||
|
showPopout: true,
|
||
|
showMinimize: true,
|
||
|
|
||
|
create: undefined,
|
||
|
open: undefined,
|
||
|
beforeClose: undefined,
|
||
|
close: undefined,
|
||
|
beforeMinimize: undefined,
|
||
|
minimize: undefined,
|
||
|
beforeRestore: undefined,
|
||
|
restore: undefined,
|
||
|
beforePopout: undefined,
|
||
|
popout: undefined
|
||
|
};
|
||
|
var dClass = "dockmodal";
|
||
|
var windowWidth = $(window).width();
|
||
|
|
||
|
function setAnimationCSS($this, $el) {
|
||
|
var aniSpeed = $this.options.animationSpeed / 1000;
|
||
|
$el.css({"transition": aniSpeed + "s right, " + aniSpeed + "s left, " + aniSpeed + "s top, " + aniSpeed + "s bottom, " + aniSpeed + "s height, " + aniSpeed + "s width"});
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
function removeAnimationCSS($el) {
|
||
|
$el.css({"transition": "none"});
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
var methods = {
|
||
|
init: function (options) {
|
||
|
|
||
|
return this.each(function () {
|
||
|
|
||
|
var $this = $(this);
|
||
|
|
||
|
var data = $this.data('dockmodal');
|
||
|
$this.options = $.extend({}, defaults, options);
|
||
|
|
||
|
// Does title a returned function?
|
||
|
(function titleCheck() {
|
||
|
if (typeof $this.options.title == "function") {
|
||
|
$this.options.title = $this.options.title.call($this);
|
||
|
}
|
||
|
})();
|
||
|
|
||
|
// If the plugin has not been initialized yet
|
||
|
if (!data) {
|
||
|
$this.data('dockmodal', $this);
|
||
|
} else {
|
||
|
$("body").append($this.closest("." + dClass).show());
|
||
|
methods.refreshLayout();
|
||
|
setTimeout(function () {
|
||
|
methods.restore.apply($this);
|
||
|
}, $this.options.animationSpeed);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Create modal
|
||
|
var $body = $("body");
|
||
|
var $window = $(window);
|
||
|
var $dockModal = $('<div/>').addClass(dClass).addClass($this.options.dialogClass);
|
||
|
if ($this.options.initialState == "modal") {
|
||
|
$dockModal.addClass("popped-out");
|
||
|
} else if ($this.options.initialState == "minimized") {
|
||
|
$dockModal.addClass("minimized");
|
||
|
}
|
||
|
$dockModal.height(0);
|
||
|
setAnimationCSS($this, $dockModal);
|
||
|
|
||
|
// Create title
|
||
|
var $dockHeader = $('<div></div>').addClass(dClass + "-header");
|
||
|
|
||
|
if ($this.options.showClose) {
|
||
|
$('<a href="#" class="header-action action-close" title="Close"><i class="icon-dockmodal-close"></i></a>').appendTo($dockHeader).click(function (e) {
|
||
|
methods.destroy.apply($this);
|
||
|
return false;
|
||
|
});
|
||
|
}
|
||
|
if ($this.options.showPopout) {
|
||
|
$('<a href="#" class="header-action action-popout" title="Pop out"><i class="icon-dockmodal-popout"></i></a>').appendTo($dockHeader).click(function (e) {
|
||
|
if ($dockModal.hasClass("popped-out")) {
|
||
|
methods.restore.apply($this);
|
||
|
} else {
|
||
|
methods.popout.apply($this);
|
||
|
}
|
||
|
return false;
|
||
|
});
|
||
|
}
|
||
|
if ($this.options.showMinimize) {
|
||
|
$('<a href="#" class="header-action action-minimize" title="Minimize"><i class="icon-dockmodal-minimize"></i></a>').appendTo($dockHeader).click(function (e) {
|
||
|
if ($dockModal.hasClass("minimized")) {
|
||
|
if ($dockModal.hasClass("popped-out")) {
|
||
|
methods.popout.apply($this);
|
||
|
} else {
|
||
|
methods.restore.apply($this);
|
||
|
}
|
||
|
} else {
|
||
|
methods.minimize.apply($this);
|
||
|
}
|
||
|
return false;
|
||
|
});
|
||
|
}
|
||
|
if ($this.options.showMinimize && $this.options.showPopout) {
|
||
|
$dockHeader.click(function () {
|
||
|
if ($dockModal.hasClass("minimized")) {
|
||
|
if ($dockModal.hasClass("popped-out")) {
|
||
|
methods.popout.apply($this);
|
||
|
} else {
|
||
|
methods.restore.apply($this);
|
||
|
}
|
||
|
} else {
|
||
|
methods.minimize.apply($this);
|
||
|
}
|
||
|
return false;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
$dockHeader.append('<div class="title-text">' + ($this.options.title || $this.attr("title")) + '</div>');
|
||
|
$dockModal.append($dockHeader);
|
||
|
|
||
|
// Create body
|
||
|
var $placeholder = $('<div class="modal-placeholder"></div>').insertAfter($this);
|
||
|
$this.placeholder = $placeholder;
|
||
|
var $dockBody = $('<div></div>').addClass(dClass + "-body").append($this);
|
||
|
$dockModal.append($dockBody);
|
||
|
|
||
|
// Create footer
|
||
|
if ($this.options.buttons.length) {
|
||
|
var $dockFooter = $('<div></div>').addClass(dClass + "-footer");
|
||
|
var $dockFooterButtonset = $('<div></div>').addClass(dClass + "-footer-buttonset");
|
||
|
$dockFooter.append($dockFooterButtonset);
|
||
|
$.each($this.options.buttons, function (indx, el) {
|
||
|
var $btn = $('<a href="#" class="btn"></a>');
|
||
|
$btn.attr({ "id": el.id, "class": el.buttonClass });
|
||
|
$btn.html(el.html);
|
||
|
$btn.click(function (e) {
|
||
|
el.click(e, $this);
|
||
|
return false;
|
||
|
});
|
||
|
$dockFooterButtonset.append($btn);
|
||
|
});
|
||
|
$dockModal.append($dockFooter);
|
||
|
} else {
|
||
|
$dockModal.addClass("no-footer");
|
||
|
}
|
||
|
|
||
|
// Create overlay
|
||
|
var $overlay = $("." + dClass + "-overlay");
|
||
|
if (!$overlay.length) {
|
||
|
$overlay = $('<div/>').addClass(dClass + "-overlay");
|
||
|
}
|
||
|
|
||
|
if ($.isFunction($this.options.create)) {
|
||
|
$this.options.create($this);
|
||
|
}
|
||
|
|
||
|
$body.append($dockModal);
|
||
|
$dockModal.after($overlay);
|
||
|
$dockBody.focus();
|
||
|
|
||
|
if ($.isFunction($this.options.open)) {
|
||
|
setTimeout(function () {
|
||
|
$this.options.open($this);
|
||
|
}, $this.options.animationSpeed);
|
||
|
}
|
||
|
|
||
|
if ($dockModal.hasClass("minimized")) {
|
||
|
$dockModal.find(".dockmodal-body, .dockmodal-footer").hide();
|
||
|
methods.minimize.apply($this);
|
||
|
} else {
|
||
|
if ($dockModal.hasClass("popped-out")) {
|
||
|
methods.popout.apply($this);
|
||
|
} else {
|
||
|
methods.restore.apply($this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$body.data("windowWidth", $window.width());
|
||
|
|
||
|
$window.unbind("resize.dockmodal").bind("resize.dockmodal", function () {
|
||
|
if ($window.width() == $body.data("windowWidth")) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$body.data("windowWidth", $window.width());
|
||
|
methods.refreshLayout();
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
destroy: function () {
|
||
|
return this.each(function () {
|
||
|
|
||
|
var $this = $(this).data('dockmodal');
|
||
|
if (!$this)
|
||
|
return;
|
||
|
|
||
|
if ($.isFunction($this.options.beforeClose)) {
|
||
|
if ($this.options.beforeClose($this) === false) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
var $dockModal = $this.closest("." + dClass);
|
||
|
|
||
|
if ($dockModal.hasClass("popped-out") && !$dockModal.hasClass("minimized")) {
|
||
|
$dockModal.css({
|
||
|
"left": "50%",
|
||
|
"right": "50%",
|
||
|
"top": "50%",
|
||
|
"bottom": "50%"
|
||
|
});
|
||
|
} else {
|
||
|
$dockModal.css({
|
||
|
"width": "0",
|
||
|
"height": "0"
|
||
|
});
|
||
|
}
|
||
|
setTimeout(function () {
|
||
|
$this.removeData('dockmodal');
|
||
|
$this.placeholder.replaceWith($this);
|
||
|
$dockModal.remove();
|
||
|
$("." + dClass + "-overlay").hide();
|
||
|
methods.refreshLayout();
|
||
|
|
||
|
if ($.isFunction($this.options.close)) {
|
||
|
$this.options.close($this);
|
||
|
}
|
||
|
}, $this.options.animationSpeed);
|
||
|
|
||
|
}
|
||
|
catch (err) {
|
||
|
alert(err.message);
|
||
|
}
|
||
|
|
||
|
})
|
||
|
},
|
||
|
close: function () {
|
||
|
methods.destroy.apply(this);
|
||
|
},
|
||
|
minimize: function () {
|
||
|
return this.each(function () {
|
||
|
|
||
|
var $this = $(this).data('dockmodal');
|
||
|
if (!$this)
|
||
|
return;
|
||
|
|
||
|
if ($.isFunction($this.options.beforeMinimize)) {
|
||
|
if ($this.options.beforeMinimize($this) === false) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var $dockModal = $this.closest("." + dClass);
|
||
|
var headerHeight = $dockModal.find(".dockmodal-header").outerHeight();
|
||
|
$dockModal.addClass("minimized").css({
|
||
|
"width": $this.options.minimizedWidth + "px",
|
||
|
"height": headerHeight + "px",
|
||
|
"left": "auto",
|
||
|
"right": "auto",
|
||
|
"top": "auto",
|
||
|
"bottom": "0"
|
||
|
});
|
||
|
setTimeout(function () {
|
||
|
// hide the body and footer
|
||
|
$dockModal.find(".dockmodal-body, .dockmodal-footer").hide();
|
||
|
|
||
|
if ($.isFunction($this.options.minimize)) {
|
||
|
$this.options.minimize($this);
|
||
|
}
|
||
|
}, $this.options.animationSpeed);
|
||
|
|
||
|
$("." + dClass + "-overlay").hide();
|
||
|
$dockModal.find(".action-minimize").attr("title", "Restore");
|
||
|
|
||
|
methods.refreshLayout();
|
||
|
})
|
||
|
},
|
||
|
restore: function () {
|
||
|
return this.each(function () {
|
||
|
|
||
|
var $this = $(this).data('dockmodal');
|
||
|
if (!$this)
|
||
|
return;
|
||
|
|
||
|
if ($.isFunction($this.options.beforeRestore)) {
|
||
|
if ($this.options.beforeRestore($this) === false) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var $dockModal = $this.closest("." + dClass);
|
||
|
$dockModal.removeClass("minimized popped-out");
|
||
|
$dockModal.find(".dockmodal-body, .dockmodal-footer").show();
|
||
|
$dockModal.css({
|
||
|
"width": $this.options.width + "px",
|
||
|
"height": $this.options.height,
|
||
|
"left": "auto",
|
||
|
"right": "auto",
|
||
|
"top": "auto",
|
||
|
"bottom": "0"
|
||
|
});
|
||
|
|
||
|
$("." + dClass + "-overlay").hide();
|
||
|
$dockModal.find(".action-minimize").attr("title", "Minimize");
|
||
|
$dockModal.find(".action-popout").attr("title", "Pop-out");
|
||
|
|
||
|
setTimeout(function () {
|
||
|
if ($.isFunction($this.options.restore)) {
|
||
|
$this.options.restore($this);
|
||
|
}
|
||
|
}, $this.options.animationSpeed);
|
||
|
|
||
|
methods.refreshLayout();
|
||
|
})
|
||
|
},
|
||
|
popout: function () {
|
||
|
return this.each(function () {
|
||
|
|
||
|
var $this = $(this).data('dockmodal');
|
||
|
if (!$this)
|
||
|
return;
|
||
|
|
||
|
if ($.isFunction($this.options.beforePopout)) {
|
||
|
if ($this.options.beforePopout($this) === false) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var $dockModal = $this.closest("." + dClass);
|
||
|
$dockModal.find(".dockmodal-body, .dockmodal-footer").show();
|
||
|
|
||
|
removeAnimationCSS($dockModal);
|
||
|
var offset = $dockModal.position();
|
||
|
var windowWidth = $(window).width();
|
||
|
$dockModal.css({
|
||
|
"width": "auto",
|
||
|
"height": "auto",
|
||
|
"left": offset.left + "px",
|
||
|
"right": (windowWidth - offset.left - $dockModal.outerWidth(true)) + "px",
|
||
|
"top": offset.top + "px",
|
||
|
"bottom": 0
|
||
|
});
|
||
|
|
||
|
setAnimationCSS($this, $dockModal);
|
||
|
setTimeout(function () {
|
||
|
$dockModal.removeClass("minimized").addClass("popped-out").css({
|
||
|
"width": "auto",
|
||
|
"height": "auto",
|
||
|
"left": $this.options.poppedOutDistance,
|
||
|
"right": $this.options.poppedOutDistance,
|
||
|
"top": $this.options.poppedOutDistance,
|
||
|
"bottom": $this.options.poppedOutDistance
|
||
|
});
|
||
|
$("." + dClass + "-overlay").show();
|
||
|
$dockModal.find(".action-popout").attr("title", "Pop-in");
|
||
|
|
||
|
methods.refreshLayout();
|
||
|
}, 10);
|
||
|
|
||
|
setTimeout(function () {
|
||
|
if ($.isFunction($this.options.popout)) {
|
||
|
$this.options.popout($this);
|
||
|
}
|
||
|
}, $this.options.animationSpeed);
|
||
|
});
|
||
|
},
|
||
|
refreshLayout: function () {
|
||
|
|
||
|
var right = 0;
|
||
|
var windowWidth = $(window).width();
|
||
|
|
||
|
$.each($("." + dClass).toArray().reverse(), function (i, val) {
|
||
|
var $dockModal = $(this);
|
||
|
var $this = $dockModal.find("." + dClass + "-body > div").data("dockmodal");
|
||
|
|
||
|
if ($dockModal.hasClass("popped-out") && !$dockModal.hasClass("minimized")) {
|
||
|
return;
|
||
|
}
|
||
|
right += $this.options.gutter;
|
||
|
$dockModal.css({ "right": right + "px" });
|
||
|
if ($dockModal.hasClass("minimized")) {
|
||
|
right += $this.options.minimizedWidth;
|
||
|
} else {
|
||
|
right += $this.options.width;
|
||
|
}
|
||
|
if (right > windowWidth) {
|
||
|
$dockModal.hide();
|
||
|
} else {
|
||
|
setTimeout(function () {
|
||
|
$dockModal.show();
|
||
|
}, $this.options.animationSpeed);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
$.fn.dockmodal = function (method) {
|
||
|
if (methods[method]) {
|
||
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||
|
} else if (typeof method === 'object' || !method) {
|
||
|
return methods.init.apply(this, arguments);
|
||
|
} else {
|
||
|
$.error('Method ' + method + ' does not exist on jQuery.dockmodal');
|
||
|
}
|
||
|
};
|
||
|
})(jQuery);
|
||
|
|
||
|
|
||
|
(function($, window, document, undefined) {
|
||
|
|
||
|
$.fn.allcppanel = function(options) {
|
||
|
|
||
|
// Plugin options
|
||
|
var defaults = {
|
||
|
grid: '.allcp-grid',
|
||
|
draggable: false,
|
||
|
mobile: false,
|
||
|
preserveGrid: false,
|
||
|
onPanel: function() {
|
||
|
console.log('callback:', 'onPanel');
|
||
|
},
|
||
|
onStart: function() {
|
||
|
console.log('callback:', 'onStart');
|
||
|
},
|
||
|
onSave: function() {
|
||
|
console.log('callback:', 'onSave');
|
||
|
},
|
||
|
onDrop: function() {
|
||
|
console.log('callback:', 'onDrop');
|
||
|
},
|
||
|
onFinish: function() {
|
||
|
console.log('callback:', 'onFinish');
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Extend default options
|
||
|
var options = $.extend({}, defaults, options);
|
||
|
|
||
|
// Variables
|
||
|
var plugin = $(this);
|
||
|
var pluginGrid = options.grid;
|
||
|
var dragSetting = options.draggable;
|
||
|
var mobileSetting = options.mobile;
|
||
|
var preserveSetting = options.preserveGrid;
|
||
|
var panels = plugin.find('.panel');
|
||
|
|
||
|
// HTML5 Local Storage Keys
|
||
|
var settingsKey = 'panel-settings_' + location.pathname;
|
||
|
var positionsKey = 'panel-positions_' + location.pathname;
|
||
|
|
||
|
// HTML5 Local Storage Gets
|
||
|
var settingsGet = localStorage.getItem(settingsKey);
|
||
|
var positionsGet = localStorage.getItem(positionsKey);
|
||
|
|
||
|
// Control Menu on Click Handler
|
||
|
$('.panel').on('click', '.panel-controls > a', function(e) {
|
||
|
e.preventDefault();
|
||
|
|
||
|
// Disable clicks while dragging
|
||
|
if ($('body.ui-drag-active').length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
methods.controlHandlers.call(this, options);
|
||
|
});
|
||
|
|
||
|
var methods = {
|
||
|
init: function(options) {
|
||
|
var This = $(this);
|
||
|
|
||
|
if (typeof options.onStart == 'function') {
|
||
|
options.onStart();
|
||
|
}
|
||
|
|
||
|
// Check on load to see if positions key is empty
|
||
|
if (!positionsGet) {
|
||
|
localStorage.setItem(positionsKey, methods.findPositions());
|
||
|
} else {
|
||
|
methods.setPositions();
|
||
|
}
|
||
|
|
||
|
// Check on load to see if settings key is empty
|
||
|
if (!settingsGet) {
|
||
|
localStorage.setItem(settingsKey, methods.modifySettings());
|
||
|
}
|
||
|
|
||
|
// Add unique ID's to grid elements
|
||
|
$(pluginGrid).each(function(i, e) {
|
||
|
$(e).attr('id', 'grid-' + i);
|
||
|
});
|
||
|
|
||
|
// Check preserve need using an invisible panel
|
||
|
if (preserveSetting) {
|
||
|
var Panel = "<div class='panel preserve-grid'></div>";
|
||
|
$(pluginGrid).each(function(i, e) {
|
||
|
$(e).append(Panel);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// Prep spec panel/container prior to menu creation
|
||
|
methods.createControls(options);
|
||
|
|
||
|
methods.applySettings();
|
||
|
|
||
|
// Create Mobile Controls
|
||
|
methods.createMobileControls(options);
|
||
|
|
||
|
if (dragSetting === true) {
|
||
|
// Activate sortable on declared grids/panels
|
||
|
plugin.sortable({
|
||
|
items: plugin.find('.panel:not(".sort-disable")'),
|
||
|
connectWith: pluginGrid,
|
||
|
cursor: 'default',
|
||
|
revert: 250,
|
||
|
handle: '.panel-heading',
|
||
|
opacity: 1,
|
||
|
delay: 100,
|
||
|
tolerance: "pointer",
|
||
|
scroll: true,
|
||
|
placeholder: 'panel-placeholder',
|
||
|
forcePlaceholderSize: true,
|
||
|
forceHelperSize: true,
|
||
|
start: function(e, ui) {
|
||
|
$('body').addClass('ui-drag-active');
|
||
|
ui.placeholder.height(ui.helper.outerHeight() - 4);
|
||
|
},
|
||
|
beforeStop: function() {
|
||
|
if (typeof options.onDrop == 'function') {
|
||
|
options.onDrop();
|
||
|
}
|
||
|
},
|
||
|
stop: function() {
|
||
|
$('body').removeClass('ui-drag-active');
|
||
|
},
|
||
|
update: function(event, ui) {
|
||
|
// toggle "loading"
|
||
|
methods.toggleLoader();
|
||
|
|
||
|
// store plugins positions
|
||
|
methods.updatePositions(options);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// onFinish callback
|
||
|
if (typeof options.onFinish == 'function') {
|
||
|
options.onFinish();
|
||
|
}
|
||
|
},
|
||
|
createMobileControls: function(options) {
|
||
|
|
||
|
var controls = panels.find('.panel-controls');
|
||
|
|
||
|
var arr = {};
|
||
|
|
||
|
$.each(controls, function(i, e) {
|
||
|
var This = $(e);
|
||
|
var ID = $(e).parents('.panel').attr('id');
|
||
|
|
||
|
var controlW = This.width();
|
||
|
var titleW = This.siblings('.panel-title').width();
|
||
|
var headingW = This.parent('.panel-heading').width();
|
||
|
var mobile = (controlW + titleW);
|
||
|
arr[ID] = mobile;
|
||
|
});
|
||
|
|
||
|
$.each(arr, function(i, e) {
|
||
|
|
||
|
var This = $('#' + i);
|
||
|
var headingW = This.width() - 75;
|
||
|
var controls = This.find('.panel-controls');
|
||
|
|
||
|
if (mobileSetting === true || headingW < e) {
|
||
|
This.addClass('mobile-controls');
|
||
|
var options = {
|
||
|
html: true,
|
||
|
placement: "left",
|
||
|
content: function(e) {
|
||
|
var Content = $(this).clone();
|
||
|
return Content;
|
||
|
},
|
||
|
template: '<div data-popover-id="'+i+'" class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
|
||
|
};
|
||
|
controls.popover(options);
|
||
|
} else {
|
||
|
controls.removeClass('mobile-controls');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// Toggle panel controls menu open on click
|
||
|
$('.mobile-controls .panel-heading > .panel-controls').on('click', function() {
|
||
|
$(this).toggleClass('panel-controls-open');
|
||
|
});
|
||
|
|
||
|
},
|
||
|
applySettings: function(options) {
|
||
|
|
||
|
var obj = this;
|
||
|
var localSettings = localStorage.getItem(settingsKey);
|
||
|
var parseSettings = JSON.parse(localSettings);
|
||
|
|
||
|
// Panel colors
|
||
|
var panelColors = "panel-primary panel-success panel-info panel-warning panel-danger panel-alert panel-system panel-dark panel-default";
|
||
|
|
||
|
$.each(parseSettings, function(i, e) {
|
||
|
|
||
|
$.each(e, function(i, e) {
|
||
|
var panelID = e['id'];
|
||
|
var panelTitle = e['title'];
|
||
|
var panelCollapsed = e['collapsed'];
|
||
|
var panelHidden = e['hidden'];
|
||
|
var panelColor = e['color'];
|
||
|
var Target = $('#' + panelID);
|
||
|
|
||
|
if (panelTitle) {
|
||
|
Target.children('.panel-heading').find('.panel-title').text(panelTitle);
|
||
|
}
|
||
|
if (panelCollapsed === 1) {
|
||
|
Target.addClass('panel-collapsed')
|
||
|
.children('.panel-body, .panel-menu, .panel-footer').hide();
|
||
|
}
|
||
|
if (panelColor) {
|
||
|
Target.removeClass(panelColors).addClass(panelColor).attr('data-panel-color', panelColor);
|
||
|
}
|
||
|
if (panelHidden === 1) {
|
||
|
Target.addClass('panel-hidden').hide().remove();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
createControls: function(options) {
|
||
|
|
||
|
// List panel controls
|
||
|
var panelControls = '<span class="panel-controls"></span>';
|
||
|
var panelTitle = '<a href="#" class="panel-control-title"></a>';
|
||
|
var panelColor = '';
|
||
|
var panelCollapse = '<a href="#" class="panel-control-collapse"></a>';
|
||
|
var panelFullscreen = '';
|
||
|
var panelRemove = '<a href="#" class="panel-control-remove"></a>';
|
||
|
var panelCallback = '<a href="#" class="panel-control-callback"></a>';
|
||
|
var panelDock = '<a href="#" class="panel-control-dockable" data-toggle="popover" data-content="panelDockContent();"></a>';
|
||
|
var panelExpose = '<a href="#" class="panel-control-expose"></a>';
|
||
|
var panelLoader = '<a href="#" class="panel-control-loader"></a>';
|
||
|
|
||
|
panels.each(function(i, e) {
|
||
|
|
||
|
var This = $(e);
|
||
|
|
||
|
var panelHeader = This.children('.panel-heading');
|
||
|
|
||
|
// Check panel for settings specific attr
|
||
|
var title = This.attr('data-panel-title');
|
||
|
var color = This.attr('data-panel-color');
|
||
|
var collapse = This.attr('data-panel-collapse');
|
||
|
var fullscreen = This.attr('data-panel-fullscreen');
|
||
|
var remove = This.attr('data-panel-remove');
|
||
|
var callback = This.attr('data-panel-callback');
|
||
|
var paneldock = This.attr('data-panel-dockable');
|
||
|
var expose = This.attr('data-panel-expose');
|
||
|
var loader = This.attr('data-panel-loader');
|
||
|
|
||
|
$(panelControls).appendTo(panelHeader);
|
||
|
|
||
|
|
||
|
// Attach "loading"
|
||
|
if (!loader) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelLoader).appendTo(panelMenu);
|
||
|
}
|
||
|
if (expose) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelExpose).appendTo(panelMenu);
|
||
|
}
|
||
|
if (paneldock) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelDock).appendTo(panelMenu);
|
||
|
}
|
||
|
if (callback) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelCallback).appendTo(panelMenu);
|
||
|
}
|
||
|
if (!title) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelTitle).appendTo(panelMenu);
|
||
|
}
|
||
|
if (!color) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelColor).appendTo(panelMenu);
|
||
|
}
|
||
|
if (!collapse) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelCollapse).appendTo(panelMenu);
|
||
|
}
|
||
|
if (!remove) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelRemove).appendTo(panelMenu);
|
||
|
}
|
||
|
if (!fullscreen) {
|
||
|
var panelMenu = panelHeader.find('.panel-controls');
|
||
|
$(panelFullscreen).appendTo(panelMenu);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
},
|
||
|
controlHandlers: function(e) {
|
||
|
|
||
|
var This = $(this);
|
||
|
|
||
|
// Control btn indentifiers
|
||
|
var action = This.attr('class');
|
||
|
var panel = This.parents('.panel');
|
||
|
|
||
|
// Panel header vars
|
||
|
var panelHeading = panel.children('.panel-heading');
|
||
|
var panelTitle = panel.find('.panel-title');
|
||
|
|
||
|
// Edit Title
|
||
|
var panelEditTitle = function() {
|
||
|
|
||
|
// Editbox menu toggle
|
||
|
var toggleBox = function() {
|
||
|
var panelEditBox = panel.find('.panel-editbox');
|
||
|
panelEditBox.slideToggle('fast', function() {
|
||
|
panel.toggleClass('panel-editbox-open');
|
||
|
|
||
|
// Save settings on close
|
||
|
if (!panel.hasClass('panel-editbox-open')) {
|
||
|
panelTitle.text(panelEditBox.children('input').val());
|
||
|
methods.updateSettings(options);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// If editbox not found, create it and attach handlers
|
||
|
if (!panel.find('.panel-editbox').length) {
|
||
|
var editBox = '<div class="panel-editbox"><input type="text" class="form-control" value="' + panelTitle.text() + '"></div>';
|
||
|
panelHeading.after(editBox);
|
||
|
|
||
|
// New editbox cont
|
||
|
var panelEditBox = panel.find('.panel-editbox');
|
||
|
|
||
|
// Update panel title on keyup
|
||
|
panelEditBox.children('input').on('keyup', function() {
|
||
|
panelTitle.text(panelEditBox.children('input').val());
|
||
|
});
|
||
|
|
||
|
// Save panel title on enter keypress
|
||
|
panelEditBox.children('input').on('keypress', function(e) {
|
||
|
if (e.which == 13) {
|
||
|
toggleBox();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
toggleBox();
|
||
|
} else {
|
||
|
// If found - toggle the menu
|
||
|
toggleBox();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Panel color definition
|
||
|
var panelColor = function() {
|
||
|
|
||
|
// Create editbox if not found
|
||
|
if (!panel.find('.panel-colorbox').length) {
|
||
|
var colorBox = '<div class="panel-colorbox"> <span class="bg-white" data-panel-color="panel-default"></span> <span class="bg-primary" data-panel-color="panel-primary"></span> <span class="bg-info" data-panel-color="panel-info"></span> <span class="bg-success" data-panel-color="panel-success"></span> <span class="bg-warning" data-panel-color="panel-warning"></span> <span class="bg-danger" data-panel-color="panel-danger"></span> <span class="bg-alert" data-panel-color="panel-alert"></span> <span class="bg-system" data-panel-color="panel-system"></span> <span class="bg-dark" data-panel-color="panel-dark"></span> </div>'
|
||
|
panelHeading.after(colorBox);
|
||
|
}
|
||
|
|
||
|
// Editbox container
|
||
|
var panelColorBox = panel.find('.panel-colorbox');
|
||
|
|
||
|
// Update panel context color on click
|
||
|
panelColorBox.on('click', '> span', function(e) {
|
||
|
var dataColor = $(this).data('panel-color');
|
||
|
var altColors = 'panel-primary panel-info panel-success panel-warning panel-danger panel-alert panel-system panel-dark panel-default panel-white';
|
||
|
panel.removeClass(altColors).addClass(dataColor).data('panel-color', dataColor);
|
||
|
methods.updateSettings(options);
|
||
|
});
|
||
|
|
||
|
// Toggle given elements visability and ".panel-editbox" class
|
||
|
// Update settings if closing box
|
||
|
panelColorBox.slideToggle('fast', function() {
|
||
|
panel.toggleClass('panel-colorbox-open');
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
// Collapse definition
|
||
|
var panelCollapse = function() {
|
||
|
|
||
|
// Toggle class
|
||
|
panel.toggleClass('panel-collapsed');
|
||
|
|
||
|
// Toggle given elements visability
|
||
|
panel.children('.panel-body, .panel-menu, .panel-footer').slideToggle('fast', function() {
|
||
|
methods.updateSettings(options);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// Fullscreen definition
|
||
|
var panelFullscreen = function() {
|
||
|
// If fullscreen - remove class and enable panel sorting
|
||
|
if ($('body.panel-fullscreen-active').length) {
|
||
|
$('body').removeClass('panel-fullscreen-active');
|
||
|
panel.removeClass('panel-fullscreen');
|
||
|
if (dragSetting === true) {
|
||
|
plugin.sortable("enable");
|
||
|
}
|
||
|
}
|
||
|
// if not active - fullscreen classes, disable panel sorting
|
||
|
else {
|
||
|
$('body').addClass('panel-fullscreen-active');
|
||
|
panel.addClass('panel-fullscreen');
|
||
|
if (dragSetting === true) {
|
||
|
plugin.sortable("disable");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Hide open mobile menus or popovers
|
||
|
$('.panel-controls').removeClass('panel-controls-open');
|
||
|
$('.popover').popover('hide');
|
||
|
|
||
|
// Trigger global window resize to resize plugins that could be
|
||
|
// in fullscreen conent
|
||
|
setTimeout(function() {
|
||
|
$(window).trigger('resize');
|
||
|
}, 100);
|
||
|
};
|
||
|
|
||
|
// Remove definition
|
||
|
var panelRemove = function() {
|
||
|
|
||
|
// Bootbox plugin is a core part
|
||
|
if (bootbox.confirm) {
|
||
|
bootbox.confirm("Are You Sure?!", function(e) {
|
||
|
if (e) {
|
||
|
setTimeout(function() {
|
||
|
panel.addClass('panel-removed').hide();
|
||
|
methods.updateSettings(options);
|
||
|
}, 200);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
} else {
|
||
|
panel.addClass('panel-removed').hide();
|
||
|
methods.updateSettings(options);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Remove definition
|
||
|
var panelCallback = function() {
|
||
|
if (typeof options.onPanel == 'function') {
|
||
|
options.onPanel();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Response
|
||
|
if ($(this).hasClass('panel-control-collapse')) {
|
||
|
panelCollapse();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-title')) {
|
||
|
panelEditTitle();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-color')) {
|
||
|
panelColor();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-fullscreen')) {
|
||
|
panelFullscreen();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-remove')) {
|
||
|
panelRemove();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-callback')) {
|
||
|
panelCallback();
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-dockable')) {
|
||
|
return
|
||
|
}
|
||
|
if ($(this).hasClass('panel-control-loader')) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Toggle Loader indicator to action response
|
||
|
methods.toggleLoader.call(this);
|
||
|
|
||
|
},
|
||
|
toggleLoader: function(options) {
|
||
|
var This = $(this);
|
||
|
var panel = This.parents('.panel');
|
||
|
|
||
|
// Add loader to panel
|
||
|
panel.addClass('panel-loader-active');
|
||
|
|
||
|
// Remove loader after time
|
||
|
setTimeout(function() {
|
||
|
panel.removeClass('panel-loader-active');
|
||
|
}, 650);
|
||
|
|
||
|
},
|
||
|
modifySettings: function(options) {
|
||
|
|
||
|
// Settings obj
|
||
|
var settingsArr = [];
|
||
|
|
||
|
// Settings for each panel
|
||
|
panels.each(function(i, e) {
|
||
|
|
||
|
var This = $(e);
|
||
|
var panelObj = {};
|
||
|
|
||
|
// Settings vars
|
||
|
var panelID = This.attr('id');
|
||
|
var panelTitle = This.children('.panel-heading').find('.panel-title').text();
|
||
|
var panelCollapsed = (This.hasClass('panel-collapsed') ? 1 : 0);
|
||
|
var panelHidden = (This.is(':hidden') ? 1 : 0);
|
||
|
var panelColor = This.data('panel-color');
|
||
|
|
||
|
panelObj['id'] = This.attr('id');
|
||
|
panelObj['title'] = This.children('.panel-heading').find('.panel-title').text();
|
||
|
panelObj['collapsed'] = (This.hasClass('panel-collapsed') ? 1 : 0);
|
||
|
panelObj['hidden'] = (This.is(':hidden') ? 1 : 0);
|
||
|
panelObj['color'] = (panelColor ? panelColor : null);
|
||
|
|
||
|
settingsArr.push({
|
||
|
'panel': panelObj
|
||
|
});
|
||
|
});
|
||
|
|
||
|
var checkedSettings = JSON.stringify(settingsArr);
|
||
|
|
||
|
// panel positions array
|
||
|
return checkedSettings;
|
||
|
},
|
||
|
findPositions: function(options) {
|
||
|
|
||
|
var grids = plugin.find(pluginGrid);
|
||
|
var gridsArr = [];
|
||
|
|
||
|
// Find present panels
|
||
|
grids.each(function(index, ele) {
|
||
|
|
||
|
var panels = $(ele).find('.panel');
|
||
|
var panelArr = [];
|
||
|
|
||
|
$(ele).attr('id', 'grid-' + index);
|
||
|
|
||
|
panels.each(function(i, e) {
|
||
|
var panelID = $(e).attr('id');
|
||
|
panelArr.push(panelID);
|
||
|
});
|
||
|
|
||
|
gridsArr[index] = panelArr;
|
||
|
});
|
||
|
|
||
|
var checkedPosition = JSON.stringify(gridsArr);
|
||
|
|
||
|
// Panel positions array
|
||
|
return checkedPosition;
|
||
|
|
||
|
},
|
||
|
setPositions: function(options) {
|
||
|
|
||
|
// Vars
|
||
|
var obj = this;
|
||
|
var localPositions = localStorage.getItem(positionsKey);
|
||
|
var parsePosition = JSON.parse(localPositions);
|
||
|
|
||
|
// Get gata and set panel's position
|
||
|
$(pluginGrid).each(function(i, e) {
|
||
|
var rowID = $(e)
|
||
|
$.each(parsePosition[i], function(i, ele) {
|
||
|
$('#' + ele).appendTo(rowID);
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
updatePositions: function(options) {
|
||
|
localStorage.setItem(positionsKey, methods.findPositions());
|
||
|
|
||
|
if (typeof options.onSave == 'function') {
|
||
|
options.onSave();
|
||
|
}
|
||
|
},
|
||
|
updateSettings: function(options) {
|
||
|
localStorage.setItem(settingsKey, methods.modifySettings());
|
||
|
|
||
|
if (typeof options.onSave == 'function') {
|
||
|
options.onSave();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return this.each(function() {
|
||
|
methods.init.call(plugin, options);
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
})(jQuery, window, document);
|
||
|
|
||
|
|
||
|
(function (root, factory) {
|
||
|
|
||
|
"use strict";
|
||
|
if (typeof define === "function" && define.amd) {
|
||
|
define(["jquery"], factory);
|
||
|
} else if (typeof exports === "object") {
|
||
|
module.exports = factory(require("jquery"));
|
||
|
} else {
|
||
|
root.bootbox = factory(root.jQuery);
|
||
|
}
|
||
|
|
||
|
}(this, function init($, undefined) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
// the base DOM structure for adding modal
|
||
|
var templates = {
|
||
|
dialog:
|
||
|
"<div class='bootbox modal' tabindex='-1' role='dialog'>" +
|
||
|
"<div class='modal-dialog'>" +
|
||
|
"<div class='modal-content'>" +
|
||
|
"<div class='modal-body'><div class='bootbox-body'></div></div>" +
|
||
|
"</div>" +
|
||
|
"</div>" +
|
||
|
"</div>",
|
||
|
header:
|
||
|
"<div class='modal-header'>" +
|
||
|
"<h4 class='modal-title'></h4>" +
|
||
|
"</div>",
|
||
|
footer:
|
||
|
"<div class='modal-footer'></div>",
|
||
|
closeButton:
|
||
|
"<button type='button' class='bootbox-close-button close' data-dismiss='modal' aria-hidden='true'>×</button>",
|
||
|
form:
|
||
|
"<form class='bootbox-form'></form>",
|
||
|
inputs: {
|
||
|
text:
|
||
|
"<input class='bootbox-input bootbox-input-text form-control' autocomplete=off type=text />",
|
||
|
textarea:
|
||
|
"<textarea class='bootbox-input bootbox-input-textarea form-control'></textarea>",
|
||
|
email:
|
||
|
"<input class='bootbox-input bootbox-input-email form-control' autocomplete='off' type='email' />",
|
||
|
select:
|
||
|
"<select class='bootbox-input bootbox-input-select form-control'></select>",
|
||
|
checkbox:
|
||
|
"<div class='checkbox'><label><input class='bootbox-input bootbox-input-checkbox' type='checkbox' /></label></div>",
|
||
|
date:
|
||
|
"<input class='bootbox-input bootbox-input-date form-control' autocomplete=off type='date' />",
|
||
|
time:
|
||
|
"<input class='bootbox-input bootbox-input-time form-control' autocomplete=off type='time' />",
|
||
|
number:
|
||
|
"<input class='bootbox-input bootbox-input-number form-control' autocomplete=off type='number' />",
|
||
|
password:
|
||
|
"<input class='bootbox-input bootbox-input-password form-control' autocomplete='off' type='password' />"
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Setting Modal
|
||
|
var defaults = {
|
||
|
locale: "en",
|
||
|
backdrop: true,
|
||
|
animate: true,
|
||
|
// additional class for top level dialog
|
||
|
className: null,
|
||
|
keyboard: false,
|
||
|
closeButton: true,
|
||
|
// show dialog immediately by default
|
||
|
show: true,
|
||
|
// dialog container
|
||
|
container: "body"
|
||
|
};
|
||
|
|
||
|
// our public object
|
||
|
var exports = {};
|
||
|
|
||
|
/* @private */
|
||
|
function _t(key) {
|
||
|
var locale = locales[defaults.locale];
|
||
|
return locale ? locale[key] : locales.en[key];
|
||
|
}
|
||
|
|
||
|
function processCallback(e, dialog, callback) {
|
||
|
e.stopPropagation();
|
||
|
e.preventDefault();
|
||
|
|
||
|
var preserveDialog = $.isFunction(callback) && callback(e) === false;
|
||
|
|
||
|
if (!preserveDialog) {
|
||
|
dialog.modal("hide");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getKeyLength(obj) {
|
||
|
var k, t = 0;
|
||
|
for (k in obj) {
|
||
|
t ++;
|
||
|
}
|
||
|
return t;
|
||
|
}
|
||
|
|
||
|
function each(collection, iterator) {
|
||
|
var index = 0;
|
||
|
$.each(collection, function(key, value) {
|
||
|
iterator(key, value, index++);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function sanitize(options) {
|
||
|
var buttons;
|
||
|
var total;
|
||
|
|
||
|
if (typeof options !== "object") {
|
||
|
throw new Error("Please supply an object of options");
|
||
|
}
|
||
|
|
||
|
if (!options.message) {
|
||
|
throw new Error("Please specify a message");
|
||
|
}
|
||
|
|
||
|
// ensure that supplied options take precedence over defaults
|
||
|
options = $.extend({}, defaults, options);
|
||
|
|
||
|
if (!options.buttons) {
|
||
|
options.buttons = {};
|
||
|
}
|
||
|
|
||
|
// Bootstrap's "static" and false backdrop args are supported only
|
||
|
options.backdrop = options.backdrop ? "static" : false;
|
||
|
|
||
|
buttons = options.buttons;
|
||
|
|
||
|
total = getKeyLength(buttons);
|
||
|
|
||
|
each(buttons, function(key, button, index) {
|
||
|
|
||
|
if ($.isFunction(button)) {
|
||
|
button = buttons[key] = {
|
||
|
callback: button
|
||
|
};
|
||
|
}
|
||
|
|
||
|
// Check if the btn has correct type
|
||
|
if ($.type(button) !== "object") {
|
||
|
throw new Error("button with key " + key + " must be an object");
|
||
|
}
|
||
|
|
||
|
if (!button.label) {
|
||
|
button.label = key;
|
||
|
}
|
||
|
|
||
|
if (!button.className) {
|
||
|
if (total <= 2 && index === total-1) {
|
||
|
// Important: add primary to the main option in a 2 btn dialog
|
||
|
button.className = "btn-primary";
|
||
|
} else {
|
||
|
button.className = "btn-default";
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return options;
|
||
|
}
|
||
|
|
||
|
function mapArguments(args, properties) {
|
||
|
var argn = args.length;
|
||
|
var options = {};
|
||
|
|
||
|
if (argn < 1 || argn > 2) {
|
||
|
throw new Error("Invalid argument length");
|
||
|
}
|
||
|
|
||
|
if (argn === 2 || typeof args[0] === "string") {
|
||
|
options[properties[0]] = args[0];
|
||
|
options[properties[1]] = args[1];
|
||
|
} else {
|
||
|
options = args[0];
|
||
|
}
|
||
|
|
||
|
return options;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* merge default dialog options with user supplied arguments
|
||
|
*/
|
||
|
function mergeArguments(defaults, args, properties) {
|
||
|
return $.extend(
|
||
|
// deep merge
|
||
|
true,
|
||
|
// make sure that the target is an empty, unreferenced object
|
||
|
{},
|
||
|
// base options object for this type of dialog (usaully - buttons)
|
||
|
defaults,
|
||
|
// args could be an object or array;
|
||
|
// if it's array properties - map it to a proper options object
|
||
|
mapArguments(
|
||
|
args,
|
||
|
properties
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Take inputs range and return valid options suitable for passing to bootbox.dialog
|
||
|
*/
|
||
|
function mergeDialogOptions(className, labels, properties, args) {
|
||
|
// Create base set of dialog properties
|
||
|
var baseOptions = {
|
||
|
className: "bootbox-" + className,
|
||
|
buttons: createLabels.apply(null, labels)
|
||
|
};
|
||
|
|
||
|
// Check generated buttons
|
||
|
return validateButtons(
|
||
|
// merge generated base properties with user supplied arguments
|
||
|
mergeArguments(
|
||
|
baseOptions,
|
||
|
args,
|
||
|
properties
|
||
|
),
|
||
|
labels
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a suitable object of button labels
|
||
|
*/
|
||
|
function createLabels() {
|
||
|
var buttons = {};
|
||
|
|
||
|
for (var i = 0, j = arguments.length; i < j; i++) {
|
||
|
var argument = arguments[i];
|
||
|
var key = argument.toLowerCase();
|
||
|
var value = argument.toUpperCase();
|
||
|
|
||
|
buttons[key] = {
|
||
|
label: _t(value)
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return buttons;
|
||
|
}
|
||
|
|
||
|
function validateButtons(options, buttons) {
|
||
|
var allowedButtons = {};
|
||
|
each(buttons, function(key, value) {
|
||
|
allowedButtons[value] = true;
|
||
|
});
|
||
|
|
||
|
each(options.buttons, function(key) {
|
||
|
if (allowedButtons[key] === undefined) {
|
||
|
throw new Error("button key " + key + " is not allowed (options are " + buttons.join("\n") + ")");
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return options;
|
||
|
}
|
||
|
|
||
|
exports.defineLocale = function (name, values) {
|
||
|
if (values) {
|
||
|
locales[name] = {
|
||
|
OK: values.OK,
|
||
|
CANCEL: values.CANCEL,
|
||
|
CONFIRM: values.CONFIRM
|
||
|
};
|
||
|
return locales[name];
|
||
|
} else {
|
||
|
delete locales[name];
|
||
|
return null;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
exports.alert = function() {
|
||
|
var options;
|
||
|
|
||
|
options = mergeDialogOptions("alert", ["ok"], ["message", "callback"], arguments);
|
||
|
|
||
|
if (options.callback && !$.isFunction(options.callback)) {
|
||
|
throw new Error("alert requires callback property to be a function when provided");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Some overrides
|
||
|
*/
|
||
|
options.buttons.ok.callback = options.onEscape = function() {
|
||
|
if ($.isFunction(options.callback)) {
|
||
|
return options.callback();
|
||
|
}
|
||
|
return true;
|
||
|
};
|
||
|
|
||
|
return exports.dialog(options);
|
||
|
};
|
||
|
|
||
|
exports.confirm = function() {
|
||
|
var options;
|
||
|
|
||
|
options = mergeDialogOptions("confirm", ["cancel", "confirm"], ["message", "callback"], arguments);
|
||
|
|
||
|
/**
|
||
|
* More overrides; undo all that user tried to set he shouldn't have
|
||
|
*/
|
||
|
options.buttons.cancel.callback = options.onEscape = function() {
|
||
|
return options.callback(false);
|
||
|
};
|
||
|
|
||
|
options.buttons.confirm.callback = function() {
|
||
|
return options.callback(true);
|
||
|
};
|
||
|
|
||
|
// Specific validation confirmation
|
||
|
if (!$.isFunction(options.callback)) {
|
||
|
throw new Error("confirm requires a callback");
|
||
|
}
|
||
|
|
||
|
return exports.dialog(options);
|
||
|
};
|
||
|
|
||
|
exports.prompt = function() {
|
||
|
var options;
|
||
|
var defaults;
|
||
|
var dialog;
|
||
|
var form;
|
||
|
var input;
|
||
|
var shouldShow;
|
||
|
var inputOptions;
|
||
|
|
||
|
// First of all = we have to create form
|
||
|
form = $(templates.form);
|
||
|
|
||
|
defaults = {
|
||
|
className: "bootbox-prompt",
|
||
|
buttons: createLabels("cancel", "confirm"),
|
||
|
value: "",
|
||
|
inputType: "text"
|
||
|
};
|
||
|
|
||
|
options = validateButtons(
|
||
|
mergeArguments(defaults, arguments, ["title", "callback"]),
|
||
|
["cancel", "confirm"]
|
||
|
);
|
||
|
|
||
|
shouldShow = (options.show === undefined) ? true : options.show;
|
||
|
|
||
|
/**
|
||
|
* Undo all that user tried to set he shouldn't have
|
||
|
*/
|
||
|
options.message = form;
|
||
|
|
||
|
options.buttons.cancel.callback = options.onEscape = function() {
|
||
|
return options.callback(null);
|
||
|
};
|
||
|
|
||
|
options.buttons.confirm.callback = function() {
|
||
|
var value;
|
||
|
|
||
|
switch (options.inputType) {
|
||
|
case "text":
|
||
|
case "textarea":
|
||
|
case "email":
|
||
|
case "select":
|
||
|
case "date":
|
||
|
case "time":
|
||
|
case "number":
|
||
|
case "password":
|
||
|
value = input.val();
|
||
|
break;
|
||
|
|
||
|
case "checkbox":
|
||
|
var checkedItems = input.find("input:checked");
|
||
|
|
||
|
value = [];
|
||
|
|
||
|
each(checkedItems, function(_, item) {
|
||
|
value.push($(item).val());
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return options.callback(value);
|
||
|
};
|
||
|
|
||
|
options.show = false;
|
||
|
|
||
|
// Prompt for specific validation
|
||
|
if (!options.title) {
|
||
|
throw new Error("prompt requires a title");
|
||
|
}
|
||
|
|
||
|
if (!$.isFunction(options.callback)) {
|
||
|
throw new Error("prompt requires a callback");
|
||
|
}
|
||
|
|
||
|
if (!templates.inputs[options.inputType]) {
|
||
|
throw new Error("invalid prompt type");
|
||
|
}
|
||
|
|
||
|
// Add input based on the supplied type
|
||
|
input = $(templates.inputs[options.inputType]);
|
||
|
|
||
|
switch (options.inputType) {
|
||
|
case "text":
|
||
|
case "textarea":
|
||
|
case "email":
|
||
|
case "date":
|
||
|
case "time":
|
||
|
case "number":
|
||
|
case "password":
|
||
|
input.val(options.value);
|
||
|
break;
|
||
|
|
||
|
case "select":
|
||
|
var groups = {};
|
||
|
inputOptions = options.inputOptions || [];
|
||
|
|
||
|
if (!inputOptions.length) {
|
||
|
throw new Error("prompt with select requires options");
|
||
|
}
|
||
|
|
||
|
each(inputOptions, function(_, option) {
|
||
|
|
||
|
// assume the element to attach to is the input
|
||
|
var elem = input;
|
||
|
|
||
|
if (option.value === undefined || option.text === undefined) {
|
||
|
throw new Error("given options in wrong format");
|
||
|
}
|
||
|
|
||
|
// but override that element if this option sits in a group
|
||
|
|
||
|
if (option.group) {
|
||
|
// initialise the group if necessary
|
||
|
if (!groups[option.group]) {
|
||
|
groups[option.group] = $("<optgroup/>").attr("label", option.group);
|
||
|
}
|
||
|
|
||
|
elem = groups[option.group];
|
||
|
}
|
||
|
|
||
|
elem.append("<option value='" + option.value + "'>" + option.text + "</option>");
|
||
|
});
|
||
|
|
||
|
each(groups, function(_, group) {
|
||
|
input.append(group);
|
||
|
});
|
||
|
|
||
|
// safe to set a select value as per a normal input
|
||
|
input.val(options.value);
|
||
|
break;
|
||
|
|
||
|
case "checkbox":
|
||
|
var values = $.isArray(options.value) ? options.value : [options.value];
|
||
|
inputOptions = options.inputOptions || [];
|
||
|
|
||
|
if (!inputOptions.length) {
|
||
|
throw new Error("prompt with checkbox requires options");
|
||
|
}
|
||
|
|
||
|
if (!inputOptions[0].value || !inputOptions[0].text) {
|
||
|
throw new Error("given options in wrong format");
|
||
|
}
|
||
|
|
||
|
// Checkboxes should be nested within a containing element
|
||
|
input = $("<div/>");
|
||
|
|
||
|
each(inputOptions, function(_, option) {
|
||
|
var checkbox = $(templates.inputs[options.inputType]);
|
||
|
|
||
|
checkbox.find("input").attr("value", option.value);
|
||
|
checkbox.find("label").append(option.text);
|
||
|
|
||
|
// Check array values for later iteration if needed
|
||
|
each(values, function(_, value) {
|
||
|
if (value === option.value) {
|
||
|
checkbox.find("input").prop("checked", true);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
input.append(checkbox);
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (options.placeholder) {
|
||
|
input.attr("placeholder", options.placeholder);
|
||
|
}
|
||
|
|
||
|
if(options.pattern){
|
||
|
input.attr("pattern", options.pattern);
|
||
|
}
|
||
|
|
||
|
// now place it in the form
|
||
|
form.append(input);
|
||
|
|
||
|
form.on("submit", function(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
dialog.find(".btn-primary").click();
|
||
|
});
|
||
|
|
||
|
dialog = exports.dialog(options);
|
||
|
|
||
|
// clear existing handler focusing the submit button
|
||
|
dialog.off("shown.bs.modal");
|
||
|
|
||
|
// and replace it with the one focusing our input, if possible
|
||
|
dialog.on("shown.bs.modal", function() {
|
||
|
input.focus();
|
||
|
});
|
||
|
|
||
|
if (shouldShow === true) {
|
||
|
dialog.modal("show");
|
||
|
}
|
||
|
|
||
|
return dialog;
|
||
|
};
|
||
|
|
||
|
exports.dialog = function(options) {
|
||
|
options = sanitize(options);
|
||
|
|
||
|
var dialog = $(templates.dialog);
|
||
|
var innerDialog = dialog.find(".modal-dialog");
|
||
|
var body = dialog.find(".modal-body");
|
||
|
var buttons = options.buttons;
|
||
|
var buttonStr = "";
|
||
|
var callbacks = {
|
||
|
onEscape: options.onEscape
|
||
|
};
|
||
|
|
||
|
if ($.fn.modal === undefined) {
|
||
|
throw new Error(
|
||
|
"$.fn.modal is not defined; please ensure you have included " +
|
||
|
"Bootstrap JS.(http://getbootstrap.com/javascript/)"
|
||
|
);
|
||
|
}
|
||
|
|
||
|
each(buttons, function(key, button) {
|
||
|
|
||
|
buttonStr += "<button data-bb-handler='" + key + "' type='button' class='btn " + button.className + "'>" + button.label + "</button>";
|
||
|
callbacks[key] = button.callback;
|
||
|
});
|
||
|
|
||
|
body.find(".bootbox-body").html(options.message);
|
||
|
|
||
|
if (options.animate === true) {
|
||
|
dialog.addClass("fade");
|
||
|
}
|
||
|
|
||
|
if (options.className) {
|
||
|
dialog.addClass(options.className);
|
||
|
}
|
||
|
|
||
|
if (options.size === "large") {
|
||
|
innerDialog.addClass("modal-lg");
|
||
|
}
|
||
|
|
||
|
if (options.size === "small") {
|
||
|
innerDialog.addClass("modal-sm");
|
||
|
}
|
||
|
|
||
|
if (options.title) {
|
||
|
body.before(templates.header);
|
||
|
}
|
||
|
|
||
|
if (options.closeButton) {
|
||
|
var closeButton = $(templates.closeButton);
|
||
|
|
||
|
if (options.title) {
|
||
|
dialog.find(".modal-header").prepend(closeButton);
|
||
|
} else {
|
||
|
closeButton.css("margin-top", "-10px").prependTo(body);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (options.title) {
|
||
|
dialog.find(".modal-title").html(options.title);
|
||
|
}
|
||
|
|
||
|
if (buttonStr.length) {
|
||
|
body.after(templates.footer);
|
||
|
dialog.find(".modal-footer").html(buttonStr);
|
||
|
}
|
||
|
|
||
|
|
||
|
dialog.on("hidden.bs.modal", function(e) {
|
||
|
// Check if we do not accidentally intercept hidden events triggered
|
||
|
// by children of the current dialog.
|
||
|
if (e.target === this) {
|
||
|
dialog.remove();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
dialog.on("shown.bs.modal", function() {
|
||
|
dialog.find(".btn-primary:first").focus();
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Bootbox event listeners
|
||
|
*/
|
||
|
|
||
|
dialog.on("escape.close.bb", function(e) {
|
||
|
if (callbacks.onEscape) {
|
||
|
processCallback(e, dialog, callbacks.onEscape);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Standard jQuery event listeners
|
||
|
*/
|
||
|
|
||
|
dialog.on("click", ".modal-footer button", function(e) {
|
||
|
var callbackKey = $(this).data("bb-handler");
|
||
|
|
||
|
processCallback(e, dialog, callbacks[callbackKey]);
|
||
|
|
||
|
});
|
||
|
|
||
|
dialog.on("click", ".bootbox-close-button", function(e) {
|
||
|
processCallback(e, dialog, callbacks.onEscape);
|
||
|
});
|
||
|
|
||
|
dialog.on("keyup", function(e) {
|
||
|
if (e.which === 27) {
|
||
|
dialog.trigger("escape.close.bb");
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// Add dialog to the DOM
|
||
|
|
||
|
$(options.container).append(dialog);
|
||
|
|
||
|
dialog.modal({
|
||
|
backdrop: options.backdrop,
|
||
|
keyboard: options.keyboard || false,
|
||
|
show: false
|
||
|
});
|
||
|
|
||
|
if (options.show) {
|
||
|
dialog.modal("show");
|
||
|
}
|
||
|
|
||
|
return dialog;
|
||
|
|
||
|
};
|
||
|
|
||
|
exports.setDefaults = function() {
|
||
|
var values = {};
|
||
|
|
||
|
if (arguments.length === 2) {
|
||
|
// allow passing of single key / value
|
||
|
values[arguments[0]] = arguments[1];
|
||
|
} else {
|
||
|
// and as an object too
|
||
|
values = arguments[0];
|
||
|
}
|
||
|
|
||
|
$.extend(defaults, values);
|
||
|
};
|
||
|
|
||
|
exports.hideAll = function() {
|
||
|
$(".bootbox").modal("hide");
|
||
|
|
||
|
return exports;
|
||
|
};
|
||
|
|
||
|
|
||
|
// Standard locales
|
||
|
var locales = {
|
||
|
br : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Cancelar",
|
||
|
CONFIRM : "Sim"
|
||
|
},
|
||
|
cs : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Zrušit",
|
||
|
CONFIRM : "Potvrdit"
|
||
|
},
|
||
|
da : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Annuller",
|
||
|
CONFIRM : "Accepter"
|
||
|
},
|
||
|
de : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Abbrechen",
|
||
|
CONFIRM : "Akzeptieren"
|
||
|
},
|
||
|
el : {
|
||
|
OK : "Εντάξει",
|
||
|
CANCEL : "Ακύρωση",
|
||
|
CONFIRM : "Επιβεβαίωση"
|
||
|
},
|
||
|
en : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Cancel",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
es : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Cancelar",
|
||
|
CONFIRM : "Aceptar"
|
||
|
},
|
||
|
et : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Katkesta",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
fi : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Peruuta",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
fr : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Annuler",
|
||
|
CONFIRM : "D'accord"
|
||
|
},
|
||
|
he : {
|
||
|
OK : "אישור",
|
||
|
CANCEL : "ביטול",
|
||
|
CONFIRM : "אישור"
|
||
|
},
|
||
|
hu : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Mégsem",
|
||
|
CONFIRM : "Megerősít"
|
||
|
},
|
||
|
hr : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Odustani",
|
||
|
CONFIRM : "Potvrdi"
|
||
|
},
|
||
|
id : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Batal",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
it : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Annulla",
|
||
|
CONFIRM : "Conferma"
|
||
|
},
|
||
|
ja : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "キャンセル",
|
||
|
CONFIRM : "確認"
|
||
|
},
|
||
|
lt : {
|
||
|
OK : "Gerai",
|
||
|
CANCEL : "Atšaukti",
|
||
|
CONFIRM : "Patvirtinti"
|
||
|
},
|
||
|
lv : {
|
||
|
OK : "Labi",
|
||
|
CANCEL : "Atcelt",
|
||
|
CONFIRM : "Apstiprināt"
|
||
|
},
|
||
|
nl : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Annuleren",
|
||
|
CONFIRM : "Accepteren"
|
||
|
},
|
||
|
no : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Avbryt",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
pl : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Anuluj",
|
||
|
CONFIRM : "Potwierdź"
|
||
|
},
|
||
|
pt : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Cancelar",
|
||
|
CONFIRM : "Confirmar"
|
||
|
},
|
||
|
ru : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Отмена",
|
||
|
CONFIRM : "Применить"
|
||
|
},
|
||
|
sv : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "Avbryt",
|
||
|
CONFIRM : "OK"
|
||
|
},
|
||
|
tr : {
|
||
|
OK : "Tamam",
|
||
|
CANCEL : "İptal",
|
||
|
CONFIRM : "Onayla"
|
||
|
},
|
||
|
zh_CN : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "取消",
|
||
|
CONFIRM : "确认"
|
||
|
},
|
||
|
zh_TW : {
|
||
|
OK : "OK",
|
||
|
CANCEL : "取消",
|
||
|
CONFIRM : "確認"
|
||
|
}
|
||
|
};
|
||
|
|
||
|
exports.init = function(_$) {
|
||
|
return init(_$ || $);
|
||
|
};
|
||
|
|
||
|
return exports;
|
||
|
}));
|
||
|
|
||
|
|
||
|
|
||
|
;
|
||
|
(function($) {
|
||
|
|
||
|
function defined(a) {
|
||
|
return typeof a !== 'undefined';
|
||
|
}
|
||
|
|
||
|
function extend(child, parent, prototype) {
|
||
|
var F = function() {};
|
||
|
F.prototype = parent.prototype;
|
||
|
child.prototype = new F();
|
||
|
child.prototype.constructor = child;
|
||
|
parent.prototype.constructor = parent;
|
||
|
child._super = parent.prototype;
|
||
|
if (prototype) {
|
||
|
$.extend(child.prototype, prototype);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var SUBST = [
|
||
|
['', ''], // specification
|
||
|
['exit', 'cancel'], // Mozilla FF & old webkits expect cancelFullScreen instead of exitFullscreen
|
||
|
['screen', 'Screen'] // Mozilla FF expects FullScreen instead of Fullscreen
|
||
|
];
|
||
|
|
||
|
var VENDOR_PREFIXES = ['', 'o', 'ms', 'moz', 'webkit', 'webkitCurrent'];
|
||
|
|
||
|
function native(obj, name) {
|
||
|
var prefixed;
|
||
|
|
||
|
if (typeof obj === 'string') {
|
||
|
name = obj;
|
||
|
obj = document;
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < SUBST.length; ++i) {
|
||
|
name = name.replace(SUBST[i][0], SUBST[i][1]);
|
||
|
for (var j = 0; j < VENDOR_PREFIXES.length; ++j) {
|
||
|
prefixed = VENDOR_PREFIXES[j];
|
||
|
prefixed += j === 0 ? name : name.charAt(0).toUpperCase() + name.substr(1);
|
||
|
if (defined(obj[prefixed])) {
|
||
|
return obj[prefixed];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return void 0;
|
||
|
}
|
||
|
var ua = navigator.userAgent;
|
||
|
var fsEnabled = native('fullscreenEnabled');
|
||
|
var IS_ANDROID_CHROME = ua.indexOf('Android') !== -1 && ua.indexOf('Chrome') !== -1;
|
||
|
var IS_NATIVELY_SUPPORTED =
|
||
|
!IS_ANDROID_CHROME &&
|
||
|
defined(native('fullscreenElement')) &&
|
||
|
(!defined(fsEnabled) || fsEnabled === true);
|
||
|
|
||
|
var version = $.fn.jquery.split('.');
|
||
|
var JQ_LT_17 = (parseInt(version[0]) < 2 && parseInt(version[1]) < 7);
|
||
|
|
||
|
var FullScreenAbstract = function() {
|
||
|
this.__options = null;
|
||
|
this._fullScreenElement = null;
|
||
|
this.__savedStyles = {};
|
||
|
};
|
||
|
|
||
|
FullScreenAbstract.prototype = {
|
||
|
_DEFAULT_OPTIONS: {
|
||
|
styles: {
|
||
|
'boxSizing': 'border-box',
|
||
|
'MozBoxSizing': 'border-box',
|
||
|
'WebkitBoxSizing': 'border-box'
|
||
|
},
|
||
|
toggleClass: null
|
||
|
},
|
||
|
__documentOverflow: 'visible',
|
||
|
__htmlOverflow: 'visible',
|
||
|
_preventDocumentScroll: function() {
|
||
|
// Disable ability
|
||
|
this.__documentOverflow = $('body')[0].style.overflow;
|
||
|
this.__htmlOverflow = $('html')[0].style.overflow;
|
||
|
|
||
|
},
|
||
|
_allowDocumentScroll: function() {
|
||
|
$('body')[0].style.overflow = this.__documentOverflow;
|
||
|
$('html')[0].style.overflow = this.__htmlOverflow;
|
||
|
},
|
||
|
_fullScreenChange: function() {
|
||
|
if (!this.__options)
|
||
|
return; // We process fullscreenchange events caused by this plugin
|
||
|
if (!this.isFullScreen()) {
|
||
|
this._allowDocumentScroll();
|
||
|
this._revertStyles();
|
||
|
this._triggerEvents();
|
||
|
this._fullScreenElement = null;
|
||
|
} else {
|
||
|
this._preventDocumentScroll();
|
||
|
this._triggerEvents();
|
||
|
}
|
||
|
},
|
||
|
_fullScreenError: function(e) {
|
||
|
if (!this.__options)
|
||
|
return; // We process fullscreenchange events caused by this plugin
|
||
|
this._revertStyles();
|
||
|
this._fullScreenElement = null;
|
||
|
if (e) {
|
||
|
$(document).trigger('fscreenerror', [e]);
|
||
|
}
|
||
|
},
|
||
|
_triggerEvents: function() {
|
||
|
$(this._fullScreenElement).trigger(this.isFullScreen() ? 'fscreenopen' : 'fscreenclose');
|
||
|
$(document).trigger('fscreenchange', [this.isFullScreen(), this._fullScreenElement]);
|
||
|
},
|
||
|
_saveAndApplyStyles: function() {
|
||
|
var $elem = $(this._fullScreenElement);
|
||
|
this.__savedStyles = {};
|
||
|
for (var property in this.__options.styles) {
|
||
|
// THIS save
|
||
|
this.__savedStyles[property] = this._fullScreenElement.style[property];
|
||
|
// THIS apply
|
||
|
this._fullScreenElement.style[property] = this.__options.styles[property];
|
||
|
}
|
||
|
if (this.__options.toggleClass) {
|
||
|
$elem.addClass(this.__options.toggleClass);
|
||
|
}
|
||
|
},
|
||
|
_revertStyles: function() {
|
||
|
var $elem = $(this._fullScreenElement);
|
||
|
for (var property in this.__options.styles) {
|
||
|
this._fullScreenElement.style[property] = this.__savedStyles[property];
|
||
|
}
|
||
|
if (this.__options.toggleClass) {
|
||
|
$elem.removeClass(this.__options.toggleClass);
|
||
|
}
|
||
|
},
|
||
|
open: function(elem, options) {
|
||
|
// do nothing if request it's for already fullscreened element
|
||
|
if (elem === this._fullScreenElement) {
|
||
|
return;
|
||
|
}
|
||
|
// exit active fullscreen before opening another
|
||
|
if (this.isFullScreen()) {
|
||
|
this.exit();
|
||
|
}
|
||
|
// save fullscreened elem
|
||
|
this._fullScreenElement = elem;
|
||
|
// apply options if any
|
||
|
this.__options = $.extend(true, {}, this._DEFAULT_OPTIONS, options);
|
||
|
// save current element styles and apply new ones
|
||
|
this._saveAndApplyStyles();
|
||
|
},
|
||
|
exit: null,
|
||
|
isFullScreen: null,
|
||
|
isNativelySupported: function() {
|
||
|
return IS_NATIVELY_SUPPORTED;
|
||
|
}
|
||
|
};
|
||
|
var FullScreenNative = function() {
|
||
|
FullScreenNative._super.constructor.apply(this, arguments);
|
||
|
this.exit = $.proxy(native('exitFullscreen'), document);
|
||
|
this._DEFAULT_OPTIONS = $.extend(true, {}, this._DEFAULT_OPTIONS, {
|
||
|
'styles': {
|
||
|
'width': '100%',
|
||
|
'height': '100%'
|
||
|
}
|
||
|
});
|
||
|
$(document)
|
||
|
.bind(this._prefixedString('fullscreenchange') + ' MSFullscreenChange', $.proxy(this._fullScreenChange, this))
|
||
|
.bind(this._prefixedString('fullscreenerror') + ' MSFullscreenError', $.proxy(this._fullScreenError, this));
|
||
|
};
|
||
|
|
||
|
extend(FullScreenNative, FullScreenAbstract, {
|
||
|
VENDOR_PREFIXES: ['', 'o', 'moz', 'webkit'],
|
||
|
_prefixedString: function(str) {
|
||
|
return $.map(this.VENDOR_PREFIXES, function(s) {
|
||
|
return s + str;
|
||
|
}).join(' ');
|
||
|
},
|
||
|
open: function(elem, options) {
|
||
|
FullScreenNative._super.open.apply(this, arguments);
|
||
|
var requestFS = native(elem, 'requestFullscreen');
|
||
|
requestFS.call(elem);
|
||
|
},
|
||
|
exit: $.noop,
|
||
|
isFullScreen: function() {
|
||
|
return native('fullscreenElement') !== null;
|
||
|
},
|
||
|
element: function() {
|
||
|
return native('fullscreenElement');
|
||
|
}
|
||
|
});
|
||
|
var FullScreenFallback = function() {
|
||
|
FullScreenFallback._super.constructor.apply(this, arguments);
|
||
|
this._DEFAULT_OPTIONS = $.extend({}, this._DEFAULT_OPTIONS, {
|
||
|
'styles': {
|
||
|
'position': 'fixed',
|
||
|
'zIndex': '2147483647',
|
||
|
'left': 0,
|
||
|
'top': 0,
|
||
|
'bottom': 0,
|
||
|
'right': 0
|
||
|
}
|
||
|
});
|
||
|
this.__delegateKeydownHandler();
|
||
|
};
|
||
|
|
||
|
extend(FullScreenFallback, FullScreenAbstract, {
|
||
|
__isFullScreen: false,
|
||
|
__delegateKeydownHandler: function() {
|
||
|
var $doc = $(document);
|
||
|
$doc.delegate('*', 'keydown.fullscreen', $.proxy(this.__keydownHandler, this));
|
||
|
var data = JQ_LT_17 ? $doc.data('events') : $._data(document).events;
|
||
|
var events = data['keydown'];
|
||
|
if (!JQ_LT_17) {
|
||
|
events.splice(0, 0, events.splice(events.delegateCount - 1, 1)[0]);
|
||
|
} else {
|
||
|
data.live.unshift(data.live.pop());
|
||
|
}
|
||
|
},
|
||
|
__keydownHandler: function(e) {
|
||
|
if (this.isFullScreen() && e.which === 27) {
|
||
|
this.exit();
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
},
|
||
|
_revertStyles: function() {
|
||
|
FullScreenFallback._super._revertStyles.apply(this, arguments);
|
||
|
// force redraw
|
||
|
this._fullScreenElement.offsetHeight;
|
||
|
},
|
||
|
open: function(elem) {
|
||
|
FullScreenFallback._super.open.apply(this, arguments);
|
||
|
this.__isFullScreen = true;
|
||
|
this._fullScreenChange();
|
||
|
},
|
||
|
exit: function() {
|
||
|
this.__isFullScreen = false;
|
||
|
this._fullScreenChange();
|
||
|
},
|
||
|
isFullScreen: function() {
|
||
|
return this.__isFullScreen;
|
||
|
},
|
||
|
element: function() {
|
||
|
return this.__isFullScreen ? this._fullScreenElement : null;
|
||
|
}
|
||
|
});
|
||
|
$.fullscreen = IS_NATIVELY_SUPPORTED
|
||
|
? new FullScreenNative()
|
||
|
: new FullScreenFallback();
|
||
|
|
||
|
$.fn.fullscreen = function(options) {
|
||
|
var elem = this[0];
|
||
|
|
||
|
options = $.extend({
|
||
|
toggleClass: null,
|
||
|
overflow: 'hidden'
|
||
|
}, options);
|
||
|
options.styles = {
|
||
|
overflow: options.overflow
|
||
|
};
|
||
|
delete options.overflow;
|
||
|
|
||
|
if (elem) {
|
||
|
$.fullscreen.open(elem, options);
|
||
|
}
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
})(jQuery);
|
||
|
|
||
|
/*!
|
||
|
** hoverIntent v1.8.0 - Copyright 2014 Brian Cherne
|
||
|
** http://cherne.net/brian/resources/jquery.hoverIntent.html
|
||
|
** You are free to use hoverIntent as long as this header is left intact.
|
||
|
*/
|
||
|
|
||
|
(function($){$.fn.hoverIntent=function(handlerIn,handlerOut,selector){var cfg={interval:100,sensitivity:6,timeout:0};if(typeof handlerIn==="object"){cfg=$.extend(cfg,handlerIn)}else{if($.isFunction(handlerOut)){cfg=$.extend(cfg,{over:handlerIn,out:handlerOut,selector:selector})}else{cfg=$.extend(cfg,{over:handlerIn,out:handlerIn,selector:handlerOut})}}var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if(Math.sqrt((pX-cX)*(pX-cX)+(pY-cY)*(pY-cY))<cfg.sensitivity){$(ob).off("mousemove.hoverIntent",track);ob.hoverIntent_s=true;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=false;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=$.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type==="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).on("mousemove.hoverIntent",track);if(!ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).off("mousemove.hoverIntent",track);if(ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.on({"mouseenter.hoverIntent":handleHover,"mouseleave.hoverIntent":handleHover},cfg.selector)}})(jQuery);
|
||
|
|
||
|
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
|
||
|
** Licensed under the MIT License (LICENSE.txt).
|
||
|
** Version: 3.0.6
|
||
|
*/
|
||
|
|
||
|
!function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,void 0!==c.axis&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),void 0!==c.wheelDeltaY&&(h=c.wheelDeltaY/120),void 0!==c.wheelDeltaX&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})}(jQuery);
|
||
|
|
||
|
/*!
|
||
|
** jQuery Smooth Scroll - v1.5.4 - 2014-11-17
|
||
|
** https://github.com/kswedberg/jquery-smooth-scroll
|
||
|
** Copyright (c) 2014 Karl Swedberg
|
||
|
** Licensed MIT (https://github.com/kswedberg/jquery-smooth-scroll/blob/master/LICENSE-MIT)
|
||
|
*/
|
||
|
|
||
|
(function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){function e(t){return t.replace(/(:|\.|\/)/g,"\\$1")}var l="1.5.4",o={},n={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},s=function(e){var l=[],o=!1,n=e.dir&&"left"===e.dir?"scrollLeft":"scrollTop";return this.each(function(){if(this!==document&&this!==window){var e=t(this);e[n]()>0?l.push(this):(e[n](1),o=e[n]()>0,o&&l.push(this),e[n](0))}}),l.length||this.each(function(){"BODY"===this.nodeName&&(l=[this])}),"first"===e.el&&l.length>1&&(l=[l[0]]),l};t.fn.extend({scrollable:function(t){var e=s.call(this,{dir:t});return this.pushStack(e)},firstScrollable:function(t){var e=s.call(this,{el:"first",dir:t});return this.pushStack(e)},smoothScroll:function(l,o){if(l=l||{},"options"===l)return o?this.each(function(){var e=t(this),l=t.extend(e.data("ssOpts")||{},o);t(this).data("ssOpts",l)}):this.first().data("ssOpts");var n=t.extend({},t.fn.smoothScroll.defaults,l),s=t.smoothScroll.filterPath(location.pathname);return this.unbind("click.smoothscroll").bind("click.smoothscroll",function(l){var o=this,r=t(this),i=t.extend({},n,r.data("ssOpts")||{}),c=n.exclude,a=i.excludeWithin,f=0,h=0,u=!0,d={},p=location.hostname===o.hostname||!o.hostname,m=i.scrollTarget||t.smoothScroll.filterPath(o.pathname)===s,S=e(o.hash);if(i.scrollTarget||p&&m&&S){for(;u&&c.length>f;)r.is(e(c[f++]))&&(u=!1);for(;u&&a.length>h;)r.closest(a[h++]).length&&(u=!1)}else u=!1;u&&(i.preventDefault&&l.preventDefault(),t.extend(d,i,{scrollTarget:i.scrollTarget||S,link:o}),t.smoothScroll(d))}),this}}),t.smoothScroll=function(e,l){if("options"===e&&"object"==typeof l)return t.extend(o,l);var n,s,r,i,c,a=0,f="offset",h="scrollTop",u={},d={};"number"==typeof e?(n=t.extend({link:null},t.fn.smoothScroll.defaults,o),r=e):(n=t.extend({link:null},t.fn.smoothScroll.defaults,e||{},o),n.scrollElement&&(f="position","static"===n.scrollElement.css("position")&&n.scrollElement.css("position","relative"))),h="left"===n.direction?"scrollLeft":h,n.scrollElement?(s=n.scrollElement,/^(?:HTML|BODY)$/.test(s[0].nodeName)||(a=s[h]())):s=t("html, body").firstScrollable(n.direction),n.beforeScroll.call(s,n),r="number"==typeof e?e:l||t(n.scrollTarget)[f]()&&t(n.scrollTarget)[f]()[n.direction]||0,u[h]=r+a+n.offset,i=n.speed,"auto"===i&&(c=u[h]-s.scrollTop(),0>c&&(c*=-1),i=c/n.autoCoefficient),d={duration:i,easing:n.easing,complete:function(){n.afterScroll.call(n.link,n)}},n.step&&(d.step=n.step),s.length?s.stop().animate(u,d):n.afterScroll.call(n.link,n)},t.smoothScroll.version=l,t.smoothScroll.filterPath=function(t){return t=t||"",t.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},t.fn.smoothScroll.defaults=n});
|
||
|
|
||
|
/*
|
||
|
** jQuery UI Touch Punch 0.2.3
|
||
|
*/
|
||
|
|
||
|
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
|
||
|
|
||
|
/*
|
||
|
** https://github.com/douglascrockford/JSON-js/blob/master/json2.js
|
||
|
*/
|
||
|
|
||
|
var JSON;if(!JSON){JSON={}}(function(){function f(a){return a<10?"0"+a:a}function quote(a){escapable.lastIndex=0;return escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b==="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];if(i&&typeof i==="object"&&typeof i.toJSON==="function"){i=i.toJSON(a)}if(typeof rep==="function"){i=rep.call(b,a,i)}switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i){return"null"}gap+=indent;h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1){h[c]=str(c,i)||"null"}e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]";gap=g;return e}if(rep&&typeof rep==="object"){f=rep.length;for(c=0;c<f;c+=1){if(typeof rep[c]==="string"){d=rep[c];e=str(d,i);if(e){h.push(quote(d)+(gap?": ":":")+e)}}}}else{for(d in i){if(Object.prototype.hasOwnProperty.call(i,d)){e=str(d,i);if(e){h.push(quote(d)+(gap?": ":":")+e)}}}}e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}";gap=g;return e}}"use strict";if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;if(typeof JSON.stringify!=="function"){JSON.stringify=function(a,b,c){var d;gap="";indent="";if(typeof c==="number"){for(d=0;d<c;d+=1){indent+=" "}}else if(typeof c==="string"){indent=c}rep=b;if(b&&typeof b!=="function"&&(typeof b!=="object"||typeof b.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":a})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e==="object"){for(c in e){if(Object.prototype.hasOwnProperty.call(e,c)){d=walk(e,c);if(d!==undefined){e[c]=d}else{delete e[c]}}}}return reviver.call(a,b,e)}var j;text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}})();
|
||
|
|
||
|
/*!
|
||
|
** Scroll Lock v1.1.1
|
||
|
** https://github.com/MohammadYounes/jquery-scrollLock
|
||
|
*/
|
||
|
|
||
|
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function e(a){var b=a.prop("clientWidth"),c=a.prop("offsetWidth"),d=parseInt(a.css("border-right-width"),10),e=parseInt(a.css("border-left-width"),10);return c>b+e+d}var b="onmousewheel"in window?"ActiveXObject"in window?"wheel":"mousewheel":"DOMMouseScroll",c=".scrollLock",d=a.fn.scrollLock;a.fn.scrollLock=function(d,f,g){return"string"!=typeof f&&(f=null),void 0!==d&&!d||"off"===d?this.each(function(){a(this).off(c)}):this.each(function(){a(this).on(b+c,f,function(b){if(!b.ctrlKey){var c=a(this);if(g===!0||e(c)){b.stopPropagation();var d=c.scrollTop(),f=c.prop("scrollHeight"),h=c.prop("clientHeight"),i=b.originalEvent.wheelDelta||-1*b.originalEvent.detail||-1*b.originalEvent.deltaY,j=0;if("wheel"===b.type){var k=c.height()/a(window).height();j=b.originalEvent.deltaY*k}(i>0&&0>=d+j||0>i&&d+j>=f-h)&&(b.preventDefault(),j&&c.scrollTop(d+j))}}})})},a.fn.scrollLock.noConflict=function(){return a.fn.scrollLock=d,this}});
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
! function($) {
|
||
|
|
||
|
"use strict"; // js hint
|
||
|
|
||
|
if (typeof ko !== 'undefined' && ko.bindingHandlers && !ko.bindingHandlers.multiselect) {
|
||
|
ko.bindingHandlers.multiselect = {
|
||
|
|
||
|
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
||
|
|
||
|
var listOfSelectedItems = allBindingsAccessor().selectedOptions;
|
||
|
var config = ko.utils.unwrapObservable(valueAccessor());
|
||
|
|
||
|
$(element).multiselect(config);
|
||
|
|
||
|
if (isObservableArray(listOfSelectedItems)) {
|
||
|
|
||
|
// Set initial selection state on the multiselect list
|
||
|
$(element).multiselect('select', ko.utils.unwrapObservable(listOfSelectedItems));
|
||
|
|
||
|
// Subscribe to selectedOptions: ko.observableArray
|
||
|
listOfSelectedItems.subscribe(function(changes) {
|
||
|
var addedArray = [],
|
||
|
deletedArray = [];
|
||
|
forEach(changes, function(change) {
|
||
|
switch (change.status) {
|
||
|
case 'added':
|
||
|
addedArray.push(change.value);
|
||
|
break;
|
||
|
case 'deleted':
|
||
|
deletedArray.push(change.value);
|
||
|
break;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (addedArray.length > 0) {
|
||
|
$(element).multiselect('select', addedArray);
|
||
|
}
|
||
|
|
||
|
if (deletedArray.length > 0) {
|
||
|
$(element).multiselect('deselect', deletedArray);
|
||
|
}
|
||
|
}, null, "arrayChange");
|
||
|
}
|
||
|
},
|
||
|
|
||
|
update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
||
|
|
||
|
var listOfItems = allBindingsAccessor().options,
|
||
|
ms = $(element).data('multiselect'),
|
||
|
config = ko.utils.unwrapObservable(valueAccessor());
|
||
|
|
||
|
if (isObservableArray(listOfItems)) {
|
||
|
// Subscribe to the options: ko.observableArray if it changes later
|
||
|
listOfItems.subscribe(function(theArray) {
|
||
|
$(element).multiselect('rebuild');
|
||
|
});
|
||
|
}
|
||
|
|
||
|
if (!ms) {
|
||
|
$(element).multiselect(config);
|
||
|
} else {
|
||
|
ms.updateOriginalOptions();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function isObservableArray(obj) {
|
||
|
return ko.isObservable(obj) && !(obj.destroyAll === undefined);
|
||
|
}
|
||
|
|
||
|
function forEach(array, callback) {
|
||
|
for (var index = 0; index < array.length; ++index) {
|
||
|
callback(array[index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Constructor - create new multiselect from the given select
|
||
|
*
|
||
|
* @param {jQuery} select
|
||
|
* @param {Object} options
|
||
|
* @returns {Multiselect}
|
||
|
*/
|
||
|
function Multiselect(select, options) {
|
||
|
|
||
|
this.$select = $(select);
|
||
|
this.options = this.mergeOptions($.extend({}, options, this.$select.data()));
|
||
|
|
||
|
// Initialization (we have to clone it for a new reference)
|
||
|
this.originalOptions = this.$select.clone()[0].options;
|
||
|
this.query = '';
|
||
|
this.searchTimeout = null;
|
||
|
|
||
|
this.options.multiple = this.$select.attr('multiple') === "multiple";
|
||
|
this.options.onChange = $.proxy(this.options.onChange, this);
|
||
|
this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this);
|
||
|
this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this);
|
||
|
this.options.onDropdownShown = $.proxy(this.options.onDropdownShown, this);
|
||
|
this.options.onDropdownHidden = $.proxy(this.options.onDropdownHidden, this);
|
||
|
|
||
|
// Build select all if enabled
|
||
|
this.buildContainer();
|
||
|
this.buildButton();
|
||
|
this.buildDropdown();
|
||
|
this.buildSelectAll();
|
||
|
this.buildDropdownOptions();
|
||
|
this.buildFilter();
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
|
||
|
if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) {
|
||
|
this.disable();
|
||
|
}
|
||
|
|
||
|
this.$select.hide().after(this.$container);
|
||
|
};
|
||
|
|
||
|
Multiselect.prototype = {
|
||
|
|
||
|
defaults: {
|
||
|
/**
|
||
|
* Default text function will print 'None selected' in case no
|
||
|
* option is selected or a list of selected options with max
|
||
|
* 3 selected options.
|
||
|
*
|
||
|
* @param {jQuery} options
|
||
|
* @param {jQuery} select
|
||
|
* @returns {String}
|
||
|
*/
|
||
|
buttonText: function(options, select) {
|
||
|
if (options.length === 0) {
|
||
|
return this.nonSelectedText + ' <b class="caret"></b>';
|
||
|
} else if (options.length == $('option', $(select)).length) {
|
||
|
return this.allSelectedText + ' <b class="caret"></b>';
|
||
|
} else if (options.length > this.numberDisplayed) {
|
||
|
return options.length + ' ' + this.nSelectedText + ' <b class="caret"></b>';
|
||
|
} else {
|
||
|
var selected = '';
|
||
|
options.each(function() {
|
||
|
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).html();
|
||
|
|
||
|
selected += label + ', ';
|
||
|
});
|
||
|
|
||
|
return selected.substr(0, selected.length - 2) + ' <b class="caret"></b>';
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* Updates the title of the button similar to the buttonText function
|
||
|
*
|
||
|
* @param {jQuery} options
|
||
|
* @param {jQuery} select
|
||
|
* @returns '/'@exp;selected@call;substr}
|
||
|
*/
|
||
|
buttonTitle: function(options, select) {
|
||
|
if (options.length === 0) {
|
||
|
return this.nonSelectedText;
|
||
|
} else {
|
||
|
var selected = '';
|
||
|
options.each(function() {
|
||
|
selected += $(this).text() + ', ';
|
||
|
});
|
||
|
return selected.substr(0, selected.length - 2);
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* Create a label
|
||
|
*
|
||
|
* @param {jQuery} element
|
||
|
* @returns {String}
|
||
|
*/
|
||
|
label: function(element) {
|
||
|
return $(element).attr('label') || $(element).html();
|
||
|
},
|
||
|
/**
|
||
|
* Triggered on change of the multiselect
|
||
|
*
|
||
|
* Not triggered when selecting / deselecting options manually
|
||
|
*
|
||
|
* @param {jQuery} option
|
||
|
* @param {Boolean} checked
|
||
|
*/
|
||
|
onChange: function(option, checked) {
|
||
|
|
||
|
},
|
||
|
/**
|
||
|
* Triggered when the dropdown is shown
|
||
|
*
|
||
|
* @param {jQuery} event
|
||
|
*/
|
||
|
onDropdownShow: function(event) {
|
||
|
|
||
|
},
|
||
|
/**
|
||
|
* Triggered when the dropdown is hidden
|
||
|
*
|
||
|
* @param {jQuery} event
|
||
|
*/
|
||
|
onDropdownHide: function(event) {
|
||
|
|
||
|
},
|
||
|
/**
|
||
|
* Triggered after the dropdown is shown
|
||
|
*
|
||
|
* @param {jQuery} event
|
||
|
*/
|
||
|
onDropdownShown: function(event) {
|
||
|
|
||
|
},
|
||
|
/**
|
||
|
* Triggered after the dropdown is hidden
|
||
|
*
|
||
|
* @param {jQuery} event
|
||
|
*/
|
||
|
onDropdownHidden: function(event) {
|
||
|
|
||
|
},
|
||
|
buttonClass: 'btn btn-default',
|
||
|
buttonWidth: 'auto',
|
||
|
buttonContainer: '<div class="btn-group" />',
|
||
|
dropRight: false,
|
||
|
selectedClass: 'active',
|
||
|
maxHeight: false,
|
||
|
checkboxName: false,
|
||
|
includeSelectAllOption: false,
|
||
|
includeSelectAllIfMoreThan: 0,
|
||
|
selectAllText: ' Select all',
|
||
|
selectAllValue: 'multiselect-all',
|
||
|
selectAllName: false,
|
||
|
enableFiltering: false,
|
||
|
enableCaseInsensitiveFiltering: false,
|
||
|
enableClickableOptGroups: false,
|
||
|
filterPlaceholder: 'Search',
|
||
|
filterBehavior: 'text', // 'text', 'value', 'both'
|
||
|
includeFilterClearBtn: true,
|
||
|
preventInputChangeEvent: false,
|
||
|
nonSelectedText: 'None selected',
|
||
|
nSelectedText: 'selected',
|
||
|
allSelectedText: 'All selected',
|
||
|
numberDisplayed: 3,
|
||
|
disableIfEmpty: false,
|
||
|
templates: {
|
||
|
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>',
|
||
|
ul: '<ul class="multiselect-container dropdown-menu"></ul>',
|
||
|
filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
|
||
|
filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove"></i></button></span>',
|
||
|
li: '<li><a href="javascript:void(0);"><label></label></a></li>',
|
||
|
divider: '<li class="multiselect-item divider"></li>',
|
||
|
liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
|
||
|
}
|
||
|
},
|
||
|
|
||
|
constructor: Multiselect,
|
||
|
|
||
|
/**
|
||
|
* Builds multiselect container
|
||
|
*/
|
||
|
buildContainer: function() {
|
||
|
this.$container = $(this.options.buttonContainer);
|
||
|
this.$container.on('show.bs.dropdown', this.options.onDropdownShow);
|
||
|
this.$container.on('hide.bs.dropdown', this.options.onDropdownHide);
|
||
|
this.$container.on('shown.bs.dropdown', this.options.onDropdownShown);
|
||
|
this.$container.on('hidden.bs.dropdown', this.options.onDropdownHidden);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Builds multiselect button
|
||
|
*/
|
||
|
buildButton: function() {
|
||
|
this.$button = $(this.options.templates.button).addClass(this.options.buttonClass);
|
||
|
|
||
|
// Adopt active state
|
||
|
if (this.$select.prop('disabled')) {
|
||
|
this.disable();
|
||
|
} else {
|
||
|
this.enable();
|
||
|
}
|
||
|
|
||
|
// Manually add button width if set
|
||
|
if (this.options.buttonWidth && this.options.buttonWidth !== 'auto') {
|
||
|
this.$button.css({
|
||
|
'width': this.options.buttonWidth
|
||
|
});
|
||
|
this.$container.css({
|
||
|
'width': this.options.buttonWidth
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// Keep the tab index from the select
|
||
|
var tabindex = this.$select.attr('tabindex');
|
||
|
if (tabindex) {
|
||
|
this.$button.attr('tabindex', tabindex);
|
||
|
}
|
||
|
|
||
|
this.$container.prepend(this.$button);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Builds "ul" representing dropdown menu
|
||
|
*/
|
||
|
buildDropdown: function() {
|
||
|
|
||
|
// Build ul
|
||
|
this.$ul = $(this.options.templates.ul);
|
||
|
|
||
|
if (this.options.dropRight) {
|
||
|
this.$ul.addClass('pull-right');
|
||
|
}
|
||
|
|
||
|
// Set dropdown menu max height to activate auto scrollbar
|
||
|
if (this.options.maxHeight) {
|
||
|
this.$ul.css({
|
||
|
'max-height': this.options.maxHeight + 'px',
|
||
|
'overflow-y': 'auto',
|
||
|
'overflow-x': 'hidden'
|
||
|
});
|
||
|
}
|
||
|
|
||
|
this.$container.append(this.$ul);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Build dropdown options and bind all nessecary events
|
||
|
*
|
||
|
* Uses createDivider and createOptionValue to create necessary options
|
||
|
*/
|
||
|
buildDropdownOptions: function() {
|
||
|
|
||
|
this.$select.children().each($.proxy(function(index, element) {
|
||
|
|
||
|
var $element = $(element);
|
||
|
// Support optgroups and options without a group simultaneously
|
||
|
var tag = $element.prop('tagName')
|
||
|
.toLowerCase();
|
||
|
|
||
|
if ($element.prop('value') === this.options.selectAllValue) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (tag === 'optgroup') {
|
||
|
this.createOptgroup(element);
|
||
|
} else if (tag === 'option') {
|
||
|
|
||
|
if ($element.data('role') === 'divider') {
|
||
|
this.createDivider();
|
||
|
} else {
|
||
|
this.createOptionValue(element);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Ignore illegal tags
|
||
|
}, this));
|
||
|
|
||
|
// Bind change event on the dropdown elements
|
||
|
$('li input', this.$ul).on('change', $.proxy(function(event) {
|
||
|
var $target = $(event.target);
|
||
|
|
||
|
var checked = $target.prop('checked') || false;
|
||
|
var isSelectAllOption = $target.val() === this.options.selectAllValue;
|
||
|
|
||
|
// Apply or unapply configured selected class
|
||
|
if (this.options.selectedClass) {
|
||
|
if (checked) {
|
||
|
$target.closest('li')
|
||
|
.addClass(this.options.selectedClass);
|
||
|
} else {
|
||
|
$target.closest('li')
|
||
|
.removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get corresponding option
|
||
|
var value = $target.val();
|
||
|
var $option = this.getOptionByValue(value);
|
||
|
|
||
|
var $optionsNotThis = $('option', this.$select).not($option);
|
||
|
var $checkboxesNotThis = $('input', this.$container).not($target);
|
||
|
|
||
|
if (isSelectAllOption) {
|
||
|
if (checked) {
|
||
|
this.selectAll();
|
||
|
} else {
|
||
|
this.deselectAll();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!isSelectAllOption) {
|
||
|
if (checked) {
|
||
|
$option.prop('selected', true);
|
||
|
|
||
|
if (this.options.multiple) {
|
||
|
// Select additional option
|
||
|
$option.prop('selected', true);
|
||
|
} else {
|
||
|
// Unselect all other options and corresponding checkboxes
|
||
|
if (this.options.selectedClass) {
|
||
|
$($checkboxesNotThis).closest('li').removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
|
||
|
$($checkboxesNotThis).prop('checked', false);
|
||
|
$optionsNotThis.prop('selected', false);
|
||
|
|
||
|
// If single selection - close
|
||
|
this.$button.click();
|
||
|
}
|
||
|
|
||
|
if (this.options.selectedClass === "active") {
|
||
|
$optionsNotThis.closest("a").css("outline", "");
|
||
|
}
|
||
|
} else {
|
||
|
// Unselect option
|
||
|
$option.prop('selected', false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
this.$select.change();
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
|
||
|
this.options.onChange($option, checked);
|
||
|
|
||
|
if (this.options.preventInputChangeEvent) {
|
||
|
return false;
|
||
|
}
|
||
|
}, this));
|
||
|
|
||
|
$('li a', this.$ul).on('touchstart click', function(event) {
|
||
|
event.stopPropagation();
|
||
|
|
||
|
var $target = $(event.target);
|
||
|
|
||
|
if (document.getSelection().type === 'Range') {
|
||
|
var $input = $(this).find("input:first");
|
||
|
|
||
|
$input.prop("checked", !$input.prop("checked"))
|
||
|
.trigger("change");
|
||
|
}
|
||
|
|
||
|
if (event.shiftKey) {
|
||
|
var checked = $target.prop('checked') || false;
|
||
|
|
||
|
if (checked) {
|
||
|
var prev = $target.closest('li')
|
||
|
.siblings('li[class="active"]:first');
|
||
|
|
||
|
var currentIdx = $target.closest('li')
|
||
|
.index();
|
||
|
var prevIdx = prev.index();
|
||
|
|
||
|
if (currentIdx > prevIdx) {
|
||
|
$target.closest("li").prevUntil(prev).each(
|
||
|
function() {
|
||
|
$(this).find("input:first").prop("checked", true)
|
||
|
.trigger("change");
|
||
|
}
|
||
|
);
|
||
|
} else {
|
||
|
$target.closest("li").nextUntil(prev).each(
|
||
|
function() {
|
||
|
$(this).find("input:first").prop("checked", true)
|
||
|
.trigger("change");
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$target.blur();
|
||
|
});
|
||
|
|
||
|
// Keyboard support
|
||
|
this.$container.off('keydown.multiselect').on('keydown.multiselect', $.proxy(function(event) {
|
||
|
if ($('input[type="text"]', this.$container).is(':focus')) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (event.keyCode === 9 && this.$container.hasClass('open')) {
|
||
|
this.$button.click();
|
||
|
} else {
|
||
|
var $items = $(this.$container).find("li:not(.divider):not(.disabled) a").filter(":visible");
|
||
|
|
||
|
if (!$items.length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var index = $items.index($items.filter(':focus'));
|
||
|
|
||
|
// Navigation up
|
||
|
if (event.keyCode === 38 && index > 0) {
|
||
|
index--;
|
||
|
}
|
||
|
// Navigate down
|
||
|
else if (event.keyCode === 40 && index < $items.length - 1) {
|
||
|
index++;
|
||
|
} else if (!~index) {
|
||
|
index = 0;
|
||
|
}
|
||
|
|
||
|
var $current = $items.eq(index);
|
||
|
$current.focus();
|
||
|
|
||
|
if (event.keyCode === 32 || event.keyCode === 13) {
|
||
|
var $checkbox = $current.find('input');
|
||
|
|
||
|
$checkbox.prop("checked", !$checkbox.prop("checked"));
|
||
|
$checkbox.change();
|
||
|
}
|
||
|
|
||
|
event.stopPropagation();
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
}, this));
|
||
|
|
||
|
if (this.options.enableClickableOptGroups && this.options.multiple) {
|
||
|
$('li.multiselect-group', this.$ul).on('click', $.proxy(function(event) {
|
||
|
event.stopPropagation();
|
||
|
|
||
|
var group = $(event.target).parent();
|
||
|
|
||
|
// Search all options in optgroup
|
||
|
var $options = group.nextUntil('li.multiselect-group');
|
||
|
|
||
|
// check or uncheck needed items
|
||
|
var allChecked = true;
|
||
|
var optionInputs = $options.find('input');
|
||
|
optionInputs.each(function() {
|
||
|
allChecked = allChecked && $(this).prop('checked');
|
||
|
});
|
||
|
|
||
|
optionInputs.prop('checked', !allChecked).trigger('change');
|
||
|
}, this));
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Create option using given select option
|
||
|
* @param {jQuery} element
|
||
|
*/
|
||
|
createOptionValue: function(element) {
|
||
|
var $element = $(element);
|
||
|
if ($element.is(':selected')) {
|
||
|
$element.prop('selected', true);
|
||
|
}
|
||
|
|
||
|
// Support label attribute on options
|
||
|
var label = this.options.label(element);
|
||
|
var value = $element.val();
|
||
|
var inputType = this.options.multiple ? "checkbox" : "radio";
|
||
|
|
||
|
var $li = $(this.options.templates.li);
|
||
|
var $label = $('label', $li);
|
||
|
$label.addClass(inputType);
|
||
|
|
||
|
var $checkbox = $('<input/>').attr('type', inputType);
|
||
|
|
||
|
if (this.options.checkboxName) {
|
||
|
$checkbox.attr('name', this.options.checkboxName);
|
||
|
}
|
||
|
$label.append($checkbox);
|
||
|
|
||
|
var selected = $element.prop('selected') || false;
|
||
|
$checkbox.val(value);
|
||
|
|
||
|
if (value === this.options.selectAllValue) {
|
||
|
$li.addClass("multiselect-item multiselect-all");
|
||
|
$checkbox.parent().parent()
|
||
|
.addClass('multiselect-all');
|
||
|
}
|
||
|
|
||
|
$label.append(" " + label);
|
||
|
$label.attr('title', $element.attr('title'));
|
||
|
|
||
|
this.$ul.append($li);
|
||
|
|
||
|
if ($element.is(':disabled')) {
|
||
|
$checkbox.attr('disabled', 'disabled')
|
||
|
.prop('disabled', true)
|
||
|
.closest('a')
|
||
|
.attr("tabindex", "-1")
|
||
|
.closest('li')
|
||
|
.addClass('disabled');
|
||
|
}
|
||
|
|
||
|
$checkbox.prop('checked', selected);
|
||
|
|
||
|
if (selected && this.options.selectedClass) {
|
||
|
$checkbox.closest('li')
|
||
|
.addClass(this.options.selectedClass);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Creates a divider using given select option
|
||
|
* @param {jQuery} element
|
||
|
*/
|
||
|
createDivider: function(element) {
|
||
|
var $divider = $(this.options.templates.divider);
|
||
|
this.$ul.append($divider);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Creates optgroup
|
||
|
* @param {jQuery} group
|
||
|
*/
|
||
|
createOptgroup: function(group) {
|
||
|
var groupName = $(group).prop('label');
|
||
|
|
||
|
// Add a group header
|
||
|
var $li = $(this.options.templates.liGroup);
|
||
|
$('label', $li).text(groupName);
|
||
|
|
||
|
if (this.options.enableClickableOptGroups) {
|
||
|
$li.addClass('multiselect-group-clickable');
|
||
|
}
|
||
|
|
||
|
this.$ul.append($li);
|
||
|
|
||
|
if ($(group).is(':disabled')) {
|
||
|
$li.addClass('disabled');
|
||
|
}
|
||
|
|
||
|
// Add group options
|
||
|
$('option', group).each($.proxy(function(index, element) {
|
||
|
this.createOptionValue(element);
|
||
|
}, this));
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Build "Selct All"
|
||
|
* Checks if a "Select All" has already been created
|
||
|
*/
|
||
|
buildSelectAll: function() {
|
||
|
if (typeof this.options.selectAllValue === 'number') {
|
||
|
this.options.selectAllValue = this.options.selectAllValue.toString();
|
||
|
}
|
||
|
|
||
|
var alreadyHasSelectAll = this.hasSelectAll();
|
||
|
|
||
|
if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple && $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) {
|
||
|
|
||
|
// Check whether to add divider after "Select All"
|
||
|
if (this.options.includeSelectAllDivider) {
|
||
|
this.$ul.prepend($(this.options.templates.divider));
|
||
|
}
|
||
|
|
||
|
var $li = $(this.options.templates.li);
|
||
|
$('label', $li).addClass("checkbox");
|
||
|
|
||
|
if (this.options.selectAllName) {
|
||
|
$('label', $li).append('<input type="checkbox" name="' + this.options.selectAllName + '" />');
|
||
|
} else {
|
||
|
$('label', $li).append('<input type="checkbox" />');
|
||
|
}
|
||
|
|
||
|
var $checkbox = $('input', $li);
|
||
|
$checkbox.val(this.options.selectAllValue);
|
||
|
|
||
|
$li.addClass("multiselect-item multiselect-all");
|
||
|
$checkbox.parent().parent()
|
||
|
.addClass('multiselect-all');
|
||
|
|
||
|
$('label', $li).append(" " + this.options.selectAllText);
|
||
|
|
||
|
this.$ul.prepend($li);
|
||
|
|
||
|
$checkbox.prop('checked', false);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Builds filter
|
||
|
*/
|
||
|
buildFilter: function() {
|
||
|
|
||
|
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
|
||
|
var enableFilterLength = Math.max(this.options.enableFiltering, this.options.enableCaseInsensitiveFiltering);
|
||
|
|
||
|
if (this.$select.find('option').length >= enableFilterLength) {
|
||
|
|
||
|
this.$filter = $(this.options.templates.filter);
|
||
|
$('input', this.$filter).attr('placeholder', this.options.filterPlaceholder);
|
||
|
|
||
|
// Adds optional filter "Clear" button
|
||
|
if (this.options.includeFilterClearBtn) {
|
||
|
var clearBtn = $(this.options.templates.filterClearBtn);
|
||
|
clearBtn.on('click', $.proxy(function(event) {
|
||
|
clearTimeout(this.searchTimeout);
|
||
|
this.$filter.find('.multiselect-search').val('');
|
||
|
$('li', this.$ul).show().removeClass("filter-hidden");
|
||
|
this.updateSelectAll();
|
||
|
}, this));
|
||
|
this.$filter.find('.input-group').append(clearBtn);
|
||
|
}
|
||
|
|
||
|
this.$ul.prepend(this.$filter);
|
||
|
|
||
|
this.$filter.val(this.query).on('click', function(event) {
|
||
|
event.stopPropagation();
|
||
|
}).on('input keydown', $.proxy(function(event) {
|
||
|
// Disable enter key default behaviour
|
||
|
if (event.which === 13) {
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
|
||
|
// Useful to catch "keydown" events after browser has updated the control
|
||
|
clearTimeout(this.searchTimeout);
|
||
|
|
||
|
this.searchTimeout = this.asyncFunction($.proxy(function() {
|
||
|
|
||
|
if (this.query !== event.target.value) {
|
||
|
this.query = event.target.value;
|
||
|
|
||
|
var currentGroup, currentGroupVisible;
|
||
|
$.each($('li', this.$ul), $.proxy(function(index, element) {
|
||
|
var value = $('input', element).val();
|
||
|
var text = $('label', element).text();
|
||
|
|
||
|
var filterCandidate = '';
|
||
|
if ((this.options.filterBehavior === 'text')) {
|
||
|
filterCandidate = text;
|
||
|
} else if ((this.options.filterBehavior === 'value')) {
|
||
|
filterCandidate = value;
|
||
|
} else if (this.options.filterBehavior === 'both') {
|
||
|
filterCandidate = text + '\n' + value;
|
||
|
}
|
||
|
|
||
|
if (value !== this.options.selectAllValue && text) {
|
||
|
// Default value we want
|
||
|
var showElement = false;
|
||
|
|
||
|
if (this.options.enableCaseInsensitiveFiltering && filterCandidate.toLowerCase().indexOf(this.query.toLowerCase()) > -1) {
|
||
|
showElement = true;
|
||
|
} else if (filterCandidate.indexOf(this.query) > -1) {
|
||
|
showElement = true;
|
||
|
}
|
||
|
|
||
|
// Toggle current element according to showElement boolean
|
||
|
$(element).toggle(showElement).toggleClass('filter-hidden', !showElement);
|
||
|
|
||
|
// Differentiate groups and group items
|
||
|
if ($(element).hasClass('multiselect-group')) {
|
||
|
// Remember group status
|
||
|
currentGroup = element;
|
||
|
currentGroupVisible = showElement;
|
||
|
} else {
|
||
|
// Show group name when at least one of its items is visible
|
||
|
if (showElement) {
|
||
|
$(currentGroup).show().removeClass('filter-hidden');
|
||
|
}
|
||
|
|
||
|
// Show all group items when group name satisfies filter
|
||
|
if (!showElement && currentGroupVisible) {
|
||
|
$(element).show().removeClass('filter-hidden');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}, this));
|
||
|
}
|
||
|
|
||
|
this.updateSelectAll();
|
||
|
}, this), 300, this);
|
||
|
}, this));
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Unbinds whole plugin
|
||
|
*/
|
||
|
destroy: function() {
|
||
|
this.$container.remove();
|
||
|
this.$select.show();
|
||
|
this.$select.data('multiselect', null);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Refreshs multiselect based on the select selected options
|
||
|
*/
|
||
|
refresh: function() {
|
||
|
$('option', this.$select).each($.proxy(function(index, element) {
|
||
|
var $input = $('li input', this.$ul).filter(function() {
|
||
|
return $(this).val() === $(element).val();
|
||
|
});
|
||
|
|
||
|
if ($(element).is(':selected')) {
|
||
|
$input.prop('checked', true);
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$input.closest('li')
|
||
|
.addClass(this.options.selectedClass);
|
||
|
}
|
||
|
} else {
|
||
|
$input.prop('checked', false);
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$input.closest('li')
|
||
|
.removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($(element).is(":disabled")) {
|
||
|
$input.attr('disabled', 'disabled')
|
||
|
.prop('disabled', true)
|
||
|
.closest('li')
|
||
|
.addClass('disabled');
|
||
|
} else {
|
||
|
$input.prop('disabled', false)
|
||
|
.closest('li')
|
||
|
.removeClass('disabled');
|
||
|
}
|
||
|
}, this));
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Select all matching options
|
||
|
*
|
||
|
* If triggerOnChange is "true" => "onChange" event is triggered
|
||
|
* only if one value is passed
|
||
|
*
|
||
|
* @param {Array} selectValues
|
||
|
* @param {Boolean} triggerOnChange
|
||
|
*/
|
||
|
select: function(selectValues, triggerOnChange) {
|
||
|
if (!$.isArray(selectValues)) {
|
||
|
selectValues = [selectValues];
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < selectValues.length; i++) {
|
||
|
var value = selectValues[i];
|
||
|
|
||
|
if (value === null || value === undefined) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
var $option = this.getOptionByValue(value);
|
||
|
var $checkbox = this.getInputByValue(value);
|
||
|
|
||
|
if ($option === undefined || $checkbox === undefined) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (!this.options.multiple) {
|
||
|
this.deselectAll(false);
|
||
|
}
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$checkbox.closest('li')
|
||
|
.addClass(this.options.selectedClass);
|
||
|
}
|
||
|
|
||
|
$checkbox.prop('checked', true);
|
||
|
$option.prop('selected', true);
|
||
|
}
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
|
||
|
if (triggerOnChange && selectValues.length === 1) {
|
||
|
this.options.onChange($option, true);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Clears all selected items
|
||
|
*/
|
||
|
clearSelection: function() {
|
||
|
this.deselectAll(false);
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Deselects all matching options
|
||
|
*
|
||
|
* If triggerOnChange is "true" => "onChange" event is triggered
|
||
|
* only if one value is passed.
|
||
|
*
|
||
|
* @param {Array} deselectValues
|
||
|
* @param {Boolean} triggerOnChange
|
||
|
*/
|
||
|
deselect: function(deselectValues, triggerOnChange) {
|
||
|
if (!$.isArray(deselectValues)) {
|
||
|
deselectValues = [deselectValues];
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < deselectValues.length; i++) {
|
||
|
var value = deselectValues[i];
|
||
|
|
||
|
if (value === null || value === undefined) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
var $option = this.getOptionByValue(value);
|
||
|
var $checkbox = this.getInputByValue(value);
|
||
|
|
||
|
if ($option === undefined || $checkbox === undefined) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$checkbox.closest('li')
|
||
|
.removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
|
||
|
$checkbox.prop('checked', false);
|
||
|
$option.prop('selected', false);
|
||
|
}
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
|
||
|
if (triggerOnChange && deselectValues.length === 1) {
|
||
|
this.options.onChange($option, false);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Selects all enabled and visible options
|
||
|
*
|
||
|
* If justVisible is true or not specified - only visible options are selected
|
||
|
*
|
||
|
* @param {Boolean} justVisible
|
||
|
*/
|
||
|
selectAll: function(justVisible) {
|
||
|
var justVisible = typeof justVisible === 'undefined' ? true : justVisible;
|
||
|
var allCheckboxes = $("li input[type='checkbox']:enabled", this.$ul);
|
||
|
var visibleCheckboxes = allCheckboxes.filter(":visible");
|
||
|
var allCheckboxesCount = allCheckboxes.length;
|
||
|
var visibleCheckboxesCount = visibleCheckboxes.length;
|
||
|
|
||
|
if (justVisible) {
|
||
|
visibleCheckboxes.prop('checked', true);
|
||
|
$("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").addClass(this.options.selectedClass);
|
||
|
} else {
|
||
|
allCheckboxes.prop('checked', true);
|
||
|
$("li:not(.divider):not(.disabled)", this.$ul).addClass(this.options.selectedClass);
|
||
|
}
|
||
|
|
||
|
if (allCheckboxesCount === visibleCheckboxesCount || justVisible === false) {
|
||
|
$("option:enabled", this.$select).prop('selected', true);
|
||
|
} else {
|
||
|
var values = visibleCheckboxes.map(function() {
|
||
|
return $(this).val();
|
||
|
}).get();
|
||
|
|
||
|
$("option:enabled", this.$select).filter(function(index) {
|
||
|
return $.inArray($(this).val(), values) !== -1;
|
||
|
}).prop('selected', true);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Deselects all options
|
||
|
*
|
||
|
* If justVisible is true or not specified - only visible options are deselected
|
||
|
*
|
||
|
* @param {Boolean} justVisible
|
||
|
*/
|
||
|
deselectAll: function(justVisible) {
|
||
|
var justVisible = typeof justVisible === 'undefined' ? true : justVisible;
|
||
|
|
||
|
if (justVisible) {
|
||
|
var visibleCheckboxes = $("li input[type='checkbox']:enabled", this.$ul).filter(":visible");
|
||
|
visibleCheckboxes.prop('checked', false);
|
||
|
|
||
|
var values = visibleCheckboxes.map(function() {
|
||
|
return $(this).val();
|
||
|
}).get();
|
||
|
|
||
|
$("option:enabled", this.$select).filter(function(index) {
|
||
|
return $.inArray($(this).val(), values) !== -1;
|
||
|
}).prop('selected', false);
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
} else {
|
||
|
$("li input[type='checkbox']:enabled", this.$ul).prop('checked', false);
|
||
|
$("option:enabled", this.$select).prop('selected', false);
|
||
|
|
||
|
if (this.options.selectedClass) {
|
||
|
$("li:not(.divider):not(.disabled)", this.$ul).removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Rebuild plugin
|
||
|
*
|
||
|
* Rebuild the dropdown, filter and the "Select all" option
|
||
|
*/
|
||
|
rebuild: function() {
|
||
|
this.$ul.html('');
|
||
|
|
||
|
// Distinguish between radios and checkboxes
|
||
|
this.options.multiple = this.$select.attr('multiple') === "multiple";
|
||
|
|
||
|
this.buildSelectAll();
|
||
|
this.buildDropdownOptions();
|
||
|
this.buildFilter();
|
||
|
|
||
|
this.updateButtonText();
|
||
|
this.updateSelectAll();
|
||
|
|
||
|
if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) {
|
||
|
this.disable();
|
||
|
}
|
||
|
|
||
|
if (this.options.dropRight) {
|
||
|
this.$ul.addClass('pull-right');
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Provided data will be used to build dropdown
|
||
|
*/
|
||
|
dataprovider: function(dataprovider) {
|
||
|
var optionDOM = "";
|
||
|
var groupCounter = 0;
|
||
|
var tags = $('');
|
||
|
|
||
|
$.each(dataprovider, function(index, option) {
|
||
|
var tag;
|
||
|
if ($.isArray(option.children)) { // create option group tag
|
||
|
groupCounter++;
|
||
|
tag = $('<optgroup/>').attr({
|
||
|
label: option.label || 'Group ' + groupCounter
|
||
|
});
|
||
|
forEach(option.children, function(subOption) { // add children option tag or tags
|
||
|
tag.append($('<option/>').attr({
|
||
|
value: subOption.value,
|
||
|
label: subOption.label || subOption.value,
|
||
|
title: subOption.title,
|
||
|
selected: !!subOption.selected
|
||
|
}));
|
||
|
});
|
||
|
|
||
|
optionDOM += '</optgroup>';
|
||
|
} else { // create option tag
|
||
|
tag = $('<option/>').attr({
|
||
|
value: option.value,
|
||
|
label: option.label || option.value,
|
||
|
title: option.title,
|
||
|
selected: !!option.selected
|
||
|
});
|
||
|
}
|
||
|
|
||
|
tags = tags.add(tag);
|
||
|
});
|
||
|
|
||
|
this.$select.empty().append(tags);
|
||
|
this.rebuild();
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Enable multiselect
|
||
|
*/
|
||
|
enable: function() {
|
||
|
this.$select.prop('disabled', false);
|
||
|
this.$button.prop('disabled', false)
|
||
|
.removeClass('disabled');
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Disable multiselect
|
||
|
*/
|
||
|
disable: function() {
|
||
|
this.$select.prop('disabled', true);
|
||
|
this.$button.prop('disabled', true)
|
||
|
.addClass('disabled');
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Set options
|
||
|
*
|
||
|
* @param {Array} options
|
||
|
*/
|
||
|
setOptions: function(options) {
|
||
|
this.options = this.mergeOptions(options);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Merges given options with the default options
|
||
|
*
|
||
|
* @param {Array} options
|
||
|
* @returns {Array}
|
||
|
*/
|
||
|
mergeOptions: function(options) {
|
||
|
return $.extend(true, {}, this.defaults, options);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Checks whether "Select all" checkbox is present
|
||
|
*
|
||
|
* @returns {Boolean}
|
||
|
*/
|
||
|
hasSelectAll: function() {
|
||
|
return $('li.' + this.options.selectAllValue, this.$ul).length > 0;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Updates the "Select all" checkbox depending on the currently displayed and selected checkboxes
|
||
|
*/
|
||
|
updateSelectAll: function() {
|
||
|
if (this.hasSelectAll()) {
|
||
|
var allBoxes = $("li:not(.multiselect-item):not(.filter-hidden) input:enabled", this.$ul);
|
||
|
var allBoxesLength = allBoxes.length;
|
||
|
var checkedBoxesLength = allBoxes.filter(":checked").length;
|
||
|
var selectAllLi = $("li." + this.options.selectAllValue, this.$ul);
|
||
|
var selectAllInput = selectAllLi.find("input");
|
||
|
|
||
|
if (checkedBoxesLength > 0 && checkedBoxesLength === allBoxesLength) {
|
||
|
selectAllInput.prop("checked", true);
|
||
|
selectAllLi.addClass(this.options.selectedClass);
|
||
|
} else {
|
||
|
selectAllInput.prop("checked", false);
|
||
|
selectAllLi.removeClass(this.options.selectedClass);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Update button text and its title depending on the currently selected options
|
||
|
*/
|
||
|
updateButtonText: function() {
|
||
|
var options = this.getSelected();
|
||
|
|
||
|
// Update the displayed button text first
|
||
|
$('.multiselect', this.$container).html(this.options.buttonText(options, this.$select));
|
||
|
|
||
|
// Now update button title attribute
|
||
|
$('.multiselect', this.$container).attr('title', this.options.buttonTitle(options, this.$select));
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Get all selected options
|
||
|
*
|
||
|
* @returns {jQUery}
|
||
|
*/
|
||
|
getSelected: function() {
|
||
|
return $('option', this.$select).filter(":selected");
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Gets a select option by its value
|
||
|
*
|
||
|
* @param {String} value
|
||
|
* @returns {jQuery}
|
||
|
*/
|
||
|
getOptionByValue: function(value) {
|
||
|
|
||
|
var options = $('option', this.$select);
|
||
|
var valueToCompare = value.toString();
|
||
|
|
||
|
for (var i = 0; i < options.length; i = i + 1) {
|
||
|
var option = options[i];
|
||
|
if (option.value === valueToCompare) {
|
||
|
return $(option);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Get the input (radio / checkbox) by its value
|
||
|
*
|
||
|
* @param {String} value
|
||
|
* @returns {jQuery}
|
||
|
*/
|
||
|
getInputByValue: function(value) {
|
||
|
|
||
|
var checkboxes = $('li input', this.$ul);
|
||
|
var valueToCompare = value.toString();
|
||
|
|
||
|
for (var i = 0; i < checkboxes.length; i = i + 1) {
|
||
|
var checkbox = checkboxes[i];
|
||
|
if (checkbox.value === valueToCompare) {
|
||
|
return $(checkbox);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Knockout integration
|
||
|
*/
|
||
|
updateOriginalOptions: function() {
|
||
|
this.originalOptions = this.$select.clone()[0].options;
|
||
|
},
|
||
|
|
||
|
asyncFunction: function(callback, timeout, self) {
|
||
|
var args = Array.prototype.slice.call(arguments, 3);
|
||
|
return setTimeout(function() {
|
||
|
callback.apply(self || window, args);
|
||
|
}, timeout);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
$.fn.multiselect = function(option, parameter, extraOptions) {
|
||
|
return this.each(function() {
|
||
|
var data = $(this).data('multiselect');
|
||
|
var options = typeof option === 'object' && option;
|
||
|
|
||
|
// Initialize multiselect
|
||
|
if (!data) {
|
||
|
data = new Multiselect(this, options);
|
||
|
$(this).data('multiselect', data);
|
||
|
}
|
||
|
|
||
|
// Call multiselect method
|
||
|
if (typeof option === 'string') {
|
||
|
data[option](parameter, extraOptions);
|
||
|
|
||
|
if (option === 'destroy') {
|
||
|
$(this).data('multiselect', false);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
$.fn.multiselect.Constructor = Multiselect;
|
||
|
|
||
|
$(function() {
|
||
|
$("select[data-role=multiselect]").multiselect();
|
||
|
});
|
||
|
|
||
|
}(window.jQuery);
|
||
|
|
||
|
|
||
|
|
||
|
!function(a){return"function"==typeof define&&define.amd?define(["jquery"],function(b){return a(b,window,document)}):a(jQuery,window,document)}(function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H;z={paneClass:"nano-pane",sliderClass:"nano-slider",contentClass:"nano-content",iOSNativeScrolling:!1,preventPageScrolling:!1,disableResize:!1,alwaysVisible:!1,flashDelay:1500,sliderMinHeight:20,sliderMaxHeight:41,documentContext:null,windowContext:null},u="scrollbar",t="scroll",l="mousedown",m="mouseenter",n="mousemove",p="mousewheel",o="mouseup",s="resize",h="drag",i="enter",w="up",r="panedown",f="DOMMouseScroll",g="down",x="wheel",j="keydown",k="keyup",v="touchmove",d="Microsoft Internet Explorer"===b.navigator.appName&&/msie 7./i.test(b.navigator.appVersion)&&b.ActiveXObject,e=null,D=b.requestAnimationFrame,y=b.cancelAnimationFrame,F=c.createElement("div").style,H=function(){var a,b,c,d,e,f;for(d=["t","webkitT","MozT","msT","OT"],a=e=0,f=d.length;f>e;a=++e)if(c=d[a],b=d[a]+"ransform",b in F)return d[a].substr(0,d[a].length-1);return!1}(),G=function(a){return H===!1?!1:""===H?a:H+a.charAt(0).toUpperCase()+a.substr(1)},E=G("transform"),B=E!==!1,A=function(){var a,b,d;return a=c.createElement("div"),b=a.style,b.position="absolute",b.width="100px",b.height="100px",b.overflow=t,b.top="-9999px",c.body.appendChild(a),d=a.offsetWidth-a.clientWidth,c.body.removeChild(a),d},C=function(){var a,c,d;return c=b.navigator.userAgent,(a=/(?=.+Mac OS X)(?=.+Firefox)/.test(c))?(d=/Firefox\/\d{2}\./.exec(c),d&&(d=d[0].replace(/\D+/g,"")),a&&+d>23):!1},q=function(){function j(d,f){this.el=d,this.options=f,e||(e=A()),this.$el=a(this.el),this.doc=a(this.options.documentContext||c),this.win=a(this.options.windowContext||b),this.body=this.doc.find("body"),this.$content=this.$el.children("."+f.contentClass),this.$content.attr("tabindex",this.options.tabIndex||0),this.content=this.$content[0],this.previousPosition=0,this.options.iOSNativeScrolling&&null!=this.el.style.WebkitOverflowScrolling?this.nativeScrolling():this.generate(),this.createEvents(),this.addEvents(),this.reset()}return j.prototype.preventScrolling=function(a,b){if(this.isActive)if(a.type===f)(b===g&&a.originalEvent.detail>0||b===w&&a.originalEvent.detail<0)&&a.preventDefault();else if(a.type===p){if(!a.originalEvent||!a.originalEvent.wheelDelta)return;(b===g&&a.originalEvent.wheelDelta<0||b===w&&a.originalEvent.wheelDelta>0)&&a.preventDefault()}},j.prototype.nativeScrolling=function(){this.$content.css({WebkitOverflowScrolling:"touch"}),this.iOSNativeScrolling=!0,this.isActive=!0},j.prototype.updateScrollValues=function(){var a,b;a=this.content,this.maxScrollTop=a.scrollHeight-a.clientHeight,this.prevScrollTop=this.contentScrollTop||0,this.contentScrollTop=a.scrollTop,b=this.contentScrollTop>this.previousPosition?"down":this.contentScrollTop<this.previousPosition?"up":"same",this.previousPosition=this.contentScrollTop,"same"!==b&&this.$el.trigger("update",{position:this.contentScrollTop,maximum:this.maxScrollTop,direction:b}),this.iOSNativeScrolling||(this.maxSliderTop=this.paneHeight-this.sliderHeight,this.sliderTop=0===this.maxScrollTop?0:this.contentScrollTop*this.maxSliderTop/this.maxScrollTop)},j.prototype.setOnScrollStyles=function(){var a;B?(a={},a[E]="translate(0, "+this.sliderTop+"px)"):a={top:this.sliderTop},D?(y&&this.scrollRAF&&y(this.scrollRAF),this.scrollRAF=D(function(b){return function(){return b.scrollRAF=null,b.slider.css(a)}}(this))):this.slider.css(a)},j.prototype.createEvents=function(){this.events={down:function(a){return function(b){return a.isBeingDragged=!0,a.offsetY=b.pageY-a.slider.offset().top,a.slider.is(b.target)||(a.offsetY=0),a.pane.addClass("active"),a.doc.bind(n,a.events[h]).bind(o,a.events[w]),a.body.bind(m,a.events[i]),!1}}(this),drag:function(a){return function(b){return a.sliderY=b.pageY-a.$el.offset().top-a.paneTop-(a.offsetY||.5*a.sliderHeight),a.scroll(),a.contentScrollTop>=a.maxScrollTop&&a.prevScrollTop!==a.maxScrollTop?a.$el.trigger("scrollend"):0===a.contentScrollTop&&0!==a.prevScrollTop&&a.$el.tri
|
||
|
|
||
|
|
||
|
|
||
|
(function ($, window) {
|
||
|
"use strict";
|
||
|
|
||
|
var namespace = "scroller",
|
||
|
$body = null,
|
||
|
classes = {
|
||
|
base: "scroller",
|
||
|
content: "scroller-content",
|
||
|
bar: "scroller-bar",
|
||
|
track: "scroller-track",
|
||
|
handle: "scroller-handle",
|
||
|
isHorizontal: "scroller-horizontal",
|
||
|
isSetup: "scroller-setup",
|
||
|
isActive: "scroller-active"
|
||
|
},
|
||
|
events = {
|
||
|
start: "touchstart." + namespace + " mousedown." + namespace,
|
||
|
move: "touchmove." + namespace + " mousemove." + namespace,
|
||
|
end: "touchend." + namespace + " mouseup." + namespace
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @options
|
||
|
* @param customClass [string] <''> "Class applied to instance"
|
||
|
* @param duration [int] <0> "Scroll animation length"
|
||
|
* @param handleSize [int] <0> "Handle size; 0 to auto size"
|
||
|
* @param horizontal [boolean] <false> "Scroll horizontally"
|
||
|
* @param trackMargin [int] <0> "Margin between track and handle edge”
|
||
|
*/
|
||
|
var options = {
|
||
|
customClass: "",
|
||
|
duration: 0,
|
||
|
handleSize: 20,
|
||
|
horizontal: false,
|
||
|
trackMargin: 0
|
||
|
};
|
||
|
|
||
|
var pub = {
|
||
|
|
||
|
/**
|
||
|
* @method
|
||
|
* @name defaults
|
||
|
* @description Sets default plugin options
|
||
|
* @param opts [object] <{}> "Options object"
|
||
|
* @example $.scroller("defaults", opts);
|
||
|
*/
|
||
|
defaults: function(opts) {
|
||
|
options = $.extend(options, opts || {});
|
||
|
return (typeof this === 'object') ? $(this) : true;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @method
|
||
|
* @name destroy
|
||
|
* @description Removes instance of plugin
|
||
|
* @example $(".target").scroller("destroy");
|
||
|
*/
|
||
|
destroy: function() {
|
||
|
return $(this).each(function(i, el) {
|
||
|
var data = $(el).data(namespace);
|
||
|
|
||
|
if (data) {
|
||
|
data.$scroller.removeClass( [data.customClass, classes.base, classes.isActive].join(" ") );
|
||
|
|
||
|
data.$bar.remove();
|
||
|
data.$content.contents().unwrap();
|
||
|
|
||
|
data.$content.off( classify(namespace) );
|
||
|
data.$scroller.off( classify(namespace) )
|
||
|
.removeData(namespace);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @method
|
||
|
* @name scroll
|
||
|
* @description Scrolls instance of plugin to element or position
|
||
|
* @param pos [string || int] <null> "Target element selector or static position"
|
||
|
* @param duration [int] <null> "Optional scroll duration"
|
||
|
* @example $.scroller("scroll", pos, duration);
|
||
|
*/
|
||
|
scroll: function(pos, dur) {
|
||
|
return $(this).each(function(i) {
|
||
|
var data = $(this).data(namespace),
|
||
|
duration = dur || options.duration;
|
||
|
|
||
|
if (typeof pos !== "number") {
|
||
|
var $el = $(pos);
|
||
|
if ($el.length > 0) {
|
||
|
var offset = $el.position();
|
||
|
if (data.horizontal) {
|
||
|
pos = offset.left + data.$content.scrollLeft();
|
||
|
} else {
|
||
|
pos = offset.top + data.$content.scrollTop();
|
||
|
}
|
||
|
} else {
|
||
|
pos = data.$content.scrollTop();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var styles = data.horizontal ? { scrollLeft: pos } : { scrollTop: pos };
|
||
|
|
||
|
data.$content.stop().animate(styles, duration);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @method
|
||
|
* @name reset
|
||
|
* @description Resets layout on instance of plugin
|
||
|
* @example $.scroller("reset");
|
||
|
*/
|
||
|
reset: function() {
|
||
|
return $(this).each(function(i) {
|
||
|
var data = $(this).data(namespace);
|
||
|
|
||
|
if (data) {
|
||
|
data.$scroller.addClass(classes.isSetup);
|
||
|
|
||
|
var barStyles = {},
|
||
|
trackStyles = {},
|
||
|
handleStyles = {},
|
||
|
handlePosition = 0,
|
||
|
isActive = true;
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
data.barHeight = data.$content[0].offsetHeight - data.$content[0].clientHeight;
|
||
|
data.frameWidth = data.$content.outerWidth();
|
||
|
data.trackWidth = data.frameWidth - (data.trackMargin * 2);
|
||
|
data.scrollWidth = data.$content[0].scrollWidth;
|
||
|
data.ratio = data.trackWidth / data.scrollWidth;
|
||
|
data.trackRatio = data.trackWidth / data.scrollWidth;
|
||
|
data.handleWidth = (data.handleSize > 0) ? data.handleSize : data.trackWidth * data.trackRatio;
|
||
|
data.scrollRatio = (data.scrollWidth - data.frameWidth) / (data.trackWidth - data.handleWidth);
|
||
|
data.handleBounds = {
|
||
|
left: 0,
|
||
|
right: data.trackWidth - data.handleWidth
|
||
|
};
|
||
|
|
||
|
data.$content.css({
|
||
|
paddingBottom: data.barHeight + data.paddingBottom
|
||
|
});
|
||
|
|
||
|
var scrollLeft = data.$content.scrollLeft();
|
||
|
|
||
|
handlePosition = scrollLeft * data.ratio;
|
||
|
isActive = (data.scrollWidth <= data.frameWidth);
|
||
|
|
||
|
barStyles = {
|
||
|
width: data.frameWidth
|
||
|
};
|
||
|
|
||
|
trackStyles = {
|
||
|
width: data.trackWidth,
|
||
|
marginLeft: data.trackMargin,
|
||
|
marginRight: data.trackMargin
|
||
|
};
|
||
|
|
||
|
handleStyles = {
|
||
|
width: data.handleWidth
|
||
|
};
|
||
|
} else {
|
||
|
// Vertical
|
||
|
data.barWidth = data.$content[0].offsetWidth - data.$content[0].clientWidth;
|
||
|
data.frameHeight = data.$content.outerHeight();
|
||
|
data.trackHeight = data.frameHeight - (data.trackMargin * 2);
|
||
|
data.scrollHeight = data.$content[0].scrollHeight;
|
||
|
data.ratio = data.trackHeight / data.scrollHeight;
|
||
|
data.trackRatio = data.trackHeight / data.scrollHeight;
|
||
|
data.handleHeight = (data.handleSize > 0) ? data.handleSize : data.trackHeight * data.trackRatio;
|
||
|
data.scrollRatio = (data.scrollHeight - data.frameHeight) / (data.trackHeight - data.handleHeight);
|
||
|
data.handleBounds = {
|
||
|
top: 0,
|
||
|
bottom: data.trackHeight - data.handleHeight
|
||
|
};
|
||
|
|
||
|
var scrollTop = data.$content.scrollTop();
|
||
|
|
||
|
handlePosition = scrollTop * data.ratio;
|
||
|
isActive = (data.scrollHeight <= data.frameHeight);
|
||
|
|
||
|
barStyles = {
|
||
|
height: data.frameHeight
|
||
|
};
|
||
|
|
||
|
trackStyles = {
|
||
|
height: data.trackHeight,
|
||
|
marginBottom: data.trackMargin,
|
||
|
marginTop: data.trackMargin
|
||
|
};
|
||
|
|
||
|
handleStyles = {
|
||
|
height: data.handleHeight
|
||
|
};
|
||
|
}
|
||
|
|
||
|
if (isActive) {
|
||
|
data.$scroller.removeClass(classes.isActive);
|
||
|
} else {
|
||
|
data.$scroller.addClass(classes.isActive);
|
||
|
}
|
||
|
|
||
|
data.$bar.css(barStyles);
|
||
|
data.$track.css(trackStyles);
|
||
|
data.$handle.css(handleStyles);
|
||
|
|
||
|
position(data, handlePosition);
|
||
|
|
||
|
data.$scroller.removeClass(classes.isSetup);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name init
|
||
|
* @description Initializes plugin
|
||
|
* @param opts [object] "Initialization options"
|
||
|
*/
|
||
|
function init(opts) {
|
||
|
// Local options
|
||
|
opts = $.extend({}, options, opts || {});
|
||
|
|
||
|
// Check for Body tag
|
||
|
if ($body === null) {
|
||
|
$body = $("body");
|
||
|
}
|
||
|
|
||
|
// Apply to each elem
|
||
|
var $items = $(this);
|
||
|
for (var i = 0, count = $items.length; i < count; i++) {
|
||
|
build($items.eq(i), opts);
|
||
|
}
|
||
|
return $items;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name build
|
||
|
* @description Builds each instance
|
||
|
* @param $scroller [jQuery object] "Target jQuery object"
|
||
|
* @param opts [object] <{}> "Options object"
|
||
|
*/
|
||
|
function build($scroller, opts) {
|
||
|
if (!$scroller.hasClass(classes.base)) {
|
||
|
// EXTEND OPTIONS
|
||
|
opts = $.extend({}, opts, $scroller.data(namespace + "-options"));
|
||
|
|
||
|
var html = '';
|
||
|
|
||
|
html += '<div class="' + classes.bar + '">';
|
||
|
html += '<div class="' + classes.track + '">';
|
||
|
html += '<div class="' + classes.handle + '">';
|
||
|
html += '</div></div></div>';
|
||
|
|
||
|
opts.paddingRight = parseInt($scroller.css("padding-right"), 10);
|
||
|
opts.paddingBottom = parseInt($scroller.css("padding-bottom"), 10);
|
||
|
|
||
|
$scroller.addClass( [classes.base, opts.customClass].join(" ") )
|
||
|
.wrapInner('<div class="' + classes.content + '" />')
|
||
|
.prepend(html);
|
||
|
|
||
|
if (opts.horizontal) {
|
||
|
$scroller.addClass(classes.isHorizontal);
|
||
|
}
|
||
|
|
||
|
var data = $.extend({
|
||
|
$scroller: $scroller,
|
||
|
$content: $scroller.find( classify(classes.content) ),
|
||
|
$bar: $scroller.find( classify(classes.bar) ),
|
||
|
$track: $scroller.find( classify(classes.track) ),
|
||
|
$handle: $scroller.find( classify(classes.handle) )
|
||
|
}, opts);
|
||
|
|
||
|
data.trackMargin = parseInt(data.trackMargin, 10);
|
||
|
|
||
|
data.$content.on("scroll." + namespace, data, onScroll);
|
||
|
data.$scroller.on(events.start, classify(classes.track), data, onTrackDown)
|
||
|
.on(events.start, classify(classes.handle), data, onHandleDown)
|
||
|
.data(namespace, data);
|
||
|
|
||
|
pub.reset.apply($scroller);
|
||
|
|
||
|
$(window).one("load", function() {
|
||
|
pub.reset.apply($scroller);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onScroll
|
||
|
* @description Handles scroll event
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onScroll(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data,
|
||
|
handleStyles = {};
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
var scrollLeft = data.$content.scrollLeft();
|
||
|
|
||
|
if (scrollLeft < 0) {
|
||
|
scrollLeft = 0;
|
||
|
}
|
||
|
|
||
|
var handleLeft = scrollLeft / data.scrollRatio;
|
||
|
|
||
|
if (handleLeft > data.handleBounds.right) {
|
||
|
handleLeft = data.handleBounds.right;
|
||
|
}
|
||
|
|
||
|
handleStyles = {
|
||
|
left: handleLeft
|
||
|
};
|
||
|
} else {
|
||
|
// Vertical
|
||
|
var scrollTop = data.$content.scrollTop();
|
||
|
|
||
|
if (scrollTop < 0) {
|
||
|
scrollTop = 0;
|
||
|
}
|
||
|
|
||
|
var handleTop = scrollTop / data.scrollRatio;
|
||
|
|
||
|
if (handleTop > data.handleBounds.bottom) {
|
||
|
handleTop = data.handleBounds.bottom;
|
||
|
}
|
||
|
|
||
|
handleStyles = {
|
||
|
top: handleTop
|
||
|
};
|
||
|
}
|
||
|
|
||
|
data.$handle.css(handleStyles);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onTrackDown
|
||
|
* @description Handles mousedown event on track
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onTrackDown(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data,
|
||
|
oe = e.originalEvent,
|
||
|
offset = data.$track.offset(),
|
||
|
touch = (typeof oe.targetTouches !== "undefined") ? oe.targetTouches[0] : null,
|
||
|
pageX = (touch) ? touch.pageX : e.clientX,
|
||
|
pageY = (touch) ? touch.pageY : e.clientY;
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
data.mouseStart = pageX;
|
||
|
data.handleLeft = pageX - offset.left - (data.handleWidth / 2);
|
||
|
|
||
|
position(data, data.handleLeft);
|
||
|
} else {
|
||
|
// Vertical
|
||
|
data.mouseStart = pageY;
|
||
|
data.handleTop = pageY - offset.top - (data.handleHeight / 2);
|
||
|
|
||
|
position(data, data.handleTop);
|
||
|
}
|
||
|
|
||
|
onStart(data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onHandleDown
|
||
|
* @description Handles mousedown event on handle
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onHandleDown(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data,
|
||
|
oe = e.originalEvent,
|
||
|
touch = (typeof oe.targetTouches !== "undefined") ? oe.targetTouches[0] : null,
|
||
|
pageX = (touch) ? touch.pageX : e.clientX,
|
||
|
pageY = (touch) ? touch.pageY : e.clientY;
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
data.mouseStart = pageX;
|
||
|
data.handleLeft = parseInt(data.$handle.css("left"), 10);
|
||
|
} else {
|
||
|
// Vertical
|
||
|
data.mouseStart = pageY;
|
||
|
data.handleTop = parseInt(data.$handle.css("top"), 10);
|
||
|
}
|
||
|
|
||
|
onStart(data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onStart
|
||
|
* @description Handles touch.mouse start
|
||
|
* @param data [object] "Instance data"
|
||
|
*/
|
||
|
function onStart(data) {
|
||
|
data.$content.off( classify(namespace) );
|
||
|
|
||
|
$body.on(events.move, data, onMouseMove)
|
||
|
.on(events.end, data, onMouseUp);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onMouseMove
|
||
|
* @description Handles mousemove event
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onMouseMove(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data,
|
||
|
oe = e.originalEvent,
|
||
|
pos = 0,
|
||
|
delta = 0,
|
||
|
touch = (typeof oe.targetTouches !== "undefined") ? oe.targetTouches[0] : null,
|
||
|
pageX = (touch) ? touch.pageX : e.clientX,
|
||
|
pageY = (touch) ? touch.pageY : e.clientY;
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
delta = data.mouseStart - pageX;
|
||
|
pos = data.handleLeft - delta;
|
||
|
} else {
|
||
|
// Vertical
|
||
|
delta = data.mouseStart - pageY;
|
||
|
pos = data.handleTop - delta;
|
||
|
}
|
||
|
|
||
|
position(data, pos);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onMouseUp
|
||
|
* @description Handles mouseup event
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onMouseUp(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data;
|
||
|
|
||
|
data.$content.on("scroll.scroller", data, onScroll);
|
||
|
$body.off(".scroller");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name onTouchEnd
|
||
|
* @description Handles mouseup event
|
||
|
* @param e [object] "Event data"
|
||
|
*/
|
||
|
function onTouchEnd(e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
var data = e.data;
|
||
|
|
||
|
data.$content.on("scroll.scroller", data, onScroll);
|
||
|
$body.off(".scroller");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name position
|
||
|
* @description Position handle based on scroll
|
||
|
* @param data [object] "Instance data"
|
||
|
* @param pos [int] "Scroll position"
|
||
|
*/
|
||
|
function position(data, pos) {
|
||
|
var handleStyles = {};
|
||
|
|
||
|
if (data.horizontal) {
|
||
|
// Horizontal
|
||
|
if (pos < data.handleBounds.left) {
|
||
|
pos = data.handleBounds.left;
|
||
|
}
|
||
|
|
||
|
if (pos > data.handleBounds.right) {
|
||
|
pos = data.handleBounds.right;
|
||
|
}
|
||
|
|
||
|
var scrollLeft = Math.round(pos * data.scrollRatio);
|
||
|
|
||
|
handleStyles = {
|
||
|
left: pos
|
||
|
};
|
||
|
|
||
|
data.$content.scrollLeft( scrollLeft );
|
||
|
} else {
|
||
|
// Vertical
|
||
|
if (pos < data.handleBounds.top) {
|
||
|
pos = data.handleBounds.top;
|
||
|
}
|
||
|
|
||
|
if (pos > data.handleBounds.bottom) {
|
||
|
pos = data.handleBounds.bottom;
|
||
|
}
|
||
|
|
||
|
var scrollTop = Math.round(pos * data.scrollRatio);
|
||
|
|
||
|
handleStyles = {
|
||
|
top: pos
|
||
|
};
|
||
|
|
||
|
data.$content.scrollTop( scrollTop );
|
||
|
}
|
||
|
|
||
|
data.$handle.css(handleStyles);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @method private
|
||
|
* @name classify
|
||
|
* @description Create class selector from text
|
||
|
* @param text [string] "Text to convert"
|
||
|
* @return [string] "New class name"
|
||
|
*/
|
||
|
function classify(text) {
|
||
|
return "." + text;
|
||
|
}
|
||
|
|
||
|
$.fn[namespace] = function(method) {
|
||
|
if (pub[method]) {
|
||
|
return pub[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||
|
} else if (typeof method === 'object' || !method) {
|
||
|
return init.apply(this, arguments);
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
$[namespace] = function(method) {
|
||
|
if (method === "defaults") {
|
||
|
pub.defaults.apply(this, Array.prototype.slice.call(arguments, 1));
|
||
|
}
|
||
|
};
|
||
|
})(jQuery);
|
||
|
|
||
|
|
||
|
;
|
||
|
(function(){var n=this,t=n._,r=Array.prototype,e=Object.prototype,u=Function.prototype,i=r.push,a=r.slice,o=r.concat,l=e.toString,c=e.hasOwnProperty,f=Array.isArray,s=Object.keys,p=u.bind,h=function(n){return n instanceof h?n:this instanceof h?void(this._wrapped=n):new h(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=h),exports._=h):n._=h,h.VERSION="1.7.0";var g=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}};h.iteratee=function(n,t,r){return null==n?h.identity:h.isFunction(n)?g(n,t,r):h.isObject(n)?h.matches(n):h.property(n)},h.each=h.forEach=function(n,t,r){if(null==n)return n;t=g(t,r);var e,u=n.length;if(u===+u)for(e=0;u>e;e++)t(n[e],e,n);else{var i=h.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},h.map=h.collect=function(n,t,r){if(null==n)return[];t=h.iteratee(t,r);for(var e,u=n.length!==+n.length&&h.keys(n),i=(u||n).length,a=Array(i),o=0;i>o;o++)e=u?u[o]:o,a[o]=t(n[e],e,n);return a};var v="Reduce of empty array with no initial value";h.reduce=h.foldl=h.inject=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length,o=0;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[o++]:o++]}for(;a>o;o++)u=i?i[o]:o,r=t(r,n[u],u,n);return r},h.reduceRight=h.foldr=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[--a]:--a]}for(;a--;)u=i?i[a]:a,r=t(r,n[u],u,n);return r},h.find=h.detect=function(n,t,r){var e;return t=h.iteratee(t,r),h.some(n,function(n,r,u){return t(n,r,u)?(e=n,!0):void 0}),e},h.filter=h.select=function(n,t,r){var e=[];return null==n?e:(t=h.iteratee(t,r),h.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e)},h.reject=function(n,t,r){return h.filter(n,h.negate(h.iteratee(t)),r)},h.every=h.all=function(n,t,r){if(null==n)return!0;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,!t(n[u],u,n))return!1;return!0},h.some=h.any=function(n,t,r){if(null==n)return!1;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,t(n[u],u,n))return!0;return!1},h.contains=h.include=function(n,t){return null==n?!1:(n.length!==+n.length&&(n=h.values(n)),h.indexOf(n,t)>=0)},h.invoke=function(n,t){var r=a.call(arguments,2),e=h.isFunction(t);return h.map(n,function(n){return(e?t:n[t]).apply(n,r)})},h.pluck=function(n,t){return h.map(n,h.property(t))},h.where=function(n,t){return h.filter(n,h.matches(t))},h.findWhere=function(n,t){return h.find(n,h.matches(t))},h.max=function(n,t,r){var e,u,i=-1/0,a=-1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],e>i&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(u>a||u===-1/0&&i===-1/0)&&(i=n,a=u)});return i},h.min=function(n,t,r){var e,u,i=1/0,a=1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],i>e&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(a>u||1/0===u&&1/0===i)&&(i=n,a=u)});return i},h.shuffle=function(n){for(var t,r=n&&n.length===+n.length?n:h.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=h.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},h.sample=function(n,t,r){return null==t||r?(n.length!==+n.length&&(n=h.values(n)),n[h.random(n.length-1)]):h.shuffle(n).slice(0,Math.max(0,t))},h.sortBy=function(n,t,r){return t=h.iteratee(t,r),h.pluck(h.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var m=function(n){return function(t,r,e){var u={};return r=h.iteratee(r,e),h.each(t,function(e,i){var a=r(e,i,t);n(u,
|
||
|
|
||
|
|
||
|
/*!
|
||
|
* Bootstrap v3.3.1 (http://getbootstrap.com)
|
||
|
* Copyright 2011-2014 Twitter, Inc.
|
||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||
|
*/
|
||
|
/*
|
||
|
if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.1",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.1",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")&&(c.prop("checked")&&this.$element.hasClass("active")?a=!1:b.find(".active").removeClass("active")),a&&c.prop("checked",!this.$element.hasClass("active")).trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active"));a&&this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=
|
||
|
})}}},c.prototype.activate=function(b,d,e){function f(){g.removeClass("active").find("> .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=this.unpin=this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.1",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=i?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=a("body").height();"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery);
|
||
|
*/
|
||
|
/*!
|
||
|
* Bootstrap v3.3.6 (http://getbootstrap.com)
|
||
|
* Copyright 2011-2015 Twitter, Inc.
|
||
|
* Licensed under the MIT license
|
||
|
*/
|
||
|
if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>2)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.6",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.6",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carouse
|
||
|
d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate.bs.scrollspy")},b.prototype.clear=function(){a(this.selector).parentsUntil(this.options.target,".active").removeClass("active")};var d=a.fn.scrollspy;a.fn.scrollspy=c,a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=d,this},a(window).on("load.bs.scrollspy.data-api",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);c.call(b,b.data())})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new c(this)),"string"==typeof b&&e[b]()})}var c=function(b){this.element=a(b)};c.VERSION="3.3.6",c.TRANSITION_DURATION=150,c.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.data("target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a"),f=a.Event("hide.bs.tab",{relatedTarget:b[0]}),g=a.Event("show.bs.tab",{relatedTarget:e[0]});if(e.trigger(f),b.trigger(g),!g.isDefaultPrevented()&&!f.isDefaultPrevented()){var h=a(d);this.activate(b.closest("li"),c),this.activate(h,h.parent(),function(){e.trigger({type:"hidden.bs.tab",relatedTarget:b[0]}),b.trigger({type:"shown.bs.tab",relatedTarget:e[0]})})}}},c.prototype.activate=function(b,d,e){function f(){g.removeClass("active").find("> .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.6",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event
|
||
|
|
||
|
(function($){
|
||
|
$(window).load(function(){
|
||
|
if ($('.scroller-navbar').length) {
|
||
|
$(".scroller-navbar ").mCustomScrollbar({
|
||
|
theme:"light-thick",
|
||
|
scrollbarPosition:"outside"
|
||
|
});
|
||
|
}
|
||
|
if ($('.scroller-block').length) {
|
||
|
$(".scroller-block").mCustomScrollbar({
|
||
|
theme:"light-thick"
|
||
|
//scrollbarPosition:"outside"
|
||
|
});
|
||
|
}
|
||
|
if ($('.scroller-chute').length) {
|
||
|
$(".scroller-chute").mCustomScrollbar({
|
||
|
theme:"light-thick"
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
})(jQuery);
|