Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Jan 4, 2014
1 parent ab27621 commit b0edbf5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions dist/summernote.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright 2013 Alan Hong. and outher contributors
* summernote may be freely distributed under the MIT license./
*
* Date: 2014-01-02T14:54Z
* Date: 2014-01-04T04:30Z
*/
(function (factory) {
/* global define */
Expand Down Expand Up @@ -188,6 +188,9 @@
return node && /^UL|^OL/.test(node.nodeName);
};

/**
* returns whether node is `note-editable` or not.
*/
var isEditable = function (node) {
return node && $(node).hasClass('note-editable');
};
Expand All @@ -202,7 +205,7 @@
* @param {function} pred - predicate function
*/
var ancestor = function (node, pred) {
while (node) {
while (node && !isEditable(node)) {
if (pred(node)) { return node; }
node = node.parentNode;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/summernote.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/js/core/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ define(['core/func', 'core/list'], function (func, list) {
return node && /^UL|^OL/.test(node.nodeName);
};

/**
* returns whether node is `note-editable` or not.
*/
var isEditable = function (node) {
return node && $(node).hasClass('note-editable');
};
Expand All @@ -38,7 +41,7 @@ define(['core/func', 'core/list'], function (func, list) {
* @param {function} pred - predicate function
*/
var ancestor = function (node, pred) {
while (node && !$(node).hasClass('note-editor')) {
while (node && !isEditable(node)) {
if (pred(node)) { return node; }
node = node.parentNode;
}
Expand Down
6 changes: 6 additions & 0 deletions test/dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var dom = $.fn.summernoteInner().dom,
test('dom.ancestor', function () {
var $cont, $b, elB;

// basic case
$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
elB = $b[0].firstChild;
Expand All @@ -17,6 +18,11 @@ test('dom.ancestor', function () {
equal(dom.ancestor(elB, dom.isDiv), $cont[0], 'find ancestor DIV');

equal(dom.ancestor(elB, dom.isU), null, 'find ancestor U: null');

// keep boundary
$cont = $('<ul><li><div class="note-editable"><b>b</b></div></li></ul>'); //b
elB = $cont.find('b')[0].firstChild;
equal(dom.ancestor(elB, dom.isPara), null, 'find paragraph ancestor outside note-editable: null');
});

test('dom.listAncestor', function () {
Expand Down

0 comments on commit b0edbf5

Please sign in to comment.