Permalink
Browse files

Converted gallery-badge with yogi

  • Loading branch information...
davglass committed Oct 17, 2012
1 parent 7363fc0 commit a44355d46b543acfc0d619a6bab478064dd5678f

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,145 @@
+YUI.add('gallery-badge', function (Y, NAME) {
+
+
+ var B = function(config) {
+ this._lazyAddAttrs = false;
+ config.node = config.host;
+ B.superclass.constructor.call(this, config);
+ };
+
+ B.NAME = "gallery-badge";
+
+ B.NS = "badge";
+
+ B.ATTRS = {
+ node: {
+ setter: function(node) {
+ return Y.one(node);
+ }
+ },
+ type: {
+ value: 'popular',
+ setter: function(v) {
+ if (v !== 'user') {
+ this.set('username', '');
+ }
+ return v;
+ }
+ },
+ header: {
+ value: '',
+ getter: function() {
+ var h = 'Popular Gallery Items';
+ switch (this.get('type')) {
+ case 'oncdn':
+ h = 'Gallery Items on the CDN';
+ break;
+ case 'featured':
+ h = 'Featured Gallery Items';
+ break;
+ case 'random':
+ h = 'Random Gallery Item';
+ break;
+ case 'user':
+ h = 'My Gallery Items';
+ break;
+ }
+ return h;
+ }
+ },
+ username: {
+ value: '',
+ setter: function(v) {
+ if (v) {
+ this.set('header', 'My Gallery Items');
+ this._setStateVal('type', 'user');
+ }
+ return v;
+ }
+ },
+ render: {
+ value: true
+ },
+ data: {
+ value: {}
+ }
+ };
+
+ Y.extend(B, Y.Base, {
+ buildUI: function(e) {
+ this.set('data', e.data);
+ if (e.data.error) {
+ return;
+ }
+ var data = e.data,
+ type = this.get('type'),
+ header = Y.Node.create('<h2>' + this.get('header') + '</h2>'),
+ node = Y.Node.create('<ul></ul>'),
+ n = this.get('node');
+
+ if (type != 'random') {
+ if (type == 'user') {
+ header = Y.Node.create('<h2><a href="http:/'+'/yuilibrary.com/gallery/user/' + data.userinfo.username + '">' + data.userinfo.fullname + '\'s Gallery Items</a></h2>');
+ }
+ Y.each(data.modules, function(v) {
+ node.append('<li><a href="' + v.url + '">' + v.title + '</a></li>');
+ });
+ } else {
+ node.append('<li><a href="' + data.modules.url + '">' + data.modules.title + '</a></li>');
+ }
+
+ n.set('innerHTML', '');
+ n.append(header);
+ n.append(node);
+ },
+ getSQL: function() {
+ var type = this.get('type'), sql;
+ if (type == 'user') {
+ sql = "select * from yui.gallery.user where (username = '" + this.get('username') + "')";
+ } else {
+ sql = "select * from yui.gallery." + type;
+ }
+ return sql;
+ },
+ updateUserUI: function(e) {
+ if (e.newVal !== '') {
+ this.updateUI();
+ }
+ },
+ updateUI: function(e) {
+ var sql = this.getSQL(), q;
+
+ q = new Y.yql(sql, Y.bind(function(r) {
+ if (r.query && r.query.results && r.query.results.json) {
+ this.fire('dataReturned', { data: r.query.results.json });
+ }
+ }, this), { env: 'http:/'+'/yuilibrary.com/yql/yui.env' });
+
+ },
+ initializer: function() {
+ this.after('typeChange', Y.bind(this.updateUI, this));
+ this.after('usernameChange', Y.bind(this.updateUserUI, this));
+ this.publish('dataReturned', {
+ type: 'datareturned',
+ defaultFn: this.buildUI
+ });
+ if (this.get('render')) {
+ this.render();
+ }
+ },
+ render: function() {
+ this.updateUI();
+ },
+ refresh: function() {
+ this.updateUI();
+ },
+ destructor: function() {
+ this.get('node').set('innerHTML', '');
+ }
+ });
+ Y.namespace('Plugin');
+ Y.Plugin.Badge = B;
+
+
+
+}, '@VERSION@', {"requires": ["node", "event", "gallery-yql", "base"], "supersedes": [], "optional": [], "skinnable": false});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,145 @@
+YUI.add('gallery-badge', function (Y, NAME) {
+
+
+ var B = function(config) {
+ this._lazyAddAttrs = false;
+ config.node = config.host;
+ B.superclass.constructor.call(this, config);
+ };
+
+ B.NAME = "gallery-badge";
+
+ B.NS = "badge";
+
+ B.ATTRS = {
+ node: {
+ setter: function(node) {
+ return Y.one(node);
+ }
+ },
+ type: {
+ value: 'popular',
+ setter: function(v) {
+ if (v !== 'user') {
+ this.set('username', '');
+ }
+ return v;
+ }
+ },
+ header: {
+ value: '',
+ getter: function() {
+ var h = 'Popular Gallery Items';
+ switch (this.get('type')) {
+ case 'oncdn':
+ h = 'Gallery Items on the CDN';
+ break;
+ case 'featured':
+ h = 'Featured Gallery Items';
+ break;
+ case 'random':
+ h = 'Random Gallery Item';
+ break;
+ case 'user':
+ h = 'My Gallery Items';
+ break;
+ }
+ return h;
+ }
+ },
+ username: {
+ value: '',
+ setter: function(v) {
+ if (v) {
+ this.set('header', 'My Gallery Items');
+ this._setStateVal('type', 'user');
+ }
+ return v;
+ }
+ },
+ render: {
+ value: true
+ },
+ data: {
+ value: {}
+ }
+ };
+
+ Y.extend(B, Y.Base, {
+ buildUI: function(e) {
+ this.set('data', e.data);
+ if (e.data.error) {
+ return;
+ }
+ var data = e.data,
+ type = this.get('type'),
+ header = Y.Node.create('<h2>' + this.get('header') + '</h2>'),
+ node = Y.Node.create('<ul></ul>'),
+ n = this.get('node');
+
+ if (type != 'random') {
+ if (type == 'user') {
+ header = Y.Node.create('<h2><a href="http:/'+'/yuilibrary.com/gallery/user/' + data.userinfo.username + '">' + data.userinfo.fullname + '\'s Gallery Items</a></h2>');
+ }
+ Y.each(data.modules, function(v) {
+ node.append('<li><a href="' + v.url + '">' + v.title + '</a></li>');
+ });
+ } else {
+ node.append('<li><a href="' + data.modules.url + '">' + data.modules.title + '</a></li>');
+ }
+
+ n.set('innerHTML', '');
+ n.append(header);
+ n.append(node);
+ },
+ getSQL: function() {
+ var type = this.get('type'), sql;
+ if (type == 'user') {
+ sql = "select * from yui.gallery.user where (username = '" + this.get('username') + "')";
+ } else {
+ sql = "select * from yui.gallery." + type;
+ }
+ return sql;
+ },
+ updateUserUI: function(e) {
+ if (e.newVal !== '') {
+ this.updateUI();
+ }
+ },
+ updateUI: function(e) {
+ var sql = this.getSQL(), q;
+
+ q = new Y.yql(sql, Y.bind(function(r) {
+ if (r.query && r.query.results && r.query.results.json) {
+ this.fire('dataReturned', { data: r.query.results.json });
+ }
+ }, this), { env: 'http:/'+'/yuilibrary.com/yql/yui.env' });
+
+ },
+ initializer: function() {
+ this.after('typeChange', Y.bind(this.updateUI, this));
+ this.after('usernameChange', Y.bind(this.updateUserUI, this));
+ this.publish('dataReturned', {
+ type: 'datareturned',
+ defaultFn: this.buildUI
+ });
+ if (this.get('render')) {
+ this.render();
+ }
+ },
+ render: function() {
+ this.updateUI();
+ },
+ refresh: function() {
+ this.updateUI();
+ },
+ destructor: function() {
+ this.get('node').set('innerHTML', '');
+ }
+ });
+ Y.namespace('Plugin');
+ Y.Plugin.Badge = B;
+
+
+
+}, '@VERSION@', {"requires": ["node", "event", "gallery-yql", "base"], "supersedes": [], "optional": [], "skinnable": false});
No changes.
@@ -0,0 +1,11 @@
+{
+ "name": "gallery-badge",
+ "builds": {
+ "gallery-badge": {
+ "jsfiles": [
+ "badge.js"
+ ],
+ "meta": {}
+ }
+ }
+}
No changes.
@@ -0,0 +1,10 @@
+{
+ "name" : "gallery-badge",
+ "displayName": "Gallery: badge",
+ "description": "A simple YUI 3 Gallery badge using the YQL Gallery Module.",
+ "author" : [ "davtest" ],
+
+ "tags": [ "gallery" ],
+
+ "examples": []
+}
@@ -0,0 +1,41 @@
+<div class="intro">
+ <p>
+ A simple YUI 3 Gallery badge using the YQL Gallery Module.
+ </p>
+</div>
+
+<h2>Description</h2>
+
+<p>A simple YUI 3 Gallery badge using the YQL Gallery Module.<br>
+<br>
+<b>Note: this badge is not skinned. It will simply produce an unordered list of modules</b><br>
+</p>
+
+```
+YUI().use('gallery-badge', function(Y) {
+
+ //Simple Use Case
+ var node = Y.one('div.badge');
+ node.plug(Y.Plugin.Badge, {
+ type: 'oncdn' //popular, new, all, featured
+ });
+
+ node.set('username', 'davglass');
+ //or
+ node.set('type', 'popular');
+
+ //Event Driven, with No Layout
+ node = Y.one('div.badge');
+ node.plug(Y.Plugin.Badge, {
+ username: 'davglass',
+ render: false
+ });
+ node.badge.on('dataReturned', function(e) {
+ e.preventDefault();
+ console.log(e);
+ });
+ node.badge.render();
+
+});
+```
+
No changes.
@@ -0,0 +1,13 @@
+{
+ "gallery-badge": {
+ "requires": [
+ "node",
+ "event",
+ "gallery-yql",
+ "base"
+ ],
+ "supersedes": [],
+ "optional": [],
+ "skinnable": false
+ }
+}
@@ -0,0 +1,24 @@
+<!doctype html>
+<html>
+<head>
+ <title>gallery-badge</title>
+ <script src="/build/yui/yui.js"></script>
+ <script src="js/tests.js"></script>
+</head>
+<body class="yui3-skin-sam">
+<div id="logger"></div>
+
+<script>
+YUI({
+ coverage: ['badge'],
+ filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw'
+}).use('test-console', 'test', 'module-tests', function(Y) {
+
+ (new Y.Test.Console()).render('#logger');
+
+ Y.Test.Runner.setName('gallery-badge');
+ Y.Test.Runner.run();
+});
+</script>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit a44355d

Please sign in to comment.