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

eZ debug

Timing: Jan 18 2025 15:13:26
Script start
Timing: Jan 18 2025 15:13:26
Module start 'content'
Timing: Jan 18 2025 15:13:27
Module end 'content'
Timing: Jan 18 2025 15:13:27
Script end

Main resources:

Total runtime1.3682 sec
Peak memory usage4,096.0000 KB
Database Queries200

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 588.8516180.8359
Module start 'content' 0.00551.2376 769.6875585.6563
Module end 'content' 1.24320.1250 1,355.3438341.3672
Script end 1.3681  1,696.7109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.2791210.0002
Check MTime0.00150.1080210.0001
Mysql Total
Database connection0.00050.040010.0005
Mysqli_queries1.288994.20262000.0064
Looping result0.00200.14691980.0000
Template Total1.338697.820.6693
Template load0.00200.146120.0010
Template processing1.336697.692720.6683
Template load and register function0.00010.006710.0001
states
state_id_array0.00080.059810.0008
state_identifier_array0.00150.113320.0008
Override
Cache load0.00180.1280420.0000
Sytem overhead
Fetch class attribute can translate value0.00130.098430.0004
Fetch class attribute name0.00160.114770.0002
XML
Image XML parsing0.00100.075130.0003
class_abstraction
Instantiating content class attribute0.00000.0020100.0000
General
dbfile0.00200.1439340.0001
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs