<commit_before>
/*!
 * Express - Server
 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var url = require('url')
  , view = require('./view')
  , connect = require('connect')
  , utils = connect.utils
  , queryString = require('querystring')
  , router = require('connect').router
  , methods = router.methods.concat(['del', 'all']);

/**
 * Initialize a new `Server` with optional `middleware`.
 *
 * @param {Array} middleware
 * @api public
 */

var Server = exports = module.exports = function Server(middleware){
  var self = this;
  this.config = {};
  this.settings = {};
  this.redirects = {};
  this.isCallbacks = {};
  this.viewHelpers = {};
  this.dynamicViewHelpers = {};
  this.errorHandlers = [];
  connect.Server.call(this, middleware || []);

  // Default "home" to /
  this.set('home', '/');

  // Set "env" to NODE_ENV, defaulting to "development"
  this.set('env', process.env.NODE_ENV || 'development');

  // Expose objects to each other
  this.use(function(req, res, next){
    req.query = {};
    res.headers = { 'X-Powered-By': 'Express' };
    req.app = res.app = self;
    req.res = res;
    res.req = req;
    req.next = next;
    // Assign req.params.get
    if (req.url.indexOf('?') > 0) {
      var query = url.parse(req.url).query;
      req.query = exports.parseQueryString(query);
    }
    next();
  });

  // Use router, expose as app.get(), etc
  var fn = router(function(app){ self.routes = app; });
  this.__defineGetter__('router', function(){
    this.__usedRouter = true;
    return fn;
  });

  // Default production configuration
  this.configure('production', function(){
    this.enable('cache views');
  });
};

/**
 * Inherit from `connect.Server`.
 */

Server.prototype.__proto__ = connect.Server.prototype;

/**
 * Support swappable querystring parsers.
 */

exports.parseQueryString = queryString.parse;

/**
 * Proxy in order to register error handlers.
 */

Server.prototype.listen = function(){
  this.registerErrorHandlers();
  connect.Server.prototype.listen.apply(this, arguments);
};

/**
 * Proxy in order to register error handlers.
 */

Server.prototype.listenFD = function(){
  this.registerErrorHandlers();
  connect.Server.prototype.listenFD.apply(this, arguments);
};

/**
 * Register error handlers. This is automatically
 * called from within `Server#listen()` and `Server#listenFD()`.
 *
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.registerErrorHandlers = function(){
  this.errorHandlers.forEach(function(fn){
    this.use(function(err, req, res, next){
      fn.apply(this, arguments);
    });
  }, this);
  return this;
};

/**
 * Proxy `connect.Server#use()` to apply settings to
 * mounted applications.
 *
 * @param {String|Function|Server} route
 * @param {Function|Server} middleware
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.use = function(route, middleware){
  if (typeof route !== 'string') {
    middleware = route, route = '/';
  }

  connect.Server.prototype.use.call(this, route, middleware);

  // Mounted an app
  if (middleware instanceof Server) {
    // Home is /:route/:home
    var app = middleware
      , home = app.set('home');
    if (home === '/') home = '';
    app.set('home', (app.route || '') + home);
    app.parent = this;
    // Mounted hook
    if (app.__mounted) app.__mounted.call(app, this);
  }

  return this;
};

/**
 * Assign a callback `fn` which is called
 * when this `Server` is passed to `Server#use()`.
 *
 * Examples:
 *
 *    var app = express.createServer(),
 *        blog = express.createServer();
 *
 *    blog.mounted(function(parent){
 *        // parent is app
 *        // "this" is blog
 *    });
 *
 *    app.use(blog);
 *
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.mounted = function(fn){
  this.__mounted = fn;
  return this;
};

/**
 * See: view.register.
 *
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.register = function(){
  view.register.apply(this, arguments);
  return this;
};

/**
 * Register the given view helpers `obj`. This method
 * can be called several times to apply additional helpers.
 *
 * @param {Object} obj
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.helpers =
Server.prototype.locals = function(obj){
  utils.merge(this.viewHelpers, obj);
  return this;
};

/**
 * Register the given dynamic view helpers `obj`. This method
 * can be called several times to apply additional helpers.
 *
 * @param {Object} obj
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.dynamicHelpers = function(obj){
  utils.merge(this.dynamicViewHelpers, obj);
  return this;
};

/**
 * Map the given param placeholder `name`(s) to the given callback `fn`.
 *
 * Param mapping is used to provide pre-conditions to routes
 * which us normalized placeholders. For example ":user_id" may
 * attempt to load the user from the database, where as ":num" may
 * pass the value through `parseInt(num, 10)`.
 *
 * When the callback function accepts only a single argument, the
 * value of placeholder is passed:
 *
 *    app.param('page', function(n){ return parseInt(n, 10); });
 *
 * After which "/users/:page" would automatically provide us with
 * an integer for `req.params.page`. If desired we could use the callback
 * signature shown below, and immediately `next(new Error('invalid page'))`
 * when `parseInt` fails.
 *
 * Alternatively the callback may accept the request, response, next, and
 * the value, acting like middlware:
 *
 *    app.param('userId', function(req, res, next, id){
 *      User.find(id, function(err, user){
 *        if (err) {
 *          next(err);
 *        } else if (user) {
 *          req.user = user;
 *          next();
 *        } else {
 *          next(new Error('failed to load user'));
 *        }
 *      });
 *    });
 *
 * Now every time ":userId" is present, the associated user object
 * will be loaded and assigned before the route handler is invoked.
 *
 * @param {String|Array} name
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.param = function(name, fn){
  if (Array.isArray(name)) {
    name.forEach(function(name){
      this.param(name, fn);
    }, this);
  } else {
    if (':' == name[0]) name = name.substr(1);
    this.routes.param(name, fn);
  }
  return this;
};

/**
 * Assign a custom exception handler callback `fn`.
 * These handlers are always _last_ in the middleware stack.
 *
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.error = function(fn){
  this.errorHandlers.push(fn);
  return this;
};

/**
 * Register the given callback `fn` for the given `type`.
 *
 * @param {String} type
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.is = function(type, fn){
  if (!fn) return this.isCallbacks[type];
  this.isCallbacks[type] = fn;
  return this;
};

/**
 * Assign `setting` to `val`, or return `setting`'s value.
 * Mounted servers inherit their parent server's settings.
 *
 * @param {String} setting
 * @param {String} val
 * @return {Server|Mixed} for chaining, or the setting value
 * @api public
 */

Server.prototype.set = function(setting, val){
  if (val === undefined) {
    if (this.settings.hasOwnProperty(setting)) {
      return this.settings[setting];
    } else if (this.parent) {
      return this.parent.set(setting);
    }
  } else {
    this.settings[setting] = val;
    return this;
  }
};

/**
 * Check if `setting` is enabled.
 *
 * @param {String} setting
 * @return {Boolean}
 * @api public
 */

Server.prototype.enabled = function(setting){
  return !!this.set(setting);
};

/**
 * Check if `setting` is disabled.
 *
 * @param {String} setting
 * @return {Boolean}
 * @api public
 */

Server.prototype.disabled = function(setting){
  return !this.set(setting);
};

/**
 * Enable `setting`.
 *
 * @param {String} setting
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.enable = function(setting){
  return this.set(setting, true);
};

/**
 * Disable `setting`.
 *
 * @param {String} setting
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.disable = function(setting){
  return this.set(setting, false);
};

/**
 * Redirect `key` to `url`.
 *
 * @param {String} key
 * @param {String} url
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.redirect = function(key, url){
  this.redirects[key] = url;
  return this;
};

/**
 * Configure callback for the given `env`.
 *
 * @param {String} env
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.configure = function(env, fn){
  if (typeof env === 'function') {
    fn = env, env = 'all';
  }
  if ('all' == env || env == this.settings.env) {
    fn.call(this);
  }
  return this;
};

// Generate routing methods

function generateMethod(method){
  Server.prototype[method] = function(path, fn){
    var self = this;

    // Ensure router is mounted
    if (!this.__usedRouter) {
      this.use(this.router);
    }

    // Route specific middleware support
    if (arguments.length > 2) {
      var args = Array.prototype.slice.call(arguments, 1);
      fn = args.pop();
      (function stack(middleware){
        middleware.forEach(function(fn){
          if (Array.isArray(fn)) {
            stack(fn);
          } else {
            self[method](path, fn);
          }
        });
      })(args);
    }

    // Generate the route
    this.routes[method](path, fn);
    return this;
  };
  return arguments.callee;
}

methods.forEach(generateMethod);

// Alias delete as "del"

Server.prototype.del = Server.prototype.delete;
<commit_msg>Fixed for middleware stacked via createServer()<commit_after>
/*!
 * Express - Server
 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var url = require('url')
  , view = require('./view')
  , connect = require('connect')
  , utils = connect.utils
  , queryString = require('querystring')
  , router = require('connect').router
  , methods = router.methods.concat(['del', 'all']);

/**
 * Initialize a new `Server` with optional `middleware`.
 *
 * @param {Array} middleware
 * @api public
 */

