| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasPanel', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitaspanel', { |
| 5 |
title : 'Panel Shortcodes', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
jQuery.fancybox({ |
| 9 |
'type' : 'inline', |
| 10 |
'title' : 'Panel Shortcode', |
| 11 |
'href' : '#oscitas-form-panel', |
| 12 |
helpers: { |
| 13 |
title : { |
| 14 |
type : 'over', |
| 15 |
position:'top' |
| 16 |
} |
| 17 |
} |
| 18 |
}); |
| 19 |
} |
| 20 |
}); |
| 21 |
}, |
| 22 |
createControl : function(n, cm) { |
| 23 |
return null; |
| 24 |
}, |
| 25 |
getInfo : function() { |
| 26 |
return { |
| 27 |
longname : "Panel Shortcode", |
| 28 |
author : 'Oscitas Themes', |
| 29 |
authorurl : 'http://www.oscitasthemes.com/', |
| 30 |
infourl : 'http://www.oscitasthemes.com/', |
| 31 |
version : "1.0" |
| 32 |
}; |
| 33 |
} |
| 34 |
}); |
| 35 |
tinymce.PluginManager.add('oscitaspanel', tinymce.plugins.oscitasPanel); |
| 36 |
})(); |
| 37 |
|
| 38 |
jQuery(function(){ |
| 39 |
// creates a form to be displayed everytime the button is clicked |
| 40 |
// you should achieve this using AJAX instead of direct html code like this |
| 41 |
var form = jQuery('<div id="oscitas-form-panel"><table id="oscitas-table" class="form-table">\ |
| 42 |
<tr>\ |
| 43 |
<th><label for="oscitas-type">Style</label></th>\ |
| 44 |
<td><select name="type" id="oscitas-panel-type">\ |
| 45 |
<option value="panel-default">Simple</option>\ |
| 46 |
<option value="panel-primary">Primary</option>\ |
| 47 |
<option value="panel-warning">Warning</option>\ |
| 48 |
<option value="panel-success">Success</option>\\n\ |
| 49 |
<option value="panel-info">Information</option>\ |
| 50 |
<option value="panel-danger">Danger</option>\ |
| 51 |
</select><br />\ |
| 52 |
</td>\ |
| 53 |
</tr>\ |
| 54 |
<tr>\ |
| 55 |
<th><label for="oscitas-line">Show footer</label></th>\ |
| 56 |
<td><input type="checkbox" id="oscitas-panel-footer"/><br />\ |
| 57 |
</td>\ |
| 58 |
</tr>\ |
| 59 |
</table>\ |
| 60 |
<p class="submit">\ |
| 61 |
<input type="button" id="oscitas-submit" class="button-primary" value="Insert Panel" name="submit" />\ |
| 62 |
</p>\ |
| 63 |
</div>'); |
| 64 |
|
| 65 |
var table = form.find('table'); |
| 66 |
form.appendTo('body').hide(); |
| 67 |
|
| 68 |
// handles the click event of the submit button |
| 69 |
form.find('#oscitas-submit').click(function(){ |
| 70 |
// defines the options and their default values |
| 71 |
// again, this is not the most elegant way to do this |
| 72 |
// but well, this gets the job done nonetheless |
| 73 |
var shortcode = '[panel class="'+table.find('#oscitas-panel-type').val()+ '"]'; |
| 74 |
shortcode += '<br/>[panel-header]<br/>Heading goes here<br/>[/panel-header]'; |
| 75 |
//shortcode += (table.find('#oscitas-panel-header').prop('checked')? '[panel-header]<br/>Heading goes here<br/>[/panel-header]': ''); |
| 76 |
shortcode += '<br/>[panel-content]<br/>Content goes here<br/>[/panel-content]'; |
| 77 |
shortcode += (table.find('#oscitas-panel-footer').prop('checked')? '<br/>[panel-footer]<br/>Footer goes here<br/>[/panel-footer]': ''); |
| 78 |
shortcode += '<br/>[/panel]'; |
| 79 |
|
| 80 |
// inserts the shortcode into the active editor |
| 81 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 82 |
|
| 83 |
jQuery.fancybox.close(); |
| 84 |
}); |
| 85 |
}); |
| 86 |
|
| 87 |
|