listtabhandler.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * @fileoverview Editor plugin to handle tab keys in lists to indent and
  16. * outdent.
  17. *
  18. * @author robbyw@google.com (Robby Walker)
  19. */
  20. goog.provide('goog.editor.plugins.ListTabHandler');
  21. goog.require('goog.dom');
  22. goog.require('goog.dom.TagName');
  23. goog.require('goog.editor.Command');
  24. goog.require('goog.editor.plugins.AbstractTabHandler');
  25. goog.require('goog.iter');
  26. /**
  27. * Plugin to handle tab keys in lists to indent and outdent.
  28. * @constructor
  29. * @extends {goog.editor.plugins.AbstractTabHandler}
  30. * @final
  31. */
  32. goog.editor.plugins.ListTabHandler = function() {
  33. goog.editor.plugins.AbstractTabHandler.call(this);
  34. };
  35. goog.inherits(
  36. goog.editor.plugins.ListTabHandler, goog.editor.plugins.AbstractTabHandler);
  37. /** @override */
  38. goog.editor.plugins.ListTabHandler.prototype.getTrogClassId = function() {
  39. return 'ListTabHandler';
  40. };
  41. /** @override */
  42. goog.editor.plugins.ListTabHandler.prototype.handleTabKey = function(e) {
  43. var range = this.getFieldObject().getRange();
  44. if (goog.dom.getAncestorByTagNameAndClass(
  45. range.getContainerElement(), goog.dom.TagName.LI) ||
  46. goog.iter.some(range, function(node) {
  47. return node.tagName == goog.dom.TagName.LI;
  48. })) {
  49. this.getFieldObject().execCommand(
  50. e.shiftKey ? goog.editor.Command.OUTDENT : goog.editor.Command.INDENT);
  51. e.preventDefault();
  52. return true;
  53. }
  54. return false;
  55. };