/*****************************************************
	  https://github.com/snovakovic/wiggle
    author: stefan.novakovich@gmail.com
    version: 0.0.2
 ***************************************************/
(function(global, factory) {
  //UMD pattern
  if (typeof exports === 'object' && typeof module !== 'undefined') {
    module.exports = factory()
  } else if (typeof define === 'function' && define.amd) {
    define(factory)
  } else {
    global.Wiggle = factory()
  }
}(this, (function() {


  return {
    init: function(settings) {
      settings.resizeDelay = settings.resizeDelay || 25;
      var screens = Array.isArray(settings.screens) ? settings.screens : [];
      var doit;
      var activeScreens = [];
      var subscribeType = {
        on: 'on',
        once: 'once',
        off: 'off'
      }
      var subscribers = {};

      updateActiveScreens();

      // Populate default subscribers
      Object.getOwnPropertyNames(subscribeType).forEach(function(name) {
        subscribers[name] = {};
      });


      window.addEventListener('resize', function() {
        clearTimeout(doit);
        doit = setTimeout(updateActiveScreens, settings.resizeDelay);
      }, true);


      function updateActiveScreens() {
        screens.forEach(function (screen) {
          var active = isScreenActive(screen);

          if (active) {
            if (!activeScreens[screen.name]) {
              activeScreens[screen.name] = screen;
              notifySubscribers(screen.name, subscribeType.on);
            }
          } else if (activeScreens[screen.name]) {
            delete activeScreens[screen.name];
            notifySubscribers(screen.name, subscribeType.off);
          }
        });
      }

      function notifySubscribers(screenName, type) {
        var screenSubscribers = subscribers[type] && subscribers[type][screenName];
        if (screenSubscribers && screenSubscribers.length) {
          screenSubscribers.forEach(function(subscriber) {
            subscriber.execute();
          });
        }
      }

      function isScreenActive(screen) {
        if (typeof screen === 'string') {
          screen = getScreen(screen);
        }

        return Boolean(screen &&
          ((screen.minWidth && window.matchMedia('(min-width: ' + screen.minWidth + 'px)').matches) ||
            (screen.maxWidth && window.matchMedia('(max-width: ' + screen.maxWidth + 'px)').matches)));
      }

      function getScreen(name) {
        for (var i = 0; i < screens.length; i++) {
          if (name === screens[i].name) {
            return screens[i];
          }
        }
      }

      function subscribe(name, type, callback) {
        subscribers[type][name] = subscribers[type][name] || [];
        subscribers[type][name].push({
          name: name,
          type: type,
          execute: callback,
        });
      }


      var public = {};

      public.on = function(screenName, callback) {
        isScreenActive(screenName) && callback();
        subscribe(screenName, subscribeType.on, callback);
      };

      public.queueOn = function(screenName, callback) {
        subscribe(screenName, subscribeType.on, callback);
      };

      public.once = function(screenName, callback) {
        isScreenActive(screenName) ? callback() :
          subscribe(screenName, subscribeType.once, callback);
      };

      public.off = function(screenName, callback) {
        !isScreenActive(screenName) && callback();
        subscribe(screenName, subscribeType.off, callback);
      };

      public.queueOff = function(screenName, callback) {
        subscribe(screenName, subscribeType.off, callback);
      };

      public.is = function(screenName) {
        return Boolean(activeScreens[screenName]);
      };

      public.getActiveScreens = function() {
        return activeScreens;
      }

      return public;
    }
  }
})));

@@ -145,17 +145,17 @@
 on: 0.0.
-2
+3
 %0A ******
@@ -494,17 +494,16 @@
 on() %7B%0A%0A
-%0A
   return
@@ -1265,17 +1265,16 @@
 function
- 
 (screen)
@@ -1289,21 +1289,8 @@
     
- var active =
  isS
@@ -1308,19 +1308,19 @@
 (screen)
-;%0A%0A
+%0A  
         
@@ -1325,21 +1325,37 @@
     
-if (
+? 
 activ
+ateScreen(screen.nam
 e)
- %7B
 %0A   
@@ -1367,27 +1367,27 @@
     
-if (!
+: de
 activ
+at
 eScreen
-s%5B
+(
 scre
@@ -1397,27 +1397,83 @@
 name
-%5D) %7B%0A       
+);%0A        %7D);%0A      %7D%0A%0A      function activateScreen(name) %7B%0A
        
+ if (!
 acti
@@ -1478,31 +1478,57 @@
 tiveScreens%5B
-s
+name%5D) %7B%0A          activeS
 creen
-.
+s%5B
 name%5D = scre
@@ -1531,20 +1531,16 @@
 screen;%0A
-    
         
@@ -1551,39 +1551,32 @@
 tifySubscribers(
-screen.
 name, subscribeT
@@ -1586,32 +1586,36 @@
 .on);%0A      
+  %7D%0A
       %7D%0A
           %7D 
@@ -1606,24 +1606,56 @@
   %7D%0A
+%0A
       
-    %7D else
+function deactivateScreen(name) %7B%0A       
  if 
@@ -1665,31 +1665,24 @@
 tiveScreens%5B
-screen.
 name%5D) %7B%0A   
@@ -1670,34 +1670,32 @@
 creens%5Bname%5D) %7B%0A
-  
           delete
@@ -1713,24 +1713,15 @@
 ens%5B
-screen.
 name%5D;%0A
-  
     
@@ -1744,23 +1744,16 @@
 cribers(
-screen.
 name, su
@@ -1782,23 +1782,9 @@
     
-  %7D%0A        %7D);
+%7D
 %0A   

Rewrite updateActiveScreens method.