<commit_before>'use strict';
angular.module('core').controller('UtilizationController', ['$scope', 'Authentication', myUtilSql,
	function($scope, Authentication) {
		// This provides Authentication context.
		$scope.authentication = Authentication;

        // Some example string
        $scope.helloText = 'Utilization View';
        $scope.descriptionText = 'This shows the utilization of the resources';

        //Data For Table
        $scope.ngData = [
        {Name: "Moroni", Age: 50, Position: 'PR Menager', Status: 'active', Date: '12.12.2014'},
        {Name: "Teancum", Age: 43, Position: 'CEO/CFO', Status: 'deactive', Date: '10.10.2014'},
        {Name: "Jacob", Age: 27, Position: 'UI Designer', Status: 'active', Date: '09.11.2013'},
        {Name: "Nephi", Age: 29, Position: 'Java programmer', Status: 'deactive', Date: '22.10.2014'},
        {Name: "Joseph", Age: 22, Position: 'Marketing manager', Status: 'active', Date: '24.08.2013'},
        {Name: "Monica", Age: 43, Position: 'President', Status: 'active', Date: '11.12.2014'},
        {Name: "Arnold", Age: 12, Position: 'CEO', Status: 'active', Date: '07.10.2013'},
        {Name: "Mark", Age: 54, Position: 'Analyst', Status: 'deactive', Date: '03.03.2014'},
        {Name: "Amelia", Age: 33, Position: 'Sales manager', Status: 'deactive', Date: '26.09.2013'},
        {Name: "Jesica", Age: 41, Position: 'Ruby programmer', Status: 'active', Date: '22.12.2013'},
        {Name: "John", Age: 48, Position: 'Marketing manager', Status: 'deactive', Date: '09.10.2014'},
        {Name: "Berg", Age: 19, Position: 'UI/UX Designer', Status: 'active', Date: '12.11.2013'}
    ];

    $scope.utilTable = { data: 'ngData' };

        //Data for Line Chart
    var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};
    var options={
        scaleShowGridLines : true,
        scaleGridLineColor : "rgba(0,0,0,.05)",
        scaleGridLineWidth : 1,
        bezierCurve : true,
        bezierCurveTension : 0.4,
        pointDot : true,
        pointDotRadius : 4,
        pointDotStrokeWidth : 1,
        pointHitDetectionRadius : 20,
        datasetStroke : true,
        datasetStrokeWidth : 2,
        datasetFill : true
    };

    var ctx = document.getElementById("myChart").getContext("2d");
    var myLineChart = new Chart(ctx).Line(data, options);

   // Data and options for Polar Chart
    var polarOptions={
    //Boolean - Show a backdrop to the scale label
    scaleShowLabelBackdrop : true,

    //String - The colour of the label backdrop
    scaleBackdropColor : "rgba(255,255,255,0.75)",

    // Boolean - Whether the scale should begin at zero
    scaleBeginAtZero : true,

    //Number - The backdrop padding above & below the label in pixels
    scaleBackdropPaddingY : 2,

    //Number - The backdrop padding to the side of the label in pixels
    scaleBackdropPaddingX : 2,

    //Boolean - Show line for each value in the scale
    scaleShowLine : true,

    //Boolean - Stroke a line around each segment in the chart
    segmentShowStroke : true,

    //String - The colour of the stroke on each segement.
    segmentStrokeColor : "#fff",

    //Number - The width of the stroke value in pixels
    segmentStrokeWidth : 2,

    //Number - Amount of animation steps
    animationSteps : 100,

    //String - Animation easing effect.
    animationEasing : "easeOutBounce",

    //Boolean - Whether to animate the rotation of the chart
    animateRotate : true,

    //Boolean - Whether to animate scaling the chart from the centre
    animateScale : false,

    };
    var polarData = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red"
    },
    {
        value: 50,
        color: "#46BFBD",
        highlight: "#5AD3D1",
        label: "Green"
    },
    {
        value: 100,
        color: "#FDB45C",
        highlight: "#FFC870",
        label: "Yellow"
    },
    {
        value: 40,
        color: "#949FB1",
        highlight: "#A8B3C5",
        label: "Grey"
    },
    {
        value: 120,
        color: "#4D5360",
        highlight: "#616774",
        label: "Dark Grey"
    }

];

        this.polarData = [
        {
            value: 300,
            color:"#a3e1d4",
            highlight: "#1ab394",
            label: "App"
        },
        {
            value: 140,
            color: "#dedede",
            highlight: "#1ab394",
            label: "Software"
        },
        {
            value: 200,
            color: "#A4CEE8",
            highlight: "#1ab394",
            label: "Laptop"
        }
    ];
    var ctx2 = document.getElementById("myPolarChart").getContext("2d");
    var myPolarChart = new Chart(ctx2).PolarArea(polarData, polarOptions);
    /**
     * Options for Polar chart
     */
    this.polarOptions = {
        scaleShowLabelBackdrop : true,
        scaleBackdropColor : "rgba(255,255,255,0.75)",
        scaleBeginAtZero : true,
        scaleBackdropPaddingY : 1,
        scaleBackdropPaddingX : 1,
        scaleShowLine : true,
        segmentShowStroke : true,
        segmentStrokeColor : "#fff",
        segmentStrokeWidth : 2,
        animationSteps : 100,
        animationEasing : "easeOutBounce",
        animateRotate : true,
        animateScale : false
    };

        console.log('invoking myUtilSql get');
		$scope.myUtilSql = myUtilSql.query();
		console.log($scope.myUtilSql);

   	}
]);<commit_msg>charts<commit_after>'use strict';
angular.module('core').controller('UtilizationController', ['$scope', 'Authentication', 'myUtilSql',
	function($scope, Authentication) {
		// This provides Authentication context.
		$scope.authentication = Authentication;

        // Some example string
        $scope.helloText = 'Utilization View';
        $scope.descriptionText = 'This shows the utilization of the resources';

        //Data For Table
        $scope.ngData = [
        {Name: "Moroni", Age: 50, Position: 'PR Menager', Status: 'active', Date: '12.12.2014'},
        {Name: "Teancum", Age: 43, Position: 'CEO/CFO', Status: 'deactive', Date: '10.10.2014'},
        {Name: "Jacob", Age: 27, Position: 'UI Designer', Status: 'active', Date: '09.11.2013'},
        {Name: "Nephi", Age: 29, Position: 'Java programmer', Status: 'deactive', Date: '22.10.2014'},
        {Name: "Joseph", Age: 22, Position: 'Marketing manager', Status: 'active', Date: '24.08.2013'},
        {Name: "Monica", Age: 43, Position: 'President', Status: 'active', Date: '11.12.2014'},
        {Name: "Arnold", Age: 12, Position: 'CEO', Status: 'active', Date: '07.10.2013'},
        {Name: "Mark", Age: 54, Position: 'Analyst', Status: 'deactive', Date: '03.03.2014'},
        {Name: "Amelia", Age: 33, Position: 'Sales manager', Status: 'deactive', Date: '26.09.2013'},
        {Name: "Jesica", Age: 41, Position: 'Ruby programmer', Status: 'active', Date: '22.12.2013'},
        {Name: "John", Age: 48, Position: 'Marketing manager', Status: 'deactive', Date: '09.10.2014'},
        {Name: "Berg", Age: 19, Position: 'UI/UX Designer', Status: 'active', Date: '12.11.2013'}
    ];

    $scope.utilTable = { data: 'ngData' };

        //Data for Line Chart
    var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};
    var options={
        scaleShowGridLines : true,
        scaleGridLineColor : "rgba(0,0,0,.05)",
        scaleGridLineWidth : 1,
        bezierCurve : true,
        bezierCurveTension : 0.4,
        pointDot : true,
        pointDotRadius : 4,
        pointDotStrokeWidth : 1,
        pointHitDetectionRadius : 20,
        datasetStroke : true,
        datasetStrokeWidth : 2,
        datasetFill : true
    };

    var ctx = document.getElementById("myChart").getContext("2d");
    var myLineChart = new Chart(ctx).Line(data, options);

   // Data and options for Polar Chart
    var polarOptions={
    //Boolean - Show a backdrop to the scale label
    scaleShowLabelBackdrop : true,

    //String - The colour of the label backdrop
    scaleBackdropColor : "rgba(255,255,255,0.75)",

    // Boolean - Whether the scale should begin at zero
    scaleBeginAtZero : true,

    //Number - The backdrop padding above & below the label in pixels
    scaleBackdropPaddingY : 2,

    //Number - The backdrop padding to the side of the label in pixels
    scaleBackdropPaddingX : 2,

    //Boolean - Show line for each value in the scale
    scaleShowLine : true,

    //Boolean - Stroke a line around each segment in the chart
    segmentShowStroke : true,

    //String - The colour of the stroke on each segement.
    segmentStrokeColor : "#fff",

    //Number - The width of the stroke value in pixels
    segmentStrokeWidth : 2,

    //Number - Amount of animation steps
    animationSteps : 100,

    //String - Animation easing effect.
    animationEasing : "easeOutBounce",

    //Boolean - Whether to animate the rotation of the chart
    animateRotate : true,

    //Boolean - Whether to animate scaling the chart from the centre
    animateScale : false,

    };
    var polarData = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red"
    },
    {
        value: 50,
        color: "#46BFBD",
        highlight: "#5AD3D1",
        label: "Green"
    },
    {
        value: 100,
        color: "#FDB45C",
        highlight: "#FFC870",
        label: "Yellow"
    },
    {
        value: 40,
        color: "#949FB1",
        highlight: "#A8B3C5",
        label: "Grey"
    },
    {
        value: 120,
        color: "#4D5360",
        highlight: "#616774",
        label: "Dark Grey"
    }

];

        this.polarData = [
        {
            value: 300,
            color:"#a3e1d4",
            highlight: "#1ab394",
            label: "App"
        },
        {
            value: 140,
            color: "#dedede",
            highlight: "#1ab394",
            label: "Software"
        },
        {
            value: 200,
            color: "#A4CEE8",
            highlight: "#1ab394",
            label: "Laptop"
        }
    ];
    var ctx2 = document.getElementById("myPolarChart").getContext("2d");
    var myPolarChart = new Chart(ctx2).PolarArea(polarData, polarOptions);
    /**
     * Options for Polar chart
     */
    this.polarOptions = {
        scaleShowLabelBackdrop : true,
        scaleBackdropColor : "rgba(255,255,255,0.75)",
        scaleBeginAtZero : true,
        scaleBackdropPaddingY : 1,
        scaleBackdropPaddingX : 1,
        scaleShowLine : true,
        segmentShowStroke : true,
        segmentStrokeColor : "#fff",
        segmentStrokeWidth : 2,
        animationSteps : 100,
        animationEasing : "easeOutBounce",
        animateRotate : true,
        animateScale : false
    };

        console.log('invoking myUtilSql get');
		$scope.myUtilSql = myUtilSql.query();
		console.log($scope.myUtilSql);

   	}
]);<|endoftext|>


