Add tags filter.
This commit is contained in:
parent
1a4c305149
commit
b484a76768
|
@ -2368,8 +2368,49 @@ var wpex = {};
|
||||||
var self = this;
|
var self = this;
|
||||||
if (undefined === $.fn.imagesLoaded || undefined === $.fn.isotope) { return }
|
if (undefined === $.fn.imagesLoaded || undefined === $.fn.isotope) { return }
|
||||||
var containers = $(window.wpexAnimsition.linkElement).parents(window.wpexAnimsition.container_block);
|
var containers = $(window.wpexAnimsition.linkElement).parents(window.wpexAnimsition.container_block);
|
||||||
|
function get_filter_constraint(filterLink){
|
||||||
|
var filter_attr = window.wpexAnimsition.filter_attr;
|
||||||
|
var filter_constraint = filterLink.attr(filter_attr);
|
||||||
|
var filter_attrs = filter_attr.split(",");
|
||||||
|
if(filter_attrs.length != 1){
|
||||||
|
filter_constraint = [];
|
||||||
|
filter_attr = "";
|
||||||
|
filter_attrs.forEach(function(fa){
|
||||||
|
var tmp_filter_constraint = filterLink.attr(fa);
|
||||||
|
if( tmp_filter_constraint != undefined){
|
||||||
|
if(window.wpexAnimsition.use_attr_filter){
|
||||||
|
if(tmp_filter_constraint == "all"){
|
||||||
|
filter_constraint.push("["+fa+"]");
|
||||||
|
}else{
|
||||||
|
filter_constraint.push("["+fa+(fa[fa.length-1] == "s" ? '*' : '')+"=\""+tmp_filter_constraint+"\"]");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
filter_constraint.push(tmp_filter_constraint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(window.wpexAnimsition.use_attr_filter){
|
||||||
|
filter_constraint = filter_constraint.join("],[");
|
||||||
|
}else{
|
||||||
|
filter_constraint = filter_constraint.join(",");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(window.wpexAnimsition.use_attr_filter){
|
||||||
|
if(filter_constraint == "all"){
|
||||||
|
filter_constraint = "["+window.wpexAnimsition.filter_attr+"]";
|
||||||
|
}else{
|
||||||
|
filter_constraint = "["+window.wpexAnimsition.filter_attr+"=\""+filter_constraint+"\"]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(filterLink.data("count_limit") != undefined){
|
||||||
|
filter_constraint = filter_constraint+":nth-child(-n+"+filterLink.data("count_limit")+")";
|
||||||
|
}
|
||||||
|
console.log(filter_constraint);
|
||||||
|
return filter_constraint;
|
||||||
|
}
|
||||||
$(containers).each(function (i,v) {
|
$(containers).each(function (i,v) {
|
||||||
var $container = $(this);
|
var $container = $(v);
|
||||||
$container.imagesLoaded(function () {
|
$container.imagesLoaded(function () {
|
||||||
var activeItems;
|
var activeItems;
|
||||||
var $filter = $container.parent().find(window.wpexAnimsition.filter_bar);
|
var $filter = $container.parent().find(window.wpexAnimsition.filter_bar);
|
||||||
|
@ -2377,31 +2418,11 @@ var wpex = {};
|
||||||
var $filterLinks = $filter.find(window.wpexAnimsition.filter_option);
|
var $filterLinks = $filter.find(window.wpexAnimsition.filter_option);
|
||||||
activeItems = '';
|
activeItems = '';
|
||||||
if($filterLinks.length != 0){
|
if($filterLinks.length != 0){
|
||||||
var filter_constraint = $filterLinks.eq(0).attr(window.wpexAnimsition.filter_attr);
|
var filter_constraint = get_filter_constraint($filterLinks.eq(0));
|
||||||
if(filter_constraint == "all"){
|
|
||||||
filter_constraint = "["+window.wpexAnimsition.filter_attr+"]";
|
|
||||||
}else{
|
|
||||||
if(window.wpexAnimsition.use_attr_filter){
|
|
||||||
filter_constraint = "["+window.wpexAnimsition.filter_attr+"=\""+filter_constraint+"\"]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($filterLinks.eq(0).data("count_limit") != undefined){
|
|
||||||
filter_constraint = filter_constraint+":nth-child(-n+"+$filterLinks.eq(0).data("count_limit")+")";
|
|
||||||
}
|
|
||||||
activeItems = filter_constraint;
|
activeItems = filter_constraint;
|
||||||
}
|
}
|
||||||
$filterLinks.click(function () {
|
$filterLinks.click(function () {
|
||||||
var filter_constraint = $(this).attr(window.wpexAnimsition.filter_attr);
|
var filter_constraint = get_filter_constraint($(this));
|
||||||
if(filter_constraint == "all"){
|
|
||||||
filter_constraint = "["+window.wpexAnimsition.filter_attr+"]";
|
|
||||||
}else{
|
|
||||||
if(window.wpexAnimsition.use_attr_filter){
|
|
||||||
filter_constraint = "["+window.wpexAnimsition.filter_attr+"=\""+filter_constraint+"\"]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($(this).data("count_limit") != undefined){
|
|
||||||
filter_constraint = filter_constraint+":nth-child(-n+"+$(this).data("count_limit")+")";
|
|
||||||
}
|
|
||||||
$grid.isotope({ filter: filter_constraint});
|
$grid.isotope({ filter: filter_constraint});
|
||||||
self.equalHeights();
|
self.equalHeights();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -133,23 +133,45 @@ class AnnouncementsController < ApplicationController
|
||||||
|
|
||||||
def pack_data(is_random=false)
|
def pack_data(is_random=false)
|
||||||
cats = OrbitHelper.widget_categories || []
|
cats = OrbitHelper.widget_categories || []
|
||||||
|
tags = OrbitHelper.widget_tags || []
|
||||||
subpart = OrbitHelper.get_current_widget
|
subpart = OrbitHelper.get_current_widget
|
||||||
get_tabs_option
|
get_tabs_option
|
||||||
anns = []
|
anns = []
|
||||||
|
use_tag = false
|
||||||
if @tab_option == 0
|
if @tab_option == 0
|
||||||
anns = get_anncs_for_pack_data(cats,is_random)
|
anns = get_anncs_for_pack_data(cats,tags,is_random)
|
||||||
else
|
else
|
||||||
|
if cats.count != 1 || tags == ["all"]
|
||||||
cats.each do |cat|
|
cats.each do |cat|
|
||||||
anns = anns + get_anncs_for_pack_data([cat])
|
anns = anns + get_anncs_for_pack_data([cat],tags)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
tags.each do |tag|
|
||||||
|
anns = anns + get_anncs_for_pack_data(cats,[tag])
|
||||||
|
end
|
||||||
|
use_tag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
mp = (anns[0]["img_src"] rescue "")
|
mp = (anns[0]["img_src"] rescue "")
|
||||||
mpd = (anns[0]["img_description"] rescue "")
|
mpd = (anns[0]["img_description"] rescue "")
|
||||||
if @tab_option == 1
|
if @tab_option == 1
|
||||||
|
if use_tag
|
||||||
|
tags = ["all"] + tags
|
||||||
|
else
|
||||||
cats = ["all"] + cats
|
cats = ["all"] + cats
|
||||||
|
end
|
||||||
anns = anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
anns = anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
||||||
end
|
end
|
||||||
cats = cats.uniq
|
cats = cats.uniq
|
||||||
|
tags = tags.uniq
|
||||||
|
tags_translations = tags.map{|tag_id|
|
||||||
|
if tag_id == "all"
|
||||||
|
t = I18n.t(:all)
|
||||||
|
else
|
||||||
|
t = Tag.find(tag_id).name rescue ""
|
||||||
|
end
|
||||||
|
[tag_id,t]
|
||||||
|
}.to_h
|
||||||
cats_translations = cats.map{|cat_id|
|
cats_translations = cats.map{|cat_id|
|
||||||
if cat_id == "all"
|
if cat_id == "all"
|
||||||
t = I18n.t(:all)
|
t = I18n.t(:all)
|
||||||
|
@ -171,12 +193,29 @@ class AnnouncementsController < ApplicationController
|
||||||
if all_cats.count == 0
|
if all_cats.count == 0
|
||||||
all_cats = ["all"]
|
all_cats = ["all"]
|
||||||
end
|
end
|
||||||
|
all_tags = tags.dup
|
||||||
|
all_tags.delete "all"
|
||||||
|
if all_tags.count == 0
|
||||||
|
all_tags = ["all"]
|
||||||
|
end
|
||||||
max_all_count = [OrbitHelper.widget_data_count,anns.count].min
|
max_all_count = [OrbitHelper.widget_data_count,anns.count].min
|
||||||
if @tab_option != 0
|
if @tab_option != 0
|
||||||
OrbitHelper.set_widget_title(OrbitHelper.widget_title +
|
OrbitHelper.set_widget_title(OrbitHelper.widget_title +
|
||||||
"<div style=\"clear: both;\"></div>" +
|
"<div style=\"clear: both;\"></div>" +
|
||||||
"<ul class=\"nav_tabs_filter\">" +
|
"<ul class=\"nav_tabs_filter\">" +
|
||||||
cats.map.with_index{|cat,i|
|
(use_tag ? tags.map.with_index{|tag,i|
|
||||||
|
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
|
||||||
|
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>(tag == 'all' ? all_tags : [tag])}.to_param if read_more_url != ""
|
||||||
|
read_more_text = I18n.t("announcement.more")
|
||||||
|
if tag != "all"
|
||||||
|
begin
|
||||||
|
read_more_text = I18n.t("announcement.more_") + tags_translations[tag]
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" data-count_limit=\"#{max_all_count}\" data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>"
|
||||||
|
}.join("") : cats.map.with_index{|cat,i|
|
||||||
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
|
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
|
||||||
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
|
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
|
||||||
read_more_text = I18n.t("announcement.more")
|
read_more_text = I18n.t("announcement.more")
|
||||||
|
@ -188,9 +227,10 @@ class AnnouncementsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(cat == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-category=\"#{cats_relations[cat]}\">#{cats_translations[cat]}</li>"
|
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(cat == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-category=\"#{cats_relations[cat]}\">#{cats_translations[cat]}</li>"
|
||||||
}.join("") +
|
}.join("")) +
|
||||||
"</ul>"
|
"</ul>"
|
||||||
)
|
)
|
||||||
|
filter_attr = (use_tag ? 'data-tags' : 'data-category')
|
||||||
extra_html = '
|
extra_html = '
|
||||||
<script>
|
<script>
|
||||||
if(typeof(wpexAnimsition) == "undefined"){
|
if(typeof(wpexAnimsition) == "undefined"){
|
||||||
|
@ -206,14 +246,18 @@ class AnnouncementsController < ApplicationController
|
||||||
"parent_block": "[data-subpart-id=\"'+subpart.id.to_s+'\"]",
|
"parent_block": "[data-subpart-id=\"'+subpart.id.to_s+'\"]",
|
||||||
"filter_bar": ".nav_tabs_filter",
|
"filter_bar": ".nav_tabs_filter",
|
||||||
"filter_option": "li.filter_tab",
|
"filter_option": "li.filter_tab",
|
||||||
"filter_attr": "data-category",
|
"filter_attr": "'+filter_attr+'",
|
||||||
"filter_target_attr": "class",
|
"filter_target_attr": "class",
|
||||||
"use_attr_filter": true,
|
"use_attr_filter": true,
|
||||||
"equal_height": false
|
"equal_height": false
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
|
var filter_attr = "'+filter_attr+'";
|
||||||
wpexAnimsition.parent_block = wpexAnimsition.parent_block + ", [data-subpart-id=\"'+subpart.id.to_s+'\"]";
|
wpexAnimsition.parent_block = wpexAnimsition.parent_block + ", [data-subpart-id=\"'+subpart.id.to_s+'\"]";
|
||||||
wpexAnimsition.container_block = wpexAnimsition.container_block + ", [data-subpart-id=\"'+subpart.id.to_s+'\"] [data-list=\"announcements\"]:not(tbody)";
|
wpexAnimsition.container_block = wpexAnimsition.container_block + ", [data-subpart-id=\"'+subpart.id.to_s+'\"] [data-list=\"announcements\"]:not(tbody)";
|
||||||
|
if( wpexAnimsition.filter_attr.indexOf(filter_attr) == -1 ){
|
||||||
|
wpexAnimsition.filter_attr += ("," + filter_attr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var wpexLocalize = {
|
var wpexLocalize = {
|
||||||
"lightboxType": "iLightbox",
|
"lightboxType": "iLightbox",
|
||||||
|
@ -410,11 +454,10 @@ class AnnouncementsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def get_anncs_for_pack_data(cats,is_random = false)
|
def get_anncs_for_pack_data(cats,tags,is_random = false)
|
||||||
tags = OrbitHelper.widget_tags || []
|
|
||||||
subpart = OrbitHelper.get_current_widget
|
subpart = OrbitHelper.get_current_widget
|
||||||
widget_data_count = OrbitHelper.widget_data_count
|
widget_data_count = OrbitHelper.widget_data_count
|
||||||
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
|
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
|
||||||
set_image_version_for_widget()
|
set_image_version_for_widget()
|
||||||
devide_flag = (!(defined? SiteFeed).nil?)
|
devide_flag = (!(defined? SiteFeed).nil?)
|
||||||
if anns_cache.count != 1 || is_random
|
if anns_cache.count != 1 || is_random
|
||||||
|
@ -432,10 +475,10 @@ class AnnouncementsController < ApplicationController
|
||||||
now_anns = sorted_anns.to_a
|
now_anns = sorted_anns.to_a
|
||||||
top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)}
|
top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)}
|
||||||
not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v)}
|
not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v)}
|
||||||
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns})
|
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns})
|
||||||
else
|
else
|
||||||
anns = sorted_anns.map{|v| data_to_human_type(v)}
|
anns = sorted_anns.map{|v| data_to_human_type(v)}
|
||||||
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns)
|
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if devide_flag
|
if devide_flag
|
||||||
|
|
|
@ -76,6 +76,7 @@ module AnnouncementsHelper
|
||||||
"subtitle" => a.subtitle,
|
"subtitle" => a.subtitle,
|
||||||
"statuses" => statuses,
|
"statuses" => statuses,
|
||||||
"category" => a.category.title,
|
"category" => a.category.title,
|
||||||
|
"tag_ids" => (a.tag_ids.map{|id| id.to_s}.to_s.gsub('"',"'") rescue '[]'),
|
||||||
"postdate" => a.postdate,
|
"postdate" => a.postdate,
|
||||||
"author" => author,
|
"author" => author,
|
||||||
"link_to_show" => link_to_show,
|
"link_to_show" => link_to_show,
|
||||||
|
@ -199,7 +200,6 @@ module AnnouncementsHelper
|
||||||
tags = page.tags
|
tags = page.tags
|
||||||
tags = params[:tags] if params[:tags].present?
|
tags = params[:tags] if params[:tags].present?
|
||||||
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
|
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
|
||||||
categories = ["all"] if params[:tags].present?
|
|
||||||
end
|
end
|
||||||
if !params["source"].present?
|
if !params["source"].present?
|
||||||
if @type == "show_widget"
|
if @type == "show_widget"
|
||||||
|
|
Loading…
Reference in New Issue