From 1825842ad09fed70d902c346ef0ea0bfff5846dd Mon Sep 17 00:00:00 2001 From: manson Date: Mon, 21 Jul 2014 16:28:09 +0800 Subject: [PATCH] Fix backend gallery show page go_back issue and theater exit fullscreen --- app/assets/javascripts/gallery.js | 16 ++++++---------- app/assets/javascripts/galleryAPI.js.erb | 12 +++++++++++- .../javascripts/galleryAPI_frontend.js.erb | 11 ++++++++++- app/controllers/admin/galleries_controller.rb | 19 +++++++++++++------ app/views/admin/galleries/show.html.erb | 4 ++++ config/routes.rb | 4 +++- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/gallery.js b/app/assets/javascripts/gallery.js index 4ab5ac5..81ea973 100644 --- a/app/assets/javascripts/gallery.js +++ b/app/assets/javascripts/gallery.js @@ -145,16 +145,12 @@ $(function() { } } - var photosData = null; if($("#imgholder").length){ - $.getJSON(window.location.pathname, function(json, textStatus) { - photosData = json; - $('.open').pageslide({ - loadComplete: function(instance,elem) { - bindEvent(instance,elem); - } - }) - }); + $('.open').pageslide({ + loadComplete: function(instance,elem) { + bindEvent(instance,elem); + } + }) } @@ -242,7 +238,7 @@ $(function() { var lastid = ( $("li.rgalbum:last").length ? $("li.rgalbum:last").data("image-id") : null), albumid = $("#fileupload_aid").val(); - $.getJSON(window.location.pathname, function(json, textStatus) { + $.getJSON('/admin/galleries/get_photoData_json?id='+albumid, function(json, textStatus) { photosData = json; }); diff --git a/app/assets/javascripts/galleryAPI.js.erb b/app/assets/javascripts/galleryAPI.js.erb index d52e08b..56e7390 100644 --- a/app/assets/javascripts/galleryAPI.js.erb +++ b/app/assets/javascripts/galleryAPI.js.erb @@ -11,6 +11,8 @@ var galleryAPI = function(){ this.loadArea = null; this.tagList = $("ul#gallery_tag_list"); this.loading = $("#loading"); + + this.fullscreen_mode = false; this.loadTheater = function(id){ @@ -139,9 +141,17 @@ var galleryAPI = function(){ } }); var browserFullScreen = function(){ - var el = document.documentElement, + if(g.fullscreen_mode==false){ + var el = document.documentElement, rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen; rfs.call(el); + g.fullscreen_mode = true; + }else{ + var el = document, + rfs = el.exitFullscreen || el.msExitFullscreen || el.webkitExitFullscreen || el.mozCancelFullScreen; + rfs.call(el); + g.fullscreen_mode = false; + } } $(window).resize(function(){ if(window.innerWidth == screen.width && window.innerHeight == screen.height) { diff --git a/app/assets/javascripts/galleryAPI_frontend.js.erb b/app/assets/javascripts/galleryAPI_frontend.js.erb index 91f1efa..b91c799 100644 --- a/app/assets/javascripts/galleryAPI_frontend.js.erb +++ b/app/assets/javascripts/galleryAPI_frontend.js.erb @@ -11,6 +11,7 @@ var galleryAPI = function(){ this.loadArea = "theater"; this.tagList = $(".taglist ul"); this.loading = $("#loading"); + this.fullscreen_mode = false; // this.authenticated = false; this.initialize = function(callbackFn){ if(g.loadArea == "theater"){ @@ -109,9 +110,17 @@ var galleryAPI = function(){ } }); var browserFullScreen = function(){ - var el = document.documentElement, + if(g.fullscreen_mode==false){ + var el = document.documentElement, rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen; rfs.call(el); + g.fullscreen_mode = true; + }else{ + var el = document, + rfs = el.exitFullscreen || el.msExitFullscreen || el.webkitExitFullscreen || el.mozCancelFullScreen; + rfs.call(el); + g.fullscreen_mode = false; + } } $(window).resize(function(){ if(window.innerWidth == screen.width && window.innerHeight == screen.height) { diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index 7e9dfae..18741eb 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -10,15 +10,12 @@ class Admin::GalleriesController < ApplicationController def show @album = Album.find(params[:id]) @images = @album.album_images - @image_content = [] + image_content = [] @images.each do |image| - @image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}} + image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}} end @tags = @module_app.tags - respond_to do |h| - h.html - h.json {render json: @image_content} - end + @photos_data = {"galleries" => image_content}.to_json end def new @@ -61,6 +58,16 @@ class Admin::GalleriesController < ApplicationController render :json =>{"success"=>true}.to_json end + def get_photoData_json + @album = Album.find(params[:id]) + @images = @album.album_images + image_content = [] + @images.each do |image| + image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}} + end + render :json=>{"galleries" => image_content}.to_json + end + def get_album_json albums = Album.all output = Array.new diff --git a/app/views/admin/galleries/show.html.erb b/app/views/admin/galleries/show.html.erb index e0a2b27..f17b8dd 100644 --- a/app/views/admin/galleries/show.html.erb +++ b/app/views/admin/galleries/show.html.erb @@ -162,6 +162,10 @@ + + <% content_for :page_specific_javascript do %> <%= javascript_include_tag "jquery.masonry.min.js" %> <%= javascript_include_tag "jquery.lite.image.resize.js" %> diff --git a/config/routes.rb b/config/routes.rb index 5ca6ba4..499d2bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,12 +4,14 @@ Rails.application.routes.draw do scope "(:locale)", locale: Regexp.new(locales.join("|")) do namespace :admin do + get "galleries/get_photoData_json" => "galleries#get_photoData_json" + resources :galleries do get "imgs" => "galleries#imgs" end resources :images post "galleries/upload_image" => "galleries#upload_image" - + get "new_images" => "galleries#new_images" post "galleries/set_cover" => "galleries#set_cover" post "galleries/delete_photos" => "images#delete_photos"