socialforge/public/javascripts/new_user.js

444 lines
13 KiB
JavaScript
Raw Normal View History

2015-08-24 11:03:09 +08:00
$(function(){
2015-08-24 16:16:07 +08:00
//右侧最小高度 = 左侧高度 - 15px 保证两边高度基本一样,页面美观
2015-08-28 17:27:51 +08:00
$("#RSide").css("min-height",$("#LSide").height()-35);
$("#users_setting").css("min-height",$("#LSide").height()-100);
2015-08-24 16:16:07 +08:00
2015-08-24 11:03:09 +08:00
//头像相关
2015-08-29 11:59:52 +08:00
$("#homepage_portrait_image").on("mouseover",function(){
2015-08-24 11:03:09 +08:00
$("#edit_user_file_btn").show();
$("#watch_user_btn").show();
2015-08-29 11:59:52 +08:00
}).on("mouseout",function(){
2015-08-24 11:03:09 +08:00
$("#edit_user_file_btn").hide();
$("#watch_user_btn").hide();
});
2015-08-26 13:56:37 +08:00
//日历选择样式
//$(".ui-datepicker-trigger").replaceWith("<div class='fl DateBorder mr10'><img class='ui-datepicker-trigger'></div>")
2015-08-24 11:03:09 +08:00
});
//编辑个人简介
function show_edit_user_introduction() {
$("#user_brief_introduction_show").hide();
$("#user_brief_introduction_edit").show();
$("#user_brief_introduction_edit").focus();
}
//编辑个人简介完成之后提交
function edit_user_introduction(url){
$.get(
url,
{ brief_introduction: $("#user_brief_introduction_edit").val() },
function (data) {
}
);
}
2015-08-24 14:44:22 +08:00
//显示更多的课程
function show_more_course(url){
$.get(
url,
{ page: $("#course_page_num").val() },
function (data) {
}
);
}
//显示更多的项目
function show_more_project(url){
$.get(
url,
2015-08-24 14:53:35 +08:00
{ page: $("#project_page_num").val() },
2015-08-24 14:44:22 +08:00
function (data) {
}
);
}
2015-08-26 17:29:47 +08:00
//老师提交 新建/修改 作业
function submit_homework(id){
if(!regex_homework_name()){
2015-08-26 17:29:47 +08:00
$("#homework_name").focus();
}
else if(!regex_homework_end_time()){
$("#homework_end_time").focus();
}
2015-09-23 09:58:31 +08:00
//else if(!regex_evaluation_start()){
// $("#evaluation_start_time").focus()
//}
//else if(!regex_evaluation_end()){
// $("#evaluation_end_time").focus()
//}
else if(!regex_course_id()){
$("#course_id").focus();
}
else{
2015-09-11 09:36:44 +08:00
2015-08-26 17:29:47 +08:00
homework_description_editor.sync();
$("#"+id).submit();
}
}
//验证新建作业的名字
function regex_homework_name()
{
var name = $.trim($("#homework_name").val());
if(name=="")
{
$("#homework_name_span").text("名称不能为空");
return false;
}
else
{
$("#homework_name_span").text("");
return true;
}
2015-08-28 10:00:48 +08:00
}
//验证截止时间
function regex_homework_end_time()
{
var name = $.trim($("#homework_end_time").val());
if(name=="")
{
$("#homework_end_time_span").text("截止时间不能为空");
return false;
}
else
{
$("#homework_end_time_span").text("");
return true;
}
}
//验证发送到课程
function regex_course_id(){
var course_id = $("#course_id").val();
if(course_id == -1)
{
$("#homework_course_id_span").text("发布课程不能为空");
return false;
}
else
{
$("#homework_course_id_span").text("");
return true;
}
}
2015-08-28 10:00:48 +08:00
//老师导入作业时查询作业
function search_homework_by_name(url){
$.get(
url,
{ name: $("#search_homework_name").val() },
function (data) {
}
);
}
//验证匿评开启时间:大于截止时间,或者为空
function regex_evaluation_start(){
var evaluation_start = $.trim($("#evaluation_start_time").val());
if(evaluation_start == ""){
return true;
}
var end_time = new Date($.trim($("#homework_end_time").val()));
var evaluation_start_time = new Date(evaluation_start);
if(evaluation_start_time > end_time){
return true;
}else{
$("#homework_end_time_span").text("开启匿评日期必须大于截止日期");
return false;
}
}
//验证匿评结束时间:大于匿评开启时间,或者为空。当匿评开启时间为空时,匿评结束时间必须为空
function regex_evaluation_end(){
var evaluation_start = $.trim($("#evaluation_start_time").val());
var evaluation_end = $.trim($("#evaluation_end_time").val());
if(evaluation_end == ""){
return true;
}else if(evaluation_start == ""){
$("#homework_end_time_span").text("开启匿评日期为空时,关闭匿评日期必须为空");
return false;
}
var evaluation_start_time = new Date(evaluation_start);
var evaluation_end_time = new Date(evaluation_end);
if(evaluation_end_time > evaluation_start_time){
return true;
}else{
$("#homework_end_time_span").text("关闭匿评日期必须大于开启匿评日期");
return false;
}
}
//提交新建作品
function new_student_work()
{
if(regexStudentWorkName()&&regexStudentWorkDescription())
{$("#new_student_work").submit();}
}
function edit_student_work(id)
{
if(regexStudentWorkName()&&regexStudentWorkDescription())
{$("#edit_student_work_" + id).submit();}
}
//验证作品名称
function regexStudentWorkName()
{
var name = $.trim($("#student_work_name").val());
if(name=="")
{
$("#student_work_name_span").text("作品名称不能为空");
return false;
}
else
{
$("#student_work_name_span").text("");
return true;
}
}
function regexStudentWorkDescription()
{
var name = $.trim($("#student_work_description").val());
if(name=="")
{
$("#student_work_description_textarea").text("作品描述不能为空");
return false;
}
else
{
$("#student_work_description_textarea").text("");
return true;
}
}
2015-09-15 15:18:33 +08:00
//学生作品
function show_project()
{
$("#about_project").slideToggle();
}
//textarea自适应高度 纯js写的 有浏览器判断
/**
* 文本框根据输入内容自适应高度
* @param {HTMLElement} 输入框元素
* @param {Number} 设置光标与输入框保持的距离(默认0)
* @param {Number} 设置最大高度(可选)
*/
var autoTextarea = function (elem, extra, maxHeight) {
extra = extra || 0;
var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
addEvent = function (type, callback) {
elem.addEventListener ?
elem.addEventListener(type, callback, false) :
elem.attachEvent('on' + type, callback);
},
getStyle = elem.currentStyle ? function (name) {
var val = elem.currentStyle[name];
if (name === 'height' && val.search(/px/i) !== 1) {
var rect = elem.getBoundingClientRect();
return rect.bottom - rect.top -
parseFloat(getStyle('paddingTop')) -
parseFloat(getStyle('paddingBottom')) + 'px';
};
return val;
} : function (name) {
return getComputedStyle(elem, null)[name];
},
minHeight = parseFloat(getStyle('height'));
elem.style.resize = 'none';
var change = function () {
var scrollTop, height,
padding = 0,
style = elem.style;
if (elem._length === elem.value.length) return;
elem._length = elem.value.length;
if (!isFirefox && !isOpera) {
padding = parseInt(getStyle('paddingTop')) + parseInt(getStyle('paddingBottom'));
};
scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
elem.style.height = minHeight + 'px';
if (elem.scrollHeight > minHeight) {
if (maxHeight && elem.scrollHeight > maxHeight) {
height = maxHeight - padding;
style.overflowY = 'auto';
} else {
height = elem.scrollHeight - padding;
style.overflowY = 'hidden';
};
style.height = height + extra + 'px';
scrollTop += parseInt(style.height) - elem.currHeight;
document.body.scrollTop = scrollTop;
document.documentElement.scrollTop = scrollTop;
elem.currHeight = parseInt(style.height);
};
};
addEvent('propertychange', change);
addEvent('input', change);
addEvent('focus', change);
change();
2015-09-15 16:11:55 +08:00
};
/////////////////////////////////////////////////////////////////////////////////////创建项目
//验证项目名称是不是为空
function regex_project_name(){
var name = $.trim($("#project_name").val());
if(name=="")
{
$("#project_name_error_msg").text("项目名称不能为空");
return false;
}
else
{
$("#project_name_error_msg").text("");
return true;
}
}
//验证项目名称是否重复---项目名称可以重复。。。。
function regex_project_name_same(){
var name = $.trim($("#project_name").val());
return true;
}
//验证项目描述
function regex_project_desc(){
var desc = $.trim($("#project_description").val());
if(desc == "")
{
$("#project_desc_error_msg").text("项目名称不能为空");
return false;
}
else
{
$("#project_desc_error_msg").text("");
return true;
}
}
//提交
function submit_project(){
if(regex_project_name()&&regex_project_desc()){
$("#new_project").submit();
}
}
/////////////////////////////////////////////////////////////////////////////////////创建项目 end
//匿评弹框取消按钮
function clickCanel(){hideModal("#popbox02");}
//匿评弹框确定按钮
function clickOK(path)
{
clickCanel();
$.ajax({
type: "GET",
url: path,
data: 'text',
success: function (data) {
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////
var autoTextarea2 = function (elem,elem2, extra, maxHeight) {
extra = extra || 0;
var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
addEvent = function (element, type, callback) {
element.addEventListener ?
element.addEventListener(type, callback, false) :
element.attachEvent('on' + type, callback);
},
getFirstStyle = elem.currentStyle ? function (name) {
var val = elem.currentStyle[name];
if (name === 'height' && val.search(/px/i) !== 1) {
var rect = elem.getBoundingClientRect();
return rect.bottom - rect.top -
parseFloat(getFirstStyle('paddingTop')) -
parseFloat(getFirstStyle('paddingBottom')) + 'px';
};
return val;
} : function (name) {
return getComputedStyle(elem, null)[name];
},
minHeight = parseFloat(getFirstStyle('height'))
elem.style.resize = 'none';
elem2.style.resize = 'none';
var change = function () {
var scrollTop, height,
padding = 0,
style = elem.style,
style2 = elem2.style;
if (elem._length === elem.value.length) return;
elem._length = elem.value.length;
elem2._length = elem._length;
if (!isFirefox && !isOpera) {
padding = parseInt(getFirstStyle('paddingTop')) + parseInt(getFirstStyle('paddingBottom'));
};
scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
elem.style.height = minHeight + 'px';
elem2.style.height = minHeight + 'px';
if (elem.scrollHeight > minHeight) {
if (maxHeight && elem.scrollHeight > maxHeight) {
height = maxHeight - padding;
style.overflowY = 'auto';
style2.overflowY = 'auto';
} else {
height = elem.scrollHeight - padding;
style.overflowY = 'hidden';
style2.overflowY = 'hidden';
};
style.height = height + extra + 'px';
style2.height = height + extra + 'px';
scrollTop += parseInt(style.height) - elem.currHeight;
document.body.scrollTop = scrollTop;
document.documentElement.scrollTop = scrollTop;
elem.currHeight = parseInt(style.height);
};
if (elem2.scrollHeight > minHeight) {
if (maxHeight && elem2.scrollHeight > maxHeight) {
height = maxHeight - padding;
style.overflowY = 'auto';
style2.overflowY = 'auto';
} else {
height = elem2.scrollHeight - padding;
style.overflowY = 'hidden';
style2.overflowY = 'hidden';
};
style.height = height + extra + 'px';
style2.height = height + extra + 'px';
scrollTop += parseInt(style2.height) - elem2.currHeight;
document.body.scrollTop = scrollTop;
document.documentElement.scrollTop = scrollTop;
elem2.currHeight = parseInt(style2.height);
};
};
addEvent(elem, 'propertychange', change);
addEvent(elem, 'input', change);
addEvent(elem, 'focus', change);
addEvent(elem2, 'propertychange', change);
addEvent(elem2, 'input', change);
addEvent(elem2, 'focus', change);
change();
};