Skip to content

Commit

Permalink
Codestyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Craigy- committed Sep 1, 2016
1 parent b0de7d3 commit 0a492ee
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions jquery.uniloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
* http://www.gnu.org/licenses/gpl.html
*/

(function($) {
(function ($) {
var uniloader = {
APNGSupported: false,
actualResizer: 'resize',

init: function() {
init: function () {
// Supports 'throttledresize' event
if('throttledresize' in jQuery.event.special) {
if ('throttledresize' in jQuery.event.special) {
this.actualResizer = 'throttledresize';
}

this._checkAPNGSupport();
},

// Check browser supported APNG or not
_checkAPNGSupport: function() {
_checkAPNGSupport: function () {
var APNGTest = new Image(),
cv = document.createElement('canvas');
APNGTest.onload = function() {
if(cv.getContext) {
APNGTest.onload = function () {
if (cv.getContext) {
var ctx = cv.getContext('2d');
ctx.drawImage(APNGTest, 0, 0);
uniloader.APNGSupported = (ctx.getImageData(0, 0, 1, 1).data[3] === 0);
Expand All @@ -42,17 +42,17 @@
},

// Calculate dimensions of the browser window
_getWindowDimensions: function() {
_getWindowDimensions: function () {
return {
width: $(window)[0].innerWidth || $(window).width(),
height: $(window)[0].innerHeight || $(window).height()
};
},

// Calculate the scrollbar width (0 - no scrollbar)
_getScrollbarWidth: function() {
_getScrollbarWidth: function () {
var wd = this._getWindowDimensions();
if($(document).height() - wd.height <= 0) {
if ($(document).height() - wd.height <= 0) {
return 0;
}

Expand All @@ -65,7 +65,7 @@
},

// Centering node in the browser window
_centerNode: function(node, scrollable) {
_centerNode: function (node, scrollable) {
var wd = this._getWindowDimensions(),
w = node.outerWidth(),
h = node.outerHeight(),
Expand All @@ -88,17 +88,16 @@
};

// Mouse loader
$.mouseLoader = function(state, options) {
$.mouseLoader = function (state, options) {
var $node = $('#uniloader-mouse');
var opts = $.extend(true, {}, uniloader.defaults, options);

// Show mouse loader
if(state) {

if (state) {
// Create node
if(!$node.length) {
if (!$node.length) {
$node = $('<div id="uniloader-mouse" />').data({
'uniloader-mousemove': function(e) {
'uniloader-mousemove': function (e) {
$node.css({
'top' : e.pageY - ($node.outerHeight() / 2),
'left' : e.pageX - ($node.outerWidth() / 2)
Expand All @@ -107,13 +106,13 @@
'uniloader-onHide': opts.onHide
});
$(document.body).append($node);
if(uniloader.APNGSupported) {
if (uniloader.APNGSupported) {
$node.css('backgroundImage', $node.css('backgroundImage').replace(/ajax\.gif/gi, 'ajax.png'));
}
}

// Show node
if($node.is(':visible')) {
if ($node.is(':visible')) {
return;
}

Expand All @@ -123,32 +122,29 @@
$node.css({
'top' : coords.top,
'left' : coords.left
}).show(opts.effectSpeed, function() {
}).show(opts.effectSpeed, function () {
opts.onShow();
});

$(document.body).on('mousemove.uniloader scroll.uniloader', $node.data('uniloader-mousemove'));

} else {

// Hide mouse loader
$node.hide(opts.effectSpeed, function() {
$node.hide(opts.effectSpeed, function () {
$node.data('uniloader-onHide')();
});

$(document.body).off('mousemove.uniloader scroll.uniloader', $node.data('uniloader-mousemove'));

}
};

// Overlay loader
$.overlayLoader = function(state, options) {
$.overlayLoader = function (state, options) {
var $overlay = $('#uniloader-overlay'),
$node = $('#uniloader-overlay-content'),
isModal = false;

// 'node' is optional
if(options && options.node) {
if (options && options.node) {
$node = $(options.node);
isModal = true;
delete options.node;
Expand All @@ -157,47 +153,46 @@
var opts = $.extend(true, {}, uniloader.defaults, options);

// Show overlay loader or modal window
if(state) {

if (state) {
// Create overlay
if(!$overlay.length) {
if (!$overlay.length) {
$overlay = $('<div id="uniloader-overlay" />');
$(document.body).append($overlay);
}

// Create overlay loader node
if(!$node.length) {
if (!$node.length) {
$node = $('<div id="uniloader-overlay-content"><div class="uniloader-overlay-content-text" /></div>');
}

// Show node
if($overlay.is(':visible')) {
if ($overlay.is(':visible')) {
$.overlayLoader(false, {
effectSpeed: 0
});
}

opts.onStart();

if(isModal) {
$overlay.on('click.uniloader', function() {
if (isModal) {
$overlay.on('click.uniloader', function () {
$.overlayLoader();
});

$(document.body).on('keypress.uniloader', function(e) {
if(e.keyCode == 27) {
$(document.body).on('keypress.uniloader', function (e) {
if (e.keyCode == 27) {
$.overlayLoader();
}
});

$node.on('click', function(e) {
$node.on('click', function (e) {
e.stopPropagation();
}).find(opts.hideSelector).on('click.uniloader', function(e) {
}).find(opts.hideSelector).on('click.uniloader', function (e) {
e.preventDefault();
$.overlayLoader();
});
}
$(window).on(uniloader.actualResizer + '.uniloader gestureend.uniloader', function() {
$(window).on(uniloader.actualResizer + '.uniloader gestureend.uniloader', function () {
var coords = uniloader._centerNode($node);
$node.css({
'top' : coords.top,
Expand All @@ -212,35 +207,32 @@
'uniloader-node': $node,
'uniloader-node-parent': $node.parent().length ? $node.parent() : $(document.body),
'uniloader-onHide': opts.onHide
}).append($node).fadeTo(opts.effectSpeed, 1, function() {
}).append($node).fadeTo(opts.effectSpeed, 1, function () {
var coords = uniloader._centerNode($node);
$node.css({
'top' : coords.top,
'left' : coords.left
}).show(opts.effectSpeed, function() {
}).show(opts.effectSpeed, function () {
opts.onShow();
});
});

} else {

// Hide node
$node = $($overlay.data('uniloader-node'));

if($overlay.data('uniloader-ismodal')) {
if ($overlay.data('uniloader-ismodal')) {
$overlay.off('.uniloader');
$(document.body).off('keypress.uniloader');
$node.find(opts.hideSelector).off('.uniloader');
}
$(window).off(uniloader.actualResizer + '.uniloader gestureend.uniloader');

$node.hide(opts.effectSpeed);
$overlay.fadeOut(opts.effectSpeed, function() {
$overlay.fadeOut(opts.effectSpeed, function () {
$($overlay.data('uniloader-node-parent')).append($node);
$('html').removeClass('uniloader-overlay-html').css('margin-right', '');
$overlay.data('uniloader-onHide')();
});

}
};

Expand Down

0 comments on commit 0a492ee

Please sign in to comment.