SlideShare uma empresa Scribd logo
1 de 20
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); } } });

Mais conteúdo relacionado

Mais procurados

Адаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
Адаптация TInyMCE редактора под нужды клиента by Vitaly NikolaevАдаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
Адаптация TInyMCE редактора под нужды клиента by Vitaly NikolaevWordCamp Kyiv
 
jQuery Plugins Intro
jQuery Plugins IntrojQuery Plugins Intro
jQuery Plugins IntroCasey West
 
Javascript and jQuery for Mobile
Javascript and jQuery for MobileJavascript and jQuery for Mobile
Javascript and jQuery for MobileIvano Malavolta
 
Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0zfconfua
 
Silex. Микрофреймворк для микроприложений
Silex. Микрофреймворк для микроприложенийSilex. Микрофреймворк для микроприложений
Silex. Микрофреймворк для микроприложенийSoftline
 
Introdução a python módulo c
Introdução a python   módulo cIntrodução a python   módulo c
Introdução a python módulo cJader Gabriel
 
Як досвід компанії перетворився на фреймворк
Як досвід компанії перетворився на фреймворкЯк досвід компанії перетворився на фреймворк
Як досвід компанії перетворився на фреймворкShtrih Sruleg
 
Vue.jsのユニットテスト
Vue.jsのユニットテストVue.jsのユニットテスト
Vue.jsのユニットテストJoe_noh
 
Un juego creado en php
Un juego creado en phpUn juego creado en php
Un juego creado en phpErwin Lobo
 
Feeds. использование и создание плагинов. Feeds API
Feeds. использование и создание плагинов. Feeds APIFeeds. использование и создание плагинов. Feeds API
Feeds. использование и создание плагинов. Feeds APIAlex S
 
Elección de licencia addsensor018 manual_netlabel
Elección de licencia addsensor018 manual_netlabelElección de licencia addsensor018 manual_netlabel
Elección de licencia addsensor018 manual_netlabelireneund
 
Domótica. Test de conocimientos
Domótica. Test de conocimientosDomótica. Test de conocimientos
Domótica. Test de conocimientosJesús Amieiro
 
Pianist and composer Jeff Kowalkowski releases strong new trio album
Pianist and composer Jeff Kowalkowski releases strong new trio albumPianist and composer Jeff Kowalkowski releases strong new trio album
Pianist and composer Jeff Kowalkowski releases strong new trio albumirwinvifxcfesre
 

Mais procurados (20)

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

Destaque

Jquery plugin development
Jquery plugin developmentJquery plugin development
Jquery plugin developmentFaruk Hossen
 
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân PhượtBox Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân PhượtTí Bụng Bự
 
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMITí Bụng Bự
 
jQuery Plugin Creation
jQuery Plugin CreationjQuery Plugin Creation
jQuery Plugin Creationbenalman
 
Oop unit 05 một số kỹ thuật java nâng cao
Oop unit 05 một số kỹ thuật java nâng caoOop unit 05 một số kỹ thuật java nâng cao
Oop unit 05 một số kỹ thuật java nâng caoTráng Hà Viết
 
Artificial intelligence ai l1-gioi thieu
Artificial intelligence ai l1-gioi thieuArtificial intelligence ai l1-gioi thieu
Artificial intelligence ai l1-gioi thieuTráng Hà Viết
 

Destaque (6)

Jquery plugin development
Jquery plugin developmentJquery plugin development
Jquery plugin development
 
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân PhượtBox Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
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
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
 
jQuery Plugin Creation
jQuery Plugin CreationjQuery Plugin Creation
jQuery Plugin Creation
 
Oop unit 05 một số kỹ thuật java nâng cao
Oop unit 05 một số kỹ thuật java nâng caoOop unit 05 một số kỹ thuật java nâng cao
Oop unit 05 một số kỹ thuật java nâng cao
 
Artificial intelligence ai l1-gioi thieu
Artificial intelligence ai l1-gioi thieuArtificial intelligence ai l1-gioi thieu
Artificial intelligence ai l1-gioi thieu
 

Mais de Simone Gentili

test driven development with phpunit
test driven development with phpunittest driven development with phpunit
test driven development with phpunitSimone Gentili
 
Back end User Group / Golang Intro
Back end User Group / Golang IntroBack end User Group / Golang Intro
Back end User Group / Golang IntroSimone Gentili
 
DevRomagna / Golang Intro
DevRomagna / Golang IntroDevRomagna / Golang Intro
DevRomagna / Golang IntroSimone Gentili
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objectsSimone Gentili
 
Corso yii #04 - il database
Corso yii   #04 - il databaseCorso yii   #04 - il database
Corso yii #04 - il databaseSimone Gentili
 
Javascript Camp - Listener Per Eventi
Javascript Camp - Listener Per EventiJavascript Camp - Listener Per Eventi
Javascript Camp - Listener Per EventiSimone Gentili
 

Mais de Simone Gentili (9)

test driven development with phpunit
test driven development with phpunittest driven development with phpunit
test driven development with phpunit
 
Back end User Group / Golang Intro
Back end User Group / Golang IntroBack end User Group / Golang Intro
Back end User Group / Golang Intro
 
Laravel Day / Deploy
Laravel Day / DeployLaravel Day / Deploy
Laravel Day / Deploy
 
DevRomagna / Golang Intro
DevRomagna / Golang IntroDevRomagna / Golang Intro
DevRomagna / Golang Intro
 
Pubmi gitflow
Pubmi gitflowPubmi gitflow
Pubmi gitflow
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
 
Corso yii #04 - il database
Corso yii   #04 - il databaseCorso yii   #04 - il database
Corso yii #04 - il database
 
Yii workshop
Yii workshopYii workshop
Yii workshop
 
Javascript Camp - Listener Per Eventi
Javascript Camp - Listener Per EventiJavascript Camp - Listener Per Eventi
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); } } });