WebsiteBaker Support (2.8.x) > Templates, Menus & Design

need a little assistance with coding

(1/2) > >>

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[&#39;PHP_SELF&#39;]),"",__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 = &#39;$(document).ready(function(){ &#39;."\n"; 

$dragscript .= &#39;    $(function() { &#39;."\n";
$dragscript .= &#39;        $("#dragableTable ul").sortable({ opacity: 0.6, cursor: \&#39;move\&#39;, update: function() { &#39;."\n";
$dragscript .= &#39;            var order = $(this).sortable("serialize") + \&#39;&action=updateRecordsListings\&#39;; &#39;."\n";
$dragscript .= &#39;            $.post("&#39;.WB_URL.&#39;/updateDB.php", order, function(theResponse){ &#39;."\n";
$dragscript .= &#39;                $("#dragableResult").html(theResponse); &#39;."\n";
$dragscript .= &#39;            }); &#39;."\n";
$dragscript .= &#39;        } &#39;."\n";
$dragscript .= &#39;        }); &#39;."\n";
$dragscript .= &#39;    }); &#39;."\n";
$dragscript .= &#39; }); &#39;."\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.&#39;/backend_body.js&#39;;
$fh = fopen($myFile, &#39;w&#39;) or die("can&#39;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