var dropdown={
title:"Button Dropdown Shortcode",
id :'oscitas-form-dropdown',
pluginName: 'dropdown'
};
(function() {
_create_tinyMCE_options(dropdown);
})();
function create_oscitas_dropdown(pluginObj){
if(jQuery(pluginObj.hashId).length){
jQuery(pluginObj.hashId).remove();
}
// creates a form to be displayed everytime the button is clicked
// you should achieve this using AJAX instead of direct html code like this
var form = jQuery('
');
var table = form.find('table');
form.appendTo('body').hide();
form.find('#osc_add_new_dditem').click(function(){
var item='Menu Item Divider ';
form.find('#oscitas-append-dropdownitem').append(item);
});
jQuery('.osc_remove_dditem').live('click',function(){
jQuery(this).parent().parent().remove();
})
jQuery('.osc_type_change').live('change',function(){
var par=jQuery(this).parent();
var item=jQuery(this);
var val=item.find('.oscitas-dropdownitem-type').val();
if(val=='divider'){
jQuery(par).find('.osc_hide').hide();
item.attr('colspan',4);
} else{
jQuery(par).find('.osc_hide').show();
item.attr('colspan',0);
}
})
// handles the click event of the submit button
form.find('#oscitas-dropdown-submit').click(function(){
var split,dropup;
var type,link,title,disabled;
var heading= jQuery('#oscitas-dropdown-heading').val();
if(jQuery('#oscitas-dropdown-split').is(":checked")==true){
split= jQuery('#oscitas-dropdown-split').val();
} else{
split='';
}
var size= jQuery('#oscitas-dropdown-size').val();
var style= jQuery('#oscitas-dropdown-style').val();
dropup= 'dropup="'+jQuery('#oscitas-dropdown-dropup').val()+'"';
var cusclass;
if(table.find('#oscitas-dropdown-class').val()!=''){
cusclass= ' class="'+table.find('#oscitas-dropdown-class').val()+'"';
}
else{
cusclass='';
}
var shortcode='';
shortcode ='[dropdown '+dropup+cusclass+'] ';
shortcode +='[dropdownhead style="'+style+'" size="'+size+'" split="'+split+'"] ';
shortcode += heading+' ';
shortcode +='[/dropdownhead] ';
shortcode +='[dropdownbody] ';
jQuery('tr.osc_dropdown_list_item').each(function(index){
type = jQuery(this).find('.oscitas-dropdownitem-type').val();
link = jQuery(this).find('.oscitas-dropdownitem-link').val();
title = jQuery(this).find('.oscitas-dropdownitem-title').val();
if(jQuery(this).find('.oscitas-dropdownitem-disabled').is(":checked")==true){
disabled='disabled="'+jQuery(this).find('.oscitas-dropdownitem-disabled').val()+'"';
} else{
disabled='';
}
if(type=='divider'){
shortcode +='[dropdownitem type="'+type+'"][/dropdownitem] ';
} else if(type=='menuitem'){
shortcode +='[dropdownitem type="'+type+'" link="'+link+'" '+disabled+']'+title+'[/dropdownitem] ';
}
});
shortcode +='[/dropdownbody] ';
shortcode +='[/dropdown]';
// inserts the shortcode into the active editor
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
close_dialogue(pluginObj.hashId);
});
}