var Server = exports = module.exports = function Server(middleware){
  var self = this;
  this.config = {};
  this.settings = {};
  this.redirects = {};
  this.isCallbacks = {};
  this.viewHelpers = {};
  this.dynamicViewHelpers = {};
  this.errorHandlers = [];
  connect.Server.call(this, []);

  // Default "home" to /
  this.set('home', '/');

  // Set "env" to NODE_ENV, defaulting to "development"
  this.set('env', process.env.NODE_ENV || 'development');

  // Expose objects to each other
  this.use(function(req, res, next){
    req.query = {};
    res.headers = { 'X-Powered-By': 'Express' };
    req.app = res.app = self;
    req.res = res;
    res.req = req;
    req.next = next;
    // Assign req.params.get
    if (req.url.indexOf('?') > 0) {
      var query = url.parse(req.url).query;
      req.query = exports.parseQueryString(query);
    }
    next();
  });

  // Apply middleware
  if (middleware) {
    middleware.forEach(function(fn){
      self.use(fn);
    });
  }

  // Use router, expose as app.get(), etc
  var fn = router(function(app){ self.routes = app; });
  this.__defineGetter__('router', function(){
    this.__usedRouter = true;
    return fn;
  });

  // Default production configuration
  this.configure('production', function(){
    this.enable('cache views');
  });
};

/**
 * Inherit from `connect.Server`.
 */

Server.prototype.__proto__ = connect.Server.prototype;

/**
 * Support swappable querystring parsers.
 */

exports.parseQueryString = queryString.parse;

/**
 * Proxy in order to register error handlers.
 */

Server.prototype.listen = function(){
  this.registerErrorHandlers();
  connect.Server.prototype.listen.apply(this, arguments);
};

/**
 * Proxy in order to register error handlers.
 */

Server.prototype.listenFD = function(){
  this.registerErrorHandlers();
  connect.Server.prototype.listenFD.apply(this, arguments);
};

/**
 * Register error handlers. This is automatically
 * called from within `Server#listen()` and `Server#listenFD()`.
 *
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.registerErrorHandlers = function(){
  this.errorHandlers.forEach(function(fn){
    this.use(function(err, req, res, next){
      fn.apply(this, arguments);
    });
  }, this);
  return this;
};

/**
 * Proxy `connect.Server#use()` to apply settings to
 * mounted applications.
 *
 * @param {String|Function|Server} route
 * @param {Function|Server} middleware
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.use = function(route, middleware){
  if (typeof route !== 'string') {
    middleware = route, route = '/';
  }

  connect.Server.prototype.use.call(this, route, middleware);

  // Mounted an app
  if (middleware instanceof Server) {
    // Home is /:route/:home
    var app = middleware
      , home = app.set('home');
    if (home === '/') home = '';
    app.set('home', (app.route || '') + home);
    app.parent = this;
    // Mounted hook
    if (app.__mounted) app.__mounted.call(app, this);
  }

  return this;
};

/**
 * Assign a callback `fn` which is called
 * when this `Server` is passed to `Server#use()`.
 *
 * Examples:
 *
 *    var app = express.createServer(),
 *        blog = express.createServer();
 *
 *    blog.mounted(function(parent){
 *        // parent is app
 *        // "this" is blog
 *    });
 *
 *    app.use(blog);
 *
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.mounted = function(fn){
  this.__mounted = fn;
  return this;
};

/**
 * See: view.register.
 *
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.register = function(){
  view.register.apply(this, arguments);
  return this;
};

/**
 * Register the given view helpers `obj`. This method
 * can be called several times to apply additional helpers.
 *
 * @param {Object} obj
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.helpers =
Server.prototype.locals = function(obj){
  utils.merge(this.viewHelpers, obj);
  return this;
};

/**
 * Register the given dynamic view helpers `obj`. This method
 * can be called several times to apply additional helpers.
 *
 * @param {Object} obj
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.dynamicHelpers = function(obj){
  utils.merge(this.dynamicViewHelpers, obj);
  return this;
};

/**
 * Map the given param placeholder `name`(s) to the given callback `fn`.
 *
 * Param mapping is used to provide pre-conditions to routes
 * which us normalized placeholders. For example ":user_id" may
 * attempt to load the user from the database, where as ":num" may
 * pass the value through `parseInt(num, 10)`.
 *
 * When the callback function accepts only a single argument, the
 * value of placeholder is passed:
 *
 *    app.param('page', function(n){ return parseInt(n, 10); });
 *
 * After which "/users/:page" would automatically provide us with
 * an integer for `req.params.page`. If desired we could use the callback
 * signature shown below, and immediately `next(new Error('invalid page'))`
 * when `parseInt` fails.
 *
 * Alternatively the callback may accept the request, response, next, and
 * the value, acting like middlware:
 *
 *    app.param('userId', function(req, res, next, id){
 *      User.find(id, function(err, user){
 *        if (err) {
 *          next(err);
 *        } else if (user) {
 *          req.user = user;
 *          next();
 *        } else {
 *          next(new Error('failed to load user'));
 *        }
 *      });
 *    });
 *
 * Now every time ":userId" is present, the associated user object
 * will be loaded and assigned before the route handler is invoked.
 *
 * @param {String|Array} name
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.param = function(name, fn){
  if (Array.isArray(name)) {
    name.forEach(function(name){
      this.param(name, fn);
    }, this);
  } else {
    if (':' == name[0]) name = name.substr(1);
    this.routes.param(name, fn);
  }
  return this;
};

/**
 * Assign a custom exception handler callback `fn`.
 * These handlers are always _last_ in the middleware stack.
 *
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.error = function(fn){
  this.errorHandlers.push(fn);
  return this;
};

/**
 * Register the given callback `fn` for the given `type`.
 *
 * @param {String} type
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.is = function(type, fn){
  if (!fn) return this.isCallbacks[type];
  this.isCallbacks[type] = fn;
  return this;
};

/**
 * Assign `setting` to `val`, or return `setting`'s value.
 * Mounted servers inherit their parent server's settings.
 *
 * @param {String} setting
 * @param {String} val
 * @return {Server|Mixed} for chaining, or the setting value
 * @api public
 */

Server.prototype.set = function(setting, val){
  if (val === undefined) {
    if (this.settings.hasOwnProperty(setting)) {
      return this.settings[setting];
    } else if (this.parent) {
      return this.parent.set(setting);
    }
  } else {
    this.settings[setting] = val;
    return this;
  }
};

/**
 * Check if `setting` is enabled.
 *
 * @param {String} setting
 * @return {Boolean}
 * @api public
 */

Server.prototype.enabled = function(setting){
  return !!this.set(setting);
};

/**
 * Check if `setting` is disabled.
 *
 * @param {String} setting
 * @return {Boolean}
 * @api public
 */

Server.prototype.disabled = function(setting){
  return !this.set(setting);
};

/**
 * Enable `setting`.
 *
 * @param {String} setting
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.enable = function(setting){
  return this.set(setting, true);
};

/**
 * Disable `setting`.
 *
 * @param {String} setting
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.disable = function(setting){
  return this.set(setting, false);
};

/**
 * Redirect `key` to `url`.
 *
 * @param {String} key
 * @param {String} url
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.redirect = function(key, url){
  this.redirects[key] = url;
  return this;
};

/**
 * Configure callback for the given `env`.
 *
 * @param {String} env
 * @param {Function} fn
 * @return {Server} for chaining
 * @api public
 */

Server.prototype.configure = function(env, fn){
  if (typeof env === 'function') {
    fn = env, env = 'all';
  }
  if ('all' == env || env == this.settings.env) {
    fn.call(this);
  }
  return this;
};

// Generate routing methods

function generateMethod(method){
  Server.prototype[method] = function(path, fn){
    var self = this;

    // Ensure router is mounted
    if (!this.__usedRouter) {
      this.use(this.router);
    }

    // Route specific middleware support
    if (arguments.length > 2) {
      var args = Array.prototype.slice.call(arguments, 1);
      fn = args.pop();
      (function stack(middleware){
        middleware.forEach(function(fn){
          if (Array.isArray(fn)) {
            stack(fn);
          } else {
            self[method](path, fn);
          }
        });
      })(args);
    }

    // Generate the route
    this.routes[method](path, fn);
    return this;
  };
  return arguments.callee;
}

methods.forEach(generateMethod);

// Alias delete as "del"

Server.prototype.del = Server.prototype.delete;
<|endoftext|>


<commit_before>/**
 * Configures the 'require' plugin.
 *
 * In the following example, we have three libraries, which are composed by a list of JavaScript and
 * CSS files. All attributes are optional but, if presents, they should look as follows.
 */
$.require('config', {
    libraries: {
        lib1: {
            sources: {
                js: ['js/script11.js', 'js/script12.js', 'js/script13.js'],
                css: ['css/style11.css', 'css/style12.css', 'css/style13.css']
            }
        },
        lib2: {
            sources: {
                js: ['js/script21.js', 'js/script22.js'],
                css: ['css/style21.css', 'css/style22.css']
            },
            requires: ['lib1']
        },
        lib3: {
            sources: {
                js: ['js/script31.js'],
                css: ['css/style31.css']
            },
            requires: ['lib2']
        }
    }
});
<commit_msg>improve demos<commit_after>/**
 * Configures the 'require' plugin.
 *
 * In the following example, we have three libraries, which are composed by a list of JavaScript and
 * CSS files. All attributes are optional but, if presents, they should look as follows.
 */
$.require('config', {
    libraries: {
        lib1: {
            sources: {
                js: ['js/script11.js', 'js/script12.js', 'js/script13.js'],
                css: ['css/style11.css', 'css/style12.css', 'css/style13.css']
            }
        },
        lib2: {
            sources: {
                js: ['js/script21.js', 'js/script22.js'],
                css: ['css/style21.css', 'css/style22.css']
            },
            requires: ['lib1']
        },
        // this library is loaded at last place
        // as it is an 'synchronous' library
        lib3: {
            async: false,
            sources: {
                js: ['js/script31.js'],
                css: ['css/style31.css']
            },
            requires: ['lib2']
        }
    }
});
<|endoftext|>


<commit_before>// Ionic Geofence example App