<commit_before>(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

             '@angular/material': 'npm:@angular/material/bundles/material.umd.js',
             '@angular/cdk': 'npm:@angular/cdk/bundles/cdk.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'hammerjs': 'npm:hammerjs',
            'tslib': 'npm:tslib/tslib.js'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            },
             hammerjs:  {
                main: './hammer.js',
                defaultExtension: 'js'}
        }
    });
})(this);
<commit_msg>material beta 12<commit_after>(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
            '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
            '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',

             //material
            '@angular/material': 'npm:@angular/material/bundles/material.umd.js',
            '@angular/cdk': 'npm:@angular/cdk/bundles/cdk.umd.js',
            '@angular/cdk/a11y': 'npm:@angular/cdk/bundles/cdk-a11y.umd.js',
            '@angular/cdk/bidi': 'npm:@angular/cdk/bundles/cdk-bidi.umd.js',
            '@angular/cdk/coercion': 'npm:@angular/cdk/bundles/cdk-coercion.umd.js',
            '@angular/cdk/collections': 'npm:@angular/cdk/bundles/cdk-collections.umd.js',
            '@angular/cdk/keycodes': 'npm:@angular/cdk/bundles/cdk-keycodes.umd.js',
            '@angular/cdk/observers': 'npm:@angular/cdk/bundles/cdk-observers.umd.js',
            '@angular/cdk/overlay': 'npm:@angular/cdk/bundles/cdk-overlay.umd.js',
            '@angular/cdk/platform': 'npm:@angular/cdk/bundles/cdk-platform.umd.js',
            '@angular/cdk/portal': 'npm:@angular/cdk/bundles/cdk-portal.umd.js',
            '@angular/cdk/rxjs': 'npm:@angular/cdk/bundles/cdk-rxjs.umd.js',
            '@angular/cdk/scrolling': 'npm:@angular/cdk/bundles/cdk-scrolling.umd.js',
            '@angular/cdk/table': 'npm:@angular/cdk/bundles/cdk-table.umd.js',
            '@angular/cdk/stepper': 'npm:@angular/cdk/bundles/cdk-stepper.umd.js',

            // other libraries
            'rxjs': 'npm:rxjs',
            'hammerjs': 'npm:hammerjs',
            'tslib': 'npm:tslib/tslib.js'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            },
             hammerjs:  {
                main: './hammer.js',
                defaultExtension: 'js'}
        }
    });
})(this);
<|endoftext|>


<commit_before>Polymer({
    is: 'editor-unit-input',

    behaviors: [EditorUI.focusable, Polymer.IronValidatableBehavior],

    listeners: {
        'keyup': '_onKeyUp',
    },

    properties: {
        invalid: {
            type: Boolean,
            value: false
        },

        value: {
            type: Number,
            notify: true,
            value: 0,
            observer: 'valueChanged',
        },

        _inputValue: {
            type: String,
            notify: true,
            value: '0',
        },

        inputValue: {
            type: Number,
            notify: true,
            value: 0,
            observer: 'inputValueChanged',
        },

        step: {
            type: Number,
            notify: true,
            value: 1,
        },

        min: {
            type: Number,
            notify: true,
            value: null,
        },

        max: {
            type: Number,
            notify: true,
            value: null,
        }
    },

    created: function () {
        this.lastTrueValue = 0;
    },

    ready: function () {
        this._initFocusable(this.$.input);
        this._updateMinMax();
    },

    attached: function () {
        this.value = this.inputValue = this._convert(this._inputValue);
    },

    _updateMinMax: function () {
        this._min = (this.min!==null) ? parseFloat(this.min) : -Number.MAX_VALUE;
        this._max = (this.max!==null) ? parseFloat(this.max) : Number.MAX_VALUE;
    },

    inputValueChanged: function () {
        this._inputValue = this.inputValue.toString();
        this.fire('input-changed');
    },

    valueChanged: function () {
        this.value = this._convert(this.value);
        this._inputValue = this._convert(this.value).toString();
    },

    confirm: function () {
        this.value = this._convert(this._inputValue);
        this.inputValue = this._convert(this._inputValue);
        this._inputValue = this.value.toString();
    },

    cancel: function() {
        this._inputValue = this.value.toString();
    },

    _onKeyDown: function (event) {
        // keydown 'enter'
        if (event.keyCode === 13) {
            if (this.value !== this._inputValue) {
                this.confirm();
            }
            this.setBlur();
            EditorUI.focusParent(this);
        }
        // keydown 'esc'
        else if (event.keyCode === 27) {
            this.cancel();
            this.setBlur();
            EditorUI.focusParent(this);
        }
        // keydown 'up'
        else if (event.keyCode === 38) {
            event.preventDefault();
            this._stepUp();
        }
        // keydown 'down'
        else if (event.keyCode === 40) {
            event.preventDefault();
            this._stepDown();
        }
    },

    _onKeyUp: function (event) {
        if (event.keyCode === 38 || event.keyCode === 40) {
            this.confirm();
            this.fire('changed');
        }
    },

    _stepUp: function () {
        if (this._nullToFloat(this._inputValue) + this.step >= this._max) {
            this._inputValue = this._max;
        }
        else {
            this._inputValue = this._nullToFloat(this._inputValue) + this.step;
        }
    },

    _stepDown: function () {
        if (this._nullToFloat(this._inputValue) - this.step <= this._min) {
            this._inputValue = this._min;
        }else {
            this._inputValue = this._nullToFloat(this._inputValue) - this.step;
        }
    },

    _increase: function (event) {
        this.timeoutID = setTimeout( function () {
            this.holdingID = setInterval( function () {
                this._stepUp();
            }.bind(this), 50);
        }.bind(this), 500 );
    },

    _decrease: function (event) {
        this.timeoutID = setTimeout( function () {
            this.holdingID = setInterval( function () {
                this._stepDown();
            }.bind(this), 50);
        }.bind(this), 500 );
    },

    _stopRoll: function () {
        clearInterval(this.holdingID);
        this.holdingID = null;

        clearTimeout(this.timeoutID);
        this.timeoutID = null;

        setTimeout(function() {
            this.confirm();
            this.fire('changed');
        }.bind(this), 1);
    },

    _convert: function ( val ) {
        if (val === '' || isNaN(val)) {
            return this.lastTrueValue;
        }
        val = parseFloat(parseFloat(val));
        if ( isNaN(val) )
            val = 0;
        if (this._min && this._max) {
            val = Math.min( Math.max( val, this._min ), this._max );
        }
        this.lastTrueValue = val;
        return val;
    },

    _nullToFloat: function (val) {
        if (!val) {
            return 0;
        }
        if ( isNaN(val) )
            return 0;
        return parseFloat(val);
    },

    _onBindValueChanged: function () {
        if (this.inputValue === this._convert(this._inputValue)) {
            this.fire('input-changed');
            return;
        }
        this.inputValue = this._convert(this._inputValue);
    },

    _onChange: function () {
        this.confirm();
        this.fire('changed');
    },

});
<commit_msg>add press up and down reset<commit_after>Polymer({
    is: 'editor-unit-input',

    behaviors: [EditorUI.focusable, Polymer.IronValidatableBehavior],

    properties: {
        invalid: {
            type: Boolean,
            value: false
        },

        value: {
            type: Number,
            notify: true,
            value: 0,
            observer: 'valueChanged',
        },

        _inputValue: {
            type: String,
            notify: true,
            value: '0',
        },

        inputValue: {
            type: Number,
            notify: true,
            value: 0,
            observer: 'inputValueChanged',
        },

        step: {
            type: Number,
            notify: true,
            value: 1,
        },

        min: {
            type: Number,
            notify: true,
            value: null,
        },

        max: {
            type: Number,
            notify: true,
            value: null,
        }
    },

    created: function () {
        this.lastTrueValue = 0;
    },

    ready: function () {
        this._initFocusable(this.$.input);
        this._updateMinMax();
    },

    attached: function () {
        this.value = this.inputValue = this._convert(this._inputValue);
    },

    _updateMinMax: function () {
        this._min = (this.min!==null) ? parseFloat(this.min) : -Number.MAX_VALUE;
        this._max = (this.max!==null) ? parseFloat(this.max) : Number.MAX_VALUE;
    },

    inputValueChanged: function () {
        this._inputValue = this.inputValue.toString();
        this.fire('input-changed');
    },

    valueChanged: function () {
        this.value = this._convert(this.value);
        this._inputValue = this._convert(this.value).toString();
    },

    confirm: function () {
        this.value = this._convert(this._inputValue);
        this.inputValue = this._convert(this._inputValue);
        this._inputValue = this.value.toString();
    },

    cancel: function() {
        this._inputValue = this.value.toString();
        this.fire('changed');
    },

    _onKeyDown: function (event) {
        // keydown 'enter'
        if (event.keyCode === 13) {
            if (this.value !== this._inputValue) {
                this.confirm();
            }
            this.setBlur();
            EditorUI.focusParent(this);
        }
        // keydown 'esc'
        else if (event.keyCode === 27) {
            this.cancel();
            this.setBlur();
            EditorUI.focusParent(this);
        }
        // keydown 'up'
        else if (event.keyCode === 38) {
            event.preventDefault();
            this._stepUp();
        }
        // keydown 'down'
        else if (event.keyCode === 40) {
            event.preventDefault();
            this._stepDown();
        }
    },

    _stepUp: function () {
        if (this._nullToFloat(this._inputValue) + this.step >= this._max) {
            this._inputValue = this._max;
        }
        else {
            this._inputValue = this._nullToFloat(this._inputValue) + this.step;
        }
    },

    _stepDown: function () {
        if (this._nullToFloat(this._inputValue) - this.step <= this._min) {
            this._inputValue = this._min;
        }
        else {
            this._inputValue = this._nullToFloat(this._inputValue) - this.step;
        }
    },

    _increase: function (event) {
        this.timeoutID = setTimeout( function () {
            this.holdingID = setInterval( function () {
                this._stepUp();
            }.bind(this), 50);
        }.bind(this), 500 );
    },

    _decrease: function (event) {
        this.timeoutID = setTimeout( function () {
            this.holdingID = setInterval( function () {
                this._stepDown();
            }.bind(this), 50);
        }.bind(this), 500 );
    },

    _stopRoll: function () {
        clearInterval(this.holdingID);
        this.holdingID = null;

        clearTimeout(this.timeoutID);
        this.timeoutID = null;

        setTimeout(function() {
            this.confirm();
            this.fire('changed');
        }.bind(this), 1);
    },

    _convert: function ( val ) {
        if (val === '' || isNaN(val)) {
            return this.lastTrueValue;
        }
        val = parseFloat(parseFloat(val));
        if ( isNaN(val) )
            val = 0;
        if (this._min && this._max) {
            val = Math.min( Math.max( val, this._min ), this._max );
        }
        this.lastTrueValue = val;
        return val;
    },

    _nullToFloat: function (val) {
        if (!val) {
            return 0;
        }
        if ( isNaN(val) )
            return 0;
        return parseFloat(val);
    },

    _onBindValueChanged: function () {
        if (this.inputValue === this._convert(this._inputValue)) {

            return;
        }
        this.inputValue = this._convert(this._inputValue);
    },

    _onChange: function () {
        this.confirm();
        this.fire('changed');
    },

});
<|endoftext|>


