SlideShare a Scribd company logo
Simone (Demo) Gentili implement a jquery plugin [email_address]
/* this code goes in pluginName.js */ (function($){ $.fn. pluginName  = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); /* this code goes in the html document */ $(selector) . pluginName(); The base (what is this?)
(function($){ $.fn. pluginName  = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pluginName(); The base Here we can assign the name at our plugin In the plugin file
(function($){ $.fn. pluginName  = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pluginName(); The base And we can call it In the web page
(function($){ $.fn. pulseEffect  = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pulseEffect (); A concrete example: pulse effect?
What the plugin has to do? $(this) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300);
Refactoring (1/5) a=Array(0.2,1.0); $(this) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300);
Refactoring (2/5) a=Array(0.2,1.0); for(i=0;i<3;i++) $(this) .animate({'opacity':a[0]},300) .animate({'opacity':a[1]},300);
Refactoring (3/5) a=Array(0.2,1.0); for(i=0;i<3;i++) for(j=0;j<2;j++) $(this).animate({'opacity': a[j] },300);
Refactoring (4/5) a=Array(0.2,1.0); d=300; for(i=0;i<3;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d );
Refactoring (5/5) a=Array(0.2,1.0); d=300; t=3; for(i=0;i<t;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d );
Pameterize variables a=Array(0.2,1.0); d=300; t =3; for(i=0;i<t;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]},d);
With literal ... d = { 'start':0.2, 'end':1.0, 'times':3, 'delay':300 }; for(i=0,a=Array( d.start , d.end );i< d.times ;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d.delay );
send parameters from html page $(selector).pulseEffect({ 'start':0.2, 'end':1.0, 'times':3, 'delay':300 });
Our plugin (function($){ $.fn.mioPulse = function( options ) { this.each(function() { d = options; for(i=0,a=Array( d.start , d.end );i< d.times ;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d.delay ); }); }; })(jQuery); $(selector).pulseEffect({ 'start':0.2, 'end':1.0, 'times':3, 'delay':300 });
$(selector).pulseEffect(); We can use  pulseEffect () with no parameters. But we have to tell our plugin to set  all  parameters as a default values.
$(selector).pulseEffect(); /* d stands for default (value) */ d = { 'times':2, 'startOp':0.3, 'endOp':1.0, 'delay':300 }; /* o stands for options */ o = (options==undefined)?d:options;
$(selector).mioPulse({'times':4}); We can use  pulseEffect () with  one  parameters. But we have to tell our plugin to set  some  parameters as a default values.
$(selector).mioPulse({'times':4}); /* code for get default values */ if(o.times==undefined)o.times=d.times; if(o.startOp==undefined)o.startOp=d.startOp; if(o.endOp==undefined)o.endOp=d.endOp; if(o.delay==undefined)o.endOp=d.endOp; /* plugin ... */
Resuming ... d = { 'times':2, 'startOp':0.3, 'endOp':1.0, 'delay':300 }; o = (options==undefined)?d:options; if(o.times==undefined)o.times=d.times; if(o.startOp==undefined)o.startOp=d.startOp; if(o.endOp==undefined)o.endOp=d.endOp; if(o.delay==undefined)o.endOp=d.endOp; this.each(function() { for(i=0,a=Array(o.startOp,o.endOp);i<o.times;i++) { for(j=0;j<2;j++) { $(this).animate({ 'opacity':a[j] },o.delay); } } });

More Related Content

PPT
Palestra sobre MongoDB com PHP no PHP'n'Rio
PDF
Add tag shortcode
PDF
Twig, los mejores trucos y técnicas avanzadas
PDF
Drupal Cms Prezentace
PDF
Java Script - Object-Oriented Programming
PDF
Silex al límite
PPTX
JS programowanie obiektowe
PDF
Jquery2
Palestra sobre MongoDB com PHP no PHP'n'Rio
Add tag shortcode
Twig, los mejores trucos y técnicas avanzadas
Drupal Cms Prezentace
Java Script - Object-Oriented Programming
Silex al límite
JS programowanie obiektowe
Jquery2

What's hot (20)

PDF
Адаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
KEY
jQuery Plugins Intro
PDF
Underscore.js
PDF
Javascript and jQuery for Mobile
PPT
Юнит тестирование в Zend Framework 2.0
PDF
Sis quiz
PPTX
Silex. Микрофреймворк для микроприложений
PDF
Introdução a python módulo c
PDF
Web components v1 intro
PDF
Як досвід компанії перетворився на фреймворк
PDF
PHP Profiling
PDF
Vue.jsのユニットテスト
PDF
Menu orastat.c
DOCX
Un juego creado en php
PDF
Feeds. использование и создание плагинов. Feeds API
PDF
Elección de licencia addsensor018 manual_netlabel
PDF
Domótica. Test de conocimientos
PDF
PHPのすべらない話#3
PDF
Pianist and composer Jeff Kowalkowski releases strong new trio album
TXT
Index2
Адаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
jQuery Plugins Intro
Underscore.js
Javascript and jQuery for Mobile
Юнит тестирование в Zend Framework 2.0
Sis quiz
Silex. Микрофреймворк для микроприложений
Introdução a python módulo c
Web components v1 intro
Як досвід компанії перетворився на фреймворк
PHP Profiling
Vue.jsのユニットテスト
Menu orastat.c
Un juego creado en php
Feeds. использование и создание плагинов. Feeds API
Elección de licencia addsensor018 manual_netlabel
Domótica. Test de conocimientos
PHPのすべらない話#3
Pianist and composer Jeff Kowalkowski releases strong new trio album
Index2
Ad

Viewers also liked (6)

PPTX
Jquery plugin development
PPTX
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
PPT
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
KEY
jQuery Plugin Creation
PDF
Oop unit 05 một số kỹ thuật java nâng cao
PDF
Artificial intelligence ai l1-gioi thieu
Jquery plugin development
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
jQuery Plugin Creation
Oop unit 05 một số kỹ thuật java nâng cao
Artificial intelligence ai l1-gioi thieu
Ad

More from Simone Gentili (9)

PPTX
test driven development with phpunit
PPTX
Back end User Group / Golang Intro
PPTX
Laravel Day / Deploy
PPT
DevRomagna / Golang Intro
PDF
Pubmi gitflow
ODP
#pugMi - DDD - Value objects
PPT
Corso yii #04 - il database
PPT
Yii workshop
PPT
Javascript Camp - Listener Per Eventi
test driven development with phpunit
Back end User Group / Golang Intro
Laravel Day / Deploy
DevRomagna / Golang Intro
Pubmi gitflow
#pugMi - DDD - Value objects
Corso yii #04 - il database
Yii workshop
Javascript Camp - Listener Per Eventi

Jquery Plugin

  • 1. Simone (Demo) Gentili implement a jquery plugin [email_address]
  • 2. /* this code goes in pluginName.js */ (function($){ $.fn. pluginName = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); /* this code goes in the html document */ $(selector) . pluginName(); The base (what is this?)
  • 3. (function($){ $.fn. pluginName = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pluginName(); The base Here we can assign the name at our plugin In the plugin file
  • 4. (function($){ $.fn. pluginName = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pluginName(); The base And we can call it In the web page
  • 5. (function($){ $.fn. pulseEffect = function(options) { this.each(function() { /* do code here*/ } }; })(jQuery); $(selector) . pulseEffect (); A concrete example: pulse effect?
  • 6. What the plugin has to do? $(this) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300) .animate({'opacity':'0.2'},300) .animate({'opacity':'1.0'},300);
  • 7. Refactoring (1/5) a=Array(0.2,1.0); $(this) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300) .animate({'opacity': a[0] },300) .animate({'opacity': a[1] },300);
  • 8. Refactoring (2/5) a=Array(0.2,1.0); for(i=0;i<3;i++) $(this) .animate({'opacity':a[0]},300) .animate({'opacity':a[1]},300);
  • 9. Refactoring (3/5) a=Array(0.2,1.0); for(i=0;i<3;i++) for(j=0;j<2;j++) $(this).animate({'opacity': a[j] },300);
  • 10. Refactoring (4/5) a=Array(0.2,1.0); d=300; for(i=0;i<3;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d );
  • 11. Refactoring (5/5) a=Array(0.2,1.0); d=300; t=3; for(i=0;i<t;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d );
  • 12. Pameterize variables a=Array(0.2,1.0); d=300; t =3; for(i=0;i<t;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]},d);
  • 13. With literal ... d = { 'start':0.2, 'end':1.0, 'times':3, 'delay':300 }; for(i=0,a=Array( d.start , d.end );i< d.times ;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d.delay );
  • 14. send parameters from html page $(selector).pulseEffect({ 'start':0.2, 'end':1.0, 'times':3, 'delay':300 });
  • 15. Our plugin (function($){ $.fn.mioPulse = function( options ) { this.each(function() { d = options; for(i=0,a=Array( d.start , d.end );i< d.times ;i++) for(j=0;j<2;j++) $(this).animate({'opacity':a[j]}, d.delay ); }); }; })(jQuery); $(selector).pulseEffect({ 'start':0.2, 'end':1.0, 'times':3, 'delay':300 });
  • 16. $(selector).pulseEffect(); We can use pulseEffect () with no parameters. But we have to tell our plugin to set all parameters as a default values.
  • 17. $(selector).pulseEffect(); /* d stands for default (value) */ d = { 'times':2, 'startOp':0.3, 'endOp':1.0, 'delay':300 }; /* o stands for options */ o = (options==undefined)?d:options;
  • 18. $(selector).mioPulse({'times':4}); We can use pulseEffect () with one parameters. But we have to tell our plugin to set some parameters as a default values.
  • 19. $(selector).mioPulse({'times':4}); /* code for get default values */ if(o.times==undefined)o.times=d.times; if(o.startOp==undefined)o.startOp=d.startOp; if(o.endOp==undefined)o.endOp=d.endOp; if(o.delay==undefined)o.endOp=d.endOp; /* plugin ... */
  • 20. Resuming ... d = { 'times':2, 'startOp':0.3, 'endOp':1.0, 'delay':300 }; o = (options==undefined)?d:options; if(o.times==undefined)o.times=d.times; if(o.startOp==undefined)o.startOp=d.startOp; if(o.endOp==undefined)o.endOp=d.endOp; if(o.delay==undefined)o.endOp=d.endOp; this.each(function() { for(i=0,a=Array(o.startOp,o.endOp);i<o.times;i++) { for(j=0;j<2;j++) { $(this).animate({ 'opacity':a[j] },o.delay); } } });