jquery升到1.11

This commit is contained in:
guange 2015-08-29 11:59:52 +08:00
parent e8fe397158
commit 18bfe1fc73
11 changed files with 321 additions and 24 deletions

View File

@ -12,7 +12,7 @@ class StudentWorkController < ApplicationController
###
def program_test
resultObj = {status: 0, results: [], error_msg: ''}
resultObj = {status: 0, results: [], error_msg: '', time: Time.now}
student_work = find_or_save_student_work
unless student_work
resultObj[:status] = 100
@ -27,11 +27,14 @@ class StudentWorkController < ApplicationController
if result["status"].to_i == -2 #编译错误
results = [result["error_msg"]]
end
student_work.student_work_tests.build(status: result["status"], results: results)
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
src: params[:src])
unless student_work.save
resultObj[:status] = 200
else
resultObj[:status] = result["status"].to_i
resultObj[:time] = student_work_test.created_at.to_s(:db)
resultObj[:index] = student_work.student_work_tests.count
end
end
@ -154,7 +157,6 @@ class StudentWorkController < ApplicationController
stundet_work.late_penalty = 0
end
render_attachment_warning_if_needed(stundet_work)
if stundet_work.save
if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分

View File

@ -1,6 +1,6 @@
# encoding: utf-8
class StudentWorkTest < ActiveRecord::Base
attr_accessible :student_work_id, :results, :status
attr_accessible :student_work_id, :results, :status, :src
belongs_to :student_work
serialize :results, Array

View File

@ -1,4 +1,4 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%= error_messages_for 'homework_common' %>
<div class="project_r_h">
<h2 class="project_h2">

View File

@ -1,4 +1,4 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%= error_messages_for 'homework_common' %>
<div class="project_r_h">
<h2 class="project_h2">

View File

@ -1,5 +1,5 @@
<% content_for :header_tags do %>
<%= javascript_include_tag 'homework' %>
<%= javascript_include_tag 'homework','baiduTemplate' %>
<% end %>
<% if @homework.homework_type == 1 %>
@ -89,6 +89,42 @@
<% else %>
<!-- 模板1开始可以使用scripttype设置为text/html来存放模板片段并且用id标示 -->
<script id="t:result-list" type="text/html">
<div class="ProResultTop">
<p class="c_blue fl">第<!=index!>次测试</p><span class="fr c_grey"><!= time !></span>
<div class="cl"></div>
</div>
<! if(status == -2){!>
<div class="ProResultCon "><!= error_msg !></div>
<!}else{!>
<div class="ProResultTable " >
<ul class="ProResultUl " >
<! for(var i =0; i <results.length; ++i){ !>
<li ><span class="w60 T_C">测试<!=i+1!></span>
<! if(results[i]["status"]!=0){ !>
<span class="w150 c_red">测试错误!</span>
<span class="w60">您的输出:</span>
<span class="W200"><!=results[i]["result"]!></span>
<span class="w60">正确输出:</span>
<span class="W200"><!=results[i]["output"]!></span>
<div class="cl"></div>
</li>
<!}else{!>
<span class="w150 c_green">测试正确!</span>
<div class="cl"></div>
</li>
<!}!>
<!}!>
</ul>
</div>
<! } !>
</script>
<!-- 模板1结束 -->
<div class="homepageRight">
<div class="HomeWork">
<div class="RightBanner">
@ -111,7 +147,8 @@
:html => { :multipart => true },
:url => {:controller => 'student_work',
:action => 'create',
:student_work_id => @student_work.id
:student_work_id => @student_work.id,
:homework => @homework.id
},
:method => :post) do |f|%>
@ -135,7 +172,7 @@
<div class="ProResult mt10">
<% @student_work.student_work_tests.each_with_index do |test, index| %>
<div class="ProResultTop">
<p class="c_blue fl">第<%= @student_work.student_work_tests.count - index%>次测试</p><span class="fr c_grey"><%= format_time(test.created_at) %></span>
<p class="c_blue fl">第<%= @student_work.student_work_tests.count - index%>次测试</p><span class="fr c_grey"><%= test.created_at.to_s(:db) %></span>
<div class="cl"></div>
</div>
<% if test.status.to_i == -2 %>

View File

@ -0,0 +1,5 @@
class AddSrcToStudentWorkTests < ActiveRecord::Migration
def change
add_column :student_work_tests, :src, :text
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150828011415) do
ActiveRecord::Schema.define(:version => 20150828155329) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1296,11 +1296,11 @@ ActiveRecord::Schema.define(:version => 20150828011415) do
create_table "student_work_tests", :force => true do |t|
t.integer "student_work_id"
t.integer "homework_test_id"
t.integer "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "results"
t.text "src"
end
create_table "student_works", :force => true do |t|

View File

