jStorage icon indicating copy to clipboard operation
jStorage copied to clipboard

Line 43: "detect a dollar object or create one if not found" - in some cases causes malfunctioning.

Open marszalek opened this issue 11 years ago • 2 comments

Imagine situation where you have a large project and don't want to allow users to use a dollar sign i.e. from the console. You just want to hide it in some of your objects. jStorage will then fail, coz in this line (43) it is checking for existance of jQuery and if it's not, it creates it. I think you should assume that anyone who want to use it, is fully aware of its requirements.

In this big project which I am working on right now, we are very happy for jStorage, but need to comment out this line, coz jQuery initializing for the second time causes to recreate this object only in scope of jStorage, which is wrong.

Correct me if I misunderstand sth.

marszalek avatar Jan 20 '14 22:01 marszalek

This was causing issues for me too. The CMS I work with uses an older version of jQuery. I need to load in the newer version of jQuery to meet the requirements of jStorage and I need to avoid conflicts. For reference, the code I am using is:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

// <jStorage.js is imported here>

var jq180 = jQuery.noConflict(true);

(function($) {
  // $.jStorage.set(); and other code goes here
})(jq180);

When I comment out the line mentioned by @marszalek, everything works fine. Otherwise I get a $.jStorage undefined error.

I think this is the same problem referenced in the following issue: #90

jhume avatar Feb 01 '16 11:02 jhume

OR you could include two versions of jQuery on the page with no-conflict mode in another namespace. It's a great way to transition between versions over a few iterations.

doublejosh avatar Feb 05 '16 09:02 doublejosh