orbit-basic/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI.js.erb

278 lines
8.3 KiB
Plaintext
Raw Normal View History

2012-08-28 07:38:35 +00:00
<%# encoding: utf-8 %>
2012-08-20 14:00:57 +00:00
$.extend($.expr[':'], {
'containsi': function (elem, i, match, array) {
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
2012-07-19 07:44:44 +00:00
var galleryAPI = function(){
g = this;
2012-07-25 08:20:07 +00:00
this.urlVars = rcom.getUrlVars();
this.albumArea = $("#orbit_gallery");
2012-08-20 14:00:57 +00:00
this.loadArea = null;
this.tagList = $("ul#gallery_tag_list");
this.loading = $("#loading");
2013-07-17 10:45:44 +00:00
2012-07-25 08:20:07 +00:00
this.loadTheater = function(id){
2013-11-06 07:23:28 +00:00
$( ".breadcrumb li:eq(1) a" ).attr("href","/panel/gallery/back_end/albums");
g.loadstart();
2012-07-29 10:52:30 +00:00
var imageArray;
var imagecount = 0;
var picHeight = 0;
var bindHandlers = function(){
var $slidelist = $('.slidelist'),
$rslide = $('.rslide'),
$rslidenav = $('.rslidenav'),
2012-07-30 17:15:48 +00:00
$img = $("#main_pic img"),
wHeight = $(window).height();
$("#main_pic").height(picHeight);
$img.height("100%");
2012-08-20 14:00:57 +00:00
$('.bt-tag').click(function(){
if(!$(this).hasClass("active"))
updatePhotoTag();
$(this).toggleClass("active");
var $tag_panel = $('#tag_panel'),
tag_panel_position = 0;
2012-07-30 17:15:48 +00:00
2012-08-20 14:00:57 +00:00
if( $tag_panel.css('right') == '0px' ){
tag_panel_position = -200;
}
$tag_panel.animate({'right':tag_panel_position}, 300);
g.albumArea
.delay(200)
.animate({'margin-right':tag_panel_position+200},300);
return false;
});
var updatePhotoTag = function(){
var tags = imageArray[imagecount].tag_ids;
2012-08-23 13:30:37 +00:00
if(tags.length > 0 && g.tagList.find("li").length == 0){
var tagnames = imageArray[imagecount].tag_names;
g.tagList.empty();
for(i in tagnames){
$li = $("<li><label>"+tagnames[i]+"</label><span style='display:none;'>"+tagnames[i]+"</span></li>");
g.tagList.append($li);
}
}else if(tags.length > 0 && g.tagList.find("li").length > 0) {
g.tagList.find("input").attr("checked",false);
for(tag in tags){
g.tagList.find("li[data-content="+tags[tag]+"] input").attr("checked",true);
}
}else if(tags.length == 0){
if(g.tagList.find("input").length == 0)
g.tagList.empty();
else
g.tagList.find("input").attr("checked",false);
2012-08-20 14:00:57 +00:00
}
}
g.albumArea.find("#tag_search_box").keyup(function(e){
sval = $(this).val();
if(sval == "<%= I18n.t('gallery.search_tags') %>")
sval = "";
sval = sval.replace(/(^\s*)|(\s*$)/g,'');
if(sval){
var re1 = new RegExp("^[\u4E00-\uFA29]*$"); //Chinese character range
var re2 = new RegExp("^[\uE7C7-\uE7F3]*$");
if ((re1.test(sval) && (re2.test(sval)))){
2012-08-22 07:59:06 +00:00
$("#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp();
2012-08-20 14:00:57 +00:00
}else{
2012-08-22 07:59:06 +00:00
$("#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp();
2012-08-20 14:00:57 +00:00
}
}else{
2012-08-22 07:59:06 +00:00
$("#gallery_tag_list li").slideDown();
2012-08-20 14:00:57 +00:00
}
})
2012-08-21 05:56:50 +00:00
g.albumArea.find("#tag_panel .bt-save").click(function(){
2012-08-29 09:13:45 +00:00
g.saveTags(imageArray[imagecount]._id,"pic",function(tagids){
imageArray[imagecount].tag_ids = tagids;
2012-08-23 13:30:37 +00:00
})
2012-08-20 14:00:57 +00:00
})
2012-07-29 10:52:30 +00:00
$(".slidectrl a.togglelist").click(function(){
var rslide_h = $rslide.outerHeight();
if ( $slidelist.height() < 1 ){
$slidelist.stop().animate({'height':rslide_h - 30}, 300);
$slidelist.find("ul").show();
} else {
$slidelist.stop().animate({'height':'0px'}, 300);
$slidelist.find("ul").hide();
}
})
2012-08-22 07:59:06 +00:00
$(".slidectrl .togglescreen").click(function(){
2012-07-29 10:52:30 +00:00
toggleFullscreen();
})
2012-08-22 07:59:06 +00:00
$(".slidectrl .browserfullscreen").click(function(){
2012-07-30 17:15:48 +00:00
browserFullScreen();
})
2012-08-22 07:59:06 +00:00
$slidelist.find(".list_element").click(function(){
2012-07-29 10:52:30 +00:00
imagecount = parseInt($(this).parent().attr("for"));
changeImage($(this));
})
2012-08-22 07:59:06 +00:00
$rslidenav.find(".navN").click(function(){
2012-07-29 10:52:30 +00:00
nextpic($(this));
})
$rslidenav.find("a.navP").click(function(){
prevpic($(this));
})
2012-08-22 07:59:06 +00:00
$("#nextpic").click(function(){
2012-07-29 10:52:30 +00:00
nextpic($(this));
})
$(document).keydown(function(e){
if (e.keyCode == 37){
2012-08-22 07:59:06 +00:00
prevpic($rslidenav.find(".navP"));
2012-07-29 10:52:30 +00:00
return false;
}
if(e.keyCode == 39){
2012-08-22 07:59:06 +00:00
nextpic($rslidenav.find(".navN"));
2012-07-29 10:52:30 +00:00
return false;
}
if(e.keyCode == 27){
toggleFullscreen();
2012-08-22 07:59:06 +00:00
$rslide.removeClass('browserFullScreen');
2012-07-29 10:52:30 +00:00
return false;
}
2012-07-30 17:15:48 +00:00
if(e.keyCode == 70 || e.keyCode == 102){
if($rslide.hasClass("fullscreen"))
browserFullScreen();
}
2012-07-29 10:52:30 +00:00
});
2012-07-30 17:15:48 +00:00
var browserFullScreen = function(){
var el = document.documentElement,
rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen;
rfs.call(el);
}
2012-08-23 13:30:37 +00:00
$(window).resize(function(){
if(window.innerWidth == screen.width && window.innerHeight == screen.height) {
$rslide.addClass('browserFullScreen');
} else {
$rslide.removeClass('browserFullScreen');
}
})
2012-07-29 10:52:30 +00:00
var nextpic = function(dom){
if(imagecount == imageArray.length - 1)
imagecount = 0;
else
imagecount++;
changeImage(dom);
}
var prevpic = function(dom){
if(imagecount == 0)
imagecount = imageArray.length - 1
else
imagecount--;
changeImage(dom);
}
var toggleFullscreen = function(){
if($rslide.hasClass("fullscreen")){
$rslide.css("position","relative");
$rslide.removeClass("fullscreen");
2012-08-22 07:59:06 +00:00
$(".slidectrl .browserfullscreen").hide();
2012-07-29 10:52:30 +00:00
$img.css({"padding":""})
2012-07-31 13:15:42 +00:00
$("#main_pic").height(picHeight );
2012-07-29 10:52:30 +00:00
}else{
2012-07-30 17:15:48 +00:00
$("#main_pic").height(wHeight);
// $img.height("100%");
2012-07-29 10:52:30 +00:00
$rslide.css("position","");
$rslide.addClass("fullscreen");
$img.css({"padding":($rslide.height()-$img.height())/2})
2012-08-22 07:59:06 +00:00
$(".slidectrl .browserfullscreen").show();
2012-07-29 10:52:30 +00:00
}
}
var changeImage = function(dom){
var pageurl = dom.attr('href');
2012-08-31 14:01:19 +00:00
2012-07-30 17:15:48 +00:00
$img.fadeOut(200,function(){
g.loadstart();
$img.attr("src","");
$img.attr({"src":dom.attr("data-content"),"height":picHeight+"px"}).load(function(){
$img.fadeIn(200);
g.loadcomplete();
});
2012-07-30 17:15:48 +00:00
if($rslide.hasClass("fullscreen")){
$img.css({"padding":($rslide.height()-$img.height())/2})
}
$slidelist.stop().animate({'height':'0px'}, 300);
$slidelist.find("ul").hide();
2012-08-31 14:01:19 +00:00
if(rcom.getInternetExplorerVersion() == -1){
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
}else{
window.location.hash = pageurl;
}
2012-07-30 17:15:48 +00:00
// $(".slideinfo b.info").text(imageArray[imagecount].title);
2012-08-20 14:00:57 +00:00
if($('.bt-tag').hasClass("active"))
updatePhotoTag();
2013-07-18 09:20:46 +00:00
if(imageArray[imagecount].description)
$(".slideinfo .info").text(imageArray[imagecount].description);
else
$(".slideinfo .info").text("");
2012-07-31 13:15:42 +00:00
if(imageArray.length > 1)
updateNavigation();
2012-07-30 17:15:48 +00:00
})
2012-08-20 14:00:57 +00:00
2012-07-29 10:52:30 +00:00
}
var updateNavigation = function(){
var next, prev;
if(imagecount == 0){
next = 1;
prev = imageArray.length - 1;
}else if(imagecount == imageArray.length - 1){
next = 0
prev = imageArray.length - 2;
}else{
next = imagecount + 1;
prev = imagecount - 1;
}
2012-08-28 13:04:48 +00:00
$(".navN").attr({"href":imageArray[next]._id,"data-content":imageArray[next].file.url});
$(".navP").attr({"href":imageArray[prev]._id,"data-content":imageArray[prev].file.url});
2012-07-29 10:52:30 +00:00
};
2012-07-31 13:15:42 +00:00
if(imageArray.length > 1)
updateNavigation();
2012-07-29 10:52:30 +00:00
}
var preparestage = function(albumid){
2012-08-28 13:04:48 +00:00
$.getJSON("../albums/"+albumid+"/imgs",function(album){
2012-08-20 14:00:57 +00:00
imageArray = eval(album.images);
$.each(album.images,function(i,image){
2012-07-29 10:52:30 +00:00
if(image._id == id)
imagecount = i;
})
bindHandlers();
})
}
2012-08-31 14:01:19 +00:00
if(rcom.getInternetExplorerVersion()!=-1){
var photo_id = window.location.hash.replace("#","");
if(photo_id){
var url = window.location.href;
var params = url.split("/");
// params[params.length-1] = photo_id;
url = url.replace(params[params.length-1],photo_id);
window.location.href = url;
}
2012-08-31 14:01:19 +00:00
}
2012-08-28 13:04:48 +00:00
var albumid = $("#main_pic").attr("data-content");
g.albumArea.find(".bt-back").attr("href","../albums/"+albumid);
g.albumArea.find(".bt-edit").attr("href","../albums/"+albumid+"/edit");
g.albumArea.css("margin-bottom","0");
picHeight = $(window).height() - ($("#orbit-bar").outerHeight() + $("#orbit_gallery .form-actions").outerHeight());
preparestage(albumid);
2012-08-20 14:00:57 +00:00
}
this.loadcomplete = function(){
g.loading.hide();
}
this.loadstart = function(){
g.loading.show();
}
2013-07-17 10:45:44 +00:00
2012-08-20 14:00:57 +00:00
}
galleryAPI.prototype.locale = "en";