angular.module('breadcrumb', [
  'ionic',
  'ionic.contrib.ui.tinderCards',
  'leaflet-directive',
  'auth0',
  'angular-storage',
  'angular-jwt',
])
.run(function (
  $window,
  $document,
  $ionicLoading,
  $state,
  $ionicPlatform,
  $log,
  $rootScope,
  GeofencePluginMock,
  auth,
  store
) {
  $ionicPlatform.ready(function () {
    $log.log('Ionic ready');
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if ($window.cordova && $window.cordova.plugins.Keyboard) {
      $window.cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if ($window.StatusBar) {
      $window.StatusBar.styleDefault();
    }
    if ($window.geofence === undefined) {
      $log.warn('Geofence Plugin not found. Using mock instead.');
      $window.geofence = GeofencePluginMock;
      $window.TransitionType = GeofencePluginMock.TransitionType;
    }
    if (navigator.splashscreen) {
      navigator.splashscreen.hide();
    }

    $window.geofence.onTransitionReceived = (geofences) => {
      $log.log(geofences);
      if (geofences) {
        $rootScope.$apply(() => {
          geofences.forEach((geo) => {
            geo.notification = geo.notification || {
              title: 'Geofence transition',
              text: 'Without notification',
            };
            // $ionicLoading.show({
            //   template: `${geo.notification.title}: ${geo.notification.text}`,
            //   noBackdrop: true,
            //   duration: 2000,
            // });
          });
        });
      }
    };

    $window.geofence.onNotificationClicked = (notificationData) => {
      $log.log(notificationData);

      if (notificationData) {
        $rootScope.$apply(() => {
          $ionicLoading.show({
            template: `Notification clicked: ${notificationData.notification.text}`,
            noBackdrop: true,
            duration: 2000,
          });

          $state.go('geofence', {
            geofenceId: notificationData.id,
          });
        });
      }
    };

    $window.geofence.initialize(() => {
      $log.log('Geofence plugin initialized');
    });

    $rootScope.$on('$locationChangeStart', () => {
      if (!auth.isAuthenticated) {
        const token = store.get('token');
        if (token) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    });
  });
})
.controller('AppCtrl', function ($scope, auth, store, $state) {
  $scope.logout = () => {
    auth.signout();
    store.remove('token');
    store.remove('profile');
    store.remove('refreshToken');
    $state.go('start', {}, { reload: true });
  };

  $scope.test = (input) => {
    console.warn(input);
  };

  $scope.setTrail = (id) => {
    localStorage.setItem('trail', id);
  };

  // $scope.user = JSON.parse(localStorage.user).username;

  $scope.overflowStyle = {
    'max-height': '125px',
    overflow: 'scroll',
  };
});
<commit_msg>(rebase) integrate changes from upstream angular branch<commit_after>// Ionic Geofence example App

angular.module('breadcrumb', [
  'ionic',
  'ionic.contrib.ui.tinderCards',
  'leaflet-directive',
  'auth0',
  'angular-storage',
  'angular-jwt',
])
.run(function (
  $window,
  $document,
  $ionicLoading,
  $state,
  $ionicPlatform,
  $log,
  $rootScope,
  GeofencePluginMock,
  auth,
  store
) {
  $ionicPlatform.ready(function () {
    $rootScope.pinged = false;
    // $log.log('Ionic ready');
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if ($window.cordova && $window.cordova.plugins.Keyboard) {
      $window.cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if ($window.StatusBar) {
      $window.StatusBar.styleDefault();
    }
    if ($window.geofence === undefined) {
      $log.warn('Geofence Plugin not found. Using mock instead.');
      $window.geofence = GeofencePluginMock;
      $window.TransitionType = GeofencePluginMock.TransitionType;
    }
    if (navigator.splashscreen) {
      navigator.splashscreen.hide();
    }

    $window.geofence.onTransitionReceived = (geofences) => {
      $log.log(geofences);
      if (geofences) {
        $rootScope.$apply(() => {
          geofences.forEach((geo) => {
            geo.notification = geo.notification || {
              title: 'Geofence transition',
              text: 'Without notification',
            };
            $rootScope.pinged = true;
          });
        });
      }
    };

    $window.geofence.onNotificationClicked = (notificationData) => {
      $log.log(notificationData);

      if (notificationData) {
        $rootScope.$apply(() => {
          $ionicLoading.show({
            template: `Notification clicked: ${notificationData.notification.text}`,
            noBackdrop: true,
            duration: 2000,
          });

          $state.go('geofence', {
            geofenceId: notificationData.id,
          });
        });
      }
    };

    $window.geofence.initialize(() => {
      $log.log('Geofence plugin initialized');
    });

    $rootScope.$on('$locationChangeStart', () => {
      if (!auth.isAuthenticated) {
        const token = store.get('token');
        if (token) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    });
  });
})
.controller('AppCtrl', function ($scope, auth, store, $state) {
  $scope.logout = () => {
    auth.signout();
    store.remove('token');
    store.remove('profile');
    store.remove('refreshToken');
    $state.go('start', {}, { reload: true });
  };

  $scope.test = (input) => {
    console.warn(input);
  };

  $scope.setTrail = (id) => {
    localStorage.setItem('trail', id);
  };

  // $scope.user = JSON.parse(localStorage.user).username;

  $scope.overflowStyle = {
    'max-height': '125px',
    overflow: 'scroll',
  };
});
<|endoftext|>


<commit_before>/**
 * @class Utils provides a number of utility functions which are handy
 *        around the app.
 *
 * @property {Boolean} debugMode This boolean can be changed from true to
 *           false for production mode to speed up the app.
 *
 * @constructs
 */
var Utils = Utils || {};

Utils.debugMode = true;

Utils.couchUrl = "http://ilanguage.iriscouch.com/sapir-firstcorpus";
/**
 * The address of the TouchDB-Android database on the Android.
 */
Utils.touchUrl = "http://localhost:8888/db";

/**
 * The address of the PouchDB database on the browser.
 */
Utils.pouchUrl = "idb://db";

Utils.activityFeedCouchUrl = "http://trisapeace.iriscouch.com/activity_feed";
/**
 * The address of the TouchDB-Android database on the Android.
 */
Utils.activityFeedTouchUrl = "http://localhost:8888/activity_feed_db";

/**
 * The address of the PouchDB database on the browser.
 */
Utils.activityFeedPouchUrl = "idb://activity_feed_db";

/**
 * The url of the authentication server.
 */
Utils.authUrl = "https://localhost:3001";//"https://ifield.fieldlinguist.com";
/**
 * The parameters of the default couch server.
 */
Utils.defaultCouchConnection = function() {
  return {
    protocol : "http://",
    domain : "ilanguage.iriscouch.com",
    port : "80",
    corpusname : "sapir-firstcorpus"
  };
};
/**
 * A message for users if they need help which brings them to our contact us form
 */
Utils.contactUs = "Contact Us";

/**
 * Console logs out, if not on Internet Explorer. Only logs out if
 * debugMode is true.
 */
Utils.debug = function(message) {
	if(navigator.appName == 'Microsoft Internet Explorer') {
		return;
	}
	if(this.debugMode) {
		console.log(message);
	}
};

/**
 * Simple Pub/sub plugin to create a decoupled javascript app
 * http://answers.oreilly.com/topic/2190-two-examples-of-the-observer-pattern-in-javascript/
 *
 * How to use it:
var hub = {};
makePublisher(hub);

hub.subscribe(
  "probeCommand",
  function(arg) {
    debug("Receiving command " + arg);
  }, self);

hub.publish(
    "probeResponse",
"Command not valid.")

var right = document.getElementById("rightSideReading");
hub.unsubscribe('probeResponse', null, center);
hub.subscribe('probeResponse', function(arg) {
  debug("Putting probe's response in the right input field.");
  var cleanedMessage = arg.replace(/[^0-9]/g, "");
  debug("Cleaned message: " + arg + " to: " + cleanedMessage);
  right.value = cleanedMessage;
}, right);

hub.subscribe('changeLogo',function(arg){
  debug("Putting the logo from the user. This is the path: "+ arg);
  img.setAttribute("src",storage.getItem("userLogo"));
},img);
 *
 */

Utils.publisher = {
  subscribers : {
    any : []
  },
  subscribe : function(type, fn, context) {
    type = type || 'any';
    fn = typeof fn === "function" ? fn : context[fn];

    if (typeof this.subscribers[type] === "undefined") {
      this.subscribers[type] = [];
    }
    this.subscribers[type].push({
      fn : fn,
      context : context || this
    });
  },
  unsubscribe : function(type, fn, context) {
    this.visitSubscribers('unsubscribe', type, fn, context);
  },
  publish : function(type, publication) {
    this.visitSubscribers('publish', type, publication);
  },
  visitSubscribers : function(action, type, arg, context) {
    var pubtype = type || 'any', subscribers = this.subscribers[pubtype], i, max = subscribers ? subscribers.length
        : 0;

    for (i = 0; i < max; i += 1) {
      if (action === 'publish') {
        subscribers[i].fn.call(subscribers[i].context, arg);
      } else {
        if (subscribers[i].context === context) {
          subscribers.splice(i, 1);
          debug("Removed subscribers");

        } else {
          debug("Not removing subscriber" + i);

        }
      }
    }
  }
};
Utils.makePublisher = function(o) {
  var i;
  for (i in Utils.publisher) {
    if (Utils.publisher.hasOwnProperty(i)
        && typeof Utils.publisher[i] === "function") {
      o[i] = Utils.publisher[i];
    }
  }
  o.subscribers = {
    any : []
  };
};

/**
 * Detects whether we are running offline on an Android app.
 *
 * Note: to Android app developers, append this to your user agent string to
 * take advantage of the offline functionality of this app.
 *
 * @returns {Boolean} true if using offline Android
 */
Utils.androidApp = function() {
	return navigator.userAgent.indexOf("OfflineAndroidApp") > -1;
};

/**
 * Detects whether we are running offline in chrome extension.
 *
 * @returns {Boolean} true if using a Chrome Extension
 */
Utils.chromeApp = function() {
	return window.location.href.indexOf("chrome-extension") > -1;
};

/**
 * If not running offline on an android or in a chrome extension,
 * assume we are online.
 *
 * @returns {Boolean} true if not on offline Android or on a Chrome
 *          Extension
 */
Utils.onlineOnly = function() {
	return !this.androidApp() && !this.chromeApp();
};

Utils.hasClass = function(ele, cls) {
	return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
};

Utils.addClass = function(ele, cls) {
	if(!this.hasClass(ele, cls))
		ele.className += " " + cls;
};

Utils.removeClass = function(ele, cls) {
	if(this.hasClass(ele, cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)', 'g');
		ele.className = ele.className.replace(reg, ' ');
	}
};

<commit_msg>putting auth server back to production server so you dont have to run local node to test<commit_after>/**
 * @class Utils provides a number of utility functions which are handy
 *        around the app.
 *
 * @property {Boolean} debugMode This boolean can be changed from true to
 *           false for production mode to speed up the app.
 *
 * @constructs
 */
var Utils = Utils || {};

Utils.debugMode = true;

Utils.couchUrl = "http://ilanguage.iriscouch.com/sapir-firstcorpus";
/**
 * The address of the TouchDB-Android database on the Android.
 */
Utils.touchUrl = "http://localhost:8888/db";

/**
 * The address of the PouchDB database on the browser.
 */
Utils.pouchUrl = "idb://db";

Utils.activityFeedCouchUrl = "http://trisapeace.iriscouch.com/activity_feed";
/**
 * The address of the TouchDB-Android database on the Android.
 */
Utils.activityFeedTouchUrl = "http://localhost:8888/activity_feed_db";

/**
 * The address of the PouchDB database on the browser.
 */
Utils.activityFeedPouchUrl = "idb://activity_feed_db";

/**
 * The url of the authentication server.
 */
Utils.authUrl = "https://ifield.fieldlinguist.com";//"https://localhost:3001";
/**
 * The parameters of the default couch server.
 */
Utils.defaultCouchConnection = function() {
  return {
    protocol : "http://",
    domain : "ilanguage.iriscouch.com",
    port : "80",
    corpusname : "sapir-firstcorpus"
  };
};
/**
 * A message for users if they need help which brings them to our contact us form
 */
Utils.contactUs = "Contact Us";

/**
 * Console logs out, if not on Internet Explorer. Only logs out if
 * debugMode is true.
 */
Utils.debug = function(message) {
	if(navigator.appName == 'Microsoft Internet Explorer') {
		return;
	}
	if(this.debugMode) {
		console.log(message);
	}
};

/**
 * Simple Pub/sub plugin to create a decoupled javascript app
 * http://answers.oreilly.com/topic/2190-two-examples-of-the-observer-pattern-in-javascript/
 *
 * How to use it:
var hub = {};
makePublisher(hub);

hub.subscribe(
  "probeCommand",
  function(arg) {
    debug("Receiving command " + arg);
  }, self);

hub.publish(
    "probeResponse",
"Command not valid.")

var right = document.getElementById("rightSideReading");
hub.unsubscribe('probeResponse', null, center);
hub.subscribe('probeResponse', function(arg) {
  debug("Putting probe's response in the right input field.");
  var cleanedMessage = arg.replace(/[^0-9]/g, "");
  debug("Cleaned message: " + arg + " to: " + cleanedMessage);
  right.value = cleanedMessage;
}, right);

hub.subscribe('changeLogo',function(arg){
  debug("Putting the logo from the user. This is the path: "+ arg);
  img.setAttribute("src",storage.getItem("userLogo"));
},img);
 *
 */

Utils.publisher = {
  subscribers : {
    any : []
  },
  subscribe : function(type, fn, context) {
    type = type || 'any';
    fn = typeof fn === "function" ? fn : context[fn];

    if (typeof this.subscribers[type] === "undefined") {
      this.subscribers[type] = [];
    }
    this.subscribers[type].push({
      fn : fn,
      context : context || this
    });
  },
  unsubscribe : function(type, fn, context) {
    this.visitSubscribers('unsubscribe', type, fn, context);
  },
  publish : function(type, publication) {
    this.visitSubscribers('publish', type, publication);
  },
  visitSubscribers : function(action, type, arg, context) {
    var pubtype = type || 'any', subscribers = this.subscribers[pubtype], i, max = subscribers ? subscribers.length
        : 0;

    for (i = 0; i < max; i += 1) {
      if (action === 'publish') {
        subscribers[i].fn.call(subscribers[i].context, arg);
      } else {
        if (subscribers[i].context === context) {
          subscribers.splice(i, 1);
          debug("Removed subscribers");

        } else {
          debug("Not removing subscriber" + i);

        }
      }
    }
  }
};
Utils.makePublisher = function(o) {
  var i;
  for (i in Utils.publisher) {
    if (Utils.publisher.hasOwnProperty(i)
        && typeof Utils.publisher[i] === "function") {
      o[i] = Utils.publisher[i];
    }
  }
  o.subscribers = {
    any : []
  };
};

/**
 * Detects whether we are running offline on an Android app.
 *
 * Note: to Android app developers, append this to your user agent string to
 * take advantage of the offline functionality of this app.
 *
 * @returns {Boolean} true if using offline Android
 */
Utils.androidApp = function() {
	return navigator.userAgent.indexOf("OfflineAndroidApp") > -1;
};

/**
 * Detects whether we are running offline in chrome extension.
 *
 * @returns {Boolean} true if using a Chrome Extension
 */
Utils.chromeApp = function() {
	return window.location.href.indexOf("chrome-extension") > -1;
};

/**
 * If not running offline on an android or in a chrome extension,
 * assume we are online.
 *
 * @returns {Boolean} true if not on offline Android or on a Chrome
 *          Extension
 */
Utils.onlineOnly = function() {
	return !this.androidApp() && !this.chromeApp();
};

Utils.hasClass = function(ele, cls) {
	return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
};

Utils.addClass = function(ele, cls) {
	if(!this.hasClass(ele, cls))
		ele.className += " " + cls;
};

Utils.removeClass = function(ele, cls) {
	if(this.hasClass(ele, cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)', 'g');
		ele.className = ele.className.replace(reg, ' ');
	}
};

<|endoftext|>


<commit_before>/**
 * example-angularjs
 * https://github.com/3lXample/example-angularjs
 *
 * Copyright (c) 2017 3lXample (https://github.com/3lXample)
 * Licensed under the MIT license
 */
(function() {
  'use strict';

  var name   = '3XApp-example';
  var module = angular.module(name);

  // Add Constants
  module.constant('exampleConstant', 'built by Anisetus Elly Efendi');

})();
<commit_msg>Add example provider value<commit_after>/**
 * example-angularjs
 * https://github.com/3lXample/example-angularjs
 *
 * Copyright (c) 2017 3lXample (https://github.com/3lXample)
 * Licensed under the MIT license
 */
(function() {
  'use strict';

  var name   = '3XApp-example';
  var module = angular.module(name);

  // Add Constants
  module.constant('exampleConstant', 'built by Anisetus Elly Efendi');

  // Add Values
  module.value('exampleValue', 'AngularJS 1.6.5');

})();
<|endoftext|>


<commit_before><commit_msg>fix android<commit_after><|endoftext|>


<commit_before>/**
 * jQuery aSimpleTour
 *
 * @description Tour web
 * @author alvaro.veliz@gmail.com
 * @servedby perkins (http://p.erkins.com)
 *
 * Dependencies :
 * - jQuery scrollTo
 *
 * This idea is based on appTour
 */

(function( $ ) {

  var settings = {
    data : [],
    autoStart : false,
    controlsPosition : 'TR',
    controlsColors : {
      background: 'rgba(8, 68, 142, 0.80)',
      color: '#fff'
    },
    tooltipColors : {
      background: 'rgba(0, 0, 0, 0.70)',
      color: '#fff'
    }
  };

  var options, step, steps;
  var ew, eh, el, et;
  var started = false;

  var $tooltip    = $('
',{
                      id         : 'tourtip',
                      className  : 'tourtip',
                      html       : ''
                    }).css({
                      'display'     : 'none',
                      'padding'     : '10px 20px',
                      'position'    : 'absolute',
                      'font-family' : 'sans-serif',
                      'border-radius' : '5px',
                      'font-size'   : '12px',
                      'box-sizing'  : 'border-box'
                    });

  var methods = {
    init : function( opts ) {
      if (started == false ) {
        started = true;
        options = $.extend(settings, opts);

        controls = '
\

Tour

Welcome to the Tour Plugin

\

\
            <button id="tourPrev" style="display:none">Previous</button>\
            <button id="tourNext">Start</button>\
            <button id="tourEnd" style="display:none">End tour</button>\

\

';
        $controlsCss = { 'display' : 'block', 'position': 'fixed', 'width' : '200px', 'padding' : '10px 20px', 'border-radius' : '10px', 'font-family' : 'sans-serif' };
        $controls = $(controls).css($controlsCss).css(options.controlsColors);
        $cpos = methods.getControlPosition(options.controlsPosition);
        $controls.css($cpos);
        $('body').append($controls);

        $tooltip.css(options.tooltipColors);

        step = -1;
        steps = options.data.length;
        $('body').prepend($tooltip);
      }
    },
    next : function() {
      step++;

      if (step == steps) {
        methods.destroy();
      }
      else {
        $tooltip.hide();
        stepData = options.data[step];

        if (step <= steps) {
          $('#tourPrev').show();
          $('#tourEnd').show();
          $('#tourNext').show().html('Next');
        }

        methods.setTooltip(stepData);
      }
    },
    prev : function() {
      $tooltip.hide();

      if (step < steps) {
        $('#tourNext').show().html('Next');
      }

      if (step <= 0) {
        $('#tourPrev').hide();
        $('#tourEnd').hide();
        $('#tourNext').html('Start');
        step--;
      }
      else {
        step--;
        stepData = options.data[step];

        methods.setTooltip(stepData);
      }
    },
    setTooltip : function(stepData) {
      $element = $(stepData.element);

      if (typeof stepData.callback != 'undefined') {
        if (stepData.callback == 'click') {
          if ($element.attr('href') != '') {
            location.href = $element.attr('href');
          }
          else {
            $element.click();
          }
        }
      }
      else {
        if (stepData.controlsPosition) {
          methods.setControlsPosition(stepData.controlsPosition);
        }

        $tooltip.html(stepData.tooltip);
        if (stepData.text) {
          $('#tourText').html(stepData.text);
        }
        tooltipPos = (typeof stepData.position == 'undefined') ? 'BL' : stepData.position;
        $pos = methods.getTooltipPosition(tooltipPos, $element);

        $tooltip.css({ 'top': $pos.top+'px', 'left': $pos.left+'px' });
        $tooltip.show('fast');

        $.scrollTo($tooltip, 200, { offset : -100});
      }
    },
    setControlsPosition : function(pos) {
      chtml = $controls.html();
      $controls.remove();
      $controls = $(controls).html(chtml);
      $controls = $controls.css($controlsCss).css(options.controlsColors);
      position = methods.getControlPosition(pos);
      $controls.css(position);
      $('body').append($controls);
    },
    getTooltipPosition : function(pos, $e) {
      ew = $element.outerWidth();
      eh = $element.outerHeight();
      el = $element.offset().left;
      et = $element.offset().top;
      tw = $tooltip.width() + parseInt($tooltip.css('padding-left')) + parseInt($tooltip.css('padding-right'));
      th = $tooltip.height() + parseInt($tooltip.css('padding-top')) +  + parseInt($tooltip.css('padding-bottom'));

      $('.tourArrow').remove();
      tbg = $tooltip.css('background-color');

      $upArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-left' : '5px solid transparent', 'border-right' : '5px solid transparent', 'border-bottom' : '5px solid '+tbg });
      $downArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-left' : '5px solid transparent', 'border-right' : '5px solid transparent', 'border-top' : '5px solid '+tbg });
      $rightArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-top' : '5px solid transparent', 'border-bottom' : '5px solid transparent', 'border-left' : '5px solid '+tbg });
      $leftArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-top' : '5px solid transparent', 'border-bottom' : '5px solid transparent', 'border-right' : '5px solid '+tbg });
      switch (pos) {
        case 'BL' :
          position = { 'left'  : el, 'top' : et + eh + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'BR' :
          position = { 'left'  : el + ew - tw, 'top' : et + eh + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'TL' :
          position = { 'left'  : el, 'top' : (et - th) -10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'TR' :
          position = { 'left'  : (el + ew) - tw, 'top' : et - th -10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'RT' :
          position = { 'left'  : el + ew + 10, 'top' : et };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;

        case 'RB' :
          position = { 'left'  : el + ew + 10, 'top' : et + eh - th };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;

        case 'LT' :
          position = { 'left'  : (el - tw) - 10, 'top' : et };
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'LB' :
          position = { 'left'  : (el - tw) - 10, 'top' : et + eh - th};
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'B'  :
          position = { 'left'  : el + ew/2 - tw/2, 'top' : (et + eh) + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'L'  :
          position = { 'left'  : (el - tw) - 10, 'top' : et + eh/2 - th/2 };
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'T'  :
          position = { 'left'  : el + ew/2 - tw/2, 'top' : (et - th) - 10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'R'  :
          position = { 'left'  : (el + ew) + 10, 'top' : et + eh/2 - th/2 };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;
      }
      return position;
    },
    getControlPosition: function(pos) {
      switch (pos)
      {
        case 'TR':
          pos = { 'top' : '10px', 'right' : '10px' };
          break;

        case 'TL':
          pos = { 'top' : '10px', 'left' : '10px' };
          break;

        case 'BL':
          pos = { 'bottom' : '10px', 'left' : '10px' };
          break;

        case 'BR':
          pos = { 'bottom' : '10px', 'right' : '10px' };
          break;
      }
      return pos;
    },
    destroy : function() {
      $('#tourControls').remove();
      $('#tourtip').remove();
      $tooltip.css({ 'display' : 'none' }).html('');
      step = -1;
      started = false;
    }
  };

  $('#tourNext').live('click', function() {
    methods.next();
  });

  $('#tourPrev').live('click', function() {
    methods.prev();
  });

  $('#tourEnd').live('click', function() {
    methods.destroy();
  })

  $.fn.aSimpleTour = function( method )
  {
    if ( methods[method] ) {
      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
    }
    else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    }
    else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.aSimpleTour' );
    }
  };

})(jQuery);

// Direct Access
$.aSimpleTour = function(opts) { $.fn.aSimpleTour(opts); }<commit_msg>welcome message<commit_after>/**
 * jQuery aSimpleTour
 *
 * @description Tour web
 * @author alvaro.veliz@gmail.com
 * @servedby perkins (http://p.erkins.com)
 *
 * Dependencies :
 * - jQuery scrollTo
 *
 * This idea is based on appTour
 */

(function( $ ) {

  var settings = {
    data : [],
    autoStart : false,
    controlsPosition : 'TR',
    welcomeMessage : '
Tour

Welcome to the Tour Plugin
',
    controlsColors : {
      background: 'rgba(8, 68, 142, 0.80)',
      color: '#fff'
    },
    tooltipColors : {
      background: 'rgba(0, 0, 0, 0.70)',
      color: '#fff'
    }
  };

  var options, step, steps;
  var ew, eh, el, et;
  var started = false;

  var $tooltip    = $('
',{
                      id         : 'tourtip',
                      className  : 'tourtip',
                      html       : ''
                    }).css({
                      'display'     : 'none',
                      'padding'     : '10px 20px',
                      'position'    : 'absolute',
                      'font-family' : 'sans-serif',
                      'border-radius' : '5px',
                      'font-size'   : '12px',
                      'box-sizing'  : 'border-box'
                    });

  var methods = {
    init : function( opts ) {
      if (started == false ) {
        started = true;
        options = $.extend(settings, opts);

        controls = '
\

'+options.welcomeMessage+'
\

\
            <button id="tourPrev" style="display:none">Previous</button>\
            <button id="tourNext">Start</button>\
            <button id="tourEnd" style="display:none">End tour</button>\

\

';
        $controlsCss = { 'display' : 'block', 'position': 'fixed', 'width' : '200px', 'padding' : '10px 20px', 'border-radius' : '10px', 'font-family' : 'sans-serif' };
        $controls = $(controls).css($controlsCss).css(options.controlsColors);
        $cpos = methods.getControlPosition(options.controlsPosition);
        $controls.css($cpos);
        $('body').append($controls);

        $tooltip.css(options.tooltipColors);

        step = -1;
        steps = options.data.length;
        $('body').prepend($tooltip);
      }
    },
    next : function() {
      step++;

      if (step == steps) {
        methods.destroy();
      }
      else {
        $tooltip.hide();
        stepData = options.data[step];

        if (step <= steps) {
          $('#tourPrev').show();
          $('#tourEnd').show();
          $('#tourNext').show().html('Next');
        }

        methods.setTooltip(stepData);
      }
    },
    prev : function() {
      $tooltip.hide();

      if (step < steps) {
        $('#tourNext').show().html('Next');
      }

      if (step <= 0) {
        $('#tourPrev').hide();
        $('#tourEnd').hide();
        $('#tourNext').html('Start');
        step--;
      }
      else {
        step--;
        stepData = options.data[step];

        methods.setTooltip(stepData);
      }
    },
    setTooltip : function(stepData) {
      $element = $(stepData.element);

      if (typeof stepData.callback != 'undefined') {
        if (stepData.callback == 'click') {
          if ($element.attr('href') != '') {
            location.href = $element.attr('href');
          }
          else {
            $element.click();
          }
        }
      }
      else {
        if (stepData.controlsPosition) {
          methods.setControlsPosition(stepData.controlsPosition);
        }

        $tooltip.html(stepData.tooltip);
        if (stepData.text) {
          $('#tourText').html(stepData.text);
        }
        tooltipPos = (typeof stepData.position == 'undefined') ? 'BL' : stepData.position;
        $pos = methods.getTooltipPosition(tooltipPos, $element);

        $tooltip.css({ 'top': $pos.top+'px', 'left': $pos.left+'px' });
        $tooltip.show('fast');

        $.scrollTo($tooltip, 200, { offset : -100});
      }
    },
    setControlsPosition : function(pos) {
      chtml = $controls.html();
      $controls.remove();
      $controls = $(controls).html(chtml);
      $controls = $controls.css($controlsCss).css(options.controlsColors);
      position = methods.getControlPosition(pos);
      $controls.css(position);
      $('body').append($controls);
    },
    getTooltipPosition : function(pos, $e) {
      ew = $element.outerWidth();
      eh = $element.outerHeight();
      el = $element.offset().left;
      et = $element.offset().top;
      tw = $tooltip.width() + parseInt($tooltip.css('padding-left')) + parseInt($tooltip.css('padding-right'));
      th = $tooltip.height() + parseInt($tooltip.css('padding-top')) +  + parseInt($tooltip.css('padding-bottom'));

      $('.tourArrow').remove();
      tbg = $tooltip.css('background-color');

      $upArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-left' : '5px solid transparent', 'border-right' : '5px solid transparent', 'border-bottom' : '5px solid '+tbg });
      $downArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-left' : '5px solid transparent', 'border-right' : '5px solid transparent', 'border-top' : '5px solid '+tbg });
      $rightArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-top' : '5px solid transparent', 'border-bottom' : '5px solid transparent', 'border-left' : '5px solid '+tbg });
      $leftArrow = $('

').css({ 'position' : 'absolute', 'display' : 'block', 'width' : '0', 'height' : '0', 'border-top' : '5px solid transparent', 'border-bottom' : '5px solid transparent', 'border-right' : '5px solid '+tbg });
      switch (pos) {
        case 'BL' :
          position = { 'left'  : el, 'top' : et + eh + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'BR' :
          position = { 'left'  : el + ew - tw, 'top' : et + eh + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'TL' :
          position = { 'left'  : el, 'top' : (et - th) -10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'TR' :
          position = { 'left'  : (el + ew) - tw, 'top' : et - th -10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'RT' :
          position = { 'left'  : el + ew + 10, 'top' : et };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;

        case 'RB' :
          position = { 'left'  : el + ew + 10, 'top' : et + eh - th };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;

        case 'LT' :
          position = { 'left'  : (el - tw) - 10, 'top' : et };
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'LB' :
          position = { 'left'  : (el - tw) - 10, 'top' : et + eh - th};
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'B'  :
          position = { 'left'  : el + ew/2 - tw/2, 'top' : (et + eh) + 10 };
          $upArrow.css({ top: '-5px', left: '48%' });
          $tooltip.prepend($upArrow);
          break;

        case 'L'  :
          position = { 'left'  : (el - tw) - 10, 'top' : et + eh/2 - th/2 };
          $rightArrow.css({ right: '-5px' });
          $tooltip.prepend($rightArrow);
          break;

        case 'T'  :
          position = { 'left'  : el + ew/2 - tw/2, 'top' : (et - th) - 10 };
          $downArrow.css({ top: th, left: '48%' });
          $tooltip.append($downArrow);
          break;

        case 'R'  :
          position = { 'left'  : (el + ew) + 10, 'top' : et + eh/2 - th/2 };
          $leftArrow.css({ left: '-5px' });
          $tooltip.prepend($leftArrow);
          break;
      }
      return position;
    },
    getControlPosition: function(pos) {
      switch (pos)
      {
        case 'TR':
          pos = { 'top' : '10px', 'right' : '10px' };
          break;

        case 'TL':
          pos = { 'top' : '10px', 'left' : '10px' };
          break;

        case 'BL':
          pos = { 'bottom' : '10px', 'left' : '10px' };
          break;

        case 'BR':
          pos = { 'bottom' : '10px', 'right' : '10px' };
          break;
      }
      return pos;
    },
    destroy : function() {
      $('#tourControls').remove();
      $('#tourtip').remove();
      $tooltip.css({ 'display' : 'none' }).html('');
      step = -1;
      started = false;
    }
  };

  $('#tourNext').live('click', function() {
    methods.next();
  });

  $('#tourPrev').live('click', function() {
    methods.prev();
  });

  $('#tourEnd').live('click', function() {
    methods.destroy();
  })

  $.fn.aSimpleTour = function( method )
  {
    if ( methods[method] ) {
      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
    }
    else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    }
    else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.aSimpleTour' );
    }
  };

})(jQuery);

// Direct Access
$.aSimpleTour = function(opts) { $.fn.aSimpleTour(opts); }<|endoftext|>


<commit_before>
// Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)

var path = require('path'),
    posix = require('posix')

// --- InvalidPathError

InvalidPathError = ExpressError.extend({
  name: 'InvalidPathError',
  init: function(path) {
    this.message = "`" + path + "' is not a valid path"
  }
})

// --- File

exports.File = Class({

  /**
   * Initialize with file _path_.
   *
   * @param  {string} path
   * @api public
   */

  init: function(path) {
    this.path = path
    if (path.indexOf('..') != -1) throw new InvalidPathError(path)
  },

  /**
   * Transfer static file to the given _request_.
   *
   *  - Ensures the file exists
   *  - Ensures the file is a regular file (not FIFO, Socket, etc)
   *  - Automatically assigns content type
   *
   * @param  {Request} request
   * @settings 'cache static files'
   * @api public
   */

  send: function(request) {
    var cache, file = this.path
    if (set('cache static files') && (cache = request.cache.get(file))) {
      request.contentType(cache.type)
      return request.halt(200, cache.content, 'binary')
    }
    path.exists(file, function(exists){
      if (!exists) return request.halt()
      posix.stat(file).addCallback(function(stats){
        if (!stats.isFile()) return request.halt()
        posix.cat(file, 'binary').addCallback(function(content){
          request.contentType(file)
          if (set('cache static files'))
            request.cache.set(file, { type: file, content: content })
          request.halt(200, content, 'binary')
        })
      })
    })
  }
})<commit_msg>Misc refactoring<commit_after>
// Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)

var path = require('path'),
    posix = require('posix')

// --- InvalidPathError

InvalidPathError = ExpressError.extend({
  name: 'InvalidPathError',
  init: function(path) {
    this.message = "`" + path + "' is not a valid path"
  }
})

// --- File

exports.File = Class({

  /**
   * Initialize with file _path_.
   *
   * @param  {string} path
   * @api public
   */

  init: function(path) {
    this.path = path
    if (path.indexOf('..') != -1) throw new InvalidPathError(path)
  },

  /**
   * Transfer static file to the given _request_.
   *
   *  - Ensures the file exists
   *  - Ensures the file is a regular file (not FIFO, Socket, etc)
   *  - Automatically assigns content type
   *
   * @param  {Request} request
   * @settings 'cache static files'
   * @api public
   */

  send: function(request) {
    var cache, file = this.path
    if (set('cache static files') && (cache = request.cache.get(file)))
      return request.contentType(cache.type),
             request.halt(200, cache.content, 'binary')
    path.exists(file, function(exists){
      if (!exists) return request.halt()
      posix.stat(file).addCallback(function(stats){
        if (!stats.isFile()) return request.halt()
        posix.cat(file, 'binary').addCallback(function(content){
          request.contentType(file)
          if (set('cache static files'))
            request.cache.set(file, { type: file, content: content })
          request.halt(200, content, 'binary')
        })
      })
    })
  }
})<|endoftext|>


<commit_before>// pvta-multiplatform

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'pvta' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'pvta.controllers' is found in controllers.js
angular.module('pvta.controllers', ['pvta.services']);

angular.module('pvta', ['ionic', 'ngCordova', 'pvta.controllers', 'angularMoment', 'jett.ionic.filter.bar'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

.config(function($stateProvider, $urlRouterProvider, $ionicFilterBarConfigProvider) {
  $stateProvider

  .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppController'
  })

  .state('app.my-buses', {
    url: '/my-buses',
    views: {
      'menuContent': {
        templateUrl: 'templates/mybuses.html',
        controller: 'MyBusesController'
      }
    }
  })
  .state('app.search', {
    url: '/search',
    views: {
      'menuContent': {
        templateUrl: 'templates/search.html',
        controller: 'SearchController'
      }
    }
  })
    .state('app.vehicle', {
    url: "/vehicles/:vehicleId",
    views: {
        'menuContent': {
          templateUrl: "templates/vehicle.html",
          controller: 'VehicleController'
        }
    }
  })

  .state('app.routes',{
      url: "/routes",
      views: {
        'menuContent': {
           templateUrl: "templates/routes.html",
           controller: 'RoutesController'
        }
      }
    })

  .state('app.route', {
    url: "/routes/:routeId",
    views: {
        'menuContent': {
          templateUrl: "templates/route.html",
          controller: 'RouteController'
        }
    }
  })

  .state('app.stop', {
    url: "/stops/:stopId",
    views: {
        'menuContent': {
          templateUrl: "templates/stop.html",
          controller: 'StopController'
        }
    }
  })

  .state('app.stops', {
    url: "/stops",
    views: {
      'menuContent': {
        templateUrl: "templates/stops.html",
        controller: 'StopsController'
      }
    }
  })

  .state('app.map', {
    url: "/map",
    views: {
        'menuContent': {
          templateUrl: "templates/map.html",
          controller: 'MapController'
        }
    }
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/my-buses');
});
<commit_msg>Added support for Android status bar color changes in app.js<commit_after>// pvta-multiplatform

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'pvta' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'pvta.controllers' is found in controllers.js
angular.module('pvta.controllers', ['pvta.services']);

angular.module('pvta', ['ionic', 'ngCordova', 'pvta.controllers', 'angularMoment', 'jett.ionic.filter.bar'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
  });
  /******************************************************
  * Set the status bar color to our app's color.
  *********************************************************
  * Only after the device has specifically told us it's ready
  * may we access the global StatusBar object.
  * **************************************************/
  document.addEventListener("deviceready", onDeviceReady, true);
  function onDeviceReady() {
    StatusBar.backgroundColorByHexString("#387ef5");
  };
})

.config(function($stateProvider, $urlRouterProvider, $ionicFilterBarConfigProvider) {
  $stateProvider

  .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppController'
  })

  .state('app.my-buses', {
    url: '/my-buses',
    views: {
      'menuContent': {
        templateUrl: 'templates/mybuses.html',
        controller: 'MyBusesController'
      }
    }
  })
  .state('app.search', {
    url: '/search',
    views: {
      'menuContent': {
        templateUrl: 'templates/search.html',
        controller: 'SearchController'
      }
    }
  })
    .state('app.vehicle', {
    url: "/vehicles/:vehicleId",
    views: {
        'menuContent': {
          templateUrl: "templates/vehicle.html",
          controller: 'VehicleController'
        }
    }
  })

  .state('app.routes',{
      url: "/routes",
      views: {
        'menuContent': {
           templateUrl: "templates/routes.html",
           controller: 'RoutesController'
        }
      }
    })

  .state('app.route', {
    url: "/routes/:routeId",
    views: {
        'menuContent': {
          templateUrl: "templates/route.html",
          controller: 'RouteController'
        }
    }
  })

  .state('app.stop', {
    url: "/stops/:stopId",
    views: {
        'menuContent': {
          templateUrl: "templates/stop.html",
          controller: 'StopController'
        }
    }
  })

  .state('app.stops', {
    url: "/stops",
    views: {
      'menuContent': {
        templateUrl: "templates/stops.html",
        controller: 'StopsController'
      }
    }
  })

  .state('app.map', {
    url: "/map",
    views: {
        'menuContent': {
          templateUrl: "templates/map.html",
          controller: 'MapController'
        }
    }
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/my-buses');
});
<|endoftext|>


<commit_before>$(document).ready(function() {
//if click_counter is odd, display "Player one go!"
  //if odd, div color change to red
  //if click_counter is even, display "player two"
  //if even, div color change to black
  //if click_counter >42, game ends

  var click_counter = 1;
  var clickLocation = {};

  $('.container').on("click", '.col', function(event){
    clickLocation = $(event.target);
    currentTarget = $("#" + currentColumn(clickLocation) + " div.empty").last();
    illegalClick();
    addClickCounter();
    notifyPlayerTurn();
    addPieceToColumn();
    verticalCheck();
    horizontalCheck();
    diagonalCheck();
  });

  //alert if click didn't register correctly
  var illegalClick = function() {
    if(currentTarget.length <= 0) {
      alert("Oops! Only click in the white, please!")
    };
  };

  //check for diagonal winner

  var diagonalCheck = function() {
    var columnStart = Number(currentColumn(clickLocation))
    var rowStart = Number(targetRow(currentTarget))
    var diag1ColorsArray = []
    var diag2ColorsArray = []
    var diagGroup1 = []
    var diagGroup2 = []

// add spaces to array to check for diagonal wins
    if(columnStart === 1) {
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 2) {
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 3) {
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 4) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 5) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
    }else if(columnStart === 6) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
    }else if(columnStart === 7){
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
    };
    console.log(diagGroup1);
    console.log(diagGroup2);
    for(var i=0; i < diagGroup1.length; i++){
      currentClasswithinGroup = diagGroup1[i][0]
      if(currentClasswithinGroup){
        diag1ColorsArray.push(diagGroup1[i][0].classList[2])
      };
    };

    for(var i=0; i < diagGroup2.length; i++){
      currentClasswithinGroup = diagGroup2[i][0]
      if(currentClasswithinGroup){
        diag2ColorsArray.push(diagGroup2[i][0].classList[2])
      };
    };

    var diag1ColorsString = diag1ColorsArray.join('');
    var diag2ColorsString = diag2ColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(diag1ColorsString) === true || blkWin.test(diag2ColorsString) === true || redWin.test(diag1ColorsString) === true || redWin.test(diag2ColorsString) === true) {
      alert(currentPlayer + " is a winner! Moop Moop!")
    };

  };

  //check for horizontal winner

  var horizontalCheck = function() {
    var horizGroup = $("." + targetRow(currentTarget));
    // console.log(horizGroup);
    var horizColorsArray = []

    for(var i=0; i < horizGroup.length; i++) {
      horizColorsArray.push(horizGroup[i].classList[2]);
    };

    var horizColorsString = horizColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(horizColorsString) === true || redWin.test(horizColorsString) === true) {
        alert(currentPlayer + " is a winner! Moop Moop!")
    };

  };

  //check for vertical winner

  var verticalCheck = function(){
    // need to replace way of collecting group - only adds to group if clicked above the target, but not on the target

    vertGroup = $("#"+ currentColumn(clickLocation)).children();
    // console.log(vertGroup);
    vertColorsArray = []

    for(var i=0; i < vertGroup.length; i++) {
      vertColorsArray.push(vertGroup[i].classList[2]);
      // console.log(vertColorsArray);
    };

    var vertColorsString = vertColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(vertColorsString) === true || redWin.test(vertColorsString) === true) {
        alert(currentPlayer + " is a winner! Moop Moop!")
    };
  };

  var addClickCounter = function(){
    click_counter ++;
    $(".click_counter").text(click_counter);

  };

  var playerOne = 'red';
  var playerTwo = 'black';
  currentPlayer = playerOne;

  var notifyPlayerTurn = function(){
    $('.p1').toggleClass('hide');
    $('.p2').toggleClass('hide');
    if(click_counter % 2 != 0){
      // $('.col').css({'background-color': 'pink'})
      currentPlayer = playerTwo;
    }
    else{
      // $('.col').css({'background-color': 'gray'})
      currentPlayer = playerOne;
    }
  };

  var addPieceToColumn = function(){
    var columnName = currentColumn(clickLocation);
    // set player colors

    var target = $("#" + columnName + " div.empty").last();
    target.removeClass("empty");
    target.addClass(currentPlayer);
    target.css({"background-color": currentPlayer});
    // console.log(target);

    if(click_counter > 42) {
      alert("Game Over! You're equally talented!")
    };

  };

});

<commit_msg>illegal click as edge case<commit_after>$(document).ready(function() {
//if click_counter is odd, display "Player one go!"
  //if odd, div color change to red
  //if click_counter is even, display "player two"
  //if even, div color change to black
  //if click_counter >42, game ends

  var click_counter = 1;
  var clickLocation = {};

  $('.container').on("click", '.col', function(event){
    clickLocation = $(event.target);
    currentTarget = $("#" + currentColumn(clickLocation) + " div.empty").last();

    if(currentTarget.length <= 0) {
      alert("Oops! Only click in the white, please!")
    } else {

      addClickCounter();
      notifyPlayerTurn();
      addPieceToColumn();
      verticalCheck();
      horizontalCheck();
      diagonalCheck();
    };

  });

  //alert if click didn't register correctly
  //added code to game flow

  // var illegalClick = function() {
  //   if(currentTarget.length <= 0) {
  //     alert("Oops! Only click in the white, please!")
  //   };
  // };

  //check for diagonal winner

  var diagonalCheck = function() {
    var columnStart = Number(currentColumn(clickLocation))
    var rowStart = Number(targetRow(currentTarget))
    var diag1ColorsArray = []
    var diag2ColorsArray = []
    var diagGroup1 = []
    var diagGroup2 = []

// add spaces to array to check for diagonal wins
    if(columnStart === 1) {
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 2) {
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 3) {
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 4) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup1.push($("#" + (columnStart + 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
      diagGroup2.push($("#" + (columnStart + 3) + " ." + (rowStart + 3)))
    }else if(columnStart === 5) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup1.push($("#" + (columnStart + 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
      diagGroup2.push($("#" + (columnStart + 2) + " ." + (rowStart + 2)))
    }else if(columnStart === 6) {
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup1.push($("#" + (columnStart + 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart + 1) + " ." + (rowStart + 1)))
    }else if(columnStart === 7){
      diagGroup1.push($("#" + (columnStart - 3) + " ." + (rowStart + 3)))
      diagGroup1.push($("#" + (columnStart - 2) + " ." + (rowStart + 2)))
      diagGroup1.push($("#" + (columnStart - 1) + " ." + (rowStart + 1)))
      diagGroup1.push($("#" + columnStart + " ." + rowStart))
      diagGroup2.push($("#" + (columnStart - 3) + " ." + (rowStart - 3)))
      diagGroup2.push($("#" + (columnStart - 2) + " ." + (rowStart - 2)))
      diagGroup2.push($("#" + (columnStart - 1) + " ." + (rowStart - 1)))
      diagGroup2.push($("#" + columnStart + " ." + rowStart))
    };
    console.log(diagGroup1);
    console.log(diagGroup2);
    for(var i=0; i < diagGroup1.length; i++){
      currentClasswithinGroup = diagGroup1[i][0]
      if(currentClasswithinGroup){
        diag1ColorsArray.push(diagGroup1[i][0].classList[2])
      };
    };

    for(var i=0; i < diagGroup2.length; i++){
      currentClasswithinGroup = diagGroup2[i][0]
      if(currentClasswithinGroup){
        diag2ColorsArray.push(diagGroup2[i][0].classList[2])
      };
    };

    var diag1ColorsString = diag1ColorsArray.join('');
    var diag2ColorsString = diag2ColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(diag1ColorsString) === true || blkWin.test(diag2ColorsString) === true || redWin.test(diag1ColorsString) === true || redWin.test(diag2ColorsString) === true) {
      alert(currentPlayer + " is a winner! Moop Moop!")
    };

  };

  //check for horizontal winner

  var horizontalCheck = function() {
    var horizGroup = $("." + targetRow(currentTarget));
    // console.log(horizGroup);
    var horizColorsArray = []

    for(var i=0; i < horizGroup.length; i++) {
      horizColorsArray.push(horizGroup[i].classList[2]);
    };

    var horizColorsString = horizColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(horizColorsString) === true || redWin.test(horizColorsString) === true) {
        alert(currentPlayer + " is a winner! Moop Moop!")
    };

  };

  //check for vertical winner

  var verticalCheck = function(){
    // need to replace way of collecting group - only adds to group if clicked above the target, but not on the target

    vertGroup = $("#"+ currentColumn(clickLocation)).children();
    // console.log(vertGroup);
    vertColorsArray = []

    for(var i=0; i < vertGroup.length; i++) {
      vertColorsArray.push(vertGroup[i].classList[2]);
      // console.log(vertColorsArray);
    };

    var vertColorsString = vertColorsArray.join('');
      blkWin = (/blackblackblackblack/)
      redWin = (/redredredred/)

    if(blkWin.test(vertColorsString) === true || redWin.test(vertColorsString) === true) {
        alert(currentPlayer + " is a winner! Moop Moop!")
    };
  };

  var addClickCounter = function(){
    click_counter ++;
    $(".click_counter").text(click_counter);

  };

  var playerOne = 'red';
  var playerTwo = 'black';
  currentPlayer = playerOne;

  var notifyPlayerTurn = function(){
    $('.p1').toggleClass('hide');
    $('.p2').toggleClass('hide');
    if(click_counter % 2 != 0){
      // $('.col').css({'background-color': 'pink'})
      currentPlayer = playerTwo;
    }
    else{
      // $('.col').css({'background-color': 'gray'})
      currentPlayer = playerOne;
    }
  };

  var addPieceToColumn = function(){
    var columnName = currentColumn(clickLocation);
    // set player colors

    var target = $("#" + columnName + " div.empty").last();
    target.removeClass("empty");
    target.addClass(currentPlayer);
    target.css({"background-color": currentPlayer});
    // console.log(target);

    if(click_counter > 42) {
      alert("Game Over! You're equally talented!")
    };

  };

});

<|endoftext|>