<commit_before>/**
 * @class Garp.FilterMenu
 * @plugin Ext.PagingToolbar
 * @author Peter
 *
 * Creates a menu button for the paging toolbar, with basic filter options
 *
 */
Garp.FilterMenu = function(){

	this.init = function(tb){

		/**
		 * Reference to the toolbar
		 */
		this.tb = tb;

		this.defaultFilter = {
			text: __('All'),
			ref: 'all'
		};

		/**
		 * Resets the button and the menu. (Provides only visual feedback: no filter applied)
		 */
		this.resetUI = function(){
			this.tb.filterBtn.setIconClass('icon-filter-off');
			this.tb.filterBtn.menu.all.setChecked(true);
			this.tb.filterStatus.hide();
			this.tb.filterStatus.update('');

		};

		/**
		 * Checks the model for possible fields to filter on. If it's not in the model, we can't put it as a filter option in the menu
		 */
		this.buildMenu = function(){

			var menuOptions = [];
			if(Garp.dataTypes[Garp.currentModel].filterMenu){
				Ext.each(Garp.dataTypes[Garp.currentModel].filterMenu, function(i){
					menuOptions.push(i);
				});
			}
			var model = Garp.dataTypes[Garp.currentModel];
			menuOptions.push(this.defaultFilter);
			if(model.getColumn('published')){
				menuOptions.push({
					text: __('Drafts'),
					ref: 'drafts'
				},{
					text: __('Published'),
					ref: 'published'
				});
			}
			if (model.getColumn('author_id')) {
				menuOptions.push({
					text: __('My items'),
					ref: 'my'
				});
			}

			Ext.each(menuOptions, function(option){
				if(typeof option.isDefault !== 'undefined' && option.isDefault){
					this.defaultFilter = option;
					return false;
				}
			}, this);

			return menuOptions;
		};

		/**
		 * Applies the selected filter and reflects the UI
		 * @param {Object} menu item
		 */
		function applyFilter(item){

			var grid = tb.ownerCt;
			var storeParams = grid.getStore().baseParams;

			if (!storeParams.query) {
				storeParams.query = {};
			}

			delete storeParams.query.online_status;
			delete storeParams.query.author_id;

			if(typeof Garp.dataTypes[Garp.currentModel].clearFilters == 'function'){
				Garp.dataTypes[Garp.currentModel].clearFilters();
			} else if (item.ref == 'all'){
				storeParams.query = {};
			}

			switch (item.ref) {
				case 'published':
					Ext.apply(storeParams.query, {
						online_status: '1'
					});
					break;
				case 'drafts':
					Ext.apply(storeParams.query, {
						online_status: '0'
					});
					break;
				case 'my':
					Ext.apply(storeParams.query, {
						author_id: Garp.localUser.id
					});
					break;
				default:
					break;
			}
			grid.getStore().reload();
			return true;
		}

		/**
		 * Build the menu
		 */
		this.filterMenu = this.buildMenu();

		this.filterStatus = tb.add({
			ref: 'filterStatus',
			text: this.defaultFilter.ref !== 'all' ? this.defaultFilter.text : '',
			xtype: 'tbtext',
			hidden: (this.defaultFilter.ref === 'all')
		});

		/**
		 * Create the button
		 */
		this.filterBtn = tb.add({
			ref: 'filterBtn',
			tooltip: 'Filter',
			iconCls: (this.defaultFilter.ref == 'all' ? 'icon-filter-off' : 'icon-filter-on'),
			hidden: (this.filterMenu.length <= 1),
			menu: {
				defaultType: 'menucheckitem',
				defaults: {
					group: 'filter',
					handler: applyFilter,
					scope: this
				},
				items: this.filterMenu
			}
		});

		// Set default as checked:
		this.filterBtn.menu.find('text', this.defaultFilter.text)[0].setChecked(true);

		// Reflect UI on menu changes:
		this.filterBtn.menu.on('itemclick', function(item, evt){
			if(item.ref === 'all'){
				this.filterStatus.update('');
				this.filterStatus.hide();
				this.filterBtn.setIconClass('icon-filter-off');
				return;
			} else if (item.text) {
				this.filterStatus.update(item.text);
			}
			this.filterStatus.show();
			this.filterBtn.setIconClass('icon-filter-on');
		}, this);

		// Make sure we don't end up with an "No items to display" AND a filter Status text:
		this.tb.on('change', function(tb){
			if(tb.store.getCount() === 0){
				this.filterStatus.hide();
			} else {
				this.filterStatus.show();
			}
		});
	};
};<commit_msg>Fixed merge conflict<commit_after>/**
 * @class Garp.FilterMenu
 * @plugin Ext.PagingToolbar
 * @author Peter
 *
 * Creates a menu button for the paging toolbar, with basic filter options
 *
 */
Garp.FilterMenu = function(){

	this.init = function(tb){

		/**
		 * Reference to the toolbar
		 */
		this.tb = tb;

		this.defaultFilter = {
			text: __('All'),
			ref: 'all'
		};

		/**
		 * Resets the button and the menu. (Provides only visual feedback: no filter applied)
		 */
		this.resetUI = function(){
			this.tb.filterBtn.setIconClass('icon-filter-off');
			this.tb.filterBtn.menu.all.setChecked(true);
			this.tb.filterStatus.hide();
			this.tb.filterStatus.update('');
		};

		/**
		 * Checks the model for possible fields to filter on. If it's not in the model, we can't put it as a filter option in the menu
		 */
		this.buildMenu = function(){

			var menuOptions = [];
			if(Garp.dataTypes[Garp.currentModel].filterMenu){
				Ext.each(Garp.dataTypes[Garp.currentModel].filterMenu, function(i){
					menuOptions.push(i);
				});
			}
			var model = Garp.dataTypes[Garp.currentModel];
			menuOptions.push(this.defaultFilter);
			if(model.getColumn('published')){
				menuOptions.push({
					text: __('Drafts'),
					ref: 'drafts'
				},{
					text: __('Published'),
					ref: 'published'
				});
			}
			if (model.getColumn('author_id')) {
				menuOptions.push({
					text: __('My items'),
					ref: 'my'
				});
			}

			Ext.each(menuOptions, function(option){
				if(typeof option.isDefault !== 'undefined' && option.isDefault){
					this.defaultFilter = option;
					return false;
				}
			}, this);

			return menuOptions;
		};

		/**
		 * Applies the selected filter and reflects the UI
		 * @param {Object} menu item
		 */
		function applyFilter(item){

			var grid = tb.ownerCt;
			var storeParams = grid.getStore().baseParams;

			if (!storeParams.query) {
				storeParams.query = {};
			}

			delete storeParams.query.online_status;
			delete storeParams.query.author_id;

			if(typeof Garp.dataTypes[Garp.currentModel].clearFilters == 'function'){
				Garp.dataTypes[Garp.currentModel].clearFilters();
			} else if (item.ref == 'all'){
				storeParams.query = {};
			}

			switch (item.ref) {
				case 'published':
					Ext.apply(storeParams.query, {
						online_status: '1'
					});
					break;
				case 'drafts':
					Ext.apply(storeParams.query, {
						online_status: '0'
					});
					break;
				case 'my':
					Ext.apply(storeParams.query, {
						author_id: Garp.localUser.id
					});
					break;
				default:
					break;
			}
			grid.getStore().reload();
			return true;
		}

		/**
		 * Build the menu
		 */
		this.filterMenu = this.buildMenu();

		this.filterStatus = tb.add({
			ref: 'filterStatus',
			text: this.defaultFilter.ref !== 'all' ? this.defaultFilter.text : '',
			xtype: 'tbtext',
			hidden: (this.defaultFilter.ref === 'all')
		});

		/**
		 * Create the button
		 */
		this.filterBtn = tb.add({
			ref: 'filterBtn',
			tooltip: 'Filter',
			iconCls: (this.defaultFilter.ref == 'all' ? 'icon-filter-off' : 'icon-filter-on'),
			hidden: (this.filterMenu.length <= 1),
			menu: {
				defaultType: 'menucheckitem',
				defaults: {
					group: 'filter',
					handler: applyFilter,
					scope: this
				},
				items: this.filterMenu
			}
		});

		// Set default as checked:
		this.filterBtn.menu.find('text', this.defaultFilter.text)[0].setChecked(true);

		// Reflect UI on menu changes:
		this.filterBtn.menu.on('itemclick', function(item, evt){
			if(item.ref === 'all'){
				this.filterStatus.update('');
				this.filterStatus.hide();
				this.filterBtn.setIconClass('icon-filter-off');
				return;
			} else if (item.text) {
				this.filterStatus.update(item.text);
			}
			this.filterStatus.show();
			this.filterBtn.setIconClass('icon-filter-on');
		}, this);

		// Make sure we don't end up with an "No items to display" AND a filter Status text:
		this.tb.on('change', function(tb){
			if(tb.store.getCount() === 0){
				this.filterStatus.hide();
			} else {
				this.filterStatus.show();
			}
		});
	};
};
<|endoftext|>


<commit_before>var _ = require('underscore');
var async = require('async');
var config = require('./config');
var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');

var pruneManifest = function (manifest) {
  return _.reduce(manifest, function (manifest, val, key) {
    if (key === '__VERSION__' || key === '__IN__') {
      manifest[key] = val;
    } else if (val.targetPaths && val.hash) {
      manifest[key] = _.omit(val, 'buffer');
    }
    return manifest;
  }, {});
};

module.exports = function (cb) {
  var manifestPath = config.get().manifestPath;
  if (!manifestPath) return cb();
  async.series([
    _.partial(mkdirp, path.dirname(manifestPath)),
    _.partial(
      fs.writeFile,
      manifestPath,
      JSON.stringify(pruneManifest(config.get().manifest))
    )
  ], cb);
};
<commit_msg>Add __TRANSFORMERS__ to special keys<commit_after>var _ = require('underscore');
var async = require('async');
var config = require('./config');
var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');

var META_KEYS = ['__VERSION__', '__IN__', '__TRANSFORMERS__'];

