Debian Codegraph @

closure-library/closure/goog/editor/plugins/listtabhandler.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Editor plugin to handle tab keys in lists to indent and
17 * outdent.
18 *
19 * @author [email protected] (Robby Walker)
20 */
21
22 goog.provide('goog.editor.plugins.ListTabHandler');
23
24 goog.require('goog.dom');
25 goog.require('goog.dom.TagName');
26 goog.require('goog.editor.Command');
27 goog.require('goog.editor.plugins.AbstractTabHandler');
28 goog.require('goog.iter');
29
30
31
32 /**
33 * Plugin to handle tab keys in lists to indent and outdent.
34 * @constructor
35 * @extends {goog.editor.plugins.AbstractTabHandler}
36 * @final
37 */
38 goog.editor.plugins.ListTabHandler = function() {
39 goog.editor.plugins.AbstractTabHandler.call(this);
40 };
41 goog.inherits(
42 goog.editor.plugins.ListTabHandler, goog.editor.plugins.AbstractTabHandler);
43
44
45 /** @override */
46 goog.editor.plugins.ListTabHandler.prototype.getTrogClassId = function() {
47 return 'ListTabHandler';
48 };
49
50
51 /** @override */
52 goog.editor.plugins.ListTabHandler.prototype.handleTabKey = function(e) {
53 var range = this.getFieldObject().getRange();
54 if (goog.dom.getAncestorByTagNameAndClass(
55 range.getContainerElement(), goog.dom.TagName.LI) ||
56 goog.iter.some(range, function(node) {
57 return node.tagName == goog.dom.TagName.LI;
58 })) {
59 this.getFieldObject().execCommand(
60 e.shiftKey ? goog.editor.Command.OUTDENT : goog.editor.Command.INDENT);
61 e.preventDefault();
62 return true;
63 }
64
65 return false;
66 };