我已經將nicEdit添加到我的代碼,但不知何故,當我選擇字體大小和家庭時,nicEdit不顯示所做的選擇。任何出路和可能的解決方案?nicEdit不顯示所選的字體大小和家族
2
A
回答
3
嗯,我調整了一下js文件來得到答案。如果你看起來足夠近,所有的功能都在那裏。 在var nicEditorSelect = bkClass.extend({
內尋找update
函數。當任何拖放框的值被改變時,該函數被調用。 elm
參數傳遞的是值。您可以通過console.log來查看該值。
this.setDisplay(elm)
將設置顯示的選定值。
0
根據最新的nicEdit.js,這裏是我改進選擇選項的解決方案。我修復了顯示文字顯示,但爲每個選項添加了一個新的顯示文本作爲第三個數組參數,以避免一個巨大的標題1顯示文字等。我也調整了寬度。
/* START CONFIG */
var nicSelectOptions = {
buttons: {
'fontFormat' : {name : __('Select Font Format'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'},
'fontFamily': { name: __('Select Font Family'), type: 'nicEditorFontFamilySelect', command: 'fontname' },
'fontSize' : {name : __('Select Font Size'), type : 'nicEditorFontSizeSelect', command : 'fontsize'}
}
};
/* END CONFIG */
var nicEditorSelect = bkClass.extend({
construct : function(e, buttonName, options, nicEditor) {
this.options = options.buttons[buttonName];
this.elm = e;
this.ne = nicEditor;
this.name = buttonName;
this.selOptions = new Array();
this.buttonWidth = buttonName === "fontSize" ? 50 : 100;
this.margin = new bkElement('div').setStyle({ 'float': 'left', margin: '2px 1px 0 1px' }).appendTo(this.elm);
this.contain = new bkElement('div').setStyle({ width: this.buttonWidth + 'px', height: '20px', cursor: 'pointer', overflow: 'hidden' }).addClass('selectContain').addEvent('click', this.toggle.closure(this)).appendTo(this.margin);
this.items = new bkElement('div').setStyle({ overflow: 'hidden', zoom: 1, border: '1px solid #ccc', paddingLeft: '3px', backgroundColor: '#fff' }).appendTo(this.contain);
this.control = new bkElement('div').setStyle({ overflow: 'hidden', 'float': 'right', height: '18px', width: '16px' }).addClass('selectControl').setStyle(this.ne.getIcon('arrow', options)).appendTo(this.items);
this.txt = new bkElement('div').setStyle({ overflow: 'hidden', 'float': 'left', width: this.buttonWidth - 22 + 'px', height: '16px', marginTop: '1px', fontFamily: 'sans-serif', textAlign: 'center', fontSize: '12px' }).addClass('selectTxt').appendTo(this.items);
if (!window.opera) {
this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
}
this.margin.noSelect();
this.ne.addEvent('selected', this.enable.closure(this)).addEvent('blur', function(event) {
this.disable.closure(this);
this.setDisplay(elm);
});
this.disable();
this.init();
},
disable : function() {
this.isDisabled = true;
this.close();
this.contain.setStyle({opacity : 0.6});
},
enable : function(t) {
this.isDisabled = false;
this.close();
this.contain.setStyle({opacity : 1});
},
setDisplay : function(txt) {
this.txt.setContent(txt);
},
toggle : function() {
if(!this.isDisabled) {
(this.pane) ? this.close() : this.open();
}
},
open : function() {
this.pane = new nicEditorPane(this.items, this.ne, { minWidth: this.buttonWidth - 2 + 'px', padding: '0px', borderTop: 0, borderLeft: '1px solid #ccc', borderRight: '1px solid #ccc', borderBottom: '0px', backgroundColor: '#fff' });
for(var i=0;i<this.selOptions.length;i++) {
var opt = this.selOptions[i];
var itmContain = new bkElement('div').setStyle({ overflow: 'hidden', borderBottom: '1px solid #ccc', minWidth: this.buttonWidth - 2 + 'px', textAlign: 'left', overflow: 'hidden', cursor: 'pointer' });
var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
itm.addEvent('click',this.update.closure(this,opt[0],opt[2])).addEvent('mouseover',this.over.closure(this,itm)).addEvent('mouseout',this.out.closure(this,itm)).setAttributes('id',opt[0]);
this.pane.append(itmContain);
if(!window.opera) {
itm.onmousedown = bkLib.cancelEvent;
}
}
},
close : function() {
if(this.pane) {
this.pane = this.pane.remove();
}
},
over : function(opt) {
opt.setStyle({backgroundColor : '#ccc'});
},
out : function(opt) {
opt.setStyle({backgroundColor : '#fff'});
},
add : function(k,v,d) {
this.selOptions.push(new Array(k,v,d));
},
update: function (elm, elmTxt) {
this.ne.nicCommand(this.options.command, elm);
this.setDisplay(elmTxt);
this.close();
}
});
var nicEditorFontFamilySelect = nicEditorSelect.extend({
sel: { 'arial': 'Arial', 'comic sans ms': 'Comic Sans', 'courier new': 'Courier New', 'georgia': 'Georgia', 'helvetica': 'Helvetica', 'impact': 'Impact', 'times new roman': 'Times', 'trebuchet ms': 'Trebuchet', 'verdana': 'Verdana' },
init : function() {
this.setDisplay('Font');
for(itm in this.sel) {
this.add(itm, '<font face="' + itm + '">' + this.sel[itm] + '</font>', '<font face="' + itm + '">' + this.sel[itm] + '</font>');
}
}
});
var nicEditorFontSizeSelect = nicEditorSelect.extend({
sel: { 1: '8', 2: '10', 3: '12', 4: '14', 5: '18', 6: '24' },
init: function() {
this.setDisplay('Size');
for (itm in this.sel) {
this.add(itm, '<font size="' + itm + '">' + this.sel[itm] + '</font>', this.sel[itm]);
}
}
});
var nicEditorFontFormatSelect = nicEditorSelect.extend({
sel: { 'p': 'Paragraph', 'h1': 'Heading 1', 'h2': 'Heading 2', 'h3': 'Heading 3', 'h4': 'Heading 4', 'h5': 'Heading 5', 'h6': 'Heading 6', 'pre': 'Pre' },
init : function() {
this.setDisplay('Style');
for(itm in this.sel) {
var tag = itm.toUpperCase();
this.add('<' + tag + '>', '<' + itm + ' style="padding: 0px; margin: 0px;">' + this.sel[itm] + '</' + tag + '>', this.sel[itm]);
}
}
});
我也重新排序在buttonList的選擇我自己的偏好:
/* START CONFIG */
var nicEditorConfig = bkClass.extend({
buttons : {
'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
'italic' : {name : __('Click to Italic'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
'underline' : {name : __('Click to Underline'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
'left' : {name : __('Left Align'), command : 'justifyleft', noActive : true},
'center' : {name : __('Center Align'), command : 'justifycenter', noActive : true},
'right' : {name : __('Right Align'), command : 'justifyright', noActive : true},
'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true},
'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']},
'ul' : {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']},
'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']},
'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']},
'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
'removeformat' : {name : __('Remove Formatting'), command : 'removeformat', noActive : true},
'indent' : {name : __('Indent Text'), command : 'indent', noActive : true},
'outdent' : {name : __('Remove Indent'), command : 'outdent', noActive : true},
'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true}
},
iconsPath : '../nicEditorIcons.gif',
buttonList: ['save', 'bold', 'italic', 'underline', 'left', 'center', 'right', 'justify', 'ol', 'ul', 'fontFormat', 'fontFamily', 'fontSize', 'indent', 'outdent', 'image', 'upload', 'link', 'unlink', 'forecolor', 'bgcolor'],
iconList : {"bgcolor":1,"forecolor":2,"bold":3,"center":4,"hr":5,"indent":6,"italic":7,"justify":8,"left":9,"ol":10,"outdent":11,"removeformat":12,"right":13,"save":24,"strikethrough":15,"subscript":16,"superscript":17,"ul":18,"underline":19,"image":20,"link":21,"unlink":22,"close":23,"arrow":25}
});
/* END CONFIG */
相關問題
- 1. Django的改變字體大小和字體家族在TinyMCE的
- 2. jQuery更改字體家族和字體大小
- 3. IE 8 - 字體家族顯示問題
- 4. ReportViewer和字體家族
- 5. 在字體設置字體家族(忽略大小)
- 6. TinyMCE增加字體家族下拉字體大小
- 7. 字體大小和瓷磚標題家族
- 8. 什麼是Bootstrap中的blockquote的CSS(字體家族,大小)
- 9. Emacs的字體家族
- 10. 更改字體家族的字體大小和字體重量與JavaScript不工作?
- 11. CSS字體家族在Windows和Mac OS X上的顯示方式不同
- 12. 瞭解字體家族
- 13. 字體家族在Firefox
- 14. Local Storage字體家族
- 15. 字體家族CSS轉換
- 16. dompdf字體家族問題
- 17. NicEdit字體和json
- 18. 無法在段落上設置字體家族或字體大小
- 19. WPF字體家族:Fonts.SystemFontFamilies&System.Drawing.Text.InstalledFontCollection()。家庭
- 20. 如何更改Nicedit編輯器中顯示的文本的Nicedit默認字體大小?
- 21. Jekyll - 如何更改pygments語法突出顯示字體家族?
- 22. 這個CSS字體家族如何正確顯示「Economica」?
- 23. DataGridView複選框在字體大小不大時顯示
- 24. 設置選擇的字體家族在Firefox中,但不在鉻
- 25. 爲什麼字體家族和字體大小不能在這個CSS代碼中工作?
- 26. 字體家族富利簡明額外大膽工作不
- 27. 如何設置Hbase表列家族的列族大小?
- 28. 在Redactor中創建字體家族下拉所見即所得
- 29. 標籤內的字體家族
- 30. 僞元素中的字體家族
是啊,我也尋找解決方案。我查看了行,update:function(elm){ - 如果我提醒elm iam獲取值,現在如何傳遞值以便所選值保持打開狀態。我試過了,this.options.command.val =榆樹沒有任何影響 – FirmView
哎呀!我忘了添加最後一步。ans已被修改。 –
+1感謝您的回答。它適用於字體大小和字體系列。它不適用於字體格式。 – FirmView