Commit e4842ab1 authored by jonnybradley's avatar jonnybradley

[FIX] plugins: Move the plugin_***_ready event handling to after the modal has...

[FIX] plugins: Move the plugin_***_ready event handling to after the modal has loaded and partially fix up the codemirror event handling code - need more
parent c6ffb977
......@@ -792,34 +792,42 @@ syntaxHighlighter = {
$(function() {
$('textarea')
.flexibleSyntaxHighlighter();
$('.codelisting')
.flexibleSyntaxHighlighter({
$('.codelisting').each(function () {
$(this).flexibleSyntaxHighlighter({
readOnly: true,
mode: 'null',
width: $(this).width() + 'px',
height: $(this).parent().height() + 'px'
});
})
});
//for plugin code
$(document)
.off('plugin_code_ready')
.on('plugin_code_ready', function(args) {
var colors = args.container.find('#param_colors input:first').hide();
var colorsSelector = $('<select class="form-control"/>')
.insertAfter(colors)
.change(function() {
colors.val(colorsSelector.val());
})
.mousedown(function() {
colorsSelector.change();
})
.mouseup(function() {
colorsSelector.change();
})
.click(function() {
colorsSelector.change();
.on('plugin_code_ready', function (args) {
var updateTextarea = function () {
colors.val(colorsSelector.val());
code.flexibleSyntaxHighlighter({
mode: colorsSelector.val(),
lineNumbers: ln.val() === "1",
theme: theme.val(),
force: true
});
};
var colors = args.modal.find('#param_colors_input').hide(),
ln = args.modal.find('#param_ln_input').change(function () {
updateTextarea.call(this);
}),
theme = args.modal.find('#param_theme_input').change(function () {
updateTextarea.call(this);
}),
code = args.modal.find('textarea[name=content]'),
colorsSelector = $('<select class="form-control"/>')
.insertAfter(colors)
.change(function () {
updateTextarea.call(this);
});
var modes = CodeMirror.modes;
for(var i in modes) {
......@@ -828,15 +836,9 @@ $(function() {
}
}
colorsSelector.val(colors.val());
colorsSelector.val(colors.val()).change();
var code = args.container.find('textarea[name=\"content\"]');
code.flexibleSyntaxHighlighter({
mode: colorsSelector.val(),
lineNumbers: true,
force: true
});
if (codeMirrorTheme == "off") {
if (codeMirrorTheme === "off") {
$(".cm-remove").click(); // cheap fix to have codemirror available but off by default
}
});
......@@ -845,7 +847,7 @@ $(function() {
$(document)
.off('plugin_html_ready')
.on('plugin_html_ready', function(args) {
var code = args.container.find('textarea:first');
var code = args.modal.find('textarea:first');
code.flexibleSyntaxHighlighter({
mode: 'xml',
......@@ -858,7 +860,7 @@ $(function() {
$(document)
.off('plugin_r_ready')
.on('plugin_r_ready', function(args) {
var r = args.container.find('textarea:first');
var r = args.modal.find('textarea:first');
r.flexibleSyntaxHighlighter({
mode: 'r',
......@@ -871,7 +873,7 @@ $(function() {
$(document)
.off('plugin_rr_ready')
.on('plugin_rr_ready', function(args) {
var r = args.container.find('textarea:first');
var r = args.modal.find('textarea:first');
r.flexibleSyntaxHighlighter({
mode: 'r',
......
......@@ -104,27 +104,29 @@
show: false // if it's the first time the show.bs.modal doesn't trigger sometimes
})
.one('loaded.bs.modal', function () { // Bind remote loaded event
// enables conditional display of inputs with a "parent" selector
handlePluginFieldsHierarchy(type);
// bind form button events and form validation
handleFormSubmit(this, type, edit_icon, area_id, replaceText);
// Trigger jQuery event 'plugin_#type#_ready' (see plugin_code_ready in codemirror_tiki.js for example)
$document
.trigger({
type: 'plugin_' + type + '_ready',
container: container,
arguments: arguments,
modal: $modal
})
.trigger({
type: 'plugin_ready',
container: container,
arguments: arguments,
modal: $modal
});
})
.modal("show")
.find('.modal-dialog').addClass("modal-lg");
//This allows users to create plugin snippets for any plugin using the jQuery event 'plugin_#type#_ready' for document
$document
.trigger({
type: 'plugin_' + type + '_ready',
container: container,
arguments: arguments,
modal: $modal
})
.trigger({
type: 'plugin_ready',
container: container,
arguments: arguments,
modal: $modal
});
};
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment