From 401b0bc7e3911c5bb2da5eadddff92b7504b6a3a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 9 Sep 2015 16:50:46 +0800 Subject: [PATCH] =?UTF-8?q?textarea=E8=87=AA=E5=8A=A8=E6=8B=89=E4=BC=B8?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E4=BC=98=E5=8C=96=EF=BC=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E4=BD=9C=E4=B8=9A=E4=BD=9C=E5=93=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_work/edit.html.erb | 106 +++++++++--------- app/views/student_work/new.html.erb | 31 ++---- public/javascripts/new_user.js | 157 ++++++++++++--------------- 3 files changed, 134 insertions(+), 160 deletions(-) diff --git a/app/views/student_work/edit.html.erb b/app/views/student_work/edit.html.erb index 5bb362b46..deb6a1201 100644 --- a/app/views/student_work/edit.html.erb +++ b/app/views/student_work/edit.html.erb @@ -1,54 +1,62 @@ -
-
-
编辑作品
-
-
-
-
- <%= labelled_form_for @work,:html => { :multipart => true } do |f|%> -
-

- - - 项目信息 - - -

-

-

-
- -

- - <%= f.select :project,options_for_select(user_projects_option,@work.project_id), {},{:class => "bo02 mb10"} %> -

-
+
+
编辑作品
+
+
-

- - -

-

-
-

- - <%= render :partial => 'attachments/new_form',:locals => {:container => @work} %> -

-
-

- 提交作品 - <%= link_to "返  回".html_safe, student_work_index_path(:homework => @homework), :class => "blue_btn grey_btn fl c_white mt10 ml10"%> -

-

-
- <% end%> +
+
+
+
+ <%= @homework.name%>(作业名称) +
+ + 截止时间:<%= @homework.end_time%> + +
+ + <%= link_to @homework.user.show_name, user_activities_path(@homework.user_id), :class => "c_blue"%> + +
+
+ <%= @homework.description.html_safe %>
-
-
-
+
+
+ +
+ <%= labelled_form_for @work,:html => { :multipart => true } do |f|%> +
+ 提示:作品名称和描述中不要出现真实的姓名信息 +
+
+ +
+ +
+

+
+
+ + +
+

+
+ +
+ <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @work, :has_program=>false} %> +
+ +
+ 确定 + + <%= link_to "取消", student_work_index_path(:homework => @homework), :class => "fr mr10 mt3"%> +
+
+ <% end%> +
diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index 703447756..1f9f547a0 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -16,23 +16,6 @@ // alert("当前作业已开启匿评,您提交作品后将不会收到任何匿评作品,您的作品也不会被其他用户匿评,如需获得最终成绩,请您联系主讲老师对您的作品单独进行评分"); }); <% end%> - - $(function(){ - $('#student_work_description').autoResize({ - // On resize: - onResize : function() { - $(this).css({opacity:0.8}); - }, - // After resize: - animateCallback : function() { - $(this).css({opacity:1}); - }, - // Quite slow animation: - animateDuration : 100, - // More extra space: - extraSpace : 0 - }); - });
@@ -62,7 +45,7 @@
-
+
<%= form_for(@student_work, :html => { :multipart => true }, :url => {:controller => 'student_work', @@ -70,19 +53,23 @@ :homework => @homework.id }) do |f|%>
- 提示:匿评作业提交的作品,作品名称和描述中不能出现真实的姓名信息 + 提示:作品名称和描述中不要出现真实的姓名信息
-
+
<%= f.text_field "name", :required => true, :size => 60, :class => "InputBox W700", :maxlength => 200, :placeholder => "请简洁的概括作品的功能或特性", :onkeyup => "regexStudentWorkName();" %>
-

+

<%= f.text_area "description", :class => "InputBox W700 H150", :placeholder => "请介绍你的作品", :onkeyup => "regexStudentWorkDescription();"%> +
-

+

diff --git a/public/javascripts/new_user.js b/public/javascripts/new_user.js index 9ffbf8b93..8362217a7 100644 --- a/public/javascripts/new_user.js +++ b/public/javascripts/new_user.js @@ -179,94 +179,73 @@ function regexStudentWorkDescription() } } -//textarea自适应高度 -(function($){ - - $.fn.autoResize = function(options) { - - // Just some abstracted details, - // to make plugin users happy: - var settings = $.extend({ - onResize : function(){}, - animate : true, - animateDuration : 150, - animateCallback : function(){}, - extraSpace : 20, - limit: 1000 - }, options); - - // Only textarea's auto-resize: - this.filter('textarea').each(function(){ - - // Get rid of scrollbars and disable WebKit resizing: - var textarea = $(this).css({resize:'none','overflow-y':'hidden'}), - - // Cache original height, for use later: - origHeight = textarea.height(), - - // Need clone of textarea, hidden off screen: - clone = (function(){ - - // Properties which may effect space taken up by chracters: - var props = ['height','width','lineHeight','textDecoration','letterSpacing'], - propOb = {}; - - // Create object of styles to apply: - $.each(props, function(i, prop){ - propOb[prop] = textarea.css(prop); - }); - - // Clone the actual textarea removing unique properties - // and insert before original textarea: - return textarea.clone().removeAttr('id').removeAttr('name').css({ - position: 'absolute', - top: 0, - left: -9999 - }).css(propOb).attr('tabIndex','-1').insertBefore(textarea); - - })(), - lastScrollTop = null, - updateSize = function() { - - // Prepare the clone: - clone.height(0).val($(this).val()).scrollTop(10000); - - // Find the height of text: - var scrollTop = Math.max(clone.scrollTop(), origHeight) + settings.extraSpace, - toChange = $(this).add(clone); - - // Don't do anything if scrollTip hasen't changed: - if (lastScrollTop === scrollTop) { return; } - lastScrollTop = scrollTop; - - // Check for limit: - if ( scrollTop >= settings.limit ) { - $(this).css('overflow-y','hidden'); - return; - } - // Fire off callback: - settings.onResize.call(this); - - // Either animate or directly apply height: - settings.animate && textarea.css('display') === 'block' ? - toChange.stop().animate({height:scrollTop}, settings.animateDuration, settings.animateCallback) - : toChange.height(scrollTop); - }; - - // Bind namespaced handlers to appropriate events: - textarea - .unbind('.dynSiz') - .bind('keyup.dynSiz', updateSize) - .bind('keydown.dynSiz', updateSize) - .bind('change.dynSiz', updateSize); - - }); - - // Chain: - return this; - +//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); + }; }; - - -})(jQuery); \ No newline at end of file + addEvent('propertychange', change); + addEvent('input', change); + addEvent('focus', change); + change(); +}; \ No newline at end of file