5
<title>Example: Natively use YUI Gallery Modules</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Natively use YUI Gallery Modules</h1>
18
<a href="#toc" class="jump">Jump to Table of Contents</a>
22
<div class="yui3-u-3-4">
24
<div class="content"><div class="intro">
25
<p>This example shows how to natively use a YUI Gallery module.</p>
29
<p><strong>Long URL:</strong> <input type="text" id="shorten" value="https://www.github.com/yui/yui3" size="35"> <input type="button" id="do_shorten" value="Shorten" class="button"></p>
30
<p><strong>Short URL:</strong> <input type="text" id="expand" value="http://bit.ly/paj1De" size="35"> <input type="button" id="do_expand" value="Expand" class="button"></p>
34
var username = 'davglass',
35
key = 'R_d2405255a50490af4394745edeb957f7';
37
YUI().use('event-key', 'node', 'gallery-bitly', function(Y) {
39
To use the bit.ly module, you must have a bit.ly username and apiKey.
40
If you do not have an apiKey, sign up for a bitly account and go to
41
your Account page to get your apiKey.
43
var bitly = new Y.bitly({
47
exp = Y.one('#expand'),
48
short = Y.one('#shorten'),
49
createElm = function(par, url) {
54
item = Y.Node.create('<em></em>');
57
item.set('innerHTML', '<a href="' + url + '">' + url + '</a>');
60
shorten = function(node) {
61
bitly.shorten(short.get('value'), function(r) {
62
var par = node.get('parentNode'),
63
item = createElm(par, r.shortUrl);
65
exp.set('value', r.shortUrl);
68
expand = function(node) {
69
bitly.expandByURL(exp.get('value'), function(r) {
70
var par = node.get('parentNode'),
71
item = createElm(par, r.longUrl);
73
short.set('value', r.longUrl);
78
Y.on('click', function(e) {
82
Y.on('click', function(e) {
86
Y.on('blur', function(e) {
90
Y.on('blur', function(e) {
94
short.on('key', function(e) {
98
exp.on('key', function(e) {
110
<h3 id="loading-gallery-modules">Loading Gallery Modules</h3>
111
<p>If a Gallery module has been pushed to the CDN, it will be available to use as a first class YUI 3 module.</p>
112
<p>To load a Gallery module, simply add its module name to your <code>YUI().use</code> call. In the code sample below we are using the <code>gallery-bitly</code> module.</p>
114
<pre class="code prettyprint">YUI().use('gallery-bitly', function(Y) {
115
//Y.bitly is available here
119
<h3 id="bitly-example">Bitly example</h3>
120
<p>This simple example demonstrates using the <a href="http://yuilibrary.com/gallery/show/bitly">gallery-bitly</a> module to expand and shorten url's.</p>
121
<p><strong>Note: </strong> We are using the gallery module directly from the <code>use</code> statement, no configuration needed.</p>
123
<pre class="code prettyprint">YUI().use('event-key', 'node', 'gallery-bitly', function(Y) {
125
To use the bit.ly module, you must have a bit.ly username and apiKey.
126
If you do not have an apiKey, sign up for a bitly account and go to
127
your Account page to get your apiKey.
129
var bitly = new Y.bitly({
133
exp = Y.one('#expand'),
134
short = Y.one('#shorten'),
135
createElm = function(par, url) {
136
var item = '';
137
if (par.one('em')) {
138
item = par.one('em');
140
item = Y.Node.create('<em></em>');
143
item.set('innerHTML', '<a href="' + url + '">' + url + '</a>');
146
shorten = function(node) {
147
bitly.shorten(short.get('value'), function(r) {
148
var par = node.get('parentNode'),
149
item = createElm(par, r.shortUrl);
151
exp.set('value', r.shortUrl);
154
expand = function(node) {
155
bitly.expandByURL(exp.get('value'), function(r) {
156
var par = node.get('parentNode'),
157
item = createElm(par, r.longUrl);
159
short.set('value', r.longUrl);
164
Y.on('click', function(e) {
166
}, '#do_shorten');
168
Y.on('click', function(e) {
170
}, '#do_expand');
172
Y.on('blur', function(e) {
174
}, '#shorten');
176
Y.on('blur', function(e) {
178
}, '#expand');
180
short.on('key', function(e) {
182
}, 'enter');
184
exp.on('key', function(e) {
186
}, 'enter');
194
<div class="yui3-u-1-4">
195
<div class="sidebar">
197
<div id="toc" class="sidebox">
199
<h2 class="no-toc">Table of Contents</h2>
205
<a href="#loading-gallery-modules">Loading Gallery Modules</a>
208
<a href="#bitly-example">Bitly example</a>
216
<div class="sidebox">
218
<h2 class="no-toc">Examples</h2>
222
<ul class="examples">
225
<li data-description="Setting up a YUI Instance">
226
<a href="yui-core.html">YUI Core</a>
231
<li data-description="Working with multiple YUI instances.">
232
<a href="yui-multi.html">Multiple Instances</a>
237
<li data-description="On-demand loading of YUI and non-YUI assets">
238
<a href="yui-loader-ext.html">YUI Loader - Dynamically Adding YUI and External Modules</a>
243
<li data-description="Create Class Hierarchies with `extend`">
244
<a href="yui-extend.html">Create Class Hierarchies with `extend`</a>
249
<li data-description="Creating a composition-based class structure using `augment`">
250
<a href="yui-augment.html">Compose Classes of Objects with `augment`</a>
255
<li data-description="Add behaviors to objects or static classes with `mix`">
256
<a href="yui-mix.html">Add Behaviors to Objects with `mix`</a>
261
<li data-description="Combine data sets and create shallow copies of objects with `merge`">
262
<a href="yui-merge.html">Combine Data Sets with `merge`</a>
267
<li data-description="Check data types with the `Lang Utilities`">
268
<a href="yui-isa.html">Check Data Types with `Lang`</a>
273
<li data-description="Get information about the current user agent with `UA`">
274
<a href="yui-ua.html">Browser Detection with `UA`</a>
279
<li data-description="Working with YUI 2 in 3">
280
<a href="yui-yui2.html">Working with YUI 2 in 3</a>
285
<li data-description="Natively use YUI Gallery Modules">
286
<a href="yui-gallery.html">Natively use YUI Gallery Modules</a>
291
<li data-description="Programatically use Loader">
292
<a href="loader-resolve.html">Programatically use Loader</a>
297
<li data-description="Executing functions in parallel">
298
<a href="parallel.html">Using Y.Parallel</a>
313
<script src="../assets/vendor/prettify/prettify-min.js"></script>
314
<script>prettyPrint();</script>