<commit_before>// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;
(function ($, window, document, undefined) {

	jQuery.event.props.push("dataTransfer");

	// undefined is used here as the undefined global variable in ECMAScript 3 is
	// mutable (ie. it can be changed by someone else). undefined isn't really being
	// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
	// can no longer be modified.

	// window and document are passed through as local variable rather than global
	// as this (slightly) quickens the resolution process and can be more efficiently
	// minified (especially when both are regularly referenced in your plugin).

	// Create the defaults once
	var pluginName = "fileUpload",
		defaults = {
			url: '',
			data: {},
			paramName: 'files',
			lazyLoad: false
		};

	// The actual plugin constructor
	function FileUpload(element, options) {
		this.element = element;
		// jQuery has an extend method which merges the contents of two or
		// more objects, storing the result in the first object. The first object
		// is generally empty as we don't want to alter the default options for
		// future instances of the plugin
		this.settings = $.extend({}, defaults, options);
		this._defaults = defaults;
		this._name = pluginName;
		this._dashdash = '--';
		this._crlf = '\r\n';

		this.init();
	}

	FileUpload.prototype = {
		init: function () {
			// Place initialization logic here
			// You already have access to the DOM element and
			// the options via the instance, e.g. this.element
			// and this.settings
			// you can add more functions like the one below and
			// call them like so: this.yourOtherFunction(this.element, this.settings).
			console.log("xD");
		},

		getBuilder: function (filename, filedata) {
			var builder = '',
				$this = this,
				boundary = '------multipartformboundary' + (new Date).getTime();

			$.each(this.settings.data, function (name, value) {
				builder += $this.buildRequestParam(name, value, boundary);
			});

			builder += this._dashdash;
			builder += boundary;
			builder += this._crlf;
			builder += 'Content-Disposition: form-data; name="' + this.settings.paramName + '"';
			builder += '; filename="' + filename + '"';
			builder += this._crlf;

			builder += 'Content-Type: application/octet-stream';
			builder += this._crlf;
			builder += this._crlf;

			builder += filedata;
			builder += this._crlf;

			builder += this._dashdash;
			builder += boundary;
			builder += this._dashdash;
			builder += this._crlf;
			return builder;
		},
		buildRequestParam: function(name, value, boundary) {
			var param = '';
			switch (typeof value) {
				case 'object':
					for (var i in value) {
						param += this.buildRequestParam(name + '[' + String(i) + ']', value[i], boundary);
					}
					break;
				case 'function':
					param += this._dashdash;
					param += boundary;
					param += this._crlf;
					param += 'Content-Disposition: form-data; name="' + name + '"';
					param += this._crlf;
					param += this._crlf;
					param += value();
					param += this._crlf;
					break;
				default:
					param += this._dashdash;
					param += boundary;
					param += this._crlf;
					param += 'Content-Disposition: form-data; name="' + name + '"';
					param += this._crlf;
					param += this._crlf;
					param += value;
					param += this._crlf;
					break;
			}

			return param;
		}
	};

	// A really lightweight plugin wrapper around the constructor,
	// preventing against multiple instantiations
	$.fn[pluginName] = function (options) {
		this.each(function () {
			if (!$.data(this, "plugin_" + pluginName)) {
				$.data(this, "plugin_" + pluginName, new FileUpload(this, options));
			}
		});

		// chain jQuery functions
		return this;
	};

})(jQuery, window, document);
<commit_msg>Inclusão de vários métodos<commit_after>// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;
(function ($, window, document, undefined) {

	jQuery.event.props.push("dataTransfer");

	// undefined is used here as the undefined global variable in ECMAScript 3 is
	// mutable (ie. it can be changed by someone else). undefined isn't really being
	// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
	// can no longer be modified.

	// window and document are passed through as local variable rather than global
	// as this (slightly) quickens the resolution process and can be more efficiently
	// minified (especially when both are regularly referenced in your plugin).

	// Create the defaults once
	var pluginName = "fileUpload",
		$this = null,
		global_progress = [],
		defaults = {
			url: '',
			data: {},
			paramName: 'files',
			lazyLoad: false,
			inputFile: null,
			maxFiles: 25,           // Ignored if queueFiles is set > 0
			maxFileSize: 1,         // MB file size limit
			maxFilesPerRequest: 1,  // 0 = All files in one request
			refresh: 1000,
			drop: false,
			dragStart: false,
			dragEnter: false,
			dragOver: false,
			dragLeave: false,
			docEnter: false,
			docOver: false,
			docLeave: false,
			beforeEach: false,
			afterAll: false,
			rename: false,
			error: false,
			uploadStarted: false,
			uploadFinished: false,
			progressUpdated: false,
			globalProgressUpdated: false,
			speedUpdated: false,
			allowedFileExtensions: [],
			allowedFileTypes: []
		},
		errors = [
			"BrowserNotSupported", "TooManyFiles", "FileTooLarge", "FileTypeNotAllowed",
			"NotFound", "NotReadable", "AbortError", "ReadError", "FileExtensionNotAllowed"
		];

	// The actual plugin constructor
	function FileUpload(element, options) {
		this.element = element;
		// jQuery has an extend method which merges the contents of two or
		// more objects, storing the result in the first object. The first object
		// is generally empty as we don't want to alter the default options for
		// future instances of the plugin
		this.settings = $.extend({}, defaults, options);
		this._defaults = defaults;
		this._name = pluginName;
		this._dashdash = '--';
		this._crlf = '\r\n';
		this._inputFile = null;
		this._files = null;

		this.init();

		$this = this;
	}

	FileUpload.prototype = {
		init: function () {
			if (this.settings.inputFile !== null) {
				switch (typeof this.settings.inputFile) {
					case 'string':
					case 'object':
						this._inputFile = $(this.settings.inputFile);
						break;
				}

				this._inputFile.hide().change(function (e) {
					$this.settings.drop(e);
					$this._files = e.target.files;
					$this.upload();
				});
			}

			this.on('drop', this.drop).on('dragstart', this.dragStart).on('dragenter', this.dragEnter).on('dragover', this.dragOver).on('dragleave', this.dragLeave);
			$(document).on('drop', this.docDrop).on('dragenter', this.docEnter).on('dragover', this.docOver).on('dragleave', this.docLeave);

			this._inputFile !== null && this.on('click', function (e) {
				$this._inputFile.trigger(e);
			});
		},

		getFormData: function (startImage) {
			var formData = new FormData();

			startImage === undefined && (startImage = 0);

			$.each(this.settings.data, function (name, value) {
				formData.append(name, value);
			});

			$.each(this._files.slice(startImage, startImage + this.settings.maxFilesPerRequest), function(index, file) {
				formData.append($this.settings.paramName + '[]', file, file.name);
			});

			return formData;
		},

		upload: function() {

		},

		drop: function(e) {
			this.settings.drop && this.settings.drop(e);

			if (!e.dataTransfer) {
				return;
			}
			this._files = e.dataTransfer.files;
			if (this._files === null || this._files === undefined || this._files.length === 0) {
				this.error(errors[0]);
				return false;
			}
			this.settings.lazyLoad || this.upload();
			e.preventDefault();
			return false;
		},

		dragStart: function(e) {
			this.settings.dragStart && this.settings.dragStart(e);
		},

		dragEnter: function(e) {
			this.settings.dragEnter && this.settings.dragEnter(e);
		},

		dragOver: function(e) {
			this.settings.dragOver && this.settings.dragOver(e);
		},

		dragLeave: function(e) {
			this.settings.dragLeave && this.settings.dragLeave(e);
		},

		docDrop: function(e) {
			this.settings.docDrop && this.settings.docDrop(e);
		},

		docEnter: function(e) {
			this.settings.docEnter && this.settings.docEnter(e);
		},

		docOver: function(e) {
			this.settings.docOver && this.settings.docOver(e);
		},

		docLeave: function(e) {
			this.settings.docLeave && this.settings.docLeave(e);
		},

		beforeEach: function() {
			this.settings.docLeave && this.settings.docLeave(e);
		},

		afterAll: function() {
			this.settings.beforeEach && this.settings.beforeEach(e);
		},

		rename: function() {
			this.settings.rename && this.settings.rename(e);
		},

		error: function(err, file, i, status) {
			this.settings.error && this.settings.error(err, file, i, status);
		},

		uploadStarted: function() {
			this.settings.uploadStarted && this.settings.uploadStarted(e);
		},

		uploadFinished: function() {
			this.settings.uploadFinished && this.settings.uploadFinished(e);
		},

		progressUpdated: function(index, file, currentProgress) {
			this.settings.progressUpdated && this.settings.progressUpdated(index, file, currentProgress);
		},

		speedUpdated: function(index, file, speed) {
			this.settings.speedUpdated && this.settings.speedUpdated(index, file, speed);
		},

		progress: function(e) {
			/**
			 * this =
			 */
			if (e.lengthComputable) {
				var percentage = Math.round((e.loaded * 100) / e.total),
					elapsed = null,
					diffTime = null,
					diffData = null,
					speed = null;

				if (this.currentProgress !== percentage) {
					this.currentProgress = percentage;
					this.progressUpdated(this.index, this.file, this.currentProgress);

					elapsed = new Date().getTime();
					diffTime = elapsed - this.currentStart;
					if (diffTime >= this.settings.refresh) {
						diffData = e.loaded - this.startData;
						speed = diffData / diffTime; // KB per second
						this.speedUpdated(this.index, this.file, speed);
						this.startData = e.loaded;
						this.currentStart = elapsed;
					}
				}
			}
		}
	};

	// A really lightweight plugin wrapper around the constructor,
	// preventing against multiple instantiations
	$.fn.fileUpload = function (options, params) {
		this.each(function () {
			if (!$.data(this, 'plugin_' + pluginName)) {
				if (typeof options !== 'object') {
					throw 'Invalid Parameter'
				}

				$.data(this, 'plugin_' + pluginName, new FileUpload(this, options));
			}

			if (typeof options === 'string') {
				typeof $.data(this, 'plugin_' + pluginName).options === 'function'
					&& $.data(this, 'plugin_' + pluginName).options(params);
			}
		});

		// chain jQuery functions
		return this;
	};

})(jQuery, window, document);
<|endoftext|>


<commit_before>(function()
{
    'use strict';

    angular
        .module('lumx.radio-button')
        .directive('lxRadioGroup', lxRadioGroup)
        .directive('lxRadioButton', lxRadioButton)
        .directive('lxRadioButtonLabel', lxRadioButtonLabel)
        .directive('lxRadioButtonHelp', lxRadioButtonHelp);

    function lxRadioGroup()
    {
        return {
            restrict: 'E',
            templateUrl: 'radio-group.html',
            transclude: true,
            replace: true
        };
    }

    function lxRadioButton()
    {
        return {
            restrict: 'E',
            templateUrl: 'radio-button.html',
            scope:
            {
                lxColor: '@?',
                name: '@',
                ngChange: '&?',
                ngDisabled: '=?',
                ngModel: '=',
                ngValue: '=?',
                value: '@?',
                lxTheme: '@?'
            },
            controller: LxRadioButtonController,
            controllerAs: 'lxRadioButton',
            bindToController: true,
            transclude: true,
            replace: true
        };
    }

    LxRadioButtonController.$inject = ['$scope', '$timeout', 'LxUtils'];

    function LxRadioButtonController($scope, $timeout, LxUtils)
    {
        var lxRadioButton = this;
        var radioButtonId;
        var radioButtonHasChildren;
        var timer;

        lxRadioButton.getRadioButtonId = getRadioButtonId;
        lxRadioButton.getRadioButtonHasChildren = getRadioButtonHasChildren;
        lxRadioButton.setRadioButtonId = setRadioButtonId;
        lxRadioButton.setRadioButtonHasChildren = setRadioButtonHasChildren;
        lxRadioButton.triggerNgChange = triggerNgChange;

        $scope.$on('$destroy', function()
        {
            $timeout.cancel(timer);
        });

        init();

        ////////////

        function getRadioButtonId()
        {
            return radioButtonId;
        }

        function getRadioButtonHasChildren()
        {
            return radioButtonHasChildren;
        }

        function init()
        {
            setRadioButtonId(LxUtils.generateUUID());
            setRadioButtonHasChildren(false);

            if (angular.isDefined(lxRadioButton.value) && angular.isUndefined(lxRadioButton.ngValue))
            {
                lxRadioButton.ngValue = lxRadioButton.value;
            }

            lxRadioButton.lxColor = angular.isUndefined(lxRadioButton.lxColor) ? 'accent' : lxRadioButton.lxColor;
        }

        function setRadioButtonId(_radioButtonId)
        {
            radioButtonId = _radioButtonId;
        }

        function setRadioButtonHasChildren(_radioButtonHasChildren)
        {
            radioButtonHasChildren = _radioButtonHasChildren;
        }

        function triggerNgChange()
        {
            timer = $timeout(lxRadioButton.ngChange);
        }
    }

    function lxRadioButtonLabel()
    {
        return {
            restrict: 'AE',
            require: ['^lxRadioButton', '^lxRadioButtonLabel'],
            templateUrl: 'radio-button-label.html',
            link: link,
            controller: LxRadioButtonLabelController,
            controllerAs: 'lxRadioButtonLabel',
            bindToController: true,
            transclude: true,
            replace: true
        };

        function link(scope, element, attrs, ctrls)
        {
            ctrls[0].setRadioButtonHasChildren(true);
            ctrls[1].setRadioButtonId(ctrls[0].getRadioButtonId());
        }
    }

    function LxRadioButtonLabelController()
    {
        var lxRadioButtonLabel = this;
        var radioButtonId;

        lxRadioButtonLabel.getRadioButtonId = getRadioButtonId;
        lxRadioButtonLabel.setRadioButtonId = setRadioButtonId;

        ////////////

        function getRadioButtonId()
        {
            return radioButtonId;
        }

        function setRadioButtonId(_radioButtonId)
        {
            radioButtonId = _radioButtonId;
        }
    }

    function lxRadioButtonHelp()
    {
        return {
            restrict: 'AE',
            require: '^lxRadioButton',
            templateUrl: 'radio-button-help.html',
            transclude: true,
            replace: true
        };
    }
})();
<commit_msg>fix radio: call init in the link function<commit_after>(function()
{
    'use strict';

    angular
        .module('lumx.radio-button')
        .directive('lxRadioGroup', lxRadioGroup)
        .directive('lxRadioButton', lxRadioButton)
        .directive('lxRadioButtonLabel', lxRadioButtonLabel)
        .directive('lxRadioButtonHelp', lxRadioButtonHelp);

    function lxRadioGroup()
    {
        return {
            restrict: 'E',
            templateUrl: 'radio-group.html',
            transclude: true,
            replace: true
        };
    }

    function lxRadioButton()
    {
        return {
            restrict: 'E',
            templateUrl: 'radio-button.html',
            scope:
            {
                lxColor: '@?',
                name: '@',
                ngChange: '&?',
                ngDisabled: '=?',
                ngModel: '=',
                ngValue: '=?',
                value: '@?',
                lxTheme: '@?'
            },
            controller: LxRadioButtonController,
            controllerAs: 'lxRadioButton',
            bindToController: true,
            transclude: true,
            link: function (scope, el, attrs, ctrl) {
                ctrl.init();
            },
            replace: true
        };
    }

    LxRadioButtonController.$inject = ['$scope', '$timeout', 'LxUtils'];

    function LxRadioButtonController($scope, $timeout, LxUtils)
    {
        var lxRadioButton = this;
        var radioButtonId;
        var radioButtonHasChildren;
        var timer;

        lxRadioButton.getRadioButtonId = getRadioButtonId;
        lxRadioButton.getRadioButtonHasChildren = getRadioButtonHasChildren;
        lxRadioButton.setRadioButtonId = setRadioButtonId;
        lxRadioButton.setRadioButtonHasChildren = setRadioButtonHasChildren;
        lxRadioButton.triggerNgChange = triggerNgChange;
        lxRadioButton.init = init;

        $scope.$on('$destroy', function()
        {
            $timeout.cancel(timer);
        });

        ////////////

        function getRadioButtonId()
        {
            return radioButtonId;
        }

        function getRadioButtonHasChildren()
        {
            return radioButtonHasChildren;
        }

        function init()
        {
            setRadioButtonId(LxUtils.generateUUID());
            setRadioButtonHasChildren(false);

            if (angular.isDefined(lxRadioButton.value) && angular.isUndefined(lxRadioButton.ngValue))
            {
                lxRadioButton.ngValue = lxRadioButton.value;
            }

            lxRadioButton.lxColor = angular.isUndefined(lxRadioButton.lxColor) ? 'accent' : lxRadioButton.lxColor;
        }

        function setRadioButtonId(_radioButtonId)
        {
            radioButtonId = _radioButtonId;
        }

        function setRadioButtonHasChildren(_radioButtonHasChildren)
        {
            radioButtonHasChildren = _radioButtonHasChildren;
        }

        function triggerNgChange()
        {
            timer = $timeout(lxRadioButton.ngChange);
        }
    }

    function lxRadioButtonLabel()
    {
        return {
            restrict: 'AE',
            require: ['^lxRadioButton', '^lxRadioButtonLabel'],
            templateUrl: 'radio-button-label.html',
            link: link,
            controller: LxRadioButtonLabelController,
            controllerAs: 'lxRadioButtonLabel',
            bindToController: true,
            transclude: true,
            replace: true
        };

        function link(scope, element, attrs, ctrls)
        {
            ctrls[0].setRadioButtonHasChildren(true);
            ctrls[1].setRadioButtonId(ctrls[0].getRadioButtonId());
        }
    }

    function LxRadioButtonLabelController()
    {
        var lxRadioButtonLabel = this;
        var radioButtonId;

        lxRadioButtonLabel.getRadioButtonId = getRadioButtonId;
        lxRadioButtonLabel.setRadioButtonId = setRadioButtonId;

        ////////////

        function getRadioButtonId()
        {
            return radioButtonId;
        }

        function setRadioButtonId(_radioButtonId)
        {
            radioButtonId = _radioButtonId;
        }
    }

    function lxRadioButtonHelp()
    {
        return {
            restrict: 'AE',
            require: '^lxRadioButton',
            templateUrl: 'radio-button-help.html',
            transclude: true,
            replace: true
        };
    }
})();
<|endoftext|>


<commit_before>/**
 * @preserve jquery.fullscreen 1.1.5
 * https://github.com/kayahr/jquery-fullscreen-plugin
 * Copyright (C) 2012-2013 Klaus Reimer <k@ailis.de>
 * Licensed under the MIT license
 * (See http://www.opensource.org/licenses/mit-license)
 */

