WebsiteBaker Support (2.8.x) > Templates, Menus & Design
need a little assistance with coding
crnogorac081:
Hi,
I am trying to insert dynamic JS into backend's footer
the code is in modify.php file and I used this from droplets, but it is not working..
--- Code: ---
$wb_page_data = str_replace('</body>',$dragscript."\n".'</body>', $wb_page_data );
--- End code ---
Or this is working only with droplets ?
Could you please tell me how to make this work ?
WebBird:
Just put your JS into backend_body.js. WB will load it automagically. (Needs WB 2.8 )
crnogorac081:
I know, but that doesnt solve the issue as I need to call a file:
--- Code: --- <script type="text/javascript">
$(document).ready(function(){
$(function() {
$("#dragableTable ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("'.WB_URL.'/updateDB.php", order, function(theResponse){
$("#dragableResult").html(theResponse);
});
}
});
});
});
</script>
--- End code ---
So I need to have WB_URL variable inside..
I also trried to use a droplet, but it doesnt work in backend..
WebBird:
I have an easy solution for this case. :-D
Create a backend.js, add:
--- Code: ---function setVar( varname, text )
{
eval(varname+"=\""+text+"\"");
}
--- End code ---
In your modify.php, add somewhere to the HTML:
--- Code: --- <script type="text/javascript">setVar( 'WB_URL', '<?php echo WB_URL; ?>' );</script>
--- End code ---
In your backend_body.js, use:
--- Code: ---var WB_URL;
...
$.post( WB_URL+'/update...');
--- End code ---
crnogorac081:
Thank mate, but I just found and tested a solution:
--- Code: ---<?php
// This makes path to current folder
$filepath=str_replace(basename($_SERVER['PHP_SELF']),"",__FILE__);
// if you are not sure where you are, you can uncomment this and see..
//echo $filepath;
// Now we write the code, just like in Droplets
$dragscript = '$(document).ready(function(){ '."\n";
$dragscript .= ' $(function() { '."\n";
$dragscript .= ' $("#dragableTable ul").sortable({ opacity: 0.6, cursor: \'move\', update: function() { '."\n";
$dragscript .= ' var order = $(this).sortable("serialize") + \'&action=updateRecordsListings\'; '."\n";
$dragscript .= ' $.post("'.WB_URL.'/updateDB.php", order, function(theResponse){ '."\n";
$dragscript .= ' $("#dragableResult").html(theResponse); '."\n";
$dragscript .= ' }); '."\n";
$dragscript .= ' } '."\n";
$dragscript .= ' }); '."\n";
$dragscript .= ' }); '."\n";
$dragscript .= ' }); '."\n";
// Now we set the filename in my case: backend_body.js (I needed this code to be written in JS, so I can getl WB_URL from config.php file )
$myFile = $filepath.'/backend_body.js';
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $dragscript);
fclose($fh);
?>
--- End code ---
This is the tutorial how to have PHP code inside Java script (description for search)
Now just another question, will this fwrite work on every server ?
I keep learning php every day..
All best,
Ivan
Navigation
[0] Message Index
[#] Next page
Go to full version