履歴: ソフトウェア/rails/ICSPM22のアルバムページ
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 7 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2015/1/20 12:37:03 | ソフトウェア/rails/ICSPM22のアルバムページ 最新版 | 33,064 | +1 | -1 | 表示 | 差分 | — |
| 2015/1/20 12:37:03 | ソフトウェア/rails/ICSPM22のアルバムページ | 33,070 | +8 | -1 | 表示 | 差分 | 選択 |
| 2015/1/20 3:37:03 | ソフトウェア/rails/ICSPM22のアルバムページ | 32,889 | +1 | -0 | 表示 | 差分 | 選択 |
| 2015/1/13 10:25:06 | ソフトウェア/rails/ICSPM22のアルバムページ | 32,888 | +3 | -3 | 表示 | 差分 | 選択 |
| 2015/1/13 10:25:06 | ソフトウェア/rails/ICSPM22のアルバムページ | 32,856 | +17 | -3 | 表示 | 差分 | 選択 |
| 2015/1/12 16:01:02 | ソフトウェア/rails/ICSPM22のアルバムページ | 32,544 | +96 | -38 | 表示 | 表示中 | 選択 |
| 2015/1/12 14:55:52 | ソフトウェア/rails/ICSPM22のアルバムページ | 31,168 | — | — | 表示 | — | 基準 |
基準: ソフトウェア/rails/ICSPM22のアルバムページ (2015/1/12 14:55:52) → 比較: ソフトウェア/rails/ICSPM22のアルバムページ (2015/1/12 16:01:02)
@@ -10,6 +10,12 @@
http://dora.bk.tsukuba.ac.jp/event/ICSPM22/photo
+PC からでもスマホからでも見られるようにするため、
+-- 画面が小さくても写真を見られる
+-- 写真をめくるのにフリックが使える
+
+といったあたりを工夫しています。
+
このページを作る際に、いろいろ調べたことをまとめます。
* 前提 [#cd431c72]
@@ -30,7 +36,7 @@
>public/images/photo/icspm22_photo_small.jpg
スナップ写真は
->public/images/photo/XXX/xxxx.jpg
+>public/images/photo/(folder名)/(写真名).jpg
LANG:console
$ ls public/images/photo/
@@ -208,7 +214,7 @@
data
end
-
+
# フォルダが存在しなければ作成する(1段階)
# 与えられたフォルダ名を返す
def confirm_existence_of_folder(folder)
@@ -302,29 +308,29 @@
本当に効果的かどうかは自信がないです。
app/assets/stylesheets/photo.css.less
- // =========================== thumbnails
+ // =========================== thumbnails
+
+ .images:after {
+ // clearfix
+ content: ".";
+ display: block;
+ height: 0;
+ font-size:0;
+ clear: both;
+ visibility:hidden;
+ }
+
+ .images div {
+ float: left;
+ border: solid white 2px;
+ }
- .images:after {
- // clearfix
- content: ".";
- display: block;
- height: 0;
- font-size:0;
- clear: both;
- visibility:hidden;
- }
-
- .images div {
- float: left;
- border: solid white 2px;
- }
-
サムネール画像は div.images の下の div の中に入ります。
様々な画面サイズのデバイスに対応するために、
float: left でリキッドスタイルにしていますが、
そのままだと次のフォルダの前で改行してくれないので、
-div.images に clearfix を施しています。[[google:clearfix]]
+div.images に clearfix を施しています。[[Google:clearfix]]
* サムネールをスプライトを使って表示する [#g62f2c52]
@@ -335,7 +341,7 @@
そこで、サムネール画像を複数横に繋げたファイルを1つ用意することで
画像のダウンロード回数を1回に減らし、
各 div にはそれを切り分けて表示することにします。
-これは [[google:css スプライト]] と呼ばれる手法です。
+これは [[Google:css スプライト]] と呼ばれる手法です。
まず、コントローラ側でスプライト画像を作成します。
@@ -429,7 +435,7 @@
%i.fa{class: 'fa-arrow-left'}
%a#next{href: 'javascript:next_image()', title: 'next image'}
%i.fa{class: 'fa-arrow-right'}
- %a#enlarge{href: '#', target: '_blank', title: 'enlarge image'}
+ %a#large{href: '#', target: '_blank', title: 'enlarge image'}
%i.fa{class: 'fa-external-link'}
app/assets/photo.css.less
@@ -530,7 +536,6 @@
@image = @images[@folder_id][1][@image_id]
@resizeComponents()
- $('.photo #image').attr('src', '') # dispose old image
$('.photo #image').attr('src', "#{@photo_root}/#{@folder}/small/#{@image[0]}")
$('.photo #large').attr('href', "#{@photo_root}/#{@folder}/large/#{@image[0]}")
$('.photo #full_screen').show()
@@ -690,14 +695,18 @@
-- まったく動かしていなければ closeImage を呼ぶ
+ dragCancel では #image_frame の位置を初期位置まで戻す
+dragStart は #image_frame に割り当てられていますが、~
+dragMove, dragEnd, dragCancel は document に割り当てられています。~
+このようにすることで、マウスが #image_frame の外に出てもイベントを追えるようになります。
+
LANG:coffeescript
registerEvents: ()->
...
$('.photo #image_frame').bind 'mousedown touchstart', (e)=> @dragStart(e)
- $('.photo #image_frame').bind 'mousemove touchmove', (e)=> @dragMove(e)
- $('.photo #image_frame').bind 'mouseup touchend', (e)=> @dragEnd(e)
- $('.photo #image_frame').bind 'touchcancel', (e)=> @dragCancel(e)
+ $(document).bind 'mousemove touchmove', (e)=> @dragMove(e)
+ $(document).bind 'mouseup touchend', (e)=> @dragEnd(e)
+ $(document).bind 'touchcancel', (e)=> @dragCancel(e)
dragStart: (e)->
return true if @drag
@@ -756,13 +765,38 @@
else
e.pageX
+* キーボード操作 [#rbb44e13]
+
+次の動作を実現します
+- ESC あるいは Back Space で全画面表示の終了
+- Left / Right で画像をめくる
+
+ LANG:coffeescript
+ $('body').bind 'keydown', (e)=>
+ return true unless $("#image_frame").is(':visible')
+ switch e.keyCode
+ when 27 # Esc
+ @closeImage()
+ false
+ when 37 # ArrowLeft
+ @prevImage()
+ false
+ when 39 # ArrowRight
+ @nextImage()
+ false
+ when 8 # BackSpace
+ @closeImage()
+ false
+ else
+ true
+
* ソースコード [#f16d9449]
以上のコードをまとめて掲載しておきます。
** app/constollers/photo_controller.rb [#gf5af678]
- LANG:ruby
+ LANG:ruby(linenumber)
#coding: utf-8
require 'rubygems'
require 'RMagick'
@@ -873,7 +907,7 @@
** app/views/photo/index.html.haml [#z97da8d6]
- LANG:haml
+ LANG:haml(linenumber)
-content_for :title do
Photo
@@ -899,7 +933,7 @@
%i.fa{class: 'fa-arrow-left'}
%a#next{href: 'javascript:next_image()', title: 'next image'}
%i.fa{class: 'fa-arrow-right'}
- %a#enlarge{href: '#', target: '_blank', title: 'enlarge image'}
+ %a#large{href: '#', target: '_blank', title: 'enlarge image'}
%i.fa{class: 'fa-external-link'}
-#=========================== image list
@@ -918,7 +952,7 @@
** app/assets/stylesheets/photo.css.less [#he19ca4b]
- LANG:less
+ LANG:less(linenumber)
// Place all the styles related to the photo controller here.
// They will automatically be included in application.css.
// You can use Less here: http://lesscss.org/
@@ -1020,7 +1054,7 @@
** app/assets/javascripts/photo.js.coffee [#f7e88bf6]
- LANG:coffeescript
+ LANG:coffeescript(linenumber)
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
@@ -1097,9 +1131,9 @@
false
$('.photo #image_frame').bind 'mousedown touchstart', (e)=> @dragStart(e)
- $('.photo #image_frame').bind 'mousemove touchmove', (e)=> @dragMove(e)
- $('.photo #image_frame').bind 'mouseup touchend', (e)=> @dragEnd(e)
- $('.photo #image_frame').bind 'touchcancel', (e)=> @dragCancel(e)
+ $(document).bind 'mousemove touchmove', (e)=> @dragMove(e)
+ $(document).bind 'mouseup touchend', (e)=> @dragEnd(e)
+ $(document).bind 'touchcancel', (e)=> @dragCancel(e)
openImage: (folder_id, image_id)->
@folder_id = parseInt folder_id
@@ -1108,17 +1142,36 @@
@image = @images[@folder_id][1][@image_id]
@resizeComponents()
- $('.photo #image').attr('src', '') # dispose old image
$('.photo #image').attr('src', "#{@photo_root}/#{@folder}/small/#{@image[0]}")
$('.photo #large').attr('href', "#{@photo_root}/#{@folder}/large/#{@image[0]}")
$('.photo #full_screen').show()
+
+ $('body').bind 'keydown', (e)=>
+ return true unless $("#image_frame").is(':visible')
+ switch e.keyCode
+ when 27 # Esc
+ @closeImage()
+ false
+ when 37 # ArrowLeft
+ @prevImage()
+ false
+ when 39 # ArrowRight
+ @nextImage()
+ false
+ when 8 # BackSpace
+ @closeImage()
+ false
+ else
+ true
window.location.hash = "browsing";
- prevImage: ()->
+ prevImage: (clear = false)->
if @image_id > 0
+ @discardImage() if clear
@openImage(@folder_id, @image_id - 1)
else if @folder_id > 0
+ @discardImage() if clear
@openImage(@folder_id - 1, @images[@folder_id - 1][1].length - 1)
else
@flashButton $(".photo #prev"), 'red'
@@ -1126,10 +1179,12 @@
@flashButton $(".photo #prev"), '#333'
true
- nextImage: ()->
+ nextImage: (clear = false)->
if @image_id < @images[@folder_id][1].length - 1
+ @discardImage() if clear
@openImage(@folder_id, @image_id + 1)
else if @folder_id < @images.length - 1
+ @discardImage() if clear
@openImage(@folder_id + 1, 0)
else
@flashButton $(".photo #next"), 'red'
@@ -1142,6 +1197,9 @@
if (window.location.hash == "#browsing")
window.history.back()
+ discardImage: ->
+ $('.photo #image').attr('src', '')
+
resizeComponents: ()->
$("#controls a").css('font-size', Math.round(window.innerHeight*7/100) + "px");
@@ -1178,9 +1236,9 @@
image.css('opacity', 0)
image.animate({opacity: 1}, 300)
if image_frame.position().left > 0
- result = @prevImage()
+ result = @prevImage(true)
else
- result = @nextImage()
+ result = @nextImage(true)
if result
image_frame.css('left', '0px')