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

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
.idea .idea
.webassets-cache .webassets-cache
*.pyc *.pyc
packed-*.js
config.py config.py
config.sls config.sls
realms/static/vendor realms/static/vendor

View file

@ -132,16 +132,25 @@ def create_app(subdomain=None):
return CurrentUser(user_id) return CurrentUser(user_id)
assets.init_app(app) assets.init_app(app)
if config.ENV is 'PROD':
if 'js_common' not in assets._named_bundles: if 'js_common' not in assets._named_bundles:
js = Bundle('vendor/jquery/jquery.js', assets.register('js_common', Bundle('packed-common.js'))
if 'js_editor' not in assets._named_bundles:
assets.register('js_editor', Bundle('packed-editor.js'))
else:
if 'js_common' not in assets._named_bundles:
js = Bundle(
Bundle('vendor/jquery/jquery.js',
'vendor/components-underscore/underscore.js', 'vendor/components-underscore/underscore.js',
'vendor/components-bootstrap/js/bootstrap.js', 'vendor/components-bootstrap/js/bootstrap.js',
'vendor/handlebars/handlebars.js', 'vendor/handlebars/handlebars.js',
'vendor/showdown/src/showdown.js', 'vendor/showdown/src/showdown.js',
'js/html-sanitizer-minified.js',
'js/wmd.js', 'js/wmd.js',
filters='closure_js'),
'js/html-sanitizer-minified.js',
'vendor/highlightjs/highlight.pack.js', 'vendor/highlightjs/highlight.pack.js',
filters='uglifyjs', output='packed-common.js') Bundle('js/main.js', filters='closure_js'),
output='packed-common.js')
assets.register('js_common', js) assets.register('js_common', js)
if 'js_editor' not in assets._named_bundles: if 'js_editor' not in assets._named_bundles:
@ -149,7 +158,7 @@ def create_app(subdomain=None):
'js/ace/mode-markdown.js', 'js/ace/mode-markdown.js',
'vendor/keymaster/keymaster.js', 'vendor/keymaster/keymaster.js',
'js/dillinger.js', 'js/dillinger.js',
filters='uglifyjs', output='packed-editor.js') filters='closure_js', output='packed-editor.js')
assets.register('js_editor', js) assets.register('js_editor', js)
repo_dir = config.repos['dir'] repo_dir = config.repos['dir']
@ -184,7 +193,10 @@ def create_app(subdomain=None):
@ratelimiter(limit=50, per=60) @ratelimiter(limit=50, per=60)
def root(): def root():
return render('home') return render('home')
#return redirect('/home')
@app.route("/home")
def home():
return redirect(url_for('root'))
@app.route("/account/") @app.route("/account/")
@login_required @login_required

View file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -103,37 +103,6 @@
{% assets "js_common" %} {% assets "js_common" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script> <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% endassets %}
<script>
hljs.initHighlightingOnLoad();
// Markdown Renderer
MDR = {
doc: null,
callback: WMD.convert,
convert: function(md, 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;
}
}
};
</script>
{% block js %}{% endblock %} {% block js %}{% endblock %}
</body> </body>
</html> </html>

View file

@ -4,6 +4,11 @@
<script type="text/javascript" src="{{ ASSET_URL }}"></script> <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% endassets %}
<script> <script>
$(function(){
$("#start-togetherjs").click(function(){
$(this).prop('disabled', true).html("Loading");
});
});
TogetherJSConfig_toolName = "Collaboration"; TogetherJSConfig_toolName = "Collaboration";
TogetherJSConfig_suppressJoinConfirmation = true; TogetherJSConfig_suppressJoinConfirmation = true;
TogetherJSConfig_getUserName = function () { TogetherJSConfig_getUserName = function () {
@ -15,12 +20,12 @@
}; };
TogetherJSConfig_on_ready = function () { TogetherJSConfig_on_ready = function () {
//$("#start-togetherjs").addClass('btn-danger').html($(this).data('end-togetherjs-html')); MDR.sanitize = true;
$("#start-togetherjs").addClass('btn-danger').html('End Collaboration'); $("#start-togetherjs").addClass('btn-danger').html('End Collaboration').prop('disabled', false);
}; };
TogetherJSConfig_on_close = function () { TogetherJSConfig_on_close = function () {
$("#start-togetherjs").removeClass('btn-danger').html('Collaborate') MDR.sanitize = null;
$("#start-togetherjs").removeClass('btn-danger').html('Collaborate').prop('disabled', false);
}; };
</script> </script>

View file

@ -6,7 +6,7 @@ python-pkgs:
- build-essential - build-essential
{% for pkg in ['BeautifulSoup', 'html5lib', 'ghdiff', 'tornado', 'pyzmq', 'itsdangerous', 'boto', 'redis', 'simplejson', 'sockjs-tornado', 'flask', 'flask-bcrypt', 'flask-login', 'flask-assets', 'gittle', 'gevent', 'lxml', 'markdown2', 'recaptcha-client', 'RethinkORM' ] %} {% for pkg in ['closure', 'ghdiff', 'tornado', 'pyzmq', 'itsdangerous', 'boto', 'redis', 'simplejson', 'sockjs-tornado', 'flask', 'flask-bcrypt', 'flask-login', 'flask-assets', 'gittle', 'gevent', 'lxml', 'markdown2', 'recaptcha-client', 'RethinkORM' ] %}
{{ pkg }}-pip: {{ pkg }}-pip:
pip: pip:
- name: {{ pkg }} - name: {{ pkg }}