Skip to content

Instantly share code, notes, and snippets.

@joerussbowman
Created October 20, 2010 17:39
Show Gist options
  • Save joerussbowman/636908 to your computer and use it in GitHub Desktop.
Save joerussbowman/636908 to your computer and use it in GitHub Desktop.
trying to figure out global events with yui3
YUI().use('cookie', 'io-base','json-parse', 'event-custom', function(Y) {
var cookieDate = new Date();
cookieDate.setMinutes(cookieDate.getMinutes() + 30);
function locationComplete(id, o) {
var data = Y.JSON.parse(o.responseText);
if (data.error == 0) {
Y.Cookie.set("fwixid", data.result.id, { expires: cookieDate });
Y.Cookie.set("fwixpretty", data.result.pretty, { expires: cookieDate });
} else {
Y.Cookie.set("fwixid", "noid", { expires: cookieDate });
}
var publisher = new Y.EventTarget();
publisher.name = 'geo publisher';
publisher.publish('global:gotgeo', {
broadcast: 2, // global level notification
emitFacade: true // emit a facade so we get the event target
});
}
if (Y.Cookie.get("fwixid") == null) {
yqlgeo.get('visitor',function(o){
Y.Cookie.set("lat", o.place.centroid.latitude, { expires: cookieDate });
Y.Cookie.set("lon", o.place.centroid.longitude, { expires: cookieDate });
Y.on('io:complete', locationComplete, Y);
Y.io('/_loc/');
});
}
});
YUI().use('event-custom', 'node', 'cookie', function(Y) {
var localtab = Y.one("#local_tab");
if (localtab == null) {
// alert('listening for gotgeo');
var tabs = Y.one('#maintabs');
Y.Global.on('global:gotgeo', function() {
alert('fired');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment