Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started work on better asynchronous speccing

  • Loading branch information...
commit bffcc0648ce1e51ece2e71c1710871235ea97d15 1 parent 2b7007e
jonas authored
View
5 TODO
@@ -1,4 +1,4 @@
-* [2/11] Further improvements
+* [2/12] Further improvements
- [-] fix specs in Firefox
- [ ] general specs
- [ ] better async handling. is there a global jQuery trigger
@@ -6,6 +6,9 @@
- [X] list specs
- [X] config.current error (Border find error)
- [ ] fix specs in chrome again
+ - [ ] create a class which handles the mode change in order to avoid
+ the same requests on mode change
+ - [ ] spec form submission, which currently won't work
- [ ] update docs
- [ ] better editor loading
- [ ] handle multiple init gracefully. Currently it stacks two editors on top of each other
View
7 source/javascripts/core/editor.js
@@ -259,7 +259,12 @@
*/
synchronize: function(callback) {
if(this.is("wysiwyg")) {
- this.currentMode.updateTextArea(this, callback);
+ if(callback){
+ callback();
+ }
+ // TODO this is to avoid double requests. This will not
+ // synchronize on form submission
+ // this.currentMode.updateTextArea(this, callback);
} else {
this.currentMode.updatePreview(this, callback);
}
View
2  source/javascripts/core/mode.js
@@ -58,7 +58,7 @@
},
/**
* Update the preview html div with the html representation of the
- *mode
+ * mode
* CONSIDER move to editor
*
* @param {Editor} editor The editor to work on
View
4 source/javascripts/modes/hamlMode.js
@@ -7,10 +7,12 @@ ME.addMode('haml', function(){
type: 'haml',
content: editor.textArea.val()
}, function(html, status, response){
+ console.log('to');
editor.preview.html(html);
if(callback){
callback();
}
+ editor.container.trigger('to_html');
});
},
toText: function(editor, callback) {
@@ -18,10 +20,12 @@ ME.addMode('haml', function(){
type: 'haml',
content: editor.preview.html()
}, function(haml, status, response){
+ console.log('from');
editor.textArea.val(haml);
if(callback){
callback();
}
+ editor.container.trigger('from_html');
});
}
};
View
54 source/javascripts/test/markupEditor.js
@@ -2,10 +2,25 @@ $(function(){
var editor = $("div.markupClick.textile").click().parent(),
timeout_ms = 200;
- function async(callback){
+ function async(editor, trigger, callback){
+ if(!trigger){
+ asyncOld(editor);
+ return;
+ }
+ var func = function(event){
+ console.log(event);
+ event.stopPropagation();
+ editor.unbind(trigger,func);
+ callback();
+ };
+ editor.bind(trigger,func);
+ }
+
+ function asyncOld(callback) {
setTimeout(callback, timeout_ms);
}
+
module("Markup");
test("click and load", function(){
@@ -35,25 +50,20 @@ $(function(){
changeMode.val('haml').change();
ok(previewButton.is(':visible'), 'preview button should be visible');
ok(editor.find('.preview').is(':visible'), 'preview should be visible');
- stop(3);
+ ok(previewButton.is('.on'), 'preview on');
- async(function(){
+ previewButton.mouseup();
+ stop(2);
+
+ async(editor, 'from_html', function(){
start();
- ok(previewButton.is('.on'), 'preview on');
-
+ ok(!previewButton.is('.on'), 'preview off');
+ ok(changeMode.val() === 'haml', 'The datamode should stay the same, was ' + changeMode.val());
previewButton.mouseup();
-
- async(function(){
+ async(editor, 'from_html', function(){
start();
- ok(!previewButton.is('.on'), 'preview off');
+ ok(previewButton.is('.on'), 'preview on');
ok(changeMode.val() === 'haml', 'The datamode should stay the same, was ' + changeMode.val());
- previewButton.mouseup();
-
- async(function(){
- start();
- ok(previewButton.is('.on'), 'preview on');
- ok(changeMode.val() === 'haml', 'The datamode should stay the same, was ' + changeMode.val());
- });
});
});
});
@@ -220,18 +230,24 @@ $(function(){
});
test('change mode should work with async modes', function(){
- var text = 'some text';
-
+ var text = 'some text',
+ previewButton = editor1.find('a.wysiwyg');
+
changeMode1.val('textile').change();
+
+ if(previewButton.is('.on')){
+ previewButton.mouseup();
+ }
+
textArea1.val(text).mouseup();
changeMode1.val('haml').change();
stop();
- async(function(){
+ async(editor1, 'from_html', function(){
changeMode1.val('textile').change();
- async(function(){
+ async(editor1, 'to_html', function(){
start();
ok(textArea1.val() === text, 'The text should not change, was ' + textArea1.val());
});
Please sign in to comment.
Something went wrong with that request. Please try again.