@ -0,0 +1,216 @@
/**
* baiduTemplate简单好用的Javascript模板引擎 1.0.6 版本
* http://baidufe.github.com/BaiduTemplate
* 开源协议BSD License
* 浏览器环境占用命名空间 baidu.template nodejs环境直接安装 npm install baidutemplate
* @param str{String} dom结点ID或者模板string
* @param data{Object} 需要渲染的json对象可以为空当data为{}仍然返回html
* @return 如果无data直接返回编译后的函数如果有data返回html
* @author wangxiao
* @email 1988wangxiao@gmail.com
*/
;(function(window){
//取得浏览器环境的baidu命名空间非浏览器环境符合commonjs规范exports出去
//修正在nodejs环境下采用baidu.template变量名
var baidu = typeof module === 'undefined' ? (window.baidu = window.baidu || {}) : module.exports;
//模板函数放置于baidu.template命名空间下
baidu.template = function(str, data){
//检查是否有该id的元素存在如果有元素则获取元素的innerHTML/value否则认为字符串为模板
var fn = (function(){
//判断如果没有document则为非浏览器环境
if(!window.document){
return bt._compile(str);
};
//HTML5规定ID可以由任何不包含空格字符的字符串组成
var element = document.getElementById(str);
if (element) {
//取到对应id的dom缓存其编译后的HTML模板函数
if (bt.cache[str]) {
return bt.cache[str];
};
//textarea或input则取value其它情况取innerHTML
var html = /^(textarea|input)$/i.test(element.nodeName) ? element.value : element.innerHTML;
return bt._compile(html);
}else{
//是模板字符串,则生成一个函数
//如果直接传入字符串作为模板,则可能变化过多,因此不考虑缓存
return bt._compile(str);
};
})();
//有数据则返回HTML字符串没有数据则返回函数 支持data={}的情况
var result = bt._isObject(data) ? fn( data ) : fn;
fn = null;
return result;
};
//取得命名空间 baidu.template
var bt = baidu.template;
//标记当前版本
bt.versions = bt.versions || [];
bt.versions.push('1.0.6');
//缓存 将对应id模板生成的函数缓存下来。
bt.cache = {};
//自定义分隔符可以含有正则中的字符可以是HTML注释开头 <! !>
bt.LEFT_DELIMITER = bt.LEFT_DELIMITER||'<%';
bt.RIGHT_DELIMITER = bt.RIGHT_DELIMITER||'%>';
//自定义默认是否转义,默认为默认自动转义
bt.ESCAPE = true;
//HTML转义
bt._encodeHTML = function (source) {
return String(source)
.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')
.replace(/\\/g,'&#92;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
};
//转义影响正则的字符
bt._encodeReg = function (source) {
return String(source).replace(/([.*+?^=!:${}()|[\]/\\])/g,'\\$1');
};
//转义UI UI变量使用在HTML页面标签onclick等事件函数参数中
bt._encodeEventHTML = function (source) {
return String(source)
.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;')
.replace(/\\\\/g,'\\')
.replace(/\\\//g,'\/')
.replace(/\\n/g,'\n')
.replace(/\\r/g,'\r');
};
//将字符串拼接生成函数,即编译过程(compile)
bt._compile = function(str){
var funBody = "var _template_fun_array=[];\nvar fn=(function(__data__){\nvar _template_varName='';\nfor(name in __data__){\n_template_varName+=('var '+name+'=__data__[\"'+name+'\"];');\n};\neval(_template_varName);\n_template_fun_array.push('"+bt._analysisStr(str)+"');\n_template_varName=null;\n})(_template_object);\nfn = null;\nreturn _template_fun_array.join('');\n";
return new Function("_template_object",funBody);
};
//判断是否是Object类型
bt._isObject = function (source) {
return 'function' === typeof source || !!(source && 'object' === typeof source);
};
//解析模板字符串
bt._analysisStr = function(str){
//取得分隔符
var _left_ = bt.LEFT_DELIMITER;
var _right_ = bt.RIGHT_DELIMITER;
//对分隔符进行转义支持正则中的元字符可以是HTML注释 <! !>
var _left = bt._encodeReg(_left_);
var _right = bt._encodeReg(_right_);
str = String(str)
//去掉分隔符中js注释
.replace(new RegExp("("+_left+"[^"+_right+"]*)//.*\n","g"), "$1")
//去掉注释内容 <%* 这里可以任意的注释 *%>
//默认支持HTML注释将HTML注释匹配掉的原因是用户有可能用 <! !>来做分割符
.replace(new RegExp("<!--.*?-->", "g"),"")
.replace(new RegExp(_left+"\\*.*?\\*"+_right, "g"),"")
//把所有换行去掉 \r回车符 \t制表符 \n换行符
.replace(new RegExp("[\\r\\t\\n]","g"), "")
//用来处理非分隔符内部的内容中含有 斜杠 \ 单引号 处理办法为HTML转义
.replace(new RegExp(_left+"(?:(?!"+_right+")[\\s\\S])*"+_right+"|((?:(?!"+_left+")[\\s\\S])+)","g"),function (item, $1) {
var str = '';
if($1){
//将 斜杠 单引 HTML转义
str = $1.replace(/\\/g,"&#92;").replace(/'/g,'&#39;');
while(/<[^<]*?&#39;[^<]*?>/g.test(str)){
//将标签内的单引号转义为\r 结合最后一步,替换为\'
str = str.replace(/(<[^<]*?)&#39;([^<]*?>)/g,'$1\r$2')
};
}else{
str = item;
}
return str ;
});
str = str
//定义变量,如果没有分号,需要容错 <%var val='test'%>
.replace(new RegExp("("+_left+"[\\s]*?var[\\s]*?.*?[\\s]*?[^;])[\\s]*?"+_right,"g"),"$1;"+_right_)
//对变量后面的分号做容错(包括转义模式 如<%:h=value%>) <%=value;%> 排除掉函数的情况 <%fun1();%> 排除定义变量情况 <%var val='test';%>
.replace(new RegExp("("+_left+":?[hvu]?[\\s]*?=[\\s]*?[^;|"+_right+"]*?);[\\s]*?"+_right,"g"),"$1"+_right_)
//按照 <% 分割为一个个数组,再用 \t 和在一起,相当于将 <% 替换为 \t
//将模板按照<%分为一段一段的,再在每段的结尾加入 \t,即用 \t 将每个模板片段前面分隔开
.split(_left_).join("\t");
//支持用户配置默认是否自动转义
if(bt.ESCAPE){
str = str
//找到 \t=任意一个字符%> 替换为 ‘,任意字符,'
//即替换简单变量 \t=data%> 替换为 ',data,'
//默认HTML转义 也支持HTML转义写法<%:h=value%>
.replace(new RegExp("\\t=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'");
}else{
str = str
//默认不转义HTML转义
.replace(new RegExp("\\t=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':$1,'");
};
str = str
//支持HTML转义写法<%:h=value%>
.replace(new RegExp("\\t:h=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'")
//支持不转义写法 <%:=value%>和<%-value%>
.replace(new RegExp("\\t(?::=|-)(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':$1,'")
//支持url转义 <%:u=value%>
.replace(new RegExp("\\t:u=(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':encodeURIComponent($1),'")
//支持UI 变量使用在HTML页面标签onclick等事件函数参数中 <%:v=value%>
.replace(new RegExp("\\t:v=(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':baidu.template._encodeEventHTML($1),'")
//将字符串按照 \t 分成为数组,在用'); 将其合并,即替换掉结尾的 \t 为 ');
//在iffor等语句前面加上 '); ,形成 ');if ');for 的形式
.split("\t").join("');")
//将 %> 替换为_template_fun_array.push('
//即去掉结尾符生成函数中的push方法
//如if(list.length=5){%><h2>',list[4],'</h2>');}
//会被替换为 if(list.length=5){_template_fun_array.push('<h2>',list[4],'</h2>');}
.split(_right_).join("_template_fun_array.push('")
//将 \r 替换为 \
.split("\r").join("\\'");
return str;
};
})(window);

View File

@ -1,5 +1,10 @@
$(function(){
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
var tested = false;
var valid_form = function() {
var src = $('#program-src').val();
var title = $('#program-title').val();
@ -15,9 +20,9 @@ $(function(){
return true;
}
$('#test-program-btn').on('click', function(){
var homework_id = $(this).attr('data-homework-id');
var student_work_id = $(this).attr('data-student-work-id');
var test_program = function(cb){
var homework_id = $('#test-program-btn').attr('data-homework-id');
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
var src = $('#program-src').val();
var title = $('#program-title').val();
@ -29,20 +34,49 @@ $(function(){
'/student_work/program_test',
{homework: homework_id, student_work_id: student_work_id, src: src, title: title},
function(data,status){
if(data.status==-2){
alert('编译失败');
tested = true;
console.log(data);
if (cb) {cb(); return;}
var html=bt('t:result-list',data);
$('.ProResult').prepend(html);
if (data.status==0) {
var r=confirm("答题正确,是否立刻提交?");
if (r) {
$(".HomeWorkCon form").submit();
}
}
}
);
});
};
$('#test-program-btn').on('click', test_program);
$('#commit-program-work-btn').on('click', function(){
if(!valid_form()){
return;
}
if($('.ProResult .ProResultTop').length<=0){
var r=confirm("测试后才能提交,是否立刻测试?");
if (r) {
test_program();
}
return;
}
if (!tested) {
test_program(function(){
$(".HomeWorkCon form").submit();
});
return;
}
$(".HomeWorkCon form").submit();
});
$('form.edit_student_work').on('keydown', '#program-src', function(){
tested = false;
})
});

File diff suppressed because one or more lines are too long

View File

@ -4,10 +4,10 @@ $(function(){
$("#users_setting").css("min-height",$("#LSide").height()-35);
//头像相关
$("#homepage_portrait_image").live("mouseover",function(){
$("#homepage_portrait_image").on("mouseover",function(){
$("#edit_user_file_btn").show();
$("#watch_user_btn").show();
}).live("mouseout",function(){
}).on("mouseout",function(){
$("#edit_user_file_btn").hide();
$("#watch_user_btn").hide();
});