diff options
author | rhenium <rhenium@rhe.jp> | 2014-07-14 05:43:47 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2014-07-14 05:43:47 +0900 |
commit | f55fcd3eb11022121468496ccbc76f022f27a13c (patch) | |
tree | 658625c1d7c17f69bb6a21fc47f1b343431947e3 | |
parent | aea3df8df6afaf1ba869306a41e2c8c5fc595981 (diff) | |
download | aclog-f55fcd3eb11022121468496ccbc76f022f27a13c.tar.gz |
web: refactor views (use helper to render loading animation)
-rw-r--r-- | app/assets/javascripts/tweets.js | 45 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 8 | ||||
-rw-r--r-- | app/views/tweets/all_best.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/all_recent.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/all_timeline.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/filter.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/user_best.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/user_favorited_by.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/user_favorites.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/user_recent.html.haml | 2 | ||||
-rw-r--r-- | app/views/tweets/user_timeline.html.haml | 2 | ||||
-rw-r--r-- | app/views/users/discovered_users.html.haml | 2 |
12 files changed, 39 insertions, 34 deletions
diff --git a/app/assets/javascripts/tweets.js b/app/assets/javascripts/tweets.js index e4f5dda..25fa145 100644 --- a/app/assets/javascripts/tweets.js +++ b/app/assets/javascripts/tweets.js @@ -1,30 +1,27 @@ Application.tweets = { _: function() { - if ($("#statuses")) { - var format_tweet = function(d) { - $("time", d).each( - function() { - $(this).text(new Date($(this).attr("datetime")) - .toLocaleString()); - }); - }; - format_tweet($(".statuses")); + var formatTweet = function(d) { + $("time", d).each(function() { + $(this).text(new Date($(this).attr("datetime")) + .toLocaleString()); + }); + }; + formatTweet($(".statuses")); - if ($("link[rel=next]")) { - $.autopager({ - content: $(".statuses"), - link: $("link[rel=next]"), - onStart: function() { - $(".loading").show(); - }, - onReceived: function(obj) { - format_tweet(obj); - }, - onComplete: function() { - $(".loading").hide(); - } - }); - } + if ($("link[rel=next]") !== null) { + $.autopager({ + content: $(".statuses"), + link: $("link[rel=next]"), + onStart: function() { + $(".loading").show(); + }, + onReceived: function(obj) { + formatTweet(obj); + }, + onComplete: function() { + $(".loading").hide(); + } + }); } $(".statuses").on("click", ".expand-responses-button", function() { diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 197b6d7..5fe6350 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -25,6 +25,14 @@ module ApplicationHelper end end + def loading_tag + capture_haml do + haml_tag(".loading") do + haml_concat image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + end + end + end + # utf8, form def utf8_enforcer_tag; raw "" end end diff --git a/app/views/tweets/all_best.html.haml b/app/views/tweets/all_best.html.haml index 629677d..77406a5 100644 --- a/app/views/tweets/all_best.html.haml +++ b/app/views/tweets/all_best.html.haml @@ -6,4 +6,4 @@ Top Tweets %small of All Time .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/all_recent.html.haml b/app/views/tweets/all_recent.html.haml index 04e7182..23b5647 100644 --- a/app/views/tweets/all_recent.html.haml +++ b/app/views/tweets/all_recent.html.haml @@ -6,4 +6,4 @@ Best Tweets %small in Last 3 Days .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/all_timeline.html.haml b/app/views/tweets/all_timeline.html.haml index 48a64cc..819b095 100644 --- a/app/views/tweets/all_timeline.html.haml +++ b/app/views/tweets/all_timeline.html.haml @@ -5,4 +5,4 @@ %h1 Public Timeline .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/filter.html.haml b/app/views/tweets/filter.html.haml index c5cbc8f..bda1102 100644 --- a/app/views/tweets/filter.html.haml +++ b/app/views/tweets/filter.html.haml @@ -8,4 +8,4 @@ = text_field_tag :q, params[:q] = submit_tag "filter", class: "btn", name: nil .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/user_best.html.haml b/app/views/tweets/user_best.html.haml index 3384d35..144a0d4 100644 --- a/app/views/tweets/user_best.html.haml +++ b/app/views/tweets/user_best.html.haml @@ -6,4 +6,4 @@ %small #{@user.screen_name}'s Best Tweets .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/user_favorited_by.html.haml b/app/views/tweets/user_favorited_by.html.haml index 931346d..9d0e13a 100644 --- a/app/views/tweets/user_favorited_by.html.haml +++ b/app/views/tweets/user_favorited_by.html.haml @@ -10,4 +10,4 @@ %a{href: user_path(@source_user.screen_name), title: "#{@source_user.name} (@#{@source_user.screen_name})"} = @source_user.screen_name .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/user_favorites.html.haml b/app/views/tweets/user_favorites.html.haml index 9e1a016..37d13b5 100644 --- a/app/views/tweets/user_favorites.html.haml +++ b/app/views/tweets/user_favorites.html.haml @@ -6,4 +6,4 @@ %small #{@user.screen_name}'s Favorites .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/user_recent.html.haml b/app/views/tweets/user_recent.html.haml index ae78dba..c1eaf7b 100644 --- a/app/views/tweets/user_recent.html.haml +++ b/app/views/tweets/user_recent.html.haml @@ -6,4 +6,4 @@ %small #{@user.screen_name}'s Recent Best Tweets .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/tweets/user_timeline.html.haml b/app/views/tweets/user_timeline.html.haml index f030533..9e5ba54 100644 --- a/app/views/tweets/user_timeline.html.haml +++ b/app/views/tweets/user_timeline.html.haml @@ -6,4 +6,4 @@ %small #{@user.screen_name}'s Timeline .statuses= render @tweets - %p.loading= image_tag "loading.gif", width: 16, height: 16, alt: "Loading..." + = loading_tag diff --git a/app/views/users/discovered_users.html.haml b/app/views/users/discovered_users.html.haml index 3cdccc7..be86b3c 100644 --- a/app/views/users/discovered_users.html.haml +++ b/app/views/users/discovered_users.html.haml @@ -1,4 +1,4 @@ -- title "@#{@user.screen_name} is Discovering ..." +- title "@#{@user.screen_name} is Discovering..." .col-sm-3.col-md-offset-1 = render "shared/sidebar_user", user: @user .col-sm-9.col-md-7.col-lg-6 |