forked from wymeditor/wymeditor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wymeditor#256 from winhamwr/issue_239
Fix for wymeditor#239: Added a list plugin that enables tab key indent for lists
- Loading branch information
Showing
7 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,7 @@ jQuery.extend(WYMeditor, { | |
|
||
KEY : { | ||
BACKSPACE: 8, | ||
TAB: 9, | ||
ENTER: 13, | ||
CTRL: 17, | ||
END: 35, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2011 PolicyStat LLC. | ||
* MIT licensed (MIT-license.txt) | ||
* | ||
* This plugin adds the ability to use tab and shift+tab to indent/outdent | ||
* lists, mimicking a user's expected behavior when inside an editor. | ||
* | ||
* @author Wes Winham (winhamwr@gmail.com) | ||
*/ | ||
|
||
function ListPlugin(options, wym) { | ||
this._options = jQuery.extend({}, options); | ||
this._wym = wym; | ||
|
||
this.init(); | ||
} | ||
|
||
ListPlugin.prototype.init = function() { | ||
this._wym.listPlugin = this; | ||
|
||
this.bindEvents(); | ||
} | ||
|
||
ListPlugin.prototype.bindEvents = function() { | ||
var listPlugin = this; | ||
var wym = this._wym; | ||
|
||
// Bind a key listener so we can handle tabs | ||
// With jQuery 1.3, live() can be used to simplify handler logic | ||
$(wym._doc).bind('keydown', listPlugin.handleKeyDown); | ||
} | ||
|
||
/** | ||
* Handle any tab presses when inside list items and indent/outdent. | ||
*/ | ||
ListPlugin.prototype.handleKeyDown = function(evt) { | ||
//'this' is the editor._doc | ||
var wym = WYMeditor.INSTANCES[this.title]; | ||
var listPlugin = wym.listPlugin; | ||
|
||
var container = wym.selected(); | ||
var name = container.tagName.toLowerCase(); | ||
// We only care about tabs when we're inside a list | ||
if (name != "li") { | ||
return null; | ||
} | ||
|
||
// Handle tab presses | ||
if (evt.keyCode == WYMeditor.KEY.TAB) { | ||
if (evt.shiftKey) { | ||
wym.exec('OUTDENT'); | ||
return false; // Short-circuit normal tab behavior | ||
} else { | ||
wym.exec('INDENT'); | ||
return false; | ||
} | ||
} | ||
|
||
return null; | ||
}; |