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