Forums / Developer / Javascript.. full file path [SOLVED]

Javascript.. full file path [SOLVED]

Author Message

Lo' F.

Wednesday 27 October 2010 2:22:07 pm

Hello again!

And again it has to do with getting images' full path but.. within a .js file and the magic of ezimage is powerless here!

The included .js code uses some images located, let's say, here "/extension/ezext/design/ezext/images/" and for this gave the exact full path.

But there is one problem: Moved the extension package to a new eZ installation, installed inside a folder under the root directory and the new absolute path looks so like "/subfolder/extension/ezext/design/ezext/images/"..

Doubting there might be a javascript way to get a full file path but if you can think of something, please, I am all ears!

Thank you guys!

loredanaebook.it

André R.

Wednesday 27 October 2010 2:44:16 pm

As all other dynamic parameters you pass them as options (object) from template to the javascript function that needs it.

tpl:
myMacigStuff.init({ldelim} 'imagePath' : {'my_image.png'|ezimage} {rdelim});

js:

myMacigStuff = {
    init: function( params ){
    $('img.swap').click(function(){
      myMacigStuff.changeImagePath( this, params['imagePath'] );
    });
  },
  changeImagePath: function( img, path ){
    img.src = path;
  }
};

This is an (untested) example on how to pass dynamic params to a static script, it is pretty much the same in most stuff (languages / cms's / frameworks) out there, and comes down to the fact that server side and client side code is executed on different machines so you need to provide the logic between them.

Hope it helps :)

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Lo' F.

Wednesday 27 October 2010 3:10:15 pm

Andre' thank you so much for your prompt reply! ..I'll test it (..tomorrow) and I'll let you know!

loredanaebook.it

Lo' F.

Sunday 14 November 2010 8:47:29 am

For days have been busy dealing with some other stuff and couldn't give much time to this.

Still undone but yet to be given a solution, I have been trying out something like this:

-in the page_head_script.tpl, between the lines including the jquery.js and the scroller.js files, I created the following script where I passed the images full path to some global variables..

{literal}
<script type="text/javascript" language="javascript">
$(document).ready(function() {    
    down="{/literal}{'down.png'|ezimage('single')}{literal}";
    bg_bottom_hightlight='\'url({/literal}{'bg-bottom-hightlight.png'|ezimage('double')}{literal}) repeat-x scroll top #C8CAD3\'';
    loading="{/literal}{'loading.gif'|ezimage('single')}{literal}";
});
</script>
{/literal}

- and in the external .js file, just recalled those variables..

var scroller_constants={
    navpanel: {height:'35px', downarrow:down, background:bg_bottom_highlight}, loadingimg: {src:loading, dimensions:[100,15]}
}

in theory those files' path should have been passed, right?

.. but it doesn't seem to work..

loredanaebook.it

Lo' F.

Sunday 14 November 2010 9:54:28 am

..done! easier than I thoght!

{literal}
<script type="text/javascript" language="javascript">
    down="{/literal}{'down.png'|ezimage('no')}{literal}";
    bg_bottom_hightlight='url({/literal}{'bg-bottom-highlight.png'|ezimage('double')}{literal}) repeat-x scroll top #C8CAD3';
    loading="{/literal}{'loading.gif'|ezimage('no')}{literal}";
</script>
{/literal}

It works like a charm!

Special thanks to Andre' who gave me the right jump start!

loredanaebook.it