Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
solve issue #3 of focusing a contenteditable when placeholder was cli…
Browse files Browse the repository at this point in the history
…cked
  • Loading branch information
yej committed Dec 31, 2014
1 parent 119da56 commit ff8672c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

v0.1.3
- solved issue #3 : focus problem with contenteditable and a placeholder

v0.1.2
- plan a show after setData null when active. #2
Expand Down
19 changes: 18 additions & 1 deletion angular-ckeditor-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@
else if(isActive()) $timeout(show);
});

// assist focusing when using contenteditable
// thank you http://stackoverflow.com/q/9093424/587407
element.focus(function() {
// focus assist is needed only after a placeholder disappeared.
// The placeholder, if any, is already removed at this stage.
// We know there was one when there is no text :
if (element.text()) return; // no placeholder was here, no need to assist focus.

if (document.createRange && window.getSelection) {
var range = document.createRange();
range.selectNodeContents(this);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
});

// Try to display placeholder.
$timeout(show);
});
Expand Down Expand Up @@ -82,7 +99,7 @@
*/

function isActive() {
return ckeditor.instance.container.hasClass('placeholder');
return ckeditor.instance.container.hasClass(className);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test"
],
"devDependencies": {
"angular-ckeditor": "~0.3.1",
"angular-ckeditor": "~0.3.2",
"angular-mocks": "~1.3.8",
"ckeditor": "#full/4.4.2",
"jquery": "~2.1.3"
Expand Down
7 changes: 6 additions & 1 deletion test/angular-ckeditor-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ describe('CKEditor placeholder directive', function () {

var element = $compile('<div ckeditor contenteditable="true" placeholder="test" ng-model="content" ready="onReady()"></div>')(scope);
});
});

// cf. issue #3
// I couldn't manage to get a test on that. If someone has ideas...
it.skip('should not hinder focusing in contenteditable mode');

});

0 comments on commit ff8672c

Please sign in to comment.