Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Any suggested methods for executing inline javascript blocks in multiple view partials?
  • I am using Themes and partials to render my pages.  Starting to include some more javascript during page executions and running into some timing/loading issues.

    I am running both jQuery and YUI, all core files are included at bottom of my base theme template.

    Problem arises when executing any inline js in views that requires use of jquery/yui.  For a single view you can wrap it inside of a window.onload callback.  That however will be problematic with 2 or many view partials with js executing.

    Typically in the past I have added a "js_exe" template block below my includes in the main template.  Then added a call/functionality to my controllers to that will capture all needed javascript to execute inline, then spit it out into the bottom of the page on request render.

    Anyone implemented any behavior for more complex js execution in their fuel setups?
  • It would be a handy addition if you could pass a string instead of a file name to the asset class, and have it render inline.

    Perhaps create a feature request for it at http://github.com/fuel/core/issues ?
  • Will have a look at that first, get a working implementation going.  If works out will submit either pull and/or feature request.
  • I used to develop some fully RESTful site. The site landing page is just a plain HTML file! PHP only serve AJAX request.

    My opinion, better load the JS Framework/Library at the top (normally in the head tag) and host the file on a fast response server. It help to prevent many inline JS issues. If the JS file is big, use the minified version.

    Try develop inline JS that will execute only when user perform some action e.g. onclick, etc. But there still have chances that user click on the item during the page loading.

    My principle, put most of the JS code in an external JS file. ( I used to write JS code in OO style. If you interested in JavaScript OOP, google it... :-) )
  • Unfortunately these blocks of JS are specific to some field handling for some forms, so really dependent on the inline content being rendered from the fieldset/views

    I always stay away from loading JS at the top of the page.., usually follow best practices around CSS at the top since its needed first for presentation, JS at the bottom, and most/all inline js execution only when needed

    I completed a first version of the js_exe block handler going.  Will try to clean it up some over the weekend and get a pull request going.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion