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
.webassets-cache
*.pyc
packed-*.js
config.py
config.sls
realms/static/vendor

View file

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

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;
}
}
};

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" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% 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 %}
</body>
</html>

View file

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

View file

@ -6,7 +6,7 @@ python-pkgs:
- 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:
pip:
- name: {{ pkg }}