Path: blob/trunk/third_party/closure/goog/editor/plugins/headerformatter.js
2868 views
// Copyright 2008 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Handles applying header styles to text.16*17*/1819goog.provide('goog.editor.plugins.HeaderFormatter');2021goog.require('goog.editor.Command');22goog.require('goog.editor.Plugin');23goog.require('goog.userAgent');24252627/**28* Applies header styles to text.29* @constructor30* @extends {goog.editor.Plugin}31* @final32*/33goog.editor.plugins.HeaderFormatter = function() {34goog.editor.Plugin.call(this);35};36goog.inherits(goog.editor.plugins.HeaderFormatter, goog.editor.Plugin);373839/** @override */40goog.editor.plugins.HeaderFormatter.prototype.getTrogClassId = function() {41return 'HeaderFormatter';42};4344// TODO(user): Move execCommand functionality from basictextformatter into45// here for headers. I'm not doing this now because it depends on the46// switch statements in basictextformatter and we'll need to abstract that out47// in order to separate out any of the functions from basictextformatter.484950/**51* Commands that can be passed as the optional argument to execCommand.52* @enum {string}53*/54goog.editor.plugins.HeaderFormatter.HEADER_COMMAND = {55H1: 'H1',56H2: 'H2',57H3: 'H3',58H4: 'H4'59};606162/**63* @override64*/65goog.editor.plugins.HeaderFormatter.prototype.handleKeyboardShortcut = function(66e, key, isModifierPressed) {67if (!isModifierPressed) {68return false;69}70var command = null;71switch (key) {72case '1':73command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H1;74break;75case '2':76command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H2;77break;78case '3':79command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H3;80break;81case '4':82command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H4;83break;84}85if (command) {86this.getFieldObject().execCommand(87goog.editor.Command.FORMAT_BLOCK, command);88// Prevent default isn't enough to cancel tab navigation in FF.89if (goog.userAgent.GECKO) {90e.stopPropagation();91}92return true;93}94return false;95};969798