Created
March 14, 2013 12:02
-
-
Save daangemist/5160843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name RockMongo with ACE | |
// @match http://127.0.0.1/rockmongo/* | |
// @match https://127.0.0.1/rockmongo/* | |
// ==/UserScript== | |
// Stolen from http://stackoverflow.com/a/3550261/360593 | |
function addHeadJS(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//cdnjs.cloudflare.com/ajax/libs/headjs/0.99/head.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
function main() { | |
head.js( | |
"//d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js", | |
function() { | |
textarea_selector = false; | |
if (document.getElementById("row_data")) | |
{ | |
textarea_selector = '#row_data'; | |
editor_width = 700; | |
editor_height = 400; | |
} | |
if ($('#query_form textarea[name=criteria]').length) | |
{ | |
textarea_selector = '#query_form textarea[name=criteria]'; | |
editor_width = 507; | |
editor_height = 100; | |
} | |
if (textarea_selector != false) | |
{ | |
var textarea = $(textarea_selector); | |
textarea.hide(); | |
if (textarea.val() == "{\n\t\t\t\t\t\n}") | |
textarea.val("{\n\t\n}"); | |
var ace_editor_div = $('<div></div>') | |
.text(textarea.val()) | |
.attr('id', 'ace_editor_div') | |
.css({ | |
'position' : 'relative', | |
'width' : editor_width+'px', | |
'height' : editor_height+'px' | |
}) | |
.insertAfter(textarea); | |
var editor = ace.edit('ace_editor_div'); | |
editor.setTheme("ace/theme/monokai"); | |
editor.getSession().setMode("ace/mode/javascript"); | |
editor.renderer.setShowGutter(false); | |
$(textarea).closest('form').submit(function() { | |
textarea.val(editor.getSession().getValue()); | |
}); | |
} | |
} | |
) | |
} | |
addHeadJS(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment