среда, 18 июня 2008 г.

Display flickr images using javascript.

Type.registerNamespace("Voodoo");

Voodoo.FlickrImages = function(element) {
Voodoo.FlickrImages.initializeBase(this, [element]);

this._numberOfPages = 0;
this._currentItem = 17;
this._maxItems = 0;
this._xml = null;
}

Voodoo.FlickrImages.prototype = {
initialize: function() {
Voodoo.FlickrImages.callBaseMethod(this, 'initialize');

$addHandler(this._prevButton, 'click', Function.createDelegate(this, this.onPrevButtonClick));
$addHandler(this._nextButton, 'click', Function.createDelegate(this, this.onNextButtonClick));

/// url for getting feeds from flickr with urls and titles to images.
Proxy.GetXml("http://api.flickr.com/services/feeds/photos_public.gne", 600,
Function.createDelegate(this, this.onGetXmlSuccess),
Function.createDelegate(this, this.onGetXmlFailure),
this);
},
dispose: function() {
Voodoo.FlickrImages.callBaseMethod(this, 'dispose');
},

onGetXmlSuccess : function(result, context, methodName) {
this._xml = result;
this._maxItems = this._xml.getElementsByTagName('feed').item(0).childNodes.length - 17 / 2;
this.reloadImage();
},

onGetXmlFailure : function(error) {
},

onPrevButtonClick : function(e) {
if (this._currentItem != 17)
{
this._currentItem -= 2;
this.reloadImage();
}
},

onNextButtonClick : function(e) {
if (this._currentItem != this._maxItems)
{
this._currentItem += 2;
this.reloadImage();
}
},

reloadImage : function() {
this._imagesPanel.innerHTML = "

" + this._xml.getElementsByTagName('feed').item(0).childNodes.item(this._currentItem).childNodes.item(13).textContent + "

";
},

get_ImagesPanel : function() {
return this._imagesPanel;
},
set_ImagesPanel : function(value) {
this._imagesPanel = value;
},

get_PrevButton : function() {
return this._prevButton;
},
set_PrevButton : function(value) {
this._prevButton = value;
},

get_NextButton : function() {
return this._nextButton;
},
set_NextButton : function(value) {
this._nextButton = value;
},

get_NumberOfPages : function() {
return this._numberOfPages;
},
set_NumberOfPages : function(value) {
this._numberOfPages = value;
}
}

Voodoo.FlickrImages.registerClass('Voodoo.FlickrImages', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

Комментариев нет: