Skip to content

Commit

Permalink
properly send parameters through from commands with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
zilkey committed Oct 9, 2009
1 parent f294868 commit 1e9c671
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
6 changes: 5 additions & 1 deletion lib/syncopate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
$('<li class="button ' + css_class + '"><a>' + command + '</a></li>')
.appendTo(toolbar)
.mousedown(function() {
self.exec(command);
if(command.join) {
self.exec(command[0], command[1]);
} else {
self.exec(command);
}
self.refresh();
});
});
Expand Down
69 changes: 59 additions & 10 deletions spec/lib/syncopate_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,17 @@ Screw.Unit(function(c) { with(c) {
describe("#load", function() {
var syncopated, textarea;

before(function() {
textarea = view.children('textarea');
syncopated = Disco.build($.Syncopate, {
textarea: textarea,
commands: commands
});
syncopated.load();
});

describe("the 'syncopated' editor's iframe document", function() {
var iframe, editor;

before(function() {
textarea = view.children('textarea');
syncopated = Disco.build($.Syncopate, {
textarea: textarea,
commands: commands
});
syncopated.load();

iframe = view.find('iframe');
editor = $(iframe[0].contentWindow.document); // (frame.contentDocument || frame.document)
});
Expand All @@ -159,7 +157,16 @@ Screw.Unit(function(c) { with(c) {
});
});

describe("the 'syncopated' editor's toolbar", function() {
describe("the 'syncopated' editor's toolbar with commands with no arguments", function() {
before(function() {
textarea = view.children('textarea');
syncopated = Disco.build($.Syncopate, {
textarea: textarea,
commands: commands
});
syncopated.load();
});

$.each(commands, function() {
$.each(this, function() {
var button_type = this;
Expand Down Expand Up @@ -188,6 +195,48 @@ Screw.Unit(function(c) { with(c) {
});
});
});

describe("the 'syncopated' editor's toolbar with comamnds with arguments", function() {
before(function() {
textarea = view.children('textarea');
syncopated = Disco.build($.Syncopate, {
textarea: textarea,
commands: commands_with_arguments
});
syncopated.load();
});

$.each(commands_with_arguments, function() {
$.each(this, function() {
var css_class = this.join("_");
var button_type = this[0];
var argument = this[1];

describe("clicking the generated " + button_type + " command button", function() {
var iframe, original, parameters;

before(function() {
iframe = view.find('iframe');
original = iframe[0].contentWindow.document.execCommand;

iframe[0].contentWindow.document.execCommand = function() {
parameters = arguments;
};
});

after(function() {
iframe[0].contentWindow.document.execCommand = original;
});

it("sends a '" + button_type + "' command to the iframe document", function() {
view.find('li.button.' + css_class).mousedown();
expect(parameters[0]).to(equal, button_type);
expect(parameters[2]).to(equal, argument);
});
});
});
});
});
});

describe("#refresh", function() {
Expand Down

0 comments on commit 1e9c671

Please sign in to comment.