PluginProbe
Easy Bootstrap Shortcode / 2.5
Easy Bootstrap Shortcode v2.5
trunk 2.4.0 2.5 3.4 3.5 3.6 3.7 4.0.0 4.4 4.5 4.5.4 5.0.0 5.0.1 5.0.2
easy-bootstrap-shortcodes / shortcode / notifications / notifications_plugin.js

notifications_plugin.js in Easy Bootstrap Shortcode 2.5, at shortcode/notifications/notifications_plugin.js

82 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var notifications={
2 title:"Notifications Shortcode",
3 id :'oscitas-form-notifications',
4 pluginName: 'notifications'
5 };
6 (function() {
7 _create_tinyMCE_options(notifications);
8 })();
9
10 function create_oscitas_notifications(pluginObj){
11 if(jQuery(pluginObj.hashId).length){
12 jQuery(pluginObj.hashId).remove();
13 }
14 // creates a form to be displayed everytime the button is clicked
15 // you should achieve this using AJAX instead of direct html code like this
16 var form = jQuery('<div id="'+pluginObj.id+'" class="oscitas-container" title="'+pluginObj.title+'"><table id="oscitas-table" class="form-table">\
17 <tr>\
18 <th><label for="oscitas-type">Style :</label></th>\
19 <td><select name="type" id="oscitas-type">\
20 <option value="alert-warning">Warning</option>\
21 <option value="alert-success">Success</option>\
22 <option value="alert-info">Information</option>\
23 <option value="alert-danger">Danger</option>\
24 </select><br />\
25 </td>\
26 </tr>\
27 <tr>\
28 <th><label for="oscitas-line">Close link</label></th>\
29 <td><input type="checkbox" id="oscitas-close"/><br />\
30 </td>\
31 </tr>\
32 <tr>\
33 <th><label for="oscitas-note-class">Custom Class:</label></th>\
34 <td><input type="text" name="line" id="oscitas-note-class" value=""/><br />\
35 </td>\
36 </tr>\
37 </table>\
38 <p class="submit">\
39 <input type="button" id="oscitas-submit" class="button-primary" value="Insert Notification" name="submit" />\
40 </p>\
41 </div>');
42
43 var table = form.find('table');
44 form.appendTo('body').hide();
45
46 // handles the click event of the submit button
47 form.find('#oscitas-submit').click(function(){
48 // defines the options and their default values
49 // again, this is not the most elegant way to do this
50 // but well, this gets the job done nonetheless
51 var options = {
52 'type' : 'error'
53 };
54 var cusclass='';
55 if(table.find('#oscitas-note-class').val()!=''){
56 cusclass= ' class="'+table.find('#oscitas-note-class').val()+'"';
57 }
58 var shortcode = '[notification';
59
60 for( var index in options) {
61 var value = table.find('#oscitas-' + index).val();
62
63 // attaches the attribute to the shortcode only if it's different from the default value
64 //if ( value !== options[index] )
65 shortcode += ' ' + index + '="' + value + '"';
66 }
67
68 var selected_content = tinyMCE.activeEditor.selection.getContent();
69 if(!selected_content)
70 var selected_content = 'Your notification';
71 shortcode += ' close="'+(table.find('#oscitas-close').prop('checked')? 'true': 'false')+ '" ';
72
73 shortcode += cusclass+']'+selected_content+'[/notification]';
74
75 // inserts the shortcode into the active editor
76 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
77
78 close_dialogue(pluginObj.hashId);
79 });
80 }
81
82