<commit_before>/**
 * Notify the user via WebKit's Notification systems. This can and should be extended as other browsers
 * impliment the system, and as the standards are fine tuned.
 * @see http://www.w3.org/TR/notifications/
 * @author <NAME> [<EMAIL>]
 */

define('utils/notifications', [
    'jquery'
], function ($) {

    /**
     * @exports utils/notifications
     * @requires jquery
     */
    var notifications = {

        /**
         * @private
         * @type {boolean}
         */
        _wantsNotifications: true,

        /**
         * Request permission from the user to access the notification api.
         * @return {boolean} Permission has been granted.
         */
        requestPermission: function () {
            if (window.webkitNotifications && this._wantsNotifications) {
                window.webkitNotifications.requestPermission(this.checkPermission);
                return true;
            }
            return false;
        },

        /**
         * Set wants notification boolean.
         * @param {boolean} value Wether the user wants notifications or not.
         */
        setWantsNotifications: function (value) {
            this._wantsNotifications = (value ? true : false);
            return this._wantsNotifications;
        },

        /**
         * Check with the browser wether permission has already been granted to access the notification api.
         * @return {boolean}
         */
        checkPermission: function () {
            return (!!window.webkitNotifications && (window.webkitNotifications.checkPermission() === 0));
        },

        /**
         * Send a message to the user through the notification api.
         * @param  {[type]} title [description]
         * @param  {[type]} body [description]
         * @param  {[type]} user_choices [description]
         * @return {[type]}  [description]
         */
        sendMessage: function (title, body, user_options) {
            user_options = user_options || {};
            var message = null,
                options = {
                    iconUrl: '../img/logo.png',
                    html: false,
                    timeout: 8
                };

            $.extend(options, user_options);

            if (window.webkitNotifications && this.checkPermission()) {
                switch (options.html) {
                case true:
                    info('options.html: true');
                    // the PHP/JS notifications page needs setting up, as it'll require styling
                    // message = window.webkitNotifications.createHTMLNotification(
                        // 'notifications.html?' +
                        //      'iconUrl=' + options.iconUrl +
                        //      '&title=' + title +
                        //      '&body=' + body
                    // );
                    break;
                case false:
                    info('options.html: false');
                    message = window.webkitNotifications.createNotification(options.iconUrl, title, body);
                    break;
                }
                message.show();

                window.setTimeout(function () {
                    message.cancel();
                }, options.timeout * 1000);

                return true;
            }
            this.requestPermission();
            return false;<commit_msg>Cleaning up notifications.<commit_after>/**
 * Notify the user via WebKit's Notification systems. This can and should be extended as other browsers
 * impliment the system, and as the standards are fine tuned.
 * @see http://www.w3.org/TR/notifications/
 * @author <NAME> [<EMAIL>]
 */

define('utils/notifications', function () {

    /**
     * @exports utils/notifications
     */
    var notifications = {

        /**
         * @private
         * @type {boolean}
         */
        _wantsNotifications: true,

        /**
         * Request permission from the user to access the notification api.
         * @return {boolean} Permission has been granted.
         */
        requestPermission: function () {
            if (window.webkitNotifications && this._wantsNotifications) {
                window.webkitNotifications.requestPermission(this.checkPermission);
                return true;
            }
            return false;
        },

        /**
         * Set wants notification boolean.
         * @param {boolean} value Wether the user wants notifications or not.
         */
        setWantsNotifications: function (value) {
            this._wantsNotifications = (value ? true : false);
            return this._wantsNotifications;
        },

        /**
         * Check with the browser wether permission has already been granted to access the notification api.
         * @return {boolean}
         */
        checkPermission: function () {
            return (!!window.webkitNotifications && (window.webkitNotifications.checkPermission() === 0));
        },

        /**
         * Send a message to the user through the notification api.
         * @param  {[type]} title [description]
         * @param  {[type]} body [description]
         * @param  {[type]} user_choices [description]
         * @return {[type]}  [description]
         */
        sendMessage: function (title, body, user_options) {
            user_options = user_options || {};
            var options = {
                    iconUrl: '../img/logo.png',
                    html: false,
                    timeout: 8
                },
                property, message;

            for (property in user_options) {
                if (user_options.hasOwnProperty(property) && options.hasOwnProperty(property)) {
                    options[property] = user_options[property];
                }
            }

            if (window.webkitNotifications && this.checkPermission()) {
                message = window.webkitNotifications.createNotification(options.iconUrl, title, body);
                message.show();

                window.setTimeout(function () {
                    message.cancel();
                }, options.timeout * 1000);

                return true;
            }
            this.requestPermission();
            return false;
{'fraction_non_alphanumeric': 0.10358629522894652, 'fraction_numerical': 0.002241434518091579, 'mean_word_length': 1.5477161500815662, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1019221', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1420, 'n_words': 395}