HtmlBox set_text function does nothing
I have some problems with this code? Here is my code that creates text editor from area
var box;
...
box = jQuery("#text_vesti").htmlbox({
toolbars:[
[
// Cut, Copy, Paste
"cut","copy","paste",
// Undo, Redo
"undo","redo",
// Bold, Italic, Underline,
"bold","italic","underline"
],
[
// Left, Right, Center, Justify
"justify","left","center","right",
// Ordered List, Unordered List
"ol","ul",
// Hyperlink, Remove Hyperlink, Image
"link","unlink","image"
],
[// Show code
"code",
// Formats, Font size, Font family, Font color, Font, Background
"fontsize","fontfamily",
],
],
skin:"silver",
icons:"silk"
});
it's create editor and it's all ok, but...in some moment I have to put text in editor to re-edit text and I use this function...
function editujOvo (id){
editovanje = true;
id_za_editovanje = id;
jQuery("#r" + pom).css({"background":"none"});
jQuery("#r" + id).css({"background":"#dfdfdf"});
pom = id;
var podaci = "br=3&id=" + id;
// alert(podaci);
jQuery.post("ajax_exe.php", podaci,function(data){
//alert(data.id);
// alert(data.naslov);
alert(data.content);
document.getElementById("naslov_vesti").value = d开发者_开发问答ata.naslov;
//document.getElementById("text_vesti").value = data.content;
box=set_text(data.content);
document.getElementById("date").value = data.datum;
window.frames["news_page"].location.reload();
},'json');
}
but it does nothing, alert just before "set_text" function tels me that data exists and it is in right form and all, but something is missing.... any ideas????
------------ And second question? in this version, or just in mine code, bold button first time does ok, but if I press it to return text to normal, it does nothing, actualy it sets one more pair of <b></b>
tags around text (it's shown in html preview).. where in code of HtmlBox plugin I can repair this function.... any one???? tnx..
set_text is suposed to be a global function? i cant se it defined and the htmlbox plugin uses nice encapsulation so i dont se it having global functions.
maybe the set_text is a method of the box????? like
box.set_text(data.content);
where is the set_text function from??
Store object return from jQuery function like that:
textbox = $('#texteditor').htmlbox({
toolbars:{...}
})
// don't do that:
function YourClass(){}
YourClass.prototype = {}
YourClass.prototype.set_htmlbox = function(){
this.hb = $('#texteditor').htmlbox({
toolbars:{...}
})
}
// because you can't in future use this field to Ajax.
var save = {
icon: 'some.png',
tooltip: 'Save',
command: function(){
// context of this function is window!!!
// DON'T! IT'S INCORRECT!!!
// this.hb.get_text()
// this.post("/save")
// this.get("/text/1")
}
}
this.hb = $('#texteditor').htmlbox({
toolbars:{...,save}
})
But you may do like that:
...
var save = {
icon: 'some.png',
tooltip: 'Save',
command: function(){
YourClass.hb.get_text()
YourClass.post("/save")
YourClass.get("/text/1")
}
}
YourClass.hb = $('#texteditor').htmlbox({
toolbars:{...,save}
})
Or like that
...
var toolname = 'Save'
var save = {
icon: 'some.png',
tooltip: toolname,
command: function(){
}
}
this.hb = $('#texteditor').htmlbox({
toolbars:{...,save}
})
var _this = this // Save context
this.hb.find('input[title='+toolname+']').unbind('click').bind('bind',function(){
_this // <- use context
})
精彩评论