प्रश्न पूछने के बाद से कुछ समय हो गया है, लेकिन जैसा कि मैं वर्तमान में बिल्कुल वही बना रहा हूं, मैंने सोचा कि मैं इस मामले के बारे में अपनी खोजों और समाधान साझा करता हूं। :)
मैं काम पर एक परीक्षण परियोजना के लिए TinyMCE का विस्तार कर रहा हूँ और हमारे समाधान कस्टम टैग की जरूरत है - उनमें से कुछ में उपयोगकर्ता, केवल एक ही लाइन में प्रवेश के लिए अन्य लोगों में सक्षम होना चाहिए एक बहुत (अपने उन्हें के रूप में) पाठ का
कदम के लिए किया जाना है, ताकि वांछित समाधान प्राप्त करने के लिए:
TinyMCE संपादक कहता हूं, कि आपके तत्व अच्छा दो विन्यास कीवर्ड extended_valid_elements और custom_elements का उपयोग कर रहे हैं:
tinymce.init({ selector: "textarea#editor", // ... extended_valid_elements : "emstart,emend", custom_elements: "emstart,emend", content_css: "editor.css" });
उद्घाटन और समापन टैग के लिए दो छवियां बनाएं। मैंने उदाहरण के लिए मेरा नाम emstart.png और emend.png के लिए मेरा नाम दिया।
अपने कस्टम तत्वों के लिए एक कस्टम सीएसएस शैली बना सकते हैं और (मेरे मामले में, एक है कि TinyMCE विन्यास में निर्दिष्ट किया जाता editor.css) कस्टम सीएसएस फ़ाइल में डाल:
emstart { background: url(emstart.png) no-repeat; background-position: left -3px top -3px; padding: 10px 10px 5px 10px; background-color:#aabbcc; border:1px dotted #CCCCCC; height:50px; width:100px; }
emend { background: url(emend.png) no-repeat; background-position: left -3px bottom -3px; padding: 5px 10px 10px 10px; background-color:#aabbcc; border:1px dotted #CCCCCC; height:50px; width:100px; }
एक कस्टम प्लगइन लिखें जो नए टैग इनपुट करता है और इसे प्लगइन्स निर्देशिका में डाल देता है।मैं मेरा customem कहा जाता है:
प्लगइन कोड:
tinymce.PluginManager.add('customem', function(editor, url) {
// Add a button that opens a window
editor.addButton('customEmElementButton', {
text: 'Custom EM',
icon: false,
onclick: function() {
// Open window
editor.windowManager.open({
title: 'Please input text',
body: [
{type: 'textbox', name: 'description', label: 'Text'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('<emstart>EM Start</emstart><p>' + e.data.description + '</p><emend>EM End</emend>');
}
});
}
});
// Adds a menu item to the tools menu
editor.addMenuItem('customEmElementMenuItem', {
text: 'Custom EM Element',
context: 'tools',
onclick: function() {
editor.insertContent('<emstart>EM Start</emstart><p>Example text!</p><emend>EM End</emend>');
}
});
});
अंतिम चरण संपादक (प्लगइन और उपकरण पट्टी विन्यास विकल्प का उपयोग) करने के लिए अपने कस्टम प्लगइन लोड करने के लिए है और परिणाम का आनंद लें:
tinymce.init({
selector: "textarea#editor",
height: "500px",
plugins: [
"code, preview, contextmenu, image, link, searchreplace, customem"
],
toolbar: "bold italic | example | code | preview | link | searchreplace | customEmElementButton",
contextmenu: "bold italic",
extended_valid_elements : "emstart,emend",
custom_elements: "emstart,emend",
content_css: "editor.css",
});
अब संपादक इस तरह दिखता है:
और अपने उदाहरण की तरह स्रोत:
बहुत बहुत धन्यवाद! ऐसा खजाना मैं सोच रहा हूं कि वे इस तरह के उदाहरण को डॉक्टर में क्यों नहीं डालते ... या शायद मैंने इसे याद किया है? –
खुशी है कि जवाब मदद की। कम से कम उत्तर लिखने के समय, मुझे लगता है कि यह * बड़ी छवि * को समझने और तथ्यों को एक साथ रखने (और प्रयोग करने) की तरह था - AFAIK दस्तावेज़ में ऐसा कोई उदाहरण नहीं है। – pasty