File "album.js"
Full path: E:/sites/Single15/tinmung2007/webroot/GIADINHTANHIEN/CAC MIEN/PhuocLong/Sept2011/album/res/m/album.js
File size: 9.86 KiB (10100 bytes)
MIME-type:
Charset: utf-8
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function hideURLbar(){
window.scrollTo(0,0);
// $( ".slides" ).show();
if (per_view>1) {
$(".bottom_navigation").css({"visibility":"visible"});
}
$(".slides").css({"visibility":"visible"});
// $(".slides").css({"display":"inline"});
}
function hideURLbarONLY(){
window.scrollTo(0,0);
}
function adjustRatio(ii)
{
if(window.innerHeight > $('#image_'+ii).attr('height'))
{
// $('#image_'+ii).attr('width', 'auto');
// $('#image_'+ii).attr('height', 100);
}
else if(window.innerWidth < $('#image_'+ii).attr('width'))
{
// $('#image_'+ii).attr('width', 100);
// $('#image_'+ii).attr('height', 'auto');
}
}
var ALBUM = function(){
var _P = {
init : function( params ) {
_P.params = params;
_P.loadXml();
},
params : null,
data : null,
loadXml : function() {
$.ajax({
type : "GET",
url : _P.params.xmlPath,
dataType : "xml",
success : function( data ) {
_P.data = data;
if (top != self || per_view === 1) {
per_view = 1;
$(".bottom").css({"height":window.innerHeight-20});
$("#album").css({"width":window.innerWidth-20});
$(".slides").css({"width":window.innerWidth-20});
$("p").css({"width":Math.round((window.innerHeight-110)/3*4)});
$(".bottom_navigation").css({"display":"none"});
}
_P.amount = per_view;
document.title = $(data).find("title:first").text();;
_P.count = $( "slide", data ).length;
_P.loadSlides();
_P.initNavigation();
}
});
},
first : 0,
amount : 0,
count : 0,
last : 0,
current : 0,
images_width : 460,
images_created : 0,
loadSlides : function(action) {
if (action == "next") {
_P.current += _P.amount;
// window.scrollTo(0,0);
} else if (action == "previous") {
_P.current -= _P.amount;
}
first_image = _P.current;
last = parseInt(first_image)+parseInt(_P.amount);
if (last > _P.count) {
last = _P.count;
}
if (_P.images_created<1) {
hideURLbarONLY();
$( ".slides" ).empty();
}
var ii = 0;
$( "slide", _P.data ).each(function( i ) {
if (i>=first_image && i<last) {
var title = $.trim( $( "title", this ).text() );
var href = $.trim( $( "description", this ).text() );
var width = $( "image", this ).attr( "width" );
var height = $( "image", this ).attr( "height" );
// sqrt_value = settings.thumb_w*(settings.thumb_w/3*2);
//
//
// var image_sqrt = images[i].thumbh*images[i].thumbw;
// var sqrt_scale = Math.sqrt(sqrt_value/image_sqrt);
// tmpThumbW = Math.round(images[i].thumbw*sqrt_scale);
// tmpThumbH = Math.round(images[i].thumbh*sqrt_scale);
//
// één beeld? dan moet de images_width afhangen van window width..
// van de window width dan maar de hoogte pakken..
// en die hoogte delen door 2 en dan keer 3..
// of.. eigenlijk moet de hoogte nu als uitgangspunt genomen worden?...
// geen oppervlakteonzin?
// hmz.. eerst maar s een eerste variant maken ait..
if (per_view === 1) {
_P.images_width = (window.innerHeight-110)/3*4;
}
//
var sqrt_value = _P.images_width*(_P.images_width/4*3);
//
var image_sqrt = width*height;
var sqrt_scale = Math.sqrt(sqrt_value/image_sqrt);
var the_width = Math.round(width*sqrt_scale);
var the_height = Math.round(height*sqrt_scale);
var slide = $.trim( $( "image", this ).text() );
var the_src = _P.params.slidesPath+slide;
if (the_width>_P.images_width) {
the_width = _P.images_width;
the_height = Math.round(the_width/width*height);
}
//
if (the_height>(window.innerHeight-120) && per_view === 1) {
the_height = (window.innerHeight-120);
the_width = Math.round(the_height/height*width);
}
//
if (_P.images_created<1) {
$( ".slides" ).append([
"<p><img id='image_",ii,"' src='loading.gif' width='",
the_width,
"' height='",
the_height,
"' alt='",
title,
"' /></p>" ].join( "" ));
$('#image_'+ii).attr('src', the_src);
if (per_view === 1) {
$('#image_'+ii).click(function() {
_P.loadSlides( "next" );
return false;
});
}
} else {
// $('#image_'+ii).attr('src', 'loading.gif');
// $('#image_'+ii).attr('src', the_src);
// $('#image_'+ii).attr('width', the_width);
// $('#image_'+ii).attr('height', the_height);
// $( "#album" ).hide();
// $( ".slides" ).hide();
$(".bottom_navigation").css({"visibility":"hidden"});
$(".slides").css({"visibility":"hidden"});
// $(".slides").css({"display":"hidden"});
$('#image_'+ii).attr('src', 'loading.gif');
}
// $('#image_'+ii).attr('src', 'loading.gif');
// $('#image_'+ii).attr('src', the_src);
$('#image_'+ii).attr('width', the_width);
$('#image_'+ii).attr('height', the_height);
adjustRatio(ii);
ii++;
}
});
$( ".status_top" ).empty();
if (per_view>1) {
$( ".status_top" ).append([first_image+1," - ",last," / ",_P.count].join( "" ));
} else {
$( ".status_top" ).append([first_image+1," / ",_P.count].join( "" ));
}
$( ".status_bottom" ).empty();
$( ".status_bottom" ).append([first_image+1," - ",last," / ",_P.count].join( "" ));
if (last == _P.count) {
$( "#album .navigate_next" ).hide();
$( "#album .navigate_bottom_next" ).hide();
} else {
$( "#album .navigate_next" ).show();
$( "#album .navigate_bottom_next" ).show();
}
$(".top_navigation").css({"visibility":"visible"});
if (_P.images_created<1 && per_view>1) {
$(".bottom_navigation").css({"visibility":"visible"});
}
if (first_image == 0) {
$( "#album .navigate_previous" ).hide();
$( "#album .navigate_bottom_previous" ).hide();
} else {
$( "#album .navigate_previous" ).show();
$( "#album .navigate_bottom_previous" ).show();
}
if (_P.images_created>0) {
// window.scrollTo(0,0);
if (per_view === 1) {
hideURLbar();
setTimeout(_P.loadSlidesYes, 30);
} else {
setTimeout(hideURLbar, 150);
setTimeout(_P.loadSlidesYes, 250);
}
}
_P.images_created = 1;
},
loadSlidesYes : function() {
first_image = _P.current;
last = parseInt(first_image)+parseInt(_P.amount);
hidesome = parseInt(first_image)+parseInt(_P.amount);
if (last > _P.count) {
last = _P.count;
}
for( i=0; i < _P.amount; i++){
$('#image_'+i).css({"display":"none"});
}
var ii = 0;
$( "slide", _P.data ).each(function( i ) {
if (i>=first_image && i<last) {
var slide = $.trim( $( "image", this ).text() );
var the_src = _P.params.slidesPath+slide;
$('#image_'+ii).attr('src', the_src);
$('#image_'+ii).css({"display":"inline"});
ii++;
}
});
},
initNavigation : function() {
$( "#album .navigate_next" ).click(function() {
_P.loadSlides( "next" );
return false;
});
$( "#album .navigate_previous" ).click(function() {
_P.loadSlides( "previous" );
return false;
});
//
$( "#album .navigate_bottom_next" ).click(function() {
_P.loadSlides( "next" );
return false;
});
$( "#album .navigate_bottom_previous" ).click(function() {
_P.loadSlides( "previous" );
return false;
});
},
};
return {
init : function( params ) {
_P.init( params );
}
};
}();
// http://stackoverflow.com/questions/1189820/parse-xml-with-jquery
var menu_count = 0;
function parseNode(node) {
var listitems = "";
if ($(node).children().length > 0) {
listitems += "<ul>";
$(node).children().each(function(i) {
// var title = $.trim( $( "title", this ).text() );
var title = $(this).find("title:first").text();
var album = $(this).find("album:first").text();
var link = $(this).find("link:first").text();
var total = $( "album", this ).attr( "total" );
// var title = $(this).attr("title");
// var url = $(this).attr("url");
if (title) {
if (menu_count == 0) {
tmp_title = "<b>" + title + "</b>";
document.title = title;
} else {
tmp_title = "" + title + "";
}
menu_count++;
if (album) {
if (total) {
if (total == "0") {
listitems += "<li>" + tmp_title + "</li>";
} else {
listitems += "<li><a href=\"?album=//" + album + "\">" + tmp_title + " ("+total+")" + "</a></li>";
}
} else {
listitems += "<li><a href=\"?album=//" + album + "\">" + tmp_title + "</a></li>";
}
} else if (link) {
listitems += "<li><a href=\"" + link + "\">" + tmp_title + "</a></li>";
}
}
// if ($(this).children().length > 0) {
if ($( "item", this ).length > 0) {
listitems += parseNode($(this));
}
});
listitems += "</ul>";
}
return listitems;
}
var MENU = function(){
var _M = {
init : function( params ) {
_M.params = params;
_M.loadXml();
},
params : null,
data : null,
loadXml : function() {
$.ajax({
type : "GET",
url : _M.params.xmlPath,
dataType : "xml",
success : function( data ) {
_M.data = data;
_M.buildMenu();
}
});
},
buildMenu : function(action) {
hideURLbarONLY();
$( ".menu" ).empty();
var listitems = "";
var rootNodes = $(_M.data).children();
$(rootNodes).each(function(i) {
listitems += parseNode($(this)[i]);
});
// $('.menu').html(listitems);
if (menu_count > 1) {
$( ".menu" ).append(listitems);
$(".menu").css({"display":"inline"});
} else {
// window.location="album.html?album=//album.xml";
// $( "#album .menu" ).hide();
var album_xml = "../../album.xml";
var slides_path = album_xml.replace("album.xml","");
ALBUM.init({
xmlPath : album_xml,
slidesPath : slides_path
});
}
},
};
return {
init : function( params ) {
_M.init( params );
}
};
}();