jQuery Kit - switch completely to jQuery script collection

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

jQuery Kit - switch completely to jQuery script collection

Post by marcus@localhorst »

UPDATE: With Version 1.4.4 r381 you can use phpwcms with any JS Lib you wish! So you don't need this anymore. See Announcement

I am more familar with jQuery and since mootools is hardcoded in phpwcms I need an easy switch without including jQuery in Template Header and without using the noConflict() mode.
If Oliver provides an optional use of other JS Libraries in future, these scripts are obsolete!
phpwcms jquery kit.zip
(8.1 KiB) Downloaded 275 times
Some explaination:
The corescript is /template/inc_script/frontend_render/jQueryKit.php
1. initialize the Lightbox (and this load mootools or later jQuery - so both scripts are always present in your site! If you don't want that keep away from this script ;-) But in case you want to use other Scripting on your site it's ok to load the full library)
2. then the variable which holds the mootools lib will be overwritten with jQuery lib (you can load it from your own server for sure! here I use the google service)
3. then overwrite the slimbox variable with the jquery Version of Light/Slimbox - no need to change anything else it's will work with the css.
Just Olivers localization in his mootools slimbox.js is gone. (no [SCHLIESSEN x] Button anymore
4. it loads a custom.js which holds some other jQuery calls for slideshows or such stuff you may not need it
5. include the frontend_edit.js to keep the frontend edit buttons/function.

Code: Select all

<?php
initializeLightbox(); // this call initMootools() and lightbox JS globally 

// now replace the mootools lib with jQuery any following mootools script will broke!
$block['custom_htmlhead']['mootools.js'] = getJavaScriptSourceLink('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');
// replace the lightbox script with jQuery version
$block['custom_htmlhead']['slimbox.js']  = getJavaScriptSourceLink('template/slimbox/js/jQslimbox.js');
// load one custom JS with all libaries and scripts
$block['custom_htmlhead']['custom.js']   = getJavaScriptSourceLink('template/inc_js/custom.js');

// load the new jQuery frontend edit
if(FE_EDIT_LINK) {
	$block['custom_htmlhead']['frontend_edit.js'] = getJavaScriptSourceLink('template/inc_js/frontend_edit.js');
}
?>

I've included all necessary scripts and some more.
The replacement for slimbox without overwrite your orginal mootools slimbox
The Frontend Edit functionality and a custom.js with some helper functions and a simple slideshow function with a simple template for CP Images Special.
It should work out of the box.
It handle the hardcoded Frontend Edit mootools JS - so you don't need to edit the index.php
For explaination see templates/inc_js/frontend_edit.js (it just fakes the addEvent() function :P
If you have accidently any other mootools scripts loaded (at example the inline JS from slider.tpl) then nothing happens!
no warning/errors - you can turn it on in development process - see the commented addEvent() functions in custom.js

I need to say I don't want to publish this as a bulletproof solution - it's just to illustrate how easy it is to extend phpwcms for your own needs.
Feel free to use it or not. For me it's an easy way to work with jQuery (or any other Lib) without messing around with noConflict() Mode of jQuery with mootools or additional markup in phpwcms templates to include the script...
cheers m.
Last edited by marcus@localhorst on Sun 29. Nov 2009, 10:03, edited 2 times in total.
User avatar
Oliver Georgi
Site Admin
Posts: 9892
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: jQuery Kit - switch completely to jQuery script collection

Post by Oliver Georgi »

I have something in preparation where you can switch your preferred JavaScript Library. It is prepared for jQuery 1.3, MooTools 1.1 and MooTools 1.2 (always current releases). It is template based and has support for Slimbox too and some more like easy Plugin loading.
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Re: jQuery Kit - switch completely to jQuery script collection

Post by marcus@localhorst »

looks really good! thanks!
Post Reply