[jQuery] How to define/access public functions for a plugin?

2010-01-04 Thread mehdi
Hi,
I've just developed a plugin that mimics the combo box control, albeit
it's a special one. That's being defined as follows:

(function($) {
$.fn.extend({
smartList: function(settings) {
//prepare settings, blah blah blah...

return this.each(function() {
//whatever code goes here...
});
}
});
})(jQuery);

You know, to use this plugin, I could easily write the following
JavaScript code:

var $myList = $('myElement').smartList();

No problem so far. Now, I need to define and access some functions
that's specific to the smartList. say, e.g., getSelectedValue,
insertItem, and the like. The problem is that I've got no idea how to
address such a thing in JavaScript. i.e., I need to write things like:

$myList.getSelectedValue();
$myList.insetItem('foo', 'bar');

But this isn't possible, since the $myList variable is a jQuery
object.

So I just defined some functions, say, $.smartList.getSelectedValue
and the like... but in this approach, I've to pass the jQuery object
to this functions as a mandatory parameter and this really sucks.
i.e., I need to get the selected value of $myList this way:

var value = $.smartList.getSelectedValue($myList);

Is there any better approach to address such a thing?

Any help would be highly appreciated,

TIA,
Mehdi


[jQuery] find and replace

2009-04-28 Thread kazim mehdi

hi
by using the following code  i am able to find only first occurrences
of the keywords can anyone help me to make it work for all of the
occurrences.

thank you

function test()
{
var keywords = ["got", "the"];
var el = $("body");
$(keywords).each(function()
{
el.html(el.html().replace(this, 
""+this+""));
});

}


[jQuery] Rewrite $('slide-images').getElementsByTagName('li'); with JQuery

2008-12-22 Thread Mehdi Saghari


 






 


how can i rewrite this function using JQuery ?!
function init() {
var lis = $('slide-images').getElementsByTagName('li');
for( i=0; i < lis.length; i++){
if(i!=0){
lis[i].style.display = 'none';
}
   }
   LastPic = lis.length -1;
}