var pruneManifest = function (manifest) {
  return _.reduce(manifest, function (manifest, val, key) {
    if (_.include(META_KEYS, key)) {
      manifest[key] = val;
    } else if (val.targetPaths && val.hash) {
      manifest[key] = _.omit(val, 'buffer');
    }
    return manifest;
  }, {});
};

module.exports = function (cb) {
  var manifestPath = config.get().manifestPath;
  if (!manifestPath) return cb();
  async.series([
    _.partial(mkdirp, path.dirname(manifestPath)),
    _.partial(
      fs.writeFile,
      manifestPath,
      JSON.stringify(pruneManifest(config.get().manifest))
    )
  ], cb);
};
<|endoftext|>


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

    angular
        .module('lumx.dropdown')
        .directive('lxDropdown', lxDropdown)
        .directive('lxDropdownToggle', lxDropdownToggle)
        .directive('lxDropdownMenu', lxDropdownMenu)
        .directive('lxDropdownFilter', lxDropdownFilter);

    lxDropdown.$inject = ['$document'];

    function lxDropdown($document)
    {
        return {
            restrict: 'E',
            templateUrl: 'dropdown.html',
            scope:
            {
                escapeClose: '=?lxEscapeClose',
                overToggle: '=?lxOverToggle',
                position: '@?lxPosition',
                width: '@?lxWidth'
            },
            link: link,
            controller: LxDropdownController,
            controllerAs: 'lxDropdown',
            bindToController: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrl)
        {
            var backwardOneWay = ['position', 'width'];
            var backwardTwoWay = ['escapeClose', 'overToggle'];

            angular.forEach(backwardOneWay, function(attribute)
            {
                if (angular.isDefined(attrs[attribute]))
                {
                    attrs.$observe(attribute, function(newValue)
                    {
                        scope.lxDropdown[attribute] = newValue;
                    });
                }
            });

            angular.forEach(backwardTwoWay, function(attribute)
            {
                if (angular.isDefined(attrs[attribute]))
                {
                    scope.$watch(function()
                    {
                        return scope.$parent.$eval(attrs[attribute]);
                    }, function(newValue)
                    {
                        scope.lxDropdown[attribute] = newValue;
                    });
                }
            });

            $document.bind('click', closeDropdownMenu);

            scope.$on('$destroy', function()
            {
                ctrl.closeDropdownMenu();
                $document.unbind('click', closeDropdownMenu);
            });

            function closeDropdownMenu()
            {
                scope.$apply(function()
                {
                    ctrl.closeDropdownMenu();
                });
            }
        }
    }

    LxDropdownController.$inject = ['$element', '$interval', '$scope', '$timeout', '$window', 'LxDepthService', 'LxEventSchedulerService'];

    function LxDropdownController($element, $interval, $scope, $timeout, $window, LxDepthService, LxEventSchedulerService)
    {
        var lxDropdown = this;
        var dropdownInterval;
        var dropdownMenu;
        var dropdownToggle;
        var idEventScheduler;

        lxDropdown.closeDropdownMenu = closeDropdownMenu;
        lxDropdown.registerDropdownMenu = registerDropdownMenu;
        lxDropdown.registerDropdownToggle = registerDropdownToggle;
        lxDropdown.toggle = toggle;

        lxDropdown.escapeClose = angular.isDefined(lxDropdown.escapeClose) ? lxDropdown.escapeClose : true;
        lxDropdown.isOpen = false;
        lxDropdown.overToggle = angular.isDefined(lxDropdown.overToggle) ? lxDropdown.overToggle : false;
        lxDropdown.position = angular.isDefined(lxDropdown.position) ? lxDropdown.position : 'left';

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

        function closeDropdownMenu()
        {
            $interval.cancel(dropdownInterval);

            dropdownMenu.css(
            {
                overflow: 'hidden'
            });

            dropdownMenu.velocity(
            {
                width: 0,
                height: 0,
            },
            {
                duration: 200,
                easing: 'easeOutQuint',
                complete: function()
                {
                    $element.find('.dropdown').removeClass('dropdown--is-open');

                    dropdownMenu
                        .removeAttr('style')
                        .removeClass('dropdown-menu--is-open')
                        .appendTo($element.find('.dropdown'));

                    $scope.$apply(function()
                    {
                        lxDropdown.isOpen = false;

                        if (lxDropdown.escapeClose)
                        {
                            LxEventSchedulerService.unregister(idEventScheduler);
                            idEventScheduler = undefined;
                        }
                    });
                }
            });
        }

        function openDropdownMenu()
        {
            LxDepthService.register();

            lxDropdown.isOpen = true;

            $element.find('.dropdown').addClass('dropdown--is-open');

            dropdownMenu
                .addClass('dropdown-menu--is-open')
                .css('z-index', LxDepthService.getDepth())
                .appendTo('body');

            if (lxDropdown.escapeClose)
            {
                idEventScheduler = LxEventSchedulerService.register('keyup', onKeyUp);
            }

            $timeout(function()
            {
                var enoughtHeight = true;
                var availableHeight = setDropdownMenuCss();
                var width = dropdownMenu.outerWidth();
                var height = dropdownMenu.outerHeight();

                if (availableHeight < height)
                {
                    enoughtHeight = false;
                    height = availableHeight;
                }

                dropdownMenu.css(
                {
                    width: 0,
                    height: 0,
                    opacity: 1,
                    overflow: 'hidden'
                });

                dropdownMenu.find('.dropdown-menu__content').css(
                {
                    width: width,
                    height: height
                });

                dropdownMenu.velocity(
                {
                    width: width
                },
                {
                    duration: 200,
                    easing: 'easeOutQuint',
                    queue: false
                });

                dropdownMenu.velocity(
                {
                    height: height
                },
                {
                    duration: 500,
                    easing: 'easeOutQuint',
                    queue: false,
                    complete: function()
                    {
                        dropdownMenu.css(
                        {
                            overflow: 'auto'
                        });

                        if (enoughtHeight)
                        {
                            dropdownMenu.css(
                            {
                                height: 'auto'
                            });
                        }

                        if (angular.isUndefined(lxDropdown.width))
                        {
                            dropdownMenu.css(
                            {
                                width: 'auto'
                            });
                        }

                        dropdownMenu.find('.dropdown-menu__content').removeAttr('style');

                        dropdownInterval = $interval(function()
                        {
                            setDropdownMenuCss();
                        }, 500);
                    }
                });
            });
        }

        function onKeyUp(_event)
        {
            if (_event.keyCode == 27)
            {
                closeDropdownMenu();
            }

            _event.stopPropagation();
        }

        function registerDropdownMenu(_dropdownMenu)
        {
            dropdownMenu = _dropdownMenu;
        }

        function registerDropdownToggle(_dropdownToggle)
        {
            dropdownToggle = _dropdownToggle;
        }

        function setDropdownMenuCss()
        {
            var windowWidth = $window.innerWidth;
            var windowHeight = $window.innerHeight;
            var dropdownToggleWidth = dropdownToggle.outerWidth();
            var dropdownToggleHeight = dropdownToggle.outerHeight();
            var dropdownToggleTop = dropdownToggle.offset().top - angular.element($window).scrollTop();
            var dropdownMenuTopAvailable;
            var dropdownMenuBottomAvailable;
            var dropdownMenuWidth;

            if (lxDropdown.overToggle)
            {
                dropdownMenuTopAvailable = dropdownToggleTop + dropdownToggleHeight;
                dropdownMenuBottomAvailable = windowHeight - dropdownToggleTop;
            }
            else
            {
                dropdownMenuTopAvailable = dropdownToggleTop;
                dropdownMenuBottomAvailable = windowHeight - (dropdownToggleTop + dropdownToggleHeight);
            }

            if (angular.isDefined(lxDropdown.width))
            {
                if (lxDropdown.width.indexOf('%') > -1)
                {
                    dropdownMenuWidth = dropdownToggleWidth * (lxDropdown.width.slice(0, -1) / 100);
                }
                else
                {
                    dropdownMenuWidth = lxDropdown.width;
                }
            }
            else
            {
                dropdownMenuWidth = 'auto';
            }

            dropdownMenu.css(
            {
                right: lxDropdown.position === 'right' ? (windowWidth - dropdownToggle.offset().left - dropdownToggleWidth) : 'auto',
                left: lxDropdown.position === 'right' ? 'auto' : dropdownToggle.offset().left,
                width: dropdownMenuWidth
            });

            if (dropdownMenuTopAvailable > dropdownMenuBottomAvailable)
            {
                dropdownMenu.css(
                {
                    bottom: lxDropdown.overToggle ? (windowHeight - dropdownToggle.offset().top - dropdownToggleHeight) : (windowHeight - dropdownToggle.offset().top)
                });

                return dropdownMenuTopAvailable;
            }
            else
            {
                dropdownMenu.css(
                {
                    top: lxDropdown.overToggle ? dropdownToggle.offset().top : (dropdownToggle.offset().top + dropdownToggleHeight)
                });

                return dropdownMenuBottomAvailable;
            }
        }

        function toggle()
        {
            if (!lxDropdown.isOpen)
            {
                openDropdownMenu();
            }
            else
            {
                closeDropdownMenu();
            }
        }
    }

    function lxDropdownToggle()
    {
        return {
            restrict: 'AE',
            templateUrl: 'dropdown-toggle.html',
            require: '^lxDropdown',
            scope: true,
            link: link,
            replace: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrl)
        {
            ctrl.registerDropdownToggle(element);

            element.bind('click', function(_event)
            {
                _event.stopPropagation();

                angular.element('.dropdown').each(function(index, dropdownElem)
                {
                    if (angular.isDefined(angular.element(dropdownElem).scope().lxDropdown) && angular.element(dropdownElem).scope().lxDropdown.isOpen)
                    {
                        angular.element(dropdownElem).scope().lxDropdown.closeDropdownMenu();
                    }
                });

                scope.$apply(function()
                {
                    ctrl.toggle();
                });
            });
        }
    }

    function lxDropdownMenu()
    {
        return {
            restrict: 'E',
            templateUrl: 'dropdown-menu.html',
            require: ['lxDropdownMenu', '^lxDropdown'],
            scope: true,
            link: link,
            controller: LxDropdownMenuController,
            controllerAs: 'lxDropdownMenu',
            bindToController: true,
            replace: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrls)
        {
            ctrls[1].registerDropdownMenu(element);
            ctrls[0].setParentController(ctrls[1]);
        }
    }

    function LxDropdownMenuController()
    {
        var lxDropdownMenu = this;

        lxDropdownMenu.setParentController = setParentController;

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

        function setParentController(_parentCtrl)
        {
            lxDropdownMenu.parentCtrl = _parentCtrl;
        }
    }

    lxDropdownFilter.$inject = ['$timeout'];

    function lxDropdownFilter($timeout)
    {
        return {
            restrict: 'A',
            link: link
        };

        function link(scope, element)
        {
            element.bind('click', function(_event)
            {
                _event.stopPropagation();
            });

            $timeout(function()
            {
                element.find('input').focus();
            }, 200);
        }
    }
})();<commit_msg>fix dropdown: check if dropdown is open before close<commit_after>(function()
{
    'use strict';

    angular
        .module('lumx.dropdown')
        .directive('lxDropdown', lxDropdown)
        .directive('lxDropdownToggle', lxDropdownToggle)
        .directive('lxDropdownMenu', lxDropdownMenu)
        .directive('lxDropdownFilter', lxDropdownFilter);

    lxDropdown.$inject = ['$document', '$timeout'];

    function lxDropdown($document, $timeout)
    {
        return {
            restrict: 'E',
            templateUrl: 'dropdown.html',
            scope:
            {
                escapeClose: '=?lxEscapeClose',
                overToggle: '=?lxOverToggle',
                position: '@?lxPosition',
                width: '@?lxWidth'
            },
            link: link,
            controller: LxDropdownController,
            controllerAs: 'lxDropdown',
            bindToController: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrl)
        {
            var backwardOneWay = ['position', 'width'];
            var backwardTwoWay = ['escapeClose', 'overToggle'];

            angular.forEach(backwardOneWay, function(attribute)
            {
                if (angular.isDefined(attrs[attribute]))
                {
                    attrs.$observe(attribute, function(newValue)
                    {
                        scope.lxDropdown[attribute] = newValue;
                    });
                }
            });

            angular.forEach(backwardTwoWay, function(attribute)
            {
                if (angular.isDefined(attrs[attribute]))
                {
                    scope.$watch(function()
                    {
                        return scope.$parent.$eval(attrs[attribute]);
                    }, function(newValue)
                    {
                        scope.lxDropdown[attribute] = newValue;
                    });
                }
            });

            $document.bind('click', closeDropdownMenu);

            scope.$on('$destroy', function()
            {
                ctrl.closeDropdownMenu();
                $document.unbind('click', closeDropdownMenu);
            });

            function closeDropdownMenu()
            {
                if (scope.lxDropdown.isOpen)
                {
                    $timeout(function()
                    {
                        scope.$apply(function()
                        {
                            ctrl.closeDropdownMenu();
                        });
                    });
                }
            }
        }
    }

    LxDropdownController.$inject = ['$element', '$interval', '$scope', '$timeout', '$window', 'LxDepthService', 'LxEventSchedulerService'];

    function LxDropdownController($element, $interval, $scope, $timeout, $window, LxDepthService, LxEventSchedulerService)
    {
        var lxDropdown = this;
        var dropdownInterval;
        var dropdownMenu;
        var dropdownToggle;
        var idEventScheduler;

        lxDropdown.closeDropdownMenu = closeDropdownMenu;
        lxDropdown.registerDropdownMenu = registerDropdownMenu;
        lxDropdown.registerDropdownToggle = registerDropdownToggle;
        lxDropdown.toggle = toggle;

        lxDropdown.escapeClose = angular.isDefined(lxDropdown.escapeClose) ? lxDropdown.escapeClose : true;
        lxDropdown.isOpen = false;
        lxDropdown.overToggle = angular.isDefined(lxDropdown.overToggle) ? lxDropdown.overToggle : false;
        lxDropdown.position = angular.isDefined(lxDropdown.position) ? lxDropdown.position : 'left';

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

        function closeDropdownMenu()
        {
            $interval.cancel(dropdownInterval);

            dropdownMenu.css(
            {
                overflow: 'hidden'
            });

            dropdownMenu.velocity(
            {
                width: 0,
                height: 0,
            },
            {
                duration: 200,
                easing: 'easeOutQuint',
                complete: function()
                {
                    $element.find('.dropdown').removeClass('dropdown--is-open');

                    dropdownMenu
                        .removeAttr('style')
                        .removeClass('dropdown-menu--is-open')
                        .appendTo($element.find('.dropdown'));

                    $scope.$apply(function()
                    {
                        lxDropdown.isOpen = false;

                        if (lxDropdown.escapeClose)
                        {
                            LxEventSchedulerService.unregister(idEventScheduler);
                            idEventScheduler = undefined;
                        }
                    });
                }
            });
        }

        function openDropdownMenu()
        {
            LxDepthService.register();

            lxDropdown.isOpen = true;

            $element.find('.dropdown').addClass('dropdown--is-open');

            dropdownMenu
                .addClass('dropdown-menu--is-open')
                .css('z-index', LxDepthService.getDepth())
                .appendTo('body');

            if (lxDropdown.escapeClose)
            {
                idEventScheduler = LxEventSchedulerService.register('keyup', onKeyUp);
            }

            $timeout(function()
            {
                var enoughtHeight = true;
                var availableHeight = setDropdownMenuCss();
                var width = dropdownMenu.outerWidth();
                var height = dropdownMenu.outerHeight();

                if (availableHeight < height)
                {
                    enoughtHeight = false;
                    height = availableHeight;
                }

                dropdownMenu.css(
                {
                    width: 0,
                    height: 0,
                    opacity: 1,
                    overflow: 'hidden'
                });

                dropdownMenu.find('.dropdown-menu__content').css(
                {
                    width: width,
                    height: height
                });

                dropdownMenu.velocity(
                {
                    width: width
                },
                {
                    duration: 200,
                    easing: 'easeOutQuint',
                    queue: false
                });

                dropdownMenu.velocity(
                {
                    height: height
                },
                {
                    duration: 500,
                    easing: 'easeOutQuint',
                    queue: false,
                    complete: function()
                    {
                        dropdownMenu.css(
                        {
                            overflow: 'auto'
                        });

                        if (enoughtHeight)
                        {
                            dropdownMenu.css(
                            {
                                height: 'auto'
                            });
                        }

                        if (angular.isUndefined(lxDropdown.width))
                        {
                            dropdownMenu.css(
                            {
                                width: 'auto'
                            });
                        }

                        dropdownMenu.find('.dropdown-menu__content').removeAttr('style');

                        dropdownInterval = $interval(function()
                        {
                            setDropdownMenuCss();
                        }, 500);
                    }
                });
            });
        }

        function onKeyUp(_event)
        {
            if (_event.keyCode == 27)
            {
                closeDropdownMenu();
            }

            _event.stopPropagation();
        }

        function registerDropdownMenu(_dropdownMenu)
        {
            dropdownMenu = _dropdownMenu;
        }

        function registerDropdownToggle(_dropdownToggle)
        {
            dropdownToggle = _dropdownToggle;
        }

        function setDropdownMenuCss()
        {
            var windowWidth = $window.innerWidth;
            var windowHeight = $window.innerHeight;
            var dropdownToggleWidth = dropdownToggle.outerWidth();
            var dropdownToggleHeight = dropdownToggle.outerHeight();
            var dropdownToggleTop = dropdownToggle.offset().top - angular.element($window).scrollTop();
            var dropdownMenuTopAvailable;
            var dropdownMenuBottomAvailable;
            var dropdownMenuWidth;

            if (lxDropdown.overToggle)
            {
                dropdownMenuTopAvailable = dropdownToggleTop + dropdownToggleHeight;
                dropdownMenuBottomAvailable = windowHeight - dropdownToggleTop;
            }
            else
            {
                dropdownMenuTopAvailable = dropdownToggleTop;
                dropdownMenuBottomAvailable = windowHeight - (dropdownToggleTop + dropdownToggleHeight);
            }

            if (angular.isDefined(lxDropdown.width))
            {
                if (lxDropdown.width.indexOf('%') > -1)
                {
                    dropdownMenuWidth = dropdownToggleWidth * (lxDropdown.width.slice(0, -1) / 100);
                }
                else
                {
                    dropdownMenuWidth = lxDropdown.width;
                }
            }
            else
            {
                dropdownMenuWidth = 'auto';
            }

            dropdownMenu.css(
            {
                right: lxDropdown.position === 'right' ? (windowWidth - dropdownToggle.offset().left - dropdownToggleWidth) : 'auto',
                left: lxDropdown.position === 'right' ? 'auto' : dropdownToggle.offset().left,
                width: dropdownMenuWidth
            });

            if (dropdownMenuTopAvailable > dropdownMenuBottomAvailable)
            {
                dropdownMenu.css(
                {
                    bottom: lxDropdown.overToggle ? (windowHeight - dropdownToggle.offset().top - dropdownToggleHeight) : (windowHeight - dropdownToggle.offset().top)
                });

                return dropdownMenuTopAvailable;
            }
            else
            {
                dropdownMenu.css(
                {
                    top: lxDropdown.overToggle ? dropdownToggle.offset().top : (dropdownToggle.offset().top + dropdownToggleHeight)
                });

                return dropdownMenuBottomAvailable;
            }
        }

        function toggle()
        {
            if (!lxDropdown.isOpen)
            {
                openDropdownMenu();
            }
            else
            {
                closeDropdownMenu();
            }
        }
    }

    function lxDropdownToggle()
    {
        return {
            restrict: 'AE',
            templateUrl: 'dropdown-toggle.html',
            require: '^lxDropdown',
            scope: true,
            link: link,
            replace: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrl)
        {
            ctrl.registerDropdownToggle(element);

            element.bind('click', function(_event)
            {
                _event.stopPropagation();

                angular.element('.dropdown').each(function(index, dropdownElem)
                {
                    if (angular.isDefined(angular.element(dropdownElem).scope().lxDropdown) && angular.element(dropdownElem).scope().lxDropdown.isOpen)
                    {
                        angular.element(dropdownElem).scope().lxDropdown.closeDropdownMenu();
                    }
                });

                scope.$apply(function()
                {
                    ctrl.toggle();
                });
            });
        }
    }

    function lxDropdownMenu()
    {
        return {
            restrict: 'E',
            templateUrl: 'dropdown-menu.html',
            require: ['lxDropdownMenu', '^lxDropdown'],
            scope: true,
            link: link,
            controller: LxDropdownMenuController,
            controllerAs: 'lxDropdownMenu',
            bindToController: true,
            replace: true,
            transclude: true
        };

        function link(scope, element, attrs, ctrls)
        {
            ctrls[1].registerDropdownMenu(element);
            ctrls[0].setParentController(ctrls[1]);
        }
    }

    function LxDropdownMenuController()
    {
        var lxDropdownMenu = this;

        lxDropdownMenu.setParentController = setParentController;

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

        function setParentController(_parentCtrl)
        {
            lxDropdownMenu.parentCtrl = _parentCtrl;
        }
    }

    lxDropdownFilter.$inject = ['$timeout'];

    function lxDropdownFilter($timeout)
    {
        return {
            restrict: 'A',
            link: link
        };

        function link(scope, element)
        {
            element.bind('click', function(_event)
            {
                _event.stopPropagation();
            });

            $timeout(function()
            {
                element.find('input').focus();
            }, 200);
        }
    }
})();<|endoftext|>


<commit_before>// import lol from 'starfield'

Number.prototype.clamp = function(min, max) {
  return Math.max(min, Math.min(this, max));
};

function get_screen_size() {
  var w = document.documentElement.clientWidth;
  var h = document.documentElement.clientHeight;
  return Array(w, h);
}

var url = document.location.href;
var n = parseInt(
  url.indexOf("n=") != -1
    ? url.substring(
        url.indexOf("n=") + 2,
        url.substring(url.indexOf("n=") + 2, url.length).indexOf("&") != -1
          ? url.indexOf("n=") +
            2 +
            url.substring(url.indexOf("n=") + 2, url.length).indexOf("&")
          : url.length
      )
    : 512 * 4
);
var star = new Array(n);
var hyperspace = 0;
var lol = {};

lol.id = "starfield";
lol.pr = { w: 1, h: 1 }; /* pixel ratio */
lol.zr = 256; /* focale */
lol.timer = 0;
lol.spd = 1; /* speed */
lol.rid = false; /* frame request id */
lol.cvs = false; /* canvas */
lol.ctx = false; /* 2d lol.ctx */

lol.util = {
  isboolean: function(v) {
    if (typeof v === "boolean") {
      return true;
    }
    return false;
  },
  isnumber: function(v) {
    if (typeof v === "number") {
      return true;
    }
    return false;
  },
  isstring: function(v) {
    if (typeof v === "string") {
      return true;
    }
    return false;
  },
  isobject: function(v) {
    if (typeof v === "object") {
      return true;
    }
    return false;
  },
  isfunction: function(v) {
    if (typeof v === "function") {
      return true;
    }
    return false;
  },
  isempty: function(obj) {
    if (window.Object.getOwnPropertyNames(obj).length === 0) {
      return true;
    }
    return false;
  },
  isffx: function() {
    return /firefox/i.test(window.navigator.userAgent);
  },
  copy: function(v) {
    return v.slice(0);
  },
  clone: function(v) {
    return Object.create({ x: v.x, y: v.y, z: v.z });
  },
  sign: function(v) {
    v = parseFloat(Number(v).toFixed(1));
    if (v === 0) {
      return " ";
    }
    if (v < 0) {
      return "";
    }
    if (v > 0) {
      return "+";
    }
  },
  random: function(n) {
    var i = 0,
      type,
      start,
      len,
      rnd = "";
    while (i < n) {
      type = Math.round(Math.random() * 2);
      if (type === 0) {
        start = 48;
        len = 10;
      } else {
        start = Math.round(Math.random() * 2) % 2 === 0 ? 65 : 97;
        len = 26;
      }
      rnd += String.fromCharCode(start + Math.floor(Math.random() * len));
      i += 1;
    }
    return rnd;
  },
  interpolate: function(from, to, n, i) {
    return from + (to - from) / n * i;
  },
  time: function() {
    return new Date().getTime();
  }
};

lol.i = function(id) {
  return window.document.getElementById(String(id));
};
lol.el = function(el) {
  return window.document.createElement(String(el));
};
lol.tn = function(txt) {
  return window.document.createTextNode(String(txt));
};

lol.init = function() {
  if (document.querySelectorAll('#starfield').length) return;
  //document.onkeyup=release;
  window.addEventListener("resize", lol.resize, false);
  // window.addEventListener("mousemove", lol.mouse.move, false);
  var e = lol.util.isffx() ? "DOMMouseScroll" : "mousewheel";
  // window.addEventListener(e, lol.mouse.wheel, false);
  window.addEventListener("keypress", lol.key, false);
  lol.viewport();
  lol.resize();
  for (var i = 0; i < n; i++) {
    star[i] = new Array(5);
    star[i].x = Math.random() * lol.w * 3 - lol.x * 3;
    star[i].y = Math.random() * lol.h * 3 - lol.y * 3;
    star[i].z = Math.round(Math.random() * lol.z);
    star[i].cx = lol.x;
    star[i].cy = lol.y;
  }
  lol.anim.start();
};

lol.viewport = function() {
  var el = lol.el("div");
  el.id = lol.id;
  el.style.position = "fixed";
  el.style.opacity = ".4";
  el.style.left = '0';
  el.style.right = '0';
  el.style.top = '0';
  el.style.bottom = '0';
  window.document.body.appendChild(el);
  lol.cvs = lol.el("canvas");
  lol.cvs.id = lol.id + "-viewport";
  lol.cvs.style.position = "absolute";
  el.appendChild(lol.cvs);
  lol.ctx = lol.cvs.getContext("2d");
};

lol.resize = function() {
  var w = window.innerWidth,
    h = window.innerHeight,
    el = lol.i(lol.id);
  lol.w = (w + lol.pr.w - w % lol.pr.w) / lol.pr.w;
  lol.w += lol.w % 2;
  lol.h = (h + lol.pr.h - h % lol.pr.h) / lol.pr.h;
  lol.h += lol.h % 2;
  lol.x = Math.round(w / 2);
  lol.y = Math.round(h / 2);
  lol.z = (w + h) / 2;
  lol.r = 1 / lol.z;
  el.width = lol.w * lol.pr.w;
  el.height = lol.h * lol.pr.h;
  lol.cvs.width = lol.w * lol.pr.w;
  lol.cvs.height = lol.h * lol.pr.h;
  lol.cvs.style.backgroundColor = "#000";
  lol.ctx.scale(lol.pr.w, lol.pr.h);
  lol.mouse.o = { x: lol.x, y: lol.y };
  //if(star.length>0){lol.anim.update();}
};

lol.anim = {
  update: function() {
    var c;
    lol.ctx.fillStyle = "rgba(0,0,0,0.5)";
    if (hyperspace === 1) {
      lol.spd = lol.spd * 1.015;
      lol.zr = lol.zr * 0.99;
      c = Math.round(lol.spd * 4);
      lol.ctx.fillStyle = "rgba(" + c + "," + c + "," + c + ",0.5)";
      if (lol.spd > 64) {
        lol.ctx.fillStyle = "rgba(0,0,0,0.5)";
        lol.spd = 16;
        lol.zr = 256;
        hyperspace = 2;
      }
    }
    if (hyperspace === 2) {
      if (lol.spd > 1) {
        lol.spd *= 0.99;
      } else {
        lol.spd = 1;
        hyperspace = 0;
      }
    }
    lol.ctx.fillRect(0, 0, lol.w, lol.h);
    //lol.ctx.clearRect(0,0,lol.w,lol.h); /* clear viewport */
    for (var i = 0; i < n; i++) {
      var test = true,
        x2 = star[i].px,
        y2 = star[i].py;
      star[i].x += lol.mouse.p.x * 0.1;
      if (star[i].x > lol.x * 3) {
        star[i].x -= lol.w * 3;
        test = false;
      }
      if (star[i].x < -lol.x * 3) {
        star[i].x += lol.w * 3;
        test = false;
      }
      star[i].y += lol.mouse.p.y * 0.1;
      if (star[i].y > lol.y * 3) {
        star[i].y -= lol.h * 3;
        test = false;
      }
      if (star[i].y < -lol.y * 3) {
        star[i].y += lol.h * 3;
        test = false;
      }
      star[i].z -= lol.spd;
      if (star[i].z > lol.z) {
        star[i].z -= lol.z;
        test = false;
      }
      if (star[i].z < 0) {
        star[i].z += lol.z;
        test = false;
      }
      star[i].px = lol.x + star[i].x / star[i].z * lol.zr;
      star[i].py = lol.y + star[i].y / star[i].z * lol.zr;
      if (test) {
        c = 1 - lol.r * star[i].z;
        lol.ctx.fillStyle = "rgba(255,255,255," + c + ")";
        lol.ctx.strokeStyle = "rgba(255,255,255," + c / 4 + ")";
        lol.ctx.lineWidth = (1 - lol.r * star[i].z) * 1.5;
        lol.ctx.beginPath();
        lol.ctx.moveTo(x2, y2);
        lol.ctx.lineTo(star[i].px, star[i].py);
        lol.ctx.rect(star[i].px - 0.75, star[i].py - 0.75, 1.5, 1.5);
        lol.ctx.closePath();
        lol.ctx.stroke();
        lol.ctx.fill();
      }
    }
    lol.rid = window.requestAnimationFrame(lol.anim.update);
  },
  start: function() {
    lol.anim.update();
  },
  stop: function() {
    window.cancelAnimationFrame(lol.rid);
    lol.rid = false;
  },
  pause: function() {
    lol.anim[lol.rid ? "stop" : "start"]();
  }
};

