Sha256: 3b4598e92968cd46ae07853042fb6869df069c4abfc54a44c107bbbf05c2d28d

Contents?: true

Size: 1.51 KB

Versions: 19

Compression:

Stored size: 1.51 KB

Contents

/**
 * 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(WYMeditor.OUTDENT);
            return false; // Short-circuit normal tab behavior
        } else {
            wym.exec(WYMeditor.INDENT);
            return false;
        }
    }

    return null;
};

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
tandem-0.2.5 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
tandem-0.2.4 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
tandem-0.2.3 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
tandem-0.2.2 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
tandem-0.2.1 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
tandem-0.2.0 vendor/assets/javascripts/tandem/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.7.5 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.7.4 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.7.2 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.7.1 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.7.0 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.6.4 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.6.2 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.5.6 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.5.5 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.5.2 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.5.1 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.5.0 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js
spud_core-0.4.0 app/assets/javascripts/wymeditor/plugins/list/jquery.wymeditor.list.js