(function(jQuery) {

/**
 * Sets or gets the fullscreen state.
 *
 * @param {boolean=} state
 *            True to enable fullscreen mode, false to disable it. If not
 *            specified then the current fullscreen state is returned.
 * @return {boolean|Element|jQuery|null}
 *            When querying the fullscreen state then the current fullscreen
 *            element (or true if browser doesn't support it) is returned
 *            when browser is currently in full screen mode. False is returned
 *            if browser is not in full screen mode. Null is returned if
 *            browser doesn't support fullscreen mode at all. When setting
 *            the fullscreen state then the current jQuery selection is
 *            returned for chaining.
 * @this {jQuery}
 */
function fullScreen(state)
{
    var e, func, doc;

    // Do nothing when nothing was selected
    if (!this.length) return this;

    // We only use the first selected element because it doesn't make sense
    // to fullscreen multiple elements.
    e = (/** @type {Element} */ this[0]);

    // Find the real element and the document (Depends on whether the
    // document itself or a HTML element was selected)
    if (e.ownerDocument)
    {
        doc = e.ownerDocument;
    }
    else
    {
        doc = e;
        e = doc.documentElement;
    }

    // When no state was specified then return the current state.
    if (state == null)
    {
        // When fullscreen mode is not supported then return null
        if (!((/** @type {?Function} */ doc["exitFullscreen"])
            || (/** @type {?Function} */ doc["webkitExitFullscreen"])
            || (/** @type {?Function} */ doc["webkitCancelFullScreen"])
            || (/** @type {?Function} */ doc["msExitFullscreen"])
            || (/** @type {?Function} */ doc["mozCancelFullScreen"])))
        {
            return null;
        }

        // Check fullscreen state
        state = !!doc["fullscreenElement"]
            || !!doc["msFullscreenElement"]
            || !!doc["webkitIsFullScreen"]
            || !!doc["mozFullScreen"];
        if (!state) return state;

        // Return current fullscreen element or "true" if browser doesn't
        // support this
        return (/** @type {?Element} */ doc["fullscreenElement"])
            || (/** @type {?Element} */ doc["webkitFullscreenElement"])
            || (/** @type {?Element} */ doc["webkitCurrentFullScreenElement"])
            || (/** @type {?Element} */ doc["msFullscreenElement"])
            || (/** @type {?Element} */ doc["mozFullScreenElement"])
            || state;
    }

    // When state was specified then enter or exit fullscreen mode.
    if (state)
    {
        // Enter fullscreen
        func = (/** @type {?Function} */ e["requestFullscreen"])
            || (/** @type {?Function} */ e["webkitRequestFullscreen"])
            || (/** @type {?Function} */ e["webkitRequestFullScreen"])
            || (/** @type {?Function} */ e["msRequestFullscreen"])
            || (/** @type {?Function} */ e["mozRequestFullScreen"]);
        if (func)
        {
            func.call(e);
        }
        return this;
    }
    else
    {
        // Exit fullscreen
        func = (/** @type {?Function} */ doc["exitFullscreen"])
            || (/** @type {?Function} */ doc["webkitExitFullscreen"])
            || (/** @type {?Function} */ doc["webkitCancelFullScreen"])
            || (/** @type {?Function} */ doc["msExitFullscreen"])
            || (/** @type {?Function} */ doc["mozCancelFullScreen"]);
        if (func) func.call(doc);
        return this;
    }
}

/**
 * Toggles the fullscreen mode.
 *
 * @return {!jQuery}
 *            The jQuery selection for chaining.
 * @this {jQuery}
 */
function toggleFullScreen()
{
    return (/** @type {!jQuery} */ fullScreen.call(this,
        !fullScreen.call(this)));
}

/**
 * Handles the browser-specific fullscreenchange event and triggers
 * a jquery event for it.
 *
 * @param {?Event} event
 *            The fullscreenchange event.
 */
function fullScreenChangeHandler(event)
{
    jQuery(document).trigger(new jQuery.Event("fullscreenchange"));
}

/**
 * Handles the browser-specific fullscreenerror event and triggers
 * a jquery event for it.
 *
 * @param {?Event} event
 *            The fullscreenerror event.
 */
function fullScreenErrorHandler(event)
{
    jQuery(document).trigger(new jQuery.Event("fullscreenerror"));
}

/**
 * Installs the fullscreenchange event handler.
 */
function installFullScreenHandlers()
{
    var e, change, error;

    // Determine event name
    e = document;
    if (e["webkitCancelFullScreen"])
    {
        change = "webkitfullscreenchange";
        error = "webkitfullscreenerror";
    }
    else if (e["msExitFullscreen"])
    {
        change = "MSFullscreenChange";
        error = "MSFullscreenError";
    }
    else if (e["mozCancelFullScreen"])
    {
        change = "mozfullscreenchange";
        error = "mozfullscreenerror";
    }
    else
    {
        change = "fullscreenchange";
        error = "fullscreenerror";
    }

    // Install the event handlers
    jQuery(document).bind(change, fullScreenChangeHandler);
    jQuery(document).bind(error, fullScreenErrorHandler);
}

jQuery.fn["fullScreen"] = fullScreen;
jQuery.fn["toggleFullScreen"] = toggleFullScreen;
installFullScreenHandlers();

})(jQuery);
<commit_msg>Prevent TypeError: Document not active - fixes #34<commit_after>/**
 * @preserve jquery.fullscreen 1.1.5
 * https://github.com/kayahr/jquery-fullscreen-plugin
 * Copyright (C) 2012-2013 Klaus Reimer <k@ailis.de>
 * Licensed under the MIT license
 * (See http://www.opensource.org/licenses/mit-license)
 */

(function(jQuery) {

/**
 * Sets or gets the fullscreen state.
 *
 * @param {boolean=} state
 *            True to enable fullscreen mode, false to disable it. If not
 *            specified then the current fullscreen state is returned.
 * @return {boolean|Element|jQuery|null}
 *            When querying the fullscreen state then the current fullscreen
 *            element (or true if browser doesn't support it) is returned
 *            when browser is currently in full screen mode. False is returned
 *            if browser is not in full screen mode. Null is returned if
 *            browser doesn't support fullscreen mode at all. When setting
 *            the fullscreen state then the current jQuery selection is
 *            returned for chaining.
 * @this {jQuery}
 */
function fullScreen(state)
{
    var e, func, doc;

    // Do nothing when nothing was selected
    if (!this.length) return this;

    // We only use the first selected element because it doesn't make sense
    // to fullscreen multiple elements.
    e = (/** @type {Element} */ this[0]);

    // Find the real element and the document (Depends on whether the
    // document itself or a HTML element was selected)
    if (e.ownerDocument)
    {
        doc = e.ownerDocument;
    }
    else
    {
        doc = e;
        e = doc.documentElement;
    }

    // When no state was specified then return the current state.
    if (state == null)
    {
        // When fullscreen mode is not supported then return null
        if (!((/** @type {?Function} */ doc["exitFullscreen"])
            || (/** @type {?Function} */ doc["webkitExitFullscreen"])
            || (/** @type {?Function} */ doc["webkitCancelFullScreen"])
            || (/** @type {?Function} */ doc["msExitFullscreen"])
            || (/** @type {?Function} */ doc["mozCancelFullScreen"])))
        {
            return null;
        }

        // Check fullscreen state
        state = fullScreenState(doc);
        if (!state) return state;

        // Return current fullscreen element or "true" if browser doesn't
        // support this
        return (/** @type {?Element} */ doc["fullscreenElement"])
            || (/** @type {?Element} */ doc["webkitFullscreenElement"])
            || (/** @type {?Element} */ doc["webkitCurrentFullScreenElement"])
            || (/** @type {?Element} */ doc["msFullscreenElement"])
            || (/** @type {?Element} */ doc["mozFullScreenElement"])
            || state;
    }

    // When state was specified then enter or exit fullscreen mode.
    if (state)
    {
        // Enter fullscreen
        func = (/** @type {?Function} */ e["requestFullscreen"])
            || (/** @type {?Function} */ e["webkitRequestFullscreen"])
            || (/** @type {?Function} */ e["webkitRequestFullScreen"])
            || (/** @type {?Function} */ e["msRequestFullscreen"])
            || (/** @type {?Function} */ e["mozRequestFullScreen"]);
        if (func)
        {
            func.call(e);
        }
        return this;
    }
    else
    {
        // Exit fullscreen
        func = (/** @type {?Function} */ doc["exitFullscreen"])
            || (/** @type {?Function} */ doc["webkitExitFullscreen"])
            || (/** @type {?Function} */ doc["webkitCancelFullScreen"])
            || (/** @type {?Function} */ doc["msExitFullscreen"])
            || (/** @type {?Function} */ doc["mozCancelFullScreen"]);
        if (func && fullScreenState(doc)) func.call(doc);
        return this;
    }
}

/**
 * Check fullscreen state
 *
 * @param {Document} doc The content document
 * @return {Boolean}
 */
function fullScreenState(doc) {
    return !!(doc["fullscreenElement"] || doc["msFullscreenElement"] || doc["webkitIsFullScreen"] || doc["mozFullScreen"]);
}

/**
 * Toggles the fullscreen mode.
 *
 * @return {!jQuery}
 *            The jQuery selection for chaining.
 * @this {jQuery}
 */
function toggleFullScreen()
{
    return (/** @type {!jQuery} */ fullScreen.call(this,
        !fullScreen.call(this)));
}

/**
 * Handles the browser-specific fullscreenchange event and triggers
 * a jquery event for it.
 *
 * @param {?Event} event
 *            The fullscreenchange event.
 */
function fullScreenChangeHandler(event)
{
    jQuery(document).trigger(new jQuery.Event("fullscreenchange"));
}

/**
 * Handles the browser-specific fullscreenerror event and triggers
 * a jquery event for it.
 *
 * @param {?Event} event
 *            The fullscreenerror event.
 */
function fullScreenErrorHandler(event)
{
    jQuery(document).trigger(new jQuery.Event("fullscreenerror"));
}

/**
 * Installs the fullscreenchange event handler.
 */
function installFullScreenHandlers()
{
    var e, change, error;

    // Determine event name
    e = document;
    if (e["webkitCancelFullScreen"])
    {
        change = "webkitfullscreenchange";
        error = "webkitfullscreenerror";
    }
    else if (e["msExitFullscreen"])
    {
        change = "MSFullscreenChange";
        error = "MSFullscreenError";
    }
    else if (e["mozCancelFullScreen"])
    {
        change = "mozfullscreenchange";
        error = "mozfullscreenerror";
    }
    else
    {
        change = "fullscreenchange";
        error = "fullscreenerror";
    }

    // Install the event handlers
    jQuery(document).bind(change, fullScreenChangeHandler);
    jQuery(document).bind(error, fullScreenErrorHandler);
}

jQuery.fn["fullScreen"] = fullScreen;
jQuery.fn["toggleFullScreen"] = toggleFullScreen;
installFullScreenHandlers();

})(jQuery);
<|endoftext|>


<commit_before>var blizzard = {
    'abathur': 'http://media.blizzard.com/heroes/videos/heroes/skins/abathur_evolutionMaster.webm',
    'anubarak': 'http://media.blizzard.com/heroes/videos/heroes/skins/anubarak_traitorKing.webm',
    'arthas': 'http://media.blizzard.com/heroes/videos/heroes/skins/arthas_theLichKing.webm',
    'azmodan': 'http://media.blizzard.com/heroes/videos/heroes/skins/azmodan_lordOfSin.webm',
    'brightwing': 'http://media.blizzard.com/heroes/videos/heroes/skins/brightwing_faerieDragon.webm',
    'chen': 'http://media.blizzard.com/heroes/videos/heroes/skins/chen_legendaryBrewmaster.webm',
    'diablo': 'http://media.blizzard.com/heroes/videos/heroes/skins/diablo_lordOfTerror.webm',
    'etc': 'http://media.blizzard.com/heroes/videos/heroes/skins/etc_rockGod.webm',
    'falstad': 'http://media.blizzard.com/heroes/videos/heroes/skins/falstad_wildhammerThane.webm',
    'gazlowe': 'http://media.blizzard.com/heroes/videos/heroes/skins/gazlowe_bossOfRatchet.webm',
    'illidan': 'http://media.blizzard.com/heroes/videos/heroes/skins/illidan_theBetrayer.webm',
    'jaina': 'http://media.blizzard.com/heroes/videos/heroes/skins/jaina_archmage.webm',
    'kaelthas': 'http://media.blizzard.com/heroes/videos/heroes/skins/kaelthas_theSunKing.webm',
    'kerrigan': 'http://media.blizzard.com/heroes/videos/heroes/skins/kerrigan_queenOfBlades.webm',
    'lili': 'http://media.blizzard.com/heroes/videos/heroes/skins/lili_worldWanderer.webm',
    'malfurion': 'http://media.blizzard.com/heroes/videos/heroes/skins/malfurion_archdruid.webm',
    'muradin': 'http://media.blizzard.com/heroes/videos/heroes/skins/muradin_mountainKing.webm',
    'murky': 'http://media.blizzard.com/heroes/videos/heroes/skins/murky_babyMurloc.webm',
    'nazeebo': 'http://media.blizzard.com/heroes/videos/heroes/skins/nazeebo_hereticWitchDoctor.webm',
    'nova': 'http://media.blizzard.com/heroes/videos/heroes/skins/nova_dominionGhost.webm',
    'raynor': 'http://media.blizzard.com/heroes/videos/heroes/skins/raynor_renegadeCommander.webm',
    'rehgar': 'http://media.blizzard.com/heroes/videos/heroes/skins/rehgar_shamanOfTheEarthenRing.webm',
    'sgt-hammer': 'http://media.blizzard.com/heroes/videos/heroes/skins/sgt-hammer_siegeTankOperator.webm',
    'sonya': 'http://media.blizzard.com/heroes/videos/heroes/skins/sonya_wanderingBarbarian.webm',
    'stitches': 'http://media.blizzard.com/heroes/videos/heroes/skins/stitches_terrorOfDarkshire.webm',
    'sylvanas': 'http://media.blizzard.com/heroes/videos/heroes/skins/sylvanas_theBansheeQueen.webm',
    'tassadar': 'http://media.blizzard.com/heroes/videos/heroes/skins/tassadar_saviorOfTheTemplar.webm',
    'the-lost-vikings': 'http://media.blizzard.com/heroes/videos/heroes/skins/the-lost-vikings_tripleTrouble.webm',
    'thrall': 'http://media.blizzard.com/heroes/videos/heroes/skins/thrall_warchiefOfTheHorde.webm',
    'tychus': 'http://media.blizzard.com/heroes/videos/heroes/skins/tychus_notoriousOutlaw.webm',
    'tyrael': 'http://media.blizzard.com/heroes/videos/heroes/skins/tyrael_archangelOfJustice.webm',
    'tyrande': 'http://media.blizzard.com/heroes/videos/heroes/skins/tyrande_highPriestessOfElune.webm',
    'uther': 'http://media.blizzard.com/heroes/videos/heroes/skins/uther_theLightbringer.webm',
    'valla': 'http://media.blizzard.com/heroes/videos/heroes/skins/valla_demonHunter.webm',
    'zagara': 'http://media.blizzard.com/heroes/videos/heroes/skins/zagara_broodmotherOfTheSwarm.webm',
    'zeratul': 'http://media.blizzard.com/heroes/videos/heroes/skins/zeratul_darkPrelate.webm'
};

var regex_color = new RegExp(
   "(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)"
 );

var regex_url = new RegExp(
  "^" +
    // protocol identifier
    "(?:(?:https?|ftp)://)" +
    // user:pass authentication
    "(?:\\S+(?::\\S*)?@)?" +
    "(?:" +
      // IP address exclusion
      // private & local networks
      "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
      "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
      "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
      // IP address dotted notation octets
      // excludes loopback network 0.0.0.0
      // excludes reserved space >= 224.0.0.0
      // excludes network & broacast addresses
      // (first & last IP address of each class)
      "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
      "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
      "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
    "|" +
      // host name
      "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
      // domain name
      "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
      // TLD identifier
      "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))*" +
    ")" +
    // port number
    "(?::\\d{2,5})?" +
    // resource path
    "(?:/\\S*)?" +
  "$", "i"
);

function properName(hero) {
    if (hero.indexOf('_') > 0) {
        hero = hero.substring(0, hero.indexOf('_'));
    }
    switch (hero) {
        case 'anubarak':
            return "Anub'arak";
            break;
        case 'etc':
            return "ETC";
            break;
        case 'kaelthas':
            return "Kael'thas";
            break;
        case 'lili':
            return "Li Li";
            break;
        case 'sgt-hammer':
            return "Sgt. Hammer";
            break;
        case 'the-lost-vikings':
            return "The Lost Vikings";
            break;
        default:
            return hero.charAt(0).toUpperCase()+hero.substr(1).toLowerCase();
    }
}

function getHeroVideo(hero) {
    // return "/assets/hero-videos/"+hero+".webm";

    return blizzard[hero];
}

// Catch ESC anywhere to blur the element, which should process the input
$(document).keyup(function(e) {
    if (e.keyCode == 27) { $(document.activeElement).blur(); }   // escape key maps to keycode `27`
});<commit_msg>minor - add buildWildcardClass function for removeClass limitation<commit_after>var blizzard = {
    'abathur': 'http://media.blizzard.com/heroes/videos/heroes/skins/abathur_evolutionMaster.webm',
    'anubarak': 'http://media.blizzard.com/heroes/videos/heroes/skins/anubarak_traitorKing.webm',
    'arthas': 'http://media.blizzard.com/heroes/videos/heroes/skins/arthas_theLichKing.webm',
    'azmodan': 'http://media.blizzard.com/heroes/videos/heroes/skins/azmodan_lordOfSin.webm',
    'brightwing': 'http://media.blizzard.com/heroes/videos/heroes/skins/brightwing_faerieDragon.webm',
    'chen': 'http://media.blizzard.com/heroes/videos/heroes/skins/chen_legendaryBrewmaster.webm',
    'diablo': 'http://media.blizzard.com/heroes/videos/heroes/skins/diablo_lordOfTerror.webm',
    'etc': 'http://media.blizzard.com/heroes/videos/heroes/skins/etc_rockGod.webm',
    'falstad': 'http://media.blizzard.com/heroes/videos/heroes/skins/falstad_wildhammerThane.webm',
    'gazlowe': 'http://media.blizzard.com/heroes/videos/heroes/skins/gazlowe_bossOfRatchet.webm',
    'illidan': 'http://media.blizzard.com/heroes/videos/heroes/skins/illidan_theBetrayer.webm',
    'jaina': 'http://media.blizzard.com/heroes/videos/heroes/skins/jaina_archmage.webm',
    'kaelthas': 'http://media.blizzard.com/heroes/videos/heroes/skins/kaelthas_theSunKing.webm',
    'kerrigan': 'http://media.blizzard.com/heroes/videos/heroes/skins/kerrigan_queenOfBlades.webm',
    'lili': 'http://media.blizzard.com/heroes/videos/heroes/skins/lili_worldWanderer.webm',
    'malfurion': 'http://media.blizzard.com/heroes/videos/heroes/skins/malfurion_archdruid.webm',
    'muradin': 'http://media.blizzard.com/heroes/videos/heroes/skins/muradin_mountainKing.webm',
    'murky': 'http://media.blizzard.com/heroes/videos/heroes/skins/murky_babyMurloc.webm',
    'nazeebo': 'http://media.blizzard.com/heroes/videos/heroes/skins/nazeebo_hereticWitchDoctor.webm',
    'nova': 'http://media.blizzard.com/heroes/videos/heroes/skins/nova_dominionGhost.webm',
    'raynor': 'http://media.blizzard.com/heroes/videos/heroes/skins/raynor_renegadeCommander.webm',
    'rehgar': 'http://media.blizzard.com/heroes/videos/heroes/skins/rehgar_shamanOfTheEarthenRing.webm',
    'sgt-hammer': 'http://media.blizzard.com/heroes/videos/heroes/skins/sgt-hammer_siegeTankOperator.webm',
    'sonya': 'http://media.blizzard.com/heroes/videos/heroes/skins/sonya_wanderingBarbarian.webm',
    'stitches': 'http://media.blizzard.com/heroes/videos/heroes/skins/stitches_terrorOfDarkshire.webm',
    'sylvanas': 'http://media.blizzard.com/heroes/videos/heroes/skins/sylvanas_theBansheeQueen.webm',
    'tassadar': 'http://media.blizzard.com/heroes/videos/heroes/skins/tassadar_saviorOfTheTemplar.webm',
    'the-lost-vikings': 'http://media.blizzard.com/heroes/videos/heroes/skins/the-lost-vikings_tripleTrouble.webm',
    'thrall': 'http://media.blizzard.com/heroes/videos/heroes/skins/thrall_warchiefOfTheHorde.webm',
    'tychus': 'http://media.blizzard.com/heroes/videos/heroes/skins/tychus_notoriousOutlaw.webm',
    'tyrael': 'http://media.blizzard.com/heroes/videos/heroes/skins/tyrael_archangelOfJustice.webm',
    'tyrande': 'http://media.blizzard.com/heroes/videos/heroes/skins/tyrande_highPriestessOfElune.webm',
    'uther': 'http://media.blizzard.com/heroes/videos/heroes/skins/uther_theLightbringer.webm',
    'valla': 'http://media.blizzard.com/heroes/videos/heroes/skins/valla_demonHunter.webm',
    'zagara': 'http://media.blizzard.com/heroes/videos/heroes/skins/zagara_broodmotherOfTheSwarm.webm',
    'zeratul': 'http://media.blizzard.com/heroes/videos/heroes/skins/zeratul_darkPrelate.webm'
};

var regex_color = new RegExp(
   "(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)"
 );

var regex_url = new RegExp(
  "^" +
    // protocol identifier
    "(?:(?:https?|ftp)://)" +
    // user:pass authentication
    "(?:\\S+(?::\\S*)?@)?" +
    "(?:" +
      // IP address exclusion
      // private & local networks
      "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
      "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
      "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
      // IP address dotted notation octets
      // excludes loopback network 0.0.0.0
      // excludes reserved space >= 224.0.0.0
      // excludes network & broacast addresses
      // (first & last IP address of each class)
      "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
      "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
      "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
    "|" +
      // host name
      "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
      // domain name
      "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
      // TLD identifier
      "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))*" +
    ")" +
    // port number
    "(?::\\d{2,5})?" +
    // resource path
    "(?:/\\S*)?" +
  "$", "i"
);

function properName(hero) {
    if (hero.indexOf('_') > 0) {
        hero = hero.substring(0, hero.indexOf('_'));
    }
    switch (hero) {
        case 'anubarak':
            return "Anub'arak";
            break;
        case 'etc':
            return "ETC";
            break;
        case 'kaelthas':
            return "Kael'thas";
            break;
        case 'lili':
            return "Li Li";
            break;
        case 'sgt-hammer':
            return "Sgt. Hammer";
            break;
        case 'the-lost-vikings':
            return "The Lost Vikings";
            break;
        default:
            return hero.charAt(0).toUpperCase()+hero.substr(1).toLowerCase();
    }
}

function getHeroVideo(hero) {
    // return "/assets/hero-videos/"+hero+".webm";

    return blizzard[hero];
}

function buildWildcardClass(prefix) {
  return function (index, css) {
    return (css.match (new RegExp("(^|\\s)" + prefix + "-\\S+", "g") ) || []).join(' ');
  }
}

// Catch ESC anywhere to blur the element, which should process the input
$(document).keyup(function(e) {
    if (e.keyCode == 27) { $(document.activeElement).blur(); }   // escape key maps to keycode `27`
});<|endoftext|>


<commit_before>(function($) {
	var has_VML, create_canvas_for, add_shape_to, clear_canvas, shape_from_area,
		canvas_style, fader, hex_to_decimal, css3color, is_image_loaded, options_from_area;

	has_VML = document.namespaces;
	has_canvas = !!document.createElement('canvas').getContext;

	if(!(has_canvas || has_VML)) {
		$.fn.maphilight = function() { return this; };
		return;
	}

	if(has_canvas) {
		fader = function(element, opacity, interval) {
			if(opacity <= 1) {
				element.style.opacity = opacity;
				window.setTimeout(fader, 10, element, opacity + 0.1, 10);
			}
		};

		hex_to_decimal = function(hex) {
			return Math.max(0, Math.min(parseInt(hex, 16), 255));
		};
		css3color = function(color, opacity) {
			return 'rgba('+hex_to_decimal(color.substr(0,2))+','+hex_to_decimal(color.substr(2,2))+','+hex_to_decimal(color.substr(4,2))+','+opacity+')';
		};
		create_canvas_for = function(img) {
			var c = $('<canvas style="width:'+img.width+'px;height:'+img.height+'px;"></canvas>').get(0);
			c.getContext("2d").clearRect(0, 0, c.width, c.height);
			return c;
		};
		add_shape_to = function(canvas, shape, coords, options, name) {
			var i, context = canvas.getContext('2d');
			context.beginPath();
			if(shape == 'rect') {
				context.rect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
			} else if(shape == 'poly') {
				context.moveTo(coords[0], coords[1]);
				for(i=2; i < coords.length; i+=2) {
					context.lineTo(coords[i], coords[i+1]);
				}
			} else if(shape == 'circ') {
				context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2, false);
			}
			context.closePath();
			if(options.fill) {
				context.fillStyle = css3color(options.fillColor, options.fillOpacity);
				context.fill();
			}
			if(options.stroke) {
				context.strokeStyle = css3color(options.strokeColor, options.strokeOpacity);
				context.lineWidth = options.strokeWidth;
				context.stroke();
			}
			if(options.fade) {
				fader(canvas, 0);
			}
		};
		clear_canvas = function(canvas) {
			canvas.getContext('2d').clearRect(0, 0, canvas.width,canvas.height);
		};
	} else {   // ie executes this code
		create_canvas_for = function(img) {
			return $('<var style="zoom:1;overflow:hidden;display:block;width:'+img.width+'px;height:'+img.height+'px;"></var>').get(0);
		};
		add_shape_to = function(canvas, shape, coords, options, name) {
			var fill, stroke, opacity, e;
			fill = '<v:fill color="#'+options.fillColor+'" opacity="'+(options.fill ? options.fillOpacity : 0)+'" />';
			stroke = (options.stroke ? 'strokeweight="'+options.strokeWidth+'" stroked="t" strokecolor="#'+options.strokeColor+'"' : 'stroked="f"');
			opacity = '<v:stroke opacity="'+options.strokeOpacity+'"/>';
			if(shape == 'rect') {
				e = $('<v:rect name="'+name+'" filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+coords[0]+'px;top:'+coords[1]+'px;width:'+(coords[2] - coords[0])+'px;height:'+(coords[3] - coords[1])+'px;"></v:rect>');
			} else if(shape == 'poly') {
				e = $('<v:shape name="'+name+'" filled="t" '+stroke+' coordorigin="0,0" coordsize="'+canvas.width+','+canvas.height+'" path="m '+coords[0]+','+coords[1]+' l '+coords.join(',')+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+canvas.width+'px;height:'+canvas.height+'px;"></v:shape>');
			} else if(shape == 'circ') {
				e = $('<v:oval name="'+name+'" filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(coords[0] - coords[2])+'px;top:'+(coords[1] - coords[2])+'px;width:'+(coords[2]*2)+'px;height:'+(coords[2]*2)+'px;"></v:oval>');
			}
			e.get(0).innerHTML = fill+opacity;
			$(canvas).append(e);
		};
		clear_canvas = function(canvas) {
			$(canvas).find('[name=highlighted]').remove();
		};
	}

	shape_from_area = function(area) {
		var i, coords = area.getAttribute('coords').split(',');
		for (i=0; i < coords.length; i++) { coords[i] = parseFloat(coords[i]); }
		return [area.getAttribute('shape').toLowerCase().substr(0,4), coords];
	};

	options_from_area = function(area, options) {
		var $area = $(area);
		return $.extend({}, options, $.metadata ? $area.metadata() : false, $area.data('maphilight'));
	};

	is_image_loaded = function(img) {
		if(!img.complete) { return false; } // IE
		if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; } // Others
		return true;
	};

	canvas_style = {
		position: 'absolute',
		left: 0,
		top: 0,
		padding: 0,
		border: 0
	};

	var ie_hax_done = false;
	$.fn.maphilight = function(opts) {
		opts = $.extend({}, $.fn.maphilight.defaults, opts);

		if($.browser.msie && !ie_hax_done) {
			document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
			var style = document.createStyleSheet();
			var shapes = ['shape','rect', 'oval', 'circ', 'fill', 'stroke', 'imagedata', 'group','textbox'];
			$.each(shapes,
				function() {
					style.addRule('v\\:' + this, "behavior: url(#default#VML); antialias:true");
				}
			);
			ie_hax_done = true;
		}

		return this.each(function() {
			var img, wrap, options, map, canvas, canvas_always, mouseover, highlighted_shape, usemap;
			img = $(this);

			if(!is_image_loaded(this)) {
				// If the image isn't fully loaded, this won't work right.  Try again later.
				return window.setTimeout(function() {
					img.maphilight(opts);
				}, 200);
			}

			options = $.extend({}, opts, $.metadata ? img.metadata() : false, img.data('maphilight'));

			// jQuery bug with Opera, results in full-url#usemap being returned from jQuery's attr.
			// So use raw getAttribute instead.
			usemap = img.get(0).getAttribute('usemap');

			map = $('map[name="'+usemap.substr(1)+'"]');

			if(!(img.is('img') && usemap && map.size() > 0)) { return; }

			if(img.hasClass('maphilighted')) {
				// We're redrawing an old map, probably to pick up changes to the options.
				// Just clear out all the old stuff.
				var wrapper = img.parent();
				img.insertBefore(wrapper);
				wrapper.remove();
				$(map).unbind('.maphilight').find('area[coords]').unbind('.maphilight');
			}

			wrap = $('

').css({
				display:'block',
				background:'url('+this.src+')',
				position:'relative',
				padding:0,
				width:this.width,
				height:this.height
				});
			if(options.wrapClass) {
				if(options.wrapClass === true) {
					wrap.addClass($(this).attr('class'));
				} else {
					wrap.addClass(options.wrapClass);
				}
			}
			img.before(wrap).css('opacity', 0).css(canvas_style).remove();
			if($.browser.msie) { img.css('filter', 'Alpha(opacity=0)'); }
			wrap.append(img);

			canvas = create_canvas_for(this);
			$(canvas).css(canvas_style);
			canvas.height = this.height;
			canvas.width = this.width;

			mouseover = function(e) {
				var shape, area_options;
				area_options = options_from_area(this, options);
				if(
					!area_options.neverOn
					&&
					!area_options.alwaysOn
				) {
					shape = shape_from_area(this);
					add_shape_to(canvas, shape[0], shape[1], area_options, "highlighted");
					if(area_options.groupBy && $(this).attr(area_options.groupBy)) {
						var first = this;
						map.find('area['+area_options.groupBy+'='+$(this).attr(area_options.groupBy)+']').each(function() {
							if(this != first) {
								var subarea_options = options_from_area(this, options);
								if(!subarea_options.neverOn && !subarea_options.alwaysOn) {
									var shape = shape_from_area(this);
									add_shape_to(canvas, shape[0], shape[1], subarea_options, "highlighted");
								}
							}
						});
					}
					// workaround for IE7, IE8 not rendering the final rectangle in a group
					$(canvas).append('<v:rect></v:rect>');
				}
			}

			$(map).bind('alwaysOn.maphilight', function() {
				// Check for areas with alwaysOn set. These are added to a *second* canvas,
				// which will get around flickering during fading.
				if(canvas_always) {
					clear_canvas(canvas_always)
				}
				if(!has_canvas) {
					$(canvas).empty();
				}
				$(map).find('area[coords]').each(function() {
					var shape, area_options;
					area_options = options_from_area(this, options);
					if(area_options.alwaysOn) {
						if(!canvas_always && has_canvas) {
							canvas_always = create_canvas_for(img.get());
							$(canvas_always).css(canvas_style);
							canvas_always.width = img.width();
							canvas_always.height = img.height();
							img.before(canvas_always);
						}
						shape = shape_from_area(this);
						if (has_canvas) {
							add_shape_to(canvas_always, shape[0], shape[1], area_options, "");
						} else {
							add_shape_to(canvas, shape[0], shape[1], area_options, "");
						}
					}
				});
			});

			$(map).trigger('alwaysOn.maphilight').find('area[coords]')
				.bind('mouseover.maphilight', mouseover)
				.bind('mouseout.maphilight', function(e) { clear_canvas(canvas); });;

			img.before(canvas); // if we put this after, the mouseover events wouldn't fire.

			img.addClass('maphilighted');
		});
	};
	$.fn.maphilight.defaults = {
		fill: true,
		fillColor: '000000',
		fillOpacity: 0.2,
		stroke: true,
		strokeColor: 'ff0000',
		strokeOpacity: 1,
		strokeWidth: 1,
		fade: true,
		alwaysOn: false,
		neverOn: false,
		groupBy: false,
		wrapClass: true
	};
})(jQuery);
<commit_msg>Wrap url in quotes<commit_after>(function($) {
	var has_VML, create_canvas_for, add_shape_to, clear_canvas, shape_from_area,
		canvas_style, fader, hex_to_decimal, css3color, is_image_loaded, options_from_area;

	has_VML = document.namespaces;
	has_canvas = !!document.createElement('canvas').getContext;

	if(!(has_canvas || has_VML)) {
		$.fn.maphilight = function() { return this; };
		return;
	}

	if(has_canvas) {
		fader = function(element, opacity, interval) {
			if(opacity <= 1) {
				element.style.opacity = opacity;
				window.setTimeout(fader, 10, element, opacity + 0.1, 10);
			}
		};

		hex_to_decimal = function(hex) {
			return Math.max(0, Math.min(parseInt(hex, 16), 255));
		};
		css3color = function(color, opacity) {
			return 'rgba('+hex_to_decimal(color.substr(0,2))+','+hex_to_decimal(color.substr(2,2))+','+hex_to_decimal(color.substr(4,2))+','+opacity+')';
		};
		create_canvas_for = function(img) {
			var c = $('<canvas style="width:'+img.width+'px;height:'+img.height+'px;"></canvas>').get(0);
			c.getContext("2d").clearRect(0, 0, c.width, c.height);
			return c;
		};
		add_shape_to = function(canvas, shape, coords, options, name) {
			var i, context = canvas.getContext('2d');
			context.beginPath();
			if(shape == 'rect') {
				context.rect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
			} else if(shape == 'poly') {
				context.moveTo(coords[0], coords[1]);
				for(i=2; i < coords.length; i+=2) {
					context.lineTo(coords[i], coords[i+1]);
				}
			} else if(shape == 'circ') {
				context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2, false);
			}
			context.closePath();
			if(options.fill) {
				context.fillStyle = css3color(options.fillColor, options.fillOpacity);
				context.fill();
			}
			if(options.stroke) {
				context.strokeStyle = css3color(options.strokeColor, options.strokeOpacity);
				context.lineWidth = options.strokeWidth;
				context.stroke();
			}
			if(options.fade) {
				fader(canvas, 0);
			}
		};
		clear_canvas = function(canvas) {
			canvas.getContext('2d').clearRect(0, 0, canvas.width,canvas.height);
		};
	} else {   // ie executes this code
		create_canvas_for = function(img) {
			return $('<var style="zoom:1;overflow:hidden;display:block;width:'+img.width+'px;height:'+img.height+'px;"></var>').get(0);
		};
		add_shape_to = function(canvas, shape, coords, options, name) {
			var fill, stroke, opacity, e;
			fill = '<v:fill color="#'+options.fillColor+'" opacity="'+(options.fill ? options.fillOpacity : 0)+'" />';
			stroke = (options.stroke ? 'strokeweight="'+options.strokeWidth+'" stroked="t" strokecolor="#'+options.strokeColor+'"' : 'stroked="f"');
			opacity = '<v:stroke opacity="'+options.strokeOpacity+'"/>';
			if(shape == 'rect') {
				e = $('<v:rect name="'+name+'" filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+coords[0]+'px;top:'+coords[1]+'px;width:'+(coords[2] - coords[0])+'px;height:'+(coords[3] - coords[1])+'px;"></v:rect>');
			} else if(shape == 'poly') {
				e = $('<v:shape name="'+name+'" filled="t" '+stroke+' coordorigin="0,0" coordsize="'+canvas.width+','+canvas.height+'" path="m '+coords[0]+','+coords[1]+' l '+coords.join(',')+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+canvas.width+'px;height:'+canvas.height+'px;"></v:shape>');
			} else if(shape == 'circ') {
				e = $('<v:oval name="'+name+'" filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(coords[0] - coords[2])+'px;top:'+(coords[1] - coords[2])+'px;width:'+(coords[2]*2)+'px;height:'+(coords[2]*2)+'px;"></v:oval>');
			}
			e.get(0).innerHTML = fill+opacity;
			$(canvas).append(e);
		};
		clear_canvas = function(canvas) {
			$(canvas).find('[name=highlighted]').remove();
		};
	}

	shape_from_area = function(area) {
		var i, coords = area.getAttribute('coords').split(',');
		for (i=0; i < coords.length; i++) { coords[i] = parseFloat(coords[i]); }
		return [area.getAttribute('shape').toLowerCase().substr(0,4), coords];
	};

	options_from_area = function(area, options) {
		var $area = $(area);
		return $.extend({}, options, $.metadata ? $area.metadata() : false, $area.data('maphilight'));
	};

	is_image_loaded = function(img) {
		if(!img.complete) { return false; } // IE
		if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; } // Others
		return true;
	};

	canvas_style = {
		position: 'absolute',
		left: 0,
		top: 0,
		padding: 0,
		border: 0
	};

	var ie_hax_done = false;
	$.fn.maphilight = function(opts) {
		opts = $.extend({}, $.fn.maphilight.defaults, opts);

		if($.browser.msie && !ie_hax_done) {
			document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
			var style = document.createStyleSheet();
			var shapes = ['shape','rect', 'oval', 'circ', 'fill', 'stroke', 'imagedata', 'group','textbox'];
			$.each(shapes,
				function() {
					style.addRule('v\\:' + this, "behavior: url(#default#VML); antialias:true");
				}
			);
			ie_hax_done = true;
		}

		return this.each(function() {
			var img, wrap, options, map, canvas, canvas_always, mouseover, highlighted_shape, usemap;
			img = $(this);

			if(!is_image_loaded(this)) {
				// If the image isn't fully loaded, this won't work right.  Try again later.
				return window.setTimeout(function() {
					img.maphilight(opts);
				}, 200);
			}

			options = $.extend({}, opts, $.metadata ? img.metadata() : false, img.data('maphilight'));

			// jQuery bug with Opera, results in full-url#usemap being returned from jQuery's attr.
			// So use raw getAttribute instead.
			usemap = img.get(0).getAttribute('usemap');

			map = $('map[name="'+usemap.substr(1)+'"]');

			if(!(img.is('img') && usemap && map.size() > 0)) { return; }

			if(img.hasClass('maphilighted')) {
				// We're redrawing an old map, probably to pick up changes to the options.
				// Just clear out all the old stuff.
				var wrapper = img.parent();
				img.insertBefore(wrapper);
				wrapper.remove();
				$(map).unbind('.maphilight').find('area[coords]').unbind('.maphilight');
			}

			wrap = $('

').css({
				display:'block',
				background:'url("'+this.src+'")',
				position:'relative',
				padding:0,
				width:this.width,
				height:this.height
				});
			if(options.wrapClass) {
				if(options.wrapClass === true) {
					wrap.addClass($(this).attr('class'));
				} else {
					wrap.addClass(options.wrapClass);
				}
			}
			img.before(wrap).css('opacity', 0).css(canvas_style).remove();
			if($.browser.msie) { img.css('filter', 'Alpha(opacity=0)'); }
			wrap.append(img);

			canvas = create_canvas_for(this);
			$(canvas).css(canvas_style);
			canvas.height = this.height;
			canvas.width = this.width;

			mouseover = function(e) {
				var shape, area_options;
				area_options = options_from_area(this, options);
				if(
					!area_options.neverOn
					&&
					!area_options.alwaysOn
				) {
					shape = shape_from_area(this);
					add_shape_to(canvas, shape[0], shape[1], area_options, "highlighted");
					if(area_options.groupBy && $(this).attr(area_options.groupBy)) {
						var first = this;
						map.find('area['+area_options.groupBy+'='+$(this).attr(area_options.groupBy)+']').each(function() {
							if(this != first) {
								var subarea_options = options_from_area(this, options);
								if(!subarea_options.neverOn && !subarea_options.alwaysOn) {
									var shape = shape_from_area(this);
									add_shape_to(canvas, shape[0], shape[1], subarea_options, "highlighted");
								}
							}
						});
					}
					// workaround for IE7, IE8 not rendering the final rectangle in a group
					$(canvas).append('<v:rect></v:rect>');
				}
			}

			$(map).bind('alwaysOn.maphilight', function() {
				// Check for areas with alwaysOn set. These are added to a *second* canvas,
				// which will get around flickering during fading.
				if(canvas_always) {
					clear_canvas(canvas_always)
				}
				if(!has_canvas) {
					$(canvas).empty();
				}
				$(map).find('area[coords]').each(function() {
					var shape, area_options;
					area_options = options_from_area(this, options);
					if(area_options.alwaysOn) {
						if(!canvas_always && has_canvas) {
							canvas_always = create_canvas_for(img.get());
							$(canvas_always).css(canvas_style);
							canvas_always.width = img.width();
							canvas_always.height = img.height();
							img.before(canvas_always);
						}
						shape = shape_from_area(this);
						if (has_canvas) {
							add_shape_to(canvas_always, shape[0], shape[1], area_options, "");
						} else {
							add_shape_to(canvas, shape[0], shape[1], area_options, "");
						}
					}
				});
			});

			$(map).trigger('alwaysOn.maphilight').find('area[coords]')
				.bind('mouseover.maphilight', mouseover)
				.bind('mouseout.maphilight', function(e) { clear_canvas(canvas); });;

			img.before(canvas); // if we put this after, the mouseover events wouldn't fire.

			img.addClass('maphilighted');
		});
	};
	$.fn.maphilight.defaults = {
		fill: true,
		fillColor: '000000',
		fillOpacity: 0.2,
		stroke: true,
		strokeColor: 'ff0000',
		strokeOpacity: 1,
		strokeWidth: 1,
		fade: true,
		alwaysOn: false,
		neverOn: false,
		groupBy: false,
		wrapClass: true
	};
})(jQuery);
<|endoftext|>


<commit_before>module.exports = {
  apps: [
    {
      name: 'simplexnoisemapgenerator',
      script: 'index.js',
      max_memory_restart: '1024M',
      instances: 0,
      log_date_format: 'YYYY-MM-DD HH:mm:ss.SSS'
    }
  ]
}
<commit_msg>Set up watch flag in pm2 ecosystem file<commit_after>module.exports = {
  apps: [
    {
      name: 'simplexnoisemapgenerator',
      script: 'index.js',
      max_memory_restart: '1024M',
      instances: 0,
      log_date_format: 'YYYY-MM-DD HH:mm:ss.SSS',
      watch: true
    }
  ]
}
<|endoftext|>


<commit_before>function subscribe(){
	cordova.exec(function(){
		console.log("test has been called success");
	}, function(){
		console.log("error happened");
	}, "MQTTService", "test", null);
}

exports.subscribe = subscribe;<commit_msg>fix small bug<commit_after>function subscribe(){
	cordova.exec(function(){
		console.log("test has been called success");
	}, function(){
		console.log("error happened");
	}, "MQTTService", "test", []);
}

exports.subscribe = subscribe;<|endoftext|>


<commit_before>var raw_toks = {
    ":": true,
    ",": true,
    ".": true,
    "..": true,//not actually used, this is just a hack
    "...": true,
    "?": true,
    "=": true,
    "(": true,
    ")": true,
    "[": true,
    "]": true,
    "{": true,
    "}": true,
    "==": true,
    "!=": true,
    "<": true,
    "<=": true,
    ">": true,
    ">=": true,
    "+": true,
    "-": true,
    "*": true,
    "/": true,
    "%": true,
};

module.exports = function(src, opts){
    opts = opts || {};

    var throwOnInvalidChar = function(c, message){
        var i = src.indexOf(c);
        if(i >= 0){
            throw {
                type: "InvalidCharacter",
                message: message,
                src: c,
                loc: {start: i, end: i + 1},
            };
        }
    };

    throwOnInvalidChar("\t", "Tabs (\\t) are not allowed. Just use 4 spaces instead.");
    throwOnInvalidChar("\r", "Carriage returns (\\r) are not allowed. Use newline (\\n) instead.");

    var tokens = [];

    var next_is_escaped;

    var c;
    var buff = "";
    var i = 0;
    var next_start = 0;

    var pushTok = function(type){
        var loc = {start: next_start, end: next_start + buff.length};
        tokens.push({
            type: type,
            src: buff,
            loc: loc
        });
        next_start = loc.end;
        buff = "";
    };
    var ctxChange = function(){
        buff = c;
    };

    while(i < src.length){
        c = src[i];

        ////////////////////////////////////////////////////////////////////////
        //spaces
        if(c === " "){
            ctxChange();
            while(i < src.length){
                c = src[i];
                if(src[i + 1] !== " "){
                    break;
                }
                buff += c;
                i += 1;
            }
            if(buff.length > 0){
                pushTok("SPACES");
            }

        ////////////////////////////////////////////////////////////////////////
        //newline
        }else if(c === "\n"){
            ctxChange();
            pushTok("NEWLINE");

        ////////////////////////////////////////////////////////////////////////
        //docstring
        }else if(c === "\"" && src[i + 1] === "\"" && src[i + 2] === "\""){
            ctxChange();
            buff += "\"\"";
            i += 3;
            next_is_escaped = false;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(next_is_escaped){
                    next_is_escaped = false;
                }else{
                    if(c === "\\"){
                        next_is_escaped = true;
                    }
                    if(c === "\"" && src[i + 1] === "\"" && src[i + 2] === "\""){
                        buff += "\"\"";
                        i += 2;
                        break;
                    }
                }
                i += 1;
            }
            if( ! /"""$/.test(buff) || /\\"""$/.test(buff)){
                throw {
                    type: "UnterminatedString",
                    message: "Use \"\"\" to close your docstring",
                    src: buff,
                    loc: {start: i - 1, end: i},
                };
            }
            pushTok("DOCSTRING");

        ////////////////////////////////////////////////////////////////////////
        //string
        }else if(c === "\""){
            ctxChange();
            i += 1;
            next_is_escaped = false;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(c === "\n"){
                    throw {
                        type: "UnexpectedCharacter",
                        message: "Use \"\"\" for multiline strings",
                        src: c,
                        loc: {start: i, end: i + 1},
                    };
                }
                if(next_is_escaped){
                    next_is_escaped = false;
                }else{
                    if(c === "\\"){
                        next_is_escaped = true;
                    }
                    if(c === "\""){
                        break;
                    }
                }
                i += 1;
            }
            if( ! /"$/.test(buff) || /\\"$/.test(buff)){
                throw {
                    type: "UnterminatedString",
                    message: "Use \" to close your string",
                    src: buff,
                    loc: {start: i - 1, end: i},
                };
            }
            pushTok("STRING");

        ////////////////////////////////////////////////////////////////////////
        //number
        }else if(/^[0-9]$/.test(c) || (c === "." && /^[0-9]$/.test(src[i + 1]))){
            ctxChange();
            buff = "";
            var has_seen_decimal = c === ".";
            while(i < src.length){
                c = src[i];
                buff += c;
                if(!/^[0-9]$/.test(src[i + 1])){
                    if(src[i+1] === "." && !has_seen_decimal){
                        has_seen_decimal = true;
                    }else{
                        break;
                    }
                }
                i += 1;
            }
            if(buff[buff.length - 1] === "."){
                buff = buff.substring(0, buff.length - 1);
                pushTok("NUMBER");
                buff = ".";
            }else{
                pushTok("NUMBER");
            }

        ////////////////////////////////////////////////////////////////////////
        //symbol
        }else if(/^[a-zA-Z_]$/.test(c)){
            ctxChange();
            buff = "";
            while(i < src.length){
                c = src[i];
                buff += c;
                if(!/^[a-zA-Z0-9_]$/.test(src[i + 1])){
                    break;
                }
                i += 1;
            }
            if(/^[A-Z]$/.test(buff[0])){
                pushTok("TYPE");
            }else{
                pushTok("SYMBOL");
            }

        ////////////////////////////////////////////////////////////////////////
        //comment
        }else if(c === ";"){
            ctxChange();
            i += 1;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(src[i + 1] === "\n"){
                    break;
                }
                i += 1;
            }
            pushTok("COMMENT");

        ////////////////////////////////////////////////////////////////////////
        //raw
        }else{
            buff += c;

            while(i < src.length){
                if(!raw_toks.hasOwnProperty(buff + src[i + 1])){
                    break;
                }
                i += 1;
                buff += src[i];
            }

            pushTok("RAW");
        }
        i += 1;
    }
    ctxChange();

    return tokens;
};
<commit_msg>cleanup<commit_after>var raw_toks = {
    ":": true,
    ",": true,
    ".": true,
    "..": true,//not actually used, this is just a hack
    "...": true,
    "?": true,
    "=": true,
    "(": true,
    ")": true,
    "[": true,
    "]": true,
    "{": true,
    "}": true,
    "==": true,
    "!=": true,
    "<": true,
    "<=": true,
    ">": true,
    ">=": true,
    "+": true,
    "-": true,
    "*": true,
    "/": true,
    "%": true,
};

module.exports = function(src, opts){
    opts = opts || {};

    var throwOnInvalidChar = function(c, message){
        var i = src.indexOf(c);
        if(i >= 0){
            throw {
                type: "InvalidCharacter",
                message: message,
                src: c,
                loc: {start: i, end: i + 1},
            };
        }
    };

    throwOnInvalidChar("\t", "Tabs (\\t) are not allowed. Just use 4 spaces instead.");
    throwOnInvalidChar("\r", "Carriage returns (\\r) are not allowed. Use newline (\\n) instead.");

    var tokens = [];

    var next_is_escaped;

    var c;
    var buff = "";
    var i = 0;
    var next_start = 0;

    var pushTok = function(type){
        var loc = {start: next_start, end: next_start + buff.length};
        tokens.push({
            type: type,
            src: buff,
            loc: loc
        });
        next_start = loc.end;
        buff = "";
    };

    while(i < src.length){
        c = src[i];

        ////////////////////////////////////////////////////////////////////////
        //spaces
        if(c === " "){
            buff = c;
            while(i < src.length){
                c = src[i];
                if(src[i + 1] !== " "){
                    break;
                }
                buff += c;
                i += 1;
            }
            if(buff.length > 0){
                pushTok("SPACES");
            }

        ////////////////////////////////////////////////////////////////////////
        //newline
        }else if(c === "\n"){
            buff = c;
            pushTok("NEWLINE");

        ////////////////////////////////////////////////////////////////////////
        //docstring
        }else if(c === "\"" && src[i + 1] === "\"" && src[i + 2] === "\""){
            buff = "\"\"\"";
            i += 3;
            next_is_escaped = false;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(next_is_escaped){
                    next_is_escaped = false;
                }else{
                    if(c === "\\"){
                        next_is_escaped = true;
                    }
                    if(c === "\"" && src[i + 1] === "\"" && src[i + 2] === "\""){
                        buff += "\"\"";
                        i += 2;
                        break;
                    }
                }
                i += 1;
            }
            if( ! /"""$/.test(buff) || /\\"""$/.test(buff)){
                throw {
                    type: "UnterminatedString",
                    message: "Use \"\"\" to close your docstring",
                    src: buff,
                    loc: {start: i - 1, end: i},
                };
            }
            pushTok("DOCSTRING");

        ////////////////////////////////////////////////////////////////////////
        //string
        }else if(c === "\""){
            buff = c;
            i += 1;
            next_is_escaped = false;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(c === "\n"){
                    throw {
                        type: "UnexpectedCharacter",
                        message: "Use \"\"\" for multiline strings",
                        src: c,
                        loc: {start: i, end: i + 1},
                    };
                }
                if(next_is_escaped){
                    next_is_escaped = false;
                }else{
                    if(c === "\\"){
                        next_is_escaped = true;
                    }
                    if(c === "\""){
                        break;
                    }
                }
                i += 1;
            }
            if( ! /"$/.test(buff) || /\\"$/.test(buff)){
                throw {
                    type: "UnterminatedString",
                    message: "Use \" to close your string",
                    src: buff,
                    loc: {start: i - 1, end: i},
                };
            }
            pushTok("STRING");

        ////////////////////////////////////////////////////////////////////////
        //number
        }else if(/^[0-9]$/.test(c) || (c === "." && /^[0-9]$/.test(src[i + 1]))){
            buff = "";
            var has_seen_decimal = c === ".";
            while(i < src.length){
                c = src[i];
                buff += c;
                if(!/^[0-9]$/.test(src[i + 1])){
                    if(src[i+1] === "." && !has_seen_decimal){
                        has_seen_decimal = true;
                    }else{
                        break;
                    }
                }
                i += 1;
            }
            if(buff[buff.length - 1] === "."){
                buff = buff.substring(0, buff.length - 1);
                pushTok("NUMBER");
                buff = ".";
            }else{
                pushTok("NUMBER");
            }

        ////////////////////////////////////////////////////////////////////////
        //symbol
        }else if(/^[a-zA-Z_]$/.test(c)){
            buff = "";
            while(i < src.length){
                c = src[i];
                buff += c;
                if(!/^[a-zA-Z0-9_]$/.test(src[i + 1])){
                    break;
                }
                i += 1;
            }
            if(/^[A-Z]$/.test(buff[0])){
                pushTok("TYPE");
            }else{
                pushTok("SYMBOL");
            }

        ////////////////////////////////////////////////////////////////////////
        //comment
        }else if(c === ";"){
            buff = c;
            i += 1;
            while(i < src.length){
                c = src[i];
                buff += c;
                if(src[i + 1] === "\n"){
                    break;
                }
                i += 1;
            }
            pushTok("COMMENT");

        ////////////////////////////////////////////////////////////////////////
        //raw
        }else{
            buff += c;

            while(i < src.length){
                if(!raw_toks.hasOwnProperty(buff + src[i + 1])){
                    break;
                }
                i += 1;
                buff += src[i];
            }

            pushTok("RAW");
        }
        i += 1;
    }

    return tokens;
};
<|endoftext|>


