DG MS; fixed tags autocomplete styling and js
This commit is contained in:
parent
32f1b61719
commit
882c0c2170
7 changed files with 80 additions and 41 deletions
|
|
@ -17,20 +17,8 @@ class TagsController < ApplicationController
|
||||||
if params[:q] && params[:q].length > 1 && request.format.json?
|
if params[:q] && params[:q].length > 1 && request.format.json?
|
||||||
params[:q].gsub!("#", "")
|
params[:q].gsub!("#", "")
|
||||||
params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10
|
params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10
|
||||||
@tags = ActsAsTaggableOn::Tag.named_like(params[:q]).limit(params[:limit] - 1)
|
@tags = ActsAsTaggableOn::Tag.autocomplete(params[:q]).limit(params[:limit] - 1)
|
||||||
@tags.map! do |obj|
|
prep_tags_for_javascript
|
||||||
{ :name => ("#"+obj.name),
|
|
||||||
:value => ("#"+obj.name),
|
|
||||||
:url => tag_path(obj.name)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
@tags << {
|
|
||||||
:name => ('#' + params[:q]),
|
|
||||||
:value => ("#" + params[:q]),
|
|
||||||
:url => tag_path(params[:q].downcase)
|
|
||||||
}
|
|
||||||
@tags.uniq!
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json{
|
format.json{
|
||||||
|
|
@ -77,4 +65,20 @@ class TagsController < ApplicationController
|
||||||
end
|
end
|
||||||
@tag_followed
|
@tag_followed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prep_tags_for_javascript
|
||||||
|
@tags.map! do |obj|
|
||||||
|
{ :name => ("#"+obj.name),
|
||||||
|
:value => ("#"+obj.name),
|
||||||
|
:url => tag_path(obj.name)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
@tags << {
|
||||||
|
:name => ('#' + params[:q]),
|
||||||
|
:value => ("#" + params[:q]),
|
||||||
|
:url => tag_path(params[:q].downcase)
|
||||||
|
}
|
||||||
|
@tags.uniq!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,8 @@ class ActsAsTaggableOn::Tag
|
||||||
def followed_count
|
def followed_count
|
||||||
@followed_count ||= TagFollowing.where(:tag_id => self.id).count
|
@followed_count ||= TagFollowing.where(:tag_id => self.id).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.autocomplete(name)
|
||||||
|
where("name LIKE ?", "#{name.downcase}%")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,32 +13,42 @@
|
||||||
%h3
|
%h3
|
||||||
= t('profiles.edit.your_private_profile')
|
= t('profiles.edit.your_private_profile')
|
||||||
|
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_bio')
|
= t('profiles.edit.your_bio')
|
||||||
= text_area_tag 'profile[bio]', profile.bio, :rows => 5, :placeholder => t('fill_me_out')
|
= text_area_tag 'profile[bio]', profile.bio, :rows => 5, :placeholder => t('fill_me_out')
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_location')
|
= t('profiles.edit.your_location')
|
||||||
%br
|
= text_field_tag 'profile[location]', profile.location, :placeholder => t('fill_me_out')
|
||||||
= text_field_tag 'profile[location]', profile.location, :placeholder => t('fill_me_out')
|
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_gender')
|
= t('profiles.edit.your_gender')
|
||||||
%br
|
= text_field_tag 'profile[gender]', profile.gender, :placeholder => t("fill_me_out")
|
||||||
= text_field_tag 'profile[gender]', profile.gender, :placeholder => t("fill_me_out")
|
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_birthday')
|
= t('profiles.edit.your_birthday')
|
||||||
%br
|
= select_date profile.birthday, :prompt => true,
|
||||||
= select_date profile.birthday, :prompt => true,
|
:default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]'
|
||||||
:default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]'
|
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('search')
|
= t('search')
|
||||||
%p{:class=>"checkbox_select"}
|
|
||||||
= label_tag 'profile[searchable]', t('profiles.edit.allow_search')
|
|
||||||
= check_box_tag 'profile[searchable]', true, profile.searchable
|
|
||||||
|
|
||||||
|
%p{:class=>"checkbox_select"}
|
||||||
|
= label_tag 'profile[searchable]', t('profiles.edit.allow_search')
|
||||||
|
= check_box_tag 'profile[searchable]', true, profile.searchable
|
||||||
|
|
||||||
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
||||||
.submit_block
|
.submit_block
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
autocompleteInput = $("#profile_tag_string");
|
autocompleteInput = $("#profile_tag_string");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
autocompleteInput.autoSuggest("#{tags_path}", {
|
autocompleteInput.autoSuggest("#{tags_path}", {
|
||||||
selectedItemProp: "name",
|
selectedItemProp: "name",
|
||||||
searchObjProps: "name",
|
searchObjProps: "name",
|
||||||
|
|
@ -21,13 +20,14 @@
|
||||||
selectionLimit: 5,
|
selectionLimit: 5,
|
||||||
minChars: 2,
|
minChars: 2,
|
||||||
keyDelay: 200,
|
keyDelay: 200,
|
||||||
startText: "#{t('profiles.edit.your_tags_placeholder')}",
|
startText: "",
|
||||||
emptyText: "#{t('no_results')}",
|
emptyText: "#{t('no_results')}",
|
||||||
preFill: data
|
preFill: data
|
||||||
});
|
});
|
||||||
|
|
||||||
autocompleteInput.bind('keydown', function(evt){
|
autocompleteInput.bind('keydown', function(evt){
|
||||||
if(evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 32){
|
if(evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 32){
|
||||||
|
evt.preventDefault();
|
||||||
if( $('li.as-result-item.active').length == 0 ){
|
if( $('li.as-result-item.active').length == 0 ){
|
||||||
$('li.as-result-item').first().click();
|
$('li.as-result-item').first().click();
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
%h3
|
%h3
|
||||||
= t('profiles.edit.your_public_profile')
|
= t('profiles.edit.your_public_profile')
|
||||||
|
|
||||||
|
|
@ -43,13 +42,23 @@
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_name')
|
= t('profiles.edit.your_name')
|
||||||
= text_field_tag 'profile[first_name]', profile.first_name, :placeholder => t('profiles.edit.first_name')
|
= text_field_tag 'profile[first_name]', profile.first_name, :placeholder => t('profiles.edit.first_name')
|
||||||
= text_field_tag 'profile[last_name]', profile.last_name, :placeholder => t('profiles.edit.last_name')
|
= text_field_tag 'profile[last_name]', profile.last_name, :placeholder => t('profiles.edit.last_name')
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_tags')
|
= t('profiles.edit.your_tags')
|
||||||
= text_field_tag 'profile[tag_string]', ""
|
|
||||||
|
= text_field_tag 'profile[tag_string]', ""
|
||||||
|
%p{:style => "color:#777;font-style:italic"}
|
||||||
|
= t('profiles.edit.your_tags_placeholder')
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('profiles.edit.your_photo')
|
= t('profiles.edit.your_photo')
|
||||||
= render 'photos/new_profile_photo', :aspect => aspect, :person => person
|
|
||||||
%br
|
= render 'photos/new_profile_photo', :aspect => aspect, :person => person
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
|
||||||
|
|
@ -275,11 +275,6 @@ ul.dropdown
|
||||||
//hacks for tagging plugin...
|
//hacks for tagging plugin...
|
||||||
ul.as-selections
|
ul.as-selections
|
||||||
:width 100% !important
|
:width 100% !important
|
||||||
>li.as-original
|
|
||||||
:width 100% !important
|
|
||||||
>input
|
|
||||||
:width 100% !important
|
|
||||||
:color #999
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
.unread
|
.unread
|
||||||
|
|
@ -835,7 +830,7 @@ a.paginate, #infscr-loading
|
||||||
:size 16px
|
:size 16px
|
||||||
:color #333
|
:color #333
|
||||||
|
|
||||||
input:not([type='submit']):not([type='reset']):not([type='hidden']),
|
input:not([type='submit']):not([type='reset']):not([type='hidden']):not(.as-input),
|
||||||
textarea
|
textarea
|
||||||
@include border-radius(2px)
|
@include border-radius(2px)
|
||||||
|
|
||||||
|
|
|
||||||
2
public/stylesheets/vendor/autoSuggest.css
vendored
2
public/stylesheets/vendor/autoSuggest.css
vendored
|
|
@ -16,7 +16,7 @@ ul.as-selections {
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.as-selections.loading {
|
ul.as-selections.loading {
|
||||||
background-color: #eee;
|
background: url("/images/ajax-loader.gif") right center no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.as-selections li {
|
ul.as-selections li {
|
||||||
|
|
|
||||||
17
spec/models/acts_as_taggable_on_tag_spec.rb
Normal file
17
spec/models/acts_as_taggable_on_tag_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe ActsAsTaggableOn::Tag do
|
||||||
|
describe '.autocomplete' do
|
||||||
|
before do
|
||||||
|
@tag = ActsAsTaggableOn::Tag.create(:name => "cats")
|
||||||
|
end
|
||||||
|
it 'downcases the tag name' do
|
||||||
|
ActsAsTaggableOn::Tag.autocomplete("CATS").should == [@tag]
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does an end where on tags' do
|
||||||
|
ActsAsTaggableOn::Tag.autocomplete("CAT").should == [@tag]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue