diff --git a/Gemfile b/Gemfile index 16d6317c..187ae8a8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,11 +2,14 @@ source "https://rubygems.org" gem "rails", "~> 4.0.0" gem "rails-observers" + +gem "coffee-rails", "~> 4.0.0" +gem "coffee-rails-source-maps", :group => :development gem "jquery-rails" +gem "jquery-ui-rails" +gem "uglifier" gem "sass-rails" -gem "uglifier" -gem "jquery-ui-rails" gem "pg", :platforms => [:ruby, :mswin, :mingw] gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.0.rc1", :platforms => :jruby diff --git a/Gemfile.lock b/Gemfile.lock index eacbe037..c8f25a73 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,15 @@ GEM cache_digests (0.3.1) actionpack (>= 3.2) thread_safe + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-rails-source-maps (1.4.0) + coffee-script-source (>= 1.6.1) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.7.0) daemons (1.1.9) dalli (2.7.0) diff-lcs (1.2.5) @@ -178,6 +187,8 @@ DEPENDENCIES acts_as_versioned_rails3 addressable cache_digests + coffee-rails (~> 4.0.0) + coffee-rails-source-maps daemons dalli diff-lcs diff --git a/app/assets/javascripts/boot.js.coffee b/app/assets/javascripts/boot.js.coffee new file mode 100644 index 00000000..8e5d7663 --- /dev/null +++ b/app/assets/javascripts/boot.js.coffee @@ -0,0 +1,4 @@ +#= require moebooru +#= require moebooru/related_tags +jQuery(document).ready -> + Moebooru.relatedTags.initialize() diff --git a/app/assets/javascripts/moebooru/related_tags.js.coffee b/app/assets/javascripts/moebooru/related_tags.js.coffee new file mode 100644 index 00000000..34803e6a --- /dev/null +++ b/app/assets/javascripts/moebooru/related_tags.js.coffee @@ -0,0 +1,121 @@ +#= require moebooru +jQuery(document).ready ($) -> + window.Moebooru.relatedTags = + recentTags: -> $.cookie("recent_tags").match(/\S+/g) || [] + myTags: -> $.cookie("my_tags").match(/\S+/g) || [] + artistSource: -> $("#post_source").val() + source: -> $ "#post_tags" + target: -> $ "#related" + tagUrl: (tag) -> Moebooru.path "/post?tags=#{encodeURIComponent tag}" + + getTags: -> + source = @source() + selectFrom = source[0].selectionStart + selectTo = source[0].selectionEnd + tags = source.val() + + if tags.length != 0 && selectFrom != 0 && selectFrom != tags.length + selectionStart = tags.slice(0, selectFrom).lastIndexOf " " + selectionEnd = tags.indexOf " ", selectTo + selectionStart = 0 if selectionStart == -1 + selectionEnd = undefined if selectionEnd == -1 + tags = tags.slice selectionStart, selectionEnd + tags + + refreshList: (extra) -> + buf = @target().empty() + if @myTags().length > 0 + buf.append @buildList("My Tags", @myTags()) + if @recentTags().length > 0 + buf.append @buildList("Recent Tags", @recentTags()) + + for title, tags of extra + buf.append @buildList(title, tags) if tags.length > 0 + + @highlightList() + + highlightList: -> + highlightedTags = @source().val().match(/\S+/g) || [] + $(".tag-column").find("a").removeClass "highlighted" + for tag in highlightedTags + $(".tag-column").find("a[href='#{@tagUrl tag}']").addClass "highlighted" + + buildList: (title, tags) -> + buf = $("
").addClass "tag-column" + buf.append $("
").text(title.replace /_/g, " ") + tagsList = $("