0

i am using a php class that returns jquery library if the class calls multiple times on same page it should include that jquery library single time .

it works if class called single times it works fine but if i call it multiple times it shows js conflict due to multiple times added of jquery library.

how can i make it sigle time include only whenever the class called multiple times....

3
  • Can't the jQuery module help you? I'm sorry, but I never used it. Please, give it a try. If you still need to create your own, I can help you.
    – Sobral
    May 17 '14 at 12:05
  • thanks robson...well its a good idea. as of now i have found an another way to do this by passing parametrs (yes or no) from template. it would be yes for first time calling the class and if yes add library and must be no to another class callings. May 19 '14 at 4:07
  • I gonna post a better way to do that.
    – Sobral
    May 19 '14 at 11:43
0

You can use the session cache to know what your plugin already did while loading the page. Unlike the session class, which is new, the session cache is there by a long time. It's intended to avoid unnecessary repeated actions.

You can create a variable called, let's say, jqueryfied.

if ( ! ee()->session->cache('my_add-on_class', 'jqueryfied'))
{
   // add your code to include the jquery

   ee()->session->set_cache('my_addon_class', 'jqueryfied', true);
}

See? Now you add-on knows if it already included the jquery script on the page.

2
  • It's awesome ... such a brilliant way to do this ... Thank You so much.... it make my plugin much familiar to users ... thanx once again... May 20 '14 at 9:15
  • @user3440483, please, if my answer is right, mark it as right. There's a lot of already answered questions unmarked here and this make hard for us to find which still needs attention. Thank you!
    – Sobral
    May 20 '14 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.