Created
October 25, 2013 02:46
-
-
Save SchumacherFM/7148736 to your computer and use it in GitHub Desktop.
Ace Editor (http://ace.c9.io/#nav=about) with Diff
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
/* | |
load js libs: | |
'/Resources/public/js/lib/ace/ace.js' | |
'/Resources/public/js/lib/ace/mode-diff.js' | |
'/Resources/public/js/lib/ace/theme-chrome.js' | |
https://github.com/Slava/diff.js/blob/master/diff.js | |
*/ | |
var data = { /*json from server ... */ | |
after: [ | |
"audioTest123↵{↵ "type": "audio",↵ "hello": "world"↵}" | |
"3↵{↵ "type": "audio",↵ "hello": "world"↵}" | |
], | |
before:[ | |
"audioTest123↵{↵ "type": "audio"↵}" | |
"3↵{↵ "type": "audio"↵}" | |
] | |
}; | |
ace.require('ace/edit_session').EditSession.prototype.$useWorker = false; | |
var massActionAceEditor = ace.edit(htmlId); | |
massActionAceEditor.setTheme('ace/theme/chrome'); | |
massActionAceEditor.setShowPrintMargin(false); | |
massActionAceEditor.setShowFoldWidgets(false); | |
massActionAceEditor.getSession().setUseWrapMode(true); | |
massActionAceEditor.clearSelection(); | |
massActionAceEditor.getSession().setMode('ace/mode/diff'); | |
var | |
joinString = '\n\n===================================================\n\n', | |
before = data.before.join(joinString), | |
after = data.after.join(joinString), | |
diffOps = diff(before.split('\n'), after.split('\n')); | |
massActionAceEditor.getSession().setValue(diffOps.map(function (o) { | |
return (o.operation === 'none' ? ' ' : o.operation === 'add' ? '+' : '-') + ' ' + o.atom; | |
}).join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment