Top Banner
$.fn.myPlugi Vytvárame jQuery PLUGIN vlastný
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: jQuery PLUGIN

$.fn.myPlugin();

VytváramejQuery

PLUGIN

vlastný

Page 2: jQuery PLUGIN

Najskôr úvod

Page 3: jQuery PLUGIN

var x = {};

Page 4: jQuery PLUGIN

var x = {};

Object Definition

Page 5: jQuery PLUGIN

var x = { doMath: function(){…}

};

Page 6: jQuery PLUGIN

var x = { doMath: function(){…}

};

Object Method

Page 7: jQuery PLUGIN

…on(‘click’, function(){…})

Page 8: jQuery PLUGIN

Anonymous Function

…on(‘click’, function(){…})

“…a function without name”

Page 9: jQuery PLUGIN

(doMath)();

Page 10: jQuery PLUGIN

(doMath)();

Function Closure

Page 11: jQuery PLUGIN

Add some magic

Page 12: jQuery PLUGIN

(function(x){…})(abc);

Function Closurewith Anonymous Function

Page 13: jQuery PLUGIN

“Tak ako urobím ten plugin?”Comic Sans

Page 14: jQuery PLUGIN

Takto!Plugin sa bude volať

yolo

Page 15: jQuery PLUGIN

Úplný základ je…

Page 16: jQuery PLUGIN

jQuery.fn.yolo = function () { // Your code };

Page 17: jQuery PLUGIN

jQuery.fn.yolo = function () { // Your code return this; };

Page 18: jQuery PLUGIN

jQuery.fn.yolo = function () { // Your code return this; };

Page 19: jQuery PLUGIN

jQuery.fn.yolo = function () { return $(this).each(function () { // Your code });};

Page 20: jQuery PLUGIN

jQuery.fn.yolo = function () { return $(this).each(function () { // Your code }); };

Page 21: jQuery PLUGIN

(function ($) { $.fn.yolo = function () { return $(this).each(function () { // Your code }); }; })(jQuery);

Page 22: jQuery PLUGIN

(function ($) { $.fn.yolo = function () { return $(this).each(function () { // Your code }); }; })(jQuery);

Page 23: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options) { return $(this).each(function () { // Your code }); }; })(jQuery);

Page 24: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options) { return $(this).each(function () { // Your code }); }; })(jQuery);

Page 25: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options) { var settings = $.extend({}, options); return $(this).each(function () { // Your code }); }; })(jQuery);

Page 26: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options) { var settings = $.extend({}, options); return $(this).each(function () { // Your code }); }; })(jQuery);

Page 27: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options, callback) { var settings = $.extend({}, options); return $(this).each(function () { // Your code (callback)(); }); }; })(jQuery);

Page 28: jQuery PLUGIN

(function ($) { $.fn.yolo = function (options, callback) { var settings = $.extend({}, options); return $(this).each(function () { // Your code (callback)(); }); }; })(jQuery);

Page 29: jQuery PLUGIN

That’s simple start folks!

Page 30: jQuery PLUGIN

Zdroje ďalších informácií• https://developer.mozilla.org/en-US/docs/Web/JavaScript/

Introduction_to_Object-Oriented_JavaScript

• http://learn.jquery.com/plugins/

• http://learn.jquery.com/performance/

• http://learn.jquery.com/code-organization/

• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Methods_Index

Page 31: jQuery PLUGIN

Otázky?© 2015 by Mino