<commit_before>/**
 * Created by jdomizio on 12/31/2014.
 */
define('sarmenu', function(require) {
    'use strict';

    var DropOverlay = require('dropoverlay'),
        util = require('util'),
        globalConfig = require('config');

    var sharedOverlay = new DropOverlay();

    var SARMENU_DEFAULT_OPT = {};

    var globalState = {
        getNextId: (function() {
            var id = ko.observable(1);
            return function() {
                var usedId = id();
                id(usedId + 1);
                return usedId;
            };
        })(),

        current: ko.observable()
    };

    function Sarmenu(params) {
        params = params || {};

        this._id = globalState.getNextId();
        this.isOpen = ko.observable(false);
        this.options = params.options || SARMENU_DEFAULT_OPT;
        this.element = null;

        this.openMenu = util.getOpenMenuHandler(this.options);
        this.closeMenu = util.getCloseMenuHandler(this.options);
    }

    Sarmenu.prototype.open = function() {
        var $element, $parent, isActive;

        $element = $(this.element);
        $parent = util.getParent($element);

        $element.trigger('focus');

        if(!this.isOpen()) {
            this.openMenu($parent);
        }
        this.isOpen(true);
        globalState.current(this._id);
    };

    Sarmenu.prototype.close = function() {
        var $element, $parent, isActive;

        $element = $(this.element);
        $parent = util.getParent($element);

        if(this.isOpen()) {
            this.closeMenu($parent);
        }
        this.isOpen(false);
    };

    Sarmenu.prototype.toggle = function() {
        this.isOpen() ? this.close() : this.open();
    };

    Sarmenu.prototype.keydown = function(e) {
        if (!/(38|40|27)/.test(e.keyCode)) return;

        e.preventDefault();
        e.stopPropagation();

        if(!this.isOpen()) return;

        this.close();
    };

    Sarmenu.prototype.init = function(element, valueAccessor, allBindings) {
        var self = this,
            params,
            $element,
            nearestDropdown;

        params = valueAccessor();

        this.element = element;

        nearestDropdown = $(element).next('.dropdown-menu');

        ko.applyBindingsToNode(element, {
            'click': function () {
                self.toggle();
            }
        });

        $(document).on('keydown', self.keydown.bind(self));

        nearestDropdown.each(function() {
            ko.applyBindingsToNode(this, {
                'click': function() {
                    self.close();
                }
            });
        });

        if(this.options.overlay) {
            this.isOpen.subscribe(function(value) {<commit_msg>Temp-commit (should probably make a dev branch)<commit_after>/**
 * Created by jdomizio on 12/31/2014.
 */
define('sarmenu', function(require) {
    'use strict';

    var DropOverlay = require('dropoverlay'),
        util = require('util'),
        globalConfig = require('config');

    var sharedOverlay = new DropOverlay();

    var SARMENU_DEFAULT_OPT = {};

    var globalState = {
        getNextId: (function() {
            var id = ko.observable(1);
            return function() {
                var usedId = id();
                id(usedId + 1);
                return usedId;
            };
        })(),

        current: ko.observable()
    };

    function Sarmenu(params) {
        params = params || {};

        this._id = globalState.getNextId();
        this.isOpen = ko.observable(false);
        this.options = params.options || SARMENU_DEFAULT_OPT;
        this.element = null;

        this.openMenu = util.getOpenMenuHandler(this.options);
        this.closeMenu = util.getCloseMenuHandler(this.options);
    }

    Sarmenu.prototype.open = function() {
        var $element, $parent, isActive;

        $element = $(this.element);
        $parent = util.getParent($element);

        $element.trigger('focus');

        if(!this.isOpen()) {
            this.openMenu($parent);
        }
        this.isOpen(true);
        globalState.current(this._id);
    };

    Sarmenu.prototype.close = function() {
        var $element, $parent, isActive;

        $element = $(this.element);
        $parent = util.getParent($element);

        if(this.isOpen()) {
            this.closeMenu($parent);
        }
        this.isOpen(false);
    };

    Sarmenu.prototype.toggle = function() {
        this.isOpen() ? this.close() : this.open();
    };

    Sarmenu.prototype.keydown = function(e) {
        if (!/(38|40|27)/.test(e.keyCode)) return;

        e.preventDefault();
        e.stopPropagation();

        if(!this.isOpen()) return;

        this.close();
    };

    /**
     * Knockout initialization for sarmenu binding
     * @param element - The element to which the sarmenu is being bound
     * @param valueAccessor - The value being passed to the binding
     * @param allBindings - All other bindings being bound on the element.
     */
    Sarmenu.prototype.init = function(element, valueAccessor, allBindings) {
        var self = this,
            params,
            $element,
            nearestDropdown;

        params = valueAccessor();

        this.element = element;

        nearestDropdown = $(element).next('.dropdown-menu');

        ko.applyBindingsToNode(element, {
            'click': function () {
                self.toggle();
            }
        });

        $(document).on('keydown', self.keydown.bind(self));

        nearestDropdown.each(function() {
            ko.applyBindingsToNode(this, {
                'click': function() {
                    self.close();
                }
            });
        });

        if(this.options.overlay) {
            this.isOpen.subscribe(function(value) {
{'fraction_non_alphanumeric': 0.13816242257398487, 'fraction_numerical': 0.0055058499655884375, 'mean_word_length': 1.8481136697697207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1014955', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1625, 'n_words': 301}