Skip to content

Commit

Permalink
Improvements at the code
Browse files Browse the repository at this point in the history
  • Loading branch information
nenomaz committed Dec 11, 2016
1 parent 7c04513 commit 1912ff9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions jquery.easy-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ along with jQuery Easy Overlay. If not, see <http://www.gnu.org/licenses/>.
(function( $ ){
$.fn.easyOverlay = function(action, options) {

// Preparing options
var defaults = {
zindex: "99999",
spin: true,
delay: 400,
};
var _options = $.extend(true, defaults, $.fn.easyOverlay.options || {}, options || {});

// States constants
var STATE_VISIBLE = 1;
var STATE_HIDDEN = 0;

var overlayZIndex;
$.fn.easyOverlay.indexCounter++;

function init(target) {
var easyOverlayIndex = $.fn.easyOverlay.indexCounter;
if(target.length <= 0 || target.data('easyOverlayState') == STATE_VISIBLE) return;
target.data('easyOverlayInitiated', true);
$.fn.easyOverlay.indexCounter++;
var easyOverlayIndex = $.fn.easyOverlay.indexCounter;

// Calculating OVERLAY DIV z-index
overlayZIndex;
var overlayZIndex;
var targetZIndex = target.css('z-index');
if (targetZIndex == "auto")
overlayZIndex = _options.zindex;
Expand Down Expand Up @@ -92,11 +93,10 @@ along with jQuery Easy Overlay. If not, see <http://www.gnu.org/licenses/>.
}

function start(target) {
var easyOverlayIndex = $.fn.easyOverlay.indexCounter;
var easyOverlayIndex = target.data('easyOverlayIndex');
// Restoring some CSS of OVERLAY DIV after every 'stop' because jquery.fadeOut method take off it
$("#jqueryEasyOverlayDiv"+easyOverlayIndex).css({
opacity : 0.5,
zIndex : overlayZIndex,
top : target.offset().top,
left : target.offset().left,
width : target.outerWidth(),
Expand All @@ -111,23 +111,25 @@ along with jQuery Easy Overlay. If not, see <http://www.gnu.org/licenses/>.
function stop(target) {
var easyOverlayIndex = target.data('easyOverlayIndex');
if( $("#jqueryEasyOverlayDiv"+easyOverlayIndex).length ) {
$("#jqueryEasyOverlayDiv"+easyOverlayIndex).fadeOut(_options.delay, function(){this.remove()});
$("#jqueryEasyOverlayDiv"+easyOverlayIndex).fadeOut(_options.delay);
}
target.data('easyOverlayState', STATE_HIDDEN);
}

switch (action) {
case 'start':
{
if(this.length > 0) {
init(this);
if(this.length == 1) {
if (typeof this.data('easyOverlayInitiated') == 'undefined') {
init(this);
}
start(this);
}
}
break;
case 'stop':
{
if (this.length > 0) {
if (this.length == 1) {
stop(this);
}
}
Expand Down

0 comments on commit 1912ff9

Please sign in to comment.