123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- if(!dojo._hasResource["dojox.image.Lightbox"]){
- dojo._hasResource["dojox.image.Lightbox"] = true;
- dojo.provide("dojox.image.Lightbox");
- dojo.experimental("dojox.image.Lightbox");
- dojo.require("dojo.window");
- dojo.require("dijit.Dialog");
- dojo.require("dojox.fx._base");
- dojo.declare("dojox.image.Lightbox",
- dijit._Widget, {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- group: "",
-
-
- title: "",
-
-
- href: "",
-
-
-
- duration: 500,
-
-
-
-
- modal: false,
-
-
- _allowPassthru: false,
-
-
-
- _attachedDialog: null,
- startup: function(){
- this.inherited(arguments);
-
- var tmp = dijit.byId('dojoxLightboxDialog');
- if(tmp){
- this._attachedDialog = tmp;
- }else{
-
- this._attachedDialog = new dojox.image.LightboxDialog({ id: "dojoxLightboxDialog" });
- this._attachedDialog.startup();
- }
- if(!this.store){
-
- this._addSelf();
- this.connect(this.domNode, "onclick", "_handleClick");
- }
- },
- _addSelf: function(){
-
- this._attachedDialog.addImage({
- href: this.href,
- title: this.title
- }, this.group || null);
- },
- _handleClick: function(/* Event */e){
-
- if(!this._allowPassthru){ e.preventDefault(); }
- else{ return; }
- this.show();
- },
- show: function(){
-
- this._attachedDialog.show(this);
- },
-
- hide: function(){
-
- this._attachedDialog.hide();
- },
-
- disable: function(){
-
- this._allowPassthru = true;
- },
- enable: function(){
-
- this._allowPassthru = false;
- },
-
- onClick: function(){
-
-
- },
-
- destroy: function(){
- this._attachedDialog.removeImage(this);
- this.inherited(arguments);
- }
- });
- dojo.declare("dojox.image.LightboxDialog",
- dijit.Dialog, {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- title: "",
-
-
-
-
-
- inGroup: null,
-
-
- imgUrl: dijit._Widget.prototype._blankGif,
-
-
-
- errorMessage: "Image not found.",
-
-
-
-
- adjust: true,
-
-
-
-
- modal: false,
-
-
- errorImg: dojo.moduleUrl("dojox.image","resources/images/warning.png"),
- templateString: dojo.cache("dojox.image", "resources/Lightbox.html", "<div class=\"dojoxLightbox\" dojoAttachPoint=\"containerNode\">\n\t<div style=\"position:relative\">\n\t\t<div dojoAttachPoint=\"imageContainer\" class=\"dojoxLightboxContainer\" dojoAttachEvent=\"onclick: _onImageClick\">\n\t\t\t<img dojoAttachPoint=\"imgNode\" src=\"${imgUrl}\" class=\"dojoxLightboxImage\" alt=\"${title}\">\n\t\t\t<div class=\"dojoxLightboxFooter\" dojoAttachPoint=\"titleNode\">\n\t\t\t\t<div class=\"dijitInline LightboxClose\" dojoAttachPoint=\"closeButtonNode\"></div>\n\t\t\t\t<div class=\"dijitInline LightboxNext\" dojoAttachPoint=\"nextButtonNode\"></div>\t\n\t\t\t\t<div class=\"dijitInline LightboxPrev\" dojoAttachPoint=\"prevButtonNode\"></div>\n\t\t\t\t<div class=\"dojoxLightboxText\" dojoAttachPoint=\"titleTextNode\"><span dojoAttachPoint=\"textNode\">${title}</span><span dojoAttachPoint=\"groupCount\" class=\"dojoxLightboxGroupText\"></span></div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n"),
- constructor: function(args){
- this._groups = this._groups || (args && args._groups) || { XnoGroupX:[] };
- },
- startup: function(){
-
-
-
-
-
- this.inherited(arguments);
-
- this._animConnects = [];
- this.connect(this.nextButtonNode, "onclick", "_nextImage");
- this.connect(this.prevButtonNode, "onclick", "_prevImage");
- this.connect(this.closeButtonNode, "onclick", "hide");
- this._makeAnims();
- this._vp = dojo.window.getBox();
- return this;
- },
- show: function(/* Object */groupData){
-
-
-
-
-
-
-
-
- var _t = this;
- this._lastGroup = groupData;
-
-
- if(!_t.open){
- _t.inherited(arguments);
- _t._modalconnects.push(
- dojo.connect(dojo.global, "onscroll", this, "_position"),
- dojo.connect(dojo.global, "onresize", this, "_position"),
- dojo.connect(dojo.body(), "onkeypress", this, "_handleKey")
- );
- if(!groupData.modal){
- _t._modalconnects.push(
- dojo.connect(dijit._underlay.domNode, "onclick", this, "onCancel")
- );
- }
- }
-
- if(this._wasStyled){
-
-
-
- var tmpImg = dojo.create("img", null, _t.imgNode, "after");
- dojo.destroy(_t.imgNode);
- _t.imgNode = tmpImg;
- _t._makeAnims();
- _t._wasStyled = false;
- }
-
- dojo.style(_t.imgNode,"opacity","0");
- dojo.style(_t.titleNode,"opacity","0");
-
- var src = groupData.href;
-
- if((groupData.group && groupData !== "XnoGroupX") || _t.inGroup){
- if(!_t.inGroup){
- _t.inGroup = _t._groups[(groupData.group)];
-
- dojo.forEach(_t.inGroup, function(g, i){
- if(g.href == groupData.href){
- _t._index = i;
-
- }
-
- });
- }
- if(!_t._index){
- _t._index = 0;
- var sr = _t.inGroup[_t._index];
- src = (sr && sr.href) || _t.errorImg;
- }
-
- _t.groupCount.innerHTML = " (" + (_t._index + 1) + " of " + Math.max(1, _t.inGroup.length) + ")";
- _t.prevButtonNode.style.visibility = "visible";
- _t.nextButtonNode.style.visibility = "visible";
- }else{
-
- _t.groupCount.innerHTML = "";
- _t.prevButtonNode.style.visibility = "hidden";
- _t.nextButtonNode.style.visibility = "hidden";
- }
- if(!groupData.leaveTitle){
- _t.textNode.innerHTML = groupData.title;
- }
- _t._ready(src);
- },
-
- _ready: function(src){
-
-
- var _t = this;
-
-
- _t._imgError = dojo.connect(_t.imgNode, "error", _t, function(){
- dojo.disconnect(_t._imgError);
-
- _t.imgNode.src = _t.errorImg;
- _t.textNode.innerHTML = _t.errorMessage;
- });
-
-
- _t._imgConnect = dojo.connect(_t.imgNode, "load", _t, function(e){
- _t.resizeTo({
- w: _t.imgNode.width,
- h: _t.imgNode.height,
- duration:_t.duration
- });
-
- dojo.disconnect(_t._imgConnect);
- if(_t._imgError){
- dojo.disconnect(_t._imgError);
- }
- });
-
- _t.imgNode.src = src;
- },
- _nextImage: function(){
-
- if(!this.inGroup){ return; }
- if(this._index + 1 < this.inGroup.length){
- this._index++;
- }else{
- this._index = 0;
- }
- this._loadImage();
- },
- _prevImage: function(){
-
- if(this.inGroup){
- if(this._index == 0){
- this._index = this.inGroup.length - 1;
- }else{
- this._index--;
- }
- this._loadImage();
- }
- },
- _loadImage: function(){
-
- this._loadingAnim.play(1);
- },
- _prepNodes: function(){
-
- this._imageReady = false;
- if(this.inGroup && this.inGroup[this._index]){
- this.show({
- href: this.inGroup[this._index].href,
- title: this.inGroup[this._index].title
- });
- }else{
- this.show({
- title: this.errorMessage,
- href: this.errorImg
- });
- }
-
- },
- _calcTitleSize: function(){
- var sizes = dojo.map(dojo.query("> *", this.titleNode).position(), function(s){ return s.h; });
- return { h: Math.max.apply(Math, sizes) };
- },
-
- resizeTo: function(/* Object */size, forceTitle){
-
-
- var adjustSize = dojo.boxModel == "border-box" ?
- dojo._getBorderExtents(this.domNode).w : 0,
- titleSize = forceTitle || this._calcTitleSize()
- ;
-
- this._lastTitleSize = titleSize;
-
- if(this.adjust &&
- (size.h + titleSize.h + adjustSize + 80 > this._vp.h ||
- size.w + adjustSize + 60 > this._vp.w
- )
- ){
- this._lastSize = size;
- size = this._scaleToFit(size);
- }
- this._currentSize = size;
-
- var _sizeAnim = dojox.fx.sizeTo({
- node: this.containerNode,
- duration: size.duration||this.duration,
- width: size.w + adjustSize,
- height: size.h + titleSize.h + adjustSize
- });
- this.connect(_sizeAnim, "onEnd", "_showImage");
- _sizeAnim.play(15);
- },
- _scaleToFit: function(/* Object */size){
-
-
-
- var ns = {},
- nvp = {
- w: this._vp.w - 80,
- h: this._vp.h - 60 - this._lastTitleSize.h
- };
-
- var viewportAspect = nvp.w / nvp.h,
- imageAspect = size.w / size.h;
-
- if(imageAspect >= viewportAspect){
- ns.h = nvp.w / imageAspect;
- ns.w = nvp.w;
- }else{
- ns.w = imageAspect * nvp.h;
- ns.h = nvp.h;
- }
-
- this._wasStyled = true;
- this._setImageSize(ns);
- ns.duration = size.duration;
- return ns;
- },
-
- _setImageSize: function(size){
-
- var s = this.imgNode;
- s.height = size.h;
- s.width = size.w;
- },
-
- _size: function(){},
-
- _position: function(/* Event */e){
-
- this._vp = dojo.window.getBox();
- this.inherited(arguments);
-
-
- if(e && e.type == "resize"){
- if(this._wasStyled){
- this._setImageSize(this._lastSize);
- this.resizeTo(this._lastSize);
- }else{
- if(this.imgNode.height + 80 > this._vp.h || this.imgNode.width + 60 > this._vp.h){
- this.resizeTo({
- w: this.imgNode.width, h: this.imgNode.height
- });
- }
- }
- }
- },
- _showImage: function(){
-
- this._showImageAnim.play(1);
- },
- _showNav: function(){
-
- var titleSizeNow = dojo.marginBox(this.titleNode);
- if(titleSizeNow.h > this._lastTitleSize.h){
- this.resizeTo(this._wasStyled ? this._lastSize : this._currentSize, titleSizeNow);
- }else{
- this._showNavAnim.play(1);
- }
- },
- hide: function(){
-
- dojo.fadeOut({
- node: this.titleNode,
- duration: 200,
-
-
- onEnd: dojo.hitch(this, function(){
- this.imgNode.src = this._blankGif;
- })
- }).play(5);
- this.inherited(arguments);
- this.inGroup = null;
- this._index = null;
- },
- addImage: function(child, group){
-
-
-
-
-
-
-
-
-
- var g = group;
- if(!child.href){ return; }
- if(g){
- if(!this._groups[g]){
- this._groups[g] = [];
- }
- this._groups[g].push(child);
- }else{ this._groups["XnoGroupX"].push(child); }
- },
- removeImage: function(/* Widget */child){
-
-
-
-
-
-
- var g = child.group || "XnoGroupX";
- dojo.every(this._groups[g], function(item, i, ar){
- if(item.href == child.href){
- ar.splice(i, 1);
- return false;
- }
- return true;
- });
- },
-
- removeGroup: function(group){
-
- if(this._groups[group]){ this._groups[group] = []; }
- },
- _handleKey: function(/* Event */e){
-
- if(!this.open){ return; }
- var dk = dojo.keys;
- switch(e.charOrCode){
-
- case dk.ESCAPE:
- this.hide();
- break;
- case dk.DOWN_ARROW:
- case dk.RIGHT_ARROW:
- case 78:
- this._nextImage();
- break;
- case dk.UP_ARROW:
- case dk.LEFT_ARROW:
- case 80:
- this._prevImage();
- break;
- }
- },
-
- _makeAnims: function(){
-
-
- dojo.forEach(this._animConnects, dojo.disconnect);
- this._animConnects = [];
- this._showImageAnim = dojo.fadeIn({
- node: this.imgNode,
- duration: this.duration
- });
- this._animConnects.push(dojo.connect(this._showImageAnim, "onEnd", this, "_showNav"));
- this._loadingAnim = dojo.fx.combine([
- dojo.fadeOut({ node:this.imgNode, duration:175 }),
- dojo.fadeOut({ node:this.titleNode, duration:175 })
- ]);
- this._animConnects.push(dojo.connect(this._loadingAnim, "onEnd", this, "_prepNodes"));
- this._showNavAnim = dojo.fadeIn({ node: this.titleNode, duration:225 });
- },
-
- onClick: function(groupData){
-
- },
-
- _onImageClick: function(e){
- if(e && e.target == this.imgNode){
- this.onClick(this._lastGroup);
-
-
- if(this._lastGroup.declaredClass){
- this._lastGroup.onClick(this._lastGroup);
- }
- }
- }
- });
- }
|