<commit_before>var directional_hotkeys = {
    40: get_next_visible,  // down arrow
    38: get_prev_visible,  // up arrow
    36: get_first_visible, // Home
    35: get_last_visible   // End
};

function simulate_keypress(keycode) {
    $(document).trigger($.Event('keydown', {keyCode: keycode}));
}

function above_view(zephyr) {
    return zephyr.offset().top < $("#main_div").offset().top;
}

function below_view(zephyr) {
    var main_div = $("#main_div");
    return zephyr.offset().top + zephyr.height() > main_div.offset().top + main_div.height();
}

function keep_pointer_in_view() {
    var next_zephyr = get_zephyr_row(selected_zephyr_id);
    if (above_view(next_zephyr)) {
        while (above_view(next_zephyr)) {
            next_zephyr = get_next_visible(next_zephyr);
        }
    } else if (below_view(next_zephyr)) {
        while (below_view(next_zephyr)) {
            next_zephyr = get_prev_visible(next_zephyr);
        }
    }
    update_selected_zephyr(next_zephyr);
}

function process_hotkey(code) {
    var next_zephyr, window_to_scroll;
    if (code in directional_hotkeys) {
        next_zephyr = directional_hotkeys[code](selected_zephyr);
        if (next_zephyr.length !== 0) {
            select_zephyr(next_zephyr, true);
        }
        if ((next_zephyr.length === 0) && (code === 40)) {
            // At the last zephyr, scroll to the bottom so we have
            // lots of nice whitespace for new zephyrs coming in.
            //
            // FIXME: this doesn't work for End because get_last_visible()
            // always returns a zephyr.
            $("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
        }
        return process_hotkey;
    }

    window_to_scroll = $(".active.scrolling_tab");
    if (window_to_scroll.length === 0) {
        window_to_scroll = $(".active").find(".scrolling-tab");
    }

    switch (code) {
    case 33: // Page Up
        window_to_scroll.scrollTop(window_to_scroll.scrollTop() - window_to_scroll.height());
        keep_pointer_in_view();
        return process_hotkey;
    case 34: // Page Down
        window_to_scroll.scrollTop(window_to_scroll.scrollTop() + window_to_scroll.height());
        keep_pointer_in_view();
        return process_hotkey;
    case 27: // Esc: hide compose pane
        hide_compose();
        return process_hotkey;
    case 67: // 'c': compose
        compose_button();
        return process_compose_hotkey;
    case 82: // 'r': respond to zephyr
        respond_to_zephyr();
        return process_key_in_input;

    case 71: // 'g': start of "go to" command
        return process_goto_hotkey;
    }

    return false;
}

var goto_hotkeys = {
    67: narrow_by_recipient,  // 'c'
    73: narrow_instance,      // 'i'
    80: narrow_all_personals, // 'p'
    65: show_all_messages,    // 'a'
    27: hide_compose          // Esc
};

function process_goto_hotkey(code) {
    if (code in goto_hotkeys)
        goto_hotkeys[code]();

    /* Always return to the initial hotkey mode, even
       with an unrecognized "go to" command. */
    return process_hotkey;
}

function process_key_in_input(code) {
    if (code === 27) {
        // User hit Escape key
        hide_compose();
        return process_hotkey;
    }
    return false;
}

function process_compose_hotkey(code) {
    if (code === 9) { // Tab: toggle between class and huddle compose tabs.
        toggle_compose();
        return process_compose_hotkey;
    } else {
        keydown_handler = process_key_in_input;
        simulate_keypress(code);
    }
}

/* The current handler function for keydown events.
   It should return a new handler, or 'false' to
   decline to handle the event. */
var keydown_handler = process_hotkey;

$(document).keydown(function (event) {
    var result = keydown_handler(event.keyCode);
    if (typeof result === 'function') {
        keydown_handler = result;
        event.preventDefault();
    }
});
<commit_msg>Enable j/k keyboard shortcuts<commit_after>var directional_hotkeys = {
    40: get_next_visible,  // down arrow
    74: get_next_visible,  // 'j'
    38: get_prev_visible,  // up arrow
    75: get_prev_visible,  // 'k'
    36: get_first_visible, // Home
    35: get_last_visible   // End
};

function simulate_keypress(keycode) {
    $(document).trigger($.Event('keydown', {keyCode: keycode}));
}

function above_view(zephyr) {
    return zephyr.offset().top < $("#main_div").offset().top;
}

function below_view(zephyr) {
    var main_div = $("#main_div");
    return zephyr.offset().top + zephyr.height() > main_div.offset().top + main_div.height();
}

function keep_pointer_in_view() {
    var next_zephyr = get_zephyr_row(selected_zephyr_id);
    if (above_view(next_zephyr)) {
        while (above_view(next_zephyr)) {
            next_zephyr = get_next_visible(next_zephyr);
        }
    } else if (below_view(next_zephyr)) {
        while (below_view(next_zephyr)) {
            next_zephyr = get_prev_visible(next_zephyr);
        }
    }
    update_selected_zephyr(next_zephyr);
}

function process_hotkey(code) {
    var next_zephyr, window_to_scroll;
    if (code in directional_hotkeys) {
        next_zephyr = directional_hotkeys[code](selected_zephyr);
        if (next_zephyr.length !== 0) {
            select_zephyr(next_zephyr, true);
        }
        if ((next_zephyr.length === 0) && (code === 40)) {
            // At the last zephyr, scroll to the bottom so we have
            // lots of nice whitespace for new zephyrs coming in.
            //
            // FIXME: this doesn't work for End because get_last_visible()
            // always returns a zephyr.
            $("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
        }
        return process_hotkey;
    }

    window_to_scroll = $(".active.scrolling_tab");
    if (window_to_scroll.length === 0) {
        window_to_scroll = $(".active").find(".scrolling-tab");
    }

    switch (code) {
    case 33: // Page Up
        window_to_scroll.scrollTop(window_to_scroll.scrollTop() - window_to_scroll.height());
        keep_pointer_in_view();
        return process_hotkey;
    case 34: // Page Down
        window_to_scroll.scrollTop(window_to_scroll.scrollTop() + window_to_scroll.height());
        keep_pointer_in_view();
        return process_hotkey;
    case 27: // Esc: hide compose pane
        hide_compose();
        return process_hotkey;
    case 67: // 'c': compose
        compose_button();
        return process_compose_hotkey;
    case 82: // 'r': respond to zephyr
        respond_to_zephyr();
        return process_key_in_input;

    case 71: // 'g': start of "go to" command
        return process_goto_hotkey;
    }

    return false;
}

var goto_hotkeys = {
    67: narrow_by_recipient,  // 'c'
    73: narrow_instance,      // 'i'
    80: narrow_all_personals, // 'p'
    65: show_all_messages,    // 'a'
    27: hide_compose          // Esc
};

function process_goto_hotkey(code) {
    if (code in goto_hotkeys)
        goto_hotkeys[code]();

    /* Always return to the initial hotkey mode, even
       with an unrecognized "go to" command. */
    return process_hotkey;
}

function process_key_in_input(code) {
    if (code === 27) {
        // User hit Escape key
        hide_compose();
        return process_hotkey;
    }
    return false;
}

function process_compose_hotkey(code) {
    if (code === 9) { // Tab: toggle between class and huddle compose tabs.
        toggle_compose();
        return process_compose_hotkey;
    } else {
        keydown_handler = process_key_in_input;
        simulate_keypress(code);
    }
}

/* The current handler function for keydown events.
   It should return a new handler, or 'false' to
   decline to handle the event. */
var keydown_handler = process_hotkey;

$(document).keydown(function (event) {
    var result = keydown_handler(event.keyCode);
    if (typeof result === 'function') {
        keydown_handler = result;
        event.preventDefault();
    }
});
<|endoftext|>


<commit_before>var search = (function () {

var exports = {};

var cached_term = "";
var cached_matches = [];
var cached_index;
var cached_table = $('table.focused_table');
var current_search_term;

// Data storage for the typeahead -- to go from object to string representation and vice versa.
var search_object = {};

function phrase_match(phrase, q) {
    // match "tes" to "test" and "stream test" but not "hostess"
    var i;
    q = q.toLowerCase();

    var parts = phrase.split(' ');
    for (i = 0; i < parts.length; i++) {
        if (parts[i].toLowerCase().indexOf(q) === 0) {
            return true;
        }
    }
    return false;
}

function person_matches_query(person, q) {
    return phrase_match(person.full_name, q) || phrase_match(person.email, q);
}

function stream_matches_query(stream_name, q) {
    return phrase_match(stream_name, q);
}

// Convert a list of operators to a human-readable description.
function describe(operators) {
    return $.map(operators, function (elem) {
        var operand = elem[1];
        switch (narrow.canonicalize_operator(elem[0])) {
        case 'is':
            if (operand === 'private') {
                return 'Narrow to all private messages';
            } else if (operand === 'starred') {
                return 'Narrow to starred messages';
            } else if (operand === 'mentioned') {
                return 'Narrow to mentioned messages';
            }
            break;

        case 'stream':
            return 'Narrow to stream ' + operand;

        case 'topic':
            return 'Narrow to topic ' + operand;

        case 'sender':
            return 'Narrow to sender ' + operand;

        case 'pm-with':
            return 'Narrow to private messages with ' + operand;

        case 'search':
            return 'Search for ' + operand;

        case 'in':
            return 'Narrow to messages in ' + operand;
        }
        return 'Narrow to (unknown operator)';
    }).join(', ');
}

function narrow_or_search_for_term(item) {
    var search_query_box = $("#search_query");
    var obj = search_object[item];
    ui.change_tab_to('#home');
    var operators = narrow.parse(obj.search_string);
    narrow.activate(operators, {trigger: 'search'});

    // It's sort of annoying that this is not in a position to
    // blur the search box, because it means that Esc won't
    // unnarrow, it'll leave the searchbox.

    // Narrowing will have already put some operators in the search box,
    // so leave the current text in.
    search_query_box.blur();
    return search_query_box.val();
}

function update_buttons_with_focus(focused) {
    var search_query = $('#search_query');

    // Show buttons iff the search input is focused, or has non-empty contents,
    // or we are narrowed.
    if (focused
        || search_query.val()
        || narrow.active()) {
        $('.search_button').removeAttr('disabled');
    } else {
        $('.search_button').attr('disabled', 'disabled');
    }
}

exports.update_button_visibility = function () {
    update_buttons_with_focus($('#search_query').is(':focus'));
};

function highlight_person(query, person) {
    var hilite = typeahead_helper.highlight_query_in_phrase;
    return hilite(query, person.full_name) + " <" + hilite(query, person.email) + ">";
}

function get_stream_suggestions(query, max_num) {
    var streams = subs.subscribed_streams();

    streams = $.grep(streams, function (stream) {
        return stream_matches_query(stream, query);
    });

    streams = typeahead_helper.sorter(query, streams);
    streams = streams.slice(0, max_num);

    var objs = $.map(streams, function (stream) {
        var prefix = 'Narrow to stream';
        var highlighted_stream = typeahead_helper.highlight_query_in_phrase(query, stream);
        var description = prefix + ' ' + highlighted_stream;
        var search_string = narrow.unparse([['stream', stream]]);
        return {description: description, search_string: search_string};
    });

    return objs;
}

function get_person_suggestions(all_people, query, prefix, operator, max_num) {
    var people = $.grep(all_people, function (person) {
        return person_matches_query(person, query);
    });

    people.sort(typeahead_helper.compare_by_pms);
    people = people.slice(0, max_num);

    var objs = $.map(people, function (person) {
        var name = highlight_person(query, person);
        var description = prefix + ' ' + name;
        var search_string = operator + ':' + person.email;
        return {description: description, search_string: search_string};
    });

    return objs;
}

function get_suggestion_based_on_query(search_string, operators) {
    // We expect caller to call narrow.parse to get operators from search_string.
    var description = describe(operators);
    description = Handlebars.Utils.escapeExpression(description);
    return {description: description, search_string: search_string};
}

function get_topic_suggestions(query, query_operators, max_num) {
    if (query_operators.length === 0) {
        return [];
    }

    var last_term = query_operators.slice(-1)[0];
    var operator = narrow.canonicalize_operator(last_term[0]);
    var operand = last_term[1];
    var stream;
    var guess;

    // stream:Rome -> show all Rome topics
    // stream:Rome topic: -> show all Rome topics
    // stream:Rome f -> show all Rome topics with a word starting in f
    // stream:Rome topic:f -> show all Rome topics with a word starting in f
    // stream:Rome topic:f -> show all Rome topics with a word starting in f

    // When narrowed to a stream:
    //   topic: -> show all topics in current stream
    //   foo -> show all topics in current stream with words starting with foo

    // If somebody explicitly types search:, then we might
    // not want to suggest topics, but I feel this is a very
    // minor issue, and narrow.parse() is currently lossy
    // in terms of telling us whether they provided the operator,
    // i.e. "foo" and "search:foo" both become [['search', 'foo']].
    switch (operator) {
    case 'stream':
        guess = '';
        stream = operand;
        break;
    case 'topic':
    case 'search':
        guess = operand;
        query_operators = query_operators.slice(0, -1);
        var filter = new narrow.Filter(query_operators);
        if (filter.has_operator('topic')) {
            return [];
        }
        if (filter.has_operator('stream')) {
            stream = filter.operands('stream')[0];
        } else {
            stream = narrow.stream();
            query_operators.push(['stream', stream]);
        }
        break;
    default:
        return [];
    }

    if (!stream) {
        return [];
    }

    stream = subs.canonicalized_name(stream);

    var topics = recent_subjects[stream];

    if (!topics) {
        return [];
    }

    // Be defensive here in case recent_subjects gets super huge, but
    // still slice off enough topics to find matches.
    topics = topics.slice(0, 100);

    // topics = $.map(topics, (t) -> t.subject)
    topics = $.map(topics, function (topic) {
        return topic.subject; // "subject" is just the name of the topic
    });

    if (guess !== '') {
        topics = $.grep(topics, function (topic) {
            // Don't suggest a topic if the user has already typed out
            // the full topic name.
            var redundant = topic.toLowerCase() === guess.toLowerCase();
            if (redundant) {
                return false;
            }
            return phrase_match(topic, guess);
        });
    }

    topics = topics.slice(0, max_num);

    // Just use alphabetical order.  While recency and read/unreadness of
    // subjects do matter in some contexts, you can get that from the left sidebar,
    // and I'm leaning toward high scannability for autocompletion.  I also don't
    // care about case.
    topics.sort();

    return $.map(topics, function (topic) {
        var topic_operator = ['topic', topic];
        var operators = query_operators.concat([topic_operator]);
        var search_string = narrow.unparse(operators);
        var description = describe(operators);
        return {description: description, search_string: search_string};
    });
}

exports.initialize = function () {
    $( "#search_query" ).typeahead({
        source: function (query, process) {
            var result = [];
            var suggestion;
            var suggestions;

            // Add an entry for narrow by operators.
            var operators = narrow.parse(query);
            if (operators.length !== 0) {
                suggestion = get_suggestion_based_on_query(query, operators);
                result = [suggestion];
            } else {
                return [];
            }

            suggestions = get_stream_suggestions(query, 4);
            result = result.concat(suggestions);

            var people = page_params.people_list;

            suggestions = get_person_suggestions(people, query, 'Narrow to private messages with', 'pm-with', 4);
            result = result.concat(suggestions);

            suggestions = get_person_suggestions(people, query, 'Narrow to messages sent by', 'sender', 4);
            result = result.concat(suggestions);

            suggestions = get_topic_suggestions(query, operators, 15);
            result = result.concat(suggestions);

            // We can't send typeahead objects, only strings.
            search_object = {};
            $.each(result, function (idx, obj) {
                search_object[obj.search_string] = obj;
            });
            return $.map(result, function (obj) {
                return obj.search_string;
            });
        },
        items: 50,
        highlighter: function (item) {
            var obj = search_object[item];
            return obj.description;
        },
        matcher: function (item) {
            return true;
        },
        updater: narrow_or_search_for_term,
        sorter: function (items) {
            return items;
        },
        smartSpaceBar: true
    });

    $("#searchbox_form").keydown(function (e) {
        exports.update_button_visibility();
        var code = e.which;
        var search_query_box = $("#search_query");
        if (code === 13 && search_query_box.is(":focus")) {
            // Don't submit the form so that the typeahead can instead
            // handle our Enter keypress. Any searching that needs
            // to be done will be handled in the keyup.
            e.preventDefault();
            return false;
        }
    }).keyup(function (e) {
        var code = e.which;
        var search_query_box = $("#search_query");
        if (code === 13 && search_query_box.is(":focus")) {
            // We just pressed enter and the box had focus, which
            // means we didn't use the typeahead at all.  In that
            // case, we should act as though we're searching by
            // operators.  (The reason the other actions don't call
            // this codepath is that they first all blur the box to
            // indicate that they've done what they need to do)
            if (search_query_box.val().trim()) {
                narrow.activate(narrow.parse(search_query_box.val()));
            }
            search_query_box.blur();
            update_buttons_with_focus(false);
        }
    });

    // Some of these functions don't actually need to be exported,
    // but the code was moved here from elsewhere, and it would be
    // more work to re-order everything and make them private.
    $('#search_exit' ).on('click', exports.clear_search);

    var query = $('#search_query');
    query.on('focus', exports.focus_search)
         .on('blur' , function () {

        // The search query box is a visual cue as to
        // whether search or narrowing is active.  If
        // neither is active, we should clear the box on
        // blur.
        //
        // But we can't do this right away, because
        // selecting something in the typeahead menu causes
        // the box to lose focus a moment before.  We would
        // clear the thing we're about to search for.
        //
        // The workaround is to check 100ms later -- long
        // enough for the search to have gone through, but
        // short enough that the user won't notice (though
        // really it would be OK if they did).

        setTimeout(function () {
            if (!(narrow.active())) {
                query.val('');
            }
            exports.update_button_visibility();
        }, 100);
    });
};

function match_on_visible_text(row, search_term) {
    // You can't select on :visible, since that includes hidden elements that
    // take up space.
    return row.find(".message_content, .message_header")
              .text().toLowerCase().indexOf(search_term) !== -1;
}

exports.focus_search = function () {
    // The search bar is not focused yet, but will be.
    update_buttons_with_focus(true);
};

exports.initiate_search = function () {
    $('#search_query').select();
};

exports.clear_search = function () {
    narrow.deactivate();

    $('table tr').removeHighlight();
    $('#search_query').blur();
    exports.update_button_visibility();
};

return exports;

}());
<commit_msg>(search) Don't show topic suggestions when a topic is already entered.<commit_after>var search = (function () {

var exports = {};

var cached_term = "";
var cached_matches = [];
var cached_index;
var cached_table = $('table.focused_table');
var current_search_term;

// Data storage for the typeahead -- to go from object to string representation and vice versa.
var search_object = {};

function phrase_match(phrase, q) {
    // match "tes" to "test" and "stream test" but not "hostess"
    var i;
    q = q.toLowerCase();

    var parts = phrase.split(' ');
    for (i = 0; i < parts.length; i++) {
        if (parts[i].toLowerCase().indexOf(q) === 0) {
            return true;
        }
    }
    return false;
}

function person_matches_query(person, q) {
    return phrase_match(person.full_name, q) || phrase_match(person.email, q);
}

function stream_matches_query(stream_name, q) {
    return phrase_match(stream_name, q);
}

// Convert a list of operators to a human-readable description.
function describe(operators) {
    return $.map(operators, function (elem) {
        var operand = elem[1];
        switch (narrow.canonicalize_operator(elem[0])) {
        case 'is':
            if (operand === 'private') {
                return 'Narrow to all private messages';
            } else if (operand === 'starred') {
                return 'Narrow to starred messages';
            } else if (operand === 'mentioned') {
                return 'Narrow to mentioned messages';
            }
            break;

        case 'stream':
            return 'Narrow to stream ' + operand;

        case 'topic':
            return 'Narrow to topic ' + operand;

        case 'sender':
            return 'Narrow to sender ' + operand;

        case 'pm-with':
            return 'Narrow to private messages with ' + operand;

        case 'search':
            return 'Search for ' + operand;

        case 'in':
            return 'Narrow to messages in ' + operand;
        }
        return 'Narrow to (unknown operator)';
    }).join(', ');
}

function narrow_or_search_for_term(item) {
    var search_query_box = $("#search_query");
    var obj = search_object[item];
    ui.change_tab_to('#home');
    var operators = narrow.parse(obj.search_string);
    narrow.activate(operators, {trigger: 'search'});

    // It's sort of annoying that this is not in a position to
    // blur the search box, because it means that Esc won't
    // unnarrow, it'll leave the searchbox.

    // Narrowing will have already put some operators in the search box,
    // so leave the current text in.
    search_query_box.blur();
    return search_query_box.val();
}

function update_buttons_with_focus(focused) {
    var search_query = $('#search_query');

    // Show buttons iff the search input is focused, or has non-empty contents,
    // or we are narrowed.
    if (focused
        || search_query.val()
        || narrow.active()) {
        $('.search_button').removeAttr('disabled');
    } else {
        $('.search_button').attr('disabled', 'disabled');
    }
}

exports.update_button_visibility = function () {
    update_buttons_with_focus($('#search_query').is(':focus'));
};

function highlight_person(query, person) {
    var hilite = typeahead_helper.highlight_query_in_phrase;
    return hilite(query, person.full_name) + " <" + hilite(query, person.email) + ">";
}

function get_stream_suggestions(query, max_num) {
    var streams = subs.subscribed_streams();

    streams = $.grep(streams, function (stream) {
        return stream_matches_query(stream, query);
    });

    streams = typeahead_helper.sorter(query, streams);
    streams = streams.slice(0, max_num);

    var objs = $.map(streams, function (stream) {
        var prefix = 'Narrow to stream';
        var highlighted_stream = typeahead_helper.highlight_query_in_phrase(query, stream);
        var description = prefix + ' ' + highlighted_stream;
        var search_string = narrow.unparse([['stream', stream]]);
        return {description: description, search_string: search_string};
    });

    return objs;
}

function get_person_suggestions(all_people, query, prefix, operator, max_num) {
    var people = $.grep(all_people, function (person) {
        return person_matches_query(person, query);
    });

    people.sort(typeahead_helper.compare_by_pms);
    people = people.slice(0, max_num);

    var objs = $.map(people, function (person) {
        var name = highlight_person(query, person);
        var description = prefix + ' ' + name;
        var search_string = operator + ':' + person.email;
        return {description: description, search_string: search_string};
    });

    return objs;
}

function get_suggestion_based_on_query(search_string, operators) {
    // We expect caller to call narrow.parse to get operators from search_string.
    var description = describe(operators);
    description = Handlebars.Utils.escapeExpression(description);
    return {description: description, search_string: search_string};
}

function get_topic_suggestions(query, query_operators, max_num) {
    if (query_operators.length === 0) {
        return [];
    }

    var last_term = query_operators.slice(-1)[0];
    var operator = narrow.canonicalize_operator(last_term[0]);
    var operand = last_term[1];
    var stream;
    var guess;
    var filter;

    // stream:Rome -> show all Rome topics
    // stream:Rome topic: -> show all Rome topics
    // stream:Rome f -> show all Rome topics with a word starting in f
    // stream:Rome topic:f -> show all Rome topics with a word starting in f
    // stream:Rome topic:f -> show all Rome topics with a word starting in f

    // When narrowed to a stream:
    //   topic: -> show all topics in current stream
    //   foo -> show all topics in current stream with words starting with foo

    // If somebody explicitly types search:, then we might
    // not want to suggest topics, but I feel this is a very
    // minor issue, and narrow.parse() is currently lossy
    // in terms of telling us whether they provided the operator,
    // i.e. "foo" and "search:foo" both become [['search', 'foo']].
    switch (operator) {
    case 'stream':
        filter = new narrow.Filter(query_operators);
        if (filter.has_operator('topic')) {
            return [];
        }
        guess = '';
        stream = operand;
        break;
    case 'topic':
    case 'search':
        guess = operand;
        query_operators = query_operators.slice(0, -1);
        filter = new narrow.Filter(query_operators);
        if (filter.has_operator('topic')) {
            return [];
        }
        if (filter.has_operator('stream')) {
            stream = filter.operands('stream')[0];
        } else {
            stream = narrow.stream();
            query_operators.push(['stream', stream]);
        }
        break;
    default:
        return [];
    }

    if (!stream) {
        return [];
    }

    stream = subs.canonicalized_name(stream);

    var topics = recent_subjects[stream];

    if (!topics) {
        return [];
    }

    // Be defensive here in case recent_subjects gets super huge, but
    // still slice off enough topics to find matches.
    topics = topics.slice(0, 100);

    // topics = $.map(topics, (t) -> t.subject)
    topics = $.map(topics, function (topic) {
        return topic.subject; // "subject" is just the name of the topic
    });

    if (guess !== '') {
        topics = $.grep(topics, function (topic) {
            // Don't suggest a topic if the user has already typed out
            // the full topic name.
            var redundant = topic.toLowerCase() === guess.toLowerCase();
            if (redundant) {
                return false;
            }
            return phrase_match(topic, guess);
        });
    }

    topics = topics.slice(0, max_num);

    // Just use alphabetical order.  While recency and read/unreadness of
    // subjects do matter in some contexts, you can get that from the left sidebar,
    // and I'm leaning toward high scannability for autocompletion.  I also don't
    // care about case.
    topics.sort();

    return $.map(topics, function (topic) {
        var topic_operator = ['topic', topic];
        var operators = query_operators.concat([topic_operator]);
        var search_string = narrow.unparse(operators);
        var description = describe(operators);
        return {description: description, search_string: search_string};
    });
}

exports.initialize = function () {
    $( "#search_query" ).typeahead({
        source: function (query, process) {
            var result = [];
            var suggestion;
            var suggestions;

            // Add an entry for narrow by operators.
            var operators = narrow.parse(query);
            if (operators.length !== 0) {
                suggestion = get_suggestion_based_on_query(query, operators);
                result = [suggestion];
            } else {
                return [];
            }

            suggestions = get_stream_suggestions(query, 4);
            result = result.concat(suggestions);

            var people = page_params.people_list;

            suggestions = get_person_suggestions(people, query, 'Narrow to private messages with', 'pm-with', 4);
            result = result.concat(suggestions);

            suggestions = get_person_suggestions(people, query, 'Narrow to messages sent by', 'sender', 4);
            result = result.concat(suggestions);

            suggestions = get_topic_suggestions(query, operators, 15);
            result = result.concat(suggestions);

            // We can't send typeahead objects, only strings.
            search_object = {};
            $.each(result, function (idx, obj) {
                search_object[obj.search_string] = obj;
            });
            return $.map(result, function (obj) {
                return obj.search_string;
            });
        },
        items: 50,
        highlighter: function (item) {
            var obj = search_object[item];
            return obj.description;
        },
        matcher: function (item) {
            return true;
        },
        updater: narrow_or_search_for_term,
        sorter: function (items) {
            return items;
        },
        smartSpaceBar: true
    });

    $("#searchbox_form").keydown(function (e) {
        exports.update_button_visibility();
        var code = e.which;
        var search_query_box = $("#search_query");
        if (code === 13 && search_query_box.is(":focus")) {
            // Don't submit the form so that the typeahead can instead
            // handle our Enter keypress. Any searching that needs
            // to be done will be handled in the keyup.
            e.preventDefault();
            return false;
        }
    }).keyup(function (e) {
        var code = e.which;
        var search_query_box = $("#search_query");
        if (code === 13 && search_query_box.is(":focus")) {
            // We just pressed enter and the box had focus, which
            // means we didn't use the typeahead at all.  In that
            // case, we should act as though we're searching by
            // operators.  (The reason the other actions don't call
            // this codepath is that they first all blur the box to
            // indicate that they've done what they need to do)
            if (search_query_box.val().trim()) {
                narrow.activate(narrow.parse(search_query_box.val()));
            }
            search_query_box.blur();
            update_buttons_with_focus(false);
        }
    });

    // Some of these functions don't actually need to be exported,
    // but the code was moved here from elsewhere, and it would be
    // more work to re-order everything and make them private.
    $('#search_exit' ).on('click', exports.clear_search);

    var query = $('#search_query');
    query.on('focus', exports.focus_search)
         .on('blur' , function () {

        // The search query box is a visual cue as to
        // whether search or narrowing is active.  If
        // neither is active, we should clear the box on
        // blur.
        //
        // But we can't do this right away, because
        // selecting something in the typeahead menu causes
        // the box to lose focus a moment before.  We would
        // clear the thing we're about to search for.
        //
        // The workaround is to check 100ms later -- long
        // enough for the search to have gone through, but
        // short enough that the user won't notice (though
        // really it would be OK if they did).

        setTimeout(function () {
            if (!(narrow.active())) {
                query.val('');
            }
            exports.update_button_visibility();
        }, 100);
    });
};

function match_on_visible_text(row, search_term) {
    // You can't select on :visible, since that includes hidden elements that
    // take up space.
    return row.find(".message_content, .message_header")
              .text().toLowerCase().indexOf(search_term) !== -1;
}

exports.focus_search = function () {
    // The search bar is not focused yet, but will be.
    update_buttons_with_focus(true);
};

exports.initiate_search = function () {
    $('#search_query').select();
};

exports.clear_search = function () {
    narrow.deactivate();

    $('table tr').removeHighlight();
    $('#search_query').blur();
    exports.update_button_visibility();
};

return exports;

}());
<|endoftext|>


<commit_before>var search = (function () {

var exports = {};

var cached_term = "";
var cached_matches = [];
var cached_index;
var cached_table = $('table.focused_table');

function match_on_visible_text(row, search_term) {
    // You can't select on :visible, since that includes hidden elements that
    // take up space.
    return row.find(".message_content, .sender_name, .message_header, .message_time")
              .text().toLowerCase().indexOf(search_term) !== -1;
}

function disable_search_arrows_if(condition, affected_arrows) {
    var i, button;

    for (i = 0; i < affected_arrows.length; i++) {
        button = $("#search_" + affected_arrows[i]);
        if (condition) {
            button.attr("disabled", "disabled");
        } else {
            button.removeAttr("disabled");
        }
    }
}

function search(term, highlighted_message, reverse) {
    // term: case-insensitive text to search for
    // highlighted_message: the current location of the pointer. Ignored
    //     on cached queries
    // reverse: boolean as to whether the search is forward or backwards
    //
    // returns a message object containing the search term.
    var previous_header_matched = false;

    var focused_table = $('table.focused_table');
    if ((term !== cached_term) || (cached_table[0] !== focused_table[0])) {
        cached_term = term;
        cached_matches = [];
        cached_index = null;
        cached_table = focused_table;
        var selected_zid = rows.id(highlighted_message);

        focused_table.find('.message_row, .recipient_row').each(function (index, row) {
            row = $(row);
            if (previous_header_matched || (match_on_visible_text(row, term))) {
                previous_header_matched = false;

                if (row.hasClass("recipient_row")) {
                    previous_header_matched = true;
                } else {
                    cached_matches.push(row);
                    var zid = rows.id(row);
                    if ((reverse && (zid <= selected_zid)) ||
                        (!reverse && (zid >= selected_zid) && !cached_index)) {
                        // Keep track of the closest match going up or down.
                        cached_index = cached_matches.length - 1;
                    }
                }
            }
        });

        disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);

        return cached_matches[cached_index];
    }

    if (reverse) {
        if (cached_index > 0) {
            cached_index--;
        }
    } else {
        if (cached_index < cached_matches.length - 1) {
            cached_index++;
        }
    }

    disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);
    disable_search_arrows_if(cached_index === 0, ["up"]);
    disable_search_arrows_if(cached_index === cached_matches.length - 1, ["down"]);

    return cached_matches[cached_index];
}

function highlight_match(row, search_term) {
    $('table tr').removeHighlight();
    row.highlight(search_term);

    row = row.prev('.recipient_row');
    if ((row.length !== 0) && (match_on_visible_text(row, search_term))) {
        row.highlight(search_term);
    }
}

exports.search_button_handler = function (reverse) {
    var query = $('#search_query').val().toLowerCase();
    var res = search(query, selected_message, reverse);
    if (!res) {
        return;
    }

    select_message(res);
    highlight_match(res, query);
    scroll_to_selected();
};

function clear_search_cache() {
    cached_term = "";
}

exports.focus_search = function () {
    // Shrink the searchbox to make room for the buttons.
    var search_query = $('#search_query');
    var new_width = search_query.width() -
        $('.search_button').outerWidth(true)*3;
    search_query.width(new_width);
    $("#search_arrows").addClass("input-append");
    $('.search_button').show();
    disable_search_arrows_if(false, ["up", "down"]);
};

exports.initiate_search = function () {
    $('#search_query').val('').focus();
};

exports.clear_search = function () {
    $('table tr').removeHighlight();
    // Clear & reset searchbox to its normal size
    $('#search_query').val('').width('');
    $("#search_arrows").removeClass("input-append");
    $("#search_up, #search_down").removeAttr("disabled");
    $('.search_button').blur().hide();
    clear_search_cache();
};

exports.something_is_highlighted = function () {
    return $(".highlight").length > 0;
};

exports.update_highlight_on_narrow = function () {
    highlight_match(selected_message, cached_term);
    clear_search_cache();
};

return exports;

}());
<commit_msg>Make searchbox shrinking idempotent.<commit_after>var search = (function () {

var exports = {};

var cached_term = "";
var cached_matches = [];
var cached_index;
var cached_table = $('table.focused_table');

function match_on_visible_text(row, search_term) {
    // You can't select on :visible, since that includes hidden elements that
    // take up space.
    return row.find(".message_content, .sender_name, .message_header, .message_time")
              .text().toLowerCase().indexOf(search_term) !== -1;
}

function disable_search_arrows_if(condition, affected_arrows) {
    var i, button;

    for (i = 0; i < affected_arrows.length; i++) {
        button = $("#search_" + affected_arrows[i]);
        if (condition) {
            button.attr("disabled", "disabled");
        } else {
            button.removeAttr("disabled");
        }
    }
}

function search(term, highlighted_message, reverse) {
    // term: case-insensitive text to search for
    // highlighted_message: the current location of the pointer. Ignored
    //     on cached queries
    // reverse: boolean as to whether the search is forward or backwards
    //
    // returns a message object containing the search term.
    var previous_header_matched = false;

    var focused_table = $('table.focused_table');
    if ((term !== cached_term) || (cached_table[0] !== focused_table[0])) {
        cached_term = term;
        cached_matches = [];
        cached_index = null;
        cached_table = focused_table;
        var selected_zid = rows.id(highlighted_message);

        focused_table.find('.message_row, .recipient_row').each(function (index, row) {
            row = $(row);
            if (previous_header_matched || (match_on_visible_text(row, term))) {
                previous_header_matched = false;

                if (row.hasClass("recipient_row")) {
                    previous_header_matched = true;
                } else {
                    cached_matches.push(row);
                    var zid = rows.id(row);
                    if ((reverse && (zid <= selected_zid)) ||
                        (!reverse && (zid >= selected_zid) && !cached_index)) {
                        // Keep track of the closest match going up or down.
                        cached_index = cached_matches.length - 1;
                    }
                }
            }
        });

        disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);

        return cached_matches[cached_index];
    }

    if (reverse) {
        if (cached_index > 0) {
            cached_index--;
        }
    } else {
        if (cached_index < cached_matches.length - 1) {
            cached_index++;
        }
    }

    disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);
    disable_search_arrows_if(cached_index === 0, ["up"]);
    disable_search_arrows_if(cached_index === cached_matches.length - 1, ["down"]);

    return cached_matches[cached_index];
}

function highlight_match(row, search_term) {
    $('table tr').removeHighlight();
    row.highlight(search_term);

    row = row.prev('.recipient_row');
    if ((row.length !== 0) && (match_on_visible_text(row, search_term))) {
        row.highlight(search_term);
    }
}

exports.search_button_handler = function (reverse) {
    var query = $('#search_query').val().toLowerCase();
    var res = search(query, selected_message, reverse);
    if (!res) {
        return;
    }

    select_message(res);
    highlight_match(res, query);
    scroll_to_selected();
};

function clear_search_cache() {
    cached_term = "";
}

exports.focus_search = function () {
    if (!$('.search_button').is(':visible')) {
        // Shrink the searchbox to make room for the buttons.
        var search_query = $('#search_query');
        var new_width = search_query.width() -
            $('.search_button').outerWidth(true)*3;
        search_query.width(new_width);
        $("#search_arrows").addClass("input-append");
        $('.search_button').show();
        disable_search_arrows_if(false, ["up", "down"]);
    }
};

exports.initiate_search = function () {
    $('#search_query').val('').focus();
};

