admin管理员组文章数量:1420668
I have a TinyMCE editor on my site. I've added iBrowser so that people can upload graphics. It's ok. I've tried also to enable them to change the background of the site that they are editing but without success: if i add in HTML div with image in background and go back to editor and press enter it moves me below the image and not to another line.
How to enable for users changing background image of site in TinyMCE?
I have a TinyMCE editor on my site. I've added iBrowser so that people can upload graphics. It's ok. I've tried also to enable them to change the background of the site that they are editing but without success: if i add in HTML div with image in background and go back to editor and press enter it moves me below the image and not to another line.
How to enable for users changing background image of site in TinyMCE?
Share Improve this question asked Dec 7, 2011 at 18:36 Tom SmykowskiTom Smykowski 26.2k57 gold badges165 silver badges247 bronze badges 3- 1 Do you plan to let them edit the entire page source, or do you want some sort of DIV with the image on? Alternatively do you want to provide them a way to set the background image and have your backend service set the style for the published page? – Brett Henderson Commented Dec 8, 2011 at 0:48
- i totaly agree with Brett, we do need some more information here – Thariama Commented Dec 8, 2011 at 8:56
- Thanks for questions. Yes, i have it work that way that background that user will change in TinyMCE will be visible on the page where contents generated from TinyMCE is shown. I've tried with DIV, but when i set background on it it shows up in editor. But when i press enter than TinyMCE jumps below div and does sort of weird things. – Tom Smykowski Commented Dec 8, 2011 at 13:54
2 Answers
Reset to default 5The following code will set the background-image style of the document within the editor (where ed is a reference to the current TinyMCE instance)
var edObj = ed.dom.getRoot();
//Set the Style "background-image" to the button's color value.
ed.dom.setStyle(edObj, 'background-image', "url(some_background_image.jpg)");
Note, I've only tested this on Safari and Firefox on Mac.
The only problem is, even if you are editing the entire HTML document using the fullpage plugin it still won't return the document with the style applied when you retrieve the content using getContent().
If you load TinyMCE with a document that has the background-image style already defined, then TinyMCE will render it.
With this in mind, depending on how you provide the end-user the ability to select the image, one approach would be to provide a way to send the selected image details back to your server at the same time as you save the document and process it there, applying the background-image style.
Just an addition to the accepted answer is that you can later retrieve the value you set in a similar fashion using getStyle(). Very useful to have the background image show up in a preview easily.
var edObj = ed.dom.getRoot();
//gets the value that looks like "url(/someImage.jpg)"
//notice getStyle() instead of setStyle
//The boolean at the end is if you want the puted style
var background = ed.dom.getStyle(edObj, 'background-image', true);
document.body.style.background = background;
For a popup displaying a preview just use:
var edObj = tinyMCEPopup.editor.dom.getRoot();
var background = tinyMCEPopup.editor.dom.getStyle(edObj, 'background-image', true);
document.body.style.background = background;
Make sure this is called after the <body>
tag or else document.body
will be undefined.
I hope this helps anyone else looking for a simple grab solution without importing jQuery.
本文标签: javascriptHow to enable user of TinyMCE to change backgroundStack Overflow
版权声明:本文标题:javascript - How to enable user of TinyMCE to change background? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745335844a2654034.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论