Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Full screen slideshow viewer
marty1101
#1 Posted : Tuesday, 7 April 2009 7:09:45 PM(UTC)
Rank: Advanced Member

Joined: 4/01/2009(UTC)
Posts: 37
Location: Taipei, Taiwan

I'm planning to add a full screen slideshow function to GSP. The current slideshow function works fine, but I would like to see the slideshow in another page with only the photos and to have more control options. This would be for images only.

I checked two sites and made some notes. So far, I don't know which is better (AJAX or Flash). If someone reviousely made similar attemps, please share with me. Thanks!

My note :
Quote:

. Where to put the link?
. Use Ajax, Flash, or ?
. Slideshow the current album's photos
. Slideshow the current album's photos and all its child albums' photos
. Slideshow sorted Seq
. Repeat? as an option?
. Change the slideshow duration during play
. No post back (avoid page reload)

Observations from other sites:
Quote:

. Wretch.cc (javascript) [http://www.wretch.cc/album/show.php?i=clickjia&b=61&f=1420785924&p=0&e#et]
___. Pause/Play
___. Interval: 2-?? sec
___. Keyboard c:next, x:previous
___. Popup photo page
___. Next, Previous
___. no Back to Album, because it's a pop-up new window
. Flickr slideshow player (Flash) [http://www.flickr.com/photos/hello-peggy/]
___. Full Screen mode
___. Mouse click on photo
______. Previous
______. Turn photo info on/off
______. Next
___. Thumbnails on the bottom
___. Back
___. Next, Previous
___. Show info
___. Option
______. Always show title and subscription
______. Play backwards
______. Interval: slow, midium, fast
______.Embiggen small things to fill screen
______. Keyboard shortcut
_________p: open photo page
_________m: open stream page
_________i: info on/off
_________left: previous
_________right: next
_________up: hide info
_________down: show info
_________Space: play pause
_________< & >: scroll description

Roger Martin
#2 Posted : Wednesday, 8 April 2009 10:58:07 AM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,301
Location: Fort Atkinson, WI

My feeling is that this would best be implemented as a top-level user control that can be inserted into a web page, just like the current Gallery user control. (Quick refresher - GSP has a couple dozen user controls, but all are are dynamically loaded into a single "top-level" user control defined in /CodeFiles/Gallery.cs.)

In other words, copy the current Gallery.cs class and give it a new name (e.g. GallerySlideShow). Then modify the code in this class to dynamically load a new user control you build (place it in the /pages/ directory and call it perhaps SlideShow.ascx). To build SlideShow.ascx you could start with mediaobject.ascx and modify it to suit your needs (as this control is close to what you want). Notice that mediaobject.ascx inherits the GalleryPage base user control - make sure to follow this model as this will give you a lot of built-in functionality unique to GSP.

I have nothing against Flash except one thing - I can't program it, and therefore I can't support it. That means I won't include it in a GSP release. If you build it like I outlined above, it will fit nicely into the existing architecture and I would like to incorporate it. (There are many ways to slice and dice GSP functionality into several top-level user controls that give developers more options - imagine a random image viewer, single media object viewer, etc.)

So for that reason and the simple fact that much of the coding is already done I recommend AJAX. The next/previous buttons and the slideshow function use AJAX to retrieve the desired media object.

Hope this helps. Let me know if there is anything else I can do to help. And thanks for pitching in!
Roger Martin
Creator and Lead Developer of Gallery Server Pro
marty1101
#3 Posted : Thursday, 9 April 2009 1:59:10 AM(UTC)
Rank: Advanced Member

Joined: 4/01/2009(UTC)
Posts: 37
Location: Taipei, Taiwan

Thank you so much for pointint the direction! I tried it today. There're many things I'm not sure of. Let me try to describe it:

1. The origional MediaObjectView slideshows from the current object to the last one in the album. Is it easy to modify this behavior to achieve slideshowing random, sorted, all photos in the current and sub-albums? and even with whatever selected photos (maybe from a web service)?

2. I have modified GSP to only display external photos. The concept might be different when considering more client-load design. I mean. To the extreme, I can put all urls on the first load and avoid postbacks to the server during slideshow. This's only a quick thought. I'm not sure how to implement it yet.

3. I had some problem dealing with GalleryPage in [\gs\pages\slideshow.ascx.cs], when I inherit GalleryPage, the galleryheader would show at least the [All Album/Album 1/Album1-1 ....], so I tried to inherit System.Web.UI.UserControl, then I lost the convenience of using GalleryPage ........ it took me a long time. Many problems happened in \CodeFiles\BaseUserControl.cs (I think it came from usercontrols in \gs\controls\slideshow.ascx.cs [from mediaobjectview.ascx.cs]
Code:

    public class BaseUserControl : UserControl
    {
        public Pages.GalleryPage GalleryPage
        {
            get
            {
                System.Web.UI.Control ctl = Parent;
                System.Web.UI.Control tempControl = this;
                while (ctl.GetType() != typeof(Gallery))
                {
                    tempControl = ctl;
                    ctl = ctl.Parent;
                }

                return (Pages.GalleryPage)tempControl;
            }
        }

It loops to find the control's parent until Gallery, but there is no Gallery because GallerySlideShow (GallerySlideShow.cs) is the top-level usercontrol. Where in slideshow.ascx.cs didn't I modify?

Do I need to have a GallerySlideShowPage.cs [like GalleryPage.cs]?

4. My current thinking is to have the slideshow link on the album view page. It will slideshow all photos with current sort order, and an option to slideshow sub-albums, and an option to ramdom display. In case there will be pages displays Today's pick, Most popular photos in the last week, Photos in my area .... the slideshow can take these photos as inputs to go through. and if this link is passed around in forums, can it be (allowed) accessed by other people?

It's still too fuzzy at this stage, I need to learn more about GSP and figure out more with the design concept. It is not as easy as I initially thought.

slideshow.aspx [from default.aspx]
Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="slideshow.aspx.cs" Inherits="GalleryServerPro.Web._slideshow" %>

<%@ Register TagPrefix="gsp" Namespace="GalleryServerPro.Web" Assembly="GalleryServerPro.Web" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<style type="text/css">
        html, body { margin:0;padding:0; }
        body { background-color:#f5f5f5; }
    </style>
</head>
<body>
<form id="form2" runat="server">
<asp:ScriptManager ID="sm" runat="server" />
<gsp:GallerySlideShow ID="galleryslideshow1" runat="server" />
</form>
</body>
</html>


\CodeFiles\GallerySlideShow.cs [from Gallery.cs]
Code:

using System;
using System.Web.UI;
using GalleryServerPro.Business;

namespace GalleryServerPro.Web
{
/// <summary>
/// The top level user control that acts as a container for other user controls used in Gallery Server Pro.
/// </summary>
[ToolboxData("<{0}:GallerySlideShow runat=\"server\"></{0}:GallerySlideShow>")]
public class GallerySlideShow : UserControl
{
#region Private Fields

private bool? _showLogin;
private bool? _showSearch;

#endregion

#region Constructors

public GallerySlideShow()
{
this.Init += GallerySlideShow_Init;
}

static GallerySlideShow()
{
}

#endregion

#region Event Handlers

void GallerySlideShow_Init(object sender, EventArgs e)
{
// Set up our "global" error handling. Since every page in GSP passes through this event handler, attaching error handling
// code to the page's Error event handler is roughly equivalent to the global error handling in web.config. We prefer to
// set up our error handling this way so as not to interfere with the user's own error handling configuration she may be
// using.
this.Page.Error += GallerySlideShow_Error;

// Check the query string for the desired page and add it to the page's controls.
this.LoadRequestedPage();
}

void GallerySlideShow_Error(object sender, EventArgs e)
{
// Grab a handle to the exception that is giving us grief.
Exception ex = Server.GetLastError();

if (Context != null)
{
if (Context.Error.InnerException != null)
ex = Context.Error.InnerException;
else if (Context.Error.GetBaseException() != null)
ex = Context.Error.GetBaseException();
else
ex = Context.Error;
}

Util.HandleGalleryException(ex);
}

#endregion

#region Public Properties

/// <summary>
/// Indicates whether to show the login controls at the top right of each page. When false, no login controls
/// are shown, but the user can navigate directly to the login page to log on. If not specified, this
/// property inherits the value in the config file.
/// </summary>
/// <value><c>true</c> if login controls are visible; otherwise, <c>false</c>.</value>
//public bool ShowLogin
//{
// get
// {
// if (!_showLogin.HasValue)
// this._showLogin = Util.GetGalleryServerProConfigSection().Core.ShowLogin;

// return _showLogin.Value;
// }
// set
// {
// this._showLogin = value;
// }
//}

/// <summary>
/// Indicates whether to show the search box at the top right of each page. If not specified, this
/// property inherits the value in the config file.
/// </summary>
/// <value><c>true</c> if the search box is visible; otherwise, <c>false</c>.</value>
//public bool ShowSearch
//{
// get
// {
// if (!_showSearch.HasValue)
// this._showSearch = Util.GetGalleryServerProConfigSection().Core.ShowSearch;

// return _showSearch.Value;
// }
// set
// {
// this._showSearch = value;
// }
//}

#endregion

#region Private Methods

private void LoadRequestedPage()
{
// Check query string for a requested page. If present, load up that page. Otherwise, default to the album view.
PageId page;

//string requestedPage = Util.GetQueryStringParameterString("g");

//if (String.IsNullOrEmpty(requestedPage))
//{
// // No 'g' query string parm. Look for 'moid' parameter, which might be present without the 'g' parm if an URL
// // was bookmarked in a version of GSP prior to 2.2.
// if (Util.GetQueryStringParameterInt32("moid") > int.MinValue)
// page = PageId.mediaobject;
// else
// page = PageId.album;
//}
//else
//{
// try
// {
// page = (PageId)System.Enum.Parse(typeof(PageId), requestedPage, true);
// }
// catch (Exception)
// {
// page = PageId.album;
// }
//}

//string src = String.Concat(Util.GalleryRoot, "/pages/", page, ".ascx");
string src = String.Concat(Util.GalleryRoot, "/pages/", "slideshow", ".ascx");
//if (src.IndexOf("/admin_") >= 0)
// src = src.Replace("/admin_", "/admin/");
//if (src.IndexOf("/error") >= 0)
// src = src.Replace("/error_", "/error/");
//if (src.IndexOf("/task_") >= 0)
// src = src.Replace("/task_", "/task/");

try
{
Control control = LoadControl(src);

// If the control is an instance of Pages.GalleryPage, then assign its GalleryPage property to the current instance.
// This gives the control convenient access to the Page property.

//Pages.GalleryPage galleryControl = control as Pages.GalleryPage;
////Pages.GallerySlideShowPage galleryControl = control as Pages.GallerySlideShowPage;
//if (galleryControl != null)
//{
// galleryControl.GalleryControl = this;
//}

this.Controls.Add(control);
}
catch (System.IO.FileNotFoundException)
{
throw new ApplicationException(String.Format(Resources.GalleryServerPro.Error_Cannot_Load_User_Control_Ex_Msg, src));
}
}

#endregion
}
}


\gs\pages\slideshow.ascx [from mediaobjecview.ascx]
Code:

<!-- Copied and modified from \Website\gs\pages\mediaobject.ascx -->
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="slideshow.ascx.cs" Inherits="GalleryServerPro.Web.gs.pages.slideshow" %>
<%@ Register Src="../controls/slideshow.ascx" TagName="slideshow" TagPrefix="marty1101" %>
<marty1101:slideshow id="slideshow1" runat="server" />


\gs\pages\slideshow.ascx.cs [from mediaobjecview.ascx.cs]
Code:

/// Copied and modified from \Website\gs\pages\mediaobject.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GalleryServerPro.Web.gs.pages
{
//public partial class slideshow : Pages.GalleryPage
public partial class slideshow : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//this.GalleryControl.ShowLogin = false;
//this.GalleryControl.ShowSearch = false;

}
}
}


\gs\controls\slideshow.ascx [from \gs\controls\mediaobjectview.ascx]
Code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="slideshow.ascx.cs" Inherits="GalleryServerPro.Web.Controls.slideshow" %>
................
all below is modified with little changes


\gs\controls\slideshow.ascx.cs [from \gs\controls\mediaobjectview.ascx.cs]
Code:

namespace GalleryServerPro.Web.Controls
{
// public partial class slideshow : System.Web.UI.UserControl
public partial class slideshow : GalleryUserControl
{
.................
all below is modified with little changes
Roger Martin
#4 Posted : Thursday, 9 April 2009 2:34:18 PM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,301
Location: Fort Atkinson, WI

It takes a while to wrap your head around the architecture. I wish I had time to put together a document to make it easier...

Quote:
1. The origonal MediaObjectView slideshows from the current object to the last one in the album. Is it easy to modify this behavior to achieve slideshowing random, sorted, all photos in the current and sub-albums? and even with whatever selected photos (maybe from a web service)?


If by easy, you mean doing it in less than an hour, the answer is probably no. You will need to study the javascript that navigates the objects, such as showNextMediaObject and showPreviousMediaObject. The showNextMediaObject function is automatically invoked every time a slide show moves forward or the user clicks Next. The key AJAX call to the server that retrieves the next or previous media object info is Gsp.Gallery.GetMediaObjectHtml().

The learning curve will go quicker if you have a dev system where you can debug javascript and server code (if not at the same time, at least separately). If you can't debug javascript, stop now and figure out how (VS, IE8, or whatever).

Quote:
2. I have modified GSP to only display external photos.


Good luck with that. I'm afraid I cannot be of much help here.

Quote:
3. I had some problem dealing with GalleryPage


You'll want to modify the GalleryPage property to look for an instance of GallerySlideShow instead:


Code:
public class BaseUserControl : UserControl
{
public Pages.GalleryPage GalleryPage
{
get
{
System.Web.UI.Control ctl = Parent;
System.Web.UI.Control tempControl = this;
while (ctl.GetType() != typeof(GallerySlideShow))
{
tempControl = ctl;
ctl = ctl.Parent;
}

return (Pages.GalleryPage)tempControl;
}
}


Quote:
4. My current thinking is to have the slideshow link on the album view page.


If you want a hyperlink that stores the list of images to display, you need to somehow embed that in the query string. How you do that is up to you, but it could be something like this:

http://www.site.com/gall...lideshow.aspx?photoIDs=3|6|82|294|22|187

(I'm not sure that the pipe character (|) is valid in an URL - you may need to use a dash (-) or something else instead.)

Related to this is the ability for the user control to receive any list of IDs to display. You could add a property to GallerySlideShow that is a List<int> containing all the media object IDs to display.

Hope I answered all your questions...
Roger Martin
Creator and Lead Developer of Gallery Server Pro
marty1101
#5 Posted : Wednesday, 29 April 2009 4:35:27 PM(UTC)
Rank: Advanced Member

Joined: 4/01/2009(UTC)
Posts: 37
Location: Taipei, Taiwan

Finally, I made the slideshow to work. The design didn't follow you suggestion, sorry. It took me several days to try to figure out the relationship among Gallery.cs , GalleryPage.cs , MediaObject.ascx ...... it's too difficult for my current programming capability, but I did learn a lot.

I used part of the suggested archietecture and codes, used javascript to do most work. A slideshow.asmx to feed image urls. This is based on the assumption that to-be-displayed images are external images. and also a modified database table and mediaobject properties ...

After loading image urls from slideshow.asmx , the browser makes no request to the server while the user doing operations on the page (pre, next, pause, play, increase/decrease sec ... etc). This is my first javascript practice. The user experience is not as good as Flickr's flash slideshow. For example, Flickr's flash slideshow can be embeded in any web site, can be in real fullscreen ... etc. Javascript is limited and hated by browsers somehow; and sometimes it needs different codes for different browsers; and also it can be blocked by browsers by default.

slideshow.aspx.cs
Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using GalleryServerPro.Business;
using GalleryServerPro.Business.Interfaces;
using GalleryServerPro.Configuration;
using GalleryServerPro.ErrorHandler.CustomExceptions;
using GalleryServerPro.Web.Entity;
using GalleryServerPro.Web;
using marty1101.GSP;
using marty1101.WebControls;

namespace GalleryServerPro.Web.Controls
{
public partial class slideshow : System.Web.UI.UserControl
{
#region Private Fields

private IAlbum _album;
private Message _message = Message.None;
private IGalleryServerRoleCollection _roles;
private string _pageTitle = String.Empty;
private bool? _isAnonymousUser;
private int[] _moids = { };
private string _ReferringUrl = string.Empty;
private static GspUrl.RootAspxPageId _thisAspxPage = GspUrl.RootAspxPageId.SlideShowAspxPage;
private string _galleryAspxPagePathFile = GspUrl.GetRootAspxPagePathFile(_thisAspxPage, GspUrl.RootAspxPageId.GalleryAspxPage);
private bool _includingSubFolders = false;
private string _GspPath = "/album";

// variables for JavaScript use
private bool _autoplay = true; // auto-play at page load
private bool _repeat = true; // repeat slideshow cycle
private int _interval = 4000;
private int _timeout_sec = 30; // if a image is not loaded within, go to the next image.
private int _preload_batch = 3; // At each slide change, we preload 'preload_batch' images more into the browser cache.
private string _progressGifUrl = Util.GalleryRoot + "/images/progressbar.gif";
private string _loadingGifUrl = Util.GalleryRoot + "/images/loading.gif";
private int _topbarMinHeight = 35; // for calculating the image container size
private string _pauseButtonTextPause = Resources.GalleryServerPro.SlideShow_PauseButton_Text_Pause;
private string _pauseButtonTextPlay = Resources.GalleryServerPro.SlideShow_PauseButton_Text_Play;

private string ReferringUrl
{
get
{
if (_ReferringUrl == string.Empty)
return GetReferringUrl();
else
return _ReferringUrl;
}
set { _ReferringUrl = value; }
}

#endregion


#region Private Properties

private bool IsAnonymousUser
{
get
{
if (!this._isAnonymousUser.HasValue)
{
this._isAnonymousUser = !HttpContext.Current.User.Identity.IsAuthenticated;
}
return this._isAnonymousUser.Value;
}
}

private Message Message
{
get
{
if (this._message == Message.None)
{
int msgId = Util.GetQueryStringParameterInt32("msg");
if (msgId > int.MinValue)
{
this._message = (Message)Enum.Parse(typeof(Message), msgId.ToString(CultureInfo.InvariantCulture));
}
}
return this._message;
}
set
{
this._message = value;
}
}

#endregion


#region Public Properties

public virtual string PageTitle
{
get {
if (_album == null)
return Resources.GalleryServerPro.SlideShow_PageTitle;
else
return Util.RemoveHtmlTags(_album.Title);
}
set { this._pageTitle = value; }
}

#endregion


#region Protected Events

protected void Page_PreRender(object sender, EventArgs e)
{
HtmlHead header = this.Page.Header;
if (header == null)
throw new WebException(Resources.GalleryServerPro.Error_Head_Tag_Missing_Server_Attribute_Ex_Msg);
SetupHeadControl(header);
}

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("class", "gsp_ns"); // gsp_ns stands for Gallery Server Pro namespace
writer.RenderBeginTag(HtmlTextWriterTag.Div);
base.Render(writer);
writer.RenderEndTag();
}

protected string GetReferringUrl()
{
return ParseReferringUrl(Util.GetQueryStringParameterString("ReturnUrl"));
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowWarningPanel(false);
ReferringLB.PostBackUrl = ReferringUrl;
ReferringLB.ToolTip = Resources.GalleryServerPro.SlideShow_ReferringUrl_Tooltip;
LogoIB.PostBackUrl = _galleryAspxPagePathFile;
LoadingImageDiv.Style.Add(HtmlTextWriterStyle.BackgroundImage, _loadingGifUrl);
MinusButton.ToolTip = Resources.GalleryServerPro.SlideShow_MinusButton_Tooltip;
PlusButton.ToolTip = Resources.GalleryServerPro.SlideShow_PlusButton_Tooltip;
PreviousButton.ToolTip = Resources.GalleryServerPro.SlideShow_PreviousButton_Tooltip;
PauseButton.ToolTip = Resources.GalleryServerPro.SlideShow_PauseButton_Tooltip;
NextButton.ToolTip = Resources.GalleryServerPro.SlideShow_NextButton_Tooltip;

string mode = Util.GetQueryStringParameterString("mode");
switch (mode)
{
default:
{
_album = GetAlbum();
AlbumMode_Validate();

if (_album != null)
{
AlbumLB.Text = _album.Title;
AlbumLB.PostBackUrl = _galleryAspxPagePathFile + "?g=album&aid=" + _album.Id.ToString();

if (Util.GetQueryStringParameterBoolean("sub") == true)
_includingSubFolders = true;
else
_includingSubFolders = false;

Gsp.SlideShow s = new Gsp.SlideShow();
int[] moids = s.GetMOIDs(_album.Id, _includingSubFolders);
if (moids != null)
{
if (moids.Length > 0)
{
if (Util.GetQueryStringParameterBoolean("autoplay") == false)
{ _autoplay = false; }
else
{ _autoplay = true; }
RegisterJavaScript(_album.Id);
}
else
{
ShowErrorMessage(Message.MediaObjectDoesNotExist);
}
}
}
break;
}
}

}
}

#endregion


#region Protected Methods

[DataObjectMethod(DataObjectMethodType.Select)]
protected IGalleryServerRoleCollection GetGalleryServerRolesForUser()
{
if (this._roles == null)
{
this._roles = Util.GetRolesForUser();
}

return this._roles;
}

[DataObjectMethod(DataObjectMethodType.Select)]
protected static IGalleryServerRoleCollection GetGalleryServerRoles()
{
return Factory.LoadGalleryServerRoles();
}

protected string ParseReferringUrl(string ReferringUrl)
{
ReferringUrl = Server.UrlDecode(ReferringUrl);
try
{ Uri ReturnUri = new Uri(ReferringUrl); }
catch (Exception ex)
{
ReferringUrl = _galleryAspxPagePathFile + "?g=album";
}

return ReferringUrl;
}

protected string ParseReturnUrl(string ReturnUrl)
{
try
{ Uri ReturnUri = new Uri(ReturnUrl); }
catch (Exception ex)
{
ReturnUrl = _galleryAspxPagePathFile + "?g=album";
}

return Server.UrlEncode(ReturnUrl);
}

protected void RedirectToLoginPage()
{
string ReturnUrl = (HttpContext.Current.Request.Url).AbsoluteUri;
ReturnUrl = ParseReturnUrl(ReturnUrl);

// This is GSP's login page
//string url = string.Format("{0}?g={1}&ReturnUrl={2}", _galleryAspxPagePathFile, PageId.login, ReturnUrl);

// This is CS2008.5's login page
string LoginUrl = HttpContext.Current.Request.FilePath; // http://localhost:16800/GSP_Source/album/slideshow.aspx
LoginUrl = LoginUrl.Replace(GspUrl.GetRootAspxFilename(_thisAspxPage), ""); // http://localhost:16800/GSP_Source/album/
LoginUrl = LoginUrl.Replace(_GspPath, ""); // http://localhost:16800/GSP_Source/
LoginUrl = LoginUrl + "login.aspx?ReturnUrl=" + ReturnUrl; // http://localhost:16800/GSP_Source/login.aspx?ReturnUrl= +ReturnUrl

System.Web.HttpContext.Current.Response.Redirect(LoginUrl, true);
}

protected void AlbumMode_Validate() //If no error, no redirect happens, and we get a viewable _album
{
if (!Util.GetGalleryServerProConfigSection().Core.AllowAnonymousBrowsing && this.IsAnonymousUser)
{ // when AllowAnonymousBrowsing=false AND user is not logged in, redirect to login page
RedirectToLoginPage();
}
else
{ // no matter if the user is logged in or not, permission has to be checked to see if this album is viewable by this user.
if (_album == null)
{
ShowErrorMessage(Message.AlbumDoesNotExist);
}
else
{
if (!Util.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, GetGalleryServerRolesForUser(), _album.Id, _album.IsPrivate))
{
if (IsAnonymousUser) // If this album can not be view by anonymous, direct to login page.
{
RedirectToLoginPage();
}
else // This use is logged in, but has no permission to view this album.
{
ShowErrorMessage(Message.InsufficientPermissionCannotViewAlbum);
}
}
}
}
}

protected void ShowWarningPanel(bool show)
{
if (show)
{
Panel1.Visible = false;
TopbarRightPanel.Visible = false;
WarningPanel.Visible = true;
}
else
{
Panel1.Visible = true;
TopbarRightPanel.Visible = true;
WarningPanel.Visible = false;
}
}

protected void ShowErrorMessage(Message err)
{
ShowWarningPanel(true);
switch (err)
{
case Message.AlbumDoesNotExist:
{
WarningLabel.Text = Resources.GalleryServerPro.SlideShow_ErrorMessage_AlbumDoesNotExist;
break;
}
case Message.InsufficientPermissionCannotViewAlbum:
{
WarningLabel.Text = Resources.GalleryServerPro.SlideShow_ErrorMessage_InsufficientPermissionCannotViewAlbum;
break;
}
case Message.MediaObjectDoesNotExist:
{
WarningLabel.Text = Resources.GalleryServerPro.SlideShow_ErrorMessage_MediaObjectDoesNotExist;
break;
}
default:
{
WarningLabel.Text = Resources.GalleryServerPro.SlideShow_ErrorMessage_UnhandledError;
break;
}
}
}

private void SetupHeadControl(HtmlHead head)
{
if (String.IsNullOrEmpty(head.Title))
head.Title = PageTitle;
head.Controls.Add(MakeStyleSheetControl(Util.GetUrl("/styles/slideshow.css")));
}

protected void RegisterJavaScript(int aid)
{

string scriptUrl1 = Util.GetUrl("/script/jquery-1.3.2.js");
string scriptUrl2 = Util.GetUrl("/script/marty1101.js");
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
            if (sm != null)
{
                sm.Scripts.Add(new ScriptReference(scriptUrl1));
                sm.Scripts.Add(new ScriptReference(scriptUrl2));
}
            else
                throw new WebException("Slideshow requires a ScriptManager on the page.");

string script = string.Empty;

/// ================
/// Initial set-up
/// ================
script = string.Format(CultureInfo.InvariantCulture, @"
var PhotoClientID = '{0}';
var LoadingImageDivClientID = '{1}';
var topbar_minHeight = {2};
var image_control = document.getElementById(PhotoClientID);
var windowInnerSize = GetWindowInnerSize();

function ShowProgressBar(show)
{{
var progressDiv = document.getElementById('progressDiv');
if (show)
progressDiv.style.display = '';
else
progressDiv.style.display = 'none';
}}

function ShowPhoto(show)
{{
if (show)
image_control.style.display = '';
else
image_control.style.display = 'none';
}}

ShowProgressBar(true);
ShowPhoto(false);

if (windowInnerSize.width < screen.availWidth*0.93 || windowInnerSize.height < screen.availHeight*0.8)
MaximizeWindow();
"
, Photo.ClientID // 0
, LoadingImageDiv.ClientID // 1
, _topbarMinHeight // 2
);

/// ================================
/// call Gsp.SlideShow Web Service
/// ================================
script += string.Format(CultureInfo.InvariantCulture, @"
var aid = {0};
var includingSubFolders = {1};
var _moids;
var _moObjects;
var errMediaObjectDoesNotExist = '{2}';
var errConnection = '{3}';

Gsp.SlideShow.GetMOIDs(aid, includingSubFolders, GetMOIDsCompleted, GetMOIDsFailure);

function GetMOIDsCompleted(results, context, methodName)
{{
_moids = results;
if (_moids == null)
{{ alert(errMediaObjectDoesNotExist); }}
else
{{
Gsp.SlideShow.GetImages(_moids, GetImagesCompleted, GetImagesFailure);
}}
}}

function GetMOIDsFailure(error, context, methodName)
{{
// alert(""GetMOIDs() "" + error.get_exceptionType() + "": "" + error.get_message());
alert(errConnection);
}}

function GetImagesCompleted(results, context, methodName)
{{
_moObjects = results;
slideshow_init();
}}

function GetImagesFailure(error, context, methodName)
{{
// alert(""GetImages() "" + error.get_exceptionType() + "": "" + error.get_message());
alert(errConnection);
}}
"
, _album.Id // 0
, _includingSubFolders.ToString().ToLower() // 1
, Resources.GalleryServerPro.SlideShow_ErrorMessage_AlbumDoesNotExist // 2
, Resources.GalleryServerPro.SlideShow_ErrorMessage_NetworkError // 3
);
ScriptManager.RegisterStartupScript(this, this.GetType(), "call_Gsp.SlideShow_webservice" + Guid.NewGuid().ToString(), script, true);

/// ===============================
/// jQuery_preloadImages function
/// ===============================
script = string.Format(CultureInfo.InvariantCulture, @"
jQuery.preloadImages = function()
{{
for(var i = 0; i<arguments.length; i++)
{{ jQuery('<img>').attr('src', arguments[i]); }}
}}
");
ScriptManager.RegisterStartupScript(this, this.GetType(), "jQuery_preloadImges" + Guid.NewGuid().ToString(), script, true);

/// ==========================
/// SlideShow Initialization
/// ==========================
script = string.Format(CultureInfo.InvariantCulture, @"
// Set global variables
var GalleryAspxFilePath = '{0}';
var play = {1};
var interval = {2};
var loadingGifUrl = '{3}';
var repeat = {4};
var timeout_sec = {5};
var referringUrl = '{6}';
var PauseButtonTextPause = '{7}';
var PauseButtonTextPlay = '{8}';
var MinusButtonClientID = '{9}';
var PlusButtonClientID = '{10}';
var PreviousButtonClientID = '{11}';
var PauseButtonClientID = '{12}';
var NextButtonClientID = '{13}';
var slide_index = 0;
var still_loading = false;
var NumberOfCheckingLoadingFailed = 0;
var NumberOf_moObjects = 0;
var intervalID;
var preloaded = new Array();
var preload_index = 1;
var preload_batch = {14};

function slideshow_init()
{{
document.onkeydown = KeyDownHandler;

if (_moObjects == null) // If there is no image, stop @here
{{
alert(errMediaObjectDoesNotExist);
}}
else
{{
image_control.onload = function() {{ still_loading = false; }} // This tells if a image is completed loaded.
ShowIntervalSecond(interval);

still_loading = false;
NumberOf_moObjects = _moObjects.length;
SetPauseButtonText(play);

for (i = 0; i < NumberOf_moObjects; i++)
{{
preloaded[i] = false;
}}

//CalculateContainerSize(); // Get sizes of the current window.
ShowFirstImage(); // Starts cycle
}}
}}

function ShowIntervalSecond(i)
{{
document.getElementById('Interval_text').innerHTML = roundNumber(i / 1000, 0);
}}

function PreLoadImages(_moObjects, start_index, end_index)
{{
if (end_index >= NumberOf_moObjects) {{ end_index = NumberOf_moObjects-1; }}
if (start_index <= end_index)
{{
for (i = start_index; i <= end_index; i++)
{{
if (!preloaded[i])
{{
// if (_moObjects[i].ThumbnailUrl != null) {{ $.preloadImages(_moObjects[i].ThumbnailUrl); }}
// else {{ alert('_moObjects[i].ThumbnailUrl is null in function PreLoadImages() !'); }}
if (_moObjects[i].ImageUrl != null) {{ $.preloadImages(_moObjects[i].ImageUrl); }}
// else {{ alert('$.preloadImages(_moObjects[i].ImageUrl is null in function PreLoadImages() !'); }}
preloaded[i] = true;
}}
}}
}}
}}

function SetPauseButtonText(play)
{{
var obj = document.getElementById(PauseButtonClientID);
if (play)
{{
obj.value = PauseButtonTextPause;
obj.style.backgroundColor = '#FA3250';
}}
else
{{
obj.value = PauseButtonTextPlay;
obj.style.backgroundColor = '#99FF99';
}}
}}

function CalculateContainerSize()
{{
var windowInnerSize = GetWindowInnerSize();
container_width = floorNumber(windowInnerSize.width * 0.9 , 0);
container_height = floorNumber((windowInnerSize.height - topbar_minHeight)* 0.9 , 0); //height of the top banner
}}

function StopTimer()
{{
if (intervalID != undefined) {{ clearInterval(intervalID); }}
}}

function RestartTimer()
{{
StopTimer();
if (play) {{ intervalID = setInterval('SlideshowCycle()', interval); }}
}}

function StopSlideshowCycle()
{{
StopTimer();
play = false;
SetPauseButtonText(play);
}}

function ShowCounter(i)
{{
document.getElementById('slideshow_topbar_counter').innerHTML = i + '/' + NumberOf_moObjects;
}}

function RenderImage(_moObject)
{{
if (_moObject == null && !AdvanceSlideIndex(repeat)) {{ StopSlideshowCycle(); }}
else
{{
ShowCounter(slide_index+1);
// CalculateContainerSize();
// display_width = _moObject.ImageWidth;
// display_height = _moObject.ImageHeight;

// if (display_width > container_width)
// {{
// display_height = floorNumber( display_height * (container_width / display_width) , 0);
// display_width = container_width;
// }}
//
// if (display_height > container_height)
// {{
// display_width = floorNumber( display_width * (container_height / display_height) , 0);
// display_height = container_height;
// }}

still_loading = true;
image_control.alt = _moObject.Title;
image_control.src = _moObject.ImageUrl;
// image_control.width = display_width;
// image_control.height = display_height;

document.getElementById('Title').innerHTML = _moObject.Title;
document.getElementById('moidUrl').href = GalleryAspxFilePath + ""?g=mediaobject&moid="" + _moObject.moid;

if (slide_index > preload_index)
{{
var start_index = slide_index - preload_batch;
if (start_index <= 0) {{ start_index = 0; }}
var end_index = slide_index + preload_batch;
if (end_index > NumberOf_moObjects-1) {{ end_index = NumberOf_moObjects-1}}
PreLoadImages(_moObjects, start_index, end_index);
}}

if (preload_index < NumberOf_moObjects)
{{
preload_index += preload_batch;
PreLoadImages(_moObjects, preload_index-preload_batch+1, preload_index);
}}
}}
}}

function ShowFirstImage()
{{
ShowProgressBar(false);
ShowPhoto(true);

slide_index = 0;
RenderImage(_moObjects[slide_index]);
if (NumberOf_moObjects <=1)
SetPauseButtonText(false);
else if (play && NumberOf_moObjects > 2)
{{
NumberOfCheckingLoadingFailed = 0;
RestartTimer();
}}
}}

function SlideshowCycle()
{{
if (NumberOfCheckingLoadingFailed * interval/1000 >= timeout_sec) {{ still_loading = false; }}

if (still_loading) {{ NumberOfCheckingLoadingFailed++; }}
else
{{
NumberOfCheckingLoadingFailed = 0;

if (AdvanceSlideIndex(repeat) && _moObjects[slide_index] != null)
{{ RenderImage(_moObjects[slide_index]); }}
else {{ StopSlideshowCycle(); }}
}}
}}

function AdvanceSlideIndex(repeat)
{{
if (slide_index < NumberOf_moObjects - 1)
{{
slide_index++;
return true;
}}
else
{{
if (repeat)
{{
slide_index = 0;
return true;
}}
else {{ return false; }}
}}
}}

function toggle_pause()
{{
play = !play;
SetPauseButtonText(play);
if (play)
{{
RestartTimer();
}}
else
{{
StopTimer();
}}
}}

function previous_image()
{{
if (NumberOf_moObjects > 0)
{{
StopTimer();
slide_index--;
if (slide_index < 0) {{ slide_index = NumberOf_moObjects - 1; }} //if first image is displayed

RenderImage(_moObjects[slide_index]);
RestartTimer();
}}
}}

function next_image()
{{
if (NumberOf_moObjects > 0)
{{
StopTimer();
slide_index++;
//if last image is reached,display the first image
if (slide_index >= NumberOf_moObjects)
slide_index = 0;

RenderImage(_moObjects[slide_index]);
RestartTimer();
}}
}}

function plus()
{{
if (interval<1000) {{ interval = 1000; }}
else {{ interval += 1000;}}
ShowIntervalSecond(interval);
RestartTimer();
}}

function minus()
{{
if (interval >1000) {{ interval -= 1000; }}
else {{ interval = 400; }}
ShowIntervalSecond(interval);
RestartTimer();
}}

function KeyDownHandler(e)
{{
var ESC = String.fromCharCode(27);
var home = String.fromCharCode(36);
var left = String.fromCharCode(37);
var right = String.fromCharCode(39);
var up = String.fromCharCode(38);
var down = String.fromCharCode(40);
var keychar = GetKBPressedChar(e);
switch(keychar)
{{
case 'M': case home:
OpenNewWindow(referringUrl);
return false; // To disable the default behavior of keydown
break;
case 'X': case left:
previous_image();
break;
  case ' ' :
toggle_pause();
return false; // To disable the default behavior of keydown
break;
  case 'C': case right:
next_image();
break;
case 'E': case up:
plus();
return false; // To disable the default behavior of keydown
break;
case 'D': case down:
minus();
return false; // To disable the default behavior of keydown
break;
case 'B': GoBackReferringUrl(); break;
case ESC: still_loading = false; break;
default: break;
}}
}}

function GoBackReferringUrl()
{{
StopTimer();
window.location = referringUrl;
}}

function OpenNewWindow(url)
{{
newwin = window.open(url, '', 'directories=no, location=yes, resizable=yes, menubar=no, toolbar=no, scrollbars=yes, status=yes');
if (window.focus) {{ newwin.focus(); }}
return false;
}}

function GetKBPressedChar(e)
{{
var keynum;
var keychar;
e = window.event || e;
if(window.event) // IE
{{ keynum = e.keyCode; }}
else if(e.which) // Netscape/Firefox/Opera
{{ keynum = e.which; }}
keychar = String.fromCharCode(keynum);
return keychar;
}}
"
, _galleryAspxPagePathFile // 0
, _autoplay.ToString().ToLower()// 1
, _interval // 2
, _loadingGifUrl // 3
, _repeat.ToString().ToLower() // 4
, _timeout_sec // 5
, ReferringUrl // 6
, _pauseButtonTextPause // 7
, _pauseButtonTextPlay // 8
, MinusButton.ClientID // 9
, PlusButton.ClientID //10
, PreviousButton.ClientID //11
, PauseButton.ClientID //12
, NextButton.ClientID //13
, _preload_batch //14
);

ScriptManager.RegisterStartupScript(this, this.GetType(), "slideshow_control" + Guid.NewGuid().ToString(), script, true);
}

#endregion


#region Private Methods

private static HtmlLink MakeStyleSheetControl(string href)
{
HtmlLink stylesheet = new HtmlLink();
stylesheet.Href = href;
stylesheet.Attributes.Add("rel", "stylesheet");
stylesheet.Attributes.Add("type", "text/css");

return stylesheet;
}

private IAlbum GetAlbum()
{
IAlbum tempAlbum = null;
if (this._album == null)
{
try
{
if (Util.GetQueryStringParameterInt32("aid") > int.MinValue)
{
tempAlbum = Factory.LoadAlbumInstance(Util.GetQueryStringParameterInt32("aid"), true);
}
}
catch (GalleryServerPro.ErrorHandler.CustomExceptions.InvalidAlbumException)
{ tempAlbum = null; }
}

return tempAlbum;
}

#endregion

}
}


Rss Feed  Atom Feed
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.