*/
if ($.fn.easyPieChart) {
$('.easy-pie-chart').each(function() {
var $this = $(this),
barColor = $this.css('color') || $this.data('pie-color'),
trackColor = $this.data('pie-track-color') || 'rgba(0,0,0,0.04)',
size = parseInt($this.data('pie-size')) || 25;
$this.easyPieChart({
barColor : barColor,
trackColor : trackColor,
scaleColor : false,
lineCap : 'butt',
lineWidth : parseInt(size / 8.5),
animate : 1500,
rotate : -90,
size : size,
onStep: function(from, to, percent) {
$(this.el).find('.percent').text(Math.round(percent));
}
});
$this = null;
});
} // end if
}
/* ~ END: INITIALIZE CHARTS */
/*
* INITIALIZE JARVIS WIDGETS
* Setup Desktop Widgets
*/
function setup_widgets_desktop() {
if ($.fn.jarvisWidgets && enableJarvisWidgets) {
$('#widget-grid').jarvisWidgets({
grid : 'article',
widgets : '.jarviswidget',
localStorage : localStorageJarvisWidgets,
deleteSettingsKey : '#deletesettingskey-options',
settingsKeyLabel : 'Reset settings?',
deletePositionKey : '#deletepositionkey-options',
positionKeyLabel : 'Reset position?',
sortable : sortableJarvisWidgets,
buttonsHidden : false,
// toggle button
toggleButton : true,
toggleClass : 'fa fa-minus | fa fa-plus',
toggleSpeed : 200,
onToggle : function() {
},
// delete btn
deleteButton : true,
deleteMsg:'Warning: This action cannot be undone!',
deleteClass : 'fa fa-times',
deleteSpeed : 200,
onDelete : function() {
},
// edit btn
editButton : true,
editPlaceholder : '.jarviswidget-editbox',
editClass : 'fa fa-cog | fa fa-save',
editSpeed : 200,
onEdit : function() {
},
// color button
colorButton : true,
// full screen
fullscreenButton : true,
fullscreenClass : 'fa fa-expand | fa fa-compress',
fullscreenDiff : 3,
onFullscreen : function() {
},
// custom btn
customButton : false,
customClass : 'folder-10 | next-10',
customStart : function() {
alert('Hello you, this is a custom button...');
},
customEnd : function() {
alert('bye, till next time...');
},
// order
buttonOrder : '%refresh% %custom% %edit% %toggle% %fullscreen% %delete%',
opacity : 1.0,
dragHandle : '> header',
placeholderClass : 'jarviswidget-placeholder',
indicator : true,
indicatorTime : 600,
ajax : true,
timestampPlaceholder : '.jarviswidget-timestamp',
timestampFormat : 'Last update: %m%/%d%/%y% %h%:%i%:%s%',
refreshButton : true,
refreshButtonClass : 'fa fa-refresh',
labelError : 'Sorry but there was a error:',
labelUpdated : 'Last Update:',
labelRefresh : 'Refresh',
labelDelete : 'Delete widget:',
afterLoad : function() {
},
rtl : false, // best not to toggle this!
onChange : function() {
console.log("onChange event");
},
onSave : function() {
console.log("onSave event");
},
ajaxnav : $.navAsAjax // declears how the localstorage should be saved (HTML or AJAX Version)
});
}
}
/*
* SETUP DESKTOP WIDGET
*/
function setup_widgets_mobile() {
if (enableMobileWidgets && enableJarvisWidgets) {
setup_widgets_desktop();
}
}
/* ~ END: INITIALIZE JARVIS WIDGETS */
/*
* LOAD SCRIPTS
* Usage:
* Define function = myPrettyCode ()...
* loadScript("js/my_lovely_script.js", myPrettyCode);
*/
function loadScript(scriptName, callback) {
if (!jsArray[scriptName]) {
var promise = jQuery.Deferred();
// adding the script tag to the head as suggested before
var body = document.getElementsByTagName('body')[0],
script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptName;
// then bind the event to the callback function
// there are several events for cross browser compatibility
script.onload = function() {
promise.resolve();
};
// fire the loading
body.appendChild(script);
// clear DOM reference
//body = null;
//script = null;
jsArray[scriptName] = promise.promise();
} else if (debugState)
root.root.console.log("This script was already loaded %c: " + scriptName, debugStyle_warning);
jsArray[scriptName].then(function () {
if(typeof callback === 'function')
callback();
});
}
/* ~ END: LOAD SCRIPTS */
/*
* APP AJAX REQUEST SETUP
* Description: Executes and fetches all ajax requests also
* updates naivgation elements to active
*/
if($.navAsAjax) {
// fire this on page load if nav exists
if ($('nav').length) {
checkURL();
}
$(document).on('click', 'nav a[href!="#"]', function(e) {
e.preventDefault();
var $this = $(e.currentTarget);
// if parent is not active then get hash, or else page is assumed to be loaded
if (!$this.parent().hasClass("active") && !$this.attr('target')) {
// update window with hash
// you could also do here: thisDevice === "mobile" - and save a little more memory
if ($.root_.hasClass('mobile-view-activated')) {
$.root_.removeClass('hidden-menu');
$('html').removeClass("hidden-menu-mobile-lock");
window.setTimeout(function() {
if (window.location.search) {
window.location.href =
window.location.href.replace(window.location.search, '')
.replace(window.location.hash, '') + '#' + $this.attr('href');
} else {
window.location.hash = $this.attr('href');
}
}, 150);
// it may not need this delay...
} else {
if (window.location.search) {
window.location.href =
window.location.href.replace(window.location.search, '')
.replace(window.location.hash, '') + '#' + $this.attr('href');
} else {
window.location.hash = $this.attr('href');
}
}
// clear DOM reference
// $this = null;
}
});
// fire links with targets on different window
$(document).on('click', 'nav a[target="_blank"]', function(e) {
e.preventDefault();
var $this = $(e.currentTarget);
window.open($this.attr('href'));
});
// fire links with targets on same window
$(document).on('click', 'nav a[target="_top"]', function(e) {
e.preventDefault();
var $this = $(e.currentTarget);
window.location = ($this.attr('href'));
});
// all links with hash tags are ignored
$(document).on('click', 'nav a[href="#"]', function(e) {
e.preventDefault();
});
// DO on hash change
$(window).on('hashchange', function() {
checkURL();
});
}
/*
* CHECK TO SEE IF URL EXISTS
*/
function checkURL() {
//get the url by removing the hash
//var url = location.hash.replace(/^#/, '');
var url = location.href.split('#').splice(1).join('#');
//BEGIN: IE11 Work Around
if (!url) {
try {
var documentUrl = window.document.URL;
if (documentUrl) {
if (documentUrl.indexOf('#', 0) > 0 && documentUrl.indexOf('#', 0) < (documentUrl.length + 1)) {
url = documentUrl.substring(documentUrl.indexOf('#', 0) + 1);
}
}
} catch (err) {}
}
//END: IE11 Work Around
container = $('#content');
// Do this if url exists (for page refresh, etc...)
if (url) {
// remove all active class
$('nav li.active').removeClass("active");
// match the url and add the active class
$('nav li:has(a[href="' + url + '"])').addClass("active");
var title = ($('nav a[href="' + url + '"]').attr('title'));
// change page title from global var
document.title = (title || document.title);
// debugState
if (debugState){
root.console.log("Page title: %c " + document.title, debugStyle_green);
}
// parse url to jquery
loadURL(url + location.search, container);
} else {
// grab the first URL from nav
var $this = $('nav > ul > li:first-child > a[href!="#"]');
//update hash
window.location.hash = $this.attr('href');
//clear dom reference
$this = null;
}
}
/*
* LOAD AJAX PAGES
*/
function loadURL(url, container) {
// debugState
if (debugState){
root.root.console.log("Loading URL: %c" + url, debugStyle);
}
$.ajax({
type : "GET",
url : url,
dataType : 'html',
cache : true, // (warning: setting it to false will cause a timestamp and will call the request twice)
beforeSend : function() {
// destroy all datatable instances
if ( $.navAsAjax && $('.dataTables_wrapper')[0] && (container[0] == $("#content")[0]) ) {
var tables = $.fn.dataTable.fnTables(true);
$(tables).each(function () {
if($(this).find('.details-control').length != 0) {
$(this).find('*').addBack().off().remove();
$(this).dataTable().fnDestroy();
} else {
$(this).dataTable().fnDestroy();
}
});
// debugState
if (debugState){
root.console.log("✔ Datatable instances nuked!!!");
}
}
// end destroy
// pop intervals (destroys jarviswidget related intervals)
if ( $.navAsAjax && $.intervalArr.length > 0 && (container[0] == $("#content")[0]) && enableJarvisWidgets ) {
while($.intervalArr.length > 0)
clearInterval($.intervalArr.pop());
// debugState
if (debugState){
root.console.log("✔ All JarvisWidget intervals cleared");
}
}
// end pop intervals
// destroy all widget instances
if ( $.navAsAjax && (container[0] == $("#content")[0]) && enableJarvisWidgets && $("#widget-grid")[0] ) {
$("#widget-grid").jarvisWidgets('destroy');
// debugState
if (debugState){
root.console.log("✔ JarvisWidgets destroyed");
}
}
// end destroy all widgets
// cluster destroy: destroy other instances that could be on the page
// this runs a script in the current loaded page before fetching the new page
if ( $.navAsAjax && (container[0] == $("#content")[0]) ) {
/*
* The following elements should be removed, if they have been created:
*
* colorList
* icon
* picker
* inline
* And unbind events from elements:
*
* icon
* picker
* inline
* especially $(document).on('mousedown')
* It will be much easier to add namespace to plugin events and then unbind using selected namespace.
*
* See also:
*
* http://f6design.com/journal/2012/05/06/a-jquery-plugin-boilerplate/
* http://keith-wood.name/pluginFramework.html
*/
// this function is below the pagefunction for all pages that has instances
if (typeof pagedestroy == 'function') {
try {
pagedestroy();
if (debugState){
root.console.log("✔ Pagedestroy()");
}
}
catch(err) {
pagedestroy = undefined;
if (debugState){
root.console.log("! Pagedestroy() Catch Error");
}
}
}
// destroy all inline charts
if ( $.fn.sparkline && $("#content .sparkline")[0] ) {
$("#content .sparkline").sparkline( 'destroy' );
if (debugState){
root.console.log("✔ Sparkline Charts destroyed!");
}
}
if ( $.fn.easyPieChart && $("#content .easy-pie-chart")[0] ) {
$("#content .easy-pie-chart").easyPieChart( 'destroy' );
if (debugState){
root.console.log("✔ EasyPieChart Charts destroyed!");
}
}
// end destory all inline charts
// destroy form controls: Datepicker, select2, autocomplete, mask, bootstrap slider
if ( $.fn.select2 && $("#content select.select2")[0] ) {
$("#content select.select2").select2('destroy');
if (debugState){
root.console.log("✔ Select2 destroyed!");
}
}
if ( $.fn.mask && $('#content [data-mask]')[0] ) {
$('#content [data-mask]').unmask();
if (debugState){
root.console.log("✔ Input Mask destroyed!");
}
}
if ( $.fn.datepicker && $('#content .datepicker')[0] ) {
$('#content .datepicker').off();
$('#content .datepicker').remove();
if (debugState){
root.console.log("✔ Datepicker destroyed!");
}
}
if ( $.fn.slider && $('#content .slider')[0] ) {
$('#content .slider').off();
$('#content .slider').remove();
if (debugState){
root.console.log("✔ Bootstrap Slider destroyed!");
}
}
// end destroy form controls
}
// end cluster destroy
// empty container and var to start garbage collection (frees memory)
pagefunction = null;
container.removeData().html("");
// place cog
container.html('
Loading...
');
// Only draw breadcrumb if it is main content material
if (container[0] == $("#content")[0]) {
// clear everything else except these key DOM elements
// we do this because sometime plugins will leave dynamic elements behind
$('body').find('> *').filter(':not(' + ignore_key_elms + ')').empty().remove();
// draw breadcrumb
drawBreadCrumb();
// scroll up
$("html").animate({
scrollTop : 0
}, "fast");
}
// end if
},
success : function(data) {
// dump data to container
container.css({
opacity : '0.0'
}).html(data).delay(50).animate({
opacity : '1.0'
}, 300);
// clear data var
data = null;
container = null;
},
error : function(xhr, status, thrownError, error) {
container.html('
');
},
async : true
});
}
/*
* UPDATE BREADCRUMB
*/
function drawBreadCrumb(opt_breadCrumbs) {
var a = $("nav li.active > a"),
b = a.length;
bread_crumb.empty(),
bread_crumb.append($("
Home
")), a.each(function() {
bread_crumb.append($("").html($.trim($(this).clone().children(".badge").remove().end().text()))), --b || (document.title = bread_crumb.find("li:last-child").text())
});
// Push breadcrumb manually -> drawBreadCrumb(["Users", "John Doe"]);
// Credits: Philip Whitt | philip.whitt@sbcglobal.net
if (opt_breadCrumbs != undefined) {
$.each(opt_breadCrumbs, function(index, value) {
bread_crumb.append($("").html(value));
document.title = bread_crumb.find("li:last-child").text();
});
}
}
/* ~ END: APP AJAX REQUEST SETUP */
/*
* PAGE SETUP
* Description: fire certain scripts that run through the page
* to check for form elements, tooltip activation, popovers, etc...
*/
function pageSetUp() {
if (thisDevice === "desktop"){
// is desktop
// activate tooltips
$("[rel=tooltip], [data-rel=tooltip]").tooltip();
// activate popovers
$("[rel=popover], [data-rel=popover]").popover();
// activate popovers with hover states
$("[rel=popover-hover], [data-rel=popover-hover]").popover({
trigger : "hover"
});
// setup widgets
setup_widgets_desktop();
// activate inline charts
runAllCharts();
// run form elements
runAllForms();
} else {
// is mobile
// activate popovers
$("[rel=popover], [data-rel=popover]").popover();
// activate popovers with hover states
$("[rel=popover-hover], [data-rel=popover-hover]").popover({
trigger : "hover"
});
// activate inline charts
runAllCharts();
// setup widgets
setup_widgets_mobile();
// run form elements
runAllForms();
}
}
/* ~ END: PAGE SETUP */
/*
* ONE POP OVER THEORY
* Keep only 1 active popover per trigger - also check and hide active popover if user clicks on document
*/
$('body').on('click', function(e) {
$('[rel="popover"], [data-rel="popover"]').each(function() {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
/* ~ END: ONE POP OVER THEORY */
/*
* DELETE MODEL DATA ON HIDDEN
* Clears the model data once it is hidden, this way you do not create duplicated data on multiple modals
*/
$('body').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
/* ~ END: DELETE MODEL DATA ON HIDDEN */
/*
* HELPFUL FUNCTIONS
* We have included some functions below that can be resued on various occasions
*
* Get param value
* example: alert( getParam( 'param' ) );
*/
function getParam(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
/* ~ END: HELPFUL FUNCTIONS */