<commit_before>/* See license.txt for terms of usage */

define([
    "firebug/lib/trace",
    "firebug/firebug",
    "firebug/lib/object",
    "firebug/remoting/debuggerClientModule",
],
function(FBTrace, Firebug, Obj, DebuggerClientModule) {

// ********************************************************************************************* //
// Constants

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;

Cu["import"]("resource://firebug/storageService.js");

// xxxHonza: create shared space for breakpoint constants.
const BP_NORMAL = 1;
const BP_MONITOR = 2;
const BP_UNTIL = 4;
const BP_ONRELOAD = 8;  // XXXjjb: This is a mark for the UI to test
const BP_ERROR = 16;
const BP_TRACE = 32; // BP used to initiate traceCalls

// ********************************************************************************************* //
// Breakpoint Store

var BreakpointStore = Obj.extend(Firebug.Module,
{
    dispatchName: "BreakpointStore",
    breakpoints: {},

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Module

    initialize: function()
    {
        Firebug.Module.initialize.apply(this, arguments);

        DebuggerClientModule.addListener(this);

        // Restore breakpoints from a file. This should be done only if it's necessary
        // (i.e. when the Debugger tool is actually activated.
        this.storage = StorageService.getStorage("breakpoints.json");
        this.restore();

        FBTrace.sysout("breakpointStore.initialize; ", this.breakpoints);
    },

    shutdown: function()
    {
        Firebug.Module.destroy.apply(this, arguments);

        DebuggerClientModule.removeListener(this);

        this.storage = null;
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // DebuggerClientModule Events

    onThreadAttached: function(context)
    {
        // Get all breakpoints
        // xxxHonza: do we have to send all the breakpoints to the server?
        // Could we optimize this somehow?
        var bps = this.getBreakpoints();

        // Set breakpoints on the server side.
        var tool = context.getTool("debugger");
        tool.setBreakpoints(context, bps, function()
        {
            FBTrace.sysout("breakpointStore.onThreadAttached; Server initialized", bps);
        });
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Breakpoint Store

    restore: function()
    {
        this.breakpoints = {};

        var urls = this.storage.getKeys();
        for (var i=0; i<urls.length; i++)
        {
            var url = urls[i];
            var bps = this.storage.getItem(url);

            // Do not restore "Run until this line" breakpoints. This should solve complaints
            // about Firebug breaking in the source even if there are no breakpoints in
            // Firebug UI.
            bps = bps.filter(function(element, index, array)
            {
                return (element.type != BP_UNTIL);
            });

            this.breakpoints[url] = bps;

            for (var j=0; j<bps.length; j++)
                bps[j].params = {};
        }
    },

    save: function(url)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return;

        var cleanBPs = [];
        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];

            if (bp.type == BP_UNTIL)
                continue;

            var cleanBP = {};
            for (var p in bp)
                cleanBP[p] = bp[p];

            delete cleanBP.params;

            cleanBPs.push(cleanBP);
        }

        this.storage.setItem(url, cleanBPs);

        FBTrace.sysout("breakpointStore.save;", this.storage);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    addBreakpoint: function(url, lineNo)
    {
        if (this.findBreakpoint(url, lineNo))
        {
            if (FBTrace.DBG_ERRORS)
                FBTrace.sysout("breakpointStore.addBreakpoint; ERROR There is alread a bp");
            return;
        }

        if (!this.breakpoints[url])
            this.breakpoints[url] = [];

        var bp = {
            href: url,
            lineNo: lineNo,
            type: BP_NORMAL,
            disabled: false,
            hitCount: -1,
            hit: 0,
            params: {},
        };

        this.breakpoints[url].push(bp);
        this.save(url);

        FBTrace.sysout("breakpointStore.addBreakpoint; " + url + " (" + lineNo + ")", bp);

        this.dispatch("onBreakpointAdded", [bp]);

        return bp;
    },

    removeBreakpoint: function(url, lineNo)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return null;

        var removedBp = null;
        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];
            if (bp.lineNo === lineNo)
            {
                bps.splice(i, 1);
                removedBp = bp;
            }
        }

        if (!removedBp)
            return;

        this.save(url);

        FBTrace.sysout("breakpointStore.removeBreakpoint; " + url +
            " (" + lineNo + ")", removedBp);

        this.dispatch("onBreakpointRemoved", [removedBp]);

        return removedBp;
    },

    findBreakpoint: function(url, lineNo)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return null;

        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];
            if (bp.lineNumber === lineNo)
                return bp;
        }

        return null;
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    getBreakpoints: function(url)
    {
        if (url)
            return this.breakpoints[url] || [];

        var bps = [];
        var urls = this.getBreakpointURLs();
        for (var i=0; i<urls.length; i++)
            bps.push.apply(bps, this.breakpoints[urls[i]] || []);

        return bps;
    },

    getBreakpointURLs: function()
    {
        return this.storage.getKeys();
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Enumerators

    enumerateBreakpoints: function(url, cb)
    {
        if (url)
        {
            var urlBreakpointsTemp = this.getBreakpoints(url);
            if (urlBreakpointsTemp)
            {
                // Clone before iteration (the array can be modified in the callback).
                var urlBreakpoints = [];
                urlBreakpoints.push.apply(urlBreakpoints, urlBreakpointsTemp);

                for (var i=0; i<urlBreakpoints.length; ++i)
                {
                    var bp = urlBreakpoints[i];
                    if (bp.type & BP_NORMAL && !(bp.type & BP_ERROR))
                    {
                        var rc = cb.call.apply(bp, [url, bp.lineNo, bp]);
                        if (rc)
                            return [bp];
                    }
                }
            }
        }
        else
        {
            var bps = [];
            var urls = this.getBreakpointURLs();
            for (var i=0; i<urls.length; i++)
                bps.push(this.enumerateBreakpoints(urls[i], cb));

            return bps;
        }
    },

    enumerateErrorBreakpoints: function()
    {
    },

    enumerateMonitors: function()
    {
    }
});

// ********************************************************************************************* //
// Registration

Firebug.registerModule(BreakpointStore);

return BreakpointStore;

// ********************************************************************************************* //
});
<commit_msg>Fix findBreakpoint method<commit_after>/* See license.txt for terms of usage */

define([
    "firebug/lib/trace",
    "firebug/firebug",
    "firebug/lib/object",
    "firebug/remoting/debuggerClientModule",
],
function(FBTrace, Firebug, Obj, DebuggerClientModule) {

// ********************************************************************************************* //
// Constants

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;

Cu["import"]("resource://firebug/storageService.js");

// xxxHonza: create shared space for breakpoint constants.
const BP_NORMAL = 1;
const BP_MONITOR = 2;
const BP_UNTIL = 4;
const BP_ONRELOAD = 8;  // XXXjjb: This is a mark for the UI to test
const BP_ERROR = 16;
const BP_TRACE = 32; // BP used to initiate traceCalls

// ********************************************************************************************* //
// Breakpoint Store

var BreakpointStore = Obj.extend(Firebug.Module,
{
    dispatchName: "BreakpointStore",
    breakpoints: {},

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Module

    initialize: function()
    {
        Firebug.Module.initialize.apply(this, arguments);

        DebuggerClientModule.addListener(this);

        // Restore breakpoints from a file. This should be done only if it's necessary
        // (i.e. when the Debugger tool is actually activated.
        this.storage = StorageService.getStorage("breakpoints.json");
        this.restore();

        FBTrace.sysout("breakpointStore.initialize; ", this.breakpoints);
    },

    shutdown: function()
    {
        Firebug.Module.destroy.apply(this, arguments);

        DebuggerClientModule.removeListener(this);

        this.storage = null;
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // DebuggerClientModule Events

    onThreadAttached: function(context)
    {
        // Get all breakpoints
        // xxxHonza: do we have to send all the breakpoints to the server?
        // Could we optimize this somehow?
        var bps = this.getBreakpoints();

        // Set breakpoints on the server side.
        var tool = context.getTool("debugger");
        tool.setBreakpoints(context, bps, function()
        {
            FBTrace.sysout("breakpointStore.onThreadAttached; Server initialized", bps);
        });
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Breakpoint Store

    restore: function()
    {
        this.breakpoints = {};

        var urls = this.storage.getKeys();
        for (var i=0; i<urls.length; i++)
        {
            var url = urls[i];
            var bps = this.storage.getItem(url);

            // Do not restore "Run until this line" breakpoints. This should solve complaints
            // about Firebug breaking in the source even if there are no breakpoints in
            // Firebug UI.
            bps = bps.filter(function(element, index, array)
            {
                return (element.type != BP_UNTIL);
            });

            this.breakpoints[url] = bps;

            for (var j=0; j<bps.length; j++)
                bps[j].params = {};
        }
    },

    save: function(url)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return;

        var cleanBPs = [];
        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];

            if (bp.type == BP_UNTIL)
                continue;

            var cleanBP = {};
            for (var p in bp)
                cleanBP[p] = bp[p];

            delete cleanBP.params;

            cleanBPs.push(cleanBP);
        }

        this.storage.setItem(url, cleanBPs);

        FBTrace.sysout("breakpointStore.save;", this.storage);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    addBreakpoint: function(url, lineNo)
    {
        if (this.findBreakpoint(url, lineNo))
        {
            if (FBTrace.DBG_ERRORS)
                FBTrace.sysout("breakpointStore.addBreakpoint; ERROR There is alread a bp");
            return;
        }

        if (!this.breakpoints[url])
            this.breakpoints[url] = [];

        var bp = {
            href: url,
            lineNo: lineNo,
            type: BP_NORMAL,
            disabled: false,
            hitCount: -1,
            hit: 0,
            params: {},
        };

        this.breakpoints[url].push(bp);
        this.save(url);

        FBTrace.sysout("breakpointStore.addBreakpoint; " + url + " (" + lineNo + ")", bp);

        this.dispatch("onBreakpointAdded", [bp]);

        return bp;
    },

    removeBreakpoint: function(url, lineNo)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return null;

        var removedBp = null;
        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];
            if (bp.lineNo === lineNo)
            {
                bps.splice(i, 1);
                removedBp = bp;
            }
        }

        if (!removedBp)
            return;

        this.save(url);

        FBTrace.sysout("breakpointStore.removeBreakpoint; " + url +
            " (" + lineNo + ")", removedBp);

        this.dispatch("onBreakpointRemoved", [removedBp]);

        return removedBp;
    },

    findBreakpoint: function(url, lineNo)
    {
        var bps = this.getBreakpoints(url);
        if (!bps)
            return null;

        // xxxHonza: Objects in the store are not instances of Breakpoint object.
        for (var i=0; i<bps.length; i++)
        {
            var bp = bps[i];
            if (bp.lineNo === lineNo)
                return bp;
        }

        return null;
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    getBreakpoints: function(url)
    {
        if (url)
            return this.breakpoints[url] || [];

        var bps = [];
        var urls = this.getBreakpointURLs();
        for (var i=0; i<urls.length; i++)
            bps.push.apply(bps, this.breakpoints[urls[i]] || []);

        return bps;
    },

    getBreakpointURLs: function()
    {
        return this.storage.getKeys();
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Enumerators

    enumerateBreakpoints: function(url, cb)
    {
        if (url)
        {
            var urlBreakpointsTemp = this.getBreakpoints(url);
            if (urlBreakpointsTemp)
            {
                // Clone before iteration (the array can be modified in the callback).
                var urlBreakpoints = [];
                urlBreakpoints.push.apply(urlBreakpoints, urlBreakpointsTemp);

                for (var i=0; i<urlBreakpoints.length; ++i)
                {
                    var bp = urlBreakpoints[i];
                    if (bp.type & BP_NORMAL && !(bp.type & BP_ERROR))
                    {
                        var rc = cb.call.apply(bp, [url, bp.lineNo, bp]);
                        if (rc)
                            return [bp];
                    }
                }
            }
        }
        else
        {
            var bps = [];
            var urls = this.getBreakpointURLs();
            for (var i=0; i<urls.length; i++)
                bps.push(this.enumerateBreakpoints(urls[i], cb));

            return bps;
        }
    },

    enumerateErrorBreakpoints: function()
    {
    },

    enumerateMonitors: function()
    {
    }
});

// ********************************************************************************************* //
// Registration

Firebug.registerModule(BreakpointStore);

return BreakpointStore;

// ********************************************************************************************* //
});
<|endoftext|>


<commit_before>/*global define:true requirejs:true*/
/* jshint strict: false */
requirejs.config({
    paths: {
        'jquery': 'jquery/jquery',
        'templatecontext': 'templatecontext'
    }
});

define(['templatecontext', 'jquery'], function (templatecontext, $) {
    console.log('Loading');
	var templatecontext = new templatecontext();
	templatecontext.init();
});<commit_msg>EXAMPLE: Update requirejs<commit_after>/*global define:true requirejs:true*/
/* jshint strict: false */
requirejs.config({
    paths: {
        'extend': 'gextend/extend',
        'keypath': 'gkeypath/keypath',
        'templatecontext': 'templatecontext'
    }
});

define(['templatecontext'], function(templatecontext) {
    console.log('Loading');
    var templatecontext = new templatecontext();
    templatecontext.init();
});<|endoftext|>


<commit_before>user_pref("app.update.auto", false);
user_pref("app.update.enabled", false);
user_pref("browser.EULA.3.accepted", true);
user_pref("browser.EULA.override", true);
user_pref("browser.displayedE10SNotice", 4);
user_pref("browser.download.manager.showWhenStarting", false);
user_pref("browser.download.manager.addToRecentDocs", false);
user_pref("browser.download.animateNotifications", false);
user_pref("browser.download.manager.scanWhenDone", false);
user_pref("browser.link.open_external", 2);
user_pref("browser.link.open_newwindow", 2);
user_pref("browser.offline", false);
user_pref("browser.reader.detectedFirstArticle", true);
user_pref("browser.safebrowsing.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("browser.search.suggest.enabled", false);
user_pref("browser.search.update", false);
user_pref("browser.selfsupport.url", "");
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.slowStartup.notificationDisabled", true);
user_pref("browser.slowStartup.maxSamples", 0);
user_pref("browser.slowStartup.samples", 0);
user_pref("browser.tabs.warnOnClose", false);
user_pref("browser.tabs.warnOnOpen", false);
user_pref("browser.tabs.animate", false);
user_pref("browser.uitour.enabled", false);
user_pref("datareporting.healthreport.logging.consoleEnabled", false);
user_pref("datareporting.healthreport.service.enabled", false);
user_pref("datareporting.healthreport.service.firstRun", false);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("datareporting.policy.dataSubmissionEnabled", false);
user_pref("datareporting.policy.dataSubmissionPolicyAccepted", false);
user_pref("devtools.errorconsole.enabled", true);
user_pref("dom.disable_open_during_load", false);
user_pref("extensions.autoDisableScopes", 10);
user_pref("extensions.blocklist.enabled", false);
user_pref("extensions.logging.enabled", true);
user_pref("extensions.update.enabled", false);
user_pref("extensions.update.autoUpdateDefault", false);
user_pref("extensions.update.notifyUser", false);
user_pref("javascript.enabled", true);
user_pref("network.http.phishy-userpass-length", 255);
user_pref("network.manage-offline-status", false);
user_pref("network.automatic-ntlm-auth.allow-non-fqdn", true);
user_pref("offline-apps.allow_by_default", true);
user_pref("prompts.tab_modal.enabled", false);
user_pref("places.history.enabled", false);
user_pref("plugins.update.url", false);
user_pref("security.csp.enable", false);
user_pref("security.fileuri.origin_policy", 3);
user_pref("security.fileuri.strict_origin_policy", false);
user_pref("security.warn_entering_secure", false);
user_pref("security.warn_entering_secure.show_once", false);
user_pref("security.warn_entering_weak", false);
user_pref("security.warn_entering_weak.show_once", false);
user_pref("security.warn_leaving_secure", false);
user_pref("security.warn_leaving_secure.show_once", false);
user_pref("security.warn_submit_insecure", false);
user_pref("security.warn_viewing_mixed", false);
user_pref("security.warn_viewing_mixed.show_once", false);
user_pref("services.sync.enabled", false);
user_pref("services.sync.engine.prefs", false);
user_pref("services.sync.engine.addons", false);
user_pref("services.sync.engine.tabs", false);
user_pref("signon.rememberSignons", false);
user_pref("toolkit.networkmanager.disable", true);
user_pref("toolkit.telemetry.enabled", false);
user_pref("toolkit.telemetry.prompted", 2);
user_pref("toolkit.telemetry.rejected", true);

user_pref("browser.dom.window.dump.enabled", true);
user_pref("browser.newtab.url", "about:blank");
user_pref("browser.newtabpage.enabled", false);
user_pref("browser.startup.homepage", "about:blank");
user_pref("browser.startup.page", 0);
user_pref("dom.max_chrome_script_run_time", 30);
user_pref("dom.max_script_run_time", 30);
user_pref("dom.report_all_js_exceptions", true);
user_pref("javascript.options.showInConsole", true);
user_pref("network.http.max-connections-per-server", 10);
user_pref("startup.homepage_welcome_url", "about:blank");
user_pref("webdriver_accept_untrusted_certs", true);
user_pref("webdriver_assume_untrusted_issuer", true);

user_pref("media.gmp-provider.enabled", false);
user_pref("browser.devedition.theme.enabled", true);
user_pref("lightweightThemes.update.enabled", false);

user_pref("extensions.logging.enabled", false);
user_pref("webdriver.log.init", true);
user_pref("webdriver.log.browser.ignore", true);
user_pref("webdriver.log.driver.ignore", true);
user_pref("webdriver.log.profiler.ignore", true);<commit_msg>Enabled devtools in Firefox prefs<commit_after>user_pref("app.update.auto", false);
user_pref("app.update.enabled", false);
user_pref("browser.EULA.3.accepted", true);
user_pref("browser.EULA.override", true);
user_pref("browser.displayedE10SNotice", 4);
user_pref("browser.download.manager.showWhenStarting", false);
user_pref("browser.download.manager.addToRecentDocs", false);
user_pref("browser.download.animateNotifications", false);
user_pref("browser.download.manager.scanWhenDone", false);
user_pref("browser.link.open_external", 2);
user_pref("browser.link.open_newwindow", 2);
user_pref("browser.offline", false);
user_pref("browser.reader.detectedFirstArticle", true);
user_pref("browser.safebrowsing.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("browser.search.suggest.enabled", false);
user_pref("browser.search.update", false);
user_pref("browser.selfsupport.url", "");
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.slowStartup.notificationDisabled", true);
user_pref("browser.slowStartup.maxSamples", 0);
user_pref("browser.slowStartup.samples", 0);
user_pref("browser.tabs.warnOnClose", false);
user_pref("browser.tabs.warnOnOpen", false);
user_pref("browser.tabs.animate", false);
user_pref("browser.uitour.enabled", false);
user_pref("datareporting.healthreport.logging.consoleEnabled", false);
user_pref("datareporting.healthreport.service.enabled", false);
user_pref("datareporting.healthreport.service.firstRun", false);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("datareporting.policy.dataSubmissionEnabled", false);
user_pref("datareporting.policy.dataSubmissionPolicyAccepted", false);
user_pref("devtools.errorconsole.enabled", true);
user_pref("dom.disable_open_during_load", false);
user_pref("extensions.autoDisableScopes", 10);
user_pref("extensions.blocklist.enabled", false);
user_pref("extensions.logging.enabled", true);
user_pref("extensions.update.enabled", false);
user_pref("extensions.update.autoUpdateDefault", false);
user_pref("extensions.update.notifyUser", false);
user_pref("javascript.enabled", true);
user_pref("network.http.phishy-userpass-length", 255);
user_pref("network.manage-offline-status", false);
user_pref("network.automatic-ntlm-auth.allow-non-fqdn", true);
user_pref("offline-apps.allow_by_default", true);
user_pref("prompts.tab_modal.enabled", false);
user_pref("places.history.enabled", false);
user_pref("plugins.update.url", false);
user_pref("security.csp.enable", false);
user_pref("security.fileuri.origin_policy", 3);
user_pref("security.fileuri.strict_origin_policy", false);
user_pref("security.warn_entering_secure", false);
user_pref("security.warn_entering_secure.show_once", false);
user_pref("security.warn_entering_weak", false);
user_pref("security.warn_entering_weak.show_once", false);
user_pref("security.warn_leaving_secure", false);
user_pref("security.warn_leaving_secure.show_once", false);
user_pref("security.warn_submit_insecure", false);
user_pref("security.warn_viewing_mixed", false);
user_pref("security.warn_viewing_mixed.show_once", false);
user_pref("services.sync.enabled", false);
user_pref("services.sync.engine.prefs", false);
user_pref("services.sync.engine.addons", false);
user_pref("services.sync.engine.tabs", false);
user_pref("signon.rememberSignons", false);
user_pref("toolkit.networkmanager.disable", true);
user_pref("toolkit.telemetry.enabled", false);
user_pref("toolkit.telemetry.prompted", 2);
user_pref("toolkit.telemetry.rejected", true);

user_pref("browser.dom.window.dump.enabled", true);
user_pref("browser.newtab.url", "about:blank");
user_pref("browser.newtabpage.enabled", false);
user_pref("browser.startup.homepage", "about:blank");
user_pref("browser.startup.page", 0);
user_pref("dom.max_chrome_script_run_time", 30);
user_pref("dom.max_script_run_time", 30);
user_pref("dom.report_all_js_exceptions", true);
user_pref("javascript.options.showInConsole", true);
user_pref("network.http.max-connections-per-server", 10);
user_pref("startup.homepage_welcome_url", "about:blank");
user_pref("webdriver_accept_untrusted_certs", true);
user_pref("webdriver_assume_untrusted_issuer", true);

user_pref("media.gmp-provider.enabled", false);
user_pref("browser.devedition.theme.enabled", true);
user_pref("lightweightThemes.update.enabled", false);
user_pref("devtools.chrome.enabled", true);

user_pref("extensions.logging.enabled", false);
user_pref("webdriver.log.init", true);
user_pref("webdriver.log.browser.ignore", true);
user_pref("webdriver.log.driver.ignore", true);
user_pref("webdriver.log.profiler.ignore", true);<|endoftext|>


<commit_before>"use strict";

function AudioManager() {
    this.reset();
}

/**
 * The AudioManager implements a queueing system to be used for audio narration
 * of demos. Objects can load media files which should be played, and when those
 * objects decide the media should be played (based on time, a button, or
 * whatever), they call `play`.
 */
AudioManager.prototype = {
    /**
     * Load a track so it will be ready to play in advance.
     */
    load: function(track) {
        var a = document.createElement('audio');
        a.setAttribute('src', 'demos/audio/' + track + '.ogg');
        a.load();
        this.tracks[track] = a;
    },

    /**
     * Play the track. Optionally provide onFinish, a callback which is called
     * when the audio has completed playing.
     */
    play: function(track, onFinish) {
        if (!(track in this.tracks)) {
            throw "Track '" + track + "' cannot be played before being loaded.";
        }

        if (this.currentTrack !== null) {
            // Another track is playing, so queue this one.
            this.queue.push({"track": track, "onFinish": onFinish});
            return;
        }

        if (onFinish) {
            this.tracks[track].addEventListener("ended", onFinish);
        }

        var endedCallback = $.proxy(this.playbackEnded, this);

        this.tracks[track].addEventListener("ended", endedCallback);
        this.tracks[track].play();
        this.currentTrack = track;
    },

    /**
     * When playback of the current track has ended, play the next track in the
     * queue, if necessary.
     */
    playbackEnded: function() {
        this.currentTrack = null;
        this.playFromQueue();
    },

    playFromQueue: function() {
        if (this.queue.length > 0) {
            var track = this.queue.shift();
            this.play(track.track, track.onFinish);
        }
    },

    /**
     * Pause current audio playback.
     */
    pause: function() {
        this.paused = true;
        if (this.currentTrack) {
            this.resumeTrack = true;
            this.tracks[this.currentTrack].pause();
        }
    },

    resume: function() {
        this.paused = false;
        if (this.currentTrack && this.resumeTrack) {
            this.tracks[this.currentTrack].play();
            this.resumeTrack = false;
        }
    },

    reset: function() {
        if (this.tracks) {
            $.each(this.tracks, function(name, track) {
                track.pause();
            });
        }

        this.tracks = {};
        this.currentTrack = null;
        this.queue = [];
        this.paused = false;
        this.resumeTrack = false;
    }
};
<commit_msg>No need for this temporary variable.<commit_after>"use strict";

function AudioManager() {
    this.reset();
}

/**
 * The AudioManager implements a queueing system to be used for audio narration
 * of demos. Objects can load media files which should be played, and when those
 * objects decide the media should be played (based on time, a button, or
 * whatever), they call `play`.
 */
AudioManager.prototype = {
    /**
     * Load a track so it will be ready to play in advance.
     */
    load: function(track) {
        var a = document.createElement('audio');
        a.setAttribute('src', 'demos/audio/' + track + '.ogg');
        a.load();
        this.tracks[track] = a;
    },

    /**
     * Play the track. Optionally provide onFinish, a callback which is called
     * when the audio has completed playing.
     */
    play: function(track, onFinish) {
        if (!(track in this.tracks)) {
            throw "Track '" + track + "' cannot be played before being loaded.";
        }

        if (this.currentTrack !== null) {
            // Another track is playing, so queue this one.
            this.queue.push({"track": track, "onFinish": onFinish});
            return;
        }

        if (onFinish) {
            this.tracks[track].addEventListener("ended", onFinish);
        }

        this.tracks[track].addEventListener("ended",
                                            $.proxy(this.playbackEnded, this));
        this.tracks[track].play();
        this.currentTrack = track;
    },

    /**
     * When playback of the current track has ended, play the next track in the
     * queue, if necessary.
     */
    playbackEnded: function() {
        this.currentTrack = null;
        this.playFromQueue();
    },

    playFromQueue: function() {
        if (this.queue.length > 0) {
            var track = this.queue.shift();
            this.play(track.track, track.onFinish);
        }
    },

    /**
     * Pause current audio playback.
     */
    pause: function() {
        this.paused = true;
        if (this.currentTrack) {
            this.resumeTrack = true;
            this.tracks[this.currentTrack].pause();
        }
    },

    resume: function() {
        this.paused = false;
        if (this.currentTrack && this.resumeTrack) {
            this.tracks[this.currentTrack].play();
            this.resumeTrack = false;
        }
    },

    reset: function() {
        if (this.tracks) {
            $.each(this.tracks, function(name, track) {
                track.pause();
            });
        }

        this.tracks = {};
        this.currentTrack = null;
        this.queue = [];
        this.paused = false;
        this.resumeTrack = false;
    }
};
<|endoftext|>


<commit_before>/*
 @author Zakai Hamilton
 @component KabTerms
 */

package.kab.terms = function KabTerms(me) {
    me.init = function () {
        me.json = null;
        me.terms = null;
        me.searchTerms = [];
        me.language = "english";
    };
    me.setLanguage = function (callback, language) {
        me.language = language.toLowerCase();
        me.core.json.load(function (json) {
            if (json) {
                me.json = json;
                var numTerms = 0;
                if (me.json.terms) {
                    numTerms = Object.keys(me.json.terms).length;
                }
                if (callback) {
                    callback(numTerms);
                }
            }
        }, "kab.terms_" + me.language);
    };
    me.parse = function (callback, wordsString, options) {
        if (!me.json) {
            if (callback) {
                callback(wordsString);
                return;
            }
            return wordsString;
        }
        var match = me.match;
        var modify = me.modify;
        var duplicateOptions = me.duplicateOptions;
        var parse = me.parse;
        var prefix = me.json.prefix;
        var suffix = me.json.suffix;
        var ignore = me.json.ignore;
        if (callback) {
            me.diagrams = {};
            me.searchTerms = {};
            wordsString = me.send("kab.terms.fixSpelling", wordsString);
            wordsString = me.send("kab.terms.format", wordsString, me.json.pre);
            me.terms = me.send("kab.terms.prepare", me.json.terms);
        }
        var terms = me.terms;
        if (terms) {
            wordsString = me.core.string.parseWords(function (words) {
                var wasPrefix = false;
                if(callback) {
                    for (var wordIndex = 0; wordIndex < words.length; wordIndex++) {
                        var word = words[wordIndex];
                        if(terms[word.toUpperCase()]) {
                            continue;
                        }
                        for(var letterIndex = word.length - 2; letterIndex > 1; letterIndex--) {
                            var firstSlice = word.slice(0, letterIndex);
                            var secondSlice = word.slice(letterIndex);
                            if(terms[firstSlice] && terms[secondSlice]) {
                                if(letterIndex < word.length) {
                                    words.splice(wordIndex, 1);
                                    words.splice(wordIndex, 0, firstSlice);
                                    words.splice(wordIndex+1, 0, secondSlice);
                                }
                                break;
                            }
                        }
                    }
                }
                for (var wordIndex = 0; wordIndex < words.length; wordIndex++) {
                    var word = words[wordIndex];
                    var isPrefix = prefix ? word.toLowerCase() in prefix : null;
                    if(isPrefix) {
                        wasPrefix = true;
                        continue;
                    }
                    word = word.toUpperCase();
                    var termLookup = terms[word];
                    if(!termLookup) {
                        wasPrefix = false;
                        continue;
                    }
                    if(wasPrefix) {
                        wordIndex--;
                        wasPrefix = false;
                    }
                    var subTermNames = termLookup["*"];
                    for (var subTermIndex = 0; subTermIndex < subTermNames.length; subTermIndex++) {
                        var term = subTermNames[subTermIndex];
                        var item = termLookup[term];
                        var prefixWord = null;
                        var suffixWord = null;
                        var numTermWords = item.numWords;
                        if(!item.numWords) {
                            numTermWords = item.numWords = term.split(" ").length;
                        }
                        if(item.suffix) {
                            numTermWords++;
                        }
                        var collectedWords = "";
                        for (var termWordIndex = 0; termWordIndex < numTermWords; termWordIndex++) {
                            if (wordIndex + termWordIndex >= words.length) {
                                break;
                            }
                            var word = words[wordIndex + termWordIndex];
                            var prefixTerm = prefix ? word.toLowerCase() in prefix : false;
                            var suffixTerm = suffix ? word.toLowerCase() in suffix : false;
                            var ignoreTerm = ignore ? ignore.includes(word) : false;
                            if (prefixTerm || ignoreTerm || suffixTerm) {
                                if (prefixTerm || suffixTerm || collectedWords) {
                                    if(prefixTerm) {
                                        prefixWord = word;
                                    }
                                    if(suffixTerm) {
                                        suffixWord = word;
                                    }
                                    numTermWords++;
                                    continue;
                                }
                            }
                            if (collectedWords) {
                                collectedWords += " " + word;
                            } else {
                                collectedWords = word;
                            }
                        }
                        var span = numTermWords;
                        var source = collectedWords;
                        var target = term;
                        var upperCase = false;
                        if (!match(item, source, target)) {
                            if(!item.case || item.case !== "sensitive") {
                                if (!match(item, source, target.toUpperCase())) {
                                    continue;
                                }
                                else {
                                    upperCase = true;
                                }
                            }
                            else {
                                continue;
                            }
                        }
                        var expansion = item.expansion;
                        var translation = item.translation;
                        var reorder = item.reorder;
                        if (expansion) {
                            if(Array.isArray(expansion)) {
                                expansion = expansion.map(function (text) {
                                    if(!text.includes(term)) {
                                        text = parse(null, text, options);
                                    }
                                    return text;
                                });
                                if (expansion.length > 1) {
                                    expansion = expansion.slice(0, -1).join(", ") + " and " + expansion.slice(-1).toString();
                                } else {
                                    expansion = expansion.slice(-1).toString();
                                }
                            }
                            else {
                                expansion = parse(null, expansion, options);
                            }
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, " (", expansion, ")", options, true);
                        }
                        else if (options.doTranslation && translation) {
                            if (!item.name) {
                                translation = me.parse(null, translation, duplicateOptions(options, {"addStyles": false}));
                            }
                            if(!("search" in item) || item.search === true) {
                                var usedTerm = me.searchTerms[translation];
                                if(!usedTerm) {
                                    usedTerm = me.searchTerms[translation] = {count:0};
                                }
                                usedTerm.count++;
                                if(item.label) {
                                    usedTerm.label = item.label;
                                }
                                else {
                                    usedTerm.label = source;
                                }
                            }
                            if(upperCase) {
                                translation = translation.toUpperCase();
                            }
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, " [", translation, "]", options);
                        }
                        else if(options.doTranslation && !options.keepSource && reorder) {
                            words.splice(wordIndex, span);
                            words.splice(wordIndex, 0, ...reorder);
                            wordIndex--;
                        }
                        else if (options.addStyles && item.style) {
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, "", source, "", duplicateOptions(options, {"keepSource": false}));
                        }
                        break;
                    }
                }
            }, wordsString);
        }
        if (callback) {
            if (me.language !== "debug") {
                wordsString = me.send("kab.terms.format", wordsString, me.json.post);
                wordsString = me.send("kab.terms.removeDuplicates", wordsString, "(", ")");
                wordsString = me.send("kab.terms.removeDuplicates", wordsString, "[", "]");
            }
            callback(wordsString, me.searchTerms);
            return;
        }
        return wordsString;
    };
    me.insert = function(words, wordIndex, collection, defaultWord, wordToInsert, text) {
        if(collection && wordToInsert) {
            for(var itemName in collection) {
                var item = collection[itemName];
                if(!item.match) {
                    continue;
                }
                if(itemName !== wordToInsert.toLowerCase()) {
                    continue;
                }
                if(!defaultWord) {
                    for(var altPrefix in collection) {
                        var altPrefixItem = collection[altPrefix];
                        if(altPrefixItem.match && text.match(me.core.string.regex(altPrefixItem.match))) {
                            defaultWord = altPrefix;
                            if(wordToInsert[0] === wordToInsert[0].toUpperCase()) {
                                defaultWord = defaultWord.charAt(0).toUpperCase() + defaultWord.slice(1);
                            }
                            wordToInsert = null;
                            break;
                        }
                    }
                }
                break;
            }
        }
        if(defaultWord && !wordToInsert) {
            var item = collection[defaultWord.toLowerCase()];
            if(item && item.replaceOnly) {
                defaultWord = null;
            }
        }
        if(wordToInsert) {
            words.splice(wordIndex, 0, wordToInsert);
        }
        else if (defaultWord) {
            words.splice(wordIndex, 0, defaultWord);
        }
    };
    me.removeFormatting = function (string) {
        string = string.replace(/\ kab-term-tooltip=".*?"/g, "");
        string = string.replace(/\ kab-term-heading=".*?"/g, "");
        string = string.replace(/\ class=".*?"/g, "");
        string = string.replace(/<\/?p>/g, "");
        string = string.replace(/<\/?span>/g, "");
        string = string.replace(/ and/g, ",");
        string = string.toLowerCase();
        return string;
    };
    me.removeDuplicates = function (wordsString, openChar, closeChar) {
        var parts = wordsString.split(me.core.string.regex("/(\\" + openChar + ".*?\\" + closeChar + ")"));
        for (var i = 0; i < parts.length - 1; i++) {
            var fragment = parts[i + 1];
            if (fragment.match(me.core.string.regex("/\\" + openChar + "\\d+\\" + closeChar))) {
                i++;
                continue;
            }
            if (fragment.startsWith(openChar) && fragment.endsWith(closeChar)) {
                var fragment = fragment.slice(1, -1);
                if (me.removeFormatting(parts[i]).includes(me.removeFormatting(fragment))) {
                    parts.splice(i + 1, 1);
                    i--;
                    continue;
                }
            }
        }
        wordsString = parts.join("");
        return wordsString;
    };
    me.fixSpelling = function(wordsString) {
        var spelling = me.json.spelling;
        if(spelling) {
            for(var incorrect in spelling) {
                var correct = spelling[incorrect];
                wordsString = wordsString.split(incorrect).join(correct);
            }
        }
        return wordsString;
    };
    me.format = function (wordsString, dict) {
        if (dict) {
            dict.map(function (item) {
                if ("enabled" in item && !item.enabled) {
                    return;
                }
                if (item.match) {
                    var checkInSplit = false;
                    var itemSplit = "\n";
                    if ("split" in item) {
                        itemSplit = me.core.string.regex(item.split);
                        checkInSplit = item.split.startsWith("/");
                    }
                    var itemJoin = itemSplit;
                    if ("join" in item) {
                        itemJoin = item.join;
                    }
                    wordsString = wordsString.split(itemSplit).map(function (selection) {
                        var inSplit = selection.match(itemSplit);
                        var matches = selection.match(me.core.string.regex(item.match));
                        if (matches && (inSplit || !checkInSplit)) {
                            if (item.prefix) {
                                selection = item.prefix + selection;
                            }
                            if (item.suffix) {
                                selection += item.suffix;
                            }
                            var find = item.find;
                            if (find) {
                                selection = selection.replace(me.core.string.regex(find), me.core.string.regex(item.replace));
                            }
                        }
                        return selection;
                    }).join(itemJoin);
                    return;
                }
                var find = item.find;
                if (find && (item.prefix || item.suffix)) {
                    wordsString = wordsString.split(me.core.string.regex(find)).join(item.replace);
                    if (item.prefix) {
                        wordsString = item.prefix + wordsString;
                    }
                    if (item.suffix) {
                        wordsString = wordsString + item.suffix;
                    }
                } else if (find) {
                    wordsString = wordsString.replace(me.core.string.regex(find), me.core.string.regex(item.replace));
                }
            });
        }
        return wordsString;
    };
    me.toCase = function (item, string) {
        var itemCase = "insensitive";
        if (item.case) {
            itemCase = item.case;
        }
        if (itemCase !== "sensitive") {
            string = string.toUpperCase();
        }
        return string;
    };
    me.match = function (item, source, target) {
        var wordStyle = "whole";
        if (item.word) {
            wordStyle = item.word;
        }
        if (wordStyle === "whole") {
            return source === target;
        } else if (wordStyle === "prefix") {
            return source.beginsWith(target);
        } else if (wordStyle === "suffix") {
            return source.endsWith(target);
        } else {
            return source.includes(target);
        }
    };
    me.duplicateOptions = function (options, overrides) {
        var duplicate = {};
        for (var key in options) {
            duplicate[key] = options[key];
        }
        if (overrides) {
            for (var key in overrides) {
                duplicate[key] = overrides[key];
            }
        }
        return duplicate;
    };
    me.modify = function (words, wordIndex, sourceLength, prefixWord, suffixWord, item, term, prefix, replacement, suffix, options, expansion) {
        words.splice(wordIndex, sourceLength);
        if(item.source) {
            term = item.source;
        }
        if (!options.doTranslation) {
            replacement = term;
        } else if (options.keepSource) {
            replacement = term + prefix + replacement + suffix;
        }
        var text = replacement;
        if (options.addStyles && (item.style || replacement !== term)) {
            replacement = me.applyStyles(term, item.style, replacement, options, expansion);
        }
        words.splice(wordIndex, 0, replacement);
        me.insert(words, wordIndex, me.json.prefix, item.prefix, prefixWord, text);
        me.insert(words, wordIndex+1, me.json.suffix, item.suffix, suffixWord, text);
    };
    me.applyStyles = function (term, styles, text, options, expansion) {
        var html = "";
        if (styles && styles.diagram && me.json.diagrams) {
            if (!me.diagrams[styles.diagram]) {
                var diagram = me.json.diagrams[styles.diagram];
                html += "";
                html += "" + diagram.title + "";
                html += "";
            }
            me.diagrams[styles.diagram] = true;
        }
        if (styles && styles.bold) {
            html += "";
        }
        if (styles && styles.phase) {
            html += "" + text + "";
        } else if (!options.keepSource && !expansion) {
            html += "" + text + "";
        } else {
            html += text;
        }
        if (styles && styles.bold) {
            html += "";
        }
        return html;
    };
    me.prepare = function(terms) {
        var result = new Map();
        for(var term in terms) {
            var info = terms[term];
            var words = term.split(" ");
            var key = words[0].toUpperCase();
            var lookup = result[key];
            if(!lookup) {
                lookup = new Map();
                result[key] = lookup;
                result[words[0]] = lookup;
            }
            lookup[term] = info;
        }
        for(var term in result) {
            var lookup = result[term];
            me.sortKeys(lookup);
        }
        me.sortKeys(result);
        return result;
    };
    me.sortKeys = function(dict) {
        var keys = Object.keys(dict);
        keys = keys.sort(function (source, target) {
            return target.length - source.length;
        });
        keys = keys.filter(function(key) {
            return !key.startsWith("!");
        });
        dict["*"] = keys;
    };
};<commit_msg>bug fix<commit_after>/*
 @author Zakai Hamilton
 @component KabTerms
 */

