| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasButtons', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitasbuttons', { |
| 5 |
title : 'Buttons Shortcodes', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
jQuery.fancybox({ |
| 9 |
'type' : 'inline', |
| 10 |
'title' : 'Button Shortcode', |
| 11 |
'href' : '#oscitas-form-button', |
| 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 : "Button 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('oscitasbuttons', tinymce.plugins.oscitasButtons); |
| 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-button"><table id="oscitas-table" class="form-table">\ |
| 42 |
<tr>\ |
| 43 |
<th><label for="oscitas-button-style">Style:</label></th>\ |
| 44 |
<td><select name="type" id="oscitas-button-style">\ |
| 45 |
<option value="btn-default">Simple</option>\ |
| 46 |
<option value="btn-primary">Primary</option>\ |
| 47 |
<option value="btn-success">Success</option>\ |
| 48 |
<option value="btn-info">Information</option>\ |
| 49 |
<option value="btn-warning">Warning</option>\ |
| 50 |
<option value="btn-danger">Danger</option>\ |
| 51 |
<option value="btn-link">Link</option>\ |
| 52 |
</select><br />\ |
| 53 |
</td>\ |
| 54 |
</tr>\ |
| 55 |
<tr>\ |
| 56 |
<th><label for="oscitas-button-size">Size:</label></th>\ |
| 57 |
<td><select name="type" id="oscitas-button-size">\ |
| 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 />\ |
| 62 |
</td>\ |
| 63 |
</tr>\ |
| 64 |
<tr>\ |
| 65 |
<th><label for="oscitas-table-rows">Make block</label></th>\ |
| 66 |
<td>\ |
| 67 |
<input type="checkbox" id="oscitas-button-block">\ |
| 68 |
<br />\ |
| 69 |
</td>\ |
| 70 |
</tr>\ |
| 71 |
<tr>\ |
| 72 |
<th><label for="oscitas-button-title">Title:</label></th>\ |
| 73 |
<td><input type="text" name="title" id="oscitas-button-title" value="Button"/><br />\ |
| 74 |
</td>\ |
| 75 |
</tr>\ |
| 76 |
<tr id="tr-button-link">\ |
| 77 |
<th><label for="oscitas-button-link">Link</label></th>\ |
| 78 |
<td><input type="text" name="link" id="oscitas-button-link" value="www.yoursitename.com" /><br />\ |
| 79 |
</td>\ |
| 80 |
</tr>\ |
| 81 |
<tr>\ |
| 82 |
<th><label for="oscitas-table-rows">Open in new window</label></th>\ |
| 83 |
<td>\ |
| 84 |
<input type="checkbox" id="oscitas-button-target">\ |
| 85 |
<br />\ |
| 86 |
</td>\ |
| 87 |
</tr>\ |
| 88 |
</table>\ |
| 89 |
<p class="submit">\ |
| 90 |
<input type="button" id="oscitas-button-submit" class="button-primary" value="Insert Button" name="submit" />\ |
| 91 |
</p>\ |
| 92 |
</div>'); |
| 93 |
|
| 94 |
var table = form.find('table'); |
| 95 |
form.appendTo('body').hide(); |
| 96 |
var colors = ['color','bgcolor']; |
| 97 |
jQuery.each(colors,function(index,color){ |
| 98 |
|
| 99 |
jQuery('#oscitas-form-button').find('#oscitas-button-'+color).after('<div id="bg-'+color+'" style="height:25px;width:25px;"></div>'); |
| 100 |
var defaultcolor = jQuery('#oscitas-button-'+color).val(); |
| 101 |
jQuery('#oscitas-form-button').find('#bg-'+color).css('backgroundColor', '#'+defaultcolor ); |
| 102 |
jQuery('#oscitas-form-button').find('#oscitas-button-'+color).ColorPicker({ |
| 103 |
color: '#0000ff', |
| 104 |
onShow: function (colpkr) { |
| 105 |
jQuery(colpkr).fadeIn(500); |
| 106 |
return false; |
| 107 |
}, |
| 108 |
onHide: function (colpkr) { |
| 109 |
jQuery(colpkr).fadeOut(500); |
| 110 |
return false; |
| 111 |
}, |
| 112 |
onChange: function (hsb, hex, rgb) { |
| 113 |
//jQuery('#oscitas-bgcolor').css('backgroundColor', '#' + hex); |
| 114 |
jQuery('#oscitas-button-'+color).val('#' + hex); |
| 115 |
jQuery('#bg-'+color).css('backgroundColor', '#' + hex) |
| 116 |
|
| 117 |
} |
| 118 |
}); |
| 119 |
|
| 120 |
}); |
| 121 |
|
| 122 |
jQuery('#oscitas-button-type').change(function(){ |
| 123 |
var abc = jQuery(this).val(); |
| 124 |
if('button-link' == abc){ |
| 125 |
jQuery("#tr-button-link").fadeIn(); |
| 126 |
jQuery("#tr-modalname").fadeOut(); |
| 127 |
}else{ |
| 128 |
jQuery("#tr-button-link").fadeOut(); |
| 129 |
jQuery("#tr-modalname").fadeIn(); |
| 130 |
} |
| 131 |
}); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
// handles the click event of the submit button |
| 137 |
form.find('#oscitas-button-submit').click(function(){ |
| 138 |
// defines the options and their default values |
| 139 |
// again, this is not the most elegant way to do this |
| 140 |
// but well, this gets the job done nonetheless |
| 141 |
var options = { |
| 142 |
'title' : 'osCitas', |
| 143 |
'link' : '' |
| 144 |
}; |
| 145 |
var type = jQuery('#oscitas-button-type').val(); |
| 146 |
var shortcode = '[button'; |
| 147 |
|
| 148 |
shortcode += ' class="'+table.find('#oscitas-button-style').val(); |
| 149 |
shortcode += ' '+table.find('#oscitas-button-size').val(); |
| 150 |
shortcode += table.find('#oscitas-button-block').prop('checked')? ' btn-block': ''; |
| 151 |
shortcode += '" '; |
| 152 |
//shortcode += ' btntag="'+table.find('#oscitas-button-type').val()+'" '; |
| 153 |
shortcode += ' target="'+(table.find('#oscitas-button-block').prop('checked')? 'true': 'false')+ '" '; |
| 154 |
|
| 155 |
for( var index in options) { |
| 156 |
var value = table.find('#oscitas-button-' + index).val(); |
| 157 |
var value = table.find('#oscitas-button-' + index).val(); |
| 158 |
shortcode += ' ' + index + '="' + value + '"'; |
| 159 |
} |
| 160 |
|
| 161 |
shortcode += ']'; |
| 162 |
|
| 163 |
// inserts the shortcode into the active editor |
| 164 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 165 |
|
| 166 |
// closes fancybox |
| 167 |
jQuery.fancybox.close(); |
| 168 |
}); |
| 169 |
}); |
| 170 |
|
| 171 |
|