<commit_before>
/**
 * Binding Component Class
 *
 * @class UI.Component.Binding
 * @author Jerome Vial, Bruno Santos
 */
define([

], function(

) {

	var _log = __debug('ui:binding');
		//_log.defineLevel('DEBUG');

	var exports = new Class({

		options: {
			api: {
				emit: 'trigger'
			}
		},

		/**
		 * Events communication controller
		 * Event bindings
		 * @return {Object} The class instance
		 */
		_initBinding: function(binding) {
			binding = binding || this.options.binding;
			this.binding = this.binding || {};
			if (!binding) {
				return;
			}

			if (!binding._list) {
				this._bindObject(binding);

			} else {
				var list = binding._list;

				for (var i = 0; list.length > i; i++ ) {
					var bind = binding[list[i]];

					this._bindObject(bind);
				}
			}

			return this.binding;
		},

		/**
		 * Bind an object
		 * @param  {Object} obj obj whit key and value to be bound
		 * @return {void}
		 */
		_bindObject: function(obj) {
			//_log.debug('_bindObject', obj);
			for (var key in obj) {
				var value = obj[key];

				if (typeof value != 'object') {
					this._bindkey(key, value);
				} else {
					this._bindList(key, value);
				}
			}
		},

		/**
		 * Bind a list of events to a specific object
		 * @param  {string} key Object path that will listen
		 * @param  {Array} values List if values to bind
		 * @return {void}
		 */
		_bindList: function(key, values) {
			//_log.debug('_bindList', key, values);
			for (var i = 0; i < values.length; i++) {
				this._bindkey(key, values[i]);
			}
		},

		/**
		 * Bind to object path
		 * get the event,
		 * get the reference to the last key of the first object,
		 * check if there is a event or a mehtod to bind
		 * @param  {string} key Object path that will listen
		 * @param  {string} val Object path to be bound
		 * @return {void}
		 */
		_bindkey: function(key, val) {
			_log.debug('_bindkey', key, val);
			var eventKeys = key.split('.');
			var ev = eventKeys[eventKeys.length - 1];

			eventKeys.pop();
			var listenerCtx = this._path(eventKeys.join('.'));

			var valKeys = val.split('.');

			//check if it's an event
			if (valKeys[valKeys.length - 2] == this.options.api.emit) {
				var emit = valKeys[valKeys.length - 1];
				this._bindEvent(listenerCtx, ev, emit, val);
			} else {
				this._bindMethod(listenerCtx, ev, val);
			}
		},

		/**
		 * Listen to the given event and trigger another
		 * @param  {Object} listenerCtx Object to listen
		 * @param  {string} ev Event that will be listened
		 * @param  {string} emit Event that will be emitted
		 * @param  {string} val Method path to be bound
		 * @return {void}
		 */
		_bindEvent: function(listenerCtx, ev, emit, val) {
			_log.debug('_bindEvent', listenerCtx, ev, emit, val);
			var emitter = this.options.api.emit;

			var valKeys = val.split('.');
			valKeys.splice(-2, 2);

			var boundCtx = this._path(valKeys.join('.'));

			if (listenerCtx && listenerCtx.addEvent && boundCtx && boundCtx.fireEvent) {
				listenerCtx.addEvent(ev, boundCtx.fireEvent.bind(boundCtx, emit));
				// keep track of the binding
				this.binding[ev] = event;
			} else if (listenerCtx && listenerCtx.on && boundCtx && boundCtx.fireEvent) {
				this.binding[ev] = event;
				listenerCtx.on(ev, boundCtx.fireEvent.bind(boundCtx, emit));
			} else {
				_log.debug('Missing context or method', listenerCtx, val);
			}
		},

		/**
		 * Listen to the given event and bind to the given method
		 * @param  {Object} listenerCtx Object to listen
		 * @param  {string} ev Event that will be listened
		 * @param  {string} val Method path to be bound
		 * @return {void}
		 */
		_bindMethod: function(listenerCtx, ev, val) {
			//_log.debug('_bindMethod', listenerCtx, ev, val);
			var method = this._path(val);

			var valKeys = val.split('.');
			valKeys.pop();
			var boundCtx = this._path(valKeys.join('.'));

			if (listenerCtx && listenerCtx.addEvent && method) {
				listenerCtx.addEvent(ev, method.bind(boundCtx));
				// keep track of the binding
				this.binding[ev] = method;
			} else if (listenerCtx && listenerCtx.on && method) {
				this.binding[ev] = method;
				listenerCtx.on(ev, method.bind(boundCtx));
			} else {
				//_log.debug('Missing context or method', listenerCtx, val);
			}
		},

		/**
		 * Return the last reference to a object
		 * @param  {string} str Object path for example key1.key2.key3
		 * @return {Object}
		 */
		_path: function(str) {
			//_log.debug('_path', str);
			if (!str) return this;
			else if (!str.match(/\./)) return this[str];

			var last;

			var keys = str.split('.');
			for (var i = 0, l = keys.length; i < l; i++) {
				var key = keys[i];

				last = last || this;
				last = last[key];
			}

			return last;
		}

	});

	return exports;
});
<commit_msg>general improvements in component binding (support more objects structures)<commit_after>/**
 * Binding Core Module Class
 * @class Core.Module.Binding
 * @author Jerome Vial, Bruno Santos
 */
(function(root, factory) {
	if (typeof define === 'function' && define.amd) {
		define([], factory);
	} else if (typeof exports === 'object') {
		module.exports = factory();
	} else {
		root.returnExports = factory();
	}
}(this, function() {

	var _log = __debug('core:module-binding').defineLevel();

	if (typeof define !== 'function') {
		Class = require('primish');
		Events = require('primish/emitter');
	}

	var exports = new Class({

		Implements: [Events],

		options: {
			api: {
				emit: 'trigger'
			}
		},

		/**
		 * Initialize
		 * @return {void}
		 */
		initialize: function() {
			_log.debug('initialize binding');

			var self = this;

			this.addEvent('initReady', function() {
				self._initBinding.bind(this)();
			});
		},

		/**
		 * Events communication controller
		 * Event bindings
		 * @return {Object}
		 */
		_initBinding: function(binding) {
			binding = binding || this.options.controller;

			this.binding = this.binding || {};

			_log.debug('_initBinding', this.options.name, binding);

			if (!binding) {
				_log.debug('missing binding options');
				return;
			}

			if (!binding._list) {
				this._bindObject(binding);
				return;
			}

			var list = binding._list;

			//_log.debug(list, binding);

			for (var i = 0; list.length > i; i++) {
				var bind = binding[list[i]];
				this.binding = this.binding || {};

				this._bindObject(bind);
			}

			if (this.fireEvent) {
				this.fireEvent('bindingsReady');
			} else if (this.trigger) {
				this.trigger('bindingsReady');
			}

			return this.binding;
		},

		/**
		 * Bind an object
		 * @param  {Object} obj obj whit key and value to be bound
		 * @return {void}
		 */
		_bindObject: function(obj) {
			//_log.debug('_bindObject', obj);

			for (var key in obj) {
				if (!obj.hasOwnProperty(key)) {
					continue;
				}
				var value = obj[key];

				if (typeof value !== 'object') {
					this._bindkey(key, value);
				} else {
					this._bindList(key, value);
				}
			}
		},

		/**
		 * Bind a list of events to a specific object
		 * @param  {string} key Object path that will listen
		 * @param  {Array} values List if values to bind
		 * @return {void}
		 */
		_bindList: function(key, values) {
			//_log.debug('_bindList', key, values);

			for (var i = 0; i < values.length; i++) {
				this._bindkey(key, values[i]);
			}
		},

		/**
		 * Bind to object path
		 * get the event,
		 * get the reference to the last key of the first object,
		 * check if there is a event or a mehtod to bind
		 * @param  {string} key Object path that will listen
		 * @param  {string} val Object path to be bound
		 * @return {void}
		 */
		_bindkey: function(key, val) {
			//_log.debug('_bindkey', key, val);

			var eventKeys = key.split('.');
			var ev = eventKeys[eventKeys.length - 1];
			eventKeys.pop();
			var listenerCtx = this._path(eventKeys.join('.'));

			//handle obj
			var obj = this._getObj(listenerCtx, val);
			if (obj) {
				for (var newCtx in obj) {
					if (!obj.hasOwnProperty(newCtx)) {
						continue;
					}
					var newKey = eventKeys.join('.') + '.' + newCtx + '.' + ev;
					//_log.debug('_bindkey', newKey, val);
					this._bindkey(newKey, val);
				}
				return;
			}

			//handle args
			var args;
			if (typeof val === 'object') {
				for (var k in val) {
					if (!val.hasOwnProperty(k)) {
						continue;
					}
					break;
				}
				args = this._processKeyObj(k, val);
				val = k;
			}

			var valKeys = val.split('.');

			//Check if it's an event
			if (valKeys[valKeys.length - 2] === this.options.api.emit) {
				var emit = valKeys[valKeys.length - 1];
				this._bindEvent(listenerCtx, ev, emit, val);
			} else {
				this._bindMethod(listenerCtx, ev, val, args);
			}
		},

		/**
		 * Process Key Obj
		 * @param  {string} key
		 * @param  {Object} val
		 * @return {Object}
		 */
		_processKeyObj: function(key, val) {
			//_log.debug('_processKeyObj', key, val);

			var args = val[key];

			for (var i = 0; i < args.length; i++) {
				var arg = args[i];

				if (arg.split('.')[0] === 'this') {
					arg = arg.split('.');
					arg.shift();
					args[i] = this._path(arg.join('.'));
				}
			}

			return args;
		},

		/**
		 * Listen to the given event and trigger another
		 * @param  {Object} listenerCtx Object to listen
		 * @param  {string} ev Event that will be listened
		 * @param  {string} emit Event that will be emitted
		 * @param  {string} val Method path to be bound
		 * @return {void}
		 */
		_bindEvent: function(listenerCtx, ev, emit, val) {
			//_log.debug('_bindEvent', listenerCtx, ev, emit, val);

			var emitter = this.options.api.emit;

			var valKeys = val.split('.');
			var save = valKeys[valKeys.length - 1];
			valKeys.splice(-2, 2);
			var boundCtx = this._path(valKeys.join('.'));

			//handle obj
			var obj = this._getObj(boundCtx, val);
			if (obj) {
				for (var newCtx in obj) {
					if (!obj.hasOwnProperty(newCtx)) {
						continue;
					}
					var newKey = valKeys.join('.') + '.' + newCtx + '.' + emitter + '.' + save;
					//_log.debug('_bindEvent', newKey);
					this._bindEvent(listenerCtx, ev, emit, newKey);
				}
				return;
			}

			if (listenerCtx && listenerCtx.addEvent && boundCtx && boundCtx.fireEvent) {
				//_log.debug('bind val', val);
				listenerCtx.addEvent(ev, boundCtx.fireEvent.bind(boundCtx, emit));
				// keep track of the binding
				this.binding[ev] = event;
			} else if (listenerCtx && listenerCtx.on && boundCtx && boundCtx.fireEvent) {
				this.binding[ev] = event;
				listenerCtx.on(ev, boundCtx.fireEvent.bind(boundCtx, emit));
			} else {
				_log.warn('missing context or method', listenerCtx, val, this);
			}
		},

		/**
		 * Listen to the given event and bind to the given method
		 * @param  {Object} listenerCtx Object to listen
		 * @param  {string} ev Event that will be listened
		 * @param  {string} val Method path to be bound
		 * @return {void}
		 */
		_bindMethod: function(listenerCtx, ev, val, args) {
			//_log.debug('_bindMethod', listenerCtx, ev, val);
			var method = this._path(val);

			var valKeys = val.split('.');
			valKeys.pop();
			var boundCtx = this._path(valKeys.join('.'));

			//handle obj
			var obj = this._getObj(boundCtx, val);
			if (obj) {
				for (var newCtx in obj) {
					if (!obj.hasOwnProperty(newCtx)) {
						continue;
					}
					var newKey = valKeys.slice(0, 2).join('.');
					newKey = val.replace(newKey, newKey + '.' + newCtx);
					//_log.debug('_bindMethod', newKey);
					this._bindMethod(listenerCtx, ev, newKey, args);
				}
				return;
			}

			if (listenerCtx && listenerCtx.addEvent && method) {
				if (args) {
					listenerCtx.addEvent(ev, method.bind(boundCtx, args));
				} else {
					listenerCtx.addEvent(ev, method.bind(boundCtx));
				}
				// keep track of the binding
				this.binding[ev] = method;
			} else if (listenerCtx && listenerCtx.on && method) {
				this.binding[ev] = method;
				listenerCtx.on(ev, method.bind(boundCtx));
			} else {
				_log.warn('missing context or method', listenerCtx, val, this);
			}
		},

		/**
		 * Return the last reference to a object
		 * @param  {string} str Object path for example key1.key2.key3
		 * @return {Object}
		 */
		_path: function(str) {
			//_log.debug('_path', str);
			if (!str) {
				return this;
			} else if (!str.match(/\./)) {
				return this[str];
			}

			var last;

			var keys = str.split('.');
			for (var i = 0, l = keys.length; i < l; i++) {
				var key = keys[i];

				last = last || this;
				last = last[key];
			}

			return last;
		},

		_getObj: function(ctx, str) {

			if (ctx && ctx.constructor && ctx.constructor.name === 'Object') {
				for (var first in ctx) {
					if (!ctx.hasOwnProperty(first)) {
						continue;
					}
					break;
				}
				if (str.indexOf(first) !== -1) {
					return;
				}
				//_log.debug('_getObj', str, ctx, first);
				return ctx;
			}
		},

	});

	return exports;

}));
<|endoftext|>


<commit_before><commit_msg>style: review fix<commit_after><|endoftext|>


