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 / dropdown / dropdown_plugin.js

dropdown_plugin.js in Easy Bootstrap Shortcode 2.5, at shortcode/dropdown/dropdown_plugin.js

161 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var dropdown={
2 title:"Button Dropdown Shortcode",
3 id :'oscitas-form-dropdown',
4 pluginName: 'dropdown'
5 };
6 (function() {
7 _create_tinyMCE_options(dropdown);
8 })();
9
10 function create_oscitas_dropdown(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 class="main_dp_th"><label for="oscitas-dropdown-heading" >Dropdown Button Features</label></th>\
19 <td><table class="tb_multiple_column_upper">\
20 <thead>\
21 <tr><th>Text</th><th>Size</th><th>Style</th><th>Split</th><th>Dropup</th></tr>\
22 </thead>\
23 <tbody>\
24 <tr>\
25 <td><input type="text" name="dropdown-heading" id="oscitas-dropdown-heading" value="Dropdown"/></td>\
26 <td><select name="type" id="oscitas-dropdown-size">\
27 <option value="">Default</option>\
28 <option value="btn-lg">Large</option>\
29 <option value="btn-sm">Small</option>\
30 <option value="btn-xs">Ex-small</option>\
31 </select><br /></td>\
32 <td><select name="type" id="oscitas-dropdown-style">\
33 <option value="btn-default">Simple</option>\
34 <option value="btn-primary">Primary</option>\
35 <option value="btn-success">Success</option>\
36 <option value="btn-info">Information</option>\
37 <option value="btn-warning">Warning</option>\
38 <option value="btn-danger">Danger</option>\
39 <option value="btn-link">Link</option>\
40 </select><br /></td>\
41 <td><input type="checkbox" name="dropdown-split" id="oscitas-dropdown-split" value="split"/></td>\
42 <td><select name="type" id="oscitas-dropdown-dropup">\
43 <option value="dropdown">Drop Down</option>\
44 <option value="dropup">Drop Up</option>\
45 </select></td>\
46 </tr>\
47 </tbody>\
48 </table></td>\
49 </tr>\
50 <tr>\
51 <th class="main_dp_th"><label for="oscitas-line">Dropdown Items</label></th>\
52 <td><table class="tb_multiple_column">\
53 <thead>\
54 <tr><th>Type</th><th>Link</th><th>Title</th><th>Disabled</th><th>Option</th></tr>\
55 </thead>\
56 <tbody id="oscitas-append-dropdownitem">\
57 <tr class="osc_dropdown_list_item">\
58 <td><input type="hidden" class="oscitas-dropdownitem-type" value="menuitem"><span>Menu Item</span></td>\
59 <td><input type="text" name="dropdown-item-link[]" class="oscitas-dropdownitem-link" value="#"/></td>\
60 <td><input type="text" name="dropdown-item-title[]" class="oscitas-dropdownitem-title" value="Dropdown Item"/></td>\
61 <td><input type="checkbox" name="dropdown-item-disabled[]" class="oscitas-dropdownitem-disabled" value="disabled"/></td><td></td>\
62 </tr>\
63 </tbody>\
64 <tfoot>\
65 <tr><td colspan="5"><a id="osc_add_new_dditem" href="javascript:;" style="text-decoration:none;"><i class="glyphicon glyphicon-plus-sign"></i> Add New Item</a></td></tr>\
66 </tfoot>\
67 </table></td>\
68 </tr>\
69 <tr>\
70 <th><label for="oscitas-dropdown-class">Custom Class:</label></th>\
71 <td><input type="text" name="line" id="oscitas-dropdown-class" value=""/><br />\
72 </td>\
73 </tr>\
74 </table>\
75 <p class="submit">\
76 <input type="button" id="oscitas-dropdown-submit" class="button-primary" value="Insert Dropdown" name="submit" />\
77 </p>\
78 </div>');
79
80 var table = form.find('table');
81 form.appendTo('body').hide();
82 form.find('#osc_add_new_dditem').click(function(){
83 var item='<tr class="osc_dropdown_list_item"><td class="osc_type_change"><select name="dropdown-item-type[]" class="oscitas-dropdownitem-type"><option value="menuitem">Menu Item</option><option value="divider">Divider</option></select></td><td class="osc_hide"><input type="text" name="dropdown-item-link[]" class="oscitas-dropdownitem-link" value="#"/></td><td class="osc_hide"><input type="text" name="dropdown-item-title[]" class="oscitas-dropdownitem-title" value="Dropdown Item"/></td><td class="osc_hide"><input type="checkbox" name="dropdown-item-disabled[]" class="oscitas-dropdownitem-disabled" value="disabled"/></td><td><a class="osc_remove_dditem" href="javascript:;" style="text-decoration:none;"><i class="glyphicon glyphicon-remove"></i></a></td></tr>';
84 form.find('#oscitas-append-dropdownitem').append(item);
85
86 });
87 jQuery('.osc_remove_dditem').live('click',function(){
88 jQuery(this).parent().parent().remove();
89 })
90 jQuery('.osc_type_change').live('change',function(){
91 var par=jQuery(this).parent();
92 var item=jQuery(this);
93 var val=item.find('.oscitas-dropdownitem-type').val();
94 if(val=='divider'){
95 jQuery(par).find('.osc_hide').hide();
96 item.attr('colspan',4);
97 } else{
98 jQuery(par).find('.osc_hide').show();
99 item.attr('colspan',0);
100 }
101 })
102 // handles the click event of the submit button
103 form.find('#oscitas-dropdown-submit').click(function(){
104 var split,dropup;
105 var type,link,title,disabled;
106 var heading= jQuery('#oscitas-dropdown-heading').val();
107
108 if(jQuery('#oscitas-dropdown-split').is(":checked")==true){
109 split= jQuery('#oscitas-dropdown-split').val();
110 } else{
111 split='';
112 }
113 var size= jQuery('#oscitas-dropdown-size').val();
114 var style= jQuery('#oscitas-dropdown-style').val();
115 dropup= 'dropup="'+jQuery('#oscitas-dropdown-dropup').val()+'"';
116
117 var cusclass;
118 if(table.find('#oscitas-dropdown-class').val()!=''){
119 cusclass= ' class="'+table.find('#oscitas-dropdown-class').val()+'"';
120 }
121 else{
122 cusclass='';
123 }
124 var shortcode='';
125 shortcode ='[dropdown '+dropup+cusclass+']<br/>';
126 shortcode +='[dropdownhead style="'+style+'" size="'+size+'" split="'+split+'"]<br/>';
127 shortcode += heading+'<br/>';
128 shortcode +='[/dropdownhead]<br/>';
129 shortcode +='[dropdownbody]<br/>';
130
131 jQuery('tr.osc_dropdown_list_item').each(function(index){
132
133 type = jQuery(this).find('.oscitas-dropdownitem-type').val();
134 link = jQuery(this).find('.oscitas-dropdownitem-link').val();
135 title = jQuery(this).find('.oscitas-dropdownitem-title').val();
136
137 if(jQuery(this).find('.oscitas-dropdownitem-disabled').is(":checked")==true){
138 disabled='disabled="'+jQuery(this).find('.oscitas-dropdownitem-disabled').val()+'"';
139 } else{
140 disabled='';
141 }
142 if(type=='divider'){
143 shortcode +='[dropdownitem type="'+type+'"][/dropdownitem]<br/>';
144 } else if(type=='menuitem'){
145 shortcode +='[dropdownitem type="'+type+'" link="'+link+'" '+disabled+']'+title+'[/dropdownitem]<br/>';
146 }
147
148 });
149
150 shortcode +='[/dropdownbody]<br/>';
151 shortcode +='[/dropdown]';
152
153
154 // inserts the shortcode into the active editor
155 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
156
157 close_dialogue(pluginObj.hashId);
158 });
159 }
160
161