<commit_before>var expect = require("chai").expect;

function toNumber(word){
  if ( word === "zero" ){
    return 0;
  }
  if ( word === "one" ){
    return 1;
  }
  if ( word === "two" ){
    return 2;
  }
  if ( word === "three" ){
    return 3;
  }
  if ( word === "four" ){
    return 4;
  }
  if ( word === "five" ){
    return 5;
  }
  if ( word === "six" ){
    return 6;
  }
  if ( word === "seven" ){
    return 7;
  }
  if ( word === "eight" ){
    return 8;
  }
  if ( word === "nine" ){
    return 9;
  }
}

function add(A, B){
  if (A === "zero" && B === "zero"){
    var A = 0;
    var B = 0;
  }
  if (A === "zero" && B === "one"){
    var A = 0;
    var B = 1;
  }
  if (A === "zero" && B === "two"){
    var A = 0;
    var B = 2;
  }
  if (A === "zero" && B === "three"){
    var A = 0;
    var B = 3;
  }
  if (A === "zero" && B === "four"){
    var A = 0;
    var B = 4;
  }
  if (A === "zero" && B === "five"){
    var A = 0;
    var B = 5;
  }
  if (A === "zero" && B === "six"){
    var A = 0;
    var B = 6;
  }
  if (A === "zero" && B === "seven"){
    var A = 0;
    var B = 7;
  }
  if (A === "zero" && B === "eight"){
    var A = 0;
    var B = 8;
  }
  if (A === "zero" && B === "nine"){
    var A = 0;
    var B = 9;
  }
  if (A === "one" && B === "zero"){
    var A = 1;
    var B = 0;
  }
  if (A === "one" && B === "one"){
    var A = 1;
    var B = 1;
  }
  if (A === "one" && B === "two"){
    var A = 1;
    var B = 2;
  }
  if (A === "one" && B === "three"){
    var A = 1;
    var B = 3;
  }
  if (A === "one" && B === "four"){
    var A = 1;
    var B = 4;
  }
  if (A === "one" && B === "five"){
    var A = 1;
    var B = 5;
  }
  if (A === "one" && B === "six"){
    var A = 1;
    var B = 6;
  }
  if (A === "one" && B === "seven"){
    var A = 1;
    var B = 7;
  }
  if (A === "one" && B === "eight"){
    var A = 1;
    var B = 8;
  }
  if (A === "one" && B === "nine"){
    var A = 1;
    var B = 9;
  }
  if (A === "two" && B === "zero"){
    var A = 2;
    var B = 0;
  }
  if (A === "two" && B === "one"){
    var A = 2;
    var B = 1;
  }
  if (A === "two" && B === "two"){
    var A = 2;
    var B = 2;
  }
  if (A === "two" && B === "three"){
    var A = 2;
    var B = 3;
  }
  if (A === "two" && B === "four"){
    var A = 2;
    var B = 4;
  }
  if (A === "two" && B === "five"){
    var A = 2;
    var B = 5;
  }
  if (A === "two" && B === "six"){
    var A = 2;
    var B = 6;
  }
  if (A === "two" && B === "seven"){
    var A = 2;
    var B = 7;
  }
  if (A === "two" && B === "eight"){
    var A = 2;
    var B = 8;
  }
  if (A === "two" && B === "nine"){
    var A = 2;
    var B = 9;
  }
  if (A === "three" && B === "zero"){
    var A = 3;
    var B = 0;
  }
  if (A === "three" && B === "one"){
    var A = 3;
    var B = 1;
  }
  if (A === "three" && B === "two"){
    var A = 3;
    var B = 2;
  }
  if (A === "three" && B === "three"){
    var A = 3;
    var B = 3;
  }
  if (A === "three" && B === "four"){
    var A = 3;
    var B = 4;
  }
  if (A === "three" && B === "five"){
    var A = 3;
    var B = 5;
  }
  if (A === "three" && B === "six"){
    var A = 3;
    var B = 6;
  }
  if (A === "three" && B === "seven"){
    var A = 3;
    var B = 7;
  }
  if (A === "three" && B === "eight"){
    var A = 3;
    var B = 8;
  }
  if (A === "three" && B === "nine"){
    var A = 3;
    var B = 9;
  }
  if (A === "four" && B === "zero"){
    var A = 4;
    var B = 0;
  }
  if (A === "four" && B === "one"){
    var A = 4;
    var B = 1;
  }
  if (A === "four" && B === "two"){
    var A = 4;
    var B = 2;
  }
  if (A === "four" && B === "three"){
    var A = 4;
    var B = 3;
  }
  if (A === "four" && B === "four"){
    var A = 4;
    var B = 4;
  }
  if (A === "four" && B === "five"){
    var A = 4;
    var B = 5;
  }
  if (A === "four" && B === "six"){
    var A = 4;
    var B = 6;
  }
  if (A === "four" && B === "seven"){
    var A = 4;
    var B = 7;
  }
  if (A === "four" && B === "eight"){
    var A = 4;
    var B = 8;
  }
  if (A === "four" && B === "nine"){
    var A = 4;
    var B = 9;
  }
  if (A === "five" && B === "zero"){
    var A = 5;
    var B = 0;
  }
  if (A === "five" && B === "one"){
    var A = 5;
    var B = 1;
  }
  if (A === "five" && B === "two"){
    var A = 5;
    var B = 2;
  }
  if (A === "five" && B === "three"){
    var A = 5;
    var B = 3;
  }
  if (A === "five" && B === "four"){
    var A = 5;
    var B = 4;
  }
  if (A === "five" && B === "five"){
    var A = 5;
    var B = 5;
  }
  if (A === "five" && B === "six"){
    var A = 5;
    var B = 6;
  }
  if (A === "five" && B === "seven"){
    var A = 5;
    var B = 7;
  }
  if (A === "five" && B ==="eight"){
    var A = 5
    var B = 8
  }
  if (A === "five" && B === "nine"){
    var A = 5
    var B = 9
  }
  return A + B
}

expect(toNumber("zero")).to.equal(0);
expect(toNumber("one")).to.equal(1);
expect(toNumber("two")).to.equal(2);
expect(toNumber("three")).to.equal(3);
expect(toNumber("four")).to.equal(4);
expect(toNumber("five")).to.equal(5);
expect(toNumber("six")).to.equal(6);
expect(toNumber("seven")).to.equal(7);
expect(toNumber("eight")).to.equal(8);
expect(toNumber("nine")).to.equal(9);

expect(add).to.exist;
expect(add("zero", "zero")).to.equal(0);
expect(add("zero", "one")).to.equal(1);
expect(add("zero", "two")).to.equal(2);
expect(add("zero", "three")).to.equal(3);
expect(add("zero", "four")).to.equal(4);
expect(add("zero", "five")).to.equal(5);
expect(add("zero", "six")).to.equal(6);
expect(add("zero", "seven")).to.equal(7);
expect(add("zero", "eight")).to.equal(8);
expect(add("zero", "nine")).to.equal(9);
expect(add("one", "zero")).to.equal(1);
expect(add("one", "one")).to.equal(2);
expect(add("one", "two")).to.equal(3);
expect(add("one", "three")).to.equal(4);
expect(add("one", "four")).to.equal(5);
expect(add("one", "five")).to.equal(6);
expect(add("one", "six")).to.equal(7);
expect(add("one", "seven")).to.equal(8);
expect(add("one", "eight")).to.equal(9);
expect(add("one", "nine")).to.equal(10);
expect(add("two", "zero")).to.equal(2);
expect(add("two", "one")).to.equal(3);
expect(add("two", "two")).to.equal(4);
expect(add("two", "three")).to.equal(5);
expect(add("two", "four")).to.equal(6);
expect(add("two", "five")).to.equal(7);
expect(add("two", "six")).to.equal(8);
expect(add("two", "seven")).to.equal(9);
expect(add("two", "eight")).to.equal(10);
expect(add("two", "nine")).to.equal(11);
expect(add("three", "zero")).to.equal(3);
expect(add("three", "one")).to.equal(4);
expect(add("three", "two")).to.equal(5);
expect(add("three", "three")).to.equal(6);
expect(add("three", "four")).to.equal(7);
expect(add("three", "five")).to.equal(8);
expect(add("three", "six")).to.equal(9);
expect(add("three", "seven")).to.equal(10);
expect(add("three", "eight")).to.equal(11);
expect(add("three", "nine")).to.equal(12);
expect(add("four", "zero")).to.equal(4);
expect(add("four", "one")).to.equal(5);
expect(add("four", "two")).to.equal(6);
expect(add("four", "three")).to.equal(7);
expect(add("four", "four")).to.equal(8);
expect(add("four", "five")).to.equal(9);
expect(add("four", "six")).to.equal(10);
expect(add("four", "seven")).to.equal(11);
expect(add("four", "eight")).to.equal(12);
expect(add("four", "nine")).to.equal(13);
expect(add("five", "zero")).to.equal(5);
expect(add("five", "one")).to.equal(6);
expect(add("five", "two")).to.equal(7);
expect(add("five", "three")).to.equal(8);
expect(add("five", "four")).to.equal(9);
expect(add("five", "five")).to.equal(10);
expect(add("five", "six")).to.equal(11);
expect(add("five", "seven")).to.equal(12);
expect(add("five", "eight")).to.equal(13);
expect(add("five", "nine")).to.equal(14);

console.log(add("five", "seven"))

console.log(1/9)

// NIGHTMARE MODE

/* function plus(A, B){
  return (toNumber(A) + toNumber(B));
}

function minus(A, B){
  return (toNumber(A) - toNumber(B));
}

function multiply(A, B){
  return (toNumber(A) * toNumber(B));
}

function divide(A, B){
  return (toNumber(A) / toNumber(B));
}

expect(plus).to.exist;
expect(plus("zero", "zero")).to.equal(0);
expect(plus("zero", "one")).to.equal(1);
expect(plus("zero", "two")).to.equal(2);

expect(minus).to.exist;
expect(minus("four", "two")).to.equal(2);

expect(multiply).to.exist;
expect(multiply("five", "three")).to.equal(15);

console.log(multiply("three", "four"))

expect(divide).to.exist;
expect(divide("five", "one").to.equal(5) */
<commit_msg>editing<commit_after>var expect = require("chai").expect;

function toNumber(word){
  if ( word === "zero" ){
    return 0;
  }
  if ( word === "one" ){
    return 1;
  }
  if ( word === "two" ){
    return 2;
  }
  if ( word === "three" ){
    return 3;
  }
  if ( word === "four" ){
    return 4;
  }
  if ( word === "five" ){
    return 5;
  }
  if ( word === "six" ){
    return 6;
  }
  if ( word === "seven" ){
    return 7;
  }
  if ( word === "eight" ){
    return 8;
  }
  if ( word === "nine" ){
    return 9;
  }
}

function add(A, B){
  if (A === "zero" && B === "zero"){
    var A = 0;
    var B = 0;
  }
  if (A === "zero" && B === "one"){
    var A = 0;
    var B = 1;
  }
  if (A === "zero" && B === "two"){
    var A = 0;
    var B = 2;
  }
  if (A === "zero" && B === "three"){
    var A = 0;
    var B = 3;
  }
  if (A === "zero" && B === "four"){
    var A = 0;
    var B = 4;
  }
  if (A === "zero" && B === "five"){
    var A = 0;
    var B = 5;
  }
  if (A === "zero" && B === "six"){
    var A = 0;
    var B = 6;
  }
  if (A === "zero" && B === "seven"){
    var A = 0;
    var B = 7;
  }
  if (A === "zero" && B === "eight"){
    var A = 0;
    var B = 8;
  }
  if (A === "zero" && B === "nine"){
    var A = 0;
    var B = 9;
  }
  if (A === "one" && B === "zero"){
    var A = 1;
    var B = 0;
  }
  if (A === "one" && B === "one"){
    var A = 1;
    var B = 1;
  }
  if (A === "one" && B === "two"){
    var A = 1;
    var B = 2;
  }
  if (A === "one" && B === "three"){
    var A = 1;
    var B = 3;
  }
  if (A === "one" && B === "four"){
    var A = 1;
    var B = 4;
  }
  if (A === "one" && B === "five"){
    var A = 1;
    var B = 5;
  }
  if (A === "one" && B === "six"){
    var A = 1;
    var B = 6;
  }
  if (A === "one" && B === "seven"){
    var A = 1;
    var B = 7;
  }
  if (A === "one" && B === "eight"){
    var A = 1;
    var B = 8;
  }
  if (A === "one" && B === "nine"){
    var A = 1;
    var B = 9;
  }
  if (A === "two" && B === "zero"){
    var A = 2;
    var B = 0;
  }
  if (A === "two" && B === "one"){
    var A = 2;
    var B = 1;
  }
  if (A === "two" && B === "two"){
    var A = 2;
    var B = 2;
  }
  if (A === "two" && B === "three"){
    var A = 2;
    var B = 3;
  }
  if (A === "two" && B === "four"){
    var A = 2;
    var B = 4;
  }
  if (A === "two" && B === "five"){
    var A = 2;
    var B = 5;
  }
  if (A === "two" && B === "six"){
    var A = 2;
    var B = 6;
  }
  if (A === "two" && B === "seven"){
    var A = 2;
    var B = 7;
  }
  if (A === "two" && B === "eight"){
    var A = 2;
    var B = 8;
  }
  if (A === "two" && B === "nine"){
    var A = 2;
    var B = 9;
  }
  if (A === "three" && B === "zero"){
    var A = 3;
    var B = 0;
  }
  if (A === "three" && B === "one"){
    var A = 3;
    var B = 1;
  }
  if (A === "three" && B === "two"){
    var A = 3;
    var B = 2;
  }
  if (A === "three" && B === "three"){
    var A = 3;
    var B = 3;
  }
  if (A === "three" && B === "four"){
    var A = 3;
    var B = 4;
  }
  if (A === "three" && B === "five"){
    var A = 3;
    var B = 5;
  }
  if (A === "three" && B === "six"){
    var A = 3;
    var B = 6;
  }
  if (A === "three" && B === "seven"){
    var A = 3;
    var B = 7;
  }
  if (A === "three" && B === "eight"){
    var A = 3;
    var B = 8;
  }
  if (A === "three" && B === "nine"){
    var A = 3;
    var B = 9;
  }
  if (A === "four" && B === "zero"){
    var A = 4;
    var B = 0;
  }
  if (A === "four" && B === "one"){
    var A = 4;
    var B = 1;
  }
  if (A === "four" && B === "two"){
    var A = 4;
    var B = 2;
  }
  if (A === "four" && B === "three"){
    var A = 4;
    var B = 3;
  }
  if (A === "four" && B === "four"){
    var A = 4;
    var B = 4;
  }
  if (A === "four" && B === "five"){
    var A = 4;
    var B = 5;
  }
  if (A === "four" && B === "six"){
    var A = 4;
    var B = 6;
  }
  if (A === "four" && B === "seven"){
    var A = 4;
    var B = 7;
  }
  if (A === "four" && B === "eight"){
    var A = 4;
    var B = 8;
  }
  if (A === "four" && B === "nine"){
    var A = 4;
    var B = 9;
  }
  if (A === "five" && B === "zero"){
    var A = 5;
    var B = 0;
  }
  if (A === "five" && B === "one"){
    var A = 5;
    var B = 1;
  }
  if (A === "five" && B === "two"){
    var A = 5;
    var B = 2;
  }
  if (A === "five" && B === "three"){
    var A = 5;
    var B = 3;
  }
  if (A === "five" && B === "four"){
    var A = 5;
    var B = 4;
  }
  if (A === "five" && B === "five"){
    var A = 5;
    var B = 5;
  }
  if (A === "five" && B === "six"){
    var A = 5;
    var B = 6;
  }
  if (A === "five" && B === "seven"){
    var A = 5;
    var B = 7;
  }
  if (A === "five" && B ==="eight"){
    var A = 5
    var B = 8
  }
  if (A === "five" && B === "nine"){
    var A = 5
    var B = 9
  }

  return A + B
}

expect(toNumber("zero")).to.equal(0);
expect(toNumber("one")).to.equal(1);
expect(toNumber("two")).to.equal(2);
expect(toNumber("three")).to.equal(3);
expect(toNumber("four")).to.equal(4);
expect(toNumber("five")).to.equal(5);
expect(toNumber("six")).to.equal(6);
expect(toNumber("seven")).to.equal(7);
expect(toNumber("eight")).to.equal(8);
expect(toNumber("nine")).to.equal(9);

expect(add).to.exist;
expect(add("zero", "zero")).to.equal(0);
expect(add("zero", "one")).to.equal(1);
expect(add("zero", "two")).to.equal(2);
expect(add("zero", "three")).to.equal(3);
expect(add("zero", "four")).to.equal(4);
expect(add("zero", "five")).to.equal(5);
expect(add("zero", "six")).to.equal(6);
expect(add("zero", "seven")).to.equal(7);
expect(add("zero", "eight")).to.equal(8);
expect(add("zero", "nine")).to.equal(9);
expect(add("one", "zero")).to.equal(1);
expect(add("one", "one")).to.equal(2);
expect(add("one", "two")).to.equal(3);
expect(add("one", "three")).to.equal(4);
expect(add("one", "four")).to.equal(5);
expect(add("one", "five")).to.equal(6);
expect(add("one", "six")).to.equal(7);
expect(add("one", "seven")).to.equal(8);
expect(add("one", "eight")).to.equal(9);
expect(add("one", "nine")).to.equal(10);
expect(add("two", "zero")).to.equal(2);
expect(add("two", "one")).to.equal(3);
expect(add("two", "two")).to.equal(4);
expect(add("two", "three")).to.equal(5);
expect(add("two", "four")).to.equal(6);
expect(add("two", "five")).to.equal(7);
expect(add("two", "six")).to.equal(8);
expect(add("two", "seven")).to.equal(9);
expect(add("two", "eight")).to.equal(10);
expect(add("two", "nine")).to.equal(11);
expect(add("three", "zero")).to.equal(3);
expect(add("three", "one")).to.equal(4);
expect(add("three", "two")).to.equal(5);
expect(add("three", "three")).to.equal(6);
expect(add("three", "four")).to.equal(7);
expect(add("three", "five")).to.equal(8);
expect(add("three", "six")).to.equal(9);
expect(add("three", "seven")).to.equal(10);
expect(add("three", "eight")).to.equal(11);
expect(add("three", "nine")).to.equal(12);
expect(add("four", "zero")).to.equal(4);
expect(add("four", "one")).to.equal(5);
expect(add("four", "two")).to.equal(6);
expect(add("four", "three")).to.equal(7);
expect(add("four", "four")).to.equal(8);
expect(add("four", "five")).to.equal(9);
expect(add("four", "six")).to.equal(10);
expect(add("four", "seven")).to.equal(11);
expect(add("four", "eight")).to.equal(12);
expect(add("four", "nine")).to.equal(13);
expect(add("five", "zero")).to.equal(5);
expect(add("five", "one")).to.equal(6);
expect(add("five", "two")).to.equal(7);
expect(add("five", "three")).to.equal(8);
expect(add("five", "four")).to.equal(9);
expect(add("five", "five")).to.equal(10);
expect(add("five", "six")).to.equal(11);
expect(add("five", "seven")).to.equal(12);
expect(add("five", "eight")).to.equal(13);
expect(add("five", "nine")).to.equal(14);
expect(add("six", "zero")).to.equal(6);
expect(add("six", "one")).to.equal(7);
expect(add("six", "two")).to.equal(8);

console.log(add("five", "seven"))

console.log(1/9)

// NIGHTMARE MODE

/* function plus(A, B){
  return (toNumber(A) + toNumber(B));
}

function minus(A, B){
  return (toNumber(A) - toNumber(B));
}

function multiply(A, B){
  return (toNumber(A) * toNumber(B));
}

function divide(A, B){
  return (toNumber(A) / toNumber(B));
}

expect(plus).to.exist;
expect(plus("zero", "zero")).to.equal(0);
expect(plus("zero", "one")).to.equal(1);
expect(plus("zero", "two")).to.equal(2);

expect(minus).to.exist;
expect(minus("four", "two")).to.equal(2);

expect(multiply).to.exist;
expect(multiply("five", "three")).to.equal(15);

console.log(multiply("three", "four"))

expect(divide).to.exist;
expect(divide("five", "one").to.equal(5) */
<|endoftext|>