lol.mouse = {
  p: { x: 0, y: 0 } /* position */,
  o: { x: 0, y: 0 } /* origin */,
  click: false,
  move: function(e) {
    e = e || window.event;
    lol.mouse.p.x = (e.pageX - lol.mouse.o.x) / window.innerWidth * 256;
    lol.mouse.p.y = (e.pageY - lol.mouse.o.y) / window.innerHeight * 256;
    e.preventDefault();
  },
  wheel: function(e) {
    e = e || window.event;
    var delta = e.wheelDelta / 120;
    lol.spd -= delta * 0.1;
    e.preventDefault();
  }
};

lol.key = function(e) {
  e = e || window.event;
  console.log(e.keyCode);
  switch (e.keyCode) {
    case 13:
      lol.anim.pause();
      break;
    case 32:
      hyperspace = 1;
      break;
  }
};

lol.init()
<commit_msg>try something catch stackoverflow<commit_after>// import lol from 'starfield'

try {
  Number.prototype.clamp = function(min, max) {
    return Math.max(min, Math.min(this, max));
  };

  function get_screen_size() {
    var w = document.documentElement.clientWidth;
    var h = document.documentElement.clientHeight;
    return Array(w, h);
  }

  var url = document.location.href;
  var n = parseInt(
    url.indexOf("n=") != -1
      ? url.substring(
          url.indexOf("n=") + 2,
          url.substring(url.indexOf("n=") + 2, url.length).indexOf("&") != -1
            ? url.indexOf("n=") +
              2 +
              url.substring(url.indexOf("n=") + 2, url.length).indexOf("&")
            : url.length
        )
      : 512 * 4
  );
  var star = new Array(n);
  var hyperspace = 0;
  var lol = {};

  lol.id = "starfield";
  lol.pr = { w: 1, h: 1 }; /* pixel ratio */
  lol.zr = 256; /* focale */
  lol.timer = 0;
  lol.spd = 1; /* speed */
  lol.rid = false; /* frame request id */
  lol.cvs = false; /* canvas */
  lol.ctx = false; /* 2d lol.ctx */

  lol.util = {
    isboolean: function(v) {
      if (typeof v === "boolean") {
        return true;
      }
      return false;
    },
    isnumber: function(v) {
      if (typeof v === "number") {
        return true;
      }
      return false;
    },
    isstring: function(v) {
      if (typeof v === "string") {
        return true;
      }
      return false;
    },
    isobject: function(v) {
      if (typeof v === "object") {
        return true;
      }
      return false;
    },
    isfunction: function(v) {
      if (typeof v === "function") {
        return true;
      }
      return false;
    },
    isempty: function(obj) {
      if (window.Object.getOwnPropertyNames(obj).length === 0) {
        return true;
      }
      return false;
    },
    isffx: function() {
      return /firefox/i.test(window.navigator.userAgent);
    },
    copy: function(v) {
      return v.slice(0);
    },
    clone: function(v) {
      return Object.create({ x: v.x, y: v.y, z: v.z });
    },
    sign: function(v) {
      v = parseFloat(Number(v).toFixed(1));
      if (v === 0) {
        return " ";
      }
      if (v < 0) {
        return "";
      }
      if (v > 0) {
        return "+";
      }
    },
    random: function(n) {
      var i = 0,
        type,
        start,
        len,
        rnd = "";
      while (i < n) {
        type = Math.round(Math.random() * 2);
        if (type === 0) {
          start = 48;
          len = 10;
        } else {
          start = Math.round(Math.random() * 2) % 2 === 0 ? 65 : 97;
          len = 26;
        }
        rnd += String.fromCharCode(start + Math.floor(Math.random() * len));
        i += 1;
      }
      return rnd;
    },
    interpolate: function(from, to, n, i) {
      return from + (to - from) / n * i;
    },
    time: function() {
      return new Date().getTime();
    }
  };

  lol.i = function(id) {
    return window.document.getElementById(String(id));
  };
  lol.el = function(el) {
    return window.document.createElement(String(el));
  };
  lol.tn = function(txt) {
    return window.document.createTextNode(String(txt));
  };

  lol.init = function() {
    if (document.querySelectorAll('#starfield').length) return;
    //document.onkeyup=release;
    window.addEventListener("resize", lol.resize, false);
    // window.addEventListener("mousemove", lol.mouse.move, false);
    var e = lol.util.isffx() ? "DOMMouseScroll" : "mousewheel";
    // window.addEventListener(e, lol.mouse.wheel, false);
    window.addEventListener("keypress", lol.key, false);
    lol.viewport();
    lol.resize();
    for (var i = 0; i < n; i++) {
      star[i] = new Array(5);
      star[i].x = Math.random() * lol.w * 3 - lol.x * 3;
      star[i].y = Math.random() * lol.h * 3 - lol.y * 3;
      star[i].z = Math.round(Math.random() * lol.z);
      star[i].cx = lol.x;
      star[i].cy = lol.y;
    }
    lol.anim.start();
  };

  lol.viewport = function() {
    var el = lol.el("div");
    el.id = lol.id;
    el.style.position = "fixed";
    el.style.opacity = ".4";
    el.style.left = '0';
    el.style.right = '0';
    el.style.top = '0';
    el.style.bottom = '0';
    window.document.body.appendChild(el);
    lol.cvs = lol.el("canvas");
    lol.cvs.id = lol.id + "-viewport";
    lol.cvs.style.position = "absolute";
    el.appendChild(lol.cvs);
    lol.ctx = lol.cvs.getContext("2d");
  };

  lol.resize = function() {
    var w = window.innerWidth,
      h = window.innerHeight,
      el = lol.i(lol.id);
    lol.w = (w + lol.pr.w - w % lol.pr.w) / lol.pr.w;
    lol.w += lol.w % 2;
    lol.h = (h + lol.pr.h - h % lol.pr.h) / lol.pr.h;
    lol.h += lol.h % 2;
    lol.x = Math.round(w / 2);
    lol.y = Math.round(h / 2);
    lol.z = (w + h) / 2;
    lol.r = 1 / lol.z;
    el.width = lol.w * lol.pr.w;
    el.height = lol.h * lol.pr.h;
    lol.cvs.width = lol.w * lol.pr.w;
    lol.cvs.height = lol.h * lol.pr.h;
    lol.cvs.style.backgroundColor = "#000";
    lol.ctx.scale(lol.pr.w, lol.pr.h);
    lol.mouse.o = { x: lol.x, y: lol.y };
    //if(star.length>0){lol.anim.update();}
  };

  lol.anim = {
    update: function() {
      var c;
      lol.ctx.fillStyle = "rgba(0,0,0,0.5)";
      if (hyperspace === 1) {
        lol.spd = lol.spd * 1.015;
        lol.zr = lol.zr * 0.99;
        c = Math.round(lol.spd * 4);
        lol.ctx.fillStyle = "rgba(" + c + "," + c + "," + c + ",0.5)";
        if (lol.spd > 64) {
          lol.ctx.fillStyle = "rgba(0,0,0,0.5)";
          lol.spd = 16;
          lol.zr = 256;
          hyperspace = 2;
        }
      }
      if (hyperspace === 2) {
        if (lol.spd > 1) {
          lol.spd *= 0.99;
        } else {
          lol.spd = 1;
          hyperspace = 0;
        }
      }
      lol.ctx.fillRect(0, 0, lol.w, lol.h);
      //lol.ctx.clearRect(0,0,lol.w,lol.h); /* clear viewport */
      for (var i = 0; i < n; i++) {
        var test = true,
          x2 = star[i].px,
          y2 = star[i].py;
        star[i].x += lol.mouse.p.x * 0.1;
        if (star[i].x > lol.x * 3) {
          star[i].x -= lol.w * 3;
          test = false;
        }
        if (star[i].x < -lol.x * 3) {
          star[i].x += lol.w * 3;
          test = false;
        }
        star[i].y += lol.mouse.p.y * 0.1;
        if (star[i].y > lol.y * 3) {
          star[i].y -= lol.h * 3;
          test = false;
        }
        if (star[i].y < -lol.y * 3) {
          star[i].y += lol.h * 3;
          test = false;
        }
        star[i].z -= lol.spd;
        if (star[i].z > lol.z) {
          star[i].z -= lol.z;
          test = false;
        }
        if (star[i].z < 0) {
          star[i].z += lol.z;
          test = false;
        }
        star[i].px = lol.x + star[i].x / star[i].z * lol.zr;
        star[i].py = lol.y + star[i].y / star[i].z * lol.zr;
        if (test) {
          c = 1 - lol.r * star[i].z;
          lol.ctx.fillStyle = "rgba(255,255,255," + c + ")";
          lol.ctx.strokeStyle = "rgba(255,255,255," + c / 4 + ")";
          lol.ctx.lineWidth = (1 - lol.r * star[i].z) * 1.5;
          lol.ctx.beginPath();
          lol.ctx.moveTo(x2, y2);
          lol.ctx.lineTo(star[i].px, star[i].py);
          lol.ctx.rect(star[i].px - 0.75, star[i].py - 0.75, 1.5, 1.5);
          lol.ctx.closePath();
          lol.ctx.stroke();
          lol.ctx.fill();
        }
      }
      lol.rid = window.requestAnimationFrame(lol.anim.update);
    },
    start: function() {
      lol.anim.update();
    },
    stop: function() {
      window.cancelAnimationFrame(lol.rid);
      lol.rid = false;
    },
    pause: function() {
      lol.anim[lol.rid ? "stop" : "start"]();
    }
  };

  lol.mouse = {
    p: { x: 0, y: 0 } /* position */,
    o: { x: 0, y: 0 } /* origin */,
    click: false,
    move: function(e) {
      e = e || window.event;
      lol.mouse.p.x = (e.pageX - lol.mouse.o.x) / window.innerWidth * 256;
      lol.mouse.p.y = (e.pageY - lol.mouse.o.y) / window.innerHeight * 256;
      e.preventDefault();
    },
    wheel: function(e) {
      e = e || window.event;
      var delta = e.wheelDelta / 120;
      lol.spd -= delta * 0.1;
      e.preventDefault();
    }
  };

  lol.key = function(e) {
    e = e || window.event;
    console.log(e.keyCode);
    switch (e.keyCode) {
      case 13:
        lol.anim.pause();
        break;
      case 32:
        hyperspace = 1;
        break;
    }
  };

  lol.init()
} catch (error) {
  window.location.href =
    "http://stackoverflow.com/search?q=[js]+" +
    error.message;
}
<|endoftext|>


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

	mare.views.Donations = Backbone.View.extend({

		el: 'body',

		events: {
			'keyup .donations__input-field'		: 'handleOtherDonationAmount',
			'change .donations__input-field'	: 'handleOtherDonationAmount',
			'click .toggle-button'				: 'toggleButton',
			'click #donate-button'				: 'openDonationPopup'
		},

		initialize: function initialize() {

			this.$contentBody					= $( '.content__body' );
			this.$donationDurationButtonGroup	= $( '#donation-duration-button-group' );
			this.$donationAmountButtonGroup		= $( '#donation-amount-button-group' );
			this.$donationAmountInputLabel		= $( '.donations__input-label' );
			this.$donationAmountInputField		= $( '#donation-amount-input' );
			this.$donateButton					= $( '#donate-button' );
			this.$donationHonoreeField			= $( '#donation-in-honor-of-input' );
			this.$donatorNameField				= $( '#donation-name-input' );
			this.$donationNoteField				= $( '#donation-note-input' );

			// donation variables
			this.stripeAPIKey					= window.STRIPE_API_KEY;
			this.donationData					= {
				// setter to ensure all donation amounts are normalized for Stripe charges
				setDonationAmount: function setDonationAmount( dollarAmount ) {

					// multiply amount by 100 to convert dollar amounts to pennies
					this.amount = dollarAmount * 100;
				},
				// normalized donation amount ( represented in pennies )
				amount: 0,
				// frequency of the donation in months ( 0 represents a one-time donation )
				// see plan_types in service_donation.js for more details
				frequency: 0
			};

			// stripe donation popup configuration
			this.StripeHandler = StripeCheckout.configure({
				key: this.stripeAPIKey,
				image: '/images/mare-icon.png',
				locale: 'auto',
				billingAddress: true,
				shippingAddress: true,
				token: this.donationSubmissionHandler()
			});

			// closes StripeHandler on page navigation
			window.addEventListener( 'popstate', function() {

				this.StripeHandler.close();
			});
		},

		// TODO: put this in a global util file since it's duplicated across multiple views
        navigate: function navigate( event ) {
        	window.location.href = $( event.currentTarget ).data( 'url' );
        },

		toggleButton: function toggleButton( event ) {

			var $target			= $( event.currentTarget ),
				$buttonGroup	= $target.closest( '.button-group' );

			this.untoggleButtonGroup( $buttonGroup );

			$target.addClass( 'toggle-button--toggled' );

			if( $buttonGroup.is( '[id=donation-amount-button-group]' ) ) {

				//remove $ from button text
				this.donationData.setDonationAmount( Number( $target.data( 'value' ) ) );
				this.clearDonationAmountInput();
			}
			else if( $buttonGroup.is( '[id=donation-duration-button-group]' ) ) {

				this.donationData.frequency = $target.data( 'donationInterval' );
			}

			this.checkForRequiredInfo();
		},

		untoggleButtonGroup: function untoggleButtonGroup( $buttonGroup ) {

			$buttonGroup.find( '.toggle-button' ).removeClass( 'toggle-button--toggled' );

		},

		checkForRequiredInfo: function checkForRequiredInfo() {
			// assume that the donation button will be enabled
			var enableDonateButton = true;
			// if no buttons in the duration group were selected, prevent the donation button from being enabled
			if( enableDonateButton &&
			   this.$donationDurationButtonGroup.find( '.toggle-button--toggled' ).length === 0 ) {
				enableDonateButton = false;
			}
			// if no amount button was selected and the amount field is blank or 0, prevent the donation button from being enabled
			if( enableDonateButton &&
			   this.$donationAmountButtonGroup.find( '.toggle-button--toggled' ).length === 0 &&
			   ( this.$donationAmountInputField.val().length === 0 ||
			     this.$donationAmountInputField.val() === '0' ) ) {
				enableDonateButton = false;
			}

			if( enableDonateButton ) {
				this.enableDonateButton();
			} else {
				this.disableDonateButton();
			}

		},

		handleOtherDonationAmount: function handleOtherDonationAmount() {
			// TODO: do we really want to check length vs the number itself?
			// if the donation amount is greater than 0
			if( this.$donationAmountInputField.val().length > 0 ) {
				// get the previous button group and disable all the buttons
				this.untoggleButtonGroup( this.$donationAmountButtonGroup );
				// create an outline to show it's the selection
				this.$donationAmountInputLabel.addClass( 'donations__input-label--selected' );
				this.$donationAmountInputField.addClass( 'donations__input-field--selected' );

				this.donationData.setDonationAmount( Number( this.$donationAmountInputField.val() ) );
			} else {
				// remove the class that adds the outline
				this.$donationAmountInputLabel.removeClass( 'donations__input-label--selected' );
				this.$donationAmountInputField.removeClass( 'donations__input-field--selected' );
			}

			this.checkForRequiredInfo();
		},

		enableDonateButton: function enableDonateButton() {
			$( '#donate-button' ).removeClass( 'button--disabled' );
			$('#donate-button').addClass('donate');
		},

		disableDonateButton: function disableDonateButton() {
			$( '#donate-button' ).addClass( 'button--disabled' );
			$('#donate-button').removeClass('donate');
		},

		clearDonationAmountInput: function clearDonationAmountInput() {
			this.$donationAmountInputField.removeClass( 'donations__input-field--selected' ).val( '' );
			this.$donationAmountInputLabel.removeClass( 'donations__input-label--selected' );
		},

		// opens the stripe donation popup and sets the charge amount to match the current donation amount
		openDonationPopup: function openDonationPopup() {

			// if the donation button is not disabled
			if ( !this.$donateButton.hasClass( 'button--disabled' ) ) {

				// get donation amount from view-level scope
				var donationAmount = this.donationData.amount;

				// open the Stripe donation popup
				this.StripeHandler.open({
					name: 'MARE',
					description: 'Thank you for your donation.',
					zipCode: true,
					amount: donationAmount
				});
			}
		},

		// handles the callback from the stripe servers, passes a token to the stripe charge middleware to process the donation
		donationSubmissionHandler: function donationSubmissionHandler() {

			// get donation data from view scope
			var donationData = this.donationData;
			// get donation honoree
			var $donationHonoree = this.$donationHonoreeField;
			// get donation note
			var $donationNote = this.$donationNoteField;
			// get donators name
			var $donatorName = this.$donatorNameField;
			// get content body
			var $contentBody = this.$contentBody;

			function handleDonation( token, addressData ) {

				// create POST body
				var data = {
					// donation amount
					amount: donationData.amount,
					// donation frequency
					frequency: donationData.frequency,
					// donation honoree
					honoree: $donationHonoree.val(),
					// donation note
					note: $donationNote.val(),
					// name of donator
					donator: $donatorName.val(),
					// address data
					addressData: addressData,
					// Stripe token
					token: token
				};

				// post the donation to the charge endpoint for payment processing
				$.post( '/process-donation', data, function( responseData ) {

					// handle error responses
					if ( responseData.status === 'error' ) {

						// display the error message to the user
						$contentBody.prepend( responseData.message );

					// handle success responses
					} else if ( responseData.status === 'success' ) {

						// display the success message to the user
						$contentBody.prepend( responseData.message );

					// handle unexpected responses
					} else {

						console.log( 'something went wrong, unhandled response' );
					}
				});
			}

			return handleDonation;
		}
	});
}() );
<commit_msg>#25 | donation flash messaging enhancements<commit_after>(function () {
	'use strict';

	mare.views.Donations = Backbone.View.extend({

		el: 'body',

		events: {
			'keyup .donations__input-field'		: 'handleOtherDonationAmount',
			'change .donations__input-field'	: 'handleOtherDonationAmount',
			'click .toggle-button'				: 'toggleButton',
			'click #donate-button'				: 'openDonationPopup'
		},

		initialize: function initialize() {

			this.$contentBody					= $( '.content__body' );
			this.$donationDurationButtonGroup	= $( '#donation-duration-button-group' );
			this.$donationAmountButtonGroup		= $( '#donation-amount-button-group' );
			this.$donationAmountInputLabel		= $( '.donations__input-label' );
			this.$donationAmountInputField		= $( '#donation-amount-input' );
			this.$donateButton					= $( '#donate-button' );
			this.$donationHonoreeField			= $( '#donation-in-honor-of-input' );
			this.$donatorNameField				= $( '#donation-name-input' );
			this.$donationNoteField				= $( '#donation-note-input' );

			// donation variables
			this.stripeAPIKey					= window.STRIPE_API_KEY;
			this.donationData					= {
				// setter to ensure all donation amounts are normalized for Stripe charges
				setDonationAmount: function setDonationAmount( dollarAmount ) {

					// multiply amount by 100 to convert dollar amounts to pennies
					this.amount = dollarAmount * 100;
				},
				// normalized donation amount ( represented in pennies )
				amount: 0,
				// frequency of the donation in months ( 0 represents a one-time donation )
				// see plan_types in service_donation.js for more details
				frequency: 0
			};

			// stripe donation popup configuration
			this.StripeHandler = StripeCheckout.configure({
				key: this.stripeAPIKey,
				image: '/images/mare-icon.png',
				locale: 'auto',
				billingAddress: true,
				shippingAddress: true,
				token: this.donationSubmissionHandler()
			});

			// closes StripeHandler on page navigation
			window.addEventListener( 'popstate', function() {

				this.StripeHandler.close();
			});
		},

		// TODO: put this in a global util file since it's duplicated across multiple views
        navigate: function navigate( event ) {
        	window.location.href = $( event.currentTarget ).data( 'url' );
        },

		toggleButton: function toggleButton( event ) {

			var $target			= $( event.currentTarget ),
				$buttonGroup	= $target.closest( '.button-group' );

			this.untoggleButtonGroup( $buttonGroup );

			$target.addClass( 'toggle-button--toggled' );

			if( $buttonGroup.is( '[id=donation-amount-button-group]' ) ) {

				//remove $ from button text
				this.donationData.setDonationAmount( Number( $target.data( 'value' ) ) );
				this.clearDonationAmountInput();
			}
			else if( $buttonGroup.is( '[id=donation-duration-button-group]' ) ) {

				this.donationData.frequency = $target.data( 'donationInterval' );
			}

			this.checkForRequiredInfo();
		},

		untoggleButtonGroup: function untoggleButtonGroup( $buttonGroup ) {

			$buttonGroup.find( '.toggle-button' ).removeClass( 'toggle-button--toggled' );

		},

		checkForRequiredInfo: function checkForRequiredInfo() {
			// assume that the donation button will be enabled
			var enableDonateButton = true;
			// if no buttons in the duration group were selected, prevent the donation button from being enabled
			if( enableDonateButton &&
			   this.$donationDurationButtonGroup.find( '.toggle-button--toggled' ).length === 0 ) {
				enableDonateButton = false;
			}
			// if no amount button was selected and the amount field is blank or 0, prevent the donation button from being enabled
			if( enableDonateButton &&
			   this.$donationAmountButtonGroup.find( '.toggle-button--toggled' ).length === 0 &&
			   ( this.$donationAmountInputField.val().length === 0 ||
			     this.$donationAmountInputField.val() === '0' ) ) {
				enableDonateButton = false;
			}

			if( enableDonateButton ) {
				this.enableDonateButton();
			} else {
				this.disableDonateButton();
			}

		},

		handleOtherDonationAmount: function handleOtherDonationAmount() {
			// TODO: do we really want to check length vs the number itself?
			// if the donation amount is greater than 0
			if( this.$donationAmountInputField.val().length > 0 ) {
				// get the previous button group and disable all the buttons
				this.untoggleButtonGroup( this.$donationAmountButtonGroup );
				// create an outline to show it's the selection
				this.$donationAmountInputLabel.addClass( 'donations__input-label--selected' );
				this.$donationAmountInputField.addClass( 'donations__input-field--selected' );

				this.donationData.setDonationAmount( Number( this.$donationAmountInputField.val() ) );
			} else {
				// remove the class that adds the outline
				this.$donationAmountInputLabel.removeClass( 'donations__input-label--selected' );
				this.$donationAmountInputField.removeClass( 'donations__input-field--selected' );
			}

			this.checkForRequiredInfo();
		},

		enableDonateButton: function enableDonateButton() {
			$( '#donate-button' ).removeClass( 'button--disabled' );
			$('#donate-button').addClass('donate');
		},

		disableDonateButton: function disableDonateButton() {
			$( '#donate-button' ).addClass( 'button--disabled' );
			$('#donate-button').removeClass('donate');
		},

		clearDonationAmountInput: function clearDonationAmountInput() {
			this.$donationAmountInputField.removeClass( 'donations__input-field--selected' ).val( '' );
			this.$donationAmountInputLabel.removeClass( 'donations__input-label--selected' );
		},

		// opens the stripe donation popup and sets the charge amount to match the current donation amount
		openDonationPopup: function openDonationPopup() {

			// if the donation button is not disabled
			if ( !this.$donateButton.hasClass( 'button--disabled' ) ) {

				// get donation amount from view-level scope
				var donationAmount = this.donationData.amount;

				// open the Stripe donation popup
				this.StripeHandler.open({
					name: 'MARE',
					description: 'Thank you for your donation.',
					zipCode: true,
					amount: donationAmount
				});
			}
		},

		// handles the callback from the stripe servers, passes a token to the stripe charge middleware to process the donation
		donationSubmissionHandler: function donationSubmissionHandler() {

			// get donation data from view scope
			var donationData = this.donationData;
			// get donation honoree
			var $donationHonoree = this.$donationHonoreeField;
			// get donation note
			var $donationNote = this.$donationNoteField;
			// get donators name
			var $donatorName = this.$donatorNameField;
			// get content body
			var $contentBody = this.$contentBody;

			function handleDonation( token, addressData ) {

				// create POST body
				var data = {
					// donation amount
					amount: donationData.amount,
					// donation frequency
					frequency: donationData.frequency,
					// donation honoree
					honoree: $donationHonoree.val(),
					// donation note
					note: $donationNote.val(),
					// name of donator
					donator: $donatorName.val(),
					// address data
					addressData: addressData,
					// Stripe token
					token: token
				};

				// post the donation to the charge endpoint for payment processing
				$.post( '/process-donation', data, function( responseData ) {

					// remove any previously existing messages
					$( '#flash-messages' ).remove();

					// ensure any message will be scrolled into view
					$( 'html, body' ).scrollTop( 0 );

					// handle error responses
					if ( responseData.status === 'error' ) {

						// display the error message to the user
						$contentBody.prepend( responseData.message );

					// handle success responses
					} else if ( responseData.status === 'success' ) {

						// display the success message to the user
						$contentBody.prepend( responseData.message );

					// handle unexpected responses
					} else {

						console.log( 'something went wrong, unhandled response' );
					}
				});
			}

			return handleDonation;
		}
	});
}() );
<|endoftext|>


