forked from cleditor/cleditor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.cleditor.table.js
90 lines (73 loc) · 2.43 KB
/
jquery.cleditor.table.js
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
/**
@preserve CLEditor Table Plugin v1.0.2
http://premiumsoftware.net/cleditor
requires CLEditor v1.2.2 or later
Copyright 2010, Chris Landowski, Premium Software, LLC
Dual licensed under the MIT or GPL Version 2 licenses.
*/
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name jquery.cleditor.table.min.js
// ==/ClosureCompiler==
var cltai18n_en = {
title: "Insert Table",
cols: "Cols",
rows: "Rows",
submit: "Submit"
};
if (!cltai18n) {
var cltai18n = cltai18n_en;
}
(function($) {
// Define the table button
$.cleditor.buttons.table = {
name: "table",
image: "table.gif",
title: cltai18n.title,
command: "inserthtml",
popupName: "table",
popupClass: "cleditorPrompt",
popupContent:
"<table cellpadding=0 cellspacing=0><tr>" +
"<td>"+cltai18n.cols+":<br><input type=text value=4 size=6></td>" +
"<td>"+cltai18n.rows+":<br><input type=text value=4 size=6></td>" +
"</tr></table><input type=button value='"+cltai18n.submit+"'>",
buttonClick: tableButtonClick
};
// Add the button to the default controls
$.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
.replace("rule ", "rule table ");
// Table button click event handler
function tableButtonClick(e, data) {
// Wire up the submit button click event handler
$(data.popup).children(":button")
.unbind("click")
.bind("click", function(e) {
// Get the editor
var editor = data.editor;
// Get the column and row count
var $text = $(data.popup).find(":text"),
cols = parseInt($text[0].value),
rows = parseInt($text[1].value);
// Build the html
var html;
if (cols > 0 && rows > 0) {
html = "<table cellpadding=2 cellspacing=2 border=1>";
for (y = 0; y < rows; y++) {
html += "<tr>";
for (x = 0; x < cols; x++)
html += "<td>" + x + "," + y + "</td>";
html += "</tr>";
}
html += "</table><br />";
}
// Insert the html
if (html)
editor.execCommand(data.command, html, null, data.button);
// Reset the text, hide the popup and set focus
$text.val("4");
editor.hidePopups();
editor.focus();
});
}
})(jQuery);