exports.clear_search = function () {
    $('table tr').removeHighlight();
    // Clear & reset searchbox to its normal size
    $('#search_query').val('').width('');
    $("#search_arrows").removeClass("input-append");
    $("#search_up, #search_down").removeAttr("disabled");
    $('.search_button').blur().hide();
    clear_search_cache();
};

exports.something_is_highlighted = function () {
    return $(".highlight").length > 0;
};

exports.update_highlight_on_narrow = function () {
    highlight_match(selected_message, cached_term);
    clear_search_cache();
};

return exports;

}());
<|endoftext|>


<commit_before>import NFL_SCHEDULE_DB from 'fantasy-weather/data/nfl-schedule-db';

import Ember from 'ember';
import moment from 'moment';
import computed from 'ember-computed-decorators';

const NFL_SEASON_FIRST_TUESDAY = new Date('09-08-2015');

let parseTeam = (team) => {
  team = team.toUpperCase();
  team = _.trim(team);
  return team;
};

export default Ember.Service.extend({

  init() {
    this._super(...arguments);
    // console.log(NFL_SCHEDULE_DB.length);
  },

  // _schedule: NFL_SCHEDULE_DB,

  /**
   * Private variable used to house the tuesdays array
   *
   * @private
   * @property __scheduleTuesdays
   * @type Array
   */
  __scheduleTuesdays: null,

  /**
   * Tuesdays array computed property reference
   * "lazy generate" the tuesdays of the nfl schedule (wait for some caller to ask for it)
   *
   * @property _scheduleTuesdays
   * @type Array
   */
  @computed('__scheduleTuesdays')
  _scheduleTuesdays(__scheduleTuesdays) {
    // If value has not been populated yet- build it
    if (_.isBlank(__scheduleTuesdays)) {
      __scheduleTuesdays = [{
        week: 1,
        tuesday: moment(NFL_SEASON_FIRST_TUESDAY)
      }];
      for (let i = 1; __scheduleTuesdays.length < 17; i++) {
        __scheduleTuesdays.push({
          week: i + 1,
          tuesday: __scheduleTuesdays[i-1].tuesday.clone().add(7, 'days')
        });
      }
      this.set('__scheduleTuesdays', __scheduleTuesdays)
    }
    return __scheduleTuesdays;
  },

  // Filter alias
  filter(query) {
    return _.filter(NFL_SCHEDULE_DB, query);
  },

  // Get week for all teams
  week(week) {
    return this.filter({ week });
  },

  // Get week number from date
  weekNumberFromDate(date) {
    if (_.isDate(date)) date = moment(date);

    // testing
    if (false) {
      date.add(2, 'days');
      console.log('2 days', date.toString());
    }

    // Get previous Tuesday
    date.day(-5);

    // Return object
    let week;
    let tuesdays = _.clone(this.get('_scheduleTuesdays'));

    // Stop when `week` has been determined
    while(!_.isNumber(week)) {
      let middleIndex = _.floor(tuesdays.length / 2);
      let middle = tuesdays[middleIndex];

      if (date.isSame(middle.tuesday, 'day')) {
        // Found the week
        week = middle.week;
      } else if (date.isAfter(middle.tuesday)) {
        // Take next middle index, to the end
        tuesdays = tuesdays.slice(middleIndex + 1);
      } else {
        // Take start, to middle index
        tuesdays = tuesdays.slice(0, middleIndex);
      }
    }

    return week;
  },

  weekNumberCurrent() {
    return this.weekNumberFromDate(moment());
  },

  // Get week for all teams by date
  weekFromDate(date) {
    return this.week(this.weekNumberFromDate(date));
  },

  // Get week for current date/time
  weekCurrent() {
    return this.weekFromDate(moment());
  },

  // Get team location
  teamLocation(team, location) {
    location = team.toLowerCase();
    let query = {};
    query[location] = parseTeam(team);
    return this.filter(query);
  },

  // Get team home games
  teamHome(team) {
    return this.teamLocation(team, 'home');
  },

  // Get team away games
  teamAway(team) {
    return this.teamLocation(team, 'away');
  },

  // Get team games
  team(team) {
    team = parseTeam(team);
    return this.filter((game) => {
      return (
        (game.home === team) ||
        (game.away === team)
      );
    });
  }

});
<commit_msg>cleanup<commit_after>import NFL_SCHEDULE_DB from 'fantasy-weather/data/nfl-schedule-db';

import Ember from 'ember';
import moment from 'moment';
import computed from 'ember-computed-decorators';

const NFL_SEASON_FIRST_TUESDAY = new Date('09-08-2015');

let parseTeam = (team) => {
  team = team.toUpperCase();
  team = _.trim(team);
  return team;
};

export default Ember.Service.extend({

  init() {
    this._super(...arguments);
    // console.log(NFL_SCHEDULE_DB.length);
  },

  // _schedule: NFL_SCHEDULE_DB,

  /**
   * Private variable used to house the tuesdays array
   *
   * @private
   * @property __scheduleTuesdays
   * @type Array
   */
  __scheduleTuesdays: null,

  /**
   * Tuesdays array computed property reference
   * "lazy generate" the tuesdays of the nfl schedule (wait for some caller to ask for it)
   *
   * @property _scheduleTuesdays
   * @type Array
   */
  @computed('__scheduleTuesdays')
  _scheduleTuesdays(__scheduleTuesdays) {
    // If value has not been populated yet- build it
    if (_.isBlank(__scheduleTuesdays)) {
      __scheduleTuesdays = [{
        week: 1,
        tuesday: moment(NFL_SEASON_FIRST_TUESDAY)
      }];
      for (let i = 1; __scheduleTuesdays.length < 17; i++) {
        __scheduleTuesdays.push({
          week: i + 1,
          tuesday: __scheduleTuesdays[i-1].tuesday.clone().add(7, 'days')
        });
      }
      this.set('__scheduleTuesdays', __scheduleTuesdays);
    }
    return __scheduleTuesdays;
  },

  // Filter alias
  filter(query) {
    return _.filter(NFL_SCHEDULE_DB, query);
  },

  // Get week for all teams
  week(week) {
    return this.filter({ week });
  },

  // Get week number from date
  weekNumberFromDate(date) {
    if (_.isDate(date)) date = moment(date);

    // testing
    if (false) {
      date.add(2, 'days');
      console.log('2 days', date.toString());
    }

    // Get previous Tuesday
    date.day(-5);

    // Return object
    let week;
    let tuesdays = _.clone(this.get('_scheduleTuesdays'));

    // Stop when `week` has been determined
    while(!_.isNumber(week)) {
      let middleIndex = _.floor(tuesdays.length / 2);
      let middle = tuesdays[middleIndex];

      if (date.isSame(middle.tuesday, 'day')) {
        // Found the week
        week = middle.week;
      } else if (date.isAfter(middle.tuesday)) {
        // Take next middle index, to the end
        tuesdays = tuesdays.slice(middleIndex + 1);
      } else {
        // Take start, to middle index
        tuesdays = tuesdays.slice(0, middleIndex);
      }
    }

    return week;
  },

  weekNumberCurrent() {
    return this.weekNumberFromDate(moment());
  },

  // Get week for all teams by date
  weekFromDate(date) {
    return this.week(this.weekNumberFromDate(date));
  },

  // Get week for current date/time
  weekCurrent() {
    return this.weekFromDate(moment());
  },

  // Get team location
  teamLocation(team, location) {
    location = team.toLowerCase();
    let query = {};
    query[location] = parseTeam(team);
    return this.filter(query);
  },

  // Get team home games
  teamHome(team) {
    return this.teamLocation(team, 'home');
  },

  // Get team away games
  teamAway(team) {
    return this.teamLocation(team, 'away');
  },

  // Get team games
  team(team) {
    team = parseTeam(team);
    return this.filter((game) => {
      return (
        (game.home === team) ||
        (game.away === team)
      );
    });
  }

});
<|endoftext|>


<commit_before>import 'bootstrap';
import 'select2';
import 'd3';
import 'dropzone';
import {} from 'jquery-ujs';
import Cookies from 'js-cookie';
import Cropper from 'cropperjs';
import moment from 'moment-timezone';
import 'moment/locale/ja';
import Turbolinks from 'turbolinks';
import Vue from 'vue';
import VueLazyload from 'vue-lazyload';

import vueLazyLoad from './common/vueLazyLoad';

import activities from './common/components/activities';
import adsense from './common/components/adsense';
import amazonItemAttacher from './common/components/amazonItemAttacher';
import analytics from './common/components/analytics';
import body from './common/components/body';
import channelReceiveButton from './common/components/channelReceiveButton';
import channelSelector from './common/components/channelSelector';
import commentGuard from './common/components/commentGuard';
import episodeList from './common/components/episodeList';
import episodeProgress from './common/components/episodeProgress';
import episodeRatingStateChart from './common/components/episodeRatingStateChart';
import episodeRecordsChart from './common/components/episodeRecordsChart';
import favoriteButton from './common/components/favoriteButton';
import flash from './common/components/flash';
import followButton from './common/components/followButton';
import impressionButton from './common/components/impressionButton';
import impressionButtonModal from './common/components/impressionButtonModal';
import inputWordsCount from './common/components/inputWordsCount';
import likeButton from './common/components/likeButton';
import omittedSynopsis from './common/components/omittedSynopsis';
import muteUserButton from './common/components/muteUserButton';
import programList from './common/components/programList';
import ratingLabel from './common/components/ratingLabel';
import ratingStateLabel from './common/components/ratingStateLabel';
import reactionButton from './common/components/reactionButton';
import record from './common/components/record';
import recordRating from './common/components/recordRating';
import recordSorter from './common/components/recordSorter';
import recordTextarea from './common/components/recordTextarea';
import recordWordCount from './common/components/recordWordCount';
import shareButtonFacebook from './common/components/shareButtonFacebook';
import shareButtonTwitter from './common/components/shareButtonTwitter';
import statusSelector from './common/components/statusSelector';
import timeAgo from './common/components/timeAgo';
import tips from './common/components/tips';
import untrackedEpisodeList from './common/components/untrackedEpisodeList';
import userHeatmap from './common/components/userHeatmap';
import usernamePreview from './common/components/usernamePreview';
import workComment from './common/components/workComment';
import workDetailButton from './common/components/workDetailButton';
import workDetailButtonModal from './common/components/workDetailButtonModal';
import workFriends from './common/components/workFriends';
import workTags from './common/components/workTags';
import youtubeModalPlayer from './common/components/youtubeModalPlayer';

