浏览器直接编辑html文件内容,Angular.js 使用execCommands在浏览器中直接编辑HTML内容...

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

var parms = [{

"cmd": "aCommandName",

"desc": "A DOMString representing the name of the command"

}, {

"cmd": "aShowDefaultUI",

"desc": "A Boolean indicating whether the default user interface should be shown. This is not implemented in Mozilla."

}, {

"cmd": "aValueArgument",

"desc": "A DOMString representing some commands (such as insertimage) require an extra value argument (the image's url). Pass an argument of null if no argument is needed."

}];

var commands = [{

"cmd": "backColor",

"val": "red",

"desc": "Changes the document background color. In styleWithCss mode, it affects the background color of the containing block instead. This requires a color value string to be passed in as a value argument. (Internet Explorer uses this to set text background color.)"

}, {

"cmd": "bold",

"icon": "bold",

"desc": "Toggles bold on/off for the selection or at the insertion point. (Internet Explorer uses the STRONG tag instead of B.)"

}, {

"cmd": "contentReadOnly",

"desc": "Makes the content document either read-only or editable. This requires a boolean true/false to be passed in as a value argument. (Not supported by Internet Explorer.)"

}, {

"cmd": "copy",

"icon": "clipboard",

"desc": "Copies the current selection to the clipboard. Clipboard capability must be enabled in the user.js preference file. See"

}, {

"cmd": "createLink",

"val": "http://twitter.com/netsi1964",

"icon": "link",

"desc": "Creates an anchor link from the selection, only if there is a selection. This requires the HREF URI string to be passed in as a value argument. The URI must contain at least a single character, which may be a white space. (Internet Explorer will create a link with a null URI value.)"

}, {

"cmd": "cut",

"icon": "scissors",

"desc": "Cuts the current selection and copies it to the clipboard. Clipboard capability must be enabled in the user.js preference file. See"

}, {

"cmd": "decreaseFontSize",

"desc": "Adds a SMALL tag around the selection or at the insertion point. (Not supported by Internet Explorer.)"

}, {

"cmd": "delete",

"icon": "scissors",

"desc": "Deletes the current selection."

}, {

"cmd": "enableInlineTableEditing",

"desc": "Enables or disables the table row and column insertion and deletion controls. (Not supported by Internet Explorer.)"

}, {

"cmd": "enableObjectResizing",

"desc": "Enables or disables the resize handles on images and other resizable objects. (Not supported by Internet Explorer.)"

}, {

"cmd": "fontName",

"val": "'Inconsolata', monospace",

"desc": "Changes the font name for the selection or at the insertion point. This requires a font name string (\"Arial\" for example) to be passed in as a value argument."

}, {

"cmd": "fontSize",

"val": "1-7",

"icon": "text-height",

"desc": "Changes the font size for the selection or at the insertion point. This requires an HTML font size (1-7) to be passed in as a value argument."

}, {

"cmd": "foreColor",

"val": "rgba(0,0,0,.5)",

"desc": "Changes a font color for the selection or at the insertion point. This requires a color value string to be passed in as a value argument."

}, {

"cmd": "formatBlock",

"desc": "Adds an HTML block-style tag around the line containing the current selection, replacing the block element containing the line if one exists (in Firefox, BLOCKQUOTE is the exception - it will wrap any containing block element). Requires a tag-name string to be passed in as a value argument. Virtually all block style tags can be used (eg. \"H1\", \"P\", \"DL\", \"BLOCKQUOTE\"). (Internet Explorer supports only heading tags H1 - H6, ADDRESS, and PRE, which must also include the tag delimiters < >, such as \"

\".)"

}, {

"cmd": "forwardDelete",

"desc": "Deletes the character ahead of the cursor's position.  It is the same as hitting the delete key."

}, {

"cmd": "heading",

"val": "h3",

"icon": "header",

"desc": "Adds a heading tag around a selection or insertion point line. Requires the tag-name string to be passed in as a value argument (i.e. \"H1\", \"H6\"). (Not supported by Internet Explorer and Safari.)"

}, {

"cmd": "hiliteColor",

"val": "Orange",

"desc": "Changes the background color for the selection or at the insertion point. Requires a color value string to be passed in as a value argument. UseCSS must be turned on for this to function. (Not supported by Internet Explorer.)"

}, {

"cmd": "increaseFontSize",

"desc": "Adds a BIG tag around the selection or at the insertion point. (Not supported by Internet Explorer.)"

}, {

"cmd": "indent",

"icon": "indent",

"desc": "Indents the line containing the selection or insertion point. In Firefox, if the selection spans multiple lines at different levels of indentation, only the least indented lines in the selection will be indented."

}, {

"cmd": "insertBrOnReturn",

"desc": "Controls whether the Enter key inserts a br tag or splits the current block element into two. (Not supported by Internet Explorer.)"

}, {

"cmd": "insertHorizontalRule",

"desc": "Inserts a horizontal rule at the insertion point (deletes selection)."

}, {

"cmd": "insertHTML",

"val": "

Life is great!

",

"icon": "code",

"desc": "Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string to be passed in as a value argument. (Not supported by Internet Explorer.)"

}, {

"cmd": "insertImage",

"val": "http://dummyimage.com/160x90",

"icon": "picture-o",

"desc": "Inserts an image at the insertion point (deletes selection). Requires the image SRC URI string to be passed in as a value argument. The URI must contain at least a single character, which may be a white space. (Internet Explorer will create a link with a null URI value.)"

}, {

"cmd": "insertOrderedList",

"icon": "list-ol",

"desc": "Creates a numbered ordered list for the selection or at the insertion point."

}, {

"cmd": "insertUnorderedList",

"icon": "list-ul",

"desc": "Creates a bulleted unordered list for the selection or at the insertion point."

}, {

"cmd": "insertParagraph",

"icon": "paragraph",

"desc": "Inserts a paragraph around the selection or the current line. (Internet Explorer inserts a paragraph at the insertion point and deletes the selection.)"

}, {

"cmd": "insertText",

"val": new Date(),

"icon": "file-text-o",

"desc": "Inserts the given plain text at the insertion point (deletes selection)."

}, {

"cmd": "italic",

"icon": "italic",

"desc": "Toggles italics on/off for the selection or at the insertion point. (Internet Explorer uses the EM tag instead of I.)"

}, {

"cmd": "justifyCenter",

"icon": "align-center",

"desc": "Centers the selection or insertion point."

}, {

"cmd": "justifyFull",

"icon": "align-justify",

"desc": "Justifies the selection or insertion point."

}, {

"cmd": "justifyLeft",

"icon": "align-left",

"desc": "Justifies the selection or insertion point to the left."

}, {

"cmd": "justifyRight",

"icon": "align-right",

"desc": "Right-justifies the selection or the insertion point."

}, {

"cmd": "outdent",

"icon": "outdent",

"desc": "Outdents the line containing the selection or insertion point."

}, {

"cmd": "paste",

"icon": "clipboard",

"desc": "Pastes the clipboard contents at the insertion point (replaces current selection). Clipboard capability must be enabled in the user.js preference file. See"

}, {

"cmd": "redo",

"icon": "repeat",

"desc": "Redoes the previous undo command."

}, {

"cmd": "removeFormat",

"desc": "Removes all formatting from the current selection."

}, {

"cmd": "selectAll",

"desc": "Selects all of the content of the editable region."

}, {

"cmd": "strikeThrough",

"icon": "strikethrough",

"desc": "Toggles strikethrough on/off for the selection or at the insertion point."

}, {

"cmd": "subscript",

"icon": "subscript",

"desc": "Toggles subscript on/off for the selection or at the insertion point."

}, {

"cmd": "superscript",

"icon": "superscript",

"desc": "Toggles superscript on/off for the selection or at the insertion point."

}, {

"cmd": "underline",

"icon": "underline",

"desc": "Toggles underline on/off for the selection or at the insertion point."

}, {

"cmd": "undo",

"icon": "undo",

"desc": "Undoes the last executed command."

}, {

"cmd": "unlink",

"icon": "chain-broken",

"desc": "Removes the anchor tag from a selected anchor link."

}, {

"cmd": "useCSS ",

"desc": "Toggles the use of HTML tags or CSS for the generated markup. Requires a boolean true/false as a value argument. NOTE: This argument is logically backwards (i.e. use false to use CSS, true to use HTML). (Not supported by Internet Explorer.) This has been deprecated; use the styleWithCSS command instead."

}, {

"cmd": "styleWithCSS",

"desc": "Replaces the useCSS command; argument works as expected, i.e. true modifies/generates style attributes in markup, false generates formatting elements."

}];

angular.module("myApp", [])

.directive("click", function() {

return {

restrict: "A",

link: function(scope, element, attrs) {

element.bind("click", function() {

scope.$evalAsync(attrs.click);

});

}

};

})

.controller("Example", function($scope) {

$scope.supported = function(cmd) {

var css = !!document.queryCommandSupported(cmd.cmd) ? "btn-succes" : "btn-error"

return css

};

$scope.icon = function(cmd) {

return (typeof cmd.icon !== "undefined") ? "fa fa-" + cmd.icon : "";

};

$scope.doCommand = function(cmd) {

if ($scope.supported(cmd) === "btn-error") {

alert("execCommand(“" + cmd.cmd + "”)\nis not supported in your browser");

return;

}

val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "";

document.execCommand(cmd.cmd, false, (cmd.val || ""));

}

$scope.commands = commands;

$scope.tags = [

'Bootstrap', 'AngularJS', 'execCommand'

]

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值