Skip to content

Commit

Permalink
FIX: h5 tag bug in title button #332
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Oct 15, 2015
1 parent 7648c33 commit abbb5f4
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/simditor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*!
* Simditor v2.3.1
* http://simditor.tower.im/
* 2015-10-15
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
Expand Down Expand Up @@ -1684,7 +1689,7 @@ Util = (function(superClass) {
return $(node).is('[class^="simditor-"]');
};

Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "table"];
Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "h5", "table"];

Util.prototype.isBlockNode = function(node) {
node = $(node)[0];
Expand Down Expand Up @@ -3092,7 +3097,7 @@ TitleButton = (function(superClass) {

TitleButton.prototype.name = 'title';

TitleButton.prototype.htmlTag = 'h1, h2, h3, h4';
TitleButton.prototype.htmlTag = 'h1, h2, h3, h4, h5';

TitleButton.prototype.disableTag = 'pre, table';

Expand Down Expand Up @@ -3132,7 +3137,7 @@ TitleButton = (function(superClass) {
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
this.el.removeClass('active-p active-h1 active-h2 active-h3');
this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
Expand Down
6 changes: 3 additions & 3 deletions site/assets/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ Util = (function(superClass) {
return $(node).is('[class^="simditor-"]');
};

Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "table"];
Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "h5", "table"];

Util.prototype.isBlockNode = function(node) {
node = $(node)[0];
Expand Down Expand Up @@ -3092,7 +3092,7 @@ TitleButton = (function(superClass) {

TitleButton.prototype.name = 'title';

TitleButton.prototype.htmlTag = 'h1, h2, h3, h4';
TitleButton.prototype.htmlTag = 'h1, h2, h3, h4, h5';

TitleButton.prototype.disableTag = 'pre, table';

Expand Down Expand Up @@ -3132,7 +3132,7 @@ TitleButton = (function(superClass) {
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
this.el.removeClass('active-p active-h1 active-h2 active-h3');
this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
Expand Down
52 changes: 52 additions & 0 deletions spec/buttons/title-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function() {
describe('Simditor title button', function() {
var $p, editor;
editor = null;
$p = null;
beforeEach(function() {
editor = spec.generateSimditor({
content: '<p>paragraph 1</>',
toolbar: ['title']
});
editor.focus();
$p = editor.body.find('> p');
editor.selection.setRangeAtStartOf($p);
return editor.trigger('selectionchanged');
});
afterEach(function() {
spec.destroySimditor();
return editor = null;
});
it("can convert paragraph to h1", function() {
var $firstBlock, button;
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(true);
expect($firstBlock.is('h1')).toBe(false);
button = editor.toolbar.list.find('.toolbar-item-title').data('button');
button.menuEl.find('.menu-item-h1').click();
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(false);
expect($firstBlock.is('h1')).toBe(true);
button.menuEl.find('.menu-item-normal').click();
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(true);
return expect($firstBlock.is('h1')).toBe(false);
});
return it("can convert paragraph to h5", function() {
var $firstBlock, button;
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(true);
expect($firstBlock.is('h5')).toBe(false);
button = editor.toolbar.list.find('.toolbar-item-title').data('button');
button.menuEl.find('.menu-item-h5').click();
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(false);
expect($firstBlock.is('h5')).toBe(true);
button.menuEl.find('.menu-item-normal').click();
$firstBlock = editor.body.children().first();
expect($firstBlock.is('p')).toBe(true);
return expect($firstBlock.is('h5')).toBe(false);
});
});

}).call(this);
51 changes: 51 additions & 0 deletions spec/src/buttons/title-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe 'Simditor title button', ->
editor = null
$p = null

beforeEach ->
editor = spec.generateSimditor
content: '''
<p>paragraph 1</>
'''
toolbar: ['title']
editor.focus()

$p = editor.body.find('> p')
editor.selection.setRangeAtStartOf $p
editor.trigger 'selectionchanged'

afterEach ->
spec.destroySimditor()
editor = null

it "can convert paragraph to h1", ->
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(true)
expect($firstBlock.is('h1')).toBe(false)

button = editor.toolbar.list.find('.toolbar-item-title').data 'button'
button.menuEl.find('.menu-item-h1').click()
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(false)
expect($firstBlock.is('h1')).toBe(true)

button.menuEl.find('.menu-item-normal').click()
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(true)
expect($firstBlock.is('h1')).toBe(false)

it "can convert paragraph to h5", ->
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(true)
expect($firstBlock.is('h5')).toBe(false)

button = editor.toolbar.list.find('.toolbar-item-title').data 'button'
button.menuEl.find('.menu-item-h5').click()
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(false)
expect($firstBlock.is('h5')).toBe(true)

button.menuEl.find('.menu-item-normal').click()
$firstBlock = editor.body.children().first()
expect($firstBlock.is('p')).toBe(true)
expect($firstBlock.is('h5')).toBe(false)
5 changes: 3 additions & 2 deletions src/buttons/title.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class TitleButton extends Button

name: 'title'

htmlTag: 'h1, h2, h3, h4'
htmlTag: 'h1, h2, h3, h4, h5'

disableTag: 'pre, table'

Expand Down Expand Up @@ -39,13 +39,14 @@ class TitleButton extends Button
super active

param ||= @node[0].tagName.toLowerCase() if active
@el.removeClass 'active-p active-h1 active-h2 active-h3'
@el.removeClass 'active-p active-h1 active-h2 active-h3 active-h4 active-h5'
@el.addClass('active active-' + param) if active

command: (param) ->
$rootNodes = @editor.selection.rootNodes()
@editor.selection.save()


$rootNodes.each (i, node) =>
$node = $ node
return if $node.is('blockquote') or $node.is(param) or
Expand Down
2 changes: 1 addition & 1 deletion src/util.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Util extends SimpleModule
$(node).is('[class^="simditor-"]')

blockNodes: ["div","p","ul","ol","li","blockquote","hr","pre","h1","h2","h3",
"h4","table"]
"h4", "h5", "table"]

isBlockNode: (node) ->
node = $(node)[0]
Expand Down

0 comments on commit abbb5f4

Please sign in to comment.