<commit_before>'use strict';

angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
  var root = {};

  var getNetwork = function(addr) {
    var Address = bitcore.Address;
    if (Address.isValid(addr, 'livenet')) {
console.log('[addressbookService.js:8] LIVENET'); //TODO
      return 'livenet';
    }
    if (Address.isValid(addr, 'testnet')) {
console.log('[addressbookService.js:12] TESTNET'); //TODO
      return 'testnet';
    }
  };

  root.getLabel = function(addr, cb) {
    storageService.getAddressbook('testnet', function(err, ab) {
      if (ab && ab[addr]) return cb(ab[addr]);

      storageService.getAddressbook('livnet', function(err, ab) {
        if (ab && ab[addr]) return cb(ab[addr]);
        return cb();
      });
    });
  };

  root.list = function(cb) {
    storageService.getAddressbook('testnet', function(err, ab) {
      if (err) return cb('Could not get the Addressbook');

      if (ab) ab = JSON.parse(ab);

      ab = ab || {};
      storageService.getAddressbook('livenet', function(err, ab2) {
        if (ab2) ab2 = JSON.parse(ab2);

        ab2 = ab2 || {};
        return cb(err, lodash.defaults(ab2, ab));
      });
    });
  };

  root.add = function(entry, cb) {
    var network = getNetwork(entry.address);
    storageService.getAddressbook(network, function(err, ab) {
      if (err) return cb(err);
      if (ab) ab = JSON.parse(ab);
      ab = ab || {};
      if (ab[entry.address]) return cb('Entry already exist');
      ab[entry.address] = entry.label;
      storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) {
        if (err) return cb('Error adding new entry');
        root.list(function(err, ab) {
          return cb(err, ab);
        });
      });
    });
  };

  root.remove = function(addr, cb) {
    var network = getNetwork(addr);
    storageService.getAddressbook(network, function(err, ab) {
      if (err) return cb(err);
      if (ab) ab = JSON.parse(ab);
      ab = ab || {};
      if (lodash.isEmpty(ab)) return cb('Addressbook is empty');
      if (!ab[addr]) return cb('Entry does not exist');
      delete ab[addr];
      storageService.setAddressbook(network, JSON.stringify(ab), function(err) {
        if (err) return cb('Error deleting entry');
        root.list(function(err, ab) {
          return cb(err, ab);
        });
      });
    });
  };

  root.removeAll = function() {
    storageService.removeAddressbook('livenet', function(err) {
      storageService.removeAddressbook('testnet', function(err) {
        if (err) return cb('Error deleting addressbook');
        return cb();
      });
    });
  };

  return root;
});
<commit_msg>removes console log<commit_after>'use strict';

angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
  var root = {};

  var getNetwork = function(addr) {
    var Address = bitcore.Address;
    if (Address.isValid(addr, 'livenet')) {
      return 'livenet';
    }
    if (Address.isValid(addr, 'testnet')) {
      return 'testnet';
    }
  };

  root.getLabel = function(addr, cb) {
    storageService.getAddressbook('testnet', function(err, ab) {
      if (ab && ab[addr]) return cb(ab[addr]);

      storageService.getAddressbook('livnet', function(err, ab) {
        if (ab && ab[addr]) return cb(ab[addr]);
        return cb();
      });
    });
  };

  root.list = function(cb) {
    storageService.getAddressbook('testnet', function(err, ab) {
      if (err) return cb('Could not get the Addressbook');

      if (ab) ab = JSON.parse(ab);

      ab = ab || {};
      storageService.getAddressbook('livenet', function(err, ab2) {
        if (ab2) ab2 = JSON.parse(ab2);

        ab2 = ab2 || {};
        return cb(err, lodash.defaults(ab2, ab));
      });
    });
  };

  root.add = function(entry, cb) {
    var network = getNetwork(entry.address);
    storageService.getAddressbook(network, function(err, ab) {
      if (err) return cb(err);
      if (ab) ab = JSON.parse(ab);
      ab = ab || {};
      if (ab[entry.address]) return cb('Entry already exist');
      ab[entry.address] = entry.label;
      storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) {
        if (err) return cb('Error adding new entry');
        root.list(function(err, ab) {
          return cb(err, ab);
        });
      });
    });
  };

  root.remove = function(addr, cb) {
    var network = getNetwork(addr);
    storageService.getAddressbook(network, function(err, ab) {
      if (err) return cb(err);
      if (ab) ab = JSON.parse(ab);
      ab = ab || {};
      if (lodash.isEmpty(ab)) return cb('Addressbook is empty');
      if (!ab[addr]) return cb('Entry does not exist');
      delete ab[addr];
      storageService.setAddressbook(network, JSON.stringify(ab), function(err) {
        if (err) return cb('Error deleting entry');
        root.list(function(err, ab) {
          return cb(err, ab);
        });
      });
    });
  };

  root.removeAll = function() {
    storageService.removeAddressbook('livenet', function(err) {
      storageService.removeAddressbook('testnet', function(err) {
        if (err) return cb('Error deleting addressbook');
        return cb();
      });
    });
  };

  return root;
});
<|endoftext|>


<commit_before>/*
  inSubnet - By Louis T. <louist@ltdev.im>
  Check an IP(v4 or v6) against a subnet.
*/
Exporter(function (isNode) {
   var proto = {
       version: '0.0.3',
       Auto: function (ip, subnet, prefix) {
             if (!ip || !subnet) {
                return false;
             };
             var sm = this.getPrefix(subnet,prefix);
             if (sm[0] && sm[1] && !isNaN(sm[1])) {
                if (this.isIPv4(ip)) {
                   return this.__IPv4(ip,sm[0],sm[1]);
                 } else {
                   return this.__IPv6(ip,sm[0],sm[1]);
                };
             };
             return false;
       },
       IPv4: function (ip, subnet, prefix) {
             var sm = this.getPrefix(subnet,prefix);
             return this.__IPv4(ip,sm[0],sm[1]);
       },
       __IPv4: function (ip, subnet, prefix) {
             if (this.isIPv4(ip) && this.isIPv4(subnet) && (prefix && !isNaN(prefix))) {
                return ((this.toInt(ip)&-1<<(32-prefix)) == this.toInt(subnet));
             };
             return false;
       },
       isIPv4: function (ip) {
             return /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$/.test(ip);
       },
       IPv6: function (ip, subnet, prefix) {
             var sm = this.getPrefix(subnet,prefix);
             return this.__IPv6(ip,sm[0],sm[1]);
       },
       __IPv6: function (ip, subnet, prefix) {
             if (this.isIPv6(ip) && this.isIPv6(subnet) && (prefix && !isNaN(prefix))) {
                var o = Array.apply(null,Array(Math.floor(prefix/16))).map(function(_){ return 0xffff; });
                if (prefix%16) {
                   o.push((1<<prefix%16)-1);
                };
                var mask = o.concat(Array.apply(null,Array(8-o.length)).map(function(_){ return 0; }));
                ip = this.toInt(ip,6), subnet = this.toInt(subnet,6);
                return mask.every(function(m,n){ return (ip[n]&m) == (subnet[n]&m) });
             };
             return false;
       },
       isIPv6: function (ip) {
             return !!(this.Expand(ip));
       },
       __isIPv6: function (ip) {
             return /^([0-9a-f]{4}|0)(\:([0-9a-f]{4}|0)){7}$/i.test(ip);
       },
       isIP: function (ip) {
             return (this.isIPv4(ip)||this.isIPv6(ip));
       },
       Validate: function (ip) {
              if (this.subnets && this.isIP(ip) && (!!(this.subnets.ipv4.length)||!!(this.subnets.ipv6.length))) {
                 var subs = this.subnets[(this.isIPv4(ip)?"ipv4":"ipv6")];
                 for (var num in subs) {
                     if (this.Auto(ip,subs[num])) {
                        return true;
                     };
                 };
              };
              return false;
       },
       setSubnets: function (subnets) {
             this.subnets = {ipv4:[],ipv6:[]};
             if (Array.isArray(subnets)) {
                for (var num in subnets) {
                    var subnet = subnets[num];
                    if (/\/(\d+){1,3}$/.test(subnet)) {
                       if (this.isIPv4(subnet.split('/')[0])) {
                          this.subnets.ipv4.push(subnet);
                        } else if (this.isIPv6(subnet.split('/')[0])) {
                          this.subnets.ipv6.push(subnet);
                       };
                    };
                };
                return (!!(this.subnets.ipv4.length)||!!(this.subnets.ipv6.length));
             };
             return false;
       },
       getPrefix: function (subnet, prefix) {
             if (/\/(\d+){1,3}$/.test(subnet)) {
                try {
                   var split = subnet.split('/');
                       subnet = split[0],
                       prefix = split[1];
                } catch (e) { }; // Handle the error!?
             };
             return [subnet,prefix];
       },
       toInt: function (ip,mode) {
             switch (mode) {
                    case 6:
                         return this.Expand(ip).split(":").map(function(x){return parseInt(x,16)});
                    case 4:
                    default:
                         return ((ip=ip.split('.'))[0]<<24|ip[1]<<16|ip[2]<<8|ip[3]);
             };
       },
       Expand: function (ip) {
             var ip = String(ip);
             if (ip.indexOf("::") != -1) {
                if (ip.match(/::/g).length > 1) {
                   return false;
                };
                var split = ip.split("::"),
                    res = (split[0]+Array(9-(split[0].split(":").length+split[1].split(":").length)).join(':0000')+':'+split[1]).split(":");
             };
             var ip = (res||ip.split(":")).map(function (x) {
                 return (x.length<4?(new Array(5-x.length).join('0')+x):x);
             }).join(":");
             return (this.__isIPv6(ip)?ip:false);
       },
   };
   return Object.create(proto);
},"inSubnet");

/*
  Need to make this better. Should check more than just
  exports and window as that can be set by anything.
*/
function Exporter (fn,plug) {
         // This just seems silly... There HAS to be a better way!
         var isNode = (typeof process==='object' && process.toString()==='[object process]' && typeof exports!=='undefined');

         // This also seems like there should be a better way...
         if (isNode) {
            module.exports = fn(isNode);
          } else {
            window[plug] = fn(isNode);
         };
};
<commit_msg>Woops, fix a bug.<commit_after>/*
  inSubnet - By Louis T. <louist@ltdev.im>
  Check an IP(v4 or v6) against a subnet.
*/
Exporter(function (isNode) {
   var proto = {
       version: '0.0.3',
       Auto: function (ip, subnet, prefix) {
             if (!ip || !subnet) {
                return false;
             };
             var sm = this.getPrefix(subnet,prefix);
             if (sm[0] && sm[1] && !isNaN(sm[1])) {
                if (this.isIPv4(ip)) {
                   return this.__IPv4(ip,sm[0],sm[1]);
                 } else {
                   return this.__IPv6(ip,sm[0],sm[1]);
                };
             };
             return false;
       },
       IPv4: function (ip, subnet, prefix) {
             var sm = this.getPrefix(subnet,prefix);
             return this.__IPv4(ip,sm[0],sm[1]);
       },
       __IPv4: function (ip, subnet, prefix) {
             if (this.isIPv4(ip) && this.isIPv4(subnet) && (prefix && !isNaN(prefix))) {
                return ((this.toInt(ip)&-1<<(32-prefix)) == this.toInt(subnet));
             };
             return false;
       },
       isIPv4: function (ip) {
             return /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$/.test(ip);
       },
       IPv6: function (ip, subnet, prefix) {
             var sm = this.getPrefix(subnet,prefix);
             return this.__IPv6(ip,sm[0],sm[1]);
       },
       __IPv6: function (ip, subnet, prefix) {
             if (this.isIPv6(ip) && this.isIPv6(subnet) && (prefix && !isNaN(prefix))) {
                var o = Array.apply(null,Array(Math.floor(prefix/16))).map(function(_){ return 0xffff; });
                if (prefix%16) {
                   o.push((1<<prefix%16)-1);
                };
                var mask = o.concat(Array.apply(null,Array(8-o.length)).map(function(_){ return 0; }));
                ip = this.toInt(ip,6), subnet = this.toInt(subnet,6);
                return mask.every(function(m,n){ return (ip[n]&m) == (subnet[n]&m) });
             };
             return false;
       },
       isIPv6: function (ip) {
             return !!(this.Expand(ip));
       },
       __isIPv6: function (ip) {
             return /^([0-9a-f]{4}|0)(\:([0-9a-f]{4}|0)){7}$/i.test(ip);
       },
       isIP: function (ip) {
             return (this.isIPv4(ip)||this.isIPv6(ip));
       },
       Validate: function (ip) {
              if (this.subnets && this.isIP(ip) && (!!(this.subnets[this.isIPv4(ip)?"ipv4":"ipv6"].length))) {
                 var subs = this.subnets[(this.isIPv4(ip)?"ipv4":"ipv6")];
                 for (var num in subs) {
                     if (this.Auto(ip,subs[num])) {
                        return true;
                     };
                 };
              };
              return false;
       },
       setSubnets: function (subnets) {
             this.subnets = {ipv4:[],ipv6:[]};
             if (Array.isArray(subnets)) {
                for (var num in subnets) {
                    var subnet = subnets[num];
                    if (/\/(\d+){1,3}$/.test(subnet)) {
                       if (this.isIPv4(subnet.split('/')[0])) {
                          this.subnets.ipv4.push(subnet);
                        } else if (this.isIPv6(subnet.split('/')[0])) {
                          this.subnets.ipv6.push(subnet);
                       };
                    };
                };
                return (!!(this.subnets.ipv4.length)||!!(this.subnets.ipv6.length));
             };
             return false;
       },
       getPrefix: function (subnet, prefix) {
             if (/\/(\d+){1,3}$/.test(subnet)) {
                try {
                   var split = subnet.split('/');
                       subnet = split[0],
                       prefix = split[1];
                } catch (e) { }; // Handle the error!?
             };
             return [subnet,prefix];
       },
       toInt: function (ip,mode) {
             switch (mode) {
                    case 6:
                         return this.Expand(ip).split(":").map(function(x){return parseInt(x,16)});
                    case 4:
                    default:
                         return ((ip=ip.split('.'))[0]<<24|ip[1]<<16|ip[2]<<8|ip[3]);
             };
       },
       Expand: function (ip) {
             var ip = String(ip);
             if (ip.indexOf("::") != -1) {
                if (ip.match(/::/g).length > 1) {
                   return false;
                };
                var split = ip.split("::"),
                    res = (split[0]+Array(9-(split[0].split(":").length+split[1].split(":").length)).join(':0000')+':'+split[1]).split(":");
             };
             var ip = (res||ip.split(":")).map(function (x) {
                 return (x.length<4?(new Array(5-x.length).join('0')+x):x);
             }).join(":");
             return (this.__isIPv6(ip)?ip:false);
       },
   };
   return Object.create(proto);
},"inSubnet");

/*
  Need to make this better. Should check more than just
  exports and window as that can be set by anything.
*/
function Exporter (fn,plug) {
         // This just seems silly... There HAS to be a better way!
         var isNode = (typeof process==='object' && process.toString()==='[object process]' && typeof exports!=='undefined');

         // This also seems like there should be a better way...
         if (isNode) {
            module.exports = fn(isNode);
          } else {
            window[plug] = fn(isNode);
         };
};
<|endoftext|>


<commit_before>/* jshint node: true */
'use strict';
var config = require('./config.webgme'),
    validateConfig = require('webgme/config/validator');

// Overwrite options as needed
config.server.port = 8080;
//config.mongo.uri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/cnn-creator';

// Authentication
config.authentication.enable = true;
config.authentication.allowGuests = true;
config.authentication.logOutUrl = '/login';

// Executors
config.executor.enable = true;

config.core.enableCustomConstraints = true;

// Plugins
config.plugin.allowServerExecution = true;
//config.plugin.allowBrowserExecution = false;

// Seeds
config.seedProjects.enable = true;
config.seedProjects.basePaths = ["./src/seeds"]

config.requirejsPaths.rosmod = "./src/common/"

// Default Project
config.client.defaultProject = { name: 'ROSMOD+IntroductionToROSMOD' };

config.client.log.level = 'info';

config.visualization.svgDirs = ["./src/svgs"]

validateConfig(config);
module.exports = config;
<commit_msg>fixed login<commit_after>/* jshint node: true */
'use strict';
var config = require('./config.webgme'),
    validateConfig = require('webgme/config/validator');

// Overwrite options as needed
config.server.port = 8080;
//config.mongo.uri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/cnn-creator';

// Authentication
config.authentication.enable = true;
config.authentication.allowGuests = true;
//config.authentication.logOutUrl = '/login';

// Executors
config.executor.enable = true;

config.core.enableCustomConstraints = true;

// Plugins
config.plugin.allowServerExecution = true;
//config.plugin.allowBrowserExecution = false;

// Seeds
config.seedProjects.enable = true;
config.seedProjects.basePaths = ["./src/seeds"]

config.requirejsPaths.rosmod = "./src/common/"

// Default Project
config.client.defaultProject = { name: 'ROSMOD+IntroductionToROSMOD' };

config.client.log.level = 'info';

config.visualization.svgDirs = ["./src/svgs"]

validateConfig(config);
module.exports = config;
<|endoftext|>


<commit_before>var config = {}

config.db = "";

module.exports = config;
<commit_msg>S E M I C O L O N<commit_after>var config = {};

config.db = "";

module.exports = config;
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2012 Taye Adeyemi
 * Open source under the MIT License.
 * https://raw.github.com/biographer/interact.js/master/LICENSE
 */

/**
 * @namespace interact.js module
 * @name interact
 */
window.interact = (function () {
    'use strict';

    var prevX = 0,
        prevY = 0,
        x0 = 0,
        y0 = 0,
        interactNodes = [],
        nodeStyle,
        target = null,
        supportsTouch = 'createTouch' in document,
        margin = supportsTouch ? 30 : 10,
        mouseIsDown = false,
        dragging = false,
        resizing = false,
        resizeAxes = 'xy',
        actions = {
            resizex: {
                cursor: 'e-resize',
                ready: function () {
                    resizeAxes = 'x';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizex');
                },
                start: function() {}
            },
            resizey: {
                cursor: 's-resize',
                ready: function () {
                    resizeAxes = 'y';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizey');
                }
            },
            resizexy: {
                cursor: 'se-resize',
                ready: function () {
                    resizeAxes = 'xy';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizexy');
                }
            },
            drag: {
                cursor: 'move',
                ready: function () {
                    events.add(docTarget, moveEvent, dragMove);
                    addClass(target.element, 'interact-target interact-dragging');
                }
            }
        },
        downEvent,
        upEvent,
        moveEvent,
        eventDict = {
            interactresizestart: 'resizestart',
            interactresizemove: 'resizemove',
            interactresizeend: 'resizeend',
            interactdragstart: 'dragstart',
            interactdragmove: 'dragmove',
            interactdragend: 'dragend'
        },
        docTarget = {
            element: document,
            events: {}
        },
        windowTarget = {
            element: window,
            events: {}
        },
        // interact events wrapper
        events = {};

        events.add = function (target, type, listener, useCapture) {
            if (typeof target.events !== 'object') {
                target.events = {};
            }

            if (typeof target.events[type] !== 'array') {
                target.events[type] = [];
            }

            target.events[type].push(listener);

            return target.element.addEventListener(type, listener, useCapture || false);
        };

        events.remove = function (target, type, listener, useCapture) {
            var i;

            if (target && target.events && target.events[type]) {

                if (listener === 'all') {
                    for (i = 0; i < target.events[type].length; i++) {
                        target.element.removeEventListener(type, target.events[type][i], useCapture || false);
                        target.events[type].splice(i, 1);
                    }
                } else {
                    for (i = 0; i < target.events[type].length; i++) {
                        if (target.events[type][i] === listener) {
                            target.element.removeEventListener(type, target.events[type][i], useCapture || false);
                            target.events[type].splice(i, 1);
                        }
                    }
                }
            }
        };

        events.removeAll = function (target) {
            var type;

            for (type in target.events) {
                if (target.events.hasOwnProperty(type)) {
                    events.remove(target, type, 'all');
                }
            }
        };

    // Should change this so devices with mouse and touch can use either/both
    if (supportsTouch) {
        downEvent = 'touchstart',
        upEvent = 'touchend',
        moveEvent = 'touchmove';
    } else {
        downEvent = 'mousedown',
        upEvent = 'mouseup',
        moveEvent = 'mousemove';
    }

    /**
     * @private
     * @event
     */
    function resizeMove(event) {
        var detail,
            resizeEvent;

        if (!resizing) {
            resizeEvent = document.createEvent('CustomEvent');
            detail = {
                axes: resizeAxes,
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (event.pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (event.pageY - y0): 0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            resizeEvent.initCustomEvent('interactresizestart', true, true, detail);
            target.element.dispatchEvent(resizeEvent);
            addClass(target.element, 'interact-resize-target');
            resizing = true;
        } else {
            resizeEvent = document.createEvent('CustomEvent');
            detail = {
                axes: resizeAxes,
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (event.pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (event.pageY - y0): 0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            resizeEvent.initCustomEvent('interactresizemove', true, true, detail);
            target.element.dispatchEvent(resizeEvent);
        }
        prevX = event.pageX;
        prevY = event.pageY;
    }

    /**
     * @private
     * @event
     */
    function dragMove(event) {
        var detail,
            dragEvent;

        if (!dragging) {
            dragEvent = document.createEvent('CustomEvent');
            detail = {
                x0: x0,
                y0: y0,
                dx: event.pageX - x0,
                dy: event.pageY - y0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            dragEvent.initCustomEvent('interactdragstart', true, true, detail);
            target.element.dispatchEvent(dragEvent);
            dragging = true;
        } else {
            dragEvent = document.createEvent('CustomEvent');
            detail = {
                x0: x0,
                y0: y0,
                dx: event.pageX - x0,
                dy: event.pageY - y0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            dragEvent.initCustomEvent('interactdragmove', true, true, detail);
            target.element.dispatchEvent(dragEvent);
        }

        prevX = event.pageX;
        prevY = event.pageY;
    }

    function autoCheck(event) {
        var clientRect = target.element.getClientRects()[0],
            action,
            right = ((event.pageX - window.scrollX - clientRect.left) > (clientRect.width - margin)),
            bottom = ((event.pageY - window.scrollY - clientRect.top) > (clientRect.height - margin));

        resizeAxes = (right?'x': '') + (bottom?'y': '');
        action = (resizeAxes && target.resize)? 'resize' + resizeAxes:
            (target.drag)? 'drag': '';

        return action;
    }

    /**
     * @private
     * @event
     */
    function mouseMove(event) {
        var right,
            bottom,
            axes,
            action;

        if (!mouseIsDown && (target = getInteractNode(event.target))) {
            if (target.resize) {
                removeClass(target.element, 'interact-resizexy interact-resizex interact-resizey');

                action = target.getAction(event);

                target.element.style.cursor = actions[action].cursor;
            } else if (dragging || resizing) {
                event.preventDefault();
            }
        }
    }

    /**
     * @private
     * @event
     */
    function mouseDown(event) {
        var right,
            bottom,
            action = '';

        mouseIsDown = true;
        if ((target = getInteractNode(event.currentTarget))) {
            event.preventDefault();

            if (target.drag || target.resize) {
                x0 = prevX = event.pageX;
                y0 = prevY = event.pageY;
                events.remove(docTarget, moveEvent, 'all');
            }
            action = target.getAction(event);

            document.documentElement.style.cursor = target.element.style.cursor = actions[action].cursor;
            actions[action].ready();
        }
    }

    /**
     * @private
     * @event
     */
    function docMouseUp (event) {
        var detail,
            pageX,
            pageY,
            endEvent;

        if (dragging) {
            endEvent = document.createEvent('CustomEvent');

            pageX = prevX;
            pageY = prevY;
            detail = {
                x0: x0,
                y0: y0,
                dx: pageX - x0,
                dy: pageY - y0,
                pageX: pageX,
                pageY: pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            endEvent.initCustomEvent('interactdragend', true, true, detail);
            target.element.dispatchEvent(endEvent);
            dragging = false;
        }

        if (resizing) {
            endEvent = document.createEvent('CustomEvent');

            pageX = prevX;
            pageY = prevY;
            detail = {
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (pageY - y0): 0,
                pageX: pageX,
                pageY: pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            endEvent.initCustomEvent('interactresizeend', true, true, detail);
            target.element.dispatchEvent(endEvent);
            resizing = false;
        }

        // Add and remove appropriate events
        events.remove(docTarget, moveEvent, resizeMove);
        events.remove(docTarget, moveEvent, dragMove);
        events.add(docTarget, moveEvent, mouseMove);

        document.documentElement.style.cursor = '';
        mouseIsDown = false;
        clearTarget();
    }

    /** @private */
    function getInteractNode(element, option) {
        var i;

        for(i=0; i < interactNodes.length; i++) {
            if (interactNodes[i].element === element) {
                if(option === 'test') {
                    return true;
                } else {
                    return interactNodes[i];
                }
            }
        }
        return null;
    }

    /** @private */
    function addClass(element, classNames) {
        var i;

        if (!element.classList) {
            return false;
        }

        classNames = classNames.split(' ');
        for (i = 0; i < classNames.length; i++) {
            element.classList.add(classNames[i]);
        }
    }

    /** @private */
    function removeClass(element, classNames) {
        var i;

        if (!element.classList) {
            return false;
        }

        classNames = classNames.split(' ');
        for (i = 0; i < classNames.length; i++) {
            element.classList.remove(classNames[i]);
        }
    }

    /** @private */
    function clearTarget() {
        if (target) {
            removeClass(target.element, 'interact-target interact-dragging interact-resizing interact-resizexy interact-resizex interact-resizexy');
        }
        target = null;
    }

    /**
     * @global
     * @name interact
     * @description Global interact object
     */
    function interact(element) {
        if (typeof element === 'string') {
            element = document.getElementById(element);
        }
        return getInteractNode(element);
    }

    /**
     * @function
     * @description Add an element to the list of interact nodes
     * @param {object HTMLElement} element The DOM Element that will be added
     * @param {object} options An object whose properties are the drag/resize options
     */
    interact.set = function (element, options) {
        var nodeAlreadySet = getInteractNode(element, 'test'),
            i = 0,
            newNode;

        if (typeof options !== 'object') {
            options = {};
        }

        newNode = {
            element: element,
            drag: ('drag' in options)? options.drag : false,
            resize: ('resize' in options)? options.resize : false,
            getAction: (typeof options.actionChecker === 'function')? options.actionChecker: autoCheck
        };

        if (nodeAlreadySet) {
            interactNodes[i] = newNode;
        } else {
            events.add(newNode, downEvent, mouseDown, false);
            interactNodes.push(newNode);
        }

        addClass(element, 'interact-node' + (newNode.resize? ' interact-resizeable': '') + (newNode.drag? ' interact-dragable': ''));
    };

    /**
     * @function
     * @description Remove an element from the list of interact nodes
     * @param {object HTMLElement} element The DOM Element that will be removed
     */
    interact.unset = function (element) {
        var i;

        for (i = 0; i < interactNodes.length; i++) {
            if (interactNodes[i].element === element) {
                interactNodes.splice(i, 1);
                events.removeAll(interactNodes[i]);
            }
        }

        removeClass(element, 'interact-node interact-target interact-dragging interact-draggable interact-resizeable interact-resize-xy interact-resize-x interact-resize-y');
    };

    /**
     * @function
     * @description Check if an element has been set
     * @param {object HTMLElement} element The DOM Element that will be searched for
     * @returns bool
     */
    interact.isSet = function(element) {
        var i;

        for(i = 0; i < interactNodes.length; i++) {
            if (interactNodes[i].element === element) {
                return true;
            }
        }
        return false;
    };

    /**
     * @function
     * @description
     * @param {string} [type] Event type to be searched for
     * @returns {string} The name of the custom interact event
     * @returns OR
     * @returns {object} An object linking event types to string values
     */
    interact.eventDict = function (type) {
        if (arguments.length === 0) {
            return eventDict;
        }

        return eventDict[type];
    };

    /**
     * @function
     * @description Displays debugging data in the browser console
     */
    interact.debug = function () {
        console.log('target         :  ' + target);
        console.log('prevX, prevY   :  ' + prevX + ', ' + prevY);
        console.log('x0, y0         :  ' + x0 + ', ' + y0);
        console.log('supportsTouch  :  ' + supportsTouch);
        console.log('mouseIsDown    :  ' + mouseIsDown);

        return {
            target: target,
            prevX: prevX,
            prevY: prevY,
            startX: x0,
            startY: y0,
            nodes: interactNodes,
            mouseIsDown: mouseIsDown,
            supportsTouch: supportsTouch
        };
    };
    interact.removeClass = removeClass;

    events.add(docTarget, upEvent, docMouseUp);
    events.add(windowTarget, 'blur' , docMouseUp);
    events.add(docTarget, moveEvent, mouseMove, 'true');

    return interact;
}());

<commit_msg>set now handles resetting an element correctly; gave interactNodes indexOf(element) method; autoCheck works with SVG<commit_after>/*
 * Copyright (c) 2012 Taye Adeyemi
 * Open source under the MIT License.
 * https://raw.github.com/biographer/interact.js/master/LICENSE
 */

/**
 * @namespace interact.js module
 * @name interact
 */
window.interact = (function () {
    'use strict';

    var prevX = 0,
        prevY = 0,
        x0 = 0,
        y0 = 0,
        interactNodes = [],
        svgTags = {
            g: 'g',
            rect: 'rect',
            circle: 'circle',
            ellipse: 'ellipse',
            text: 'text',
            path: 'path',
            line: 'line',
            image: 'image'
        },
        target = null,
        supportsTouch = 'createTouch' in document,
        margin = supportsTouch ? 30 : 10,
        mouseIsDown = false,
        dragging = false,
        resizing = false,
        resizeAxes = 'xy',
        actions = {
            resizex: {
                cursor: 'e-resize',
                ready: function () {
                    if (!target.resize) {
                        return false;
                    }
                    resizeAxes = 'x';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizex');
                },
                start: function() {}
            },
            resizey: {
                cursor: 's-resize',
                ready: function () {
                    if (!target.resize) {
                        return false;
                    }
                    resizeAxes = 'y';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizey');
                }
            },
            resizexy: {
                cursor: 'se-resize',
                ready: function () {
                    if (!target.resize) {
                        return false;
                    }
                    resizeAxes = 'xy';
                    events.add(docTarget, moveEvent, resizeMove);
                    addClass(target.element, 'interact-target interact-resizexy');
                }
            },
            drag: {
                cursor: 'move',
                ready: function () {
                    if (!target.drag) {
                        return false;
                    }
                    events.add(docTarget, moveEvent, dragMove);
                    addClass(target.element, 'interact-target interact-dragging');
                }
            }
        },
        downEvent,
        upEvent,
        moveEvent,
        eventDict = {
            interactresizestart: 'resizestart',
            interactresizemove: 'resizemove',
            interactresizeend: 'resizeend',
            interactdragstart: 'dragstart',
            interactdragmove: 'dragmove',
            interactdragend: 'dragend'
        },
        docTarget = {
            element: document,
            events: {}
        },
        windowTarget = {
            element: window,
            events: {}
        },
        // interact events wrapper
        events = {};

        events.add = function (target, type, listener, useCapture) {
            if (typeof target.events !== 'object') {
                target.events = {};
            }

            if (typeof target.events[type] !== 'array') {
                target.events[type] = [];
            }

            target.events[type].push(listener);

            return target.element.addEventListener(type, listener, useCapture || false);
        };

        events.remove = function (target, type, listener, useCapture) {
            var i;

            if (target && target.events && target.events[type]) {

                if (listener === 'all') {
                    for (i = 0; i < target.events[type].length; i++) {
                        target.element.removeEventListener(type, target.events[type][i], useCapture || false);
                        target.events[type].splice(i, 1);
                    }
                } else {
                    for (i = 0; i < target.events[type].length; i++) {
                        if (target.events[type][i] === listener) {
                            target.element.removeEventListener(type, target.events[type][i], useCapture || false);
                            target.events[type].splice(i, 1);
                        }
                    }
                }
            }
        };

        events.removeAll = function (target) {
            var type;

            for (type in target.events) {
                if (target.events.hasOwnProperty(type)) {
                    events.remove(target, type, 'all');
                }
            }
        };

    // Should change this so devices with mouse and touch can use either/both
    if (supportsTouch) {
        downEvent = 'touchstart',
        upEvent = 'touchend',
        moveEvent = 'touchmove';
    } else {
        downEvent = 'mousedown',
        upEvent = 'mouseup',
        moveEvent = 'mousemove';
    }

    /**
     * @private
     * @event
     */
    function resizeMove(event) {
        var detail,
            resizeEvent;

        if (!resizing) {
            resizeEvent = document.createEvent('CustomEvent');
            detail = {
                axes: resizeAxes,
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (event.pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (event.pageY - y0): 0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            resizeEvent.initCustomEvent('interactresizestart', true, true, detail);
            target.element.dispatchEvent(resizeEvent);
            addClass(target.element, 'interact-resize-target');
            resizing = true;
        } else {
            resizeEvent = document.createEvent('CustomEvent');
            detail = {
                axes: resizeAxes,
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (event.pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (event.pageY - y0): 0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            resizeEvent.initCustomEvent('interactresizemove', true, true, detail);
            target.element.dispatchEvent(resizeEvent);
        }
        prevX = event.pageX;
        prevY = event.pageY;
    }

    /**
     * @private
     * @event
     */
    function dragMove(event) {
        var detail,
            dragEvent;

        if (!dragging) {
            dragEvent = document.createEvent('CustomEvent');
            detail = {
                x0: x0,
                y0: y0,
                dx: event.pageX - x0,
                dy: event.pageY - y0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            dragEvent.initCustomEvent('interactdragstart', true, true, detail);
            target.element.dispatchEvent(dragEvent);
            dragging = true;
        } else {
            dragEvent = document.createEvent('CustomEvent');
            detail = {
                x0: x0,
                y0: y0,
                dx: event.pageX - x0,
                dy: event.pageY - y0,
                pageX: event.pageX,
                pageY: event.pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            dragEvent.initCustomEvent('interactdragmove', true, true, detail);
            target.element.dispatchEvent(dragEvent);
        }

        prevX = event.pageX;
        prevY = event.pageY;
    }

    function autoCheck(event) {
        var clientRect,
            right,
            bottom,
            action;

        if (target.element.nodeName in svgTags) {
            clientRect = target.element.getBoundingClientRect();
            right = ((event.pageX - window.scrollX - clientRect.left) > (clientRect.width - margin));
            bottom = ((event.pageY - window.scrollY - clientRect.top) > (clientRect.height - margin));
            resizeAxes = (right?'x': '') + (bottom?'y': '');
            action = (resizeAxes && target.resize)?
                'resize' + resizeAxes:
                'drag';

            return action;
        }

        clientRect = target.element.getClientRects()[0];
        action,
        right = ((event.pageX - window.scrollX - clientRect.left) > (clientRect.width - margin));
        bottom = ((event.pageY - window.scrollY - clientRect.top) > (clientRect.height - margin));

        resizeAxes = (right?'x': '') + (bottom?'y': '');
        action = (resizeAxes && target.resize)?
            'resize' + resizeAxes:
            'drag';

        return action;
    }

    /**
     * @private
     * @event
     */
    function mouseMove(event) {
        var right,
            bottom,
            axes,
            action;

        if (!mouseIsDown && (target = getInteractNode(event.target))) {
            if (target.resize) {
                removeClass(target.element, 'interact-resizexy interact-resizex interact-resizey');

                action = target.getAction(event);

                target.element.style.cursor = actions[action].cursor;
            } else if (dragging || resizing) {
                event.preventDefault();
            }
        }
    }

    /**
     * @private
     * @event
     */
    function mouseDown(event) {
        var right,
            bottom,
            action = '';

        mouseIsDown = true;
        if ((target = getInteractNode(event.currentTarget))) {
            event.preventDefault();

            if (target.drag || target.resize) {
                x0 = prevX = event.pageX;
                y0 = prevY = event.pageY;
                events.remove(docTarget, moveEvent, 'all');
            }
            action = target.getAction(event);

            document.documentElement.style.cursor = target.element.style.cursor = actions[action].cursor;
            actions[action].ready();
        }
    }

    /**
     * @private
     * @event
     */
    function docMouseUp (event) {
        var detail,
            pageX,
            pageY,
            endEvent;

        if (dragging) {
            endEvent = document.createEvent('CustomEvent');

            pageX = prevX;
            pageY = prevY;
            detail = {
                x0: x0,
                y0: y0,
                dx: pageX - x0,
                dy: pageY - y0,
                pageX: pageX,
                pageY: pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            endEvent.initCustomEvent('interactdragend', true, true, detail);
            target.element.dispatchEvent(endEvent);
            dragging = false;
        }

        if (resizing) {
            endEvent = document.createEvent('CustomEvent');

            pageX = prevX;
            pageY = prevY;
            detail = {
                x0: x0,
                y0: y0,
                dx: (resizeAxes === 'xy' || resizeAxes === 'x')? (pageX - x0): 0,
                dy: (resizeAxes === 'xy' || resizeAxes === 'y')? (pageY - y0): 0,
                pageX: pageX,
                pageY: pageY,
                ctrlKey: event.ctrlKey,
                altKey: event.altKey,
                shiftKey: event.shiftKey,
                metaKey: event.metaKey,
                button: event.button
            };
            endEvent.initCustomEvent('interactresizeend', true, true, detail);
            target.element.dispatchEvent(endEvent);
            resizing = false;
        }

        // Add and remove appropriate events
        events.remove(docTarget, moveEvent, resizeMove);
        events.remove(docTarget, moveEvent, dragMove);
        events.add(docTarget, moveEvent, mouseMove);

        document.documentElement.style.cursor = '';
        mouseIsDown = false;
        clearTarget();
    }

    /** @private */
    interactNodes.indexOf = function (element) {
        var i;

        for (i = 0; i < interactNodes.length; i++) {
            if (interactNodes[i].element === element) {
                return i;
            }
        }
        return -1;
    }

    /** @private */
    function getInteractNode(element) {
        var i = interactNodes.indexOf(element) ;

        return interactNodes[i];
    }

    /** @private */
    function addClass(element, classNames) {
        var i;

        if (!element.classList) {
            return false;
        }

        classNames = classNames.split(' ');
        for (i = 0; i < classNames.length; i++) {
            element.classList.add(classNames[i]);
        }
    }

    /** @private */
    function removeClass(element, classNames) {
        var i;

        if (!element.classList) {
            return false;
        }

        classNames = classNames.split(' ');
        for (i = 0; i < classNames.length; i++) {
            element.classList.remove(classNames[i]);
        }
    }

    /** @private */
    function clearTarget() {
        if (target) {
            removeClass(target.element, 'interact-target interact-dragging interact-resizing interact-resizexy interact-resizex interact-resizexy');
        }
        target = null;
    }

    /**
     * @global
     * @name interact
     * @description Global interact object
     */
    function interact(element) {
        if (typeof element === 'string') {
            element = document.getElementById(element);
        }
        return getInteractNode(element);
    }

    /**
     * @function
     * @description Add an element to the list of interact nodes
     * @param {object HTMLElement} {object SVGElement} element The DOM Element that will be added
     * @param {object} options An object whose properties are the drag/resize options
     */
    interact.set = function (element, options) {
        var indexOfElement = interactNodes.indexOf(element),
            newNode;

        if (typeof options !== 'object') {
            options = {};
        }

        newNode = {
            element: element,
            drag: ('drag' in options)? options.drag : false,
            resize: ('resize' in options)? options.resize : false,
            getAction: (typeof options.actionChecker === 'function')? options.actionChecker: autoCheck
        };

        if (indexOfElement !== -1) {
            interactNodes[indexOfElement] = newNode;
        } else {
            events.add(newNode, downEvent, mouseDown, false);
            interactNodes.push(newNode);
        }

        addClass(element, 'interact-node' + (newNode.resize? ' interact-resizeable': '') + (newNode.drag? ' interact-dragable': ''));
    };

    /**
     * @function
     * @description Remove an element from the list of interact nodes
     * @param {object HTMLElement} element The DOM Element that will be removed
     */
    interact.unset = function (element) {
        var i = interactNodes.indexOf(element);

        if (i !== -1) {
            events.removeAll(interactNodes[i]);
            interactNodes.splice(i, 1);
            removeClass(element, 'interact-node interact-target interact-dragging interact-draggable interact-resizeable interact-resize-xy interact-resize-x interact-resize-y');
        }

    };

    /**
     * @function
     * @description Check if an element has been set
     * @param {object HTMLElement} element The DOM Element that will be searched for
     * @returns bool
     */
    interact.isSet = function(element) {
        var i;

        return interactNodes.indexOf(element !== -1);
    };

    /**
     * @function
     * @description
     * @param {string} [type] Event type to be searched for
     * @returns {string} The name of the custom interact event
     * @returns OR
     * @returns {object} An object linking event types to string values
     */
    interact.eventDict = function (type) {
        if (arguments.length === 0) {
            return eventDict;
        }

        return eventDict[type];
    };

    /**
     * @function
     * @description Displays debugging data in the browser console
     */
    interact.debug = function () {
        console.log('target         :  ' + target);
        console.log('prevX, prevY   :  ' + prevX, prevY);
        console.log('x0, y0         :  ' + x0, y0);
        console.log('supportsTouch  :  ' + supportsTouch);
        console.log('mouseIsDown    :  ' + mouseIsDown);

        return {
            target: target,
            prevX: prevX,
            prevY: prevY,
            startX: x0,
            startY: y0,
            nodes: interactNodes,
            mouseIsDown: mouseIsDown,
            supportsTouch: supportsTouch
        };
    };
    interact.removeClass = removeClass;
    window.nodes = interactNodes;

    events.add(docTarget, upEvent, docMouseUp);
    events.add(windowTarget, 'blur' , docMouseUp);
    events.add(docTarget, moveEvent, mouseMove, 'true');

    return interact;
}());

<|endoftext|>


<commit_before>// Taye Adeyemi

/** @namespace */
window.interact = (function () {
	"use strict";

	var prevX = 0,
		prevY = 0,
		interactNodes = [],
		nodeStyle,
		target = null,
		supportsTouch = 'createTouch' in document,
		mouseIsDown = false,
		downEvent,
		upEvent,
		moveEvent,
		edgeWidth = supportsTouch? 30 : 10,
		typeErr = new TypeError('Type Error'),
		events = {
			add: function (target, type, listener, useCapture) {
				if (target.events === undefined) {
					target.events = [];
				}
				if (target.events[type] === undefined) {
					target.events[type] = [];
				}
				target.addEventListener(type, listener, useCapture || false);
				target.events[type].push(listener);
				return listener;
			},
			remove: function (target, type, listener, useCapture) {
				if (target && target.events && target.events[type]) {
					var i;
					if (listener === undefined) {
						for (i=0; i < target.events[type].length; i++) {
							target.removeEventListener(type, target.events[type][i], useCapture || false);
							target.events[type].splice(i, 1);
						}
					}
					else {
						for (i=0; i < target.events[type].length; i++) {
							if (target.events[type][i] === listener) {
								target.removeEventListener(type, listener, useCapture || false);
								target.events[type].splice(i, 1);
							}
						}
					}
				}
			}
		};

	/** @private */
	function xResize(event) {
		event.preventDefault();

		if (mouseIsDown && target.actions.resize) {
			addClass(target.element, 'interact-target');

			var x = event.pageX,
			newWidth = ( event.pageX > target.location.x)? target.width + (x - prevX) : 0 ;

			target.setSize(newWidth, target.height);
			prevX = x;
		}
	}

	/** @private */
	function yResize(event) {
		event.preventDefault();

		if (mouseIsDown && target.actions.resize) {
			addClass(target.element, 'interact-target');
			var y = event.pageY,
			newHeight = ( event.pageY > target.location.y)? target.height + (y - prevY) : 0 ;

			target.setSize(target.width, newHeight);
			prevY = y;
		}
	}

	/** @private */
	function xyResize(event) {
		event.preventDefault();

		if (mouseIsDown && target.actions.resize) {
			addClass(target.element, 'interact-target');
			var x = event.pageX, y = event.pageY,
			newWidth = ( event.pageX > target.location.x)? target.width + (x - prevX) : 0 ,
			newHeight = ( event.pageY > target.location.y)? target.height + (y - prevY) : 0 ;

			target.setSize(newWidth, newHeight);
			prevX = x;
			prevY = y;
		}
	}
	/* Should change this so devices with mouse and touch can use both */
	if (supportsTouch) {
		downEvent = 'touchstart',
		upEvent = 'touchend',
		moveEvent = 'touchmove';
	}
	else {
		downEvent = 'mousedown',
		upEvent = 'mouseup',
		moveEvent = 'mousemove';
	}

	/** @private */
	function docMouseUp (event) {
		console.log('target = ' + target);
		events.remove(document, moveEvent, xResize);
		events.remove(document, moveEvent, yResize);
		events.remove(document, moveEvent, xyResize);
		events.remove(document, moveEvent, interact.drag.xyDrag);

		mouseIsDown = false;
		clearTarget();
		events.add(document, moveEvent, mouseMove);
	}

	/** @private */
	function mouseMove(event) {
		if (event.target.actions && (event.target.actions.resize || event.target.actions.drag)) {
			var x = event.pageX,
				y = event.pageY,
				target = event.target.object,
				right = (x - target.location.x > target.width - edgeWidth),
				bottom = (y - target.location.y > target.height - edgeWidth);

			if (right) {
				target.element.style.cursor = bottom?'se-resize' : 'e-resize';
			}
			else {
				target.element.style.cursor = bottom?'s-resize' : target.actions.drag? 'pointer' : 'default';
			}
		}
	};

	/** @private */
	function mouseDown(event) {
		mouseIsDown = true;
		if (event.target.actions && (event.target.actions.resize || event.target.actions.drag)) {
			var	right,
				bottom;

				prevX = event.pageX;
				prevY = event.pageY;
				target = event.target.object;
				right = (prevX - target.location.x > target.width - edgeWidth),
				bottom = (prevY - target.location.y > target.height - edgeWidth);

			if (right) {
				event.preventDefault();

				events.remove(document, moveEvent);
				console.log('resizing on right');
				if (bottom) {
					events.add( document, moveEvent, xyResize );
				}
				else {
					events.add( document, moveEvent, xResize ) ;
				}
			}
			else if (bottom) {
				console.log('resizing on bottom');
				events.remove(document, moveEvent);
				events.add( document, moveEvent, yResize );
			}
			else if (target.actions.drag) {
				event.preventDefault();

				bringToFront(target.element);
				console.log('moving node');
				events.remove(document, moveEvent);
				events.add( document, moveEvent, interact.drag.xyDrag );
				target.element.style.cursor = 'move';
			}
		return false;
		}
	}

	/** @private */
	function give(parent, child) {
		return parent.appendChild(child);
	}

	/** @private */
	function make(tag, parent) {
		return parent?	parent.appendChild(document.createElement(tag)):
				parent.createElement(tag);
	}

	/** @private */
	function disown(element) {
		return element.parentElement.removeChild(element);
	}

	/** @private */
	function removeClass(element, className) {
		element.className =
			element.className.replace( new RegExp( '(?:^|\\s)' + className + '(?!\\S)' ) , '' );
	}

	/** @private */
	function addClass(element, className) {
		if (!element.className.match( new RegExp( '(?:^|\\s)' + className + '(?!\\S)' ))) {
			element.className += ' ' + className;
		}
	}

	/**
	 * @class Vector Class for locations and dimensions
	 * @param {number} x Value of X ordinate
	 * @param {number} y Value of Y ordinate
	 */
	function Vector(x, y) {
		this.x = x || 0;
		this.y = y || 0;
	}

	Vector.prototype.set = function (x, y) {
		this.x = x;
		this.y = y || x;
	};

	Vector.prototype.setX = function (x) {
		this.x = x;
	};

	Vector.prototype.setY = function (y) {
		this.y = y;
	};

	Vector.prototype.copy = function (other) {
		if (!other.x && other.y) {
			return;
		}
		this.x = other.x;
		this.y = other.y;
	};

	/**
	 * @class Node for demonstrating interact functionality
	 * @param {number} x Horizontal position
	 * @param {number} y Vertical position
	 * @param {number} w Element width
	 * @param {number} h Element height
	 */
	function demoNode(x, y, w, h) {
		this.location = new Vector(x, y);
		this.width = w || 0;
		this.height = h || 0;
		this.actions = {resize: true, drag: true};

		this.element = document.createElement('div');
		this.element.actions = this.actions;
		this.element.object = this;

		this.element.style.setProperty('width', this.width + 'px', '');
		this.element.style.setProperty('height', this.height + 'px', '');
		this.element.style.setProperty('left', x + 'px', '');
		this.element.style.setProperty('top', y + 'px', '');
		this.element.className += ' interact-node ';

		if (!nodeStyle) {
			nodeStyle = document.createElement('style');
			nodeStyle.type = 'text/css';
			nodeStyle.innerHTML =' .interact-node { background-color:#2288FF; border:5px solid #333333; border-radius:10px; cursor:move; position:absolute; width:100px; height: 100px}';
			nodeStyle.innerHTML +=' .interact-node:hover { border-color: #AAAAAA; }';
			nodeStyle.innerHTML +=' .interact-target { border-style: dashed; }';
			document.body.appendChild(nodeStyle);
		}
	}

	demoNode.prototype.setSize = function (x, y) {
		if (x && x.constructor.name == 'Vector') {
			this.width =  x.x;
			this.height =  x.y;
		}
		else {
			if (x == null || y == null) {
				typeErr.name = 'Incorrect parameter types';
				typeErr.message = 'demoNode.setSize Parameters must be a single Vector or two numbers.';
				throw (typeErr);
			}
			this.width = x;
			this.height = y;
		}
		this.element.style.setProperty('width', Math.max(x, 20) + 'px', '');
		this.element.style.setProperty('height', Math.max(y, 20) + 'px', '');
	};

	demoNode.prototype.position = function (x, y) {
		if (x === undefined || y === undefined) {
			return;
		}

		this.location.set(x, y);
		this.element.style.setProperty('left', x + 'px', '');
		this.element.style.setProperty('top', y + 'px', '');
	};

	/** @private */
	function bringToFront(element) {
		// Very lazy
		var parent = element.parentElement;
		give(parent, disown(element));
	}

	/** @private */
	function clearTarget() {
		if (target) {
			removeClass(target.element, 'interact-target');
		}
		target = null;
	}

	/**
	 * @name interact
	 *
	 */
	var interact = {};
	interact.nodes = [];

	/**
	 * @function
	 * @memberOf interact
	 * @description Display debugging data in the browser console
	 */
	interact.debug = function () {
		console.log('target   : ' + target);
		console.log('prevX    : ' + prevX);
		console.log('prevY    : ' + prevY);
		throw (typeErr);
	}

	/**
	 * @function
	 * @description Add an element to the list of interact nodes
	 * @param {object HTMLElement} element The DOM Element that will be added
	 * @param {object} options An object with boolean properties
	 */
	interact.set = function (element, options) {
		var	newNode = {
				element: element,
				drag: options.drag || false,
				resize: options.resize || false,
				parent: options.parent || false
			};
		addClass('interact-node');
		interactNodes.push(newNode);

		// different things to be done for normal nodes and graphics nodes
	};

	/**
	 * @function
	 * @description Remove an element from the list of interact nodes
	 * @param {object HTMLElement} element The DOM Element that will be removed
	 */
	interact.unset = function (element) {
		var i;
		for (i = 0; i < interactNodes.length; i++) {
			if (interactNodes[i].element === element) {
				interactNodes.splice(i-1, 1);
			}
		}
	};

	/**
	 * @description Contains drag functions
	 */
	interact.drag = {
		xyDrag: function (event) {
			event.preventDefault();
			if (mouseIsDown && target.actions.drag) {
				addClass(target.element, 'interact-target');
				var x = event.pageX,
					y = event.pageY;

				target.position(target.location.x + x - prevX , target.location.y + (y - prevY));
				prevX = x;
				prevY = y;
			}
		}
	};

	/**
	 * @function
	 * @description introduce random draggable, resizeable nodes to the document (for testing)
	 * @param {number} [n] The number of nodes to be added (default
	 * @param {object} options An object with boolean properties
	 */
	interact.randomNodes = function (n, parent) {
		n = n || 10;
		parent = parent || document.body;

		for (var i = 0; i < n; i++) {
			if (interact.nodes[i]!==undefined && interact.nodes[i].element.parentNode === parent) {
				var par = interact.nodes[i].element.parentNode;

				par.removeChild(interact.nodes[i].element);
				interact.nodes[i] = new demoNode(Math.random()*(window.screen.width - 20), Math.random()*(window.screen.height - 20), Math.random()* 200, Math.random()* 200);
				give(par, interact.nodes[interact].element);
			}
			else {
				interact.nodes.push(new demoNode(Math.random()*(window.screen.width - 20), Math.random()*(window.screen.height - 20), Math.random()* 200, Math.random()* 200));
				give(document.body, interact.nodes[i].element);
			}
		}
	};
	events.add( document, moveEvent, mouseMove);
	events.add( document, downEvent, mouseDown);
	events.add( document, 'dragenter', function (event) {event.preventDefault();});

	events.add(document, upEvent, docMouseUp);
	return interact;
}());

<commit_msg>JSDoced and fixed bug preventing resizing on one axis when the other value was too small<commit_after>// Taye Adeyemi

/**
 * @namespace interact.js module
 * @name interact
 */
window.interact = (function () {
	"use strict";

	var prevX = 0,
		prevY = 0,
		interactNodes = [],
		nodeStyle,
		target = null,
		supportsTouch = 'createTouch' in document,
		mouseIsDown = false,
		downEvent,
		upEvent,
		moveEvent,
		margin = supportsTouch ? 30 : 10,
		typeErr = new TypeError('Type Error'),
		events = {
			add: function (target, type, listener, useCapture) {
				if (target.events === undefined) {
					target.events = [];
				}
				if (target.events[type] === undefined) {
					target.events[type] = [];
				}
				target.addEventListener(type, listener, useCapture || false);
				target.events[type].push(listener);
				return listener;
			},
			remove: function (target, type, listener, useCapture) {
				if (target && target.events && target.events[type]) {
					var i;
					if (listener === undefined) {
						for (i = 0; i < target.events[type].length; i++) {
							target.removeEventListener(type, target.events[type][i], useCapture || false);
							target.events[type].splice(i, 1);
						}
					}
					else {
						for (i = 0; i < target.events[type].length; i++) {
							if (target.events[type][i] === listener) {
								target.removeEventListener(type, listener, useCapture || false);
								target.events[type].splice(i, 1);
							}
						}
					}
				}
			}
		};

	/** @private */
	function xResize(event) {
		event.preventDefault();
			if (mouseIsDown && target.actions.resize) {
			addClass(target.element, 'interact-target');
					var x = event.pageX,
			newWidth = ( event.pageX > target.location.x)? target.width + (x - prevX) : 0 ;

			target.setSize(newWidth, target.height);
			prevX = x;
		}
	}

	/** @private */
	function yResize(event) {
		event.preventDefault();
			if (mouseIsDown && target.actions.resize) {
			addClass(target.element, 'interact-target');
			var y = event.pageY,
			newHeight = ( event.pageY > target.location.y)? target.height + (y - prevY) : 0 ;

			target.setSize(target.width, newHeight);
			prevY = y;
		}
	}

	/** @private */
	function xyResize(event) {
		event.preventDefault();
			if (mouseIsDown && target.actions.resize) {			addClass(target.element, 'interact-target');			var x = event.pageX, y = event.pageY,
			newWidth = ( event.pageX > target.location.x)? target.width + (x - prevX) : 0 ,
			newHeight = ( event.pageY > target.location.y)? target.height + (y - prevY) : 0 ;

			target.setSize(newWidth, newHeight);
			prevX = x;
			prevY = y;
		}
	}
	/* Should change this so devices with mouse and touch can use both */
	if (supportsTouch) {
		downEvent = 'touchstart',
		upEvent = 'touchend',
		moveEvent = 'touchmove';
	}
	else {
		downEvent = 'mousedown',
		upEvent = 'mouseup',
		moveEvent = 'mousemove';
	}

	/** @private */
	function docMouseUp (event) {
		console.log('target = ' + target);
		events.remove(document, moveEvent, xResize);
		events.remove(document, moveEvent, yResize);
		events.remove(document, moveEvent, xyResize);
		events.remove(document, moveEvent, interact.drag.xyDrag);
			mouseIsDown = false;
		clearTarget();
		events.add(document, moveEvent, mouseMove);
	}

	/** @private */
	function mouseMove(event) {
		if (event.target.actions && (event.target.actions.resize || event.target.actions.drag)) {
			var x = event.pageX,
				y = event.pageY,
				target = event.target.object,
				right = (x - target.location.x > target.width - margin),
				bottom = (y - target.location.y > target.height - margin);

			if (right) {
				target.element.style.cursor = bottom?'se-resize' : 'e-resize';
			}
			else {
				target.element.style.cursor = bottom?'s-resize' : target.actions.drag? 'pointer' : 'default';
			}
		}
	}

	/**
	 * @private
	 */
	function mouseDown(event) {
		mouseIsDown = true;
		if (event.target.actions && (event.target.actions.resize || event.target.actions.drag)) {
			var	right,
				bottom;

				prevX = event.pageX;
				prevY = event.pageY;
				target = event.target.object;
				right = (prevX - target.location.x > target.width - margin),
				bottom = (prevY - target.location.y > target.height - margin);

			if (right) {
				event.preventDefault();

				events.remove(document, moveEvent);
				console.log('resizing on right');
				if (bottom) {
					events.add( document, moveEvent, xyResize );
				}
				else {
					events.add( document, moveEvent, xResize ) ;
				}
			}
			else if (bottom) {
				console.log('resizing on bottom');
				events.remove(document, moveEvent);
				events.add( document, moveEvent, yResize );
			}
			else if (target.actions.drag) {
				event.preventDefault();

				bringToFront(target.element);
				console.log('moving node');
				events.remove(document, moveEvent);
				events.add( document, moveEvent, interact.drag.xyDrag );
				target.element.style.cursor = 'move';							}
		return false;
		}
	}

	/** @private */
	function give(parent, child) {
		return parent.appendChild(child);
	}

	/** @private */
	function make(tag, parent) {
		return parent?	parent.appendChild(document.createElement(tag)):
				parent.createElement(tag);
	}

	/** @private */
	function disown(element) {
		return element.parentElement.removeChild(element);
	}

	/** @private */
	function removeClass(element, className) {
		element.className =
			element.className.replace( new RegExp( '(?:^|\\s)' + className + '(?!\\S)' ) , '' );
	}

	/** @private */
	function addClass(element, className) {
		if (!element.className.match( new RegExp( '(?:^|\\s)' + className + '(?!\\S)' ))) {
			element.className += ' ' + className;
		}
	}

	/**
	 * @class Vector Class for locations and dimensions
	 * @private
	 * @param {number} x Value of X ordinate
	 * @param {number} y Value of Y ordinate
	 */
	function Vector(x, y) {
		this.x = x || 0;
		this.y = y || 0;
	}
	/** @private */
	Vector.prototype.set = function (x, y) {
		this.x = x;
		this.y = y || x;
	};

	/** @private */
	Vector.prototype.copy = function (other) {
		if (!other.x && other.y) {
			return;
		}
		this.x = other.x;
		this.y = other.y;
	};

	/**
	 * @class Node for demonstrating interact functionality
	 * @private
	 * @param {number} x Horizontal position
	 * @param {number} y Vertical position
	 * @param {number} w Element width
	 * @param {number} h Element height
	 */
	function demoNode(x, y, w, h) {
		this.location = new Vector(x, y);
		this.width = w || 0;
		this.height = h || 0;
		this.actions = {resize: true, drag: true};

			this.element = document.createElement('div');
		this.element.actions = this.actions;
		this.element.object = this;
			this.element.style.setProperty('width', this.width + 'px', '');
		this.element.style.setProperty('height', this.height + 'px', '');
		this.element.style.setProperty('left', x + 'px', '');
		this.element.style.setProperty('top', y + 'px', '');
		this.element.className += ' interact-node ';
			if (!nodeStyle) {
			nodeStyle = document.createElement('style');
			nodeStyle.type = 'text/css';
			nodeStyle.innerHTML =' .interact-node { background-color:#2288FF; border:5px solid #333333; border-radius:10px; cursor:move; position:absolute; width:100px; height: 100px}';
			nodeStyle.innerHTML +=' .interact-node:hover { border-color: #AAAAAA; }';
			nodeStyle.innerHTML +=' .interact-target { border-style: dashed; }';
			document.body.appendChild(nodeStyle);
		}
	}

	/**
	 * @throws typeError
	 */
	demoNode.prototype.setSize = function (x, y) {
		if (x && x.constructor.name === 'Vector') {
			this.width =  x.x;
			this.height =  x.y;
		}
		else {
			if (typeof x !== 'number' || typeof y !== 'number') {
				typeErr.name = 'Incorrect parameter types';
				typeErr.message = 'demoNode.setSize parameters must be a single Vector or two numbers.';
				throw (typeErr);
			}
			this.width = x;
			this.height = y;
		}
		this.element.style.setProperty('width', Math.max(x, 20) + 'px', '');
		this.element.style.setProperty('height', Math.max(y, 20) + 'px', '');
	};

	/**
	 * @throws typeError
	 */
	demoNode.prototype.position = function (x, y) {
		if (x && x.constructor.name === 'Vector') {
		this.location.copy(x);
		}
		else {
			if (typeof x !== 'number' || typeof y !== 'number') {
				typeErr.name = 'Incorrect parameter types';
				typeErr.message = 'demoNode.position parameters must be a single Vector or two numbers.';
				throw (typeErr);
			}
			this.location.set(x, y);
		}
		this.element.style.setProperty('left', x + 'px', '');
		this.element.style.setProperty('top', y + 'px', '');
	};

	/** @private */
	function bringToFront(element) {
		// Very lazy
		var parent = element.parentElement;
		give(parent, disown(element));
	}

	/** @private */
	function clearTarget() {
		if (target) {
			removeClass(target.element, 'interact-target');
		}
		target = null;
	}
	/**
	 * @description Global interact object
	 */
	var interact = {};

	/**
	 * @description Array of interact nodes
	 */
	interact.nodes = [];

	/**
	 * @function
	 * @description Displays debugging data in the browser console
	 */
	interact.debug = function () {
		console.log('target   : ' + target);
		console.log('prevX    : ' + prevX);
		console.log('prevY    : ' + prevY);
		console.log('nodes    : ' + interact.nodes.length);
	}

	/**
	 * @function
	 * @description Add an element to the list of interact nodes
	 * @param {object HTMLElement} element The DOM Element that will be added
	 * @param {object} options An object whose properties are the drag/resize options
	 */
	interact.set = function (element, options) {
		var	newNode = {
				element: element,
				drag: options.drag || false,
				resize: options.resize || false,
				parent: options.parent || false,
				axis: options.axis || 'xy'
			};
		addClass(element, 'interact-node');
		interactNodes.push(newNode);
	};

	/**
	 * @function
	 * @description Remove an element from the list of interact nodes
	 * @param {object HTMLElement} element The DOM Element that will be removed
	 */
	interact.unset = function (element) {
		var i;
		for (i = 0; i < interactNodes.length; i++) {
			if (interactNodes[i].element === element) {
				interactNodes.splice(i-1, 1);
			}
		}
	};
	/**
	 * @description Contains drag functions. Currently here for debugging. Will be made private.
	 */
	interact.drag = {
		xyDrag: function (event) {
			event.preventDefault();
			if (mouseIsDown && target.actions.drag) {
				addClass(target.element, 'interact-target');
				var x = event.pageX,
					y = event.pageY;

				target.position(target.location.x + x - prevX , target.location.y + (y - prevY));
				prevX = x;
				prevY = y;
			}
		}
	};

	/**
	 * @function
	 * @description Introduce random draggable, resizeable nodes to the document (for testing)
	 * @param {number} [n] The number of nodes to be added (default: 10)
	 * @param {object} [parent] An object with boolean properties (default: document.body)
	 */
	interact.randomNodes = function (n, parent) {
		var i;

		n = n || 10;
		parent = parent || document.body;
			for (i = 0; i < n; i++) {
			if (interact.nodes[i]!==undefined && interact.nodes[i].element.parentNode === parent) {
				var par = interact.nodes[i].element.parentNode;
							par.removeChild(interact.nodes[i].element);
				interact.nodes[i] = new demoNode(Math.random()*(window.screen.width - 20), Math.random()*(window.screen.height - 20), Math.random()* 200, Math.random()* 200);
				give(par, interact.nodes[interact].element);
			}
			else {
				interact.nodes.push(new demoNode(Math.random()*(window.screen.width - 20), Math.random()*(window.screen.height - 20), Math.random()* 200, Math.random()* 200));
				give(document.body, interact.nodes[i].element);
			}
		}
	};
	events.add( document, moveEvent, mouseMove);
	events.add( document, downEvent, mouseDown);
	events.add( document, 'dragenter', function (event) { event.preventDefault(); });
	events.add(document, upEvent, docMouseUp);
	return interact;
}());

<|endoftext|>


<commit_before>import { _ } from 'meteor/erasaur:meteor-lodash';
import { AdvisorLogs } from '/imports/api/log/AdvisorLogCollection';
import { CareerGoals } from '/imports/api/career/CareerGoalCollection';
import { Courses } from '/imports/api/course/CourseCollection';
import { CourseInstances } from '/imports/api/course/CourseInstanceCollection';
import { DesiredDegrees } from '/imports/api/degree/DesiredDegreeCollection';
import { Feeds } from '/imports/api/feed/FeedCollection';
import { Feedbacks } from '/imports/api/feedback/FeedbackCollection';
import { FeedbackInstances } from '/imports/api/feedback/FeedbackInstanceCollection';
import { HelpMessages } from '/imports/api/help/HelpMessageCollection';
import { Interests } from '/imports/api/interest/InterestCollection';
import { InterestTypes } from '/imports/api/interest/InterestTypeCollection';
import { MentorAnswers } from '/imports/api/mentor/MentorAnswerCollection';
import { MentorQuestions } from '/imports/api/mentor/MentorQuestionCollection';
import { MentorProfiles } from '/imports/api/mentor/MentorProfileCollection';
import { OpportunityTypes } from '/imports/api/opportunity/OpportunityTypeCollection';
import { Opportunities } from '/imports/api/opportunity/OpportunityCollection';
import { OpportunityInstances } from '/imports/api/opportunity/OpportunityInstanceCollection';
import { Reviews } from '/imports/api/review/ReviewCollection';
import { Semesters } from '/imports/api/semester/SemesterCollection';
import { Slugs } from '/imports/api/slug/SlugCollection';
import { StarDataLogs } from '/imports/api/star/StarDataLogCollection';
import { Teasers } from '/imports/api/teaser/TeaserCollection';
import { Users } from '/imports/api/user/UserCollection';
import { VerificationRequests } from '/imports/api/verification/VerificationRequestCollection';
import { WorkInstances } from '/imports/api/work/WorkInstanceCollection';
import { AcademicYearInstances } from '/imports/api/year/AcademicYearInstanceCollection';
import { PlanChoices } from '/imports/api/degree/PlanChoiceCollection';
import { AcademicPlans } from '/imports/api/degree/AcademicPlanCollection';

/** @module api/base/BaseUtilities */

/**
 * Deletes all RadGrad data model entities. (Hopefully).
 */
export function removeAllEntities() {
  CareerGoals.removeAll();
  Courses.removeAll();
  CourseInstances.removeAll();
  DesiredDegrees.removeAll();
  Feeds.removeAll();
  Feedbacks.removeAll();
  FeedbackInstances.removeAll();
  HelpMessages.removeAll();
  Interests.removeAll();
  InterestTypes.removeAll();
  AdvisorLogs.removeAll();
  MentorAnswers.removeAll();
  MentorQuestions.removeAll();
  MentorProfiles.removeAll();
  Opportunities.removeAll();
  OpportunityInstances.removeAll();
  OpportunityTypes.removeAll();
  Reviews.removeAll();
  Semesters.removeAll();
  Slugs.removeAll();
  StarDataLogs.removeAll();
  Teasers.removeAll();
  Users.removeAll();
  VerificationRequests.removeAll();
  WorkInstances.removeAll();
  AcademicYearInstances.removeAll();
  PlanChoices.removeAll();
  AcademicPlans.removeAll();
}

export function clientRemoveAllEntities() {
  let items = CareerGoals.find().fetch();
  _.map(items, (i) => {
    CareerGoals.removeIt(i._id);
  });
  items = Courses.find().fetch();
  _.map(items, (i) => {
    Courses.removeIt(i._id);
  });
  items = CourseInstances.find().fetch();
  _.map(items, (i) => {
    CourseInstances.removeIt(i._id);
  });
  items = DesiredDegrees.find().fetch();
  _.map(items, (i) => {
    DesiredDegrees.removeIt(i._id);
  });
  items = Feeds.find().fetch();
  _.map(items, (i) => {
    Feeds.removeIt(i._id);
  });
  items = Feedbacks.find().fetch();
  _.map(items, (i) => {
    Feedbacks.removeIt(i._id);
  });
  items = FeedbackInstances.find().fetch();
  _.map(items, (i) => {
    FeedbackInstances.removeIt(i._id);
  });
  items = HelpMessages.find().fetch();
  _.map(items, (i) => {
    HelpMessages.removeIt(i._id);
  });
  items = Interests.find().fetch();
  _.map(items, (i) => {
    Interests.removeIt(i._id);
  });
  items = InterestTypes.find().fetch();
  _.map(items, (i) => {
    InterestTypes.removeIt(i._id);
  });
  items = AdvisorLogs.find().fetch();
  _.map(items, (i) => {
    AdvisorLogs.removeIt(i._id);
  });
  items = MentorAnswers.find().fetch();
  _.map(items, (i) => {
    MentorAnswers.removeIt(i._id);
  });
  items = MentorQuestions.find().fetch();
  _.map(items, (i) => {
    MentorQuestions.removeIt(i._id);
  });
  items = MentorProfiles.find().fetch();
  _.map(items, (i) => {
    MentorProfiles.removeIt(i._id);
  });
  items = Opportunities.find().fetch();
  _.map(items, (i) => {
    Opportunities.removeIt(i._id);
  });
  items = OpportunityInstances.find().fetch();
  _.map(items, (i) => {
    OpportunityInstances.removeIt(i._id);
  });
  items = OpportunityTypes.find().fetch();
  _.map(items, (i) => {
    OpportunityTypes.removeIt(i._id);
  });
  items = Reviews.find().fetch();
  _.map(items, (i) => {
    Reviews.removeIt(i._id);
  });
  items = Semesters.find().fetch();
  _.map(items, (i) => {
    Semesters.removeIt(i._id);
  });
  items = Slugs.find().fetch();
  _.map(items, (i) => {
    Slugs.removeIt(i._id);
  });
  items = StarDataLogs.find().fetch();
  _.map(items, (i) => {
    StarDataLogs.removeIt(i._id);
  });
  items = Teasers.find().fetch();
  _.map(items, (i) => {
    Teasers.removeIt(i._id);
  });
  items = Users.find().fetch();
  _.map(items, (i) => {
    Users.removeIt(i._id);
  });
  items = VerificationRequests.find().fetch();
  _.map(items, (i) => {
    VerificationRequests.removeIt(i._id);
  });
  items = WorkInstances.find().fetch();
  _.map(items, (i) => {
    WorkInstances.removeIt(i._id);
  });
  items = AcademicYearInstances.find().fetch();
  _.map(items, (i) => {
    AcademicYearInstances.removeIt(i._id);
  });
  items = PlanChoices.find().fetch();
  _.map(items, (i) => {
    PlanChoices.removeIt(i._id);
  });
  items = AcademicPlans.find().fetch();
  _.map(items, (i) => {
    AcademicPlans.removeIt(i._id);
  });
}
<commit_msg>Removed work<commit_after>import { _ } from 'meteor/erasaur:meteor-lodash';
import { AdvisorLogs } from '/imports/api/log/AdvisorLogCollection';
import { CareerGoals } from '/imports/api/career/CareerGoalCollection';
import { Courses } from '/imports/api/course/CourseCollection';
import { CourseInstances } from '/imports/api/course/CourseInstanceCollection';
import { DesiredDegrees } from '/imports/api/degree/DesiredDegreeCollection';
import { Feeds } from '/imports/api/feed/FeedCollection';
import { Feedbacks } from '/imports/api/feedback/FeedbackCollection';
import { FeedbackInstances } from '/imports/api/feedback/FeedbackInstanceCollection';
import { HelpMessages } from '/imports/api/help/HelpMessageCollection';
import { Interests } from '/imports/api/interest/InterestCollection';
import { InterestTypes } from '/imports/api/interest/InterestTypeCollection';
import { MentorAnswers } from '/imports/api/mentor/MentorAnswerCollection';
import { MentorQuestions } from '/imports/api/mentor/MentorQuestionCollection';
import { MentorProfiles } from '/imports/api/mentor/MentorProfileCollection';
import { OpportunityTypes } from '/imports/api/opportunity/OpportunityTypeCollection';
import { Opportunities } from '/imports/api/opportunity/OpportunityCollection';
import { OpportunityInstances } from '/imports/api/opportunity/OpportunityInstanceCollection';
import { Reviews } from '/imports/api/review/ReviewCollection';
import { Semesters } from '/imports/api/semester/SemesterCollection';
import { Slugs } from '/imports/api/slug/SlugCollection';
import { StarDataLogs } from '/imports/api/star/StarDataLogCollection';
import { Teasers } from '/imports/api/teaser/TeaserCollection';
import { Users } from '/imports/api/user/UserCollection';
import { VerificationRequests } from '/imports/api/verification/VerificationRequestCollection';
import { AcademicYearInstances } from '/imports/api/year/AcademicYearInstanceCollection';
import { PlanChoices } from '/imports/api/degree/PlanChoiceCollection';
import { AcademicPlans } from '/imports/api/degree/AcademicPlanCollection';

/** @module api/base/BaseUtilities */

/**
 * Deletes all RadGrad data model entities. (Hopefully).
 */
export function removeAllEntities() {
  CareerGoals.removeAll();
  Courses.removeAll();
  CourseInstances.removeAll();
  DesiredDegrees.removeAll();
  Feeds.removeAll();
  Feedbacks.removeAll();
  FeedbackInstances.removeAll();
  HelpMessages.removeAll();
  Interests.removeAll();
  InterestTypes.removeAll();
  AdvisorLogs.removeAll();
  MentorAnswers.removeAll();
  MentorQuestions.removeAll();
  MentorProfiles.removeAll();
  Opportunities.removeAll();
  OpportunityInstances.removeAll();
  OpportunityTypes.removeAll();
  Reviews.removeAll();
  Semesters.removeAll();
  Slugs.removeAll();
  StarDataLogs.removeAll();
  Teasers.removeAll();
  Users.removeAll();
  VerificationRequests.removeAll();
  AcademicYearInstances.removeAll();
  PlanChoices.removeAll();
  AcademicPlans.removeAll();
}

export function clientRemoveAllEntities() {
  let items = CareerGoals.find().fetch();
  _.map(items, (i) => {
    CareerGoals.removeIt(i._id);
  });
  items = Courses.find().fetch();
  _.map(items, (i) => {
    Courses.removeIt(i._id);
  });
  items = CourseInstances.find().fetch();
  _.map(items, (i) => {
    CourseInstances.removeIt(i._id);
  });
  items = DesiredDegrees.find().fetch();
  _.map(items, (i) => {
    DesiredDegrees.removeIt(i._id);
  });
  items = Feeds.find().fetch();
  _.map(items, (i) => {
    Feeds.removeIt(i._id);
  });
  items = Feedbacks.find().fetch();
  _.map(items, (i) => {
    Feedbacks.removeIt(i._id);
  });
  items = FeedbackInstances.find().fetch();
  _.map(items, (i) => {
    FeedbackInstances.removeIt(i._id);
  });
  items = HelpMessages.find().fetch();
  _.map(items, (i) => {
    HelpMessages.removeIt(i._id);
  });
  items = Interests.find().fetch();
  _.map(items, (i) => {
    Interests.removeIt(i._id);
  });
  items = InterestTypes.find().fetch();
  _.map(items, (i) => {
    InterestTypes.removeIt(i._id);
  });
  items = AdvisorLogs.find().fetch();
  _.map(items, (i) => {
    AdvisorLogs.removeIt(i._id);
  });
  items = MentorAnswers.find().fetch();
  _.map(items, (i) => {
    MentorAnswers.removeIt(i._id);
  });
  items = MentorQuestions.find().fetch();
  _.map(items, (i) => {
    MentorQuestions.removeIt(i._id);
  });
  items = MentorProfiles.find().fetch();
  _.map(items, (i) => {
    MentorProfiles.removeIt(i._id);
  });
  items = Opportunities.find().fetch();
  _.map(items, (i) => {
    Opportunities.removeIt(i._id);
  });
  items = OpportunityInstances.find().fetch();
  _.map(items, (i) => {
    OpportunityInstances.removeIt(i._id);
  });
  items = OpportunityTypes.find().fetch();
  _.map(items, (i) => {
    OpportunityTypes.removeIt(i._id);
  });
  items = Reviews.find().fetch();
  _.map(items, (i) => {
    Reviews.removeIt(i._id);
  });
  items = Semesters.find().fetch();
  _.map(items, (i) => {
    Semesters.removeIt(i._id);
  });
  items = Slugs.find().fetch();
  _.map(items, (i) => {
    Slugs.removeIt(i._id);
  });
  items = StarDataLogs.find().fetch();
  _.map(items, (i) => {
    StarDataLogs.removeIt(i._id);
  });
  items = Teasers.find().fetch();
  _.map(items, (i) => {
    Teasers.removeIt(i._id);
  });
  items = Users.find().fetch();
  _.map(items, (i) => {
    Users.removeIt(i._id);
  });
  items = VerificationRequests.find().fetch();
  _.map(items, (i) => {
    VerificationRequests.removeIt(i._id);
  });
  items = AcademicYearInstances.find().fetch();
  _.map(items, (i) => {
    AcademicYearInstances.removeIt(i._id);
  });
  items = PlanChoices.find().fetch();
  _.map(items, (i) => {
    PlanChoices.removeIt(i._id);
  });
  items = AcademicPlans.find().fetch();
  _.map(items, (i) => {
    AcademicPlans.removeIt(i._id);
  });
}
<|endoftext|>


<commit_before>import React, { Component } from 'react';
import '../App.css';
let request = require('superagent');

class SearchBar extends Component {

  constructor() {
    super();

    this.previous_input = "";
  }

  request() {
    request
      .get("http://localhost:5000/search/" + this.previous_input)
      .accept('json')
      .end( (err, res) => {
        console.log('err: ' + err);
        if (res) {
          console.log(JSON.parse(res.text));
        }
      });
  }

  render() {
    return (

        <input id="search-input" className="search-input" type="text" placeholder="nick 0, nick 1, nick 2, ..." onKeyUp={this.search.bind(this)}></input>

    );
  }

  search() {
    var raw_input = document.getElementById('search-input').value;
    this.previous_input = raw_input;
    this.request();
    //console.log("i did stuff");
    // send raw_input to Flask here!
  }

}

export default SearchBar;
<commit_msg>Shortened the placeholder in the search bar<commit_after>import React, { Component } from 'react';
import '../App.css';
let request = require('superagent');

class SearchBar extends Component {

  constructor() {
    super();

    this.previous_input = "";
  }

  request() {
    request
      .get("http://localhost:5000/search/" + this.previous_input)
      .accept('json')
      .end( (err, res) => {
        console.log('err: ' + err);
        if (res) {
          console.log(JSON.parse(res.text));
        }
      });
  }

  render() {
    return (

        <input id="search-input" className="search-input" type="text" placeholder="nick 0, nick 1, ..." onKeyUp={this.search.bind(this)}></input>

    );
  }

  search() {
    var raw_input = document.getElementById('search-input').value;
    this.previous_input = raw_input;
    this.request();
    //console.log("i did stuff");
    // send raw_input to Flask here!
  }

}

export default SearchBar;
<|endoftext|>