Results 1 to 4 of 4
-
9th Jun 2010, 10:18 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comCreating a jQuery plugin
Thought i would share my knowledge of jQuery plugins !
Ok so lets get started!
Information:
jQuery plugins are functions that are stored within jQuery and calledwhen the function is used on an element, jQuery also passes in the DOM element into the function so you can directly work with that element!
Plugin Structure:
The structure that i like to uses is like so..
PHP Code:(function(){
$.fn.#PLUGIN_NAME# = function(){
}
})($)
basics
PHP Code:(function(){
$.fn.changeVal = function(newVal){
$(this).val(newVal);
}
})($)
- The plugin is called changeVal
- Were getting 1 parameter newVal
- Were using the keyword this to select the element
- then were using regular jQuery functions to change the val
and this would be used like so
PHP Code:$('a.changeMe').changeVal('New Value here');
PHP Code:(function(){
$.fn.externalLinks = function(){
$(this).each(function(){ //As were dealing with multiple itesm we loop this
//here this is now the single a element.
if($(this).attr('href').match(/http\:\ /\ //gi))
{
//The link has http:// within it! so we add some external attrubutes.
$(this).attr('target','_blank').addClass('external_link');
}
});
}
})($)
the usage of this is really simple
PHP Code:$('a').externalLinks();
This will give you a little more idea of what you can do with plugins!
PHP Code:(function($){
$.fn.lwcookie = function(name, value, options){
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document .cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document . cookie && document .cookie* != '') {
var cookies = document .cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')){
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
})($ || jQuery)
Hope this helps you - Say thankslitewarez Reviewed by litewarez on . Creating a jQuery plugin Thought i would share my knowledge of jQuery plugins ! Ok so lets get started! Information: jQuery plugins are functions that are stored within jQuery and calledwhen the function is used on an element, jQuery also passes in the DOM element into the function so you can directly work with that element! Plugin Structure: The structure that i like to uses is like so.. Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
9th Jun 2010, 10:22 PM #2Member
Seems alittle advanced for the new people this might be useful to them
http://www.ilovecolors.com.ar/create-jquery-plugin/Signature too big, removed by staff.
-
9th Jun 2010, 10:24 PM #3OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comAdvanced :/ its basics :/ cant get any basic'er
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
10th Jun 2010, 12:05 AM #4Member
:\ ok :\ well i was just sayin :\
Signature too big, removed by staff.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
JQuery and RegExr Help :|
By Porsche_maniak in forum Web Development AreaReplies: 4Last Post: 1st Jun 2012, 12:26 AM -
JQuery help
By xElliex in forum Web Development AreaReplies: 5Last Post: 25th Aug 2011, 10:38 PM -
Anyone who knows Javascript / jquery / Css
By Czechi in forum Completed TransactionsReplies: 5Last Post: 17th Aug 2010, 06:41 AM -
jQuery tooltip help
By devilzkrazy in forum Technical Help Desk SupportReplies: 0Last Post: 22nd May 2010, 04:24 PM -
Introduction to jQuery
By litewarez in forum Tutorials and GuidesReplies: 4Last Post: 14th Jan 2010, 02:51 AM
themaPoster - post to forums and...
Version 5.18 released. Open older version (or...