collaboration editor update fix, use closure for compression

This commit is contained in:
Matthew Scragg 2013-10-10 10:38:30 -05:00
parent 88fdf6b2ca
commit ccbf8336ea
9 changed files with 1313 additions and 86 deletions

View file

@ -10,6 +10,7 @@ $(function(){
var editor
, autoInterval
, keyCheck // used to detect changes not made via keyup
, profile =
{
theme: 'ace/theme/idle_fingers'
@ -291,7 +292,6 @@ $(function(){
// Immediately populate the preview <div>
previewMd();
});
@ -331,8 +331,12 @@ $(function(){
* @return {Void}
*/
function saveFile(isManual){
updateUserProfile({currentMd: editor.getSession().getValue()})
if (!keyCheck && profile.currentMd != editor.getSession().getValue()) {
previewMd();
console.log(keyCheck);
}
keyCheck = false;
updateUserProfile({currentMd: editor.getSession().getValue()});
if (isManual) {
updateUserProfile({ currentMd: "" });
@ -356,14 +360,13 @@ $(function(){
*/
function autoSave(){
if(profile.autosave.enabled){
if(profile.autosave.enabled) {
autoInterval = setInterval( function(){
// firefox barfs if I don't pass in anon func to setTimeout.
saveFile();
}, profile.autosave.interval);
}
else{
} else {
clearInterval( autoInterval )
}
@ -399,7 +402,7 @@ $(function(){
// check for same theme
var $target = $(e.target);
if( $target.attr('data-value') === profile.theme) { return; }
else{
else {
// add/remove class
$theme.find('li > a.selected').removeClass('selected');
$target.addClass('selected');
@ -422,19 +425,14 @@ $(function(){
*/
function fetchTheme(th, cb){
var name = th.split('/').pop();
asyncLoad("/static/js/ace/theme-"+ name +".js", function(){
asyncLoad("/static/js/ace/theme-"+ name +".js", function() {
editor.setTheme(th);
cb && cb();
updateBg(name);
updateUserProfile({theme: th});
});
}); // end asyncLoad
} // end fetchTheme(t)
}
/**
* Change the body background color based on theme.
@ -468,7 +466,7 @@ $(function(){
if (selectionCount !== undefined) {
msg += selectionCount + " of ";
}
if(profile.wordcount){
if (profile.wordcount) {
$wordcounter.text(msg + countWords(getTextInElement($preview[0])));
}
}
@ -481,14 +479,13 @@ $(function(){
*/
function updateFilename(str){
// Check for string because it may be keyup event object
var f
var f;
if(typeof str === 'string'){
f = str
}else
{
f = getCurrentFilenameFromField()
f = str;
} else {
f = getCurrentFilenameFromField();
}
updateUserProfile( {current_filename: f })
updateUserProfile( { current_filename: f });
}
@ -532,31 +529,27 @@ $(function(){
alert('Sad Panda - No localStorage for you!')
}
/**
* Toggles the autosave feature.
*
* @return {Void}
*/
function toggleAutoSave(){
$autosave.html( profile.autosave.enabled ? '<i class="icon-remove"></i>&nbsp;Disable Autosave' : '<i class="icon-ok"></i>&nbsp;Enable Autosave' );
updateUserProfile({autosave: {enabled: !profile.autosave.enabled }});
autoSave();
}
/**
* Bind keyup handler to the editor.
*
* @return {Void}
*/
function bindPreview(){
$('#editor').bind('keyup', previewMd);
$('#editor').bind('keyup', function() {
keyCheck = true;
previewMd();
});
}
/**

33
realms/static/js/main.js Normal file
View file

@ -0,0 +1,33 @@
// Init highlight JS
hljs.initHighlightingOnLoad();
// Markdown Renderer
MDR = {
doc: null,
callback: WMD.convert,
sanitize: null, // Override
convert: function(md, sanitize){
if (this.sanitize !== null) {
sanitize = this.sanitize;
}
this.doc = this.callback(md);
var html = this.doc.html;
if (sanitize) {
// Causes some problems with inline styles
html = html_sanitize(html);
}
html = this.hook(html);
return html;
},
hook: function(html) {
if (!this.doc.metadata) {
return html;
}
try {
var template = Handlebars.compile(html);
return template(this.doc.metadata);
} catch(e) {
return html;
}
}
};