|
//http://woork.blogspot.com/2009/02/best-image-croppers-ready-to-use-for.html |
|
|
|
|
|
$.extend($.imgAreaSelect, { |
|
animate: function (fx) { |
|
var start = fx.elem.start, end = fx.elem.end, now = fx.now, |
|
curX1 = Math.round(start.x1 + (end.x1 - start.x1) * now), |
|
curY1 = Math.round(start.y1 + (end.y1 - start.y1) * now), |
|
curX2 = Math.round(start.x2 + (end.x2 - start.x2) * now), |
|
curY2 = Math.round(start.y2 + (end.y2 - start.y2) * now); |
|
fx.elem.ias.setSelection(curX1, curY1, curX2, curY2); |
|
fx.elem.ias.update(); |
|
}, |
|
prototype: $.extend($.imgAreaSelect.prototype, { |
|
animateSelection: function (x1, y1, x2, y2, duration) { |
|
var fx = $.extend($('<div/>')[0], { |
|
ias: this, |
|
start: this.getSelection(), |
|
end: { x1: x1, y1: y1, x2: x2, y2: y2 } |
|
}); |
|
|
|
if (!$.imgAreaSelect.fxStepDefault) { |
|
$.imgAreaSelect.fxStepDefault = $.fx.step._default; |
|
$.fx.step._default = function (fx) { |
|
return fx.elem.ias ? $.imgAreaSelect.animate(fx) : |
|
$.imgAreaSelect.fxStepDefault(fx); |
|
}; |
|
} |
|
|
|
$(fx).animate({ cur: 1 }, duration, 'swing'); |
|
} |
|
}) |
|
}); |
|
|
|
function preview(img, selection) { |
|
var scaleX = 180 / (selection.width || 1); |
|
var scaleY = 180 / (selection.height || 1); |
|
|
|
$('img#prew_avatar_pic').css({ |
|
//width: Math.round(scaleX * 300) + 'px', |
|
//height: Math.round(scaleY * 300) + 'px', |
|
width: Math.round(scaleX * img.width) + 'px', |
|
height: Math.round(scaleY * img.height) + 'px', |
|
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', |
|
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' |
|
}); |
|
|
|
//取得真实图片/裁剪框 的比值 确保 上传至服务器是准确的裁剪值 |
|
if ($.browser.msie || $("#prew_avatar_pic")[0].naturalWidth == null) { |
|
var img = new Image(); |
|
img.src = $("#prew_avatar_pic")[0].src |
|
|
|
var ratio_w = img.width / $("#old_avatar_pic").width() |
|
var ratio_h = img.height / $("#old_avatar_pic").height() |
|
} else { |
|
var ratio_w = $("#prew_avatar_pic")[0].naturalWidth / $("#old_avatar_pic").width() |
|
var ratio_h = $("#prew_avatar_pic")[0].naturalHeight / $("#old_avatar_pic").height() |
|
}; |
|
if (! isNaN(selection.x1) ) { |
|
$("#crop_x").val(selection.x1 * ratio_w); |
|
$("#crop_y").val(selection.y1 * ratio_h); |
|
$("#crop_w").val(selection.width * ratio_w); |
|
$("#crop_h").val(selection.height * ratio_h); |
|
} |
|
|
|
} |
|
|
|
//http://odyniec.net/projects/imgareaselect/usage.html |
|
//persistent If set to true, clicking outside the selection area will not start a new selection (ie. the user will only be able to move/resize the existing selection area) default: false |
|
function imgareaselect (id) { |
|
var width = $("img#"+id).width(); |
|
var height = $("img#"+id).height(); |
|
$("img#"+id).imgAreaSelect({ x1: (width/2-25), y1: (width/2-25), x2: (height/2+25), y2: (height/2+25), aspectRatio: '1:1', handles: true, persistent: true, hide: false, minWidth: 50, minHeight:50, maxHeight:300, maxWidth: 300 ,onInit: preview, onSelectChange: preview, onSelectStart: preview }); |
|
} |
|
|
|
//img file upload validate |
|
$.validator.addMethod('filesize', function(value, element, param) { |
|
if ($.browser.msie){ |
|
return true |
|
} else { |
|
return this.optional(element) || (element.files[0].size <= param) |
|
} |
|
}); |
|
|
|
//local img file prew |
|
// File target is a <input type="file" /> |
|
function readURL(input_id,prew_img_id) { |
|
input = $("#"+input_id)[0] |
|
if (input.files && input.files[0]) { |
|
var reader = new FileReader(); |
|
|
|
reader.onload = function (e) { |
|
|
|
$('#'+prew_img_id) |
|
.attr('src', e.target.result) |
|
//.width(150) |
|
//.height(200); |
|
|
|
}; |
|
|
|
reader.readAsDataURL(input.files[0]); |
|
} |
|
} |
|
|
|
function set_old_img_style(img_id){ |
|
var cssObj = { |
|
"max-width": "300px", |
|
"max-height": "300px", |
|
"_width": "300px", |
|
"_height": "300px", |
|
"text-align": "center", |
|
"vertical-align": "middle", |
|
//"position":"static !important", |
|
//"position": "relative", |
|
//"padding": "50% 50% 50% 50%", |
|
//"top": "-50%", |
|
//"left": "-50%", |
|
"vertical-align": "middle" |
|
} |
|
|
|
$('#'+img_id).css(cssObj) |
|
|
|
} |
|
|
|
// validate for ie,which cannot work with file api |
|
function profile_face_validator(profile_face){ |
|
if (profile_face == null) { |
|
var profile_face = $("#profile_face") |
|
} |
|
var error_messages = { |
|
required: "请选择一个图片", |
|
accept: "图片文件必须是JPG,GIF,BMP或者PNG格式"} |
|
//var profile_face = $("#profile_face") |
|
var successed = false |
|
|
|
// other simple validator for ie |
|
if (profile_face.val() == null && profile_face.val() == ""){ |
|
humanMsg.displayMsg(error_messages.required); |
|
} else { |
|
if (profile_face.val().match(/png$|jpg$|gif$|bmp$|PNG&|JPG$|GIF&|BMP/) == null){ |
|
humanMsg.displayMsg(error_messages.accept); |
|
} else { |
|
successed = true |
|
} |
|
} |
|
|
|
return successed |
|
} |
|
|
|
$(document).ready(function() { |
|
if (! $.browser.msie){ |
|
// 非IE 主流 浏览器 验证 |
|
$('form.l_upload_profile_face').validate({ |
|
onfocusout: true, |
|
onkeyup: true, |
|
errorPlacement: function(error, element) { |
|
//error.appendTo(element.parent().next()); |
|
//var error_text = error[0].innerText |
|
var error_text = error[0].textContent |
|
if (error_text != null && error_text != ""){ |
|
humanMsg.displayMsg(error_text); |
|
} |
|
|
|
// if ( element.is(":radio") ) |
|
// error.appendTo( element.siblings("span") ); |
|
// else if ( element.is(":checkbox") ){ |
|
// error.appendTo ( element.siblings("span") ); |
|
// } |
|
// else |
|
// error.appendTo( element.parent() ); |
|
}, |
|
invalidHandler: function() { |
|
$("form.l_upload_profile_face input.save_btn").attr("disable","true") |
|
}, |
|
success: function() { |
|
//var id = 'profile_face' |
|
//imgareaselect(id) |
|
//readURL(input_id=id ,prew_img_id='old_avatar_pic') |
|
//readURL(input_id=id ,prew_img_id='prew_avatar_pic') |
|
//$("form.upload_photos input.save_btn").attr("disable","") |
|
$("form.l_upload_profile_face input.save_btn").attr("disable","") |
|
}, |
|
//success: function() { |
|
submitHandler:function(form) { |
|
var id = 'profile_face' |
|
//imgareaselect(id) |
|
//readURL(input_id=id ,prew_img_id='old_avatar_pic') |
|
//readURL(input_id=id ,prew_img_id='prew_avatar_pic') |
|
//imgareaselect(id='old_avatar_pic') |
|
//$("form.upload_photos input.save_btn").attr("disable","") |
|
$("form.l_upload_profile_face input.save_btn").attr("disable","") |
|
form.submit(); |
|
} |
|
}); |
|
//$('form.l_upload_profile_face').find("#profile_face") 与上层 form 绑定 |
|
|
|
if ($('form.l_upload_profile_face').find("#profile_face").length > 0){ |
|
$('form.l_upload_profile_face').find("#profile_face").rules("add", { |
|
required: true, |
|
accept: "image/*", |
|
filesize: 2097152, |
|
|
|
messages: { |
|
required: "请选择一个图片", |
|
accept: "图片文件必须是JPG,GIF,BMP或者PNG格式", |
|
filesize: "图片文件必须小于2MB" |
|
} |
|
}); |
|
} |
|
|
|
} |
|
|
|
|
|
//jquery.validate似乎只在type=”submit”才会触发,当使用button类型的时候不起作用,看了一下手册发现了一个valid()方法可以手工触发验证,返回一个boolean值。 |
|
var profile_face = $('form.l_upload_profile_face').find("#profile_face") |
|
profile_face.live('change',function() { |
|
if ($.browser.msie){ |
|
if (profile_face_validator()) { |
|
//手动提交表单 |
|
//$('form.l_upload_profile_face').serialize() |
|
//$('form.l_upload_profile_face').serializeArray() |
|
$("#ie_submit").val("true") |
|
$('form.l_upload_profile_face').submit(); |
|
} |
|
|
|
} else { |
|
if (profile_face.valid()){ |
|
var id = 'profile_face' |
|
//imgareaselect(id) |
|
readURL(input_id=id ,prew_img_id='old_avatar_pic') |
|
readURL(input_id=id ,prew_img_id='prew_avatar_pic') |
|
set_old_img_style(img_id = 'old_avatar_pic') |
|
imgareaselect(id='old_avatar_pic') |
|
//$("form.upload_photos input.save_btn").attr("disable","") |
|
$("form.l_upload_profile_face input.save_btn").attr("disable","true") |
|
} |
|
} |
|
}) |
|
|
|
|
|
// IE内核浏览器 验证 |
|
var old_avatar_submit = $('form.upload_face_old').find('input.edit_avatar_submit') |
|
old_avatar_submit.live('click',function() { |
|
if (profile_face_validator(profile_face = $("form.upload_face_old #profile_face"))){ |
|
return true |
|
} else { |
|
return false |
|
} |
|
}) |
|
|
|
//$('form.l_upload_profile_face').find("#profile_face") 与上层 form 绑定 |
|
}); |
|
|
|
|
|
// 新旧两种 上传模式切换 |
|
$(document).ready(function() { |
|
//切换至 旧模式 |
|
$(".avatar_edit .l_normol a").live('click',function() { |
|
$(".avatar_edit .l_new").hide(); |
|
$(".avatar_edit .old").show(); |
|
$("img#old_avatar_pic").imgAreaSelect({hide: true}) |
|
return false; |
|
}); |
|
|
|
//切换回 新模式 |
|
$(".avatar_edit .return_new a").live('click',function() { |
|
$(".avatar_edit .l_new").show(); |
|
$(".avatar_edit .old").hide(); |
|
|
|
|
|
// |
|
|
|
$("img#old_avatar_pic").imgAreaSelect({hide: true, disable: true}) |
|
//$("img#old_avatar_pic").imgAreaSelect({enable: true}) |
|
//<img alt="L_upload_img" id="old_avatar_pic" src="/assets/l_upload_img-665dd092d98def5bb330e478bb7f5b28.jpg"> |
|
//if ($("img#old_avatar_pic").attr('src').match(/l_upload_img\.jpg/) == null && $("img#old_avatar_pic").attr('src') != ''){ |
|
if ($("img#old_avatar_pic").attr('src').match(/l_upload_img/) == null && $("img#old_avatar_pic").attr('src') != ''){ |
|
imgareaselect("old_avatar_pic") |
|
$("img#old_avatar_pic").imgAreaSelect({hide: false, enable: true}) |
|
//$("img#old_avatar_pic").attr('src') |
|
}else{ |
|
$("img#old_avatar_pic").attr('src',"/assets/l_upload_img.jpg") |
|
} |
|
return false; |
|
}); |
|
|
|
// tab 切换后 隐藏 imgAreaSelect |
|
$(".avatar_edit").bind('style_display_change', function() { |
|
console.log($(this).css('display')); |
|
$("img#old_avatar_pic").imgAreaSelect({hide: true, disable: true}) |
|
if ($(this).css('display') == "none"){ |
|
//$("img#old_avatar_pic").imgAreaSelect({hide: true, disable: true}) |
|
} else { |
|
if ($(".avatar_edit div.l_new").css('display') != "none"){ |
|
//$("img#old_avatar_pic").imgAreaSelect({enable: true}) |
|
//<img alt="L_upload_img" id="old_avatar_pic" src="/assets/l_upload_img-665dd092d98def5bb330e478bb7f5b28.jpg"> |
|
//if ($("img#old_avatar_pic").attr('src').match(/l_upload_img\.jpg/) == null && $("img#old_avatar_pic").attr('src') != ''){ |
|
if ($("img#old_avatar_pic").attr('src').match(/l_upload_img/) == null && $("img#old_avatar_pic").attr('src') != ''){ |
|
imgareaselect("old_avatar_pic") |
|
$("img#old_avatar_pic").imgAreaSelect({hide: false, enable: true}) |
|
//$("img#old_avatar_pic").attr('src') |
|
}else{ |
|
//$("img#old_avatar_pic").imgAreaSelect({hide: true}) |
|
$("img#old_avatar_pic").attr('src',"/assets/l_upload_img.jpg") |
|
} |
|
} |
|
} |
|
}); |
|
}) |
|
|
|
|
|
|
|
//城市弹出层 |
|
$("#btn_location").live("click",function() { |
|
$("#pop_city").show(); |
|
$(".province_citys").addClass("hidden"); |
|
$(".sl_ad_close").live("click",function() { |
|
$("#pop_city").hide(); |
|
}); |
|
}); |
|
var pryName, cityName; |
|
$("#provinces_list a").live("click",function() { |
|
var pryParent = $(this).parents(".panel_link"); |
|
var pryTag = $(this).attr("href"); |
|
if ($(this).parent().hasClass("municipality")) { |
|
$("#pop_city").hide(); |
|
} |
|
$(".province_citys").each(function(i) { |
|
var cityTitle = $(".province_citys").eq(i).attr("title"); |
|
if (pryTag.indexOf(cityTitle) > -1) { |
|
$(".province_citys").addClass("hidden"); |
|
$(".province_citys").eq(i).removeClass("hidden"); |
|
}; |
|
}); |
|
$("a", pryParent).removeClass("prov_cur"); |
|
$(this).addClass("prov_cur"); |
|
pryName = $(this).text(); |
|
$(".city_txt").html(pryName); |
|
$("#profile_city").val(pryName); |
|
return pryName; |
|
}); |
|
$("#province_show a").live("click",function() { |
|
//cityName = pryName + $(this).text(); |
|
cityName = $(this).text(); |
|
$(".city_txt").html(cityName); |
|
$("#profile_city").val(cityName); |
|
$("#pop_city").hide(); |
|
$("i.city_txt").change(); |
|
}); |
|
$("#direct_city a").live("click",function(){ |
|
var dirCity = $(this).text(); |
|
$(".city_txt").html(dirCity); |
|
$("#profile_city").val(dirCity); |
|
$("#pop_city").hide(); |
|
$("i.city_txt").change(); |
|
}); |
|
//滑动条 |
|
var sliderMod = { |
|
init: function(cateStage) { |
|
if (cateStage == "" || cateStage == 0 ) { |
|
cateStage1 = 13; |
|
} else { |
|
cateStage1 = 13 + (cateStage) * 88; |
|
} |
|
$("#status_link1 .ui-slider-handle").css("left", cateStage1 + "px"); |
|
$("#slider-status").slider({ |
|
change:function(){ |
|
var curPos = parseInt($("#status_link1 .ui-slider-handle").css("left")); |
|
if (curPos >= 0 && curPos < 60) { |
|
$("#status_link1 .ui-slider-handle").css("left","13px"); |
|
$("#cate_wrap a").eq(0).click(); |
|
} |
|
if (60 < curPos && curPos < 150) { |
|
$("#status_link1 .ui-slider-handle").css("left","101px"); |
|
$("#cate_wrap a").eq(1).click(); |
|
} |
|
if (150 < curPos && curPos < 230) { |
|
$("#status_link1 .ui-slider-handle").css("left","189px"); |
|
$("#cate_wrap a").eq(2).click(); |
|
} |
|
if (230 < curPos && curPos < 340) { |
|
$("#status_link1 .ui-slider-handle").css("left","277px"); |
|
$("#cate_wrap a").eq(3).click(); |
|
} |
|
} |
|
}); |
|
$("#cate_wrap a").each(function(i) { |
|
$(this).live("click",function() { |
|
$("#profile_pregnancy_status").val(i+1); |
|
var catePosX = 13 + i * 88; |
|
$("#status_link1 .ui-slider-handle").css("left", catePosX + "px"); |
|
switch (i*1) |
|
{ |
|
case 0: |
|
$(".baby_predict").hide(); |
|
$(".baby_plan").show(); |
|
$(".baby_ready").hide(); |
|
break; |
|
|
|
case 1: |
|
$(".baby_predict").show(); |
|
$(".baby_plan").hide(); |
|
$(".baby_ready").hide(); |
|
break; |
|
|
|
case 2: |
|
$(".baby_predict").hide(); |
|
$(".baby_plan").hide(); |
|
$(".baby_ready").show(); |
|
break; |
|
|
|
default: |
|
$(".baby_predict").hide(); |
|
$(".baby_plan").hide(); |
|
$(".baby_ready").hide(); |
|
}; |
|
return cateStage = i; |
|
}); |
|
}); |
|
} |
|
}; |
|
|
|
jQuery(document).ready(function($){ |
|
var pregnancy_status = $("#profile_pregnancy_status").val()*1-1+'' |
|
sliderMod.init(cateStage =pregnancy_status, $("#profile_pregnancy_status").val()); |
|
sliderMod.init(cateStage =pregnancy_status, $("#profile_pregnancy_status").val()); |
|
var ppsVal = pregnancy_status; |
|
switch (ppsVal) { |
|
case "0": |
|
$(".baby_predict").hide(); |
|
$(".baby_plan").show(); |
|
$(".baby_ready").hide(); |
|
break; |
|
case "1": |
|
$(".baby_predict").show(); |
|
$(".baby_plan").hide(); |
|
$(".baby_ready").hide(); |
|
break; |
|
case "2": |
|
$(".baby_predict").hide(); |
|
$(".baby_plan").hide(); |
|
$(".baby_ready").show(); |
|
break; |
|
}; |
|
$('#_child_pre_birthday').change( |
|
function(){ |
|
$("#profile_child_birthday").val($("#_child_pre_birthday").val()); |
|
}); |
|
|
|
$('#profile_child_birthday').change( |
|
function(){ |
|
$("#_child_pre_birthday").val($("#profile_child_birthday").val()); |
|
}); |
|
|
|
var guess_city = $('b.cc_city em label').text() |
|
if (guess_city != "") |
|
{ |
|
$("#profile_city").val(guess_city) |
|
}; |
|
$("i.city_txt").change(function(){ |
|
$("b.cc_city").delay(2000).fadeOut(400); |
|
d}) |
|
}); |
|
|
|
jQuery(document).ready(function($){ |
|
//添加宝宝信息 |
|
var babyAdd = 0; |
|
$(".baby_add").live("click",function(){ |
|
if ($(".baby_add_1").css("display") =="block"){ |
|
babyAdd = 1; |
|
} |
|
if ($(".baby_add_2").css("display") =="block"){ |
|
$(".baby_add_2").show(); |
|
$(this).hide(); |
|
} |
|
if (babyAdd == 0) { |
|
$(".baby_add_1").show(); |
|
babyAdd = 1; |
|
}else { |
|
$(".baby_add_2").show(); |
|
$(this).hide(); |
|
} |
|
}); |
|
|
|
//展开收缩+- |
|
$(".tag_recommend .shrink_icon").live("click",function(){ |
|
$(".personal_tag").toggle(); |
|
$(this).toggleClass("turn_state") |
|
}) |
|
$(".contact_mode .shrink_icon").live("click",function(){ |
|
|
|
$(".pe_co_form").toggle(); |
|
$(this).toggleClass("turn_state") |
|
}) |
|
|
|
//预产期计算工具 |
|
$("#ycq_count").live("click",function(){ |
|
$(".ycq_count_tool").show(); |
|
}) |
|
$(".yct_hd .close").live("click",function(){ |
|
$(".ycq_count_tool").hide(); |
|
}) |
|
$('#cal_yuchanqi').live("click",function(){ |
|
yuchanqi() |
|
//$(".ycq_count_tool").delay(2000).fadeOut(400); |
|
}); |
|
//排卵期计算工具 |
|
$("#plq_count").live("click",function(){ |
|
$(".plq_count_tool").show(); |
|
}) |
|
$(".plq_hd .close").live("click",function(){ |
|
$(".plq_count_tool").hide(); |
|
}) |
|
}); |
|
|
|
function update_ptag(tag_list){ |
|
$.ajax({ |
|
type: "post", |
|
url: "/profiles/update_ptag", |
|
data : { |
|
tag_list : tag_list, |
|
}, |
|
success: function(result) { |
|
console.log("SUCCESS"); |
|
console.log(result); |
|
}, |
|
error: function(result) { |
|
console.log("ERROR"); |
|
console.log(result); |
|
} |
|
}); |
|
} |
|
//ajax update_ptag |
|
jQuery(document).ready(function($){ |
|
$("#update_ptag_button").live("click",function(){ |
|
if ($("#profile_tag_list").val() != "") |
|
{ |
|
update_ptag(tag_list=$("#profile_tag_list").val()) |
|
} |
|
}) |
|
}); |
|
|
|
// sync pregnancy display |
|
jQuery(document).ready(function($){ |
|
var pregnancy_timeline = ["孕早期","孕中期","孕晚期"] |
|
if ($("#profile_pregnancy_timeline").val() != "") |
|
{ |
|
var index = $("#profile_pregnancy_timeline").val()*1-1 |
|
$("strong.pregnancy").text(pregnancy_timeline[index]) |
|
} |
|
|
|
$("#profile_pregnancy_timeline").change(function(){ |
|
if ($("#profile_pregnancy_timeline").val() != "") |
|
{ |
|
var index = $("#profile_pregnancy_timeline").val()*1-1 |
|
$("strong.pregnancy").text(pregnancy_timeline[index]) |
|
} |
|
}) |
|
}); |
|
|
|
//ajax black_list autocomplate |
|
jQuery(document).ready(function($){ |
|
function split( val ) { |
|
return val.split( /,\s*/ ); |
|
} |
|
function extractLast( term ) { |
|
return split( term ).pop(); |
|
} |
|
|
|
var relate_user_cache = {}, |
|
lastXhr; |
|
|
|
if ($("#new_blacklist").length > 0){ |
|
$("#new_blacklist") |
|
// don't navigate away from the field on tab when selecting an item |
|
/*.bind( "keydown", function( event ) { |
|
if ( event.keyCode === $.ui.keyCode.TAB && |
|
$( this ).data( "autocomplete" ).menu.active ) { |
|
event.preventDefault(); |
|
} |
|
})*/ |
|
.autocomplete({ |
|
delay: 0, |
|
minLength: 0, |
|
focus: function( event, ui ) { |
|
$( "#project" ).val( ui.item.label ); |
|
return false; |
|
}, |
|
source: function( request, response ) { |
|
var term = request.term; |
|
if ( term in relate_user_cache ) { |
|
response( relate_user_cache[ term ] ); |
|
return; |
|
} |
|
|
|
lastXhr = $.getJSON( '/profiles/relate_user', request, function( data, status, xhr ) { |
|
relate_user_cache[ term ] = data; |
|
if ( xhr === lastXhr ) { |
|
response( data ); |
|
} |
|
}); |
|
}, |
|
search: function() { |
|
// custom minLength |
|
var term = extractLast( this.value ); |
|
if ( term.length < 0 ) { |
|
return false; |
|
} |
|
}, |
|
focus: function() { |
|
// prevent value inserted on focus |
|
return false; |
|
}, |
|
select: function( event, ui ) { |
|
var terms = split( this.value ); |
|
// remove the current input |
|
terms.pop(); |
|
// add the selected item |
|
terms.push( ui.item.value ); |
|
// add placeholder to get the comma-and-space at the end |
|
terms.push( "" ); |
|
this.value = terms.join( ", " ); |
|
var tmp = $("#add_user_list").val() |
|
$("#add_user_list").val(ui.item.id+","+tmp) |
|
return false; |
|
} |
|
|
|
}) |
|
.data( "autocomplete" )._renderItem = function( ul, item ) { |
|
return $( "<li id= user_"+item.id+"></li>" ) |
|
.data( "item.autocomplete", item ) |
|
.append( "<a>"+"<img src=" + item.icon+ " width='32' height='32'/>" + item.label + "<br>" + "</a>" ) |
|
.appendTo( ul ); |
|
}; |
|
console.log("#new_blacklist chage"); |
|
} |
|
|
|
}); |
|
function follow_user(link, followable_type) { |
|
var followable_id = $(link).attr("user_id") |
|
$.ajax({ |
|
url : "/profiles/add_collection", |
|
type : "post", |
|
async: false, |
|
data : { |
|
followable_id : followable_id, |
|
followable_type : followable_type |
|
}, |
|
beforeSend : function(xhr) { |
|
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')) |
|
}, |
|
success : function(transport) { |
|
//if(transport == '需要登录') { |
|
// window.location.href = '/users/sign_in'; |
|
//} else { |
|
$(link).attr("class","add_attent has_add_attent") |
|
$(link).text("已关注") |
|
//} |
|
}, |
|
error : function(jqXHR, textStatus) { |
|
if(jqXHR.status == "401") { |
|
window.location.replace('/users/sign_in') |
|
} |
|
} |
|
}) |
|
}; |
|
function unfollow_user(link,followable_type) { |
|
followable_id = $(link).attr("user_id") |
|
|
|
$.ajax({ |
|
url : "/profiles/delete_collection", |
|
type : "post", |
|
async: false, |
|
data : { |
|
followable_id : followable_id, |
|
followable_type : followable_type |
|
}, |
|
beforeSend : function(xhr) { |
|
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')) |
|
}, |
|
success : function(transport) { |
|
if(transport == '需要登录') { |
|
window.location.href = '/users/sign_in'; |
|
} else { |
|
$(link).attr("class","add_attent") |
|
$(link).text("+关注") |
|
//g("collection").innerHTML = '已收藏[' + transport + ']'; |
|
} |
|
}, |
|
error : function() { |
|
//请求出错处理 |
|
} |
|
}) |
|
}; |
|
function follow_or_unfollow(link){ |
|
if ($(link).attr("class") == "add_attent"){ |
|
follow_user(link = link,followable_type = "User") |
|
}else if ($(link).attr("class") == "add_attent has_add_attent"){ |
|
unfollow_user(link = link,followable_type = "User") |
|
}else{ |
|
//not match nothing to do ... |
|
} |
|
} |
|
// profile recomment follow and stop follow |
|
jQuery(document).ready(function($){ |
|
//call for each recomment obj |
|
$(".add_attent").each(function(){ |
|
$(this).live("click",function() { |
|
follow_or_unfollow(this) |
|
}) |
|
}); |
|
$("#followallexperts").live("click",function(){ |
|
$(".add_attent").not(".has_add_attent").each(function() { |
|
follow_user(link = this,followable_type = "User") |
|
}); |
|
}) |
|
$("#followallusers").live("click",function(){ |
|
$(".add_attent").not(".has_add_attent").each(function() { |
|
follow_user(link = this,followable_type = "User") |
|
}); |
|
}) |
|
/* |
|
$(".add_attent").not(".has_add_attent").each(function() { |
|
follow_user(link = this,followable_type = "User") |
|
}); |
|
|
|
$(".has_add_attent").each(function() { |
|
unfollow_user(link = this,followable_type = "User") |
|
}); |
|
*/ |
|
|
|
}); |
|
//添加标签列表 |
|
$("#ptb_tag_list i").bind({ |
|
mouseover:function(){$(this).addClass("put");}, |
|
mouseout:function(){$(this).removeClass("put");}, |
|
click:function(){$(this).parent().hide();} |
|
}); |
|
//黑名单列表 |
|
$("#bll_list i").bind({ |
|
mouseover:function(){$(this).addClass("put");}, |
|
mouseout:function(){$(this).removeClass("put");}, |
|
click:function(){$(this).parent().hide();} |
|
}); |