-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtinymce-dialog.html
71 lines (58 loc) · 2.88 KB
/
tinymce-dialog.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
<!DOCTYPE html>
<html>
<head>
<!-- Disable browser caching of dialog window -->
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />
<style type='text/css'>
body { font-family: sans-serif; font-size: 1.1em; background-color: #F1F1F1; color: #222; }
#tdsk_php_version { font-size: 1.3em; }
input[type="text"] { padding: 4px 6px; }
input[type="submit"] { padding: 4px; font-size: 1.2em; }
</style>
</head>
<body>
<div id="tdsk_dialog_wrapper">
<p id="tdsk_php_version">No data yet. Will be provided by JavaScript below.</p>
<form>
<label for="dumb_shortcode_text">Insert Text Shortcode Should Display</label><br />
<input type="text" name="dumb_shortcode_text" /><br /><br />
<input type="submit" value="Insert Shortcode" />
</form>
</div>
<script type="text/javascript">
// Step 1: Get arguments passed to dialog.
var passed_arguments = top.tinymce.activeEditor.windowManager.getParams();
// Step 1a: Setup jQuery. More Info: http://johnmorris.me/computers/using-jquery-and-jquery-ui-in-tinymce-dialog-iframe/
/**
* To use jQuery, use the $ variable and pass jq_context as the second parameter.
* e.g. $("#tdsk_dialog_wrapper", jq_context)
*/
var $ = passed_arguments.jquery;
var jq_context = document.getElementsByTagName("body")[0];
// Step 2: Insert the shortcode when submit is clicked.
$("form", jq_context).submit(function(event) {
event.preventDefault();
// Step 2a: Construct the shortcode
// Get the input text
var input_text = $("input[name='dumb_shortcode_text']", jq_context).val();
// Construct the shortcode
var shortcode = '[tdsk-dumb-shortcode';
// Do we have a value in the input?
if( input_text != "" ) {
// Yes, we do. Add the text argument to the shortcode.
shortcode += ' text="' + input_text + '"';
}
// Close the shortcode
shortcode += ']';
// Step 2b: Insert the shortcode into the editor
passed_arguments.editor.selection.setContent(shortcode);
passed_arguments.editor.windowManager.close();
});
// Step 3: Use the passed PHP version to prove that passing data
// from PHP can work.
$("#tdsk_php_version", jq_context).text("PHP Version: " + passed_arguments.php_version);
</script>
</body>
</html>