package.kab.terms = function KabTerms(me) {
    me.init = function () {
        me.json = null;
        me.terms = null;
        me.searchTerms = [];
        me.language = "english";
    };
    me.setLanguage = function (callback, language) {
        me.language = language.toLowerCase();
        me.core.json.load(function (json) {
            if (json) {
                me.json = json;
                var numTerms = 0;
                if (me.json.terms) {
                    numTerms = Object.keys(me.json.terms).length;
                }
                if (callback) {
                    callback(numTerms);
                }
            }
        }, "kab.terms_" + me.language);
    };
    me.parse = function (callback, wordsString, options) {
        if (!me.json) {
            if (callback) {
                callback(wordsString);
                return;
            }
            return wordsString;
        }
        var match = me.match;
        var modify = me.modify;
        var duplicateOptions = me.duplicateOptions;
        var parse = me.parse;
        var prefix = me.json.prefix;
        var suffix = me.json.suffix;
        var ignore = me.json.ignore;
        if (callback) {
            me.diagrams = {};
            me.searchTerms = {};
            wordsString = me.send("kab.terms.fixSpelling", wordsString);
            wordsString = me.send("kab.terms.format", wordsString, me.json.pre);
            me.terms = me.send("kab.terms.prepare", me.json.terms);
        }
        var terms = me.terms;
        if (terms) {
            wordsString = me.core.string.parseWords(function (words) {
                var wasPrefix = false;
                if(callback) {
                    for (var wordIndex = 0; wordIndex < words.length; wordIndex++) {
                        var word = words[wordIndex];
                        if(terms[word.toUpperCase()]) {
                            continue;
                        }
                        for(var letterIndex = word.length - 2; letterIndex > 1; letterIndex--) {
                            var firstSlice = word.slice(0, letterIndex);
                            var secondSlice = word.slice(letterIndex);
                            if(terms[firstSlice] && terms[secondSlice]) {
                                if(letterIndex < word.length) {
                                    words.splice(wordIndex, 1);
                                    words.splice(wordIndex, 0, firstSlice);
                                    words.splice(wordIndex+1, 0, secondSlice);
                                }
                                break;
                            }
                        }
                    }
                }
                for (var wordIndex = 0; wordIndex < words.length; wordIndex++) {
                    var word = words[wordIndex];
                    var isPrefix = prefix ? word.toLowerCase() in prefix : null;
                    if(isPrefix) {
                        wasPrefix = true;
                        continue;
                    }
                    word = word.toUpperCase();
                    var termLookup = terms[word];
                    if(!termLookup) {
                        wasPrefix = false;
                        continue;
                    }
                    if(wasPrefix) {
                        wordIndex--;
                        wasPrefix = false;
                    }
                    var subTermNames = termLookup["*"];
                    for (var subTermIndex = 0; subTermIndex < subTermNames.length; subTermIndex++) {
                        var term = subTermNames[subTermIndex];
                        var item = termLookup[term];
                        var prefixWord = null;
                        var suffixWord = null;
                        var numTermWords = item.numWords;
                        if(!item.numWords) {
                            numTermWords = item.numWords = term.split(" ").length;
                        }
                        if(item.suffix) {
                            numTermWords++;
                        }
                        var collectedWords = "";
                        for (var termWordIndex = 0; termWordIndex < numTermWords; termWordIndex++) {
                            if (wordIndex + termWordIndex >= words.length) {
                                break;
                            }
                            var word = words[wordIndex + termWordIndex];
                            var prefixTerm = prefix ? word.toLowerCase() in prefix : false;
                            var suffixTerm = suffix ? word.toLowerCase() in suffix : false;
                            var ignoreTerm = ignore ? ignore.includes(word) : false;
                            if (prefixTerm || ignoreTerm || suffixTerm) {
                                if (prefixTerm || suffixTerm || collectedWords) {
                                    if(prefixTerm) {
                                        prefixWord = word;
                                    }
                                    if(suffixTerm) {
                                        suffixWord = word;
                                    }
                                    numTermWords++;
                                    continue;
                                }
                            }
                            if (collectedWords) {
                                collectedWords += " " + word;
                            } else {
                                collectedWords = word;
                            }
                        }
                        var span = numTermWords;
                        var source = collectedWords;
                        var target = term;
                        var upperCase = false;
                        if (!match(item, source, target)) {
                            if(!item.case || item.case !== "sensitive") {
                                if (!match(item, source, target.toUpperCase())) {
                                    continue;
                                }
                                else {
                                    upperCase = true;
                                }
                            }
                            else {
                                continue;
                            }
                        }
                        var expansion = item.expansion;
                        var translation = item.translation;
                        var reorder = item.reorder;
                        if (expansion) {
                            if(Array.isArray(expansion)) {
                                expansion = expansion.map(function (text) {
                                    if(!text.includes(term)) {
                                        text = parse(null, text, options);
                                    }
                                    return text;
                                });
                                if (expansion.length > 1) {
                                    expansion = expansion.slice(0, -1).join(", ") + " and " + expansion.slice(-1).toString();
                                } else {
                                    expansion = expansion.slice(-1).toString();
                                }
                            }
                            else {
                                expansion = parse(null, expansion, options);
                            }
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, " (", expansion, ")", options, true);
                        }
                        else if (options.doTranslation && translation) {
                            if (!item.name) {
                                translation = me.parse(null, translation, duplicateOptions(options, {"addStyles": false}));
                            }
                            if(!("search" in item) || item.search === true) {
                                var usedTerm = me.searchTerms[translation];
                                if(!usedTerm) {
                                    usedTerm = me.searchTerms[translation] = {count:0};
                                }
                                usedTerm.count++;
                                if(item.label) {
                                    usedTerm.label = item.label;
                                }
                                else {
                                    usedTerm.label = term;
                                }
                            }
                            if(upperCase) {
                                translation = translation.toUpperCase();
                            }
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, " [", translation, "]", options);
                        }
                        else if(options.doTranslation && !options.keepSource && reorder) {
                            words.splice(wordIndex, span);
                            words.splice(wordIndex, 0, ...reorder);
                            wordIndex--;
                        }
                        else if (options.addStyles && item.style) {
                            modify(words, wordIndex, span, prefixWord, suffixWord, item, source, "", source, "", duplicateOptions(options, {"keepSource": false}));
                        }
                        break;
                    }
                }
            }, wordsString);
        }
        if (callback) {
            if (me.language !== "debug") {
                wordsString = me.send("kab.terms.format", wordsString, me.json.post);
                wordsString = me.send("kab.terms.removeDuplicates", wordsString, "(", ")");
                wordsString = me.send("kab.terms.removeDuplicates", wordsString, "[", "]");
            }
            callback(wordsString, me.searchTerms);
            return;
        }
        return wordsString;
    };
    me.insert = function(words, wordIndex, collection, defaultWord, wordToInsert, text) {
        if(collection && wordToInsert) {
            for(var itemName in collection) {
                var item = collection[itemName];
                if(!item.match) {
                    continue;
                }
                if(itemName !== wordToInsert.toLowerCase()) {
                    continue;
                }
                if(!defaultWord) {
                    for(var altPrefix in collection) {
                        var altPrefixItem = collection[altPrefix];
                        if(altPrefixItem.match && text.match(me.core.string.regex(altPrefixItem.match))) {
                            defaultWord = altPrefix;
                            if(wordToInsert[0] === wordToInsert[0].toUpperCase()) {
                                defaultWord = defaultWord.charAt(0).toUpperCase() + defaultWord.slice(1);
                            }
                            wordToInsert = null;
                            break;
                        }
                    }
                }
                break;
            }
        }
        if(defaultWord && !wordToInsert) {
            var item = collection[defaultWord.toLowerCase()];
            if(item && item.replaceOnly) {
                defaultWord = null;
            }
        }
        if(wordToInsert) {
            words.splice(wordIndex, 0, wordToInsert);
        }
        else if (defaultWord) {
            words.splice(wordIndex, 0, defaultWord);
        }
    };
    me.removeFormatting = function (string) {
        string = string.replace(/\ kab-term-tooltip=".*?"/g, "");
        string = string.replace(/\ kab-term-heading=".*?"/g, "");
        string = string.replace(/\ class=".*?"/g, "");
        string = string.replace(/<\/?p>/g, "");
        string = string.replace(/<\/?span>/g, "");
        string = string.replace(/ and/g, ",");
        string = string.toLowerCase();
        return string;
    };
    me.removeDuplicates = function (wordsString, openChar, closeChar) {
        var parts = wordsString.split(me.core.string.regex("/(\\" + openChar + ".*?\\" + closeChar + ")"));
        for (var i = 0; i < parts.length - 1; i++) {
            var fragment = parts[i + 1];
            if (fragment.match(me.core.string.regex("/\\" + openChar + "\\d+\\" + closeChar))) {
                i++;
                continue;
            }
            if (fragment.startsWith(openChar) && fragment.endsWith(closeChar)) {
                var fragment = fragment.slice(1, -1);
                if (me.removeFormatting(parts[i]).includes(me.removeFormatting(fragment))) {
                    parts.splice(i + 1, 1);
                    i--;
                    continue;
                }
            }
        }
        wordsString = parts.join("");
        return wordsString;
    };
    me.fixSpelling = function(wordsString) {
        var spelling = me.json.spelling;
        if(spelling) {
            for(var incorrect in spelling) {
                var correct = spelling[incorrect];
                wordsString = wordsString.split(incorrect).join(correct);
            }
        }
        return wordsString;
    };
    me.format = function (wordsString, dict) {
        if (dict) {
            dict.map(function (item) {
                if ("enabled" in item && !item.enabled) {
                    return;
                }
                if (item.match) {
                    var checkInSplit = false;
                    var itemSplit = "\n";
                    if ("split" in item) {
                        itemSplit = me.core.string.regex(item.split);
                        checkInSplit = item.split.startsWith("/");
                    }
                    var itemJoin = itemSplit;
                    if ("join" in item) {
                        itemJoin = item.join;
                    }
                    wordsString = wordsString.split(itemSplit).map(function (selection) {
                        var inSplit = selection.match(itemSplit);
                        var matches = selection.match(me.core.string.regex(item.match));
                        if (matches && (inSplit || !checkInSplit)) {
                            if (item.prefix) {
                                selection = item.prefix + selection;
                            }
                            if (item.suffix) {
                                selection += item.suffix;
                            }
                            var find = item.find;
                            if (find) {
                                selection = selection.replace(me.core.string.regex(find), me.core.string.regex(item.replace));
                            }
                        }
                        return selection;
                    }).join(itemJoin);
                    return;
                }
                var find = item.find;
                if (find && (item.prefix || item.suffix)) {
                    wordsString = wordsString.split(me.core.string.regex(find)).join(item.replace);
                    if (item.prefix) {
                        wordsString = item.prefix + wordsString;
                    }
                    if (item.suffix) {
                        wordsString = wordsString + item.suffix;
                    }
                } else if (find) {
                    wordsString = wordsString.replace(me.core.string.regex(find), me.core.string.regex(item.replace));
                }
            });
        }
        return wordsString;
    };
    me.toCase = function (item, string) {
        var itemCase = "insensitive";
        if (item.case) {
            itemCase = item.case;
        }
        if (itemCase !== "sensitive") {
            string = string.toUpperCase();
        }
        return string;
    };
    me.match = function (item, source, target) {
        var wordStyle = "whole";
        if (item.word) {
            wordStyle = item.word;
        }
        if (wordStyle === "whole") {
            return source === target;
        } else if (wordStyle === "prefix") {
            return source.beginsWith(target);
        } else if (wordStyle === "suffix") {
            return source.endsWith(target);
        } else {
            return source.includes(target);
        }
    };
    me.duplicateOptions = function (options, overrides) {
        var duplicate = {};
        for (var key in options) {
            duplicate[key] = options[key];
        }
        if (overrides) {
            for (var key in overrides) {
                duplicate[key] = overrides[key];
            }
        }
        return duplicate;
    };
    me.modify = function (words, wordIndex, sourceLength, prefixWord, suffixWord, item, term, prefix, replacement, suffix, options, expansion) {
        words.splice(wordIndex, sourceLength);
        if(item.source) {
            term = item.source;
        }
        if (!options.doTranslation) {
            replacement = term;
        } else if (options.keepSource) {
            replacement = term + prefix + replacement + suffix;
        }
        var text = replacement;
        if (options.addStyles && (item.style || replacement !== term)) {
            replacement = me.applyStyles(term, item.style, replacement, options, expansion);
        }
        words.splice(wordIndex, 0, replacement);
        me.insert(words, wordIndex, me.json.prefix, item.prefix, prefixWord, text);
        me.insert(words, wordIndex+1, me.json.suffix, item.suffix, suffixWord, text);
    };
    me.applyStyles = function (term, styles, text, options, expansion) {
        var html = "";
        if (styles && styles.diagram && me.json.diagrams) {
            if (!me.diagrams[styles.diagram]) {
                var diagram = me.json.diagrams[styles.diagram];
                html += "";
                html += "" + diagram.title + "";
                html += "";
            }
            me.diagrams[styles.diagram] = true;
        }
        if (styles && styles.bold) {
            html += "";
        }
        if (styles && styles.phase) {
            html += "" + text + "";
        } else if (!options.keepSource && !expansion) {
            html += "" + text + "";
        } else {
            html += text;
        }
        if (styles && styles.bold) {
            html += "";
        }
        return html;
    };
    me.prepare = function(terms) {
        var result = new Map();
        for(var term in terms) {
            var info = terms[term];
            var words = term.split(" ");
            var key = words[0].toUpperCase();
            var lookup = result[key];
            if(!lookup) {
                lookup = new Map();
                result[key] = lookup;
                result[words[0]] = lookup;
            }
            lookup[term] = info;
        }
        for(var term in result) {
            var lookup = result[term];
            me.sortKeys(lookup);
        }
        me.sortKeys(result);
        return result;
    };
    me.sortKeys = function(dict) {
        var keys = Object.keys(dict);
        keys = keys.sort(function (source, target) {
            return target.length - source.length;
        });
        keys = keys.filter(function(key) {
            return !key.startsWith("!");
        });
        dict["*"] = keys;
    };
};<|endoftext|>


<commit_before>function SystemMessage(content) {
	this.content = content;
}

module.exports.SystemMessage = SystemMessage;<commit_msg>Modify system notification. Change name and the entire prototype.<commit_after><|endoftext|>


<commit_before>module.exports = function (config) {
  config.set({
    basePath: '..',
    frameworks: ['mocha'],
    reporters: ['mocha'],
    files: ['test/build/bundle.js'],
    port: 9876,
    colors: true,
    singleRun: true,
    logLevel: config.LOG_INFO
  });
};
<commit_msg>Up controls test activity timeout<commit_after>module.exports = function (config) {
  config.set({
    basePath: '..',
    frameworks: ['mocha'],
    reporters: ['mocha'],
    files: ['test/build/bundle.js'],
    port: 9876,
    colors: true,
    singleRun: true,
    logLevel: config.LOG_INFO,
    browserNoActivityTimeout: 30000
  });
};
<|endoftext|>


<commit_before>var fs = require('fs');
var Discord = require('discord.js');
var youtubeStream = require('youtube-audio-stream');
var bot = new Discord.Client();
var token = null;

try {
    token = fs.readFileSync('token', 'utf8');
} catch (err) {
    console.log('Could not open token file');
    process.exit();
}

bot.on('ready', () => {
    console.log('Bot ready');
});

bot.on('message', msg => {
    let prefix = '.';

    // if not a bot command or message was sent from bot then do nothing
    if (!(msg.content.startsWith(prefix)) || msg.author.bot) {
        return;
    }

    if (msg.content.startsWith(prefix + 'play')) {
        // print message if author is not in a voice channel
        var msgSender = msg.author.id;
        // get all voice channels and check if the sender is one of them
        // only get channels from the server that the message was sent from
        var allChannels = msg.guild.channels.array();
        // filter for voice channels
        var voiceChannels = [];
        for (let i = 0; i < allChannels.length; i++) {
            if (allChannels[i].type === 'voice') {
                voiceChannels.push(allChannels[i]);
            }
        }
        // check for the voice channel the sender is in, return if not in one
        var channelToStream = null;
        for (let i = 0; i < voiceChannels.length; i++) {
            let channelMembers = voiceChannels[i].members.array();
            let channelFound = false;
            for (let j = 0; j < channelMembers.length; j++) {
                if (channelMembers[i].id === msgSender) {
                    channelToStream = voiceChannels[i];
                    channelFound = true;
                    break;
                }
            }
            if (channelFound) {
                break;
            }
        }
        if (channelToStream === null) {
            msg.channel.sendMessage('You must be in a voice channel to play a song.');
            return;
        }
    }
});

bot.login(token);<commit_msg>added youtube audio streaming functionality<commit_after>var fs = require('fs');
var Discord = require('discord.js');
var youtubeStream = require('youtube-audio-stream');
var bot = new Discord.Client();
var token = null;

try {
    token = fs.readFileSync('token', 'utf8');
} catch (err) {
    console.log('Could not open token file');
    process.exit();
}

bot.on('ready', () => {
    console.log('Bot ready');
});

bot.on('message', msg => {
    let prefix = '.';

    // if not a bot command or message was sent from bot then do nothing
    if (!(msg.content.startsWith(prefix)) || msg.author.bot) {
        return;
    }

    if (msg.content.startsWith(prefix + 'play')) {
        // print message if author is not in a voice channel
        var msgSender = msg.author.id;
        // get all voice channels and check if the sender is one of them
        // only get channels from the server that the message was sent from
        var allChannels = msg.guild.channels.array();
        // filter for voice channels
        var voiceChannels = [];
        for (let i = 0; i < allChannels.length; i++) {
            if (allChannels[i].type === 'voice') {
                voiceChannels.push(allChannels[i]);
            }
        }
        // check for the voice channel the sender is in, return if not in one
        var channelToStream = null;
        for (let i = 0; i < voiceChannels.length; i++) {
            let channelMembers = voiceChannels[i].members.array();
            let channelFound = false;
            for (let j = 0; j < channelMembers.length; j++) {
                if (channelMembers[i].id === msgSender) {
                    channelToStream = voiceChannels[i];
                    channelFound = true;
                    break;
                }
            }
            if (channelFound) {
                break;
            }
        }
        if (channelToStream === null) {
            msg.channel.sendMessage('You must be in a voice channel to play a song.');
            return;
        }

        // join the voice channel and stream the video
        var songUrl = msg.content.split(' ')[1];
        channelToStream.join().then(connection => {
            connection.playStream(youtubeStream(songUrl));
        });
    }
});

bot.login(token);<|endoftext|>


<commit_before>var BufferedReader = require ("../build/buffered-reader");

new BufferedReader ("file", { start: 3, end: 6 }).seek (1, function (error){
	if (error) return console.log (error);

	this.readBytes (10, function (error, bytes, bytesRead){
		if (error) return console.log (error);

		console.log (bytes); //Prints: 0x44 0x55 0x66
		console.log ("bytes read: " + bytesRead); //Prints: 3

		this.close (function (error){
			if (error) console.log (error);
		});
	});
});<commit_msg>updated example<commit_after>var BufferedReader = require ("../build/buffered-reader");

new BufferedReader ("file", { start: 3, end: 6 })
	.seek (1, function (error){
	if (error) return console.log (error);

	//The cursor points to 0x44 (start 3 + seek 1 = 4, from 0)
	this.readBytes (10, function (error, bytes, bytesRead){
		if (error) return console.log (error);

		console.log (bytes); //Prints: 0x44 0x55 0x66 (end 6, from 0)
		console.log ("bytes read: " + bytesRead); //Prints: 3

		this.close (function (error){
			if (error) console.log (error);
		});
	});
});<|endoftext|>


<commit_before>/*
 * Copyright (C) DreamLab Onet.pl Sp. z o. o.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

var uriparser = require("../build/default/uriparser");
var assert = require('assert');
var undef;

var url = "http://eloszka.pl";
url = uriparser.parse(url);
console.log(url);
assert.equal(url.protocol, "http:");
assert.equal(url.auth, undef);
assert.equal(url.host, "eloszka.pl");
assert.equal(url.port, undef);
assert.equal(url.query, undef);
assert.equal(url.fragment, undef);
assert.equal(url.path, "/");

var url = "http://eloszka.pl/";
url = uriparser.parse(url);
console.log(url);
assert.equal(url.protocol, "http:");
assert.equal(url.auth, undef);
assert.equal(url.host, "eloszka.pl");
assert.equal(url.port, undef);
assert.equal(url.query, undef);
assert.equal(url.fragment, undef);
assert.equal(url.path, "/");

var url = "/1.txt?test1=okok";
url = uriparser.parse(url);
console.log(url);
assert.equal(url.protocol, undef);
assert.equal(url.auth, undef);
assert.equal(url.host, undef);
assert.equal(url.port, undef);
assert.deepEqual(url.query, {test1: "okok"});
assert.equal(url.fragment, undef);
assert.equal(url.path, "/1.txt");
<commit_msg>Cleanup<commit_after><|endoftext|>


<commit_before>var async = require('async');
var BaaSClient = require('./client');

function BaaSPool (options, done) {
  var size = options.size || 5;
  var created = 0;
  var clients = this._clients = [];

  async.whilst(
    function () { return created < size; },
    function (done) {
      clients.push(new BaaSClient(options, done));
      created++;
    }, done);
}

BaaSPool.prototype.compare = function () {
  var client = this._clients.shift();
  client.compare.apply(client, arguments);
  this._clients.push(client);
};

BaaSPool.prototype.hash = function () {
  var client = this._clients.shift();
  client.hash.apply(client, arguments);
  this._clients.push(client);
};

module.exports = BaaSPool;<commit_msg>improve pool<commit_after>var async = require('async');
var BaaSClient = require('./client');

function BaaSPool (options, done) {
  var size = options.size || 5;
  var created = 0;
  var clients = this._clients = [];

  this._current_client = 0;

  async.whilst(
    function () { return created < size; },
    function (done) {
      clients.push(new BaaSClient(options, done));
      created++;
    }, done);
}

BaaSPool.prototype._getClient = function () {
  this._current_client++;

  if (this._current_client >= this._clients.length) {
    this._current_client = 0;
  }

  return this._clients[this._current_client];
};

BaaSPool.prototype.compare = function () {
  var client = this._getClient();
  client.compare.apply(client, arguments);
};

BaaSPool.prototype.hash = function () {
  var client = this._getClient();
  client.hash.apply(client, arguments);
};

module.exports = BaaSPool;<|endoftext|>


<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
  StyleSheet,
  Text,
  Image,
  View,
  Animated
} from 'react-native';

import { getTouchableComponent } from './utils/touchable';

const DEFAULT_MARGIN = 8;

class FloatingActionItem extends Component {
  constructor(props) {
    super(props);

    this.animation = new Animated.Value(0);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.active !== this.props.active) {
      Animated.spring(this.animation, { toValue: nextProps.active ? 1 : 0 }).start();
    }
  }

  handleOnPress = () => {
    const { name, onPress } = this.props;

    onPress(name);
  };

  renderText() {
    const {
      // @deprecated in favor of textElevation
      elevation, // eslint-disable-line
      text,
      position,
      textElevation,
      textBackground,
      textColor
    } = this.props;

    if (elevation !== undefined) {
      console.warn('FloatingActionItem: "elevation" property was deprecated. Please use "textElevation"');
    }

    if (text) {
      return (
        <View
          key="text"
          style={[
            styles.textContainer,
            styles[`${position}TextContainer`],
            {
              backgroundColor: textBackground,
              elevation: textElevation || elevation
            }]
          }
        >
          <Text
            style={[
              styles.text,
              {
                color: textColor
              }
            ]}
          >
            {text}
          </Text>
        </View>
      );
    }

    return null;
  }

  renderButton() {
    const { icon, color } = this.props;

    let iconStyle;

    if (icon && icon.uri) {
      iconStyle = styles.iconLogo;
    } else {
      iconStyle = styles.icon;
    }

    return (
      <View key="button" style={[styles.button, { backgroundColor: color }]}>
        {
          React.isValidElement(icon) ? icon : <Image style={iconStyle} source={icon} />
        }
      </View>
    );
  }

  render() {
    const { position, distanceToEdge, paddingTopBottom } = this.props;
    const Touchable = getTouchableComponent(false);

    const animatedActionContainerStyle = {
      marginBottom: this.animation.interpolate({
        inputRange: [0, 1],
        outputRange: [5, 10]
      })
    };

    const components = [];
    const distanceToEdgeActionContainer = {};

    if (position === 'left') {
      components.push(this.renderButton());
      components.push(this.renderText());
      distanceToEdgeActionContainer.paddingLeft = distanceToEdge + DEFAULT_MARGIN;
    } else if (position === 'right') {
      components.push(this.renderText());
      components.push(this.renderButton());
      distanceToEdgeActionContainer.paddingRight = distanceToEdge + DEFAULT_MARGIN;
    } else {
      components.push(this.renderButton());
    }

    return (
      <Touchable activeOpacity={0.4} style={styles.container} onPress={this.handleOnPress}>
        <Animated.View
          style={[
            styles.actionContainer,
            animatedActionContainerStyle,
            styles[`${position}ActionContainer`],
            distanceToEdgeActionContainer,
            {
              paddingTop: paddingTopBottom,
              paddingBottom: paddingTopBottom
            }
          ]}
        >
          {components}
        </Animated.View>
      </Touchable>
    );
  }
}

FloatingActionItem.propTypes = {
  color: PropTypes.string,
  icon: PropTypes.any,
  name: PropTypes.string.isRequired,
  text: PropTypes.string,
  textBackground: PropTypes.string,
  textColor: PropTypes.string,
  // not on doc
  textElevation: PropTypes.number,
  // not modified by user
  position: PropTypes.oneOf(['left', 'right', 'center']),
  active: PropTypes.bool,
  distanceToEdge: PropTypes.number,
  paddingTopBottom: PropTypes.number, // modified by parent property "actionsPaddingTopBottom"
  onPress: PropTypes.func
};

FloatingActionItem.defaultProps = {
  color: '#1253bc',
  distanceToEdge: 30,
  textElevation: 5,
  textColor: '#444444',
  textBackground: '#ffffff'
};

const styles = StyleSheet.create({
  container: {
    elevation: 0,
    flex: 1,
    flexDirection: 'column'
  },
  actionContainer: {
    elevation: 0,
    flex: 1,
    flexDirection: 'row',
    paddingLeft: 10,
    paddingRight: 10,
    paddingBottom: 8,
    paddingTop: 8
  },
  centerActionContainer: {
    paddingLeft: 10,
    paddingRight: 10
  },
  textContainer: {
    paddingHorizontal: 8,
    shadowOpacity: 0.35,
    shadowOffset: {
      width: 0,
      height: 5
    },
    shadowColor: '#000000',
    shadowRadius: 3,
    elevation: 5,
    borderRadius: 4,
    height: 22,
    marginTop: 8
  },
  leftTextContainer: {
    marginLeft: 14
  },
  rightTextContainer: {
    marginRight: 14
  },
  text: {
    fontSize: 14,
    lineHeight: 20
  },
  button: {
    alignItems: 'center',
    justifyContent: 'center',
    width: 40,
    height: 40,
    borderRadius: 20,
    shadowOpacity: 0.35,
    shadowOffset: {
      width: 0,
      height: 5
    },
    shadowColor: '#000000',
    shadowRadius: 3,
    elevation: 5
  },
  iconLogo: {
    resizeMode: 'cover',
    width: 40,
    height: 40,
    borderRadius: 20
  },
  icon: {
    resizeMode: 'contain',
    width: 20,
    height: 20
  }
});

export default FloatingActionItem;
<commit_msg>Update FloatingActionItem.js<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
  StyleSheet,
  Text,
  Image,
  View,
  Animated
} from 'react-native';

import { getTouchableComponent } from './utils/touchable';

const DEFAULT_MARGIN = 8;

class FloatingActionItem extends Component {
  constructor(props) {
    super(props);

    this.animation = new Animated.Value(0);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.active !== this.props.active) {
      Animated.spring(this.animation, { toValue: nextProps.active ? 1 : 0 }).start();
    }
  }

  handleOnPress = () => {
    const { name, onPress } = this.props;

    onPress(name);
  };

  renderText() {
    const {
      // @deprecated in favor of textElevation
      elevation, // eslint-disable-line
      text,
      position,
      textElevation,
      textBackground,
      textColor
    } = this.props;

    if (elevation !== undefined) {
      console.warn('FloatingActionItem: "elevation" property was deprecated. Please use "textElevation"');
    }

    if (text) {
      return (
        <View
          key="text"
          style={[
            styles.textContainer,
            styles[`${position}TextContainer`],
            {
              backgroundColor: textBackground,
              elevation: textElevation || elevation
            }]
          }
        >
          <Text
            style={[
              styles.text,
              {
                color: textColor
              }
            ]}
          >
            {text}
          </Text>
        </View>
      );
    }

    return null;
  }

  renderButton() {
    const { icon, color, size } = this.props;

    let iconStyle;

    if (icon && icon.uri) {
      iconStyle = styles.iconLogo;
    } else {
      iconStyle = styles.icon;
    }

    return (
      <View key="button" style={[styles.button, { backgroundColor: color, width : size, height : size }]}>
        {
          React.isValidElement(icon) ? icon : <Image style={iconStyle} source={icon} />
        }
      </View>
    );
  }

  render() {
    const { position, distanceToEdge, paddingTopBottom } = this.props;
    const Touchable = getTouchableComponent(false);

    const animatedActionContainerStyle = {
      marginBottom: this.animation.interpolate({
        inputRange: [0, 1],
        outputRange: [5, 10]
      })
    };

    const components = [];
    const distanceToEdgeActionContainer = {};

    if (position === 'left') {
      components.push(this.renderButton());
      components.push(this.renderText());
      distanceToEdgeActionContainer.paddingLeft = distanceToEdge + DEFAULT_MARGIN;
    } else if (position === 'right') {
      components.push(this.renderText());
      components.push(this.renderButton());
      distanceToEdgeActionContainer.paddingRight = distanceToEdge + DEFAULT_MARGIN;
    } else {
      components.push(this.renderButton());
    }

    return (
      <Touchable activeOpacity={0.4} style={styles.container} onPress={this.handleOnPress}>
        <Animated.View
          style={[
            styles.actionContainer,
            animatedActionContainerStyle,
            styles[`${position}ActionContainer`],
            distanceToEdgeActionContainer,
            {
              paddingTop: paddingTopBottom,
              paddingBottom: paddingTopBottom
            }
          ]}
        >
          {components}
        </Animated.View>
      </Touchable>
    );
  }
}

FloatingActionItem.propTypes = {
  color: PropTypes.string,
  icon: PropTypes.any,
  name: PropTypes.string.isRequired,
  text: PropTypes.string,
  textBackground: PropTypes.string,
  textColor: PropTypes.string,
  size : PropTypes.number,
  // not on doc
  textElevation: PropTypes.number,
  // not modified by user
  position: PropTypes.oneOf(['left', 'right', 'center']),
  active: PropTypes.bool,
  distanceToEdge: PropTypes.number,
  paddingTopBottom: PropTypes.number, // modified by parent property "actionsPaddingTopBottom"
  onPress: PropTypes.func
};

FloatingActionItem.defaultProps = {
  color: '#1253bc',
  distanceToEdge: 30,
  textElevation: 5,
  textColor: '#444444',
  textBackground: '#ffffff',
  size : 40
};

const styles = StyleSheet.create({
  container: {
    elevation: 0,
    flex: 1,
    flexDirection: 'column'
  },
  actionContainer: {
    elevation: 0,
    flex: 1,
    flexDirection: 'row',
    paddingLeft: 10,
    paddingRight: 10,
    paddingBottom: 8,
    paddingTop: 8
  },
  centerActionContainer: {
    paddingLeft: 10,
    paddingRight: 10
  },
  textContainer: {
    paddingHorizontal: 8,
    shadowOpacity: 0.35,
    shadowOffset: {
      width: 0,
      height: 5
    },
    shadowColor: '#000000',
    shadowRadius: 3,
    elevation: 5,
    borderRadius: 4,
    height: 22,
    marginTop: 8
  },
  leftTextContainer: {
    marginLeft: 14
  },
  rightTextContainer: {
    marginRight: 14
  },
  text: {
    fontSize: 14,
    lineHeight: 20
  },
  button: {
    alignItems: 'center',
    justifyContent: 'center',
    borderRadius: 20,
    shadowOpacity: 0.35,
    shadowOffset: {
      width: 0,
      height: 5
    },
    shadowColor: '#000000',
    shadowRadius: 3,
    elevation: 5
  },
  iconLogo: {
    resizeMode: 'cover',
    width: 40,
    height: 40,
    borderRadius: 20
  },
  icon: {
    resizeMode: 'contain',
    width: 20,
    height: 20
  }
});

export default FloatingActionItem;
<|endoftext|>


<commit_before>'use strict';

function fileUpload(button) {
				// create iframe
				debugger;
				var iframe = document.createElement("iframe");
				iframe.width=240;
				console.log(iframe.width);
				iframe.height=240;
				iframe.id='upload';
				iframe.src='/test';

				button.parentNode.appendChild(iframe);

				setTimeout('button.parentNode.removeChild(iframe)',1000);

				var img = document.createElement('img');
				img.id = 'img';
				img.width = 128;
				img.height = 128;
				img.src="{{ url_for('static', filename='uploads/_Detection_') }}";

				button.parentNode.appendChild(img);

				var iframeId = document.getElementById('upload');
				console.log(iframeId);
}

<commit_msg>Delete test.js<commit_after><|endoftext|>