Alternatives to Protosafe?

6 views
Skip to first unread message

Diodeus

unread,
Jul 9, 2009, 3:10:45 PM7/9/09
to Prototype & script.aculo.us
I am working on a content delivery solution. This would allow people
to include some content on their page by adding a script tag. I would
like to add some slickness to the content, so I would like to use
Prototype.

I'm looking for some suggestions to safely add Prototype to the target
pages (I'm inserting a script tag dynamically) without interfering
with an existing copy of Prototype, jQuery or other libraries.

Alex McAuley

unread,
Jul 9, 2009, 4:48:20 PM7/9/09
to prototype-s...@googlegroups.com
You could check for the jQuery object - this will get round jQuery...

if(jQuery) {
..........................

}
There must be prototype only objects/functions/classes you can test for in
prototype....

I am not sure about other libraries but i think extjs uses the "Ext."
namespace and similar with yahoo

Diodeus

unread,
Jul 9, 2009, 4:52:03 PM7/9/09
to Prototype & script.aculo.us
I'd rather not test for conflicts, but rather to safely coexist.

On Jul 9, 4:48 pm, "Alex McAuley" <webmas...@thecarmarketplace.com>
wrote:

waldro...@gmail.com

unread,
Jul 9, 2009, 4:58:26 PM7/9/09
to prototype-s...@googlegroups.com
Alex, he can just check for Prototype :)

if ( Prototype ) {
.....

Alex McAuley

unread,
Jul 9, 2009, 5:00:10 PM7/9/09
to prototype-s...@googlegroups.com
Doh!... didnt think of that

Alex McAuley

unread,
Jul 9, 2009, 5:00:45 PM7/9/09
to prototype-s...@googlegroups.com
well anything that uses "$" will not safley co-exist so you -need- to test
for conflicts in order to co-exist properly
----- Original Message -----
From: "Diodeus" <dio...@gmail.com>
To: "Prototype & script.aculo.us" <prototype-s...@googlegroups.com>
Sent: Thursday, July 09, 2009 9:52 PM
Subject: [Proto-Scripty] Re: Alternatives to Protosafe?



Matt Foster

unread,
Jul 9, 2009, 5:29:16 PM7/9/09
to Prototype & script.aculo.us
Pretty sure you can run

jQuery.noConflict()

and then make sure anything dependant on jQuery's version of $ will
now have to use the more verbose reference of "jQuery"

There still may be issues, but Prototype was designed to be powerful,
not play nice.


--

http://positionabsolute.net


On Jul 9, 5:00 pm, "Alex McAuley" <webmas...@thecarmarketplace.com>
wrote:

Josh Powell

unread,
Jul 10, 2009, 2:41:43 PM7/10/09
to Prototype & script.aculo.us
You cannot safely add Prototype to the target pages. Prototype
changes javascript in general, not just jQuery. It adds methods to
native objects. If the target pages are already running jQuery in
noConflict() mode then you won't interfere, but if you put their pages
in noConflict() mode then you will mess up their javascript that
relies on it. There could also be custom code that relies on for
(each in obj) that will break if you add prototype, and there is no
way to check for that.

You will also be breaking pages that use mootools, which does not have
a noConflict() mode.

Prototype does not have a noConflict() mode because the theory behind
it prevents that from happening, once native objects are extended
there is no way to unextend them. You are going to have to use jQuery
or Dojo for this project if you want to add a library to their pages.
Probably jQuery as it only adds the jQuery variable to the global
namespace, and even then you should use noConflict() mode and return
the $ to its previous state before exiting your code, so in case they
are using jQuery you give them back use of $ before you are done.

If you want to do the least potential damage by adding Prototype to
others pages, then check to make sure it doesn't already exist, and
then check to make sure $ doesn't already exist, and if it does
disable any special effects or give a warning saying that this feature
cannot be used because it will interfere with the existing code.

Good luck!

Matt Foster

unread,
Jul 10, 2009, 4:04:23 PM7/10/09
to Prototype & script.aculo.us
Besides the $ function and using for(var in ) for iteration over an
array. I can't think of other conflicts prototype would cause with
existing code.

--

http://positionabsolute.net

Josh Powell

unread,
Jul 10, 2009, 4:28:18 PM7/10/09
to Prototype & script.aculo.us
If other libraries or js code extend the native objects with the same
methods, the one included last wins. In this case, it will almost
always be prototype because he is loading it dynamically.
Reply all
Reply to author
Forward
0 new messages