| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.oscitasWpcolumns', { |
| 3 |
init : function(ed, url) { |
| 4 |
ed.addButton('oscitaswpcolumns', { |
| 5 |
title : 'Columns Shortcodes', |
| 6 |
image : url+'/icon.png', |
| 7 |
onclick : function() { |
| 8 |
create_oscitas_wpcolumns(); |
| 9 |
jQuery.fancybox({ |
| 10 |
'autoSize':false, |
| 11 |
'autoWidth':false, |
| 12 |
'fitToView':false, |
| 13 |
'width':1094, |
| 14 |
'type' : 'inline', |
| 15 |
'title' : 'Columns Shortcode', |
| 16 |
'height': 'auto', |
| 17 |
'href' : '#oscitas-form-wpcolumns', |
| 18 |
helpers: { |
| 19 |
title : { |
| 20 |
type : 'over', |
| 21 |
position:'top' |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
}); |
| 26 |
} |
| 27 |
}); |
| 28 |
}, |
| 29 |
createControl : function(n, cm) { |
| 30 |
return null; |
| 31 |
}, |
| 32 |
getInfo : function() { |
| 33 |
return { |
| 34 |
longname : "Columns Shortcode", |
| 35 |
author : 'Oscitas Themes', |
| 36 |
authorurl : 'http://www.oscitasthemes.com/', |
| 37 |
infourl : 'http://www.oscitasthemes.com/', |
| 38 |
version : "2.0.0" |
| 39 |
}; |
| 40 |
} |
| 41 |
}); |
| 42 |
tinymce.PluginManager.add('oscitaswpcolumns', tinymce.plugins.oscitasWpcolumns); |
| 43 |
})(); |
| 44 |
|
| 45 |
function create_oscitas_wpcolumns(){ |
| 46 |
if(jQuery('#oscitas-form-wpcolumns').length){ |
| 47 |
jQuery('#oscitas-form-wpcolumns').remove(); |
| 48 |
} |
| 49 |
// creates a form to be displayed everytime the button is clicked |
| 50 |
// you should achieve this using AJAX instead of direct html code like this |
| 51 |
var form = jQuery('<div id="oscitas-form-wpcolumns" class="oscitas-container">\ |
| 52 |
<table id="oscitas-table" class="form-table">\ |
| 53 |
<tr>\ |
| 54 |
<th><label for="oscitas-no-of-wpcolumns">Number of columns</label></th>\ |
| 55 |
<td><select name="type" id="oscitas-no-of-wpcolumns">\ |
| 56 |
<option value="1" selected="selected">One column</option>\ |
| 57 |
<option value="2">Two columns</option>\ |
| 58 |
<option value="3">Three columns</option>\ |
| 59 |
<option value="4">Four columns</option>\ |
| 60 |
</select><br />\ |
| 61 |
</td>\ |
| 62 |
</tr>\ |
| 63 |
<tr id="wptwo" style="display:none;">\ |
| 64 |
<th><label for="oscitas-two-columns">2 column division</label></th>\ |
| 65 |
<td><select name="type" id="oscitas-two-columns" class="osc-change-col">\ |
| 66 |
<option value="6$6">1/2-1/2</option>\ |
| 67 |
<option value="4$8">1/3-2/3</option>\ |
| 68 |
<option value="8$3">2/3-1/3</option>\ |
| 69 |
<option value="3$9">1/4-3/4</option>\ |
| 70 |
<option value="9$3">3/4-1/4</option>\ |
| 71 |
</select> For Large Screen<br />\ |
| 72 |
</td>\ |
| 73 |
</tr>\ |
| 74 |
<tr id="wpthree" style="display:none;">\ |
| 75 |
<th><label for="oscitas-three-columns">3 column division</label></th>\ |
| 76 |
<td><select name="type" id="oscitas-three-columns" class="osc-change-col">\ |
| 77 |
<option value="4$4$4">1/3-1/3-1/3</option>\ |
| 78 |
<option value="3$6$3">1/4-2/4-1/4</option>\ |
| 79 |
<option value="3$3$6">1/4-1/4-2/4</option>\ |
| 80 |
<option value="6$3$3">2/4-1/4-1/4</option>\ |
| 81 |
</select> For Large Screen<br />\ |
| 82 |
</tr>\ |
| 83 |
<tr id="">\ |
| 84 |
<th><label for="append_column_table">Column Specification</label></th>\ |
| 85 |
<td id="append_column_table"></td>\ |
| 86 |
</tr>\ |
| 87 |
<tr>\ |
| 88 |
<th><label for="oscitas-column-class">Custom Class:</label></th>\ |
| 89 |
<td><input type="text" name="line" id="oscitas-column-class" value=""/>\ |
| 90 |
</td>\ |
| 91 |
</tr>\ |
| 92 |
</table>\ |
| 93 |
<p class="submit">\ |
| 94 |
<input type="button" id="oscitas-submit-wp_column" class="button-primary" value="Insert Columns" name="submit" />\ |
| 95 |
</p>\ |
| 96 |
</div>'); |
| 97 |
var table = form.find('table'); |
| 98 |
form.appendTo('body').hide(); |
| 99 |
|
| 100 |
function show_table(){ |
| 101 |
|
| 102 |
var ele='',e=0,sm,smoff,md,mdoff,lg,lgoff,xs,xsoff,sel,val=0,selcol,hidecol; |
| 103 |
var col= form.find('#oscitas-no-of-wpcolumns').val(); |
| 104 |
ele = '<i>You can select different column style for different screens such as medium, small(e.g < 992px), x-small(e.g < 768px)</i><br/>'; |
| 105 |
|
| 106 |
var option={ |
| 107 |
'lg':'Large Screen', |
| 108 |
'md': 'Medium Screen', |
| 109 |
'sm': 'Small Screen', |
| 110 |
'xs':'X-small Screen' |
| 111 |
} |
| 112 |
ele+= '<table id="appended" class="tb_multiple_column"><thead><tr><th>Screen</th><th style="min-width:50px;max-width:50px">Hide Row</th>'; |
| 113 |
|
| 114 |
for(i=1;i<=col;i++){ |
| 115 |
ele+='<th><div class="head_division head_division_check">Clear Left</div><div class="head_division">Column</div><div class="head_division">Offset</div><div class="head_division head_division_check right">Hide</div></th>'; |
| 116 |
|
| 117 |
} |
| 118 |
ele+= '</tr></thead><tbody class="column_tbody">'; |
| 119 |
jQuery.each(option,function(index,val){ |
| 120 |
ele+='<tr><th class="column_td_first">'+val+'</th><td style="min-width:50px;max-width:50px"><input type="checkbox" name="'+index+'rowhide" id="'+index+'rowhide" value="yes"></td>'; |
| 121 |
for(var i=1;i<=col;i++){ |
| 122 |
sm='<select name="'+index+'['+i+']" id="'+index+i+'">'; |
| 123 |
for( e=1;e<=12;e++){ |
| 124 |
if(index=='lg'){ |
| 125 |
|
| 126 |
selcol=12/col; |
| 127 |
if(e==selcol){ |
| 128 |
sel='selected=selected' |
| 129 |
} |
| 130 |
else{ |
| 131 |
sel=''; |
| 132 |
} |
| 133 |
} else{ |
| 134 |
if(e==12){ |
| 135 |
sel='selected=selected' |
| 136 |
} |
| 137 |
else{ |
| 138 |
sel=''; |
| 139 |
} |
| 140 |
} |
| 141 |
sm+='<option value="'+e+'" '+sel+'>'+e+'</option>'; |
| 142 |
} |
| 143 |
sm+='</select>'; |
| 144 |
smoff='<select name="'+index+'off['+i+']" id="'+index+'off'+i+'">'; |
| 145 |
for( e=0;e<12;e++){ |
| 146 |
|
| 147 |
smoff+='<option value="'+e+'">'+e+'</option>'; |
| 148 |
} |
| 149 |
smoff+='</select>'; |
| 150 |
|
| 151 |
clearleft='<input type="checkbox" name="'+index+'clear['+i+']" id="'+index+'clear'+i+'" value="yes">'; |
| 152 |
|
| 153 |
hidecol='<input type="checkbox" name="'+index+'hide['+i+']" id="'+index+'hide'+i+'" value="yes">'; |
| 154 |
|
| 155 |
|
| 156 |
ele+='<td><div class="head_division head_division_check">'+clearleft+'</div><div class="head_division">'+sm+'</div><div class="head_division">'+smoff+'</div><div class="head_division head_division_check right">'+hidecol+'</div></td>'; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
} |
| 161 |
ele+='</tr>'; |
| 162 |
}); |
| 163 |
ele +='</tbody></table>'; |
| 164 |
table.find('#append_column_table').html(ele); |
| 165 |
jQuery('#oscitas-form-wpcolumns table>tr:visible:even').css('background', '#F0F0F0'); |
| 166 |
jQuery('#oscitas-form-wpcolumns table>tr:visible:odd').css('background', '#DADADD'); |
| 167 |
|
| 168 |
} |
| 169 |
function chnage_col_value(){ |
| 170 |
|
| 171 |
var col= form.find('#oscitas-no-of-wpcolumns').val(),str,arr=[],i=0; |
| 172 |
if(col==2 || col==3){ |
| 173 |
if(col==2){ |
| 174 |
str=form.find('#oscitas-two-columns').val(); |
| 175 |
} else if(col==3){ |
| 176 |
str=form.find('#oscitas-three-columns').val(); |
| 177 |
} |
| 178 |
arr=str.split('$'); |
| 179 |
jQuery.each(arr,function(index,val){ |
| 180 |
i=parseInt(index)+1; |
| 181 |
jQuery('#lg'+i).val(val); |
| 182 |
}) |
| 183 |
|
| 184 |
} |
| 185 |
jQuery('#oscitas-form-wpcolumns table tr:visible:even').css('background', '#F0F0F0'); |
| 186 |
jQuery('#oscitas-form-wpcolumns table tr:visible:odd').css('background', '#DADADD'); |
| 187 |
} |
| 188 |
|
| 189 |
show_table(); |
| 190 |
|
| 191 |
jQuery('#oscitas-no-of-wpcolumns').change(function(){ |
| 192 |
var noOfColumns = jQuery(this).val(); |
| 193 |
if(2 == noOfColumns){ |
| 194 |
|
| 195 |
jQuery("#wpthree").hide(); |
| 196 |
jQuery("#wptwo").show(); |
| 197 |
} |
| 198 |
else if(3 == noOfColumns){ |
| 199 |
jQuery("#wptwo").hide(); |
| 200 |
jQuery("#wpthree").show(); |
| 201 |
} |
| 202 |
else{ |
| 203 |
jQuery("#wptwo").hide(); |
| 204 |
jQuery("#wpthree").hide(); |
| 205 |
|
| 206 |
} |
| 207 |
show_table(); |
| 208 |
chnage_col_value(); |
| 209 |
|
| 210 |
|
| 211 |
}); |
| 212 |
form.find('.osc-change-col').change(function(){ |
| 213 |
chnage_col_value(); |
| 214 |
}) |
| 215 |
var arr={ |
| 216 |
1:'lg', |
| 217 |
2: 'md', |
| 218 |
3:'sm', |
| 219 |
4:'xs' |
| 220 |
}; |
| 221 |
|
| 222 |
|
| 223 |
var value1 =0,valueoff=0,lastSel,previous; |
| 224 |
jQuery.each(arr,function(i,valuenum){ |
| 225 |
jQuery.each(arr,function(tt,index){ |
| 226 |
|
| 227 |
jQuery('#'+index+i).live('focus',function(){ |
| 228 |
previous = this.value; |
| 229 |
}).live('change',function(){ |
| 230 |
value1= parseInt(jQuery(this).val()); |
| 231 |
valueoff =parseInt(jQuery('#'+index+'off'+i).val()); |
| 232 |
value1=value1+valueoff; |
| 233 |
if(value1<=12){ |
| 234 |
previous = this.value; |
| 235 |
} |
| 236 |
else{ |
| 237 |
jQuery('#'+index+i).val(previous); |
| 238 |
alert('Can\'t Change, exceeds the limit'); |
| 239 |
} |
| 240 |
}); |
| 241 |
|
| 242 |
jQuery('#'+index+'off'+i).live('focus',function(){ |
| 243 |
previous = this.value; |
| 244 |
}).live('change',function(){ |
| 245 |
value1= parseInt(jQuery(this).val()); |
| 246 |
valueoff = parseInt(jQuery('#'+index+i).val()); |
| 247 |
value1=value1+valueoff; |
| 248 |
if(value1<=12){ |
| 249 |
previous = this.value; |
| 250 |
} |
| 251 |
else{ |
| 252 |
jQuery('#'+index+'off'+i).val(previous); |
| 253 |
alert('Can\'t Change, exceeds the limit'); |
| 254 |
} |
| 255 |
}) |
| 256 |
}) |
| 257 |
}); |
| 258 |
|
| 259 |
// handles the click event of the submit button |
| 260 |
form.find('#oscitas-submit-wp_column').click(function(){ |
| 261 |
// defines the options and their default values |
| 262 |
// again, this is not the most elegant way to do this |
| 263 |
// but well, this gets the job done nonetheless |
| 264 |
var a_md=[],a_sm=[],a_xs=[],a_lg=[],j=0,a_md_off=[],a_sm_off=[],a_xs_off=[],a_lg_off=[],a_md_hide=[],a_sm_hide=[],a_xs_hide=[],a_lg_hide=[],sm='',md='',xs='',smoff='',mdoff='',xsoff='',lgoff='',smhide='',mdhide='',xshide='',lghide='',smclear='',mdclear='',xsclear='',lgclear=''; |
| 265 |
|
| 266 |
|
| 267 |
var noOfColumns = jQuery('#oscitas-no-of-wpcolumns').val(); |
| 268 |
var shortcode = ''; |
| 269 |
var cusclass=''; |
| 270 |
if(table.find('#oscitas-column-class').val()!=''){ |
| 271 |
cusclass= ' class="'+table.find('#oscitas-column-class').val()+'"'; |
| 272 |
} |
| 273 |
shortcode ='[row'+cusclass+']'; |
| 274 |
for(var i=1;i<=parseInt(noOfColumns);i++){ |
| 275 |
|
| 276 |
a_md[i] = jQuery('#md'+i).val(); |
| 277 |
a_sm[i] = jQuery('#sm'+i).val(); |
| 278 |
a_xs[i] = jQuery('#xs'+i).val(); |
| 279 |
a_lg[i] = jQuery('#lg'+i).val(); |
| 280 |
a_md_off[i] = jQuery('#mdoff'+i).val(); |
| 281 |
a_sm_off[i] = jQuery('#smoff'+i).val(); |
| 282 |
a_xs_off[i] = jQuery('#xsoff'+i).val(); |
| 283 |
a_lg_off[i] = jQuery('#lgoff'+i).val(); |
| 284 |
|
| 285 |
//if(a_md[i]!=12){ |
| 286 |
md=' md="'+a_md[i]+'"'; |
| 287 |
//} else{ |
| 288 |
// md=''; |
| 289 |
//} |
| 290 |
//if(a_sm[i]!=12){ |
| 291 |
sm=' sm="'+a_sm[i]+'"'; |
| 292 |
//} else{ |
| 293 |
// sm=''; |
| 294 |
//} |
| 295 |
//if(a_xs[i]!=12){ |
| 296 |
xs=' xs="'+a_xs[i]+'"'; |
| 297 |
//} else{ |
| 298 |
// xs=''; |
| 299 |
//} |
| 300 |
if(a_md_off[i]!=0){ |
| 301 |
mdoff=' mdoff="'+a_md_off[i]+'"'; |
| 302 |
} |
| 303 |
else{ |
| 304 |
mdoff=''; |
| 305 |
} |
| 306 |
if(a_sm_off[i]!=0){ |
| 307 |
smoff=' smoff="'+a_sm_off[i]+'"'; |
| 308 |
} |
| 309 |
else{ |
| 310 |
smoff=''; |
| 311 |
} |
| 312 |
if(a_xs_off[i]!=0){ |
| 313 |
xsoff=' xsoff="'+a_xs_off[i]+'"'; |
| 314 |
} |
| 315 |
else{ |
| 316 |
xsoff=''; |
| 317 |
} |
| 318 |
if(a_lg_off[i]!=0){ |
| 319 |
lgoff=' lgoff="'+a_lg_off[i]+'"'; |
| 320 |
} |
| 321 |
else{ |
| 322 |
lgoff=''; |
| 323 |
} |
| 324 |
|
| 325 |
if(jQuery('#mdrowhide').is(':checked') || jQuery('#mdhide'+i).is(':checked')){ |
| 326 |
mdhide=' mdhide="yes"'; |
| 327 |
} |
| 328 |
else{ |
| 329 |
mdhide=''; |
| 330 |
} |
| 331 |
if(jQuery('#smrowhide').is(':checked') ||jQuery('#smhide'+i).is(':checked')){ |
| 332 |
smhide=' smhide="yes"'; |
| 333 |
} |
| 334 |
else{ |
| 335 |
smhide=''; |
| 336 |
} |
| 337 |
if(jQuery('#xsrowhide').is(':checked') ||jQuery('#xshide'+i).is(':checked')){ |
| 338 |
xshide=' xshide="yes"'; |
| 339 |
} |
| 340 |
else{ |
| 341 |
xshide=''; |
| 342 |
} |
| 343 |
if(jQuery('#lgrowhide').is(':checked') ||jQuery('#lghide'+i).is(':checked')){ |
| 344 |
lghide=' lghide="yes"'; |
| 345 |
} |
| 346 |
else{ |
| 347 |
lghide=''; |
| 348 |
} |
| 349 |
|
| 350 |
if(jQuery('#mdclear'+i).is(':checked')){ |
| 351 |
mdclear=' mdclear="yes"'; |
| 352 |
} |
| 353 |
else{ |
| 354 |
mdclear=''; |
| 355 |
} |
| 356 |
if(jQuery('#smclear'+i).is(':checked')){ |
| 357 |
smclear=' smclear="yes"'; |
| 358 |
} |
| 359 |
else{ |
| 360 |
smclear=''; |
| 361 |
} |
| 362 |
if(jQuery('#xsclear'+i).is(':checked')){ |
| 363 |
xsclear=' xsclear="yes"'; |
| 364 |
} |
| 365 |
else{ |
| 366 |
xsclear=''; |
| 367 |
} |
| 368 |
if(jQuery('#lgclear'+i).is(':checked')){ |
| 369 |
lgclear=' lgclear="yes"'; |
| 370 |
} |
| 371 |
else{ |
| 372 |
lgclear=''; |
| 373 |
} |
| 374 |
|
| 375 |
shortcode += '<br/>[column lg="'+a_lg[i]+'"'+md+sm+xs+mdoff+smoff+xsoff+lgoff+mdhide+smhide+xshide+lghide+mdclear+smclear+xsclear+lgclear+' ]<br/>text<br/>[/column]'; |
| 376 |
} |
| 377 |
|
| 378 |
shortcode += '<br/>[/row]'; |
| 379 |
// inserts the shortcode into the active editor |
| 380 |
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); |
| 381 |
// closes Thickbox |
| 382 |
jQuery.fancybox.close(); |
| 383 |
}); |
| 384 |
} |
| 385 |
|