There is Yii solution for javacript clashing?

Often in one page, especially the main page we include these features:

  • News Slideshow

  • Expand / collaps content

  • Slider for gallery

  • Accordion

but often that these plugins can not be in one page, they affect each other and make other features not working.

Are Yii has a solution for this?

The reason why they would have that problem is because they all access the same information and since you only load it once, it turns into a problem where if one accesses information the other needs and alters it, you get conflict of interest.

Now Yii doesn’t have a solution for this per-say however the fix is to customize those features into OOP classes. This can be done through the Yii framework, it would take time and effort however.

What you’d have to do is extend an application class that utilizes the included jQuery in the framework but manipulate it so for each instance of an object ( a particular feature) it instantiates a new version of the object therefore making it so requests are private to that object (feature).

It was a common initial javascript problem when Ajax first came out, scripts would run but you couldn’t have conflicting scripts, thus kinda pointless. The work around was making multiple scripts or creating a class that would initiate a new script every time a new object was made requesting it.

The amount of work involved to do this, I’m not sure exactly, not a jQuery nor Ajax expert but you would have to work between PHP and javascript building your own custom class addition to the framework to do it, that much I do know.

As it stands I believe the functions already supported by the framework (like Treeview, autocomplete etc) can be used dynamically all on the same page without interference because they are class based (nature of the framework) but I’m not 100% sure on this. That may be a good start to look into, check the framework code and documentation classes holding the javascript information and then view the assets folder of a particular web app to see the included features.

Thanks you Whoopass… hmmm… still a lot of homework to do