| 1 |
(function() { |
| 2 |
tinymce.PluginManager.add('vbo-shortcodes', function(editor, url) { |
| 3 |
// add Button to Visual Editor Toolbar |
| 4 |
editor.addButton('vbo-shortcodes', { |
| 5 |
title: 'VikBooking Shortcodes List', |
| 6 |
cmd: 'vbo-shortcodes', |
| 7 |
icon: 'wp_code' |
| 8 |
}); |
| 9 |
|
| 10 |
editor.addCommand('vbo-shortcodes', function() { |
| 11 |
openVikBookingShortcodes(editor); |
| 12 |
}); |
| 13 |
|
| 14 |
}); |
| 15 |
})(); |
| 16 |
|
| 17 |
var shortcodes_editor = null; |
| 18 |
|
| 19 |
function openVikBookingShortcodes(editor) { |
| 20 |
|
| 21 |
shortcodes_editor = editor; |
| 22 |
|
| 23 |
var html = ''; |
| 24 |
|
| 25 |
for (var group in VIKBOOKING_SHORTCODES) { |
| 26 |
|
| 27 |
html += '<div class="shortcodes-block">'; |
| 28 |
html += '<div class="shortcodes-group"><a href="javascript: void(0);" onclick="toggleVikBookingShortcode(this);">' + group + '</a></div>'; |
| 29 |
html += '<div class="shortcodes-container">'; |
| 30 |
|
| 31 |
for (var i = 0; i < VIKBOOKING_SHORTCODES[group].length; i++) { |
| 32 |
var row = VIKBOOKING_SHORTCODES[group][i]; |
| 33 |
|
| 34 |
html += '<div class="shortcode-record" onclick="selectVikBookingShortcode(this);" data-code=\'' + row.shortcode + '\'">'; |
| 35 |
html += '<div class="maindetails">' + row.name + '</div>'; |
| 36 |
html += '<div class="subdetails">'; |
| 37 |
html += '<small class="postid">Post ID: ' + row.post_id + '</small>'; |
| 38 |
html += '<small class="createdon">Created On: ' + row.createdon + '</small>'; |
| 39 |
html += '</div>'; |
| 40 |
html += '</div>'; |
| 41 |
} |
| 42 |
|
| 43 |
html += '</div></div>'; |
| 44 |
} |
| 45 |
|
| 46 |
jQuery('body').append( |
| 47 |
'<div id="vbo-shortcodes-backdrop" class="vbo-tinymce-backdrop"></div>\n'+ |
| 48 |
'<div id="vbo-shortcodes-wrap" class="vbo-tinymce-modal wp-core-ui has-text-field" role="dialog" aria-labelledby="link-modal-title">\n'+ |
| 49 |
'<form id="vbo-shortcodes" tabindex="-1">\n'+ |
| 50 |
'<h1>VikBooking Shortcodes List</h1>\n'+ |
| 51 |
'<button type="button" onclick="dismissVikBookingShortcodes();" class="vbo-tinymce-dismiss"><span class="screen-reader-text">Close</span></button>\n'+ |
| 52 |
'<div class="vbo-tinymce-body">' + html + '</div>\n'+ |
| 53 |
'<div class="vbo-tinymce-submitbox">\n'+ |
| 54 |
'<div id="vbo-tinymce-cancel">\n'+ |
| 55 |
'<button type="button" class="button" onclick="dismissVikBookingShortcodes();">Cancel</button>\n'+ |
| 56 |
'</div>\n'+ |
| 57 |
'<div id="vbo-tinymce-update">\n'+ |
| 58 |
'<button type="button" class="button button-primary" disabled onclick="putVikBookingShortcode();">Add</button>\n'+ |
| 59 |
'</div>\n'+ |
| 60 |
'</div>\n'+ |
| 61 |
'</form>\n'+ |
| 62 |
'</div>\n' |
| 63 |
); |
| 64 |
|
| 65 |
jQuery('#vbo-shortcodes-backdrop').on('click', function() { |
| 66 |
dismissVikBookingShortcodes(); |
| 67 |
}); |
| 68 |
} |
| 69 |
|
| 70 |
function dismissVikBookingShortcodes() { |
| 71 |
jQuery('#vbo-shortcodes-backdrop, #vbo-shortcodes-wrap').remove(); |
| 72 |
} |
| 73 |
|
| 74 |
function toggleVikBookingShortcode(link) { |
| 75 |
var next = jQuery(link).parent().next(); |
| 76 |
var show = next.is(':visible') ? false : true; |
| 77 |
|
| 78 |
jQuery('.shortcodes-container').slideUp(); |
| 79 |
|
| 80 |
if (show) { |
| 81 |
next.slideDown(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
function selectVikBookingShortcode(record) { |
| 86 |
jQuery('.shortcode-record').removeClass('selected'); |
| 87 |
jQuery(record).addClass('selected'); |
| 88 |
|
| 89 |
jQuery('#vbo-tinymce-update button').prop('disabled', false); |
| 90 |
} |
| 91 |
|
| 92 |
function putVikBookingShortcode() { |
| 93 |
var shortcode = jQuery('.shortcode-record.selected').data('code'); |
| 94 |
|
| 95 |
shortcodes_editor.execCommand('mceReplaceContent', false, shortcode); |
| 96 |
|
| 97 |
dismissVikBookingShortcodes(); |
| 98 |
} |
| 99 |
|