Revision 551d4b78
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/ClientJS.pm | ||
---|---|---|
65 | 65 |
removeData => 2, |
66 | 66 |
|
67 | 67 |
# Form Events |
68 |
focus => 1, |
|
68 |
focus => 1, # kivi.set_focus(<TARGET>)
|
|
69 | 69 |
|
70 | 70 |
# Generic Event Handling ## pattern: $(<TARGET>).<FUNCTION>(<ARG1>, kivi.get_function_by_name(<ARG2>)) |
71 | 71 |
on => 3, |
... | ... | |
106 | 106 |
'jstree:deselect_node' => 2, |
107 | 107 |
'jstree:deselect_all' => 1, |
108 | 108 |
|
109 |
# ## ckeditor stuff ## |
|
110 |
'focus_ckeditor' => 1, # kivi.focus_ckeditor_when_ready(<TARGET>) |
|
111 |
|
|
109 | 112 |
# ## other stuff ## |
110 | 113 |
redirect_to => 1, # window.location.href = <TARGET> |
111 | 114 |
|
... | ... | |
201 | 204 |
return $self; |
202 | 205 |
} |
203 | 206 |
|
207 |
sub ckeditor { |
|
208 |
my ($self) = @_; |
|
209 |
$self->{_prefix} = 'ckeditor:'; |
|
210 |
return $self; |
|
211 |
} |
|
212 |
|
|
204 | 213 |
sub flash { |
205 | 214 |
my ($self, $type, @messages) = @_; |
206 | 215 |
|
js/client_js.js | ||
---|---|---|
80 | 80 |
else if (action[0] == 'removeData') $(action[1]).removeData(action[2]); |
81 | 81 |
|
82 | 82 |
// Form Events |
83 |
else if (action[0] == 'focus') $(action[1]).focus();
|
|
83 |
else if (action[0] == 'focus') kivi.set_focus(action[1]);
|
|
84 | 84 |
|
85 | 85 |
// Generic Event Handling ## |
86 | 86 |
else if (action[0] == 'on') $(action[1]).on(action[2], kivi.get_function_by_name(action[3])); |
... | ... | |
121 | 121 |
else if (action[0] == 'jstree:deselect_node') $.jstree._reference($(action[1])).deselect_node(action[2]); |
122 | 122 |
else if (action[0] == 'jstree:deselect_all') $.jstree._reference($(action[1])).deselect_all(); |
123 | 123 |
|
124 |
// ## ckeditor stuff ## |
|
125 |
else if (action[0] == 'focus_ckeditor') kivi.focus_ckeditor_when_ready(action[1]); |
|
126 |
|
|
124 | 127 |
// ## other stuff ## |
125 | 128 |
else if (action[0] == 'redirect_to') window.location.href = action[1]; |
126 | 129 |
else if (action[0] == 'flash') kivi.display_flash(action[1], action[2]); |
js/kivi.js | ||
---|---|---|
27 | 27 |
ns._locale = locale; |
28 | 28 |
}; |
29 | 29 |
|
30 |
ns.set_focus = function(element) { |
|
31 |
var $e = $(element).eq(0); |
|
32 |
if ($e.data('ckeditorInstance')) |
|
33 |
ns.focus_ckeditor_when_ready($e); |
|
34 |
else |
|
35 |
$e.focus(); |
|
36 |
}; |
|
37 |
|
|
38 |
ns.focus_ckeditor_when_ready = function(element) { |
|
39 |
$(element).ckeditor(function() { ns.focus_ckeditor(element); }); |
|
40 |
}; |
|
41 |
|
|
42 |
ns.focus_ckeditor = function(element) { |
|
43 |
var editor = $(element).ckeditorGet(); |
|
44 |
var editable = editor.editable(); |
|
45 |
|
|
46 |
if (editable.is('textarea')) { |
|
47 |
var textarea = editable.$; |
|
48 |
|
|
49 |
if (CKEDITOR.env.ie) |
|
50 |
textarea.createTextRange().execCommand('SelectAll'); |
|
51 |
else { |
|
52 |
textarea.selectionStart = 0; |
|
53 |
textarea.selectionEnd = textarea.value.length; |
|
54 |
} |
|
55 |
|
|
56 |
textarea.focus(); |
|
57 |
|
|
58 |
} else { |
|
59 |
if (editable.is('body')) |
|
60 |
editor.document.$.execCommand('SelectAll', false, null); |
|
61 |
|
|
62 |
else { |
|
63 |
var range = editor.createRange(); |
|
64 |
range.selectNodeContents(editable); |
|
65 |
range.select(); |
|
66 |
} |
|
67 |
|
|
68 |
editor.forceNextSelectionCheck(); |
|
69 |
editor.selectionChange(); |
|
70 |
|
|
71 |
editor.focus(); |
|
72 |
} |
|
73 |
}; |
|
74 |
|
|
30 | 75 |
ns.init_tabwidget = function(element) { |
31 | 76 |
var $element = $(element); |
32 | 77 |
var tabsParams = {}; |
... | ... | |
44 | 89 |
$element.tabs(tabsParams); |
45 | 90 |
}; |
46 | 91 |
|
92 |
ns.init_text_editor = function(element) { |
|
93 |
var layouts = { |
|
94 |
all: [ [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript' ], [ 'BulletedList', 'NumberedList' ], [ 'RemoveFormat' ] ], |
|
95 |
default: [ [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript' ], [ 'BulletedList', 'NumberedList' ], [ 'RemoveFormat' ] ] |
|
96 |
}; |
|
97 |
|
|
98 |
var $e = $(element); |
|
99 |
var buttons = layouts[ $e.data('texteditor-layout') || 'default' ] || layouts['default']; |
|
100 |
var config = { |
|
101 |
entities: false, |
|
102 |
language: 'de', |
|
103 |
removePlugins: 'resize', |
|
104 |
toolbar: buttons |
|
105 |
} |
|
106 |
|
|
107 |
var style = $e.prop('style'); |
|
108 |
$(['width', 'height']).each(function(idx, prop) { |
|
109 |
var matches = (style[prop] || '').match(/(\d+)px/); |
|
110 |
if (matches && (matches.length > 1)) |
|
111 |
config[prop] = matches[1]; |
|
112 |
}); |
|
113 |
|
|
114 |
$e.ckeditor(config); |
|
115 |
|
|
116 |
if ($e.hasClass('texteditor-autofocus')) |
|
117 |
$e.ckeditor(function() { ns.focus_ckeditor($e); }); |
|
118 |
}; |
|
119 |
|
|
47 | 120 |
ns.reinit_widgets = function() { |
48 | 121 |
ns.run_once_for('.datepicker', 'datepicker', function(elt) { |
49 | 122 |
$(elt).datepicker(); |
... | ... | |
63 | 136 |
}); |
64 | 137 |
|
65 | 138 |
ns.run_once_for('.tabwidget', 'tabwidget', kivi.init_tabwidget); |
139 |
ns.run_once_for('.texteditor', 'texteditor', kivi.init_text_editor); |
|
66 | 140 |
}; |
67 | 141 |
|
68 | 142 |
ns.submit_ajax_form = function(url, form_selector, additional_data) { |
Auch abrufbar als: Unified diff
kivi.js: ckeditor über Klasse »texteditor« nutzen können