<commit_before><?xml version="1.0" encoding="utf-8"?>
<project path="" name="Bridge.NET" author="Object.NET, Inc." version="1.10.0" copyright="@version   : 1.10.0 - Bridge.NET
@author    : Object.NET, Inc. http://bridge.net/
@date      : 2015-11-18
@copyright : Copyright (c) 2008-2015, Object.NET, Inc. (http://object.net/). All rights reserved.
@license   : See license.txt and https://github.com/bridgedotnet/Bridge.NET/blob/master/LICENSE." output="$project" source="False" minify="False" doc="False" master="true" zip="true">
  <file name="Init.js" />
  <file name="End.js" />
  <file name="Core.js" />
  <file name="Nullable.js" />
  <file name="Char.js" />
  <file name="String.js" />
  <file name="Enum.js" />
  <file name="Class.js" />
  <file name="Exception.js" />
  <file name="Interfaces.js" />
  <file name="Globalization.js" />
  <file name="Math.js" />
  <file name="Integer.js" />
  <file name="Decimal.js" />
  <file name="Date.js" />
  <file name="TimeSpan.js" />
  <file name="Text/StringBuilder.js" />
  <file name="Text/Regex.js" />
  <file name="Collections/Interfaces.js" path="Collections" />
  <file name="Collections/CustomEnumerator.js" path="Collections" />
  <file name="Collections/ArrayEnumerator.js" path="Collections" />
  <file name="Collections/EqualityComparer.js" path="Collections" />
  <file name="Collections/Comparer.js" path="Collections" />
  <file name="Collections/Dictionary.js" path="Collections" />
  <file name="Collections/List.js" path="Collections" />
  <file name="Browser.js" />
  <file name="Task.js" />
  <file name="Validation.js" />
  <file name="Version.js" />
  <file name="Attribute.js" />
  <file name="INotifyPropertyChanged.js" />
  <file name="Array.js" />
  <file name="linq.js" />
  <target name="Bridge.NET" file="$output\bridge.js" debug="True">
    <include name="Init.js" />
    <include name="Core.js" />
    <include name="Nullable.js" />
    <include name="Char.js" />
    <include name="String.js" />
    <include name="Enum.js" />
    <include name="Class.js" />
    <include name="Exception.js" />
    <include name="Interfaces.js" />
    <include name="Globalization.js" />
    <include name="Math.js" />
    <include name="Integer.js" />
    <include name="Decimal.js" />
    <include name="Date.js" />
    <include name="TimeSpan.js" />
    <include name="Text/StringBuilder.js" />
    <include name="Text/Regex.js" />
    <include name="Browser.js" />
    <include name="Array.js" />
    <include name="Collections/Interfaces.js" />
    <include name="Collections/CustomEnumerator.js" />
    <include name="Collections/ArrayEnumerator.js" />
    <include name="Collections/EqualityComparer.js" />
    <include name="Collections/Comparer.js" />
    <include name="Collections/Dictionary.js" />
    <include name="Collections/List.js" />
    <include name="Task.js" />
    <include name="Validation.js" />
    <include name="Version.js" />
    <include name="Attribute.js" />
    <include name="INotifyPropertyChanged.js" />
    <include name="linq.js" />
    <include name="End.js" />
  </target>
</project><commit_msg>Updated release date<commit_after><?xml version="1.0" encoding="utf-8"?>
<project path="" name="Bridge.NET" author="Object.NET, Inc." version="1.10.0" copyright="@version   : 1.10.0 - Bridge.NET
@author    : Object.NET, Inc. http://bridge.net/
@date      : 2015-11-23
@copyright : Copyright (c) 2008-2015, Object.NET, Inc. (http://object.net/). All rights reserved.
@license   : See license.txt and https://github.com/bridgedotnet/Bridge.NET/blob/master/LICENSE." output="$project" source="False" minify="False" doc="False" master="true" zip="true">
  <file name="Init.js" />
  <file name="End.js" />
  <file name="Core.js" />
  <file name="Nullable.js" />
  <file name="Char.js" />
  <file name="String.js" />
  <file name="Enum.js" />
  <file name="Class.js" />
  <file name="Exception.js" />
  <file name="Interfaces.js" />
  <file name="Globalization.js" />
  <file name="Math.js" />
  <file name="Integer.js" />
  <file name="Decimal.js" />
  <file name="Date.js" />
  <file name="TimeSpan.js" />
  <file name="Text/StringBuilder.js" />
  <file name="Text/Regex.js" />
  <file name="Collections/Interfaces.js" path="Collections" />
  <file name="Collections/CustomEnumerator.js" path="Collections" />
  <file name="Collections/ArrayEnumerator.js" path="Collections" />
  <file name="Collections/EqualityComparer.js" path="Collections" />
  <file name="Collections/Comparer.js" path="Collections" />
  <file name="Collections/Dictionary.js" path="Collections" />
  <file name="Collections/List.js" path="Collections" />
  <file name="Browser.js" />
  <file name="Task.js" />
  <file name="Validation.js" />
  <file name="Version.js" />
  <file name="Attribute.js" />
  <file name="INotifyPropertyChanged.js" />
  <file name="Array.js" />
  <file name="linq.js" />
  <target name="Bridge.NET" file="$output\bridge.js" debug="True">
    <include name="Init.js" />
    <include name="Core.js" />
    <include name="Nullable.js" />
    <include name="Char.js" />
    <include name="String.js" />
    <include name="Enum.js" />
    <include name="Class.js" />
    <include name="Exception.js" />
    <include name="Interfaces.js" />
    <include name="Globalization.js" />
    <include name="Math.js" />
    <include name="Integer.js" />
    <include name="Decimal.js" />
    <include name="Date.js" />
    <include name="TimeSpan.js" />
    <include name="Text/StringBuilder.js" />
    <include name="Text/Regex.js" />
    <include name="Browser.js" />
    <include name="Array.js" />
    <include name="Collections/Interfaces.js" />
    <include name="Collections/CustomEnumerator.js" />
    <include name="Collections/ArrayEnumerator.js" />
    <include name="Collections/EqualityComparer.js" />
    <include name="Collections/Comparer.js" />
    <include name="Collections/Dictionary.js" />
    <include name="Collections/List.js" />
    <include name="Task.js" />
    <include name="Validation.js" />
    <include name="Version.js" />
    <include name="Attribute.js" />
    <include name="INotifyPropertyChanged.js" />
    <include name="linq.js" />
    <include name="End.js" />
  </target>
</project>
<|endoftext|>


<commit_before>

    function IOMMarker(info, diameter, image, map) {
      this.latlng_ = new google.maps.LatLng(parseFloat(info.lat),parseFloat(info.lon));
      this.url = info.url;
      this.count = info.count;
      this.total_in_region = info.total_in_region;
      this.image = image;
    	this.map_ = map;
    	this.name = info.name;
    	this.diameter = diameter;

      this.offsetVertical_ = -(this.diameter/2);
      this.offsetHorizontal_ = -(this.diameter/2);
      this.height_ = this.diameter;
      this.width_ = this.diameter;

      this.setMap(map);
    }

    IOMMarker.prototype = new google.maps.OverlayView();

    IOMMarker.prototype.draw = function() {

      var me = this;
    	var num = 0;

      var div = this.div_;
      if (!div) {
        div = this.div_ = document.createElement('div');
        div.style.border = "none";
        div.style.position = "absolute";
    		div.style.width = this.diameter + 'px';
    		div.style.height = this.diameter + 'px';
    		div.style.zIndex = 1;
        div.style.cursor = "pointer";

    		//Marker image
        var marker_image = document.createElement('img');
        marker_image.style.position = "relative";
        marker_image.style.width = "100%";
        marker_image.style.height = "100%";
        marker_image.src = this.image;
        div.appendChild(marker_image);

        if(this.count>1) {
            var count = document.createElement('p');
            count.style.position = "absolute";
            count.style.top = "50%";
            count.style.left = "50%";
            count.style.height = "15px";
            count.style.textAlign = "center";
            if (this.diameter==20) {
              count.style.margin ="-6px 0 0 0px";
              count.style.font = "normal 10px Arial";
            } else if (this.diameter==26) {
              count.style.margin ="-6px 0 0 0px";
              count.style.font = "normal 11px Arial";
            } else if (this.diameter==34) {
              count.style.margin ="-7px 0 0 0px";
              count.style.font = "normal 12px Arial";
            } else if (this.diameter==42) {
              count.style.margin ="-7px 0 0 0px";
              count.style.font = "normal 15px Arial";
            } else {
              count.style.margin ="-9px 0 0 0px";
              count.style.font = "normal 18px Arial";
            }
            count.style.color = "white";
            $(count).text(this.count);
            div.appendChild(count);
        }

        //Marker address
        if (map_type=="overview_map") {

          var hidden_div = document.createElement('div');
          hidden_div.style.border = "none";
          hidden_div.style.position = "absolute";
          hidden_div.style.margin = "0px";
          hidden_div.style.padding = "0px";
          hidden_div.style.display = "none";
          hidden_div.style.bottom = this.diameter + 4 +"px";
          hidden_div.style.left = (this.diameter/2)-(175/2)+"px";
          hidden_div.style.width = '175px';

          try {
          if (kind!=null) {
            var top_hidden = document.createElement('div');
            top_hidden.style.border = "none";
            top_hidden.style.position = "relative";
            top_hidden.style.float = "left";
            top_hidden.style.padding = "9px 15px 3px 11px";
            top_hidden.style.width = '149px';
            top_hidden.style.height = 'auto';
            top_hidden.style.background = "url('/images/sites/common/tooltips/body_tooltip.png') no-repeat center top";
            top_hidden.style.font = "normal 17px 'PT Sans Bold'";
            top_hidden.style.textAlign = "center";
            top_hidden.style.color = "white";
            if (kind=="sector" || kind=="cluster") {
              $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects in this '+kind:' project in this '+kind)+'
'+this.total_in_region+' in total');
            } else {
              $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects by this '+kind:' project by this '+kind)+'
'+this.total_in_region+' in total');
            }
            hidden_div.appendChild(top_hidden);
          }} catch (e) {
            var top_hidden = document.createElement('div');
            top_hidden.style.border = "none";
            top_hidden.style.position = "relative";
            top_hidden.style.float = "left";
            top_hidden.style.padding = "9px 15px 3px 11px";
            top_hidden.style.width = '149px';
            top_hidden.style.height = 'auto';
            top_hidden.style.background = "url('/images/sites/common/tooltips/body_tooltip.png') no-repeat center top";
            top_hidden.style.font = "normal 17px 'PT Sans Bold'";
            top_hidden.style.textAlign = "center";
            top_hidden.style.color = "white";
            $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects':' project')+'');
            hidden_div.appendChild(top_hidden);
          }

          var bottom_hidden = document.createElement('div');
          bottom_hidden.style.border = "none";
          bottom_hidden.style.position = "relative";
          bottom_hidden.style.float = "left";
          bottom_hidden.style.background = "url('/images/sites/common/tooltips/bottom_tooltip.png') no-repeat 0 0";
          bottom_hidden.style.width = '175px';
          bottom_hidden.style.height = '14px';
          hidden_div.appendChild(bottom_hidden);

          div.appendChild(hidden_div);

          google.maps.event.addDomListener(div,'mouseover',function(ev){
            $(this).css('zIndex',global_index++);
            $(this).children('div').show();
          });

          google.maps.event.addDomListener(div,'mouseout',function(ev){
            $(this).children('div').hide();
          });
        } else {
          google.maps.event.addDomListener(div,'mouseover',function(ev){
            $(this).css('zIndex',global_index++);
          });
        }

        if (this.url!=undefined) {
          google.maps.event.addDomListener(div,'click',function(ev){
      	    try{
      				ev.stopPropagation();
      			}catch(e){
      				event.cancelBubble=true;
      			};
      			window.location.href=me.url;
      	  });
        }

    		google.maps.event.addDomListener(div,'mousedown',function(ev){
    	    try{
    				ev.stopPropagation();
    			}catch(e){
    				event.cancelBubble=true;
    			};
    	  });

        var panes = this.getPanes();
        panes.floatPane.appendChild(div);

        if (($(this.div_).children('p').width()+6)>this.width_) {
          $(this.div_).children('p').css('display','none');
        } else {
          $(this.div_).children('p').css('margin-left',-($(this.div_).children('p').width()/2) + "px");
        }

      }

    	var pixPosition = me.getProjection().fromLatLngToDivPixel(me.latlng_);
      if (pixPosition) {
    	  div.style.width = me.width_ + 'px';
    	  div.style.left = (pixPosition.x + me.offsetHorizontal_) + 'px';
    	  div.style.height = me.height_ + 'px';
    	  div.style.top = (pixPosition.y + me.offsetVertical_) + 'px';
      }

    };

    IOMMarker.prototype.remove = function() {
      if (this.div_) {
        this.div_.parentNode.removeChild(this.div_);
        this.div_ = null;
      }
    };

    IOMMarker.prototype.hide = function() {
      if (this.div_) {
        $(this.div_).find('div').fadeOut();
      }
    };
<commit_msg>hawaii<commit_after>

    function IOMMarker(info, diameter, image, map) {
      this.latlng_ = new google.maps.LatLng(parseFloat(info.lat),parseFloat(info.lon));
      this.url = info.url;
      this.count = info.count;
      this.total_in_region = info.total_in_region;
      this.image = image;
    	this.map_ = map;
    	this.name = info.name;
    	this.diameter = diameter;

      this.offsetVertical_ = -(this.diameter/2);
      this.offsetHorizontal_ = -(this.diameter/2);
      this.height_ = this.diameter;
      this.width_ = this.diameter;

      this.setMap(map);
    }

    IOMMarker.prototype = new google.maps.OverlayView();

    IOMMarker.prototype.draw = function() {

      var me = this;
    	var num = 0;

      var div = this.div_;
      if (!div) {
        div = this.div_ = document.createElement('div');
        div.style.border = "none";
        div.style.position = "absolute";
    		div.style.width = this.diameter + 'px';
    		div.style.height = this.diameter + 'px';
    		div.style.zIndex = 1;
        div.style.cursor = "pointer";

    		//Marker image
        var marker_image = document.createElement('img');
        marker_image.style.position = "relative";
        marker_image.style.width = "100%";
        marker_image.style.height = "100%";
        marker_image.src = this.image;
        div.appendChild(marker_image);

        if (show_regions_with_one_project!=undefined) {
          var count = document.createElement('p');
          count.style.position = "absolute";
          count.style.top = "50%";
          count.style.left = "50%";
          count.style.height = "15px";
          count.style.textAlign = "center";
          if (this.diameter==20) {
            count.style.margin ="-6px 0 0 0px";
            count.style.font = "normal 10px Arial";
          } else if (this.diameter==26) {
            count.style.margin ="-6px 0 0 0px";
            count.style.font = "normal 11px Arial";
          } else if (this.diameter==34) {
            count.style.margin ="-7px 0 0 0px";
            count.style.font = "normal 12px Arial";
          } else if (this.diameter==42) {
            count.style.margin ="-7px 0 0 0px";
            count.style.font = "normal 15px Arial";
          } else {
            count.style.margin ="-9px 0 0 0px";
            count.style.font = "normal 18px Arial";
          }
          count.style.color = "white";
          $(count).text(this.count);
          div.appendChild(count);
        } else {
          if(this.count>1) {
              var count = document.createElement('p');
              count.style.position = "absolute";
              count.style.top = "50%";
              count.style.left = "50%";
              count.style.height = "15px";
              count.style.textAlign = "center";
              if (this.diameter==20) {
                count.style.margin ="-6px 0 0 0px";
                count.style.font = "normal 10px Arial";
              } else if (this.diameter==26) {
                count.style.margin ="-6px 0 0 0px";
                count.style.font = "normal 11px Arial";
              } else if (this.diameter==34) {
                count.style.margin ="-7px 0 0 0px";
                count.style.font = "normal 12px Arial";
              } else if (this.diameter==42) {
                count.style.margin ="-7px 0 0 0px";
                count.style.font = "normal 15px Arial";
              } else {
                count.style.margin ="-9px 0 0 0px";
                count.style.font = "normal 18px Arial";
              }
              count.style.color = "white";
              $(count).text(this.count);
              div.appendChild(count);
          }
        }

        //Marker address
        if (map_type=="overview_map") {

          var hidden_div = document.createElement('div');
          hidden_div.style.border = "none";
          hidden_div.style.position = "absolute";
          hidden_div.style.margin = "0px";
          hidden_div.style.padding = "0px";
          hidden_div.style.display = "none";
          hidden_div.style.bottom = this.diameter + 4 +"px";
          hidden_div.style.left = (this.diameter/2)-(175/2)+"px";
          hidden_div.style.width = '175px';

          try {
          if (kind!=null) {
            var top_hidden = document.createElement('div');
            top_hidden.style.border = "none";
            top_hidden.style.position = "relative";
            top_hidden.style.float = "left";
            top_hidden.style.padding = "9px 15px 3px 11px";
            top_hidden.style.width = '149px';
            top_hidden.style.height = 'auto';
            top_hidden.style.background = "url('/images/sites/common/tooltips/body_tooltip.png') no-repeat center top";
            top_hidden.style.font = "normal 17px 'PT Sans Bold'";
            top_hidden.style.textAlign = "center";
            top_hidden.style.color = "white";
            if (kind=="sector" || kind=="cluster") {
              $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects in this '+kind:' project in this '+kind)+'
'+this.total_in_region+' in total');
            } else {
              $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects by this '+kind:' project by this '+kind)+'
'+this.total_in_region+' in total');
            }
            hidden_div.appendChild(top_hidden);
          }} catch (e) {
            var top_hidden = document.createElement('div');
            top_hidden.style.border = "none";
            top_hidden.style.position = "relative";
            top_hidden.style.float = "left";
            top_hidden.style.padding = "9px 15px 3px 11px";
            top_hidden.style.width = '149px';
            top_hidden.style.height = 'auto';
            top_hidden.style.background = "url('/images/sites/common/tooltips/body_tooltip.png') no-repeat center top";
            top_hidden.style.font = "normal 17px 'PT Sans Bold'";
            top_hidden.style.textAlign = "center";
            top_hidden.style.color = "white";
            $(top_hidden).html(this.name+'
'+this.count+ ((this.count>1)?' projects':' project')+'');
            hidden_div.appendChild(top_hidden);
          }

          var bottom_hidden = document.createElement('div');
          bottom_hidden.style.border = "none";
          bottom_hidden.style.position = "relative";
          bottom_hidden.style.float = "left";
          bottom_hidden.style.background = "url('/images/sites/common/tooltips/bottom_tooltip.png') no-repeat 0 0";
          bottom_hidden.style.width = '175px';
          bottom_hidden.style.height = '14px';
          hidden_div.appendChild(bottom_hidden);

          div.appendChild(hidden_div);

          google.maps.event.addDomListener(div,'mouseover',function(ev){
            $(this).css('zIndex',global_index++);
            $(this).children('div').show();
          });

          google.maps.event.addDomListener(div,'mouseout',function(ev){
            $(this).children('div').hide();
          });
        } else {
          google.maps.event.addDomListener(div,'mouseover',function(ev){
            $(this).css('zIndex',global_index++);
          });
        }

        if (this.url!=undefined) {
          google.maps.event.addDomListener(div,'click',function(ev){
      	    try{
      				ev.stopPropagation();
      			}catch(e){
      				event.cancelBubble=true;
      			};
      			window.location.href=me.url;
      	  });
        }

    		google.maps.event.addDomListener(div,'mousedown',function(ev){
    	    try{
    				ev.stopPropagation();
    			}catch(e){
    				event.cancelBubble=true;
    			};
    	  });

        var panes = this.getPanes();
        panes.floatPane.appendChild(div);

        if (($(this.div_).children('p').width()+6)>this.width_) {
          $(this.div_).children('p').css('display','none');
        } else {
          $(this.div_).children('p').css('margin-left',-($(this.div_).children('p').width()/2) + "px");
        }

      }

    	var pixPosition = me.getProjection().fromLatLngToDivPixel(me.latlng_);
      if (pixPosition) {
    	  div.style.width = me.width_ + 'px';
    	  div.style.left = (pixPosition.x + me.offsetHorizontal_) + 'px';
    	  div.style.height = me.height_ + 'px';
    	  div.style.top = (pixPosition.y + me.offsetVertical_) + 'px';
      }

    };

    IOMMarker.prototype.remove = function() {
      if (this.div_) {
        this.div_.parentNode.removeChild(this.div_);
        this.div_ = null;
      }
    };

    IOMMarker.prototype.hide = function() {
      if (this.div_) {
        $(this.div_).find('div').fadeOut();
      }
    };
<|endoftext|>


<commit_before>/*
 Copyright (c) 2013, Yahoo! Inc.  All rights reserved.
 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
var path = require('path'),
    fs = require('fs'),
    existsSync = fs.existsSync || path.existsSync,
    CAMEL_PATTERN = /([a-z])([A-Z])/g,
    YML_PATTERN = /\.ya?ml$/,
    yaml = require('js-yaml'),
    defaults = require('./report/common/defaults');

function defaultConfig(includeBackCompatAttrs) {
    var ret = {
        verbose: false,
        instrumentation: {
            root: '.',
            extensions: ['.js'],
            'default-excludes': true,
            excludes: [],
            'embed-source': false,
            variable: '__coverage__',
            compact: true,
            'preserve-comments': false,
            'complete-copy': false,
            'save-baseline': false,
            'baseline-file': './coverage/coverage-baseline.json',
            'include-all-sources': false,
            'include-pid': false,
            'include-babel-polyfill': false,
            'use-babel-runtime': false,
            'babel-stage': 2,
            'es-modules': false
        },
        reporting: {
            print: 'summary',
            reports: [ 'lcov' ],
            dir: './coverage'
        },
        hooks: {
            'hook-run-in-context': false,
            'post-require-hook': null,
            'handle-sigint': false
        },
        check: {
            global: {
                statements: 0,
                lines: 0,
                branches: 0,
                functions: 0,
                excludes: [] // Currently list of files (root + path). For future, extend to patterns.
            },
            each: {
                statements: 0,
                lines: 0,
                branches: 0,
                functions: 0,
                excludes: []
            }
        }
    };
    ret.reporting.watermarks = defaults.watermarks();
    ret.reporting['report-config'] = defaults.defaultReportConfig();

    if (includeBackCompatAttrs) {
        ret.instrumentation['preload-sources'] = false;
    }

    return ret;
}

function dasherize(word) {
    return word.replace(CAMEL_PATTERN, function (match, lch, uch) {
        return lch + '-' + uch.toLowerCase();
    });
}
function isScalar(v) {
    if (v === null) { return true; }
    return v !== undefined && !Array.isArray(v) && typeof v !== 'object';
}

function isObject(v) {
    return typeof v === 'object' && v !== null && !Array.isArray(v);
}

function mergeObjects(explicit, template) {

    var ret = {};

    Object.keys(template).forEach(function (k) {
        var v1 = template[k],
            v2 = explicit[k];

        if (Array.isArray(v1)) {
            ret[k] = Array.isArray(v2) && v2.length > 0 ? v2 : v1;
        } else if (isObject(v1)) {
            v2 = isObject(v2) ? v2 : {};
            ret[k] = mergeObjects(v2, v1);
        } else {
            ret[k] = isScalar(v2) ? v2 : v1;
        }
    });
    return ret;
}

function mergeDefaults(explicit, implicit) {
    return mergeObjects(explicit || {}, implicit);
}

function addMethods() {
    var args = Array.prototype.slice.call(arguments),
        cons = args.shift();

    args.forEach(function (arg) {
        var method = arg,
            property = dasherize(arg);
        cons.prototype[method] = function () {
            return this.config[property];
        };
    });
}

/**
 * Object that returns instrumentation options
 * @class InstrumentOptions
 * @module config
 * @constructor
 * @param config the instrumentation part of the config object
 */
function InstrumentOptions(config) {
    if (config['preload-sources']) {
        console.error('The preload-sources option is deprecated, please use include-all-sources instead.');
        config['include-all-sources'] = config['preload-sources'];
    }
    this.config = config;
}

/**
 * returns if default excludes should be turned on. Used by the `cover` command.
 * @method defaultExcludes
 * @return {Boolean} true if default excludes should be turned on
 */
/**
 * returns if non-JS files should be copied during instrumentation. Used by the
 * `instrument` command.
 * @method completeCopy
 * @return {Boolean} true if non-JS files should be copied
 */
/**
 * returns if the source should be embedded in the instrumented code. Used by the
 * `instrument` command.
 * @method embedSource
 * @return {Boolean} true if the source should be embedded in the instrumented code
 */
/**
 * the coverage variable name to use. Used by the `instrument` command.
 * @method variable
 * @return {String} the coverage variable name to use
 */
/**
 * returns if the output should be compact JS. Used by the `instrument` command.
 * @method compact
 * @return {Boolean} true if the output should be compact
 */
/**
 * returns if comments should be preserved in the generated JS. Used by the
 * `cover` and `instrument` commands.
 * @method preserveComments
 * @return {Boolean} true if comments should be preserved in the generated JS
 */
/**
 * returns if a zero-coverage baseline file should be written as part of
 * instrumentation. This allows reporting to display numbers for files that have
 * no tests. Used by the  `instrument` command.
 * @method saveBaseline
 * @return {Boolean} true if a baseline coverage file should be written.
 */
/**
 * Sets the baseline coverage filename. Used by the  `instrument` command.
 * @method baselineFile
 * @return {String} the name of the baseline coverage file.
 */
/**
 * returns if comments the JS to instrument contains es6 Module syntax.
 * @method esModules
 * @return {Boolean} true if code contains es6 import/export statements.
 */
/**
 * returns if the coverage filename should include the PID. Used by the  `instrument` command.
 * @method includePid
 * @return {Boolean} true to include pid in coverage filename.
 */

addMethods(InstrumentOptions,
    'extensions', 'defaultExcludes', 'completeCopy',
    'embedSource', 'variable', 'compact', 'preserveComments',
    'saveBaseline', 'baselineFile', 'esModules',
    'includeAllSources', 'includePid', 'includeBabelPolyfill', 'useBabelRuntime', 'babelStage');

/**
 * returns the root directory used by istanbul which is typically the root of the
 * source tree. Used by the `cover` and `report` commands.
 * @method root
 * @return {String} the root directory used by istanbul.
 */
InstrumentOptions.prototype.root = function () { return path.resolve(this.config.root); };
/**
 * returns an array of fileset patterns that should be excluded for instrumentation.
 * Used by the `instrument` and `cover` commands.
 * @method excludes
 * @return {Array} an array of fileset patterns that should be excluded for
 *  instrumentation.
 */
InstrumentOptions.prototype.excludes = function (excludeTests) {
    var defs;
    if (this.defaultExcludes()) {
        defs = [ '**/node_modules/**' ];
        if (excludeTests) {
            defs = defs.concat(['**/test/**', '**/tests/**']);
        }
        return defs.concat(this.config.excludes);
    }
    return this.config.excludes;
};

/**
 * Object that returns reporting options
 * @class ReportingOptions
 * @module config
 * @constructor
 * @param config the reporting part of the config object
 */
function ReportingOptions(config) {
    this.config = config;
}

/**
 * returns the kind of information to be printed on the console. May be one
 * of `summary`, `detail`, `both` or `none`. Used by the
 * `cover` command.
 * @method print
 * @return {String} the kind of information to print to the console at the end
 * of the `cover` command execution.
 */
/**
 * returns a list of reports that should be generated at the end of a run. Used
 * by the `cover` and `report` commands.
 * @method reports
 * @return {Array} an array of reports that should be produced
 */
/**
 * returns the directory under which reports should be generated. Used by the
 * `cover` and `report` commands.
 *
 * @method dir
 * @return {String} the directory under which reports should be generated.
 */
/**
 * returns an object that has keys that are report format names and values that are objects
 * containing detailed configuration for each format. Running `istanbul help config`
 * will give you all the keys per report format that can be overridden.
 * Used by the `cover` and `report` commands.
 * @method reportConfig
 * @return {Object} detailed report configuration per report format.
 */
addMethods(ReportingOptions, 'print', 'reports', 'dir', 'reportConfig');

function isInvalidMark(v, key) {
    var prefix = 'Watermark for [' + key + '] :';

    if (v.length !== 2) {
        return prefix + 'must be an array of length 2';
    }
    v[0] = Number(v[0]);
    v[1] = Number(v[1]);

    if (isNaN(v[0]) || isNaN(v[1])) {
        return prefix + 'must have valid numbers';
    }
    if (v[0] < 0 || v[1] < 0) {
        return prefix + 'must be positive numbers';
    }
    if (v[1] > 100) {
        return prefix + 'cannot exceed 100';
    }
    if (v[1] <= v[0]) {
        return prefix + 'low must be less than high';
    }
    return null;
}

/**
 * returns the low and high watermarks to be used to designate whether coverage
 * is `low`, `medium` or `high`. Statements, functions, branches and lines can
 * have independent watermarks. These are respected by all reports
 * that color for low, medium and high coverage. See the default configuration for exact syntax
 * using `istanbul help config`. Used by the `cover` and `report` commands.
 *
 * @method watermarks
 * @return {Object} an object containing low and high watermarks for statements,
 *  branches, functions and lines.
 */
ReportingOptions.prototype.watermarks = function () {
    var v = this.config.watermarks,
        defs = defaults.watermarks(),
        ret = {};

    Object.keys(defs).forEach(function (k) {
        var mark = v[k], //it will already be a non-zero length array because of the way the merge works
            message = isInvalidMark(mark, k);
        if (message) {
            console.error(message);
            ret[k] = defs[k];
        } else {
            ret[k] = mark;
        }
    });
    return ret;
};

/**
 * Object that returns hook options. Note that istanbul does not provide an
 * option to hook `require`. This is always done by the `cover` command.
 * @class HookOptions
 * @module config
 * @constructor
 * @param config the hooks part of the config object
 */
function HookOptions(config) {
    this.config = config;
}

/**
 * returns if `vm.runInThisContext` needs to be hooked, in addition to the standard
 * `require` hooks added by istanbul. This should be true for code that uses
 * RequireJS for example. Used by the `cover` command.
 * @method hookRunInContext
 * @return {Boolean} true if `vm.runInThisContext` needs to be hooked for coverage
 */
/**
 * returns a path to JS file or a dependent module that should be used for
 * post-processing files after they have been required. See the `yui-istanbul` module for
 * an example of a post-require hook. This particular hook modifies the yui loader when
 * that file is required to add istanbul interceptors. Use by the `cover` command
 *
 * @method postRequireHook
 * @return {String} a path to a JS file or the name of a node module that needs
 * to be used as a `require` post-processor
 */
/**
 * returns if istanbul needs to add a SIGINT (control-c, usually) handler to
 * save coverage information. Useful for getting code coverage out of processes
 * that run forever and need a SIGINT to terminate.
 * @method handleSigint
 * @return {Boolean} true if SIGINT needs to be hooked to write coverage information
 */

addMethods(HookOptions, 'hookRunInContext', 'postRequireHook', 'handleSigint');

/**
 * represents the istanbul configuration and provides sub-objects that can
 * return instrumentation, reporting and hook options respectively.
 * Usage
 * -----
 *
 *      var configObj = require('istanbul').config.loadFile();
 *
 *      console.log(configObj.reporting.reports());
 *
 * @class Configuration
 * @module config
 * @param {Object} obj  the base object to use as the configuration
 * @param {Object} overrides optional - override attributes that are merged into
 *  the base config
 * @constructor
 */
function Configuration(obj, overrides) {

    var config = mergeDefaults(obj, defaultConfig(true));
    if (isObject(overrides)) {
        config = mergeDefaults(overrides, config);
    }
    if (config.verbose) {
        console.error('Using configuration');
        console.error('-------------------');
        console.error(yaml.safeDump(config, { indent: 4, flowLevel: 3 }));
        console.error('-------------------\n');
    }
    this.verbose = config.verbose;
    this.instrumentation = new InstrumentOptions(config.instrumentation);
    this.reporting = new ReportingOptions(config.reporting);
    this.hooks = new HookOptions(config.hooks);
    this.check = config.check; // Pass raw config sub-object.
}

/**
 * true if verbose logging is required
 * @property verbose
 * @type Boolean
 */
/**
 * instrumentation options
 * @property instrumentation
 * @type InstrumentOptions
 */
/**
 * reporting options
 * @property reporting
 * @type ReportingOptions
 */
/**
 * hook options
 * @property hooks
 * @type HookOptions
 */

function loadFile(file, overrides) {
    var defaultConfigFile = path.resolve('.istanbul.yml'),
        configObject;

    if (file) {
        if (!existsSync(file)) {
            throw new Error('Invalid configuration file specified:' + file);
        }
    } else {
        if (existsSync(defaultConfigFile)) {
            file = defaultConfigFile;
        }
    }

    if (file) {
        if (overrides && overrides.verbose === true) {
            console.error('Loading config: ' + file);
        }
        configObject = file.match(YML_PATTERN) ?
            yaml.safeLoad(fs.readFileSync(file, 'utf8'), { filename: file }) :
            require(path.resolve(file));
    }

    return new Configuration(configObject, overrides);
}

function loadObject(obj, overrides) {
    return new Configuration(obj, overrides);
}

/**
 * methods to load the configuration object.
 * Usage
 * -----
 *
 *      var config = require('istanbul').config,
 *          configObj = config.loadFile();
 *
 *      console.log(configObj.reporting.reports());
 *
 * @class Config
 * @module main
 * @static
 */
module.exports = {
    /**
     * loads the specified configuration file with optional overrides. Throws
     * when a file is specified and it is not found.
     * @method loadFile
     * @static
     * @param {String} file the file to load. If falsy, the default config file, if present, is loaded.
     *  If not a default config is used.
     * @param {Object} overrides - an object with override keys that are merged into the
     *  config object loaded
     * @return {Configuration} the config object with overrides applied
     */
    loadFile: loadFile,
    /**
     * loads the specified configuration object with optional overrides.
     * @method loadObject
     * @static
     * @param {Object} obj the object to use as the base configuration.
     * @param {Object} overrides - an object with override keys that are merged into the
     *  config object
     * @return {Configuration} the config object with overrides applied
     */
    loadObject: loadObject,
    /**
     * returns the default configuration object. Note that this is a plain object
     * and not a `Configuration` instance.
     * @method defaultConfig
     * @static
     * @return {Object} an object that represents the default config
     */
    defaultConfig: defaultConfig
};
<commit_msg>Use extensions list as in babel<commit_after>/*
 Copyright (c) 2013, Yahoo! Inc.  All rights reserved.
 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
var path = require('path'),
    fs = require('fs'),
    existsSync = fs.existsSync || path.existsSync,
    CAMEL_PATTERN = /([a-z])([A-Z])/g,
    YML_PATTERN = /\.ya?ml$/,
    yaml = require('js-yaml'),
    defaults = require('./report/common/defaults');

function defaultConfig(includeBackCompatAttrs) {
    var ret = {
        verbose: false,
        instrumentation: {
            root: '.',
            extensions: ['.js','.jsx','.es6','.es'],
            'default-excludes': true,
            excludes: [],
            'embed-source': false,
            variable: '__coverage__',
            compact: true,
            'preserve-comments': false,
            'complete-copy': false,
            'save-baseline': false,
            'baseline-file': './coverage/coverage-baseline.json',
            'include-all-sources': false,
            'include-pid': false,
            'include-babel-polyfill': false,
            'use-babel-runtime': false,
            'babel-stage': 2,
            'es-modules': false
        },
        reporting: {
            print: 'summary',
            reports: [ 'lcov' ],
            dir: './coverage'
        },
        hooks: {
            'hook-run-in-context': false,
            'post-require-hook': null,
            'handle-sigint': false
        },
        check: {
            global: {
                statements: 0,
                lines: 0,
                branches: 0,
                functions: 0,
                excludes: [] // Currently list of files (root + path). For future, extend to patterns.
            },
            each: {
                statements: 0,
                lines: 0,
                branches: 0,
                functions: 0,
                excludes: []
            }
        }
    };
    ret.reporting.watermarks = defaults.watermarks();
    ret.reporting['report-config'] = defaults.defaultReportConfig();

    if (includeBackCompatAttrs) {
        ret.instrumentation['preload-sources'] = false;
    }

    return ret;
}

function dasherize(word) {
    return word.replace(CAMEL_PATTERN, function (match, lch, uch) {
        return lch + '-' + uch.toLowerCase();
    });
}
function isScalar(v) {
    if (v === null) { return true; }
    return v !== undefined && !Array.isArray(v) && typeof v !== 'object';
}

function isObject(v) {
    return typeof v === 'object' && v !== null && !Array.isArray(v);
}

function mergeObjects(explicit, template) {

    var ret = {};

    Object.keys(template).forEach(function (k) {
        var v1 = template[k],
            v2 = explicit[k];

        if (Array.isArray(v1)) {
            ret[k] = Array.isArray(v2) && v2.length > 0 ? v2 : v1;
        } else if (isObject(v1)) {
            v2 = isObject(v2) ? v2 : {};
            ret[k] = mergeObjects(v2, v1);
        } else {
            ret[k] = isScalar(v2) ? v2 : v1;
        }
    });
    return ret;
}

function mergeDefaults(explicit, implicit) {
    return mergeObjects(explicit || {}, implicit);
}

function addMethods() {
    var args = Array.prototype.slice.call(arguments),
        cons = args.shift();

    args.forEach(function (arg) {
        var method = arg,
            property = dasherize(arg);
        cons.prototype[method] = function () {
            return this.config[property];
        };
    });
}

/**
 * Object that returns instrumentation options
 * @class InstrumentOptions
 * @module config
 * @constructor
 * @param config the instrumentation part of the config object
 */
function InstrumentOptions(config) {
    if (config['preload-sources']) {
        console.error('The preload-sources option is deprecated, please use include-all-sources instead.');
        config['include-all-sources'] = config['preload-sources'];
    }
    this.config = config;
}

/**
 * returns if default excludes should be turned on. Used by the `cover` command.
 * @method defaultExcludes
 * @return {Boolean} true if default excludes should be turned on
 */
/**
 * returns if non-JS files should be copied during instrumentation. Used by the
 * `instrument` command.
 * @method completeCopy
 * @return {Boolean} true if non-JS files should be copied
 */
/**
 * returns if the source should be embedded in the instrumented code. Used by the
 * `instrument` command.
 * @method embedSource
 * @return {Boolean} true if the source should be embedded in the instrumented code
 */
/**
 * the coverage variable name to use. Used by the `instrument` command.
 * @method variable
 * @return {String} the coverage variable name to use
 */
/**
 * returns if the output should be compact JS. Used by the `instrument` command.
 * @method compact
 * @return {Boolean} true if the output should be compact
 */
/**
 * returns if comments should be preserved in the generated JS. Used by the
 * `cover` and `instrument` commands.
 * @method preserveComments
 * @return {Boolean} true if comments should be preserved in the generated JS
 */
/**
 * returns if a zero-coverage baseline file should be written as part of
 * instrumentation. This allows reporting to display numbers for files that have
 * no tests. Used by the  `instrument` command.
 * @method saveBaseline
 * @return {Boolean} true if a baseline coverage file should be written.
 */
/**
 * Sets the baseline coverage filename. Used by the  `instrument` command.
 * @method baselineFile
 * @return {String} the name of the baseline coverage file.
 */
/**
 * returns if comments the JS to instrument contains es6 Module syntax.
 * @method esModules
 * @return {Boolean} true if code contains es6 import/export statements.
 */
/**
 * returns if the coverage filename should include the PID. Used by the  `instrument` command.
 * @method includePid
 * @return {Boolean} true to include pid in coverage filename.
 */

addMethods(InstrumentOptions,
    'extensions', 'defaultExcludes', 'completeCopy',
    'embedSource', 'variable', 'compact', 'preserveComments',
    'saveBaseline', 'baselineFile', 'esModules',
    'includeAllSources', 'includePid', 'includeBabelPolyfill', 'useBabelRuntime', 'babelStage');

/**
 * returns the root directory used by istanbul which is typically the root of the
 * source tree. Used by the `cover` and `report` commands.
 * @method root
 * @return {String} the root directory used by istanbul.
 */
InstrumentOptions.prototype.root = function () { return path.resolve(this.config.root); };
/**
 * returns an array of fileset patterns that should be excluded for instrumentation.
 * Used by the `instrument` and `cover` commands.
 * @method excludes
 * @return {Array} an array of fileset patterns that should be excluded for
 *  instrumentation.
 */
InstrumentOptions.prototype.excludes = function (excludeTests) {
    var defs;
    if (this.defaultExcludes()) {
        defs = [ '**/node_modules/**' ];
        if (excludeTests) {
            defs = defs.concat(['**/test/**', '**/tests/**']);
        }
        return defs.concat(this.config.excludes);
    }
    return this.config.excludes;
};

/**
 * Object that returns reporting options
 * @class ReportingOptions
 * @module config
 * @constructor
 * @param config the reporting part of the config object
 */
function ReportingOptions(config) {
    this.config = config;
}

/**
 * returns the kind of information to be printed on the console. May be one
 * of `summary`, `detail`, `both` or `none`. Used by the
 * `cover` command.
 * @method print
 * @return {String} the kind of information to print to the console at the end
 * of the `cover` command execution.
 */
/**
 * returns a list of reports that should be generated at the end of a run. Used
 * by the `cover` and `report` commands.
 * @method reports
 * @return {Array} an array of reports that should be produced
 */
/**
 * returns the directory under which reports should be generated. Used by the
 * `cover` and `report` commands.
 *
 * @method dir
 * @return {String} the directory under which reports should be generated.
 */
/**
 * returns an object that has keys that are report format names and values that are objects
 * containing detailed configuration for each format. Running `istanbul help config`
 * will give you all the keys per report format that can be overridden.
 * Used by the `cover` and `report` commands.
 * @method reportConfig
 * @return {Object} detailed report configuration per report format.
 */
addMethods(ReportingOptions, 'print', 'reports', 'dir', 'reportConfig');

function isInvalidMark(v, key) {
    var prefix = 'Watermark for [' + key + '] :';

    if (v.length !== 2) {
        return prefix + 'must be an array of length 2';
    }
    v[0] = Number(v[0]);
    v[1] = Number(v[1]);

    if (isNaN(v[0]) || isNaN(v[1])) {
        return prefix + 'must have valid numbers';
    }
    if (v[0] < 0 || v[1] < 0) {
        return prefix + 'must be positive numbers';
    }
    if (v[1] > 100) {
        return prefix + 'cannot exceed 100';
    }
    if (v[1] <= v[0]) {
        return prefix + 'low must be less than high';
    }
    return null;
}

/**
 * returns the low and high watermarks to be used to designate whether coverage
 * is `low`, `medium` or `high`. Statements, functions, branches and lines can
 * have independent watermarks. These are respected by all reports
 * that color for low, medium and high coverage. See the default configuration for exact syntax
 * using `istanbul help config`. Used by the `cover` and `report` commands.
 *
 * @method watermarks
 * @return {Object} an object containing low and high watermarks for statements,
 *  branches, functions and lines.
 */
ReportingOptions.prototype.watermarks = function () {
    var v = this.config.watermarks,
        defs = defaults.watermarks(),
        ret = {};

    Object.keys(defs).forEach(function (k) {
        var mark = v[k], //it will already be a non-zero length array because of the way the merge works
            message = isInvalidMark(mark, k);
        if (message) {
            console.error(message);
            ret[k] = defs[k];
        } else {
            ret[k] = mark;
        }
    });
    return ret;
};

/**
 * Object that returns hook options. Note that istanbul does not provide an
 * option to hook `require`. This is always done by the `cover` command.
 * @class HookOptions
 * @module config
 * @constructor
 * @param config the hooks part of the config object
 */
function HookOptions(config) {
    this.config = config;
}

/**
 * returns if `vm.runInThisContext` needs to be hooked, in addition to the standard
 * `require` hooks added by istanbul. This should be true for code that uses
 * RequireJS for example. Used by the `cover` command.
 * @method hookRunInContext
 * @return {Boolean} true if `vm.runInThisContext` needs to be hooked for coverage
 */
/**
 * returns a path to JS file or a dependent module that should be used for
 * post-processing files after they have been required. See the `yui-istanbul` module for
 * an example of a post-require hook. This particular hook modifies the yui loader when
 * that file is required to add istanbul interceptors. Use by the `cover` command
 *
 * @method postRequireHook
 * @return {String} a path to a JS file or the name of a node module that needs
 * to be used as a `require` post-processor
 */
/**
 * returns if istanbul needs to add a SIGINT (control-c, usually) handler to
 * save coverage information. Useful for getting code coverage out of processes
 * that run forever and need a SIGINT to terminate.
 * @method handleSigint
 * @return {Boolean} true if SIGINT needs to be hooked to write coverage information
 */

addMethods(HookOptions, 'hookRunInContext', 'postRequireHook', 'handleSigint');

/**
 * represents the istanbul configuration and provides sub-objects that can
 * return instrumentation, reporting and hook options respectively.
 * Usage
 * -----
 *
 *      var configObj = require('istanbul').config.loadFile();
 *
 *      console.log(configObj.reporting.reports());
 *
 * @class Configuration
 * @module config
 * @param {Object} obj  the base object to use as the configuration
 * @param {Object} overrides optional - override attributes that are merged into
 *  the base config
 * @constructor
 */
function Configuration(obj, overrides) {

    var config = mergeDefaults(obj, defaultConfig(true));
    if (isObject(overrides)) {
        config = mergeDefaults(overrides, config);
    }
    if (config.verbose) {
        console.error('Using configuration');
        console.error('-------------------');
        console.error(yaml.safeDump(config, { indent: 4, flowLevel: 3 }));
        console.error('-------------------\n');
    }
    this.verbose = config.verbose;
    this.instrumentation = new InstrumentOptions(config.instrumentation);
    this.reporting = new ReportingOptions(config.reporting);
    this.hooks = new HookOptions(config.hooks);
    this.check = config.check; // Pass raw config sub-object.
}

/**
 * true if verbose logging is required
 * @property verbose
 * @type Boolean
 */
/**
 * instrumentation options
 * @property instrumentation
 * @type InstrumentOptions
 */
/**
 * reporting options
 * @property reporting
 * @type ReportingOptions
 */
/**
 * hook options
 * @property hooks
 * @type HookOptions
 */

function loadFile(file, overrides) {
    var defaultConfigFile = path.resolve('.istanbul.yml'),
        configObject;

    if (file) {
        if (!existsSync(file)) {
            throw new Error('Invalid configuration file specified:' + file);
        }
    } else {
        if (existsSync(defaultConfigFile)) {
            file = defaultConfigFile;
        }
    }

    if (file) {
        if (overrides && overrides.verbose === true) {
            console.error('Loading config: ' + file);
        }
        configObject = file.match(YML_PATTERN) ?
            yaml.safeLoad(fs.readFileSync(file, 'utf8'), { filename: file }) :
            require(path.resolve(file));
    }

    return new Configuration(configObject, overrides);
}

function loadObject(obj, overrides) {
    return new Configuration(obj, overrides);
}

/**
 * methods to load the configuration object.
 * Usage
 * -----
 *
 *      var config = require('istanbul').config,
 *          configObj = config.loadFile();
 *
 *      console.log(configObj.reporting.reports());
 *
 * @class Config
 * @module main
 * @static
 */
module.exports = {
    /**
     * loads the specified configuration file with optional overrides. Throws
     * when a file is specified and it is not found.
     * @method loadFile
     * @static
     * @param {String} file the file to load. If falsy, the default config file, if present, is loaded.
     *  If not a default config is used.
     * @param {Object} overrides - an object with override keys that are merged into the
     *  config object loaded
     * @return {Configuration} the config object with overrides applied
     */
    loadFile: loadFile,
    /**
     * loads the specified configuration object with optional overrides.
     * @method loadObject
     * @static
     * @param {Object} obj the object to use as the base configuration.
     * @param {Object} overrides - an object with override keys that are merged into the
     *  config object
     * @return {Configuration} the config object with overrides applied
     */
    loadObject: loadObject,
    /**
     * returns the default configuration object. Note that this is a plain object
     * and not a `Configuration` instance.
     * @method defaultConfig
     * @static
     * @return {Object} an object that represents the default config
     */
    defaultConfig: defaultConfig
};
<|endoftext|>


<commit_before>'use strict';

const { expect } = require('chai');
const { execSync } = require('child_process');

describe('cal', () => {
  it('should handle the current month', () => {
    const goal = execSync('cal').toString();
    const output = execSync('./cal.js').toString();

    expect(output).to.equal(goal);
  });
});
<commit_msg>add some tests for zellers congruence<commit_after>'use strict';

const { expect } = require('chai');
const { execSync } = require('child_process');

describe('cal', () => {
  describe('CLI', () => {
    it('should handle the current month', () => {
      const goal = execSync('cal').toString();
      const output = execSync('./cal.js').toString();

      expect(output).to.equal(goal);
    });
  });

  describe("Zeller's congruence", () => {
    // const zellers = require('../lib/zellers.js');

    describe('.modifiedMonth', () => {
      it('return 13 for January', () => {
        expect(zellers.modifiedMonth(1)).to.equal(13);
      });
      // 2 === 14
      // 3 === 3
    });

    describe('.modifiedYear', () => {
      it('returns 2014 for Jan 2015', () => {
        expect(zellers.modifiedYear(2015, 1)).to.equal(2014);
      });
      // 2016, 2 === 2015
      // 2017, 3 === 2017
    });

    describe('.getDay', () => {
      it('returns 2 (Tuesday) for March 1, 2016', () => {
        expect(zellers.getDay(2016, 3, 1)).to.equal(2);
      });
      // 2000, 3, 1 === 3
      // 2100, 3, 1 === 1
      // 2200, 3, 2 === 0
      // 2300, 3, 1 === 4
    });
  });
});
<|endoftext|>


<commit_before>module.exports = function () {

  var distFolder = './dist/';
  var assetsFolder = './assets/';
  var scriptsFolder = './scripts/';
  var server = './server/';

  var config = {};

  config.defaultPort = 7654;

  config.htmlmin = {
    options: {
      collapseWhitespace: true,
      conservativeCollapse: true,
      removeComments: true
    }
  }

  config.paths = {
    css: {
      dest: assetsFolder + 'styles/',
      fileName: 'styles.css'
    },
    dist: distFolder,
    devCommons: [],
    fonts: assetsFolder + 'fonts/',
    html: {
      all: ['./**/*.html', '!./node_modules'],
      templates: scriptsFolder + '**/*.html',
      index: './index.html'
    },
    images: assetsFolder + 'img/',
    js: {
      base: 'scripts',
      dev: scriptsFolder + '**/*.js',
      dest: distFolder + 'scripts'
    },
    less: {
      dest: './assets/styles/',
      dev: './assets/less/**/*.less',
      fileName: 'styles.css'
    },
    sass: {
      dev: './assets/sass/**/*.s+(a|c)ss',
    },
  };

  config.node = {
    devEnvFolder: scriptsFolder,
    devIndex: './index.html',
    distEnvFolder: distFolder,
    distIndex: './index.html',
    options: {
      script: server + 'app.js',
      delayTime: 1,
      watch: [server]
    }
  };

  config.plato = {
    dest: './reports/plato',
    options: {
      title: 'Plato report'
    }
  };

  config.server = {
    options: {
      dev: {
        root: './',
        livereload: true,
      },
      dist: {
        root: distFolder,
      }
    }
  };

  //Allows to change between sass or less framework
  config.style = {
    framework: 'sass'
  };

  config.templateCache = {
    dest: scriptsFolder + 'app/templates/',
    fileName: 'templates.js',
    options: {
      module: 'app.core.templates',
      moduleSystem: 'IIFE',
      root: 'scripts/',
      standalone: true
    }
  }

  return config;
};
<commit_msg>Refactor to split tasks<commit_after><|endoftext|>


<commit_before>
/**
 * Module dependencies
 */

var _ = require('lodash');
var utils = require('../../../utils/helpers');
var nestedOperations = require('../../../utils/nestedOperations');
var hop = utils.object.hasOwnProperty;

/**
 * Update the current instance with the currently set values
 *
 * Called in the model instance context.
 *
 * @param {Object} collection
 * @param {Object} proto
 * @param {Array} mutatedModels
 * @param {Function} callback
 */

var Update = module.exports = function(collection, proto, mutatedModels, cb) {

  var values = typeof proto.toObject === 'function' ? proto.toObject() : proto;
  var attributes = collection.waterline.schema[collection.identity].attributes;
  var primaryKey = this.findPrimaryKey(attributes, values);

  if(!primaryKey) return cb(new Error('No Primary Key set to update the record with! ' +
    'Try setting an attribute as a primary key or include an ID property.'));

  if(!values[primaryKey]) return cb(new Error('No Primary Key set to update the record with! ' +
    'Primary Key must have a value, it can\'t be an optional value.'));

  // Build Search Criteria
  var criteria = {};
  criteria[primaryKey] = values[primaryKey];

  // Clone values so they can be mutated
  var _values = _.cloneDeep(values);

  // For any nested model associations (objects not collection arrays) that were not changed,
  // lets set the value to just the foreign key so that an update query is not performed on the
  // associatied model.
  var keys = _.keys(_values);
  keys.forEach(function(key) {

    // Nix any collection attributes so that they do not get sync'd during the update process.
    // One reason for this is that the result set is not guaranteed to be complete,
    // so the sync could exclude items.
    if (attributes[key] && hop(attributes[key], 'collection') && attributes[key].collection) {

      delete _values[key];
      return;
    }

    // If the key was changed, keep it expanded
    if (mutatedModels.indexOf(key) !== -1) return;

    // Reduce it down to a foreign key value
    var vals = {};
    vals[key] = _values[key];

    // Delete and replace the value with a reduced version
    delete _values[key];
    var reduced = nestedOperations.reduceAssociations(collection.identity, collection.waterline.schema, vals);
    _values = _.merge(_values, reduced);
  });

  // Update the collection with the new values
  collection.update(criteria, _values, cb);
};

/**
 * Find Primary Key
 *
 * @param {Object} attributes
 * @param {Object} values
 * @api private
 */

Update.prototype.findPrimaryKey = function(attributes, values) {
  var primaryKey = null;

  for(var attribute in attributes) {
    if(hop(attributes[attribute], 'primaryKey') && attributes[attribute].primaryKey) {
      primaryKey = attribute;
      break;
    }
  }

  // If no primary key check for an ID property
  if(!primaryKey && hop(values, 'id')) primaryKey = 'id';

  return primaryKey;
};
<commit_msg>clean-up newlines from last commit.<commit_after>
/**
 * Module dependencies
 */

var _ = require('lodash');
var utils = require('../../../utils/helpers');
var nestedOperations = require('../../../utils/nestedOperations');
var hop = utils.object.hasOwnProperty;

/**
 * Update the current instance with the currently set values
 *
 * Called in the model instance context.
 *
 * @param {Object} collection
 * @param {Object} proto
 * @param {Array} mutatedModels
 * @param {Function} callback
 */

var Update = module.exports = function(collection, proto, mutatedModels, cb) {

  var values = typeof proto.toObject === 'function' ? proto.toObject() : proto;
  var attributes = collection.waterline.schema[collection.identity].attributes;
  var primaryKey = this.findPrimaryKey(attributes, values);

  if(!primaryKey) return cb(new Error('No Primary Key set to update the record with! ' +
    'Try setting an attribute as a primary key or include an ID property.'));

  if(!values[primaryKey]) return cb(new Error('No Primary Key set to update the record with! ' +
    'Primary Key must have a value, it can\'t be an optional value.'));

  // Build Search Criteria
  var criteria = {};
  criteria[primaryKey] = values[primaryKey];

  // Clone values so they can be mutated
  var _values = _.cloneDeep(values);

  // For any nested model associations (objects not collection arrays) that were not changed,
  // lets set the value to just the foreign key so that an update query is not performed on the
  // associatied model.
  var keys = _.keys(_values);
  keys.forEach(function(key) {

    // Nix any collection attributes so that they do not get sync'd during the update process.
    // One reason for this is that the result set is not guaranteed to be complete,
    // so the sync could exclude items.
    if (attributes[key] && hop(attributes[key], 'collection') && attributes[key].collection) {

      delete _values[key];
      return;
    }

    // If the key was changed, keep it expanded
    if(mutatedModels.indexOf(key) !== -1) return;

    // Reduce it down to a foreign key value
    var vals = {};
    vals[key] = _values[key];

    // Delete and replace the value with a reduced version
    delete _values[key];
    var reduced = nestedOperations.reduceAssociations(collection.identity, collection.waterline.schema, vals);
    _values = _.merge(_values, reduced);
  });

  // Update the collection with the new values
  collection.update(criteria, _values, cb);
};

/**
 * Find Primary Key
 *
 * @param {Object} attributes
 * @param {Object} values
 * @api private
 */

Update.prototype.findPrimaryKey = function(attributes, values) {
  var primaryKey = null;

  for(var attribute in attributes) {
    if(hop(attributes[attribute], 'primaryKey') && attributes[attribute].primaryKey) {
      primaryKey = attribute;
      break;
    }
  }

  // If no primary key check for an ID property
  if(!primaryKey && hop(values, 'id')) primaryKey = 'id';

  return primaryKey;
};
<|endoftext|>