~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/docs/yui/yui-gallery.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
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>
11
 
</head>
12
 
<body>
13
 
 
14
 
<div id="doc">
15
 
    <h1>Example: Natively use YUI Gallery Modules</h1>
16
 
 
17
 
    
18
 
        <a href="#toc" class="jump">Jump to Table of Contents</a>
19
 
    
20
 
 
21
 
    <div class="yui3-g">
22
 
        <div class="yui3-u-3-4">
23
 
            <div id="main">
24
 
                <div class="content"><div class="intro">
25
 
<p>This example shows how to natively use a YUI Gallery module.</p>
26
 
</div>
27
 
 
28
 
<div class="example">
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>
31
 
 
32
 
<script>
33
 
(function() {
34
 
var username = 'davglass',
35
 
    key = 'R_d2405255a50490af4394745edeb957f7';
36
 
 
37
 
YUI().use('event-key', 'node', 'gallery-bitly', function(Y) {
38
 
    /*
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.
42
 
    */
43
 
    var bitly = new Y.bitly({
44
 
        username: username,
45
 
        key: key
46
 
    }),
47
 
    exp = Y.one('#expand'),
48
 
    short = Y.one('#shorten'),
49
 
    createElm = function(par, url) {
50
 
        var item = '';
51
 
        if (par.one('em')) {
52
 
            item = par.one('em');
53
 
        } else {
54
 
            item = Y.Node.create('<em></em>');
55
 
            par.append(item);
56
 
        }
57
 
        item.set('innerHTML', '<a href="' + url + '">' + url + '</a>');
58
 
        return item;
59
 
    },
60
 
    shorten = function(node) {
61
 
        bitly.shorten(short.get('value'), function(r) {
62
 
            var par = node.get('parentNode'),
63
 
                item = createElm(par, r.shortUrl);
64
 
 
65
 
            exp.set('value', r.shortUrl);
66
 
        });
67
 
    },
68
 
    expand = function(node) {
69
 
        bitly.expandByURL(exp.get('value'), function(r) {
70
 
            var par = node.get('parentNode'),
71
 
                item = createElm(par, r.longUrl);
72
 
 
73
 
            short.set('value', r.longUrl);
74
 
        });
75
 
    };
76
 
    
77
 
 
78
 
    Y.on('click', function(e) {
79
 
        shorten(e.target);
80
 
    }, '#do_shorten');
81
 
 
82
 
    Y.on('click', function(e) {
83
 
        expand(e.target);
84
 
    }, '#do_expand');
85
 
 
86
 
    Y.on('blur', function(e) {
87
 
        shorten(e.target);
88
 
    }, '#shorten');
89
 
 
90
 
    Y.on('blur', function(e) {
91
 
        expand(e.target);
92
 
    }, '#expand');
93
 
 
94
 
    short.on('key', function(e) {
95
 
        shorten(e.target);
96
 
    }, 'enter');
97
 
 
98
 
    exp.on('key', function(e) {
99
 
        expand(e.target);
100
 
    }, 'enter');
101
 
 
102
 
});
103
 
 
104
 
 
105
 
})();
106
 
</script>
107
 
 
108
 
</div>
109
 
 
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>
113
 
 
114
 
<pre class="code prettyprint">YUI().use(&#x27;gallery-bitly&#x27;, function(Y) {
115
 
    &#x2F;&#x2F;Y.bitly is available here
116
 
});</pre>
117
 
 
118
 
 
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>
122
 
 
123
 
<pre class="code prettyprint">YUI().use(&#x27;event-key&#x27;, &#x27;node&#x27;, &#x27;gallery-bitly&#x27;, function(Y) {
124
 
    &#x2F;*
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.
128
 
    *&#x2F;
129
 
    var bitly = new Y.bitly({
130
 
        username: username,
131
 
        key: key
132
 
    }),
133
 
    exp = Y.one(&#x27;#expand&#x27;),
134
 
    short = Y.one(&#x27;#shorten&#x27;),
135
 
    createElm = function(par, url) {
136
 
        var item = &#x27;&#x27;;
137
 
        if (par.one(&#x27;em&#x27;)) {
138
 
            item = par.one(&#x27;em&#x27;);
139
 
        } else {
140
 
            item = Y.Node.create(&#x27;&lt;em&gt;&lt;&#x2F;em&gt;&#x27;);
141
 
            par.append(item);
142
 
        }
143
 
        item.set(&#x27;innerHTML&#x27;, &#x27;&lt;a href=&quot;&#x27; + url + &#x27;&quot;&gt;&#x27; + url + &#x27;&lt;&#x2F;a&gt;&#x27;);
144
 
        return item;
145
 
    },
146
 
    shorten = function(node) {
147
 
        bitly.shorten(short.get(&#x27;value&#x27;), function(r) {
148
 
            var par = node.get(&#x27;parentNode&#x27;),
149
 
                item = createElm(par, r.shortUrl);
150
 
 
151
 
            exp.set(&#x27;value&#x27;, r.shortUrl);
152
 
        });
153
 
    },
154
 
    expand = function(node) {
155
 
        bitly.expandByURL(exp.get(&#x27;value&#x27;), function(r) {
156
 
            var par = node.get(&#x27;parentNode&#x27;),
157
 
                item = createElm(par, r.longUrl);
158
 
 
159
 
            short.set(&#x27;value&#x27;, r.longUrl);
160
 
        });
161
 
    };
162
 
    
163
 
 
164
 
    Y.on(&#x27;click&#x27;, function(e) {
165
 
        shorten(e.target);
166
 
    }, &#x27;#do_shorten&#x27;);
167
 
 
168
 
    Y.on(&#x27;click&#x27;, function(e) {
169
 
        expand(e.target);
170
 
    }, &#x27;#do_expand&#x27;);
171
 
 
172
 
    Y.on(&#x27;blur&#x27;, function(e) {
173
 
        shorten(e.target);
174
 
    }, &#x27;#shorten&#x27;);
175
 
 
176
 
    Y.on(&#x27;blur&#x27;, function(e) {
177
 
        expand(e.target);
178
 
    }, &#x27;#expand&#x27;);
179
 
 
180
 
    short.on(&#x27;key&#x27;, function(e) {
181
 
        shorten(e.target);
182
 
    }, &#x27;enter&#x27;);
183
 
 
184
 
    exp.on(&#x27;key&#x27;, function(e) {
185
 
        expand(e.target);
186
 
    }, &#x27;enter&#x27;);
187
 
 
188
 
});</pre>
189
 
 
190
 
</div>
191
 
            </div>
192
 
        </div>
193
 
 
194
 
        <div class="yui3-u-1-4">
195
 
            <div class="sidebar">
196
 
                
197
 
                    <div id="toc" class="sidebox">
198
 
                        <div class="hd">
199
 
                            <h2 class="no-toc">Table of Contents</h2>
200
 
                        </div>
201
 
 
202
 
                        <div class="bd">
203
 
                            <ul class="toc">
204
 
<li>
205
 
<a href="#loading-gallery-modules">Loading Gallery Modules</a>
206
 
</li>
207
 
<li>
208
 
<a href="#bitly-example">Bitly example</a>
209
 
</li>
210
 
</ul>
211
 
                        </div>
212
 
                    </div>
213
 
                
214
 
 
215
 
                
216
 
                    <div class="sidebox">
217
 
                        <div class="hd">
218
 
                            <h2 class="no-toc">Examples</h2>
219
 
                        </div>
220
 
 
221
 
                        <div class="bd">
222
 
                            <ul class="examples">
223
 
                                
224
 
                                    
225
 
                                        <li data-description="Setting up a YUI Instance">
226
 
                                            <a href="yui-core.html">YUI Core</a>
227
 
                                        </li>
228
 
                                    
229
 
                                
230
 
                                    
231
 
                                        <li data-description="Working with multiple YUI instances.">
232
 
                                            <a href="yui-multi.html">Multiple Instances</a>
233
 
                                        </li>
234
 
                                    
235
 
                                
236
 
                                    
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>
239
 
                                        </li>
240
 
                                    
241
 
                                
242
 
                                    
243
 
                                        <li data-description="Create Class Hierarchies with &#x60;extend&#x60;">
244
 
                                            <a href="yui-extend.html">Create Class Hierarchies with &#x60;extend&#x60;</a>
245
 
                                        </li>
246
 
                                    
247
 
                                
248
 
                                    
249
 
                                        <li data-description="Creating a composition-based class structure using &#x60;augment&#x60;">
250
 
                                            <a href="yui-augment.html">Compose Classes of Objects with &#x60;augment&#x60;</a>
251
 
                                        </li>
252
 
                                    
253
 
                                
254
 
                                    
255
 
                                        <li data-description="Add behaviors to objects or static classes with &#x60;mix&#x60;">
256
 
                                            <a href="yui-mix.html">Add Behaviors to Objects with &#x60;mix&#x60;</a>
257
 
                                        </li>
258
 
                                    
259
 
                                
260
 
                                    
261
 
                                        <li data-description="Combine data sets and create shallow copies of objects with &#x60;merge&#x60;">
262
 
                                            <a href="yui-merge.html">Combine Data Sets with &#x60;merge&#x60;</a>
263
 
                                        </li>
264
 
                                    
265
 
                                
266
 
                                    
267
 
                                        <li data-description="Check data types with the &#x60;Lang Utilities&#x60;">
268
 
                                            <a href="yui-isa.html">Check Data Types with &#x60;Lang&#x60;</a>
269
 
                                        </li>
270
 
                                    
271
 
                                
272
 
                                    
273
 
                                        <li data-description="Get information about the current user agent with &#x60;UA&#x60;">
274
 
                                            <a href="yui-ua.html">Browser Detection with &#x60;UA&#x60;</a>
275
 
                                        </li>
276
 
                                    
277
 
                                
278
 
                                    
279
 
                                        <li data-description="Working with YUI 2 in 3">
280
 
                                            <a href="yui-yui2.html">Working with YUI 2 in 3</a>
281
 
                                        </li>
282
 
                                    
283
 
                                
284
 
                                    
285
 
                                        <li data-description="Natively use YUI Gallery Modules">
286
 
                                            <a href="yui-gallery.html">Natively use YUI Gallery Modules</a>
287
 
                                        </li>
288
 
                                    
289
 
                                
290
 
                                    
291
 
                                        <li data-description="Programatically use Loader">
292
 
                                            <a href="loader-resolve.html">Programatically use Loader</a>
293
 
                                        </li>
294
 
                                    
295
 
                                
296
 
                                    
297
 
                                        <li data-description="Executing functions in parallel">
298
 
                                            <a href="parallel.html">Using Y.Parallel</a>
299
 
                                        </li>
300
 
                                    
301
 
                                
302
 
                            </ul>
303
 
                        </div>
304
 
                    </div>
305
 
                
306
 
 
307
 
                
308
 
            </div>
309
 
        </div>
310
 
    </div>
311
 
</div>
312
 
 
313
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
314
 
<script>prettyPrint();</script>
315
 
 
316
 
</body>
317
 
</html>