Last active
October 1, 2015 12:08
-
-
Save albohlabs/1989402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add("my-widget", function (Y) { | |
var Node = Y.Node, | |
getClassName = Y.ClassNameManager.getClassName, | |
i, j, | |
baseClasses = ["_CLASS", "title", "loader", "viewer", "tweet", "ui", "label", "input", "button", "error"], | |
templates = ["_TEMPLATE", "<hgroup class={titleclass}><h1>{title}</h1><h2>{subtitle}<span>{term}</span></h2></hgroup>", "<div class={loaderclass}>loading...</div>", "<div class={viewerclass}></div>", "<article><a href={userurl} title={username}><img src={avatar} alt={username} /><h1>{username}</h1></a><p>{text}</p></article>", "<div class={uiclass}></div>", "<label class={labelclass}>{labeltext}</label>", "<input class={inputclass} />", "<button class={buttonclass}>{buttontext}</button>", "<p class={errorclass}>{message}</p>"]; | |
//constructor | |
function MyWidget(config) { | |
MyWidget.superclass.constructor.apply(this, arguments); | |
} | |
Y.namespace("DW").MyWidget = MyWidget; | |
MyWidget.NAME = "mywidget"; | |
MyWidget.ATTRS = { | |
term: { | |
value: "yui3", | |
validator: "_validateTerm" | |
}, | |
numberOfTweets: { | |
value: 5 | |
}, | |
baseURL: { | |
value: "http://search.twitter.com/search.json?&with_twitter_user_id=true&include_entities=true&callback={callback}" | |
}, | |
strings: { | |
value: { | |
title: "Twitter Search Widget", | |
subTitle: "Showing results for:", | |
label: "Search Term", | |
button: "Search", | |
errorMsg: "I'm sorry, that search term did not return any results. Please try a different term" | |
} | |
} | |
}; | |
MyWidget.HTML_PARSER = { | |
term: function (srcNode) { | |
var input = srcNode.one("input"); | |
if (input) { | |
var val = input.get("value"); | |
input.remove(); | |
} | |
return val; | |
} | |
}; | |
MyWidget = Y.extend(MyWidget, Y.Widget, { | |
initializer: function () { | |
}, | |
destructor:fucntion() { | |
}, | |
_validateTerm: function (val) { | |
return val !== this.get("term"); | |
}, | |
}); | |
}, "0.0.1", { requires: ["widget", "substitute", "jsonp"] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment