我如何更改谷歌页面编辑器使用字体真棒图标
How can I change the Google Pagedown Editor to use font awesome icons?
我们使用带有AngularJS指令的pagedown编辑器。我相信这与在堆栈溢出中使用的相同:
angular.module("ui.pagedown", [])
.directive("pagedownEditor", function ($compile, $timeout, $window, $q) {
var nextId = 0;
var converter = Markdown.getSanitizingConverter();
Markdown.Extra.init(converter, mdExtraOptions);
converter.hooks.chain("preBlockGamut", function (text, rbg) {
return text.replace(/^ {0,3}""" *'n((?:.*?'n)+?) {0,3}""" *$/gm, function (whole, inner) {
return "<blockquote>" + rbg(inner) + "</blockquote>'n";
});
});
return {
restrict: "E",
scope: {
content: "=",
showPreview: "@",
help: "&",
insertImage: "&"
},
link: function (scope, element, attrs) {
var editorUniqueId;
if (attrs.id == null) {
editorUniqueId = nextId++;
} else {
editorUniqueId = attrs.id;
}
// just hide the preview, we still need it for "onPreviewRefresh" hook
var previewHiddenStyle = scope.showPreview == "false" ? "display: none;" : "";
var newElement = $compile(
'<div>' +
'<div class="wmd-panel">' +
'<div id="wmd-button-bar-' + editorUniqueId + '"></div>' +
'<textarea class="wmd-input" id="wmd-input-' + editorUniqueId + '" ng-model="content"></textarea>' +
'</div>' +
'<div id="wmd-preview-' + editorUniqueId + '" class="pagedown-preview wmd-panel wmd-preview" style="' + previewHiddenStyle + '"></div>' +
'</div>')(scope);
// html() doesn't work
element.append(newElement);
var help = angular.isFunction(scope.help) ? scope.help : function () {
// redirect to the guide by default
$window.open("http://daringfireball.net/projects/markdown/syntax", "_blank");
};
var editor = new Markdown.Editor(converter, "-" + editorUniqueId, {
handler: help
});
var editorElement = angular.element(document.getElementById("wmd-input-" + editorUniqueId));
//add watch for content
if(scope.showPreview != "false") {
scope.$watch('content', function () {
editor.refreshPreview();
});
}
editor.hooks.chain("onPreviewRefresh", function() {
// wire up changes caused by user interaction with the pagedown controls
// and do within $apply
$timeout(function() {
scope.content = editorElement.val();
});
});
if (angular.isFunction(scope.insertImage)) {
editor.hooks.set("insertImageDialog", function(callback) {
// expect it to return a promise or a url string
var result = scope.insertImage();
// Note that you cannot call the callback directly from the hook; you have to wait for the current scope to be exited.
// https://code.google.com/p/pagedown/wiki/PageDown#insertImageDialog
$timeout(function() {
if (!result) {
// must be null to indicate failure
callback(null);
} else {
// safe way to handle either string or promise
$q.when(result).then(
function success(imgUrl) {
callback(imgUrl);
},
function error(reason) {
callback(null);
}
);
}
});
return true;
});
}
editor.run();
}
}
})
.directive("pagedownViewer", function ($compile, $sce) {
var converter = Markdown.getSanitizingConverter();
Markdown.Extra.init(converter, mdExtraOptions);
return {
restrict: "E",
scope: {
content: "="
},
link: function (scope, element, attrs) {
var unwatch;
var run = function run() {
// stop continuing and watching if scope or the content is unreachable
if (!scope || (scope.content == undefined || scope.content == null) && unwatch) {
unwatch();
return;
}
scope.sanitizedContent = $sce.trustAsHtml(converter.makeHtml(scope.content));
};
unwatch = scope.$watch("content", run);
run();
var newElementHtml = "<pre ng-bind-html='sanitizedContent'></pre>";
var newElement = $compile(newElementHtml)(scope);
element.append(newElement);
}
}
});
http://plnkr.co/edit/1Vxo5UfYpHQdjhWatimU?p=preview
我们想将其更改为使用字体很棒的图标集,而不是使用图标,但我们不确定如何做到这一点。
有人知道我需要做些什么来让它使用很棒的字体而不是默认的图标吗。
谢谢,
当前PageDown编辑器不支持对按钮栏呈现进行任何自定义。
所以你只剩下三个选项:
- 您只需创建自己的按钮图像文件,并将其用于图标。然而,在这种情况下,你正在失去使用字体真棒的好处
- 分叉并向
Markdown.Editor.js
添加必要的修改 - 您可以在编辑器呈现后更改生成的HTML,删除旧按钮并添加新按钮,但有些功能不起作用,稍后会详细介绍
解决方案1:创建自定义按钮图像
PageDown编辑器使用一个精灵图像来存储所有按钮及其悬停和禁用状态。所以你可以修改它以拥有你的自定义按钮。
然后你只需要更改你的CSS来使用图标(这里我使用了SO编辑器按钮):
.wmd-button > span {
background-image: url("http://cdn.sstatic.net/stackoverflow/img/wmd-buttons.svg");
}
Plunker
解决方案2:分叉Markdown.Editor.js
:
本质上你必须改变两种方法:
- 生成CCD_ 4并应用背景定位的CCD_ 3函数(PageDown编辑器使用大图像来包含所有按钮及其状态)。这里你只需要添加FA类
- 处理事件连线、悬停效果和禁用状态的
setupButton
。在这里,您需要删除已启用的状态处理或可选的悬停处理,因为这也可以在angular-pagedown.css
中完成
所以makeButton
的代码看起来像:
var makeButton = function (id, title, XShift, textOp, faclass) {
var button = document.createElement("li");
button.className = "wmd-button";
button.style.left = xPosition + "px";
xPosition += 25;
var buttonImage = document.createElement("span");
buttonImage.className = "fa " + faclass;
button.id = id + postfix;
button.appendChild(buttonImage);
button.title = title;
button.XShift = XShift;
if (textOp)
button.textOp = textOp;
setupButton(button, true);
buttonRow.appendChild(button);
return button;
};
setupButton
看起来是这样的:
function setupButton(button, isEnabled) {
var image = button.getElementsByTagName("span")[0];
if (isEnabled) {
image.style.color = "#000000"
if (!button.isHelp) {
button.onclick = function () {
doClick(this);
return false;
}
}
}
else {
image.style.color = "#c5c5c5"
button.onmouseover = button.onmouseout = button.onclick = function () { };
}
}
最后,您必须修改makeButton
的调用站点,以便在创建按钮时包含所需的字体真棒类:
buttons.bold = makeButton("wmd-bold-button", getString("bold"), "0px", bindCommand("doBold"), "fa-bold");
//...
在CSS方面,你需要添加悬停效果并删除背景:
.wmd-button > span {
text-align: center;
width: 20px;
height: 20px;
display: inline-block;
}
.wmd-button > span:hover {
background: lightskyblue;
}
Plunker
解决方案3:更改生成的HTML:
此解决方案不需要更改Markdown.Editor,但启用/禁用状态处理不起作用。
基本上,您必须在editor.run();
:之后的角度指令中,将字体真棒类添加到生成的span
:中
var icons = [
{md: "wmd-bold-button", fa: "fa-bold"},
//...
]
icons.forEach(function(i) {
var e = angular.element(document.getElementById(i.md + "-" + editorUniqueId));
e.find("span").addClass("fa "+ i.fa);
});
在这种情况下,您还需要稍微更改CSS:
.wmd-button > span {
width: 20px;
height: 20px;
}
.wmd-button > span:hover {
background: #99cafa;
width: 20px;
height: 20px;
}
Plunker
您可以使用字体很棒的PageDown库
相关文章:
- 向上滑动操作后,字体真棒图标不显示
- 在jquery中设置字体真棒图标
- 如何导出字体真棒svg图标作为base64网址
- 我如何更改谷歌页面编辑器使用字体真棒图标
- 字体真棒图标不显示
- 单击社交媒体图标(字体真棒)而未重定向到href
- 如何将 dijit 树中的图标替换为字体真棒图标
- 如何让导入的 css 字体/图标对影子 dom 中的元素产生影响
- 是否可以在悬停时在两个字体图标之间切换
- 在 JavaScript 之前加载字体图标
- 在占位符上选择2字体真棒图标
- 字体真棒图标,带有点击事件集
- 如何在我的高图表饼图中获取一个数据标签,这是一个字体很棒的图标
- 单击按钮上的图标字体图标(有时是文本)时,Backbone.js事件未触发
- jQuery:旋转加号到减号字体的真棒图标,在手风琴部分点击
- 是否可以将字体图标转换回它'的私人使用代码
- 更改字体图标(字体真棒)在IE中不起作用
- Javascript:在svg's中使用字体图标我如何使用"u"
- SVG中的字体图标在IE 11中不起作用
- 是否有一种方法来访问字体图标从html5画布