ref: master
public/javascripts/tinymce/tests/manual/custom_theme.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
<!DOCTYPE html> <html> <head> <title>Custom theme manual test</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- TinyMCE --> <script src="../../js/tinymce/tinymce.dev.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/cupertino/jquery-ui.css" type="text/css" /> <script> tinymce.init({ mode: "exact", elements: "elm1", plugins: "autolink,lists,pagebreak,layer,table,save,emoticons,insertdatetime,preview," + "media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,template," + "wordcount,advlist,autosave,visualblocks", content_css: "css/custom_theme_content.css", theme: function(editor, target) { var dom = tinymce.DOM, editorContainer; // Generate UI editorContainer = dom.insertAfter(dom.create('div', {style: 'border: 1px solid gray'}, '<div>' + '<button data-mce-command="bold">B</button>' + '<button data-mce-command="italic">I</button>' + '<button data-mce-command="mceInsertContent" data-mce-value="Hello">Insert Hello</button>' + '</div>' + '<div style="border-top: 1px solid gray"></div>' ), target); // Set editor container size to target element size dom.setStyle(editorContainer, 'width', target.offsetWidth); // Bind events for each button tinymce.each(dom.select('button', editorContainer), function(button) { dom.bind(button, 'click', function(e) { e.preventDefault(); // Execute editor command based on data parameters editor.execCommand(dom.getAttrib(e.target, 'data-mce-command'), false, dom.getAttrib(e.target, 'data-mce-value')); }); }); // Register state change listeners editor.on('init', function() { tinymce.each(dom.select('button', editorContainer), function(button) { editor.formatter.formatChanged(dom.getAttrib(button, 'data-mce-command'), function(state) { button.style.color = state ? "red" : ""; }); }); }); // Return editor and iframe containers return { editorContainer: editorContainer, iframeContainer: editorContainer.lastChild, // Calculate iframe height: target height - toolbar height iframeHeight: target.offsetHeight - editorContainer.firstChild.offsetHeight }; } }); tinymce.init({ mode: "exact", elements: "elm2", plugins: "autolink lists pagebreak layer table save emoticons insertdatetime preview " + "media searchreplace print contextmenu paste directionality fullscreen noneditable visualchars nonbreaking template," + "wordcount,advlist,autosave,visualblocks", content_css: "css/custom_theme_content.css", theme: function(editor, target) { // Generate UI var editorContainer = $(target).after( '<div class="ui-widget ui-corner-all">' + '<div class="ui-widget-header" style="padding: 2px">' + '<input type="checkbox" id="bold" data-mce-command="bold" /><label for="bold">B</label>' + '<input type="checkbox" id="italic" data-mce-command="italic" /><label for="italic">I</label>' + '<button data-mce-command="mceInsertContent" data-mce-value="Hello">Insert Hello</button>' + '</div>' + '<div class="ui-widget-content ui-corner-bottom"></div>' + '</div>' ).next(); // Bind events for each button $("button,input", editorContainer).button().click(function(e) { e.preventDefault(); // Execute editor command based on data parameters editor.execCommand($(this).attr('data-mce-command'),false, $(this).attr('data-mce-value')); }); // Register state change listeners editor.on('init', function() { $("input", editorContainer).each(function(i, button) { editor.formatter.formatChanged($(button).attr('data-mce-command'), function(state) { $(button).attr('checked', state).button('refresh'); }); }); }); // Set editor container with to target width editorContainer.css('width', $(target).width()); // Return editor and iframe containers return { editorContainer: editorContainer[0], iframeContainer: editorContainer.children().eq(-1), // Calculate iframe height: target height - toolbar height iframeHeight: $(target).height() - editorContainer.first().outerHeight() }; } }); </script> <!-- /TinyMCE --> </head> <body> <form method="post" action="http://www.tinymce.com/dump.php?example=true"> <div> <h4>Custom UI using TinyMCE API</h4> <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded --> <div> <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%"> <p> This is some example text that you can edit inside the <strong>TinyMCE editor</strong>. </p> <p> Nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. Nam sed lectus quam, ut sagittis tellus. Quisque dignissim mauris a augue rutrum tempor. Donec vitae purus nec massa vestibulum ornare sit amet id tellus. Nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. Aliquam molestie volutpat dapibus. Nunc interdum viverra sodales. Morbi laoreet pulvinar gravida. Quisque ut turpis sagittis nunc accumsan vehicula. Duis elementum congue ultrices. Cras faucibus feugiat arcu quis lacinia. In hac habitasse platea dictumst. Pellentesque fermentum magna sit amet tellus varius ullamcorper. Vestibulum at urna augue, eget varius neque. Fusce facilisis venenatis dapibus. Integer non sem at arcu euismod tempor nec sed nisl. Morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros. </p> </textarea> </div> <!-- Some integration calls --> <a href="javascript:;" onclick="tinymce.get('elm1').show();return false;">[Show]</a> <a href="javascript:;" onclick="tinymce.get('elm1').hide();return false;">[Hide]</a> <a href="javascript:;" onclick="tinymce.get('elm1').execCommand('Bold');return false;">[Bold]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm1').getContent());return false;">[Get contents]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm1').selection.getContent());return false;">[Get selected HTML]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm1').selection.getContent({format : 'text'}));return false;">[Get selected text]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm1').selection.getNode().nodeName);return false;">[Get selected element]</a> <a href="javascript:;" onclick="tinymce.execCommand('mceInsertContent',false,'<b>Hello world!!</b>');return false;">[Insert HTML]</a> <a href="javascript:;" onclick="tinymce.execCommand('mceReplaceContent',false,'<b>{$selection}</b>');return false;">[Replace selection]</a> </div> <div> <h4>Custom UI using jQuery/jQueryUI APIs</h4> <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded --> <div> <textarea id="elm2" name="elm2" rows="15" cols="80" style="width: 80%"> <p> This is some example text that you can edit inside the <strong>TinyMCE editor</strong>. </p> <p> Nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. Nam sed lectus quam, ut sagittis tellus. Quisque dignissim mauris a augue rutrum tempor. Donec vitae purus nec massa vestibulum ornare sit amet id tellus. Nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. Aliquam molestie volutpat dapibus. Nunc interdum viverra sodales. Morbi laoreet pulvinar gravida. Quisque ut turpis sagittis nunc accumsan vehicula. Duis elementum congue ultrices. Cras faucibus feugiat arcu quis lacinia. In hac habitasse platea dictumst. Pellentesque fermentum magna sit amet tellus varius ullamcorper. Vestibulum at urna augue, eget varius neque. Fusce facilisis venenatis dapibus. Integer non sem at arcu euismod tempor nec sed nisl. Morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros. </p> </textarea> </div> <!-- Some integration calls --> <a href="javascript:;" onclick="tinymce.get('elm2').show();return false;">[Show]</a> <a href="javascript:;" onclick="tinymce.get('elm2').hide();return false;">[Hide]</a> <a href="javascript:;" onclick="tinymce.get('elm2').execCommand('Bold');return false;">[Bold]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm2').getContent());return false;">[Get contents]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm2').selection.getContent());return false;">[Get selected HTML]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm2').selection.getContent({format : 'text'}));return false;">[Get selected text]</a> <a href="javascript:;" onclick="alert(tinymce.get('elm2').selection.getNode().nodeName);return false;">[Get selected element]</a> <a href="javascript:;" onclick="tinymce.execCommand('mceInsertContent',false,'<b>Hello world!!</b>');return false;">[Insert HTML]</a> <a href="javascript:;" onclick="tinymce.execCommand('mceReplaceContent',false,'<b>{$selection}</b>');return false;">[Replace selection]</a> </div> </form> </body> </html> |