Need help making extension dynamic

17 views
Skip to first unread message

jonPrecise

unread,
Jan 5, 2010, 9:20:34 PM1/5/10
to jQTouch

Hi guys, I hope someone can help me out with this..
I'm using Sam Shull's ( brickysam26 ) scrolling extension which is a
very nice mod of Matteo Spinelli's iScroll script to allow pseudo
fixed positioning.
I've got it working perfectly but the problem is that it only links to
the specified class for elements in the current DOM when the jQtouch
object is first initiated .. any pages brought in by AJAX are not
included..
This has led me to initiate an additional jQtouch object on every AJAX
call .. of course this is causing huge memory usage the longer you're
in the site ( every time the object is initiated it adds another
object to the memory ) .

I think this may be resolved by using the *live* method but my
inexperience with jQuery is getting me nowhere..

below is a condensed version of Sam Shull's extension adding iScroll
to a jqt class ,
any suggestions would be appreciated.

(function($)
{
$.fn.scrollVertically = function (options)
{
return this.each(function ()
{
new iScroll( this, options );
});
};
if ($.jQTouch)
{

$.jQTouch.addExtension(function (jQTouch){
function binder (info)
{
vertical = info.page.find('.vertical-scroll > div');
vertical.scrollVertically({acceleration: Number(vertical.attr
("scrollspeed") || 0.009)});
}
$(document.body)
.bind('pageInserted', binder);
$(function()
{
$('body > *')
.each(function()
{
binder({page: $(this)});
});
});
});

world_eggplant

unread,
Jan 6, 2010, 5:44:15 PM1/6/10
to jQTouch
The jQuery live method only allows certain events, but not new custom
(without modifying/prototyping the live method, that is. Probably).

Using $('body > *).each most of the time is a horrible thing to do. It
can be a huge, huge resource- and memory hog and should be avoided to
all time.

And why exactly do you want to make a jQTouch plugin out of something
that already is a jQuery plugin? This seems a tat pointless in my
mind, it should either be a jQuery plugin, or a jQTouch plugin. Most
likely a jQTouch plugin in this case, because of the pageInserted
trigger (only exists in jQTouch?)

Here's a short example of how you can make things a tat simpler:

function binder ( scope ) {
var $vertical = $('.vertical-scroll > div', scope.page); // using a
second parameter to jQuery is scope, that it only searches within that
node (similar to $(obj).find('.whatever');
$vertical.scrollVertically({accelleration: Number($vertical.attr
('scrollspeed') || 0.009}); // assumes scrollVertically method is a
jQuery plugin, will most likely need to be changed if jQTouch.
}
$(function(){
binder ( {page:$document} ); // initialize it for the document
$(document).bind('pageInserted', binder); // call on insert,
pageInserted privides with node.page (=object inserted) I take it?
});

This will probably not work straight out of the box, but it sort of
demonstrates my point.

Good luck, sorry if I confused you more,

Jonas

Sam

unread,
Feb 2, 2010, 11:55:37 PM2/2/10
to jQTouch
@jonPrecise,
Sorry about that, it appears that I was using an older version of
jQTouch that didn't fire the pageInserted event, I tried upgrading to
the latest trunk revision, but there appears to be a large number of
changes that are not compatible with the example, and since I didn't
want to rewrite the example, I just added the pageInserted event to
the older revision of jQTouch I was already using.

Anyway, you can get the new example here (http://
jqextensions.googlecode.com/files/example.zip) and I added an ajax
loaded example, and an example with a sticky footer, just for fun. :)

Reply all
Reply to author
Forward
0 new messages