| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasPanel', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitaspanel', { |
| 5 |
title : 'Panel Shortcode', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
create_oscitas_panel(); |
| 9 |
jQuery.fancybox({ |
| 10 |
'type' : 'inline', |
| 11 |
'title' : 'Panel Shortcode', |
| 12 |
'href' : '#oscitas-form-panel', |
| 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 : "Panel 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('oscitaspanel', tinymce.plugins.oscitasPanel); |
| 37 |
})(); |
| 38 |
|
| 39 |
function create_oscitas_panel(){ |
| 40 |
if(jQuery('#oscitas-form-panel').length){ |
| 41 |
jQuery('#oscitas-form-panel').remove(); |
| 42 |
} |
| 43 |
// creates a form to be displayed everytime the button is clicked |
| 44 |
// you should achieve this using AJAX instead of direct html code like this |
| 45 |
var form = jQuery('<div id="oscitas-form-panel" class="oscitas-container"><table id="oscitas-table" class="form-table">\ |
| 46 |
<tr>\ |
| 47 |
<th><label for="oscitas-type">Style</label></th>\ |
| 48 |
<td><select name="type" id="oscitas-panel-type">\ |
| 49 |
<option value="panel-default">Simple</option>\ |
| 50 |
<option value="panel-primary">Primary</option>\ |
| 51 |
<option value="panel-warning">Warning</option>\ |
| 52 |
<option value="panel-success">Success</option>\ |
| 53 |
<option value="panel-info">Information</option>\ |
| 54 |
<option value="panel-danger">Danger</option>\ |
| 55 |
</select><br />\ |
| 56 |
</td>\ |
| 57 |
</tr>\ |
| 58 |
<tr>\ |
| 59 |
<th><label for="oscitas-line">Show footer</label></th>\ |
| 60 |
<td><input type="checkbox" id="oscitas-panel-footer"/><br />\ |
| 61 |
</td>\ |
| 62 |
</tr>\ |
| 63 |
<tr>\ |
| 64 |
<th><label for="oscitas-panel-class">Custom Class:</label></th>\ |
| 65 |
<td><input type="text" name="line" id="oscitas-panel-class" value=""/><br />\ |
| 66 |
</td>\ |
| 67 |
</tr>\ |
| 68 |
</table>\ |
| 69 |
<p class="submit">\ |
| 70 |
<input type="button" id="oscitas-submit" class="button-primary" value="Insert Panel" name="submit" />\ |
| 71 |
</p>\ |
| 72 |
</div>'); |
| 73 |
|
| 74 |
var table = form.find('table'); |
| 75 |
form.appendTo('body').hide(); |
| 76 |
|
| 77 |
// handles the click event of the submit button |
| 78 |
form.find('#oscitas-submit').click(function(){ |
| 79 |
// defines the options and their default values |
| 80 |
// again, this is not the most elegant way to do this |
| 81 |
// but well, this gets the job done nonetheless |
| 82 |
var cusclass=''; |
| 83 |
if(table.find('#oscitas-panel-class').val()!=''){ |
| 84 |
cusclass= ' class="'+table.find('#oscitas-panel-class').val()+'"'; |
| 85 |
} |
| 86 |
var shortcode = '[panel style="'+table.find('#oscitas-panel-type').val()+ '"'+cusclass+']'; |
| 87 |
shortcode += '<br/>[panel-header]<br/>Heading goes here<br/>[/panel-header]'; |
| 88 |
//shortcode += (table.find('#oscitas-panel-header').prop('checked')? '[panel-header]<br/>Heading goes here<br/>[/panel-header]': ''); |
| 89 |
shortcode += '<br/>[panel-content]<br/>Content goes here<br/>[/panel-content]'; |
| 90 |
shortcode += (table.find('#oscitas-panel-footer').prop('checked')? '<br/>[panel-footer]<br/>Footer goes here<br/>[/panel-footer]': ''); |
| 91 |
shortcode += '<br/>[/panel]'; |
| 92 |
|
| 93 |
// inserts the shortcode into the active editor |
| 94 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 95 |
|
| 96 |
jQuery.fancybox.close(); |
| 97 |
}); |
| 98 |
} |
| 99 |
|
| 100 |
|