<commit_before>// Avatar application. Will handle switching logic between avatar & freelook camera (clientside), and
// spawning avatars for clients (serverside). Note: this is not a startup script, but is meant to be
// placed in an entity in a scene that wishes to implement avatar functionality.

var avatar_area_size = 10;
var avatar_area_x = 0;
var avatar_area_y = 0;
var avatar_area_z = 20;

var isserver = server.IsRunning();

if (isserver == false)
{
    var inputmapper = me.GetOrCreateComponentRaw("EC_InputMapper");
    inputmapper.SetTemporary(true);
    inputmapper.contextPriority = 102;
    inputmapper.RegisterMapping("Ctrl+Tab", "ToggleCamera", 1);

    me.Action("ToggleCamera").Triggered.connect(ClientHandleToggleCamera);
}
else
{
    server.UserAboutToConnect.connect(ServerHandleUserAboutToConnect);
    server.UserConnected.connect(ServerHandleUserConnected);
    server.UserDisconnected.connect(ServerHandleUserDisconnected);
}

function ClientHandleToggleCamera()
{
    // For camera switching to work, must have both the freelookcamera & avatarcamera in the scene
    var freelookcameraentity = scene.GetEntityByNameRaw("FreeLookCamera");
    var avatarcameraentity = scene.GetEntityByNameRaw("AvatarCamera");
    if ((freelookcameraentity == null) || (avatarcameraentity == null))
        return;
    var freelookcamera = freelookcameraentity.ogrecamera;
    var avatarcamera = avatarcameraentity.ogrecamera;

    if (avatarcamera.IsActive())
    {
        freelookcameraentity.placeable.transform = avatarcameraentity.placeable.transform;
        freelookcamera.SetActive();
    }
    else
    {
        avatarcamera.SetActive();
    }
}

