SlideShare a Scribd company logo
The Next Step, Part 2
Where have we been?
SimpleYUI, inline JS
External JS file via <script>
Plugin for Node objects
Simple Widget
Why continue?
Then where are we going?
Widget provides some structure
initializer : function(config) {
var node = this.get("node");
if(node) {
if(!this.get("content")) {
this.set("content",
node.getAttribute("title"));
}
node.removeAttribute("title");
}
},
destructor : function() {
this._handlers.detach();
this._handlers = null;
},
renderUI
bindUI
bindUI : function() {
var node = this.get("node");
this._handlers = node.on({
mouseenter : {
fn : function() {
this.get('boundingBox').setStyles({
left : e.pageX + 5,
top : e.pageY + 5
});
this.show();
},
context : this
},
mouseleave: Y.bind(this.hide, this)
});
},
syncUI
syncUI : function() {
this.publish("sync", {
defaultFn : Y.bind(function() {
this.get('contentBox')
.setContent(this.get('content'));
}, this)
}).fire();
}
YUI().use("gallery-tooltip", function(Y) {
var tooltip = new Y.Tooltip({
visible : false,
render : true,
node : Y.one("a")
});
});
Now what?
Plugins for new behaviors
new Y.Tooltip({
visible : false,
render : true,
node : Y.one("a"),
plugins : [ Y.Plugin.TooltipSimpleDisplay ]
});
//or
var tooltip = New Y.Tooltip({
visible : false,
render : true,
node : Y.one("a")
});
tooltip.plug(Y.Plugin.TooltipSimpleDisplay);
Simple Plugin
Y.Base.create("TooltipSimpleDisplay", Y.Plugin.Base, [], {
initializer : function() {
var host = this.get("host");
host.on("sync", function(e) {
//prevent default sync method
e.preventDefault();
var content = host.get('content') + " + plugin";
host.get("contentBox").setContent(content);
}, this);
}
}, {
NS : 'TooltipSimpleDisplay'
});
Powered by Custom Events
That call to preventDefault is important
syncUI : function() {
this.publish("sync", {
//Now we see why this slightly
//odd syntax was important
//it lets this method be
//overriden by plugins
defaultFn : Y.bind(function() {
this.get('contentBox')
.setContent(this.get('content'));
}, this)
}).fire();
}
We can go further
http://www.flickr.com/photos/st3f4n/4501172754/
Transitions Module
Adding some flash
new Y.Tooltip({
visible : false,
render : true,
node : Y.one("a"),
plugins : [
//from gallery
Y.Plugin.TransitionOverlay
]
});
Still, not really all that useful
http://www.flickr.com/photos/zen/1174874997/
WidgetIO
YQL
WidgetYQL
Y.Base.create("WidgetYQL", Y.Plugin.Base, [], {
_yql : null,
initializer : function() {
this.after([
"queryChange", "formatterChange", "configChange"
], this._createYQL, this);
},
_ _createYQL : function() {
attrs = this.getAttrs([
"query", "formatter", "config"
]);
this._yql = new Y.YQLRequest(
attrs.query,
Y.bind(attrs.formatter, this),
attrs.config
);
},
sendQuery : function() {
return this._yql.send();
}
tooltip.plug(Y.Plugin.WidgetYQL, {
query : "SELECT * FROM ...",
formatter : function(r) {
host._yqlData = r.query.results.quote;
host.set("content",
r.query...LastTradePriceOnly);
host.fire("yqlResponse", r);
}
});
Repeating yourself sucks
Plugins are full JS objects
Plugins on top of plugins
http://idont/have/a/source/its/just/funny
initializer : function() {
var host = this.get("host");
host.plug(Y.namespace("Plugin").WidgetYQL, {
query : "SELECT * FROM ...",
formatter : function(r) {
host.set("content", r.query.res...);
host.fire("yqlResponse");
}
}
host.on(["visibleChange", "renderedChange"],
function(e) {
host.YQL.sendQuery();
}, this);
host.on("yqlResponse", function() {
host.syncUI();
});
}
Multiple plugins
new Y.Tooltip({
visible : false,
render : true,
node : Y.one('a'),
plugins : [
Y.Plugin.TransitionOverlay,
Y.Plugin.TooltipYQL,
Y.Plugin.TooltipDisplay
]
});
Done? Not so fast.
Prove it works, use tests
Widget & YUITest
var test = new Y.Test.Case({
name : "Simple Tooltip Test",
"tooltip should render without errors" :
function() {
var tooltip = new Y.Tooltip({
visible : false,
render : true,
node : Y.one('a')
});
}
});
//add & run test
Y.Test.Runner.add(test);
Y.Test.Runner.run();
Didn’t do anything too dumb
(yet)
Not very useful though
http://www.flickr.com/photos/sewitsforyou/3466154372/
Event simulation adds utility
new Y.Test.Case({
name : "Tooltip Event Simulation Test",
"tooltip should show on mouseenter" :
function() {
//create tooltip
var tooltip = ...
//simulate mousing over the link
Y.one("a").simulate("mouseover");
//fail if the tooltip isn't visible
Y.assert(
tooltip.get("visible"),
"Tooltip wasn't visible“
);
}
});
Lots of JS is async though
Sync tests don’t solve everything
this.wait()
this.resume()
"tooltip should transition to visible" : function() {
var tooltip = ...
//resume the test once the transition has finished
tooltip.transitionPlugin.on("end",
function(visible) {
this.resume(function() {
Y.assert(visible && tooltip.get("visible"),
"Tooltip wasn't visible");
});
}, this);
//show the overlay, triggering the transition
tooltip.show();
//wait for a bit for the transition to end
this.wait(1000);
}
Inline JS, great for prototyping
Bad for more complicated testing
Scaling up the testing
new Y.Test.Case({
name : "Advanced Tests",
//set up a tooltip before every test, clean it up
setUp : function() { ... },
tearDown : function() { ... },
//multiple tests
"tooltip should render without errors" : function() { ... },
"tooltip should show on mouseenter" : function() { ... },
"tooltip should transition to visible" : function() { ... },
"YQL plugin should get data from YQL" : function() { ... }
});
YUI Gallery
You’ve been meaning to share more anyways, right?
One way to flesh out your idea
Definitely not the only one
Patrick Cavit
@tivac on twitter
“tivac” in IRC
http://patcavit.com
http://lanyrd.com/people/tivac/

More Related Content

KEY
Object-Oriented Javascript
PDF
History of jQuery
PPTX
AngularJS $Provide Service
PPTX
Nodejs do teste de unidade ao de integração
PPTX
AngularJS Services
PDF
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
PDF
AngularJs
PDF
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Object-Oriented Javascript
History of jQuery
AngularJS $Provide Service
Nodejs do teste de unidade ao de integração
AngularJS Services
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
AngularJs
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-

What's hot (18)

PDF
05 JavaScript #burningkeyboards
PDF
06 jQuery #burningkeyboards
PDF
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
PDF
Introduction to cron queue
PDF
Cyclejs introduction
PPTX
Get started with YUI
PDF
Asynchronous JS in Odoo
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
PDF
HTML,CSS Next
KEY
jrubykaigi2010-lt-rubeus
PPTX
99 líneas que lo simplifican todo( sin animar)
PPTX
AngularJS: what is underneath the hood
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
PDF
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
PDF
A New Baseline for Front-End Devs
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
PPTX
AngularJS Compile Process
05 JavaScript #burningkeyboards
06 jQuery #burningkeyboards
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
Introduction to cron queue
Cyclejs introduction
Get started with YUI
Asynchronous JS in Odoo
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
HTML,CSS Next
jrubykaigi2010-lt-rubeus
99 líneas que lo simplifican todo( sin animar)
AngularJS: what is underneath the hood
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
A New Baseline for Front-End Devs
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
AngularJS Compile Process
Ad

Similar to The next step, part 2 (20)

PDF
Hack U - YUI - 2012 IIT Kharagpur
PPT
YUI3 - IIT Madras HackU
PPTX
Embracing YUI3 and Frontend Perf
ZIP
YUI 3
PPTX
YUI (Advanced)
PDF
JavaScript Libraries: The Big Picture
PDF
Yui intro
PPT
Yuihacku iitd-sumana
PPT
YUI 3 Loading Strategies - YUIConf2010
PPTX
YUI Hidden Gems
PDF
YUI - HackU 2010 IIT Mumbai
KEY
Achieving Performance Zen with YUI 3
PDF
JavaScript Libraries (@Media)
KEY
Running YUI 3 on Node.js - JSConf 2010
PDF
How to make Ajax Libraries work for you
PDF
YUI Evolved
PDF
JavaScript Library Overview
PDF
JavaScript Libraries (Kings of Code)
PDF
YUI introduction to build hack interfaces
PDF
yui3 is Sexy - 使用 YUI 3 的 Sexy Part !
Hack U - YUI - 2012 IIT Kharagpur
YUI3 - IIT Madras HackU
Embracing YUI3 and Frontend Perf
YUI 3
YUI (Advanced)
JavaScript Libraries: The Big Picture
Yui intro
Yuihacku iitd-sumana
YUI 3 Loading Strategies - YUIConf2010
YUI Hidden Gems
YUI - HackU 2010 IIT Mumbai
Achieving Performance Zen with YUI 3
JavaScript Libraries (@Media)
Running YUI 3 on Node.js - JSConf 2010
How to make Ajax Libraries work for you
YUI Evolved
JavaScript Library Overview
JavaScript Libraries (Kings of Code)
YUI introduction to build hack interfaces
yui3 is Sexy - 使用 YUI 3 的 Sexy Part !
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
1. Introduction to Computer Programming.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Machine Learning_overview_presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
A Presentation on Artificial Intelligence
PDF
Getting Started with Data Integration: FME Form 101
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
1. Introduction to Computer Programming.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine Learning_overview_presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A Presentation on Artificial Intelligence
Getting Started with Data Integration: FME Form 101
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25-Week II
20250228 LYD VKU AI Blended-Learning.pptx

The next step, part 2

  • 1. The Next Step, Part 2
  • 4. External JS file via <script>
  • 5. Plugin for Node objects
  • 8. Then where are we going?
  • 10. initializer : function(config) { var node = this.get("node"); if(node) { if(!this.get("content")) { this.set("content", node.getAttribute("title")); } node.removeAttribute("title"); } }, destructor : function() { this._handlers.detach(); this._handlers = null; },
  • 13. bindUI : function() { var node = this.get("node"); this._handlers = node.on({ mouseenter : { fn : function() { this.get('boundingBox').setStyles({ left : e.pageX + 5, top : e.pageY + 5 }); this.show(); }, context : this }, mouseleave: Y.bind(this.hide, this) }); },
  • 15. syncUI : function() { this.publish("sync", { defaultFn : Y.bind(function() { this.get('contentBox') .setContent(this.get('content')); }, this) }).fire(); }
  • 16. YUI().use("gallery-tooltip", function(Y) { var tooltip = new Y.Tooltip({ visible : false, render : true, node : Y.one("a") }); });
  • 18. Plugins for new behaviors
  • 19. new Y.Tooltip({ visible : false, render : true, node : Y.one("a"), plugins : [ Y.Plugin.TooltipSimpleDisplay ] }); //or var tooltip = New Y.Tooltip({ visible : false, render : true, node : Y.one("a") }); tooltip.plug(Y.Plugin.TooltipSimpleDisplay);
  • 21. Y.Base.create("TooltipSimpleDisplay", Y.Plugin.Base, [], { initializer : function() { var host = this.get("host"); host.on("sync", function(e) { //prevent default sync method e.preventDefault(); var content = host.get('content') + " + plugin"; host.get("contentBox").setContent(content); }, this); } }, { NS : 'TooltipSimpleDisplay' });
  • 22. Powered by Custom Events That call to preventDefault is important
  • 23. syncUI : function() { this.publish("sync", { //Now we see why this slightly //odd syntax was important //it lets this method be //overriden by plugins defaultFn : Y.bind(function() { this.get('contentBox') .setContent(this.get('content')); }, this) }).fire(); }
  • 24. We can go further http://www.flickr.com/photos/st3f4n/4501172754/
  • 26. new Y.Tooltip({ visible : false, render : true, node : Y.one("a"), plugins : [ //from gallery Y.Plugin.TransitionOverlay ] });
  • 27. Still, not really all that useful http://www.flickr.com/photos/zen/1174874997/
  • 29. YQL
  • 31. Y.Base.create("WidgetYQL", Y.Plugin.Base, [], { _yql : null, initializer : function() { this.after([ "queryChange", "formatterChange", "configChange" ], this._createYQL, this); }, _ _createYQL : function() { attrs = this.getAttrs([ "query", "formatter", "config" ]); this._yql = new Y.YQLRequest( attrs.query, Y.bind(attrs.formatter, this), attrs.config ); }, sendQuery : function() { return this._yql.send(); }
  • 32. tooltip.plug(Y.Plugin.WidgetYQL, { query : "SELECT * FROM ...", formatter : function(r) { host._yqlData = r.query.results.quote; host.set("content", r.query...LastTradePriceOnly); host.fire("yqlResponse", r); } });
  • 34. Plugins are full JS objects
  • 35. Plugins on top of plugins http://idont/have/a/source/its/just/funny
  • 36. initializer : function() { var host = this.get("host"); host.plug(Y.namespace("Plugin").WidgetYQL, { query : "SELECT * FROM ...", formatter : function(r) { host.set("content", r.query.res...); host.fire("yqlResponse"); } } host.on(["visibleChange", "renderedChange"], function(e) { host.YQL.sendQuery(); }, this); host.on("yqlResponse", function() { host.syncUI(); }); }
  • 38. new Y.Tooltip({ visible : false, render : true, node : Y.one('a'), plugins : [ Y.Plugin.TransitionOverlay, Y.Plugin.TooltipYQL, Y.Plugin.TooltipDisplay ] });
  • 39. Done? Not so fast.
  • 40. Prove it works, use tests
  • 42. var test = new Y.Test.Case({ name : "Simple Tooltip Test", "tooltip should render without errors" : function() { var tooltip = new Y.Tooltip({ visible : false, render : true, node : Y.one('a') }); } }); //add & run test Y.Test.Runner.add(test); Y.Test.Runner.run();
  • 43. Didn’t do anything too dumb (yet)
  • 44. Not very useful though http://www.flickr.com/photos/sewitsforyou/3466154372/
  • 46. new Y.Test.Case({ name : "Tooltip Event Simulation Test", "tooltip should show on mouseenter" : function() { //create tooltip var tooltip = ... //simulate mousing over the link Y.one("a").simulate("mouseover"); //fail if the tooltip isn't visible Y.assert( tooltip.get("visible"), "Tooltip wasn't visible“ ); } });
  • 47. Lots of JS is async though Sync tests don’t solve everything
  • 50. "tooltip should transition to visible" : function() { var tooltip = ... //resume the test once the transition has finished tooltip.transitionPlugin.on("end", function(visible) { this.resume(function() { Y.assert(visible && tooltip.get("visible"), "Tooltip wasn't visible"); }); }, this); //show the overlay, triggering the transition tooltip.show(); //wait for a bit for the transition to end this.wait(1000); }
  • 51. Inline JS, great for prototyping Bad for more complicated testing
  • 52. Scaling up the testing
  • 53. new Y.Test.Case({ name : "Advanced Tests", //set up a tooltip before every test, clean it up setUp : function() { ... }, tearDown : function() { ... }, //multiple tests "tooltip should render without errors" : function() { ... }, "tooltip should show on mouseenter" : function() { ... }, "tooltip should transition to visible" : function() { ... }, "YQL plugin should get data from YQL" : function() { ... } });
  • 54. YUI Gallery You’ve been meaning to share more anyways, right?
  • 55. One way to flesh out your idea Definitely not the only one
  • 56. Patrick Cavit @tivac on twitter “tivac” in IRC http://patcavit.com http://lanyrd.com/people/tivac/

Editor's Notes

  • #25: http://www.flickr.com/photos/st3f4n/4501172754/
  • #28: http://www.flickr.com/photos/zen/1174874997/
  • #45: http://www.flickr.com/photos/sewitsforyou/3466154372/