I'm working with Wordpress and my objective is to create a kind of main.js
file to call instead of including in page my script. Being a plugin, I need to use some php variables and functions into it.
Can I just write my .js like
<?php
$dd = get_option('KleeiaDev_project_period');
if(empty($dd)) $dd = 7; ?>
var myDate=new Date();
myDate.setDate(myDate.getDate()+<?php echo $dd; ?>);
$(document).ready(function() {
$('#ending').datepicker({
showSecond: false,
timeFormat: 'hh:mm:ss',
currentText: '<?php _e('Now','KleeiaDev'); ?>',
closeText: '<?php _e('Done','KleeiaDev'); ?>',
ampm: false,
dateFormat: 'dd-mm-yy',
timeFormat: 'hh:mm tt',
timeSuffix: '',
maxDateTime: myDate,
timeOnlyTitle: '<?php _e('Choose Time','KleeiaDev'); ?>',
timeText: '<?php _e('Time','KleeiaDev'); ?>',
hourText: '<?php _e('Hour','KleeiaDev'); ?>',
minuteText: '<?php _e('Minute','KleeiaDev'); ?>',
secondText: '<?php _e('Second','KleeiaDev'); ?>',
timezoneText: '<?php _e('Time Zone','KleeiaDev'); ?>'
});
});
Or should I consider something? I mean is that possible? For now this piece of code and more is directly in my php plugin file. Thanks.