| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasDropdown', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitasdropdown', { |
| 5 |
title : 'Button Dropdown Shortcode', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
create_oscitas_dropdown(); |
| 9 |
jQuery.fancybox({ |
| 10 |
'type' : 'inline', |
| 11 |
'title' : 'Button Dropdown Shortcode', |
| 12 |
'href' : '#oscitas-form-dropdown', |
| 13 |
helpers: { |
| 14 |
title : { |
| 15 |
type : 'over', |
| 16 |
position:'top' |
| 17 |
} |
| 18 |
} |
| 19 |
}); |
| 20 |
} |
| 21 |
}); |
| 22 |
}, |
| 23 |
createControl : function(n, cm) { |
| 24 |
return null; |
| 25 |
}, |
| 26 |
getInfo : function() { |
| 27 |
return { |
| 28 |
longname : "Button Dropdown Shortcode", |
| 29 |
author : 'Oscitas Themes', |
| 30 |
authorurl : 'http://www.oscitasthemes.com/', |
| 31 |
infourl : 'http://www.oscitasthemes.com/', |
| 32 |
version : "2.0.0" |
| 33 |
}; |
| 34 |
} |
| 35 |
}); |
| 36 |
tinymce.PluginManager.add('oscitasdropdown', tinymce.plugins.oscitasDropdown); |
| 37 |
})(); |
| 38 |
|
| 39 |
|
| 40 |
function create_oscitas_dropdown(){ |
| 41 |
if(jQuery('#oscitas-form-dropdown').length){ |
| 42 |
jQuery('#oscitas-form-dropdown').remove(); |
| 43 |
} |
| 44 |
// creates a form to be displayed everytime the button is clicked |
| 45 |
// you should achieve this using AJAX instead of direct html code like this |
| 46 |
var form = jQuery('<div id="oscitas-form-dropdown" class="oscitas-container"><table id="oscitas-table" class="form-table">\ |
| 47 |
<tr>\ |
| 48 |
<th class="main_dp_th"><label for="oscitas-dropdown-heading" >Dropdown Button Features</label></th>\ |
| 49 |
<td><table class="tb_multiple_column_upper">\ |
| 50 |
<thead>\ |
| 51 |
<tr><th>Text</th><th>Size</th><th>Style</th><th>Split</th><th>Dropup</th></tr>\ |
| 52 |
</thead>\ |
| 53 |
<tbody>\ |
| 54 |
<tr>\ |
| 55 |
<td><input type="text" name="dropdown-heading" id="oscitas-dropdown-heading" value="Dropdown"/></td>\ |
| 56 |
<td><select name="type" id="oscitas-dropdown-size">\ |
| 57 |
<option value="">Default</option>\ |
| 58 |
<option value="btn-lg">Large</option>\ |
| 59 |
<option value="btn-sm">Small</option>\ |
| 60 |
<option value="btn-xs">Ex-small</option>\ |
| 61 |
</select><br /></td>\ |
| 62 |
<td><select name="type" id="oscitas-dropdown-style">\ |
| 63 |
<option value="btn-default">Simple</option>\ |
| 64 |
<option value="btn-primary">Primary</option>\ |
| 65 |
<option value="btn-success">Success</option>\ |
| 66 |
<option value="btn-info">Information</option>\ |
| 67 |
<option value="btn-warning">Warning</option>\ |
| 68 |
<option value="btn-danger">Danger</option>\ |
| 69 |
<option value="btn-link">Link</option>\ |
| 70 |
</select><br /></td>\ |
| 71 |
<td><input type="checkbox" name="dropdown-split" id="oscitas-dropdown-split" value="split"/></td>\ |
| 72 |
<td><select name="type" id="oscitas-dropdown-dropup">\ |
| 73 |
<option value="dropdown">Drop Down</option>\ |
| 74 |
<option value="dropup">Drop Up</option>\ |
| 75 |
</select></td>\ |
| 76 |
</tr>\ |
| 77 |
</tbody>\ |
| 78 |
</table></td>\ |
| 79 |
</tr>\ |
| 80 |
<tr>\ |
| 81 |
<th class="main_dp_th"><label for="oscitas-line">Dropdown Items</label></th>\ |
| 82 |
<td><table class="tb_multiple_column">\ |
| 83 |
<thead>\ |
| 84 |
<tr><th>Type</th><th>Link</th><th>Title</th><th>Disabled</th><th>Option</th></tr>\ |
| 85 |
</thead>\ |
| 86 |
<tbody id="oscitas-append-dropdownitem">\ |
| 87 |
<tr class="osc_dropdown_list_item">\ |
| 88 |
<td><input type="hidden" class="oscitas-dropdownitem-type" value="menuitem"><span>Menu Item</span></td>\ |
| 89 |
<td><input type="text" name="dropdown-item-link[]" class="oscitas-dropdownitem-link" value="#"/></td>\ |
| 90 |
<td><input type="text" name="dropdown-item-title[]" class="oscitas-dropdownitem-title" value="Dropdown Item"/></td>\ |
| 91 |
<td><input type="checkbox" name="dropdown-item-disabled[]" class="oscitas-dropdownitem-disabled" value="disabled"/></td><td></td>\ |
| 92 |
</tr>\ |
| 93 |
</tbody>\ |
| 94 |
<tfoot>\ |
| 95 |
<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>\ |
| 96 |
</tfoot>\ |
| 97 |
</table></td>\ |
| 98 |
</tr>\ |
| 99 |
<tr>\ |
| 100 |
<th><label for="oscitas-dropdown-class">Custom Class:</label></th>\ |
| 101 |
<td><input type="text" name="line" id="oscitas-dropdown-class" value=""/><br />\ |
| 102 |
</td>\ |
| 103 |
</tr>\ |
| 104 |
</table>\ |
| 105 |
<p class="submit">\ |
| 106 |
<input type="button" id="oscitas-dropdown-submit" class="button-primary" value="Insert Dropdown" name="submit" />\ |
| 107 |
</p>\ |
| 108 |
</div>'); |
| 109 |
|
| 110 |
var table = form.find('table'); |
| 111 |
form.appendTo('body').hide(); |
| 112 |
form.find('#osc_add_new_dditem').click(function(){ |
| 113 |
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>'; |
| 114 |
form.find('#oscitas-append-dropdownitem').append(item); |
| 115 |
|
| 116 |
}); |
| 117 |
jQuery('.osc_remove_dditem').live('click',function(){ |
| 118 |
jQuery(this).parent().parent().remove(); |
| 119 |
}) |
| 120 |
jQuery('.osc_type_change').live('change',function(){ |
| 121 |
var par=jQuery(this).parent(); |
| 122 |
var item=jQuery(this); |
| 123 |
var val=item.find('.oscitas-dropdownitem-type').val(); |
| 124 |
if(val=='divider'){ |
| 125 |
jQuery(par).find('.osc_hide').hide(); |
| 126 |
item.attr('colspan',4); |
| 127 |
} else{ |
| 128 |
jQuery(par).find('.osc_hide').show(); |
| 129 |
item.attr('colspan',0); |
| 130 |
} |
| 131 |
}) |
| 132 |
// handles the click event of the submit button |
| 133 |
form.find('#oscitas-dropdown-submit').click(function(){ |
| 134 |
var split,dropup; |
| 135 |
var type,link,title,disabled; |
| 136 |
var heading= jQuery('#oscitas-dropdown-heading').val(); |
| 137 |
|
| 138 |
if(jQuery('#oscitas-dropdown-split').is(":checked")==true){ |
| 139 |
split= jQuery('#oscitas-dropdown-split').val(); |
| 140 |
} else{ |
| 141 |
split=''; |
| 142 |
} |
| 143 |
var size= jQuery('#oscitas-dropdown-size').val(); |
| 144 |
var style= jQuery('#oscitas-dropdown-style').val(); |
| 145 |
dropup= 'dropup="'+jQuery('#oscitas-dropdown-dropup').val()+'"'; |
| 146 |
|
| 147 |
var cusclass; |
| 148 |
if(table.find('#oscitas-dropdown-class').val()!=''){ |
| 149 |
cusclass= ' class="'+table.find('#oscitas-dropdown-class').val()+'"'; |
| 150 |
} |
| 151 |
else{ |
| 152 |
cusclass=''; |
| 153 |
} |
| 154 |
var shortcode=''; |
| 155 |
shortcode ='[dropdown '+dropup+cusclass+']<br/>'; |
| 156 |
shortcode +='[dropdownhead style="'+style+'" size="'+size+'" split="'+split+'"]<br/>'; |
| 157 |
shortcode += heading+'<br/>'; |
| 158 |
shortcode +='[/dropdownhead]<br/>'; |
| 159 |
shortcode +='[dropdownbody]<br/>'; |
| 160 |
|
| 161 |
jQuery('tr.osc_dropdown_list_item').each(function(index){ |
| 162 |
|
| 163 |
type = jQuery(this).find('.oscitas-dropdownitem-type').val(); |
| 164 |
link = jQuery(this).find('.oscitas-dropdownitem-link').val(); |
| 165 |
title = jQuery(this).find('.oscitas-dropdownitem-title').val(); |
| 166 |
|
| 167 |
if(jQuery(this).find('.oscitas-dropdownitem-disabled').is(":checked")==true){ |
| 168 |
disabled='disabled="'+jQuery(this).find('.oscitas-dropdownitem-disabled').val()+'"'; |
| 169 |
} else{ |
| 170 |
disabled=''; |
| 171 |
} |
| 172 |
if(type=='divider'){ |
| 173 |
shortcode +='[dropdownitem type="'+type+'"][/dropdownitem]<br/>'; |
| 174 |
} else if(type=='menuitem'){ |
| 175 |
shortcode +='[dropdownitem type="'+type+'" link="'+link+'" '+disabled+']'+title+'[/dropdownitem]<br/>'; |
| 176 |
} |
| 177 |
|
| 178 |
}); |
| 179 |
|
| 180 |
shortcode +='[/dropdownbody]<br/>'; |
| 181 |
shortcode +='[/dropdown]'; |
| 182 |
|
| 183 |
|
| 184 |
// inserts the shortcode into the active editor |
| 185 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 186 |
|
| 187 |
jQuery.fancybox.close(); |
| 188 |
}); |
| 189 |
} |
| 190 |
|
| 191 |
|