Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 372294 - Don't store stuff in the plugin's URL fragment
  • Loading branch information
Mark Macdonald committed Mar 2, 2012
1 parent ea32bcf commit e2acb10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 49 deletions.
17 changes: 8 additions & 9 deletions codeMirrorPlugin.html
Expand Up @@ -44,17 +44,11 @@ <h2>Requirements</h2>
<h2>Installation</h2>
<form>
<ol>
<li>Check the modes that you want to enable support for:
<div class="cols">
<ul id="modelist" class="modelist"></ul>
</div>
<button type="button" onclick="check('all');">Check All</button>
<button type="button" onclick="check('none');">Check None</button>
<button type="button" onclick="check(defaults);">Defaults</button></li>
<li>Copy the resulting URL from this box:<br>
<li>Copy the following URL:<br>
<textarea id="url" class="url" type="text" onclick="this.focus(); this.select();" rows="1" wrap="off"></textarea>
</li>
<li>Log in to your Orion environment, go to the "Plugins" page, paste the URL into the "Install" field, and click Install.</li>
<li>Log in to your Orion environment, and click the "Settings" link on the top banner.</li>
<li>Select the "Plugins" category, click "Install", paste the URL into the field, and click "Submit".</li>
</ol>
</form>

Expand All @@ -64,5 +58,10 @@ <h2>Usage</h2>
<li>Create a new file with an extension corresponding to one of the modes you installed. (For example, <code>test.php</code> if you installed PHP mode). Click on it.</li>
<li>You'll be taken to an editing page. Type some (valid) code in the editor, and it will be syntax-colored.</li>
</ol>

<h2>Supported Modes</h2>
<div class="cols">
<ul id="modelist" class="modelist"></ul>
</div>
</body>
</html>
47 changes: 7 additions & 40 deletions lib/codeMirrorPlugin.js
Expand Up @@ -35,7 +35,6 @@ function registerPlugin(mEventTarget, mTextModel, mMirror, mMirrorTextModel, mHi
}

var modes = ["clike", "clojure", "coffeescript", "css", "diff", "groovy", "haskell", "htmlmixed", "javascript", "jinja2", "lua", "markdown", "ntriples", "pascal", "perl", "php", "plsql", "python", "r", "rst", "ruby", "rust", "scheme", "smalltalk", "sparql", "stex", "tiddlywiki", "velocity", "xml", "xmlpure", "yaml"];
var defaults = ["clike", "css", "htmlmixed", "javascript", "perl", "php", "ruby", "xml", "xmlpure"];
var deps = {
"htmlmixed": ["css", "xml", "javascript"],
"php": ["clike", "css", "javascript", "xml"]
Expand Down Expand Up @@ -143,57 +142,26 @@ function registerPlugin(mEventTarget, mTextModel, mMirror, mMirrorTextModel, mHi
};
}).filter(function(ct) { return !!ct; });
}
function boxes() {
return Array.prototype.filter.call(document.getElementsByTagName("input"), function(i){ return i.type === "checkbox"; });
}
function updateURL() {
var base = window.location.href.replace(window.location.hash, "");
var q = boxes().map(function(box) { return box.checked && box.value; }).filter(function(b) { return !!b; });
var hash = q.join("+");
document.getElementById("url").value = base + (base[base.length-1] !== "#" ? "#" : "") + hash;
window.location.hash = hash;
}
function add(what) {
boxes().forEach(function(box) {
box.checked = box.checked || what.indexOf(box.value) !== -1;
});
}
function onBoxClick(e) {
if (e.target.tagName === "LABEL") { return; }
var box = e.target;
if (deps[box.value]) { add(deps[box.value], true); }
updateURL();
}
function createForm() {
var list = document.getElementById("modelist");
modes.forEach(function(mode) {
var li = document.createElement("li");
var label = document.createElement("label");
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.value = mode;
label.addEventListener("click", onBoxClick, false);
label.appendChild(checkbox);
label.appendChild(document.createTextNode(mode));
var label = document.createElement("div");
var modeNode = document.createElement("a");
modeNode.href = "http://codemirror.net/mode/" + mode + "/";
modeNode.innerHTML = mode;
label.appendChild(modeNode);
li.appendChild(label);
list.appendChild(li);
});
}

function check(/*"all"|"none"|Array*/ what) {
boxes().forEach(function(box) {
box.checked = (what === "all" || (what instanceof Array && what.indexOf(box.value) !== -1));
});
updateURL();
}

function errback(e) { console.log("orion-codemirror: Couldn't install plugin: " + e); }

// Register plugin
(function() {
var hash = (window.location.hash).substring(1);
var modeSet = hash && hash.split("+");
modeSet = (modeSet && modeSet.length) ? modeSet : defaults; // modeSet to install
var modeSet = modes; // modeSet to install
try {
var model = new mMirrorTextModel.MirrorTextModel();
var highlighter = new mHighlighter.Highlighter(model, mirror);
Expand Down Expand Up @@ -247,7 +215,6 @@ function registerPlugin(mEventTarget, mTextModel, mMirror, mMirrorTextModel, mHi
}

createForm();
check(modeSet);
updateURL();
document.getElementById("url").value = window.location.href;
}());
}

0 comments on commit e2acb10

Please sign in to comment.