Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FiC's $() func compatible with jQuery & Prototype deprecated
Message
De
02/08/2013 04:19:25
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
FoxInCloud
Titre:
FiC's $() func compatible with jQuery & Prototype deprecated
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Web
Divers
Thread ID:
01579722
Message ID:
01579722
Vues:
65
Hi All,

To help developers use jQuery code to implement surface events such as .mouseMove(), and/or add jQuery UI features to their FoxInCloud application, the recent FoxInCloud Application Server version (1.30) came bundled with jQuery.

FoxInCloud was built on Prototype.js since the early days of 'AJAX' (2005);
Prototype and jQuery both implement a $() function *, though differently, yielding different results.
* In many JavaScript libraries, $() is some kind of magic wand that brings many features in a single tiny place

jQuery.noConflict() allows using jQuery side-by-side sith another js library such as Prototype in the same application / html page.
When running jQuery.noConflict(), jQuery code can use either of these syntaxes:

- 'jQuery()' instead of $(), e.g.
jQuery.noConflict();
jQuery('my Selector').html(); // .html() is a sample jQuery method
// instead of 
$('my Selector').html();
- $() within a 'self executing function', e.g.
(function($){$('my Selector').html();})(jQuery); // function() executes automatically with $ 'replaced by' jQuery
http://api.jquery.com/jQuery.noConflict/ gives details about this implementation.

As most jQuery code samples available on the web use the $() syntax, and the JavaScript concept of 'self executing function' is not that easy to understand with a VFP background, we attempted to work around this dilemma by rewriting a $() function that would be compatible with Prototype (required by FoxInCloud.js code) and whatever jQuery code VFP dev. would like to add to his application.

Very enthusiastic by the idea of solving this issue and the kind of code we had in mind, we just forgot that no code should ever be written before knowing how to test it ... (aka TDD, test driven development).
We finally did this test HTML page recently and realized that one use case - $(DOM element) - could not be discriminated between Prototype and jQuery, making the whole code useless.

And we had to take the hard decision of dumping this code we were so proud of - another good lesson to never by-pass TDD!

If ever you've already added jQuery code to your application using plain $() (and I doubt so, it sould not run), please make sure to wrap this code in a self executing function as explained above, or bulk replace '$' by 'jQuery'.

Located at the very beginning of FoxInCloud.js, this code will be commented in next version (can't delete it for now ...;)
Thierry Nivelet
FoxinCloud
Give your VFP application a second life, web-based, in YOUR cloud
http://foxincloud.com/
Never explain, never complain (Queen Elizabeth II)
Répondre
Fil
Voir

Click here to load this message in the networking platform