Post by Chris on Sept 3, 2015 19:12:58 GMT -8
Make sure the installed version of your Custom Post Template plugin is at least version 1.0.1, older versions may lack the properties that this script searches for to identify the proper components.
Add the following code to your Global Footer (how to edit your forum headers & footers)
Add the following code to your Global Footer (how to edit your forum headers & footers)
<script>
/* relocate custom template to bbcode tab and enable preview tab */
;
(function () {
if (window.shorty_custom_post_template) {
var scpti = shorty_custom_post_template.init;
shorty_custom_post_template.init = function () {
scpti.call(shorty_custom_post_template);
var wysiwygWidget = $.ui.wysiwyg.prototype;
var custom_template = $('#custom_template_div');
var editorContainer = custom_template.next().show(); //...and unhide wysiwyg wrapper
//force bbcode mode
var createWYSIWYG = wysiwygWidget._create;
if(custom_template.length){
wysiwygWidget._create = function(){
var initial_run = this.options.defaultEditor = 'bbcode';
//find the submit handler and run it on tabswitch to generate the post for preview
//NOTE: required fields not checked during tab switches only at submit time
var getPostText = $.map($('form.form_thread_new,form.form_post_new').data('events').submit, function (ev, i) {
if (ev.handler.toString().indexOf('custom_template_div') != -1){
return ev;
}
return null;
}),
tabswitch = wysiwygWidget.switchEditor;
wysiwygWidget.switchEditor = function (editorName) {
if (editorName == 'visual') {
getPostText[0].handler();
}
tabswitch.apply(this, arguments);
if(initial_run){
$('#menu-item-visual').toggleClass('ui-active', editorName == 'visual');
$('#menu-item-bbcode').toggleClass('ui-active', editorName == 'bbcode');
initial_run = null;
}
}
//call original method
createWYSIWYG.apply(this, arguments);
//hide control bar
$('.ui-wysiwyg .controls').hide()
//hide bbcode editor textarea and replace with custom form
$('.ui-wysiwyg .editors .bbcode-editor').contents().hide().end()
.append(custom_template);
//make preview uneditable
$('body', wysiwygWidget.editors.visual.document).prop('contentEditable', false).attr('contentEditable', 'false')
.on('keydown mousedown', function () {
this.contentEditable = false;
})
//bucket list and mop
$(window).load(function () {
//hide 3rd party stuff (add image, word count, etc.)
editorContainer.find('>:not(.ui-wysiwyg, .wysiwyg-tabs, input, script, textarea)').hide();
custom_template.show();
})
}
};
}
}
})();
</script>