| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasWell', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitaswell', { |
| 5 |
title : 'Well Shortcode', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
create_oscitas_well(); |
| 9 |
jQuery.fancybox({ |
| 10 |
'type' : 'inline', |
| 11 |
'title' : 'Well Shortcode', |
| 12 |
'href' : '#oscitas-form-well', |
| 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 : "Well 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('oscitaswell', tinymce.plugins.oscitasWell); |
| 37 |
})(); |
| 38 |
|
| 39 |
function create_oscitas_well(){ |
| 40 |
if(jQuery('#oscitas-form-well').length){ |
| 41 |
jQuery('#oscitas-form-well').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-well"><table id="oscitas-table" class="form-table">\ |
| 46 |
<tr>\ |
| 47 |
<th><label for="oscitas-well-type">Well Type:</label></th>\ |
| 48 |
<td><select name="type" id="oscitas-well-type">\ |
| 49 |
<option value="">Default</option>\ |
| 50 |
<option value="well-lg">Large</option>\ |
| 51 |
<option value="well-sm">Small</option>\ |
| 52 |
</select><br />\ |
| 53 |
</td>\ |
| 54 |
</tr>\ |
| 55 |
<tr>\ |
| 56 |
<th><label for="oscitas-well-content">Well Content:</label></th>\ |
| 57 |
<td><textarea name="well" id="oscitas-well-content">Your Content</textarea><br />\ |
| 58 |
</td>\ |
| 59 |
</tr>\ |
| 60 |
<tr>\ |
| 61 |
<th><label for="oscitas-well-class">Custom Class:</label></th>\ |
| 62 |
<td><input type="text" name="line" id="oscitas-well-class" value=""/><br />\ |
| 63 |
</td>\ |
| 64 |
</tr>\ |
| 65 |
</table>\ |
| 66 |
<p class="submit">\ |
| 67 |
<input type="button" id="oscitas-well-submit" class="button-primary" value="Insert Well" name="submit" />\ |
| 68 |
</p>\ |
| 69 |
</div>'); |
| 70 |
|
| 71 |
var table = form.find('table'); |
| 72 |
form.appendTo('body').hide(); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
// handles the click event of the submit button |
| 78 |
form.find('#oscitas-well-submit').click(function(){ |
| 79 |
var cusclass=''; |
| 80 |
if(table.find('#oscitas-well-class').val()!=''){ |
| 81 |
cusclass= ' class="'+table.find('#oscitas-well-class').val()+'"'; |
| 82 |
} |
| 83 |
var shortcode = '[well type="'+jQuery('#oscitas-well-type').val()+'"'+cusclass+']<br class="osc"/>'; |
| 84 |
shortcode += jQuery('#oscitas-well-content').val()+'<br class="osc"/>'; |
| 85 |
shortcode += '[/well]'; |
| 86 |
|
| 87 |
// inserts the shortcode into the active editor |
| 88 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 89 |
|
| 90 |
// closes fancybox |
| 91 |
jQuery.fancybox.close(); |
| 92 |
}); |
| 93 |
} |
| 94 |
|
| 95 |
|