import searchForm from './pc/components/searchForm';
import imageAttachForm from './pc/components/imageAttachForm';
import imageAttachModal from './pc/components/imageAttachModal';

import resourceSelect from './common/directives/resourceSelect';

document.addEventListener('turbolinks:load', event => {
  moment.locale(gon.user.locale);
  Cookies.set('ann_time_zone', moment.tz.guess(), {
    domain: '.annict.com',
    secure: true
  });

  Vue.config.debug = true;

  Vue.use(VueLazyload);

  Vue.component('c-activities', activities);
  Vue.component('c-adsense', adsense);
  Vue.component('c-amazon-item-attacher', amazonItemAttacher);
  Vue.component('c-analytics', analytics(event));
  Vue.component('c-body', body);
  Vue.component('c-channel-receive-button', channelReceiveButton);
  Vue.component('c-channel-selector', channelSelector);
  Vue.component('c-comment-guard', commentGuard);
  Vue.component('c-episode-list', episodeList);
  Vue.component('c-episode-progress', episodeProgress);
  Vue.component('c-episode-rating-state-chart', episodeRatingStateChart);
  Vue.component('c-episode-records-chart', episodeRecordsChart);
  Vue.component('c-favorite-button', favoriteButton);
  Vue.component('c-flash', flash);
  Vue.component('c-follow-button', followButton);
  Vue.component('c-image-attach-form', imageAttachForm);
  Vue.component('c-image-attach-modal', imageAttachModal);
  Vue.component('c-impression-button', impressionButton);
  Vue.component('c-impression-button-modal', impressionButtonModal);
  Vue.component('c-input-words-count', inputWordsCount);
  Vue.component('c-like-button', likeButton);
  Vue.component('c-omitted-synopsis', omittedSynopsis);
  Vue.component('c-mute-user-button', muteUserButton);
  Vue.component('c-program-list', programList);
  Vue.component('c-rating-label', ratingLabel);
  Vue.component('c-rating-state-label', ratingStateLabel);
  Vue.component('c-reaction-button', reactionButton);
  Vue.component('c-record', record);
  Vue.component('c-record-rating', recordRating);
  Vue.component('c-record-sorter', recordSorter);
  Vue.component('c-record-textarea', recordTextarea);
  Vue.component('c-record-word-count', recordWordCount);
  Vue.component('c-search-form', searchForm);
  Vue.component('c-share-button-facebook', shareButtonFacebook);
  Vue.component('c-share-button-twitter', shareButtonTwitter);
  Vue.component('c-status-selector', statusSelector);
  Vue.component('c-time-ago', timeAgo);
  Vue.component('c-tips', tips);
  Vue.component('c-untracked-episode-list', untrackedEpisodeList);
  Vue.component('c-user-heatmap', userHeatmap);
  Vue.component('c-username-preview', usernamePreview);
  Vue.component('c-work-comment', workComment);
  Vue.component('c-work-detail-button', workDetailButton);
  Vue.component('c-work-detail-button-modal', workDetailButtonModal);
  Vue.component('c-work-friends', workFriends);
  Vue.component('c-work-tags', workTags);
  Vue.component('c-youtube-modal-player', youtubeModalPlayer);

  Vue.directive('resource-select', resourceSelect);

  Vue.nextTick(() => {
    vueLazyLoad.refresh();
  });

  new Vue({
    el: '.p-application'
  });
});

Turbolinks.start();
console.log('＼(^o^)／＼(^o^)／');
<commit_msg>Remove test code<commit_after>import 'bootstrap';
import 'select2';
import 'd3';
import 'dropzone';
import {} from 'jquery-ujs';
import Cookies from 'js-cookie';
import Cropper from 'cropperjs';
import moment from 'moment-timezone';
import 'moment/locale/ja';
import Turbolinks from 'turbolinks';
import Vue from 'vue';
import VueLazyload from 'vue-lazyload';

import vueLazyLoad from './common/vueLazyLoad';

import activities from './common/components/activities';
import adsense from './common/components/adsense';
import amazonItemAttacher from './common/components/amazonItemAttacher';
import analytics from './common/components/analytics';
import body from './common/components/body';
import channelReceiveButton from './common/components/channelReceiveButton';
import channelSelector from './common/components/channelSelector';
import commentGuard from './common/components/commentGuard';
import episodeList from './common/components/episodeList';
import episodeProgress from './common/components/episodeProgress';
import episodeRatingStateChart from './common/components/episodeRatingStateChart';
import episodeRecordsChart from './common/components/episodeRecordsChart';
import favoriteButton from './common/components/favoriteButton';
import flash from './common/components/flash';
import followButton from './common/components/followButton';
import impressionButton from './common/components/impressionButton';
import impressionButtonModal from './common/components/impressionButtonModal';
import inputWordsCount from './common/components/inputWordsCount';
import likeButton from './common/components/likeButton';
import omittedSynopsis from './common/components/omittedSynopsis';
import muteUserButton from './common/components/muteUserButton';
import programList from './common/components/programList';
import ratingLabel from './common/components/ratingLabel';
import ratingStateLabel from './common/components/ratingStateLabel';
import reactionButton from './common/components/reactionButton';
import record from './common/components/record';
import recordRating from './common/components/recordRating';
import recordSorter from './common/components/recordSorter';
import recordTextarea from './common/components/recordTextarea';
import recordWordCount from './common/components/recordWordCount';
import shareButtonFacebook from './common/components/shareButtonFacebook';
import shareButtonTwitter from './common/components/shareButtonTwitter';
import statusSelector from './common/components/statusSelector';
import timeAgo from './common/components/timeAgo';
import tips from './common/components/tips';
import untrackedEpisodeList from './common/components/untrackedEpisodeList';
import userHeatmap from './common/components/userHeatmap';
import usernamePreview from './common/components/usernamePreview';
import workComment from './common/components/workComment';
import workDetailButton from './common/components/workDetailButton';
import workDetailButtonModal from './common/components/workDetailButtonModal';
import workFriends from './common/components/workFriends';
import workTags from './common/components/workTags';
import youtubeModalPlayer from './common/components/youtubeModalPlayer';

import searchForm from './pc/components/searchForm';
import imageAttachForm from './pc/components/imageAttachForm';
import imageAttachModal from './pc/components/imageAttachModal';

import resourceSelect from './common/directives/resourceSelect';

document.addEventListener('turbolinks:load', event => {
  moment.locale(gon.user.locale);
  Cookies.set('ann_time_zone', moment.tz.guess(), {
    domain: '.annict.com',
    secure: true
  });

  Vue.config.debug = true;

  Vue.use(VueLazyload);

  Vue.component('c-activities', activities);
  Vue.component('c-adsense', adsense);
  Vue.component('c-amazon-item-attacher', amazonItemAttacher);
  Vue.component('c-analytics', analytics(event));
  Vue.component('c-body', body);
  Vue.component('c-channel-receive-button', channelReceiveButton);
  Vue.component('c-channel-selector', channelSelector);
  Vue.component('c-comment-guard', commentGuard);
  Vue.component('c-episode-list', episodeList);
  Vue.component('c-episode-progress', episodeProgress);
  Vue.component('c-episode-rating-state-chart', episodeRatingStateChart);
  Vue.component('c-episode-records-chart', episodeRecordsChart);
  Vue.component('c-favorite-button', favoriteButton);
  Vue.component('c-flash', flash);
  Vue.component('c-follow-button', followButton);
  Vue.component('c-image-attach-form', imageAttachForm);
  Vue.component('c-image-attach-modal', imageAttachModal);
  Vue.component('c-impression-button', impressionButton);
  Vue.component('c-impression-button-modal', impressionButtonModal);
  Vue.component('c-input-words-count', inputWordsCount);
  Vue.component('c-like-button', likeButton);
  Vue.component('c-omitted-synopsis', omittedSynopsis);
  Vue.component('c-mute-user-button', muteUserButton);
  Vue.component('c-program-list', programList);
  Vue.component('c-rating-label', ratingLabel);
  Vue.component('c-rating-state-label', ratingStateLabel);
  Vue.component('c-reaction-button', reactionButton);
  Vue.component('c-record', record);
  Vue.component('c-record-rating', recordRating);
  Vue.component('c-record-sorter', recordSorter);
  Vue.component('c-record-textarea', recordTextarea);
  Vue.component('c-record-word-count', recordWordCount);
  Vue.component('c-search-form', searchForm);
  Vue.component('c-share-button-facebook', shareButtonFacebook);
  Vue.component('c-share-button-twitter', shareButtonTwitter);
  Vue.component('c-status-selector', statusSelector);
  Vue.component('c-time-ago', timeAgo);
  Vue.component('c-tips', tips);
  Vue.component('c-untracked-episode-list', untrackedEpisodeList);
  Vue.component('c-user-heatmap', userHeatmap);
  Vue.component('c-username-preview', usernamePreview);
  Vue.component('c-work-comment', workComment);
  Vue.component('c-work-detail-button', workDetailButton);
  Vue.component('c-work-detail-button-modal', workDetailButtonModal);
  Vue.component('c-work-friends', workFriends);
  Vue.component('c-work-tags', workTags);
  Vue.component('c-youtube-modal-player', youtubeModalPlayer);

  Vue.directive('resource-select', resourceSelect);

  Vue.nextTick(() => {
    vueLazyLoad.refresh();
  });

  new Vue({
    el: '.p-application'
  });
});

Turbolinks.start();
<|endoftext|>