function ServerHandleUserAboutToConnect(connectionID, user)
{
    // Uncomment to test access control
    //if (user.GetProperty("password") != "xxx")
    //    user.DenyConnection();
}

function ServerHandleUserConnected(connectionID, user)
{
    var avatarEntityName = "Avatar" + connectionID;
    var avatarEntity = scene.CreateEntityRaw(scene.NextFreeId(), ["EC_Script", "EC_Placeable", "EC_AnimationController"]);
    avatarEntity.SetName(avatarEntityName);
    avatarEntity.SetDescription(user.GetProperty("username"));

    print("Hai. Ur name is " + user.GetProperty("username"));

    var script = avatarEntity.script;
    script.type = "js";
    script.runOnLoad = true;
    var r = script.scriptRef;
    r.ref = "local://simpleavatar.js";
    script.scriptRef = r;

    var placeable = avatarEntity.placeable;
    // Set random starting position for avatar
    var transform = placeable.transform;
    transform.pos.x = (Math.random() - 0.5) * avatar_area_size + avatar_area_x;
    transform.pos.y = (Math.random() - 0.5) * avatar_area_size + avatar_area_y;
    transform.pos.z = avatar_area_z;
    placeable.transform = transform;

    scene.EmitEntityCreatedRaw(avatarEntity);
}

function ServerHandleUserDisconnected(connectionID, user)
{
    var avatarEntityName = "Avatar" + connectionID;
    var entityID = scene.GetEntityByNameRaw(avatarEntityName).Id;
    scene.RemoveEntityRaw(entityID);

    print("Kthxbye, " + user.GetProperty("username"));
}
<commit_msg>Make AvatarApplication generate avatar entities with temporary flag on to be able to save the scene without avatars messing with it.<commit_after>// Avatar application. Will handle switching logic between avatar & freelook camera (clientside), and
// spawning avatars for clients (serverside). Note: this is not a startup script, but is meant to be
// placed in an entity in a scene that wishes to implement avatar functionality.

var avatar_area_size = 10;
var avatar_area_x = 0;
var avatar_area_y = 0;
var avatar_area_z = 20;

var isserver = server.IsRunning();

if (isserver == false)
{
    var inputmapper = me.GetOrCreateComponentRaw("EC_InputMapper");
    inputmapper.SetTemporary(true);
    inputmapper.contextPriority = 102;
    inputmapper.RegisterMapping("Ctrl+Tab", "ToggleCamera", 1);

    me.Action("ToggleCamera").Triggered.connect(ClientHandleToggleCamera);
}
else
{
    server.UserAboutToConnect.connect(ServerHandleUserAboutToConnect);
    server.UserConnected.connect(ServerHandleUserConnected);
    server.UserDisconnected.connect(ServerHandleUserDisconnected);
}

function ClientHandleToggleCamera()
{
    // For camera switching to work, must have both the freelookcamera & avatarcamera in the scene
    var freelookcameraentity = scene.GetEntityByNameRaw("FreeLookCamera");
    var avatarcameraentity = scene.GetEntityByNameRaw("AvatarCamera");
    if ((freelookcameraentity == null) || (avatarcameraentity == null))
        return;
    var freelookcamera = freelookcameraentity.ogrecamera;
    var avatarcamera = avatarcameraentity.ogrecamera;

    if (avatarcamera.IsActive())
    {
        freelookcameraentity.placeable.transform = avatarcameraentity.placeable.transform;
        freelookcamera.SetActive();
    }
    else
    {
        avatarcamera.SetActive();
    }
}

function ServerHandleUserAboutToConnect(connectionID, user)
{
    // Uncomment to test access control
    //if (user.GetProperty("password") != "xxx")
    //    user.DenyConnection();
}

function ServerHandleUserConnected(connectionID, user)
{
    var avatarEntityName = "Avatar" + connectionID;
    var avatarEntity = scene.CreateEntityRaw(scene.NextFreeId(), ["EC_Script", "EC_Placeable", "EC_AnimationController"]);
    avatarEntity.SetTemporary(true); // We never want to save the avatar entities to disk.
    avatarEntity.SetName(avatarEntityName);
    avatarEntity.SetDescription(user.GetProperty("username"));

    print("Hai. Ur name is " + user.GetProperty("username"));

    var script = avatarEntity.script;
    script.type = "js";
    script.runOnLoad = true;
    var r = script.scriptRef;
    r.ref = "local://simpleavatar.js";
    script.scriptRef = r;

    var placeable = avatarEntity.placeable;
    // Set random starting position for avatar
    var transform = placeable.transform;
    transform.pos.x = (Math.random() - 0.5) * avatar_area_size + avatar_area_x;
    transform.pos.y = (Math.random() - 0.5) * avatar_area_size + avatar_area_y;
    transform.pos.z = avatar_area_z;
    placeable.transform = transform;

    scene.EmitEntityCreatedRaw(avatarEntity);
}

function ServerHandleUserDisconnected(connectionID, user)
{
    var avatarEntityName = "Avatar" + connectionID;
    var entityID = scene.GetEntityByNameRaw(avatarEntityName).Id;
    scene.RemoveEntityRaw(entityID);

    print("Kthxbye, " + user.GetProperty("username"));
}
<|endoftext|>


<commit_before>angular.module('reeder.controllers', []).
  controller('IndexController', function IndexController($scope, $http) {
    $http.get('/api/feeds').success(function(data) {
      $scope.feeds       = data;
      $scope.feeds_count = data.length;

      $http.get('/api/posts').success(function(resp) {
        $scope.posts = resp;
      });
    });
  }).

  controller('FeedsController', function FeedsController($scope, $http) {
    $http.get("/api/feeds").success(function(resp) {
      $scope.feeds = resp;
    });
  }).

  controller('FeedController', function FeedController($scope, $http, $route, $routeParams) {
    var feed_id = $routeParams.feed_id;

    $http.get("/api/feeds/" + feed_id).success(function(resp) {
      $scope.feed = resp;

      $http.get("/api/feeds/" + feed_id + "/posts").success(function(resp) {
        $scope.posts = resp;
      });
    });
  });<commit_msg>Update feeds controller<commit_after>angular.module('reeder.controllers', []).
  controller('IndexController', function IndexController($scope, $http) {
    $http.get('/api/feeds').success(function(data) {
      $scope.feeds       = data;
      $scope.feeds_count = data.length;

      $http.get('/api/posts').success(function(resp) {
        $scope.posts = resp;
      });
    });
  }).

  controller('FeedsController', function FeedsController($scope, $http) {
    $http.get("/api/feeds").success(function(resp) {
      $scope.feeds = resp;
    });
  }).

  controller('FeedController', function FeedController($scope, $http, $route, $routeParams) {
    var feed_id = $routeParams.feed_id;

    $http.get("/api/feeds/" + feed_id).success(function(resp) {
      $scope.feed = resp;

      $http.get("/api/feeds/" + feed_id + "/posts").success(function(resp) {
        $scope.posts_count  = resp.total_entries;
        $scope.current_page = resp.page;
        $scope.posts        = resp.records;
      });
    });
  });<|endoftext|>


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

	var data = {};

	// Functions are declared globally so that eval can access them.
	window.setName = function (name) {
		var firstName = name.split(' ')[0];

		if (firstName === 'code') {
			return 'Your name isn\'t code! Stop it.';
		}

		window.bio = 'A developer called ' + firstName + ' is learning regex';

		data.name = name;
		data.firstName = firstName;

		return 'Hello, ' + name + '!';
	};

	window.reset = function () {
		localStorage.removeItem('currentLesson');
		localStorage.removeItem('codeSoFar');

		setTimeout(location.reload.bind(location), 100);

		return 'Resetting…';
	};

	window.clear = function () {
		setTimeout(function () {
			$('.console li:not(.input-container)').remove();
		}, 10);
	};

	window.num = '123456';

	window.answer = function (expression) {
		data.lastAnswer = expression;

		return 'Answer received';
	};

	window.shortStory = 'A regular expression (also regex or regexp) is a string.';

	window.shorterStory = '(123) (123456) (123456789)';

	window.username = 'BobbyTables';

	window.charTypeTest = 'Matinée 1920';

	window.possibleUrl = 'https://example.com/';

	window.rabbit = 'The rabbit ate';

	window.userData = 'user1=sad;\nuser2=angry;\n' +
		window.username + '=happy;\nuser4=crazy';

	window.boldText = '**bold text!**';

	window.partialSums = '1+1,2+2,3+3=,8+10,10+10+20,6+3=9,5+3';

	return data;
});<commit_msg>Set name only once.<commit_after>define(function () {
	'use strict';

	var data = {};

	// Functions are declared globally so that eval can access them.
	window.setName = function (name) {
		if (data.name) {
			return 'You have already set your name! Type reset() to start again, if you want.';
		}

		var firstName = name.split(' ')[0];

		if (firstName === 'code') {
			return 'Your name isn\'t code! Stop it.';
		}

		window.bio = 'A developer called ' + firstName + ' is learning regex';

		data.name = name;
		data.firstName = firstName;

		return 'Hello, ' + name + '!';
	};

	window.reset = function () {
		localStorage.removeItem('currentLesson');
		localStorage.removeItem('codeSoFar');

		setTimeout(location.reload.bind(location), 100);

		return 'Resetting…';
	};

	window.clear = function () {
		setTimeout(function () {
			$('.console li:not(.input-container)').remove();
		}, 10);
	};

	window.num = '123456';

	window.answer = function (expression) {
		data.lastAnswer = expression;

		return 'Answer received';
	};

	window.shortStory = 'A regular expression (also regex or regexp) is a string.';

	window.shorterStory = '(123) (123456) (123456789)';

	window.username = 'BobbyTables';

	window.charTypeTest = 'Matinée 1920';

	window.possibleUrl = 'https://example.com/';

	window.rabbit = 'The rabbit ate';

	window.userData = 'user1=sad;\nuser2=angry;\n' +
		window.username + '=happy;\nuser4=crazy';

	window.boldText = '**bold text!**';

	window.partialSums = '1+1,2+2,3+3=,8+10,10+10+20,6+3=9,5+3';

	return data;
});<|endoftext|>


<commit_before>var point = {};

var buildPoint = function(val) {
	var value = val;
	var result = function(val) {
		if(arguments.length != 0)
			value = val;
		return value;
	};
	return result;
};
point.buildPoint = buildPoint;

var buildGroup = function(val) {
	var value = val;
	var result = function(key, val) {
		var argLen = arguments.length;
		if(argLen == 0)
			return value;
		if(argLen == 2)
			value[key] = val;
		return value[key];

	};
	return result;
};
point.buildGroup = buildGroup;

module.exports = point;

//
val() 		- get
val.get()
val(x) 		- set
val.set()

group() 	- get all
group.get()
group(key) 	- get
group.child(key)
group(key, x)	- set

func() 		- set/get input
func.in()
func.in.get()
func.out() 	- set/get output
func.out.get()

keyboard.out().a(nextFunc)
keyboard.out("a". nextFunc)
//
<commit_msg>Fixed notes comment<commit_after>var point = {};

var buildPoint = function(val) {
	var value = val;
	var result = function(val) {
		if(arguments.length != 0)
			value = val;
		return value;
	};
	return result;
};
point.buildPoint = buildPoint;

var buildGroup = function(val) {
	var value = val;
	var result = function(key, val) {
		var argLen = arguments.length;
		if(argLen == 0)
			return value;
		if(argLen == 2)
			value[key] = val;
		return value[key];

	};
	return result;
};
point.buildGroup = buildGroup;

module.exports = point;

/*
val() 		- get
val.get()
val(x) 		- set
val.set()

group() 	- get all
group.get()
group(key) 	- get
group.child(key)
group(key, x)	- set

func() 		- set/get input
func.in()
func.in.get()
func.out() 	- set/get output
func.out.get()

keyboard.out().a(nextFunc)
keyboard.out("a". nextFunc)
*/
<|endoftext|>


<commit_before>'use strict';

const browsers = [
  'last 1 Chrome versions',
  'last 1 Firefox versions',
  'last 1 Safari versions'
];

const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
  browsers.push('ie 11');
}

module.exports = {
  browsers
};
<commit_msg>refactor: use Boolean constructor to cast CI variable<commit_after>'use strict';

const browsers = [
  'last 1 Chrome versions',
  'last 1 Firefox versions',
  'last 1 Safari versions'
];

const isCI = Boolean(process.env.CI);
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
  browsers.push('ie 11');
}

module.exports = {
  browsers
};
<|endoftext|>