plugin.html revision 22e7b8682fb30ed90ef0b0cbce6235e589a85708
1756N/A<!DOCTYPE html>
1879N/A<html>
1756N/A<head>
1756N/A <link rel="stylesheet" href="http://yui.yahooapis.com/3.0.0b1/build/cssfonts/fonts-min.css">
1756N/A <style>
1756N/A body {
1756N/A font-size:16px;
1756N/A }
1756N/A .demoified {
1756N/A font-size:200%;
1756N/A border:10px solid red;
1756N/A }
1756N/A script.mine {
1756N/A clear:left;
1756N/A white-space:pre;
1756N/A display:block;
1756N/A font-family:monospace;
1756N/A background:#eef;
1879N/A }
1879N/A script::before, script::after {
1879N/A content:"<script>";
1756N/A }
1756N/A script::after {
1756N/A content:"</script>";
1879N/A }
1879N/A script[src]::before {
1879N/A content:"<script src=\"" attr(src) "\">";
3863N/A white-space:nowrap;
1879N/A }
1879N/A script[src] {
1756N/A background:#fff;
1756N/A }
1756N/A </style>
1756N/A
1756N/A <title>autocomplete exploration</title>
1756N/A</head>
1756N/A<body class="yui-skin-sam">
1756N/A
1756N/A<form>
1756N/A <label for="ac">
1756N/A INPUT!
1756N/A </label>
1756N/A <input name="ac" id="ac" type="text">
1756N/A <input type="submit" id="log" value="Show times">
1756N/A</form>
1756N/A<script class="mine" src="/build/yui/yui.js"></script>
1756N/A<script class="mine">
1756N/A// watch typing events, log "fetch" signals
1756N/AYUI({
1756N/A debug: true,
1756N/A base: "/build/",
1756N/A filter: 'raw'
1756N/A}).use(
1756N/A 'node', 'console', 'console-filters', "datasource",
3863N/A 'log', 'pluginhost', 'node-pluginhost', function (Y) {
1756N/A
1756N/A Y.one = Y.one || Y.get;
1756N/A
3863N/A new Y.Console({
1756N/A plugins : [ Y.Plugin.ConsoleFilters ],
1756N/A newestOnTop : false,
1756N/A useBrowserConsole : true
1756N/A }).render();
1756N/A
1756N/A // Create a very demonstrative plugin.
1756N/A
1756N/A function DemoPlugin () {
1756N/A Y.log("Starting DemoPlugin ctor, about to call parent ctor");
1756N/A DemoPlugin.superclass.constructor.apply(this, arguments);
1756N/A Y.log("Done with DemoPlugin ctor, returning");
1756N/A };
1756N/A
1756N/A // define attributes as static properties on the class.
1756N/A DemoPlugin.ATTRS = {
1756N/A onlyForReading : {
1756N/A value : "cannot be changed",
1756N/A readOnly : true
1756N/A },
1756N/A hasGetter : {
1756N/A getter : function () {
1756N/A Y.log("Get the 'hasGetter' property");
1756N/A return "got";
1756N/A }
1756N/A },
1756N/A hasSetter : {
1756N/A setter : function (k) {
1756N/A Y.log("Setting the 'hasSetter' property to "+k);
1756N/A Y.log("About to return " + (k+k));
1756N/A return k + k;
1756N/A }
1756N/A },
1756N/A simpleValue : {
3863N/A value : "simple"
3863N/A },
1756N/A hasGetterAndSetter : {
1756N/A getter : function () {
3863N/A Y.log("Get on hasGetterAndSetter");
1756N/A return "Return from get";
1756N/A },
1756N/A setter : function () {
1756N/A Y.log("Set on hasGetterAndSetter");
1756N/A return "Return from set";
1756N/A }
1756N/A },
1756N/A incrementor : (function () {
1756N/A var i = 0;
3863N/A return {
3863N/A getter : function () {
1756N/A Y.log("Getting incrementor: "+i);
1756N/A return i ++;
1756N/A },
1756N/A setter : function (j) {
1756N/A Y.log("Setting incrementor: "+j);
1756N/A return i = j;
3863N/A }
1756N/A };
1756N/A })()
1756N/A };
1756N/A Y.extend(DemoPlugin, Y.Plugin.Base, {
1756N/A _privateMember : "pretend-private",
1756N/A _privateMethod : function () {
1756N/A Y.log("Called _privateMethod (which is only pretend-private.)");
1756N/A },
1756N/A publicMember : "public",
1756N/A publicMethod : function () {
1756N/A Y.log("Called publicMethod");
1756N/A },
1756N/A getTheHost : function () {
1756N/A Y.log("My host is: "+this.get("host"));
1756N/A return this.get("host");
1756N/A },
1756N/A initializer : function (config) {
1756N/A Y.log("Initializing: "+config);
1756N/A this._privateMethod();
1756N/A Y.log("Done initializing");
1756N/A }
1756N/A });
1756N/A
1756N/A DemoPlugin.NAME = "demoName";
1756N/A DemoPlugin.NS = "demoNS";
1756N/A
1756N/A Y.namespace("Plugin").DemoPlugin = DemoPlugin;
1756N/A
1756N/A // Now let's plug it into something.
1756N/A
1756N/A window.myNode = Y.one("#ac");
1756N/A myNode.plug(Y.Plugin.DemoPlugin);
1756N/A
1756N/A myNode.demoNS.set("hasSetter", 10);
1756N/A Y.log("getting hasGetter: "+myNode.demoNS.get("hasGetter"));
1756N/A
1756N/A Y.log("Incrementor: "+myNode.demoNS.get("incrementor"));
1756N/A Y.log("Incrementor: "+myNode.demoNS.get("incrementor"));
1756N/A Y.log("Incrementor: "+myNode.demoNS.get("incrementor"));
1756N/A Y.log("Incrementor: "+myNode.demoNS.get("incrementor"));
1756N/A
1756N/A myNode.demoNS.set("hasGetterAndSetter", 10);
1756N/A Y.log("now getting... "+myNode.demoNS.get("hasGetterAndSetter"));
1756N/A
1756N/A myNode.demoNS.getTheHost().set("className", "demoified");
1756N/A
1756N/A Y.log("My eyes! Ze underscores do nussing! "+myNode.demoNS._privateMember);
1756N/A Y.log("Not get()able, since it's not an ATTR: "+myNode.demoNS.get("_privateMember"));
1756N/A Y.log("Get it out in the open: "+myNode.demoNS.publicMember);
3863N/A Y.log("Not get()able, since it's not an ATTR: "+myNode.demoNS.get("publicMember"));
1756N/A
1756N/A myOtherNode = Y.one("#log");
1756N/A Y.log("Hasn't been plugged, so demoNS on other node is: "+myOtherNode.demoNS);
1756N/A myOtherNode.plug(Y.Plugin.DemoPlugin);
3863N/A Y.log("Now it's been plugged, so: "+myOtherNode.demoNS);
3863N/A});
1756N/A
1756N/A</script>
1756N/A</body>
1756N/A</html>
3863N/A