Widget / Edit Boot Javascript

This widget lets you define your base Javascript that gets executed when your URL is entered. The root panel is loaded first by ChiliPeppr and then you can load your own content in the body area. Your code is only executed once the root panel is loaded.

by chilipeppr

HTML

<script src="http://www.chilipeppr.com/js/require.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<div id="com-chilipeppr-widget-editbootscript-body" class="panel-body">
    <form role="form" >
        <div class="form-group">
            <div id="forking-panel" class="well hidden"></div>
            <div class="alert alert-warning hidden"></div>
            <label for="inputUrl">URL</label>
            <table>
                <tr>
                    <td>http://chilipeppr.com/&nbsp;</td>
                    <td>
                        <input type="text" class="form-control" id="com-chilipeppr-widget-editbootscript-inputUrl" placeholder="Pick your URL" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="form-group">
            <label for="com-chilipeppr-widget-editbootscript-inputScript">Base Boot Javascript</label>
            <textarea id="com-chilipeppr-widget-editbootscript-inputScript" class="form-control" rows="5"></textarea>
        </div>
        <div id="com-chilipeppr-widget-editbootscript-inputScriptExample" class="hidden">// Sample Base Boot Javascript
// ----------------------
// You should create a JSFiddle that loads your content 
// by forking an existing workspace to get started. Then 
// you can also fork any widgets, elements, or other 
// JSFiddles that you need to modify so that others can 
// benefit from your modifications.
            
// The chilipeppr.load() method is used to load a 
// JSFiddle and inject it's HTML (inluding its 
// CSS/Javascript) into a DOM element. The first 
// parament must be the HTML ID of the DOM element.
chilipeppr.load("pnlWorkspace",
     // Edit URL below to your JSFiddle
    "http://fiddle.jshell.net/myfiddlenuser/n3DLs/show/light/", function() {
		
        console.log("My workspace done loading.");
            
        // This is an example of publishing to the flash message 
       ...

CSS

.modal-body #com-chilipeppr-widget-editbootscript-body {
    padding:0;
}
#com-chilipeppr-widget-editbootscript-body .alert {
    margin-top:0;
}

JavaScript

cprequire_test(['inline:com-chilipeppr-widget-editbootscript'], function (editboot) {
    console.log("Running Edit Boot Javascript Widget");
    editboot.init();
    //editboot.doFork();
    console.log("initted");
} /*end_test*/ );

cpdefine('inline:com-chilipeppr-widget-editbootscript', ['chilipeppr_ready'], function () {

    return {

        id: 'com-chilipeppr-widget-editbootscript',
        url: "http://fiddle.jshell.net/chilipeppr/uNALR/show/light/",
        fiddleurl: "http://jsfiddle.net/chilipeppr/uNALR/",
        name: "Widget / Edit Boot Javascript",
        desc: "This widget lets you define your base Javascript that gets executed when your URL is entered. The root panel is loaded first by ChiliPeppr and then you can load your own content in the body area. Your code is only executed once the root panel is loaded.",
        publish: [''],
        subscribe: [''],
        isForkMode: false,

        init: function () {
            this.isForkMode = false;
            this.urlSetup();
            this.formSetup();
            var url = this.extractUrl();
            var forkDom = $('#com-chilipeppr-widget-editbootscript-body #forking-panel');
            forkDom.addClass("hidden");
            //if (!url) url = "asdf";
            if (url) {
                // perform submit
                this.urlSubmit();
            } else {
                // this is root
                var that = this;
                this.urlSubmit(null, function() {
                    if (!that.isForkMode) {
                        var warningDom = $('#com-chilipeppr-widget-editbootscript-body .alert');
                        warningDom.text("This is the root URL. You may not edit it, but you may copy the Javascript for your own Hardware Fiddle. It would be best to fork the workspace in JSFiddle and modify your boot script to reference your new fork.");
                    }
                });
            }                
                
        },
        doFork:...