From bb8a6af13e35eeaa1ce73ff8a15b5e57bc425285 Mon Sep 17 00:00:00 2001 From: linchun Date: Fri, 4 Mar 2016 15:31:40 +0800 Subject: [PATCH 01/44] =?UTF-8?q?admin=E7=95=8C=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B2=BE=E5=93=81=E8=AF=BE=E7=A8=8B=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E7=9B=AE=E5=89=8D=E8=AF=A5=E9=A1=B5=E9=9D=A2=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=B2=BE=E5=93=81=E8=AF=BE=E7=A8=8B=E6=98=AF=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 7 ++ app/helpers/courses_helper.rb | 5 ++ app/views/admin/excellent_courses.html.erb | 75 ++++++++++++++++++++++ config/locales/en.yml | 1 + config/locales/zh.yml | 1 + config/routes.rb | 1 + db/schema.rb | 7 +- lib/redmine.rb | 1 + 8 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/excellent_courses.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 01703f679..1701e6b7c 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -49,6 +49,13 @@ class AdminController < ApplicationController end end + def excellent_courses + @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) + respond_to do |format| + format.html + end + end + def users sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 2cdb277be..1875f920d 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -71,6 +71,11 @@ module CoursesHelper project.members.count end + # 统计课程中作品的数量 + def student_works_num course + StudentWork.find_by_sql("SELECT * FROM student_works WHERE homework_common_id IN (SELECT id FROM homework_commons WHERE course_id = '#{course.id}')").count + end + # 返回教师数量,即roles表中定义的Manager def teacherCount project project ? project.members.count - studentCount(project).to_i : 0 diff --git a/app/views/admin/excellent_courses.html.erb b/app/views/admin/excellent_courses.html.erb new file mode 100644 index 000000000..e21ba32aa --- /dev/null +++ b/app/views/admin/excellent_courses.html.erb @@ -0,0 +1,75 @@ +

+ <%=l(:label_excellent_courses_list)%> +

+ +
+ + + + + + + + + + + + + + + + <% @courses.each do |course| %> + "> + + + + + + + + + + + <% end %> + +
+ 序号 + + 课程名 + + 主讲老师 + + 学生数 + + 作业数 + + 作品数 + + 资源数 + + 帖子数 + + 动态数 +
+ <%= course.id %> + + + <%= link_to(course.name, course_path(course.id)) %> + + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + <%= studentCount(course) %> + + <%= course.homework_commons.count%> + + <%= student_works_num(course) %> + + <%= visable_attachemnts_incourse(course).count%> + + <%= course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", course.boards.first.id, nil).count %> + + + <%= course.course_activities.count%> +
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bed45103..ec4d69147 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1520,6 +1520,7 @@ en: label_submit_comments: Submit_comments label_course_empty_select: You have not selected course! label_enterprise_page_made: enterprise_page + label_excellent_courses_list: excellent_courses #api label_recently_updated_notification: Recently updated notification diff --git a/config/locales/zh.yml b/config/locales/zh.yml index e9d3ed813..98983ffa7 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -483,6 +483,7 @@ zh: label_requirement: 需求 label_new_course: 课程列表 label_course_all: 课程列表 + label_excellent_courses_list: 精品课程列表 label_teacher_all: 所有教师 label_requirement_enterprise_list: 众包列表 label_new_homework: 作业 diff --git a/config/routes.rb b/config/routes.rb index 7754365ad..445cecaf9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -933,6 +933,7 @@ RedmineApp::Application.routes.draw do match 'admin', :to => 'admin#index', :via => :get match 'admin/projects', :via => :get get 'admin/courses' + get 'admin/excellent_courses' match 'admin/users', :via => :get match 'admin/messages', :via => :get match 'admin/first_page_made', as: :first_page_made diff --git a/db/schema.rb b/db/schema.rb index 2593e09fd..2dad292f4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160224074034) do +ActiveRecord::Schema.define(:version => 20160225031230) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -2013,6 +2013,11 @@ ActiveRecord::Schema.define(:version => 20160224074034) do add_index "wikis", ["project_id"], :name => "wikis_project_id" + create_table "wlcs", :force => true do |t| + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "workflows", :force => true do |t| t.integer "tracker_id", :default => 0, :null => false t.integer "old_status_id", :default => 0, :null => false diff --git a/lib/redmine.rb b/lib/redmine.rb index 8ebdacfa6..7bb43f905 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -391,6 +391,7 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :messages_list, {:controller => 'admin', :action => 'messages_list'}, :caption => :label_message_plural menu.push :notices, {:controller => 'admin', :action => 'notices'}, :caption => :label_notification_list menu.push :latest_login_users, {:controller => 'admin', :action => 'latest_login_users'}, :caption => :label_latest_login_user_list + menu.push :excellent_courses, {:controller => 'admin', :action => 'excellent_courses'}, :caption => :label_excellent_courses_list menu.push :homework, {:controller => 'admin', :action => 'homework'}, :caption => :label_user_homework end From b7f4b584f2c83d16456574a1c6bfc11caf0824c3 Mon Sep 17 00:00:00 2001 From: linchun Date: Mon, 7 Mar 2016 16:46:02 +0800 Subject: [PATCH 02/44] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=95=8C=E9=9D=A2=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 14 ++++ app/views/admin/course_resource_list.html.erb | 67 +++++++++++++++++++ .../_search_attachment_results.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/zh.yml | 1 + config/routes.rb | 1 + lib/redmine.rb | 1 + 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/course_resource_list.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 1701e6b7c..4259aa333 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -49,6 +49,7 @@ class AdminController < ApplicationController end end + #管理员界面精品课程列表 def excellent_courses @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) respond_to do |format| @@ -56,6 +57,19 @@ class AdminController < ApplicationController end end + #管理员界面课程资源列表 + def course_resource_list + @resource = Attachment.find_all_by_container_id(12) + + @resource = paginateHelper @resource,30 + @page = (params['page'] || 1).to_i - 1 + + respond_to do |format| + format.html + end + + end + def users sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb new file mode 100644 index 000000000..7a2ac1af1 --- /dev/null +++ b/app/views/admin/course_resource_list.html.erb @@ -0,0 +1,67 @@ +

<%=l(:label_course_resource_list)%>

+ + +
+ + + + + + + + + + + + + + + <% @resource.each do |resource| %> + "> + + + + + + + + + <% end %> + + + + +
+ 资源名称 + + 资源大小 + + 资源类型 + + 上传时间 + + 下载次数 + + 上传者 + + 所属课程 +
+ <%= resource.filename %> + + <%= number_to_human_size(resource.filesize)%> + + 课程资源 + + <%= format_date(resource.created_on)%> + + <%= resource.downloads %> + + <%= link_to(User.find(resource.author_id).realname, user_path(User.find(resource.author_id)) ) %> + + <%=link_to Course.find(resource.container_id).name, course_path(Course.find(resource.container_id)), :class => "hidden fl w170" %> +
+
+ + \ No newline at end of file diff --git a/app/views/welcome/_search_attachment_results.html.erb b/app/views/welcome/_search_attachment_results.html.erb index 21ba68336..e51706085 100644 --- a/app/views/welcome/_search_attachment_results.html.erb +++ b/app/views/welcome/_search_attachment_results.html.erb @@ -21,6 +21,6 @@ <% end %>
- <%= paginate attachments,:params => {:controller => 'welcome', :action => 'search',:search_type=>'attachment'}%> + {:controller => 'welcome', :action => 'search',:search_type=>'attachment'}%>
<% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index ec4d69147..86a285342 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1521,6 +1521,7 @@ en: label_course_empty_select: You have not selected course! label_enterprise_page_made: enterprise_page label_excellent_courses_list: excellent_courses + label_course_resource_list: course_resource_list #api label_recently_updated_notification: Recently updated notification diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 98983ffa7..8884b0e67 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -484,6 +484,7 @@ zh: label_new_course: 课程列表 label_course_all: 课程列表 label_excellent_courses_list: 精品课程列表 + label_course_resource_list: 课程资源列表 label_teacher_all: 所有教师 label_requirement_enterprise_list: 众包列表 label_new_homework: 作业 diff --git a/config/routes.rb b/config/routes.rb index 445cecaf9..e92590895 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -934,6 +934,7 @@ RedmineApp::Application.routes.draw do match 'admin/projects', :via => :get get 'admin/courses' get 'admin/excellent_courses' + get 'admin/course_resource_list' match 'admin/users', :via => :get match 'admin/messages', :via => :get match 'admin/first_page_made', as: :first_page_made diff --git a/lib/redmine.rb b/lib/redmine.rb index 7bb43f905..21309b710 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -392,6 +392,7 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :notices, {:controller => 'admin', :action => 'notices'}, :caption => :label_notification_list menu.push :latest_login_users, {:controller => 'admin', :action => 'latest_login_users'}, :caption => :label_latest_login_user_list menu.push :excellent_courses, {:controller => 'admin', :action => 'excellent_courses'}, :caption => :label_excellent_courses_list + menu.push :var, {:controller => 'admin', :action => 'course_resource_list'}, :caption => :label_course_resource_list menu.push :homework, {:controller => 'admin', :action => 'homework'}, :caption => :label_user_homework end From 3c66a297673f1f6ee3102a5c0049c984783307e0 Mon Sep 17 00:00:00 2001 From: linchun Date: Tue, 8 Mar 2016 11:01:08 +0800 Subject: [PATCH 03/44] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=88=97=E8=A1=A8=EF=BC=8C=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=B5=84=E6=BA=90=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 14 +++- app/views/admin/course_resource_list.html.erb | 21 +++--- .../admin/project_resource_list.html.erb | 64 +++++++++++++++++++ config/locales/en.yml | 1 + config/locales/zh.yml | 1 + config/routes.rb | 1 + lib/redmine.rb | 3 +- 7 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 app/views/admin/project_resource_list.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4259aa333..7ff36c11d 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -59,17 +59,27 @@ class AdminController < ApplicationController #管理员界面课程资源列表 def course_resource_list - @resource = Attachment.find_all_by_container_id(12) - + @resource = Attachment.where(:container_type => 'Course') @resource = paginateHelper @resource,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html end + end + + #管理员界面項目资源列表 + def project_resource_list + @pro_resource = Attachment.where(:container_type => 'Project') + @pro_resource = paginateHelper @pro_resource,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end end + def users sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb index 7a2ac1af1..4316555f7 100644 --- a/app/views/admin/course_resource_list.html.erb +++ b/app/views/admin/course_resource_list.html.erb @@ -6,25 +6,25 @@ - + 资源名称 - + 资源大小 - + 资源类型 - + 上传时间 - + 下载次数 上传者 - + 所属课程 @@ -33,10 +33,10 @@ <% @resource.each do |resource| %> "> - <%= resource.filename %> + <%= link_to truncate(resource.filename, :length => 18), download_named_attachment_path(resource.id, resource.filename ), :title => resource.filename,:class=>'resourcesBlack'%> - <%= number_to_human_size(resource.filesize)%> + <%= number_to_human_size(resource.filesize)%> 课程资源 @@ -51,13 +51,10 @@ <%= link_to(User.find(resource.author_id).realname, user_path(User.find(resource.author_id)) ) %> - <%=link_to Course.find(resource.container_id).name, course_path(Course.find(resource.container_id)), :class => "hidden fl w170" %> + <%=link_to truncate(Course.find(resource.container_id).name, :length => 10), course_path(Course.find(resource.container_id)), :title => Course.find(resource.container_id).name, :class => "hidden fl w170" %> <% end %> - - - diff --git a/app/views/admin/project_resource_list.html.erb b/app/views/admin/project_resource_list.html.erb new file mode 100644 index 000000000..c245f73b8 --- /dev/null +++ b/app/views/admin/project_resource_list.html.erb @@ -0,0 +1,64 @@ +

<%=l(:label_project_resource_list)%>

+ + +
+ + + + + + + + + + + + + + + <% @pro_resource.each do |pro_resource| %> + "> + + + + + + + + + <% end %> + +
+ 资源名称 + + 资源大小 + + 资源类型 + + 上传时间 + + 下载次数 + + 上传者 + + 所属项目 +
+ <%= link_to truncate(pro_resource.filename, :length => 18), download_named_attachment_path(pro_resource.id, pro_resource.filename ), :title => pro_resource.filename,:class=>'resourcesBlack'%> + + <%= number_to_human_size(pro_resource.filesize)%> + + 项目资源 + + <%= format_date(pro_resource.created_on)%> + + <%= pro_resource.downloads %> + + <%= link_to(User.find(pro_resource.author_id).realname, user_path(User.find(pro_resource.author_id)) ) %> + + <%=link_to truncate(Project.find(pro_resource.container_id).name, :length => 10), project_path(Project.find(pro_resource.container_id)), :title => Project.find(pro_resource.container_id).name, :class => "hidden fl w170" %> +
+
+ + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 86a285342..3da533eb7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1522,6 +1522,7 @@ en: label_enterprise_page_made: enterprise_page label_excellent_courses_list: excellent_courses label_course_resource_list: course_resource_list + label_project_resource_list: project_resource_list #api label_recently_updated_notification: Recently updated notification diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 8884b0e67..b6bd6afa4 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -485,6 +485,7 @@ zh: label_course_all: 课程列表 label_excellent_courses_list: 精品课程列表 label_course_resource_list: 课程资源列表 + label_project_resource_list: 項目资源列表 label_teacher_all: 所有教师 label_requirement_enterprise_list: 众包列表 label_new_homework: 作业 diff --git a/config/routes.rb b/config/routes.rb index e92590895..de1d9d652 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -935,6 +935,7 @@ RedmineApp::Application.routes.draw do get 'admin/courses' get 'admin/excellent_courses' get 'admin/course_resource_list' + get 'admin/project_resource_list' match 'admin/users', :via => :get match 'admin/messages', :via => :get match 'admin/first_page_made', as: :first_page_made diff --git a/lib/redmine.rb b/lib/redmine.rb index 21309b710..47ee3d38f 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -392,7 +392,8 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :notices, {:controller => 'admin', :action => 'notices'}, :caption => :label_notification_list menu.push :latest_login_users, {:controller => 'admin', :action => 'latest_login_users'}, :caption => :label_latest_login_user_list menu.push :excellent_courses, {:controller => 'admin', :action => 'excellent_courses'}, :caption => :label_excellent_courses_list - menu.push :var, {:controller => 'admin', :action => 'course_resource_list'}, :caption => :label_course_resource_list + menu.push :course_resource_list, {:controller => 'admin', :action => 'course_resource_list'}, :caption => :label_course_resource_list + menu.push :project_resource_list, {:controller => 'admin', :action => 'project_resource_list'}, :caption => :label_project_resource_list menu.push :homework, {:controller => 'admin', :action => 'homework'}, :caption => :label_user_homework end From e073d581691cdc77b35b841d0496b23bc02fdb6c Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 9 Mar 2016 10:16:27 +0800 Subject: [PATCH 04/44] =?UTF-8?q?KE=E7=9A=84=E5=87=A0=E4=B8=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9=201.=E6=88=91=E8=A6=81=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=202.=E6=AE=B5=E8=90=BD=E9=A2=9C=E8=89=B2=203.?= =?UTF-8?q?=E5=8F=98=E7=B2=97=E6=BB=9A=E5=8A=A8=E6=9D=A1=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=204.=E6=B2=A1=E9=BB=98=E8=AE=A4=E5=AD=97=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/kindeditor/kindeditor.js | 2 +- public/assets/kindeditor/plugins/code/previewcode.css | 1 + public/assets/kindeditor/plugins/image/image.js | 3 +++ public/assets/kindeditor/plugins/media/media.js | 3 +++ public/assets/kindeditor/plugins/preview/preview.js | 2 +- public/assets/kindeditor/plugins/table/table.js | 3 +++ public/stylesheets/new_user.css | 6 +++--- 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 6065a563f..6da24733c 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -2765,7 +2765,7 @@ _extend(KCmd, { sel.addRange(rng); if (doc !== document) { var pos = K(rng.endContainer).pos(); - win.scrollTo(pos.x, pos.y); + //win.scrollTo(pos.x, pos.y); } } win.focus(); diff --git a/public/assets/kindeditor/plugins/code/previewcode.css b/public/assets/kindeditor/plugins/code/previewcode.css index c8e5df4e1..7ccc0a6f9 100644 --- a/public/assets/kindeditor/plugins/code/previewcode.css +++ b/public/assets/kindeditor/plugins/code/previewcode.css @@ -1,5 +1,6 @@ .ke-content { font-size: 10pt; + font-family:Tahoma; } .ke-content pre { font-size:9pt; diff --git a/public/assets/kindeditor/plugins/image/image.js b/public/assets/kindeditor/plugins/image/image.js index 1c3f0dd45..82646d73a 100644 --- a/public/assets/kindeditor/plugins/image/image.js +++ b/public/assets/kindeditor/plugins/image/image.js @@ -98,6 +98,9 @@ KindEditor.plugin('image', function(K) { yesBtn : { name : self.lang('yes'), click : function(e) { + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(self.edit.html())){ + self.edit.html(''); + } // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319 if (dialog.isLoading) { return; diff --git a/public/assets/kindeditor/plugins/media/media.js b/public/assets/kindeditor/plugins/media/media.js index 6d0d3a387..e108d8595 100644 --- a/public/assets/kindeditor/plugins/media/media.js +++ b/public/assets/kindeditor/plugins/media/media.js @@ -47,6 +47,9 @@ KindEditor.plugin('media', function(K) { yesBtn : { name : self.lang('yes'), click : function(e) { + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(self.edit.html())){ + self.edit.html(''); + } var url = K.trim(urlBox.val()), width = widthBox.val(), height = heightBox.val(); diff --git a/public/assets/kindeditor/plugins/preview/preview.js b/public/assets/kindeditor/plugins/preview/preview.js index ef6e2cf16..c32c5a1c9 100644 --- a/public/assets/kindeditor/plugins/preview/preview.js +++ b/public/assets/kindeditor/plugins/preview/preview.js @@ -25,7 +25,7 @@ KindEditor.plugin('preview', function(K) { doc.open(); doc.write(self.fullHtml()); doc.close(); - K(doc.body).css('background-color', '#FFF'); + K(doc.body).css({'background-color': '#FFF','word-break':'break-all','word-wrap':'wrap-all'}); iframe[0].contentWindow.focus(); }); }); diff --git a/public/assets/kindeditor/plugins/table/table.js b/public/assets/kindeditor/plugins/table/table.js index 634e9b7fc..ba72a0ff8 100644 --- a/public/assets/kindeditor/plugins/table/table.js +++ b/public/assets/kindeditor/plugins/table/table.js @@ -129,6 +129,9 @@ KindEditor.plugin('table', function(K) { yesBtn : { name : self.lang('yes'), click : function(e) { + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(self.edit.html())){ + self.edit.html(''); + } var rows = rowsBox.val(), cols = colsBox.val(), width = widthBox.val(), diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index a923ae86f..d2ec8a8b9 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -32,9 +32,9 @@ table{ background:#fff;} .min_search{ width:150px; height:20px; border:1px solid #d0d0d0; color:#666; background:url(../images/public_icon.png) 135px -193px no-repeat; cursor:pointer;} .db {display:block;} /* font & color */ -h2{ font-size:18px; color:#269ac9;} -h3{ font-size:14px; color:#e8770d;} -h4{ font-size:14px; color:#3b3b3b;} +h2{ font-size:18px; } /*color:#269ac9;*/ +h3{ font-size:14px;}/* color:#e8770d;*/ +h4{ font-size:14px; }/*color:#3b3b3b;*/ .f12{font-size:12px; font-weight:normal;} .f14{font-size:14px;} .f16{font-size:16px;} From 5dcd3b682603834a8bfdf1891d62ed0b13f189b3 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 9 Mar 2016 15:32:08 +0800 Subject: [PATCH 05/44] =?UTF-8?q?=E8=A7=A3=E5=86=B3KE=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=E4=B8=80=E8=A1=8C=E4=B8=8E=E4=B8=A4=E8=A1=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/create_kindeditor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/javascripts/create_kindeditor.js b/public/javascripts/create_kindeditor.js index fc2ac8938..99f080165 100644 --- a/public/javascripts/create_kindeditor.js +++ b/public/javascripts/create_kindeditor.js @@ -11,10 +11,16 @@ function sd_create_editor(params){ height:"33px",// == undefined ? "30px":paramsHeight+"px", minHeight:"33px",// == undefined ? "30px":paramsHeight+"px", width:params.width, + /* items:['emoticons','fontname', 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', 'formatblock', 'fontsize', '|','indent', 'outdent', - '|','imagedirectupload','more'], + '|','imagedirectupload','more'],*/ + items : ['code','emoticons','fontname', + 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', + 'formatblock', 'fontsize', '|','indent', 'outdent', + '|','imagedirectupload','table', 'media', 'preview',"more" + ], afterChange:function(){//按键事件 var edit = this.edit; var body = edit.doc.body; From 1c6deadfd7cb7251f07337c8e128fa39d2825cb3 Mon Sep 17 00:00:00 2001 From: luoquan <545501972@qq.com> Date: Thu, 10 Mar 2016 10:58:43 +0800 Subject: [PATCH 06/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9KE=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E4=B8=8E=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=AF=B9=E5=85=B6=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/stylesheets/new_user.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index a923ae86f..050ac1341 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -702,7 +702,7 @@ a.postOptionLink:hover {color:#ffffff; background-color:#269ac9;} .imageFuzzy {filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity:0.5;opacity: 0.5;} .homepagePostReplyDes {float:left; width:642px; margin-left:15px;} .homepagePostReplyPublisher {font-size:12px; color:#888888; margin-bottom:5px;} -.homepagePostReplyContent {font-size:12px; color:#484848; margin-bottom:12px;} +.homepagePostReplyContent {font-size:12px; color:#484848; margin:3px 5px 12px 5px;font: 14px/1.5 "sans serif",tahoma,verdana,helvetica;font-family: 微软雅黑, 宋体;} .table_maxWidth table {max-width: 642px;} .homepagePostProjectState {width:52px; height:20px; line-height:20px; border-radius:1px; background-color:#28be6c; color:#ffffff; text-align:center; vertical-align:middle; font-size:12px; display:inline-block; margin-left:5px;} .homepagePostAssignTo {float:left; font-size:14px; color:#269ac9;} From 352f06887ff4af20a66d8139f90652c640f1c943 Mon Sep 17 00:00:00 2001 From: luoquan <545501972@qq.com> Date: Thu, 10 Mar 2016 11:01:58 +0800 Subject: [PATCH 07/44] 0 --- test/unit/poll_votes_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/poll_votes_test.rb b/test/unit/poll_votes_test.rb index 77ab9121e..04d266f1d 100644 --- a/test/unit/poll_votes_test.rb +++ b/test/unit/poll_votes_test.rb @@ -1,7 +1,7 @@ -require 'test_helper' - -class PollVotesTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end +require 'test_helper' + +class PollVotesTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From a6da304b56219f66ca8f096ab582c0bd9118c1e5 Mon Sep 17 00:00:00 2001 From: luoquan <545501972@qq.com> Date: Thu, 10 Mar 2016 11:10:05 +0800 Subject: [PATCH 08/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9KE=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E5=90=8E=E5=8F=91=E5=B8=83=E5=AF=B9=E4=B8=8D?= =?UTF-8?q?=E9=BD=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kindeditor/plugins/code/previewcode.css | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/public/assets/kindeditor/plugins/code/previewcode.css b/public/assets/kindeditor/plugins/code/previewcode.css index c8e5df4e1..03f0b69a8 100644 --- a/public/assets/kindeditor/plugins/code/previewcode.css +++ b/public/assets/kindeditor/plugins/code/previewcode.css @@ -1,49 +1,50 @@ -.ke-content { - font-size: 10pt; -} -.ke-content pre { - font-size:9pt; - font-family:Courier New,Arial; - border:1px solid #ddd; - border-left:5px solid #6CE26C; - background:#f6f6f6; - padding:5px; -} - -.ke-content code { - margin: 0 2px; - padding: 0 5px; - white-space: nowrap; - border: 1px solid #DDD; - background-color: #F6F6F6; - border-radius: 3px; -} - -.ke-content pre>code { - margin: 0; - padding: 0; - white-space: pre; - border: none; - background: transparent; -} - -.ke-content pre code { - background-color: transparent; - border: none; -} - -.ke-content p { - /*margin: 0 0 15px 0;*/ - /*margin-bottom:15pt;*/ - line-height:1.5; - /*letter-spacing: 1px;*/ -} - -.ke-content div.ref {border:1px solid #ddd;margin:0 0 10px 0;padding:2px;font-size:9pt;background:#ffe;} -.ke-content div.ref h4 {margin:0;padding:1px 3px;background:#CC9966;color:#fff;font-size:9pt;font-weight:normal;} -.ke-content div.ref .ref_body {margin:0;padding:2px;line-height:20px;color:#666;font-size:9pt;} - - -.ke-content blockquote {margin:15px 10px;border:2px solid #eee;padding:5px 5px 5px 35px;background:#f4f5f7 url('../img/blockquote.gif') no-repeat left top;color:#060;font-size:9pt;} -span.at {color:#269ac9;} +.ke-content { + font-size: 12px; + font: 14px/1.5 "sans serif",tahoma,verdana,helvetica;font-family: 微软雅黑, 宋体; +} +.ke-content pre { + font-size:9pt; + font-family:Courier New,Arial; + border:1px solid #ddd; + border-left:5px solid #6CE26C; + background:#f6f6f6; + padding:5px; +} + +.ke-content code { + margin: 0 2px; + padding: 0 5px; + white-space: nowrap; + border: 1px solid #DDD; + background-color: #F6F6F6; + border-radius: 3px; +} + +.ke-content pre>code { + margin: 0; + padding: 0; + white-space: pre; + border: none; + background: transparent; +} + +.ke-content pre code { + background-color: transparent; + border: none; +} + +.ke-content p { + /*margin: 0 0 15px 0;*/ + /*margin-bottom:15pt;*/ + line-height:1.5; + /*letter-spacing: 1px;*/ +} + +.ke-content div.ref {border:1px solid #ddd;margin:0 0 10px 0;padding:2px;font-size:9pt;background:#ffe;} +.ke-content div.ref h4 {margin:0;padding:1px 3px;background:#CC9966;color:#fff;font-size:9pt;font-weight:normal;} +.ke-content div.ref .ref_body {margin:0;padding:2px;line-height:20px;color:#666;font-size:9pt;} + + +.ke-content blockquote {margin:15px 10px;border:2px solid #eee;padding:5px 5px 5px 35px;background:#f4f5f7 url('../img/blockquote.gif') no-repeat left top;color:#060;font-size:9pt;} +span.at {color:#269ac9;} span.at a{color:#269ac9;text-decoration: none;} \ No newline at end of file From 5ea618b52082db27d8251342338aedf0c769a4f8 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 10 Mar 2016 11:16:39 +0800 Subject: [PATCH 09/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9KE=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=B2=A1=E6=98=BE=E7=A4=BA=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/kindeditor/kindeditor.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 6da24733c..2d164f0ba 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -5646,6 +5646,26 @@ _plugin('core', function(K) { }else{ //TODO 暂时什么也不做 } + var _bod = $(self.cmd.doc.body); + var body = self.cmd.doc.body; + var _bw = _bod.width(),_bh = Math.max((K.IE ? body.scrollHeight : (K.GECKO ? body.offsetHeight+26:body.offsetHeight))); + var _bsh = 0; + _bod.children().each(function(){ + _bsh += $(this).height(); + }); + var _imgbase = _bod.find("img"); + _imgbase[0].onload = function(){ + var _iw=_imgbase.width(),_ih = _imgbase.height(); + var _alh = _bsh + _ih; + var _rhig = _alh > _bh ? _alh : _bh; + switch(self.resizeType){ + case 1: + var _defh = self.toolbar.div.height() + self.statusbar.height(); + _defh = _defh > 0 ? _defh + 6 : _defh; + self.resize(null,_rhig + _defh); + break; + } + } } else { alert(data.message); } From 9b5cd8f8807688ac78cd53c0c4fdf25ce32b7fe8 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 10 Mar 2016 11:28:56 +0800 Subject: [PATCH 10/44] =?UTF-8?q?KE=E8=A1=A8=E6=A0=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/kindeditor/plugins/table/table.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/assets/kindeditor/plugins/table/table.js b/public/assets/kindeditor/plugins/table/table.js index ba72a0ff8..c96ab0326 100644 --- a/public/assets/kindeditor/plugins/table/table.js +++ b/public/assets/kindeditor/plugins/table/table.js @@ -228,8 +228,10 @@ KindEditor.plugin('table', function(K) { } if (borderColor !== '') { table.attr('borderColor', borderColor); + table.css("border-color",borderColor); } else { table.removeAttr('borderColor'); + table.css("border-color","none"); } self.hideDialog().focus(); self.cmd.range.moveToBookmark(bookmark); @@ -251,7 +253,10 @@ KindEditor.plugin('table', function(K) { if (border !== ''){ style += 'border:'+border+'px solid;'; } - + if (borderColor !== ''){ + style += 'border-color:'+borderColor+';'; + } + style += 'table-layout: '+'fixed;'; var html = '') + ''; + html += '' + (K.IE ? ' ' : '
') + ''; } html += ''; } From 7f7979e9559a4f0ba1ebcf4e9a2f1b4e4627fe16 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 10 Mar 2016 15:12:16 +0800 Subject: [PATCH 11/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E5=A4=9A=E6=AC=A1=E7=82=B9=E5=87=BB=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=8C=89=E9=92=AE=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/blog_comments/_simple_ke_reply_form.html.erb | 2 +- app/views/blogs/_article.html.erb | 2 +- app/views/courses/syllabus.html.erb | 2 +- app/views/issues/_issue_replies.html.erb | 2 +- app/views/issues/_issue_reply_ke_form.html.erb | 2 +- app/views/memos/show.html.erb | 2 +- app/views/messages/_reply_message.html.erb | 2 +- app/views/org_document_comments/_simple_ke_reply_form.html.erb | 2 +- app/views/organizations/_org_course_homework.html.erb | 2 +- app/views/organizations/_org_course_message.html.erb | 2 +- app/views/organizations/_org_course_news.html.erb | 2 +- app/views/organizations/_org_project_issue.html.erb | 2 +- app/views/organizations/_org_subfield_message.html.erb | 2 +- app/views/organizations/_org_subfield_news.html.erb | 2 +- app/views/organizations/_project_message.html.erb | 2 +- app/views/organizations/_show_org_document.html.erb | 2 +- app/views/projects/_project_news.html.erb | 2 +- app/views/users/_course_homework.html.erb | 2 +- app/views/users/_course_journalsformessage.html.erb | 2 +- app/views/users/_course_message.html.erb | 2 +- app/views/users/_course_news.html.erb | 2 +- app/views/users/_project_issue_reply.html.erb | 2 +- app/views/users/_project_message.html.erb | 2 +- app/views/users/_project_news.html.erb | 2 +- app/views/users/_user_blog.html.erb | 2 +- app/views/users/_user_homework_detail.html.erb | 2 +- app/views/users/_user_journalsformessage.html.erb | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index e222d8e56..0d989c50a 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -10,7 +10,7 @@
-
+

<% end%> diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 05f69055f..858fefb08 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -200,7 +200,7 @@
- +

<% end%> diff --git a/app/views/courses/syllabus.html.erb b/app/views/courses/syllabus.html.erb index e12876ce9..e9d735900 100644 --- a/app/views/courses/syllabus.html.erb +++ b/app/views/courses/syllabus.html.erb @@ -192,7 +192,7 @@
- +

<% end%> diff --git a/app/views/issues/_issue_replies.html.erb b/app/views/issues/_issue_replies.html.erb index 4c5c922f0..a1a567101 100644 --- a/app/views/issues/_issue_replies.html.erb +++ b/app/views/issues/_issue_replies.html.erb @@ -74,7 +74,7 @@ <%= render :partial => 'attachments/issue_reply', :locals => {:container => @issue} %> - +
<% end %> diff --git a/app/views/issues/_issue_reply_ke_form.html.erb b/app/views/issues/_issue_reply_ke_form.html.erb index e84d5905c..16bdade05 100644 --- a/app/views/issues/_issue_reply_ke_form.html.erb +++ b/app/views/issues/_issue_reply_ke_form.html.erb @@ -16,7 +16,7 @@
- +
<% end %> diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index 16bc5c742..4feb998cf 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -113,7 +113,7 @@ <%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %>
- +

<% end%> diff --git a/app/views/messages/_reply_message.html.erb b/app/views/messages/_reply_message.html.erb index 2d957dbda..d0cec9e62 100644 --- a/app/views/messages/_reply_message.html.erb +++ b/app/views/messages/_reply_message.html.erb @@ -8,7 +8,7 @@
- +

<% end%> diff --git a/app/views/org_document_comments/_simple_ke_reply_form.html.erb b/app/views/org_document_comments/_simple_ke_reply_form.html.erb index 44eb71500..6280db653 100644 --- a/app/views/org_document_comments/_simple_ke_reply_form.html.erb +++ b/app/views/org_document_comments/_simple_ke_reply_form.html.erb @@ -7,7 +7,7 @@
- +

<% end%> diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index 499ea6357..a437acc7e 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -356,7 +356,7 @@ <%= hidden_field_tag 'course_activity',params[:course_activity],:value =>course_activity %>
- +

<% end%> diff --git a/app/views/organizations/_org_course_message.html.erb b/app/views/organizations/_org_course_message.html.erb index 99229634e..4873fbba9 100644 --- a/app/views/organizations/_org_course_message.html.erb +++ b/app/views/organizations/_org_course_message.html.erb @@ -144,7 +144,7 @@
- +

<% end%> diff --git a/app/views/organizations/_org_course_news.html.erb b/app/views/organizations/_org_course_news.html.erb index ecdf728f8..213fc0e0b 100644 --- a/app/views/organizations/_org_course_news.html.erb +++ b/app/views/organizations/_org_course_news.html.erb @@ -110,7 +110,7 @@
- +

<% end%> diff --git a/app/views/organizations/_org_project_issue.html.erb b/app/views/organizations/_org_project_issue.html.erb index 855a8053c..e403e86a3 100644 --- a/app/views/organizations/_org_project_issue.html.erb +++ b/app/views/organizations/_org_project_issue.html.erb @@ -127,7 +127,7 @@
- +

<% end%> diff --git a/app/views/organizations/_org_subfield_message.html.erb b/app/views/organizations/_org_subfield_message.html.erb index aa2493c5f..a89b37b46 100644 --- a/app/views/organizations/_org_subfield_message.html.erb +++ b/app/views/organizations/_org_subfield_message.html.erb @@ -147,7 +147,7 @@
- +

<% end%> diff --git a/app/views/organizations/_org_subfield_news.html.erb b/app/views/organizations/_org_subfield_news.html.erb index edbdfa16b..5a96a1449 100644 --- a/app/views/organizations/_org_subfield_news.html.erb +++ b/app/views/organizations/_org_subfield_news.html.erb @@ -130,7 +130,7 @@
- +

<% end%> diff --git a/app/views/organizations/_project_message.html.erb b/app/views/organizations/_project_message.html.erb index 3b459f366..fef6a5651 100644 --- a/app/views/organizations/_project_message.html.erb +++ b/app/views/organizations/_project_message.html.erb @@ -122,7 +122,7 @@
- +

<% end%> diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index 2584e4209..d053341e1 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -119,7 +119,7 @@
- +

diff --git a/app/views/projects/_project_news.html.erb b/app/views/projects/_project_news.html.erb index 518ee3a2b..c3d4d5bfb 100644 --- a/app/views/projects/_project_news.html.erb +++ b/app/views/projects/_project_news.html.erb @@ -110,7 +110,7 @@
- +

<% end%> diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 9dd5eaa7a..5529998a7 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -356,7 +356,7 @@ <%= hidden_field_tag 'course_activity',params[:course_activity],:value =>course_activity %>
- +

<% end%> diff --git a/app/views/users/_course_journalsformessage.html.erb b/app/views/users/_course_journalsformessage.html.erb index 6b28fb568..79d609182 100644 --- a/app/views/users/_course_journalsformessage.html.erb +++ b/app/views/users/_course_journalsformessage.html.erb @@ -96,7 +96,7 @@ <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %>
- +

<% end%> diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index bb2a31dcc..df084357a 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -178,7 +178,7 @@
- +

<% end%> diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index 15dd486ec..560b76fd4 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -135,7 +135,7 @@
- +

<% end%> diff --git a/app/views/users/_project_issue_reply.html.erb b/app/views/users/_project_issue_reply.html.erb index adebd74ad..d76913e23 100644 --- a/app/views/users/_project_issue_reply.html.erb +++ b/app/views/users/_project_issue_reply.html.erb @@ -76,7 +76,7 @@
- +

<% end%> diff --git a/app/views/users/_project_message.html.erb b/app/views/users/_project_message.html.erb index 30183c4d1..dd2c832cf 100644 --- a/app/views/users/_project_message.html.erb +++ b/app/views/users/_project_message.html.erb @@ -154,7 +154,7 @@
- +

<% end%> diff --git a/app/views/users/_project_news.html.erb b/app/views/users/_project_news.html.erb index 9e02c4cf4..7f5d185e5 100644 --- a/app/views/users/_project_news.html.erb +++ b/app/views/users/_project_news.html.erb @@ -132,7 +132,7 @@
- +

<% end%> diff --git a/app/views/users/_user_blog.html.erb b/app/views/users/_user_blog.html.erb index 244951dfa..032f6b9a9 100644 --- a/app/views/users/_user_blog.html.erb +++ b/app/views/users/_user_blog.html.erb @@ -122,7 +122,7 @@
- +

<% end%> diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 9f3847735..0c34993b7 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -360,7 +360,7 @@ <%= hidden_field_tag 'is_in_course',params[:is_in_course],:value =>is_in_course %>
- +

<% end%> diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index f49a65262..c53f90273 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -139,7 +139,7 @@ <%= hidden_field_tag 'is_activity',params[:is_activity],:value =>is_activity %>
- +

<% end%> From 28b481cf36a1b6597860921d3afc62671143b6e2 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 10 Mar 2016 15:37:07 +0800 Subject: [PATCH 12/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9KE=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=97=B6=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=9D=9E=E5=9B=BE=E7=89=87=E6=A0=BC=E5=BC=8F=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/kindeditor/kindeditor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 2d164f0ba..bb52ee067 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -5667,7 +5667,8 @@ _plugin('core', function(K) { } } } else { - alert(data.message); + //alert(data.message); + alert("仅支持如下图片格式:bmp,jpeg,jpg,png,gif,BMP,JPEG,JPG,PNG,GIF"); } }, afterError : function(str) { From c2553253006460c3533f7e00d3ca80b09df59671 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 10 Mar 2016 15:47:03 +0800 Subject: [PATCH 13/44] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/_new_member_list.html.erb | 54 ++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index fd33d5a19..65429b995 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -24,7 +24,8 @@
  • 姓名
  • 学号
  • -
  • +
  • 分班
  • +
  • <%= link_to '作业积分', member_score_sort_course_path(:sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? @group.id : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true%> <% if @score_sort_by == 'desc' %> @@ -58,11 +59,26 @@
  • <%= link_to("#{l(:label_bidding_user_studentcode)}:#{member.user.user_extensions.student_id}".html_safe,user_path(member.user)) %>
  • <% end%>
+ <% if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %> +
+
+ + <% else %> +
+ +
+ <% end %> <%= link_to format("%0.2f",member.score.nil? ? 0 : member.score.to_s), { :action => 'show_member_score', :member_id => member.id, :remote => true}, - :class => 'ml258 c_red' %> + :class => 'ml25 c_red' %> <%= format_date(member.created_on)%> <%= call_hook(:view_projects_settings_members_table_row, { :course => @course, :member => member}) %> @@ -79,3 +95,37 @@

<% end%> + + From 0d8052da28e9308c51c32bab42da3186af2643b8 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 10 Mar 2016 17:04:26 +0800 Subject: [PATCH 14/44] =?UTF-8?q?=E8=80=81=E5=B8=88=E6=8A=8A=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=8A=A0=E5=85=A5=E6=9F=90=E4=B8=80=E4=B8=AA=E5=88=86?= =?UTF-8?q?=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 ++++ app/helpers/courses_helper.rb | 18 ++++++++++ app/views/courses/_new_member_list.html.erb | 35 +++++++++++++------ app/views/courses/teacher_assign_group.js.erb | 0 config/routes.rb | 1 + 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 app/views/courses/teacher_assign_group.js.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 708ac9a14..81c21eb3d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -240,6 +240,13 @@ class CoursesController < ApplicationController # req[:message] = l(:modal_valid_passing) if req[:message].blank? render :json => req end + + def teacher_assign_group + member = Member.where(:course_id => @course.id, :user_id => User.current.id).first + member.course_group_id = params[:course_group_id].to_i + member.save + end + def join_group @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index cbc514df6..148b20d2e 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -601,6 +601,24 @@ module CoursesHelper Course.tagged_with(tag_name).order('updated_at desc') end + #分班下拉框 + def course_group_option course + type = [] + option1 = [] + option1 << "暂无" + option1 << 0 + type << option1 + unless course.course_groups.nil? + course.course_groups.each do |cg| + option = [] + option << cg.name + option << cg.id + type << option + end + end + type + end + #课程实践年份下拉框 def course_time_option year type = [] diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index 65429b995..12a5d9626 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -60,18 +60,30 @@ <% end%> <% if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %> -
-
- + <% if @course.course_groups.nil? %> +
+ +
+ <% else %> + <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %> +
+ +
+ <%= select( :name,:group_id, course_group_option(@course), + { :include_blank => false,:selected => member.course_group_id}, + {:onchange=>"join_group_function('#join_group_form_#{member.id}');", :id =>"course_group_id", :name => "course_group_id",:class=>"w125 undis class-edit fl", :style => "margin-left: 105px;"}) %> + + <% end %> + <% end %> <% else %>
- +
<% end %> <%= link_to format("%0.2f",member.score.nil? ? 0 : member.score.to_s), { @@ -127,5 +139,8 @@ stopPropagation(e); }); }); + function join_group_function(id){ + $(id).submit(); + } diff --git a/app/views/courses/teacher_assign_group.js.erb b/app/views/courses/teacher_assign_group.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index dd02bf4af..2730fac3e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1005,6 +1005,7 @@ RedmineApp::Application.routes.draw do get 'course_outline' post 'search_course_outline' post 'set_course_outline' + post 'teacher_assign_group' get 'syllabus' get 'search_public_orgs_not_in_course' get "homework_search" From a7b9d8424a6440c595cceceb4e5b6d62f6035efe Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 10 Mar 2016 17:41:53 +0800 Subject: [PATCH 15/44] =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=AD=E7=9A=84=E5=AD=A6=E7=94=9F=E5=8F=AF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=88=86=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 ++++++- app/views/courses/_new_member_list.html.erb | 6 +++--- app/views/courses/teacher_assign_group.js.erb | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 81c21eb3d..98e195e30 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -242,9 +242,14 @@ class CoursesController < ApplicationController end def teacher_assign_group - member = Member.where(:course_id => @course.id, :user_id => User.current.id).first + member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first member.course_group_id = params[:course_group_id].to_i member.save + @course_groups = @course.course_groups + @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + respond_to do |format| + format.js + end end def join_group diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index 12a5d9626..b399c6035 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -60,12 +60,12 @@ <% end%> <% if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %> - <% if @course.course_groups.nil? %> + <% if @course.course_groups.nil? || @group %>
- +
<% else %> - <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %> + <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id,:user_id => member.user_id},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %>
diff --git a/app/views/courses/teacher_assign_group.js.erb b/app/views/courses/teacher_assign_group.js.erb index e69de29bb..1429bb753 100644 --- a/app/views/courses/teacher_assign_group.js.erb +++ b/app/views/courses/teacher_assign_group.js.erb @@ -0,0 +1 @@ +$("#st_groups").html("<%=escape_javascript(render :partial => 'new_groups_name', :locals => {:course_groups => @course_groups}) %>"); \ No newline at end of file From 2d14b26c11939adda46bb1f1a6eddb61e0a600a9 Mon Sep 17 00:00:00 2001 From: luoquan <545501972@qq.com> Date: Fri, 11 Mar 2016 09:52:11 +0800 Subject: [PATCH 16/44] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E8=A1=8C=E8=B7=9D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/lineheight/lineheight.js | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/public/assets/kindeditor/plugins/lineheight/lineheight.js b/public/assets/kindeditor/plugins/lineheight/lineheight.js index ae679d788..823ebdeaf 100644 --- a/public/assets/kindeditor/plugins/lineheight/lineheight.js +++ b/public/assets/kindeditor/plugins/lineheight/lineheight.js @@ -1,38 +1,40 @@ -/******************************************************************************* -* KindEditor - WYSIWYG HTML Editor for Internet -* Copyright (C) 2006-2011 kindsoft.net -* -* @author Roddy -* @site http://www.kindsoft.net/ -* @licence http://www.kindsoft.net/license.php -*******************************************************************************/ - -KindEditor.plugin('lineheight', function(K) { - var self = this, name = 'lineheight', lang = self.lang(name + '.'); - self.clickToolbar(name, function() { - var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'}); - if (commonNode) { - curVal = commonNode.css('line-height'); - } - var menu = self.createMenu({ - name : name, - width : 150 - }); - K.each(lang.lineHeight, function(i, row) { - K.each(row, function(key, val) { - menu.addItem({ - title : val, - checked : curVal === key, - click : function() { - self.cmd.toggle('', { - span : '.line-height=' + key - }); - self.updateState(); - self.addBookmark(); - self.hideMenu(); - } - }); - }); - }); - }); -}); +/******************************************************************************* +* KindEditor - WYSIWYG HTML Editor for Internet +* Copyright (C) 2006-2011 kindsoft.net +* +* @author Roddy +* @site http://www.kindsoft.net/ +* @licence http://www.kindsoft.net/license.php +*******************************************************************************/ + +KindEditor.plugin('lineheight', function(K) { + var self = this, name = 'lineheight', lang = self.lang(name + '.'); + self.clickToolbar(name, function() { + var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'}); + if (commonNode) { + curVal = commonNode.css('line-height'); + } + var menu = self.createMenu({ + name : name, + width : 150 + }); + K.each(lang.lineHeight, function(i, row) { + K.each(row, function(key, val) { + menu.addItem({ + title : val, + checked : curVal === key, + click : function() { + self.cmd.toggle('', { + span : '.line-height=' + key + }); + self.updateState(); + self.addBookmark(); + //curVal = key; + //self.cmd.doc.body.style.lineHeight = key; + self.hideMenu(); + } + }); + }); + }); + }); +}); From e80caf87b2057ef7f96130fc1e2eb4a6fde3ad3e Mon Sep 17 00:00:00 2001 From: luoquan <545501972@qq.com> Date: Fri, 11 Mar 2016 09:52:36 +0800 Subject: [PATCH 17/44] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E8=A1=8C=E8=B7=9D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/kindeditor/kindeditor.js | 12201 ++++++++++++----------- 1 file changed, 6107 insertions(+), 6094 deletions(-) diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 6065a563f..8978e8775 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -1,6094 +1,6107 @@ -//function dump_obj(myObject) { -// var s = ""; -// for (var property in myObject) { -// s = s + "\n "+property +": " + myObject[property] ; -// } -// alert(s); -//} -/******************************************************************************* -* KindEditor - WYSIWYG HTML Editor for Internet -* Copyright (C) 2006-2013 kindsoft.net -* -* @author Roddy -* @website http://www.kindsoft.net/ -* @licence http://www.kindsoft.net/license.php -* @version 4.1.10 (2013-11-23) -*******************************************************************************/ -(function (window, undefined) { - if (window.KindEditor) { - return; - } -if (!window.console) { - window.console = {}; -} -if (!console.log) { - console.log = function () {}; -} -var _VERSION = '4.1.10 (2013-11-23)', - _ua = navigator.userAgent.toLowerCase(), - _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1, - _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1, - _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1, - _WEBKIT = _ua.indexOf('applewebkit') > -1, - _OPERA = _ua.indexOf('opera') > -1, - _MOBILE = _ua.indexOf('mobile') > -1, - _IOS = /ipad|iphone|ipod/.test(_ua), - _QUIRKS = document.compatMode != 'CSS1Compat', - _IERANGE = !window.getSelection, - _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua), - _V = _matches ? _matches[1] : '0', - _TIME = new Date().getTime(); -function _isArray(val) { - if (!val) { - return false; - } - return Object.prototype.toString.call(val) === '[object Array]'; -} -function _isFunction(val) { - if (!val) { - return false; - } - return Object.prototype.toString.call(val) === '[object Function]'; -} -function _inArray(val, arr) { - for (var i = 0, len = arr.length; i < len; i++) { - if (val === arr[i]) { - return i; - } - } - return -1; -} -function _each(obj, fn) { - if (_isArray(obj)) { - for (var i = 0, len = obj.length; i < len; i++) { - if (fn.call(obj[i], i, obj[i]) === false) { - break; - } - } - } else { - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - if (fn.call(obj[key], key, obj[key]) === false) { - break; - } - } - } - } -} -function _trim(str) { - return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, ''); -} -function _inString(val, str, delimiter) { - delimiter = delimiter === undefined ? ',' : delimiter; - return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0; -} -function _addUnit(val, unit) { - unit = unit || 'px'; - return val && /^\d+$/.test(val) ? val + unit : val; -} -function _removeUnit(val) { - var match; - return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0; -} -function _escape(val) { - return val.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); -} -function _unescape(val) { - return val.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&'); -} -function _toCamel(str) { - var arr = str.split('-'); - str = ''; - _each(arr, function(key, val) { - str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val; - }); - return str; -} -function _toHex(val) { - function hex(d) { - var s = parseInt(d, 10).toString(16).toUpperCase(); - return s.length > 1 ? s : '0' + s; - } - return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig, - function($0, $1, $2, $3) { - return '#' + hex($1) + hex($2) + hex($3); - } - ); -} -function _toMap(val, delimiter) { - delimiter = delimiter === undefined ? ',' : delimiter; - var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match; - _each(arr, function(key, val) { - if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) { - for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) { - map[i.toString()] = true; - } - } else { - map[val] = true; - } - }); - return map; -} -function _toArray(obj, offset) { - return Array.prototype.slice.call(obj, offset || 0); -} -function _undef(val, defaultVal) { - return val === undefined ? defaultVal : val; -} -function _invalidUrl(url) { - return !url || /[<>"]/.test(url); -} -function _addParam(url, param) { - return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param; -} -function _extend(child, parent, proto) { - if (!proto) { - proto = parent; - parent = null; - } - var childProto; - if (parent) { - var fn = function () {}; - fn.prototype = parent.prototype; - childProto = new fn(); - _each(proto, function(key, val) { - childProto[key] = val; - }); - } else { - childProto = proto; - } - childProto.constructor = child; - child.prototype = childProto; - child.parent = parent ? parent.prototype : null; -} -function _json(text) { - var match; - if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) { - text = match[0]; - } - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; - cx.lastIndex = 0; - if (cx.test(text)) { - text = text.replace(cx, function (a) { - return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); - }); - } - if (/^[\],:{}\s]*$/. - test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). - replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). - replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { - return eval('(' + text + ')'); - } - throw 'JSON parse error'; -} -var _round = Math.round; -var K = { - DEBUG : false, - VERSION : _VERSION, - IE : _IE, - GECKO : _GECKO, - WEBKIT : _WEBKIT, - OPERA : _OPERA, - V : _V, - TIME : _TIME, - each : _each, - isArray : _isArray, - isFunction : _isFunction, - inArray : _inArray, - inString : _inString, - trim : _trim, - addUnit : _addUnit, - removeUnit : _removeUnit, - escape : _escape, - unescape : _unescape, - toCamel : _toCamel, - toHex : _toHex, - toMap : _toMap, - toArray : _toArray, - undef : _undef, - invalidUrl : _invalidUrl, - addParam : _addParam, - extend : _extend, - json : _json -}; -var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'), - _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'), - _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'), - _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'), - _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'), - _PRE_TAG_MAP = _toMap('pre,style,script'), - _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'), - _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'), - _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'), - _VALUE_TAG_MAP = _toMap('input,button,textarea,select'); -// Begining of modification by Macrow -function _getBasePath() { - var refPath = '/assets/kindeditor/'; - var els = document.getElementsByTagName('script'), src; - for (var i = 0, len = els.length; i < len; i++) { - src = els[i].src || ''; - if (/(kindeditor|application)[\w\-\.]*\.js/.test(src)) { - return src.substring(0, src.indexOf('assets')) + refPath; - } - } - return refPath; -} -// End of modification by Macrow -K.basePath = _getBasePath(); -K.options = { - designMode : true, - fullscreenMode : false, - filterMode : true, - wellFormatMode : true, - shadowMode : true, - loadStyleMode : true, - basePath : K.basePath, - emotionsBasePath: 'http://forge.trustie.net', //TODO - themesPath : K.basePath + 'themes/', - langPath : K.basePath + 'lang/', - pluginsPath : K.basePath + 'plugins/', - themeType : 'default', - langType : 'zh_CN', - urlType : '', - newlineTag : 'p', - resizeType : 2, - syncType : 'form', - pasteType : 2, - dialogAlignType : 'page', - useContextmenu : true, - fullscreenShortcut : false, - bodyClass : 'ke-content', - indentChar : '\t', - cssPath : K.basePath +'plugins/code/previewcode.css', - cssData : 'font{color:black;}', - minWidth : 650, - minHeight : 100, - minChangeSize : 1, - zIndex : 811213, - items : ['code','emoticons','fontname', - 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', - 'formatblock', 'fontsize', '|','indent', 'outdent', - '|','imagedirectupload','table', 'media', 'preview',"more" - ], - noDisableItems : ['source', 'fullscreen'], - colorTable : [ - ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], - ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], - ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], - ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] - ], - fontSizeTable : ['选中的字体大小:','9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'], - htmlTags : { - font : ['id', 'class', 'color', 'size', 'face', '.background-color'], - span : [ - 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background', - '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height', 'data-user-id' - ], - div : [ - 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color', - '.background-color', '.font-size', '.font-family', '.font-weight', '.background', - '.font-style', '.text-decoration', '.vertical-align', '.margin-left' - ], - table: [ - 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor', - '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color', - '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background', - '.width', '.height', '.border-collapse' - ], - 'td,th': [ - 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', - '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight', - '.font-style', '.text-decoration', '.vertical-align', '.background', '.border' - ], - a : ['id', 'class', 'href', 'target', 'name'], - embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'], - img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'], - 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ - 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', - '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' - ], - pre : ['id', 'class'], - hr : ['id', 'class', '.page-break-after'], - 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'], - iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height'] - }, - layout : '
' -}; -var _useCapture = false; -var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222'); -var _CURSORMOVE_KEY_MAP = _toMap('33..40'); -var _CHANGE_KEY_MAP = {}; -_each(_INPUT_KEY_MAP, function(key, val) { - _CHANGE_KEY_MAP[key] = val; -}); -_each(_CURSORMOVE_KEY_MAP, function(key, val) { - _CHANGE_KEY_MAP[key] = val; -}); -function _bindEvent(el, type, fn) { - if (el.addEventListener){ - el.addEventListener(type, fn, _useCapture); - } else if (el.attachEvent){ - el.attachEvent('on' + type, fn); - } -} -function _unbindEvent(el, type, fn) { - if (el.removeEventListener){ - el.removeEventListener(type, fn, _useCapture); - } else if (el.detachEvent){ - el.detachEvent('on' + type, fn); - } -} -var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' + - 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' + - 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(','); -function KEvent(el, event) { - this.init(el, event); -} -_extend(KEvent, { - init : function(el, event) { - var self = this, doc = el.ownerDocument || el.document || el; - self.event = event; - _each(_EVENT_PROPS, function(key, val) { - self[val] = event[val]; - }); - if (!self.target) { - self.target = self.srcElement || doc; - } - if (self.target.nodeType === 3) { - self.target = self.target.parentNode; - } - if (!self.relatedTarget && self.fromElement) { - self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement; - } - if (self.pageX == null && self.clientX != null) { - var d = doc.documentElement, body = doc.body; - self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0); - self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0); - } - if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) { - self.which = self.charCode || self.keyCode; - } - if (!self.metaKey && self.ctrlKey) { - self.metaKey = self.ctrlKey; - } - if (!self.which && self.button !== undefined) { - self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0))); - } - switch (self.which) { - case 186 : - self.which = 59; - break; - case 187 : - case 107 : - case 43 : - self.which = 61; - break; - case 189 : - case 45 : - self.which = 109; - break; - case 42 : - self.which = 106; - break; - case 47 : - self.which = 111; - break; - case 78 : - self.which = 110; - break; - } - if (self.which >= 96 && self.which <= 105) { - self.which -= 48; - } - }, - preventDefault : function() { - var ev = this.event; - if (ev.preventDefault) { - ev.preventDefault(); - } else { - ev.returnValue = false; - } - }, - stopPropagation : function() { - var ev = this.event; - if (ev.stopPropagation) { - ev.stopPropagation(); - } else { - ev.cancelBubble = true; - } - }, - stop : function() { - this.preventDefault(); - this.stopPropagation(); - } -}); -var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {}; -function _getId(el) { - return el[_eventExpendo] || null; -} -function _setId(el) { - el[_eventExpendo] = ++_eventId; - return _eventId; -} -function _removeId(el) { - try { - delete el[_eventExpendo]; - } catch(e) { - if (el.removeAttribute) { - el.removeAttribute(_eventExpendo); - } - } -} -function _bind(el, type, fn) { - if (type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _bind(el, this, fn); - }); - return; - } - var id = _getId(el); - if (!id) { - id = _setId(el); - } - if (_eventData[id] === undefined) { - _eventData[id] = {}; - } - var events = _eventData[id][type]; - if (events && events.length > 0) { - _unbindEvent(el, type, events[0]); - } else { - _eventData[id][type] = []; - _eventData[id].el = el; - } - events = _eventData[id][type]; - if (events.length === 0) { - events[0] = function(e) { - var kevent = e ? new KEvent(el, e) : undefined; - _each(events, function(i, event) { - if (i > 0 && event) { - event.call(el, kevent); - } - }); - }; - } - if (_inArray(fn, events) < 0) { - events.push(fn); - } - _bindEvent(el, type, events[0]); -} -function _unbind(el, type, fn) { - if (type && type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _unbind(el, this, fn); - }); - return; - } - var id = _getId(el); - if (!id) { - return; - } - if (type === undefined) { - if (id in _eventData) { - _each(_eventData[id], function(key, events) { - if (key != 'el' && events.length > 0) { - _unbindEvent(el, key, events[0]); - } - }); - delete _eventData[id]; - _removeId(el); - } - return; - } - if (!_eventData[id]) { - return; - } - var events = _eventData[id][type]; - if (events && events.length > 0) { - if (fn === undefined) { - _unbindEvent(el, type, events[0]); - delete _eventData[id][type]; - } else { - _each(events, function(i, event) { - if (i > 0 && event === fn) { - events.splice(i, 1); - } - }); - if (events.length == 1) { - _unbindEvent(el, type, events[0]); - delete _eventData[id][type]; - } - } - var count = 0; - _each(_eventData[id], function() { - count++; - }); - if (count < 2) { - delete _eventData[id]; - _removeId(el); - } - } -} -function _fire(el, type) { - if (type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _fire(el, this); - }); - return; - } - var id = _getId(el); - if (!id) { - return; - } - var events = _eventData[id][type]; - if (_eventData[id] && events && events.length > 0) { - events[0](); - } -} -function _ctrl(el, key, fn) { - var self = this; - key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0); - _bind(el, 'keydown', function(e) { - if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) { - fn.call(el); - e.stop(); - } - }); -} -var _readyFinished = false; -function _ready(fn) { - if (_readyFinished) { - fn(KindEditor); - return; - } - var loaded = false; - function readyFunc() { - if (!loaded) { - loaded = true; - fn(KindEditor); - _readyFinished = true; - } - } - function ieReadyFunc() { - if (!loaded) { - try { - document.documentElement.doScroll('left'); - } catch(e) { - setTimeout(ieReadyFunc, 100); - return; - } - readyFunc(); - } - } - function ieReadyStateFunc() { - if (document.readyState === 'complete') { - readyFunc(); - } - } - if (document.addEventListener) { - _bind(document, 'DOMContentLoaded', readyFunc); - } else if (document.attachEvent) { - _bind(document, 'readystatechange', ieReadyStateFunc); - var toplevel = false; - try { - toplevel = window.frameElement == null; - } catch(e) {} - if (document.documentElement.doScroll && toplevel) { - ieReadyFunc(); - } - } - _bind(window, 'load', readyFunc); -} -if (_IE) { - window.attachEvent('onunload', function() { - _each(_eventData, function(key, events) { - if (events.el) { - _unbind(events.el); - } - }); - }); -} -K.ctrl = _ctrl; -K.ready = _ready; -function _getCssList(css) { - var list = {}, - reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g, - match; - while ((match = reg.exec(css))) { - var key = _trim(match[1].toLowerCase()), - val = _trim(_toHex(match[2])); - list[key] = val; - } - return list; -} -function _getAttrList(tag) { - var list = {}, - reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g, - match; - while ((match = reg.exec(tag))) { - var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(), - val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || ''; - list[key] = val; - } - return list; -} -function _addClassToTag(tag, className) { - if (/\s+class\s*=/.test(tag)) { - tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) { - if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) { - return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3; - } else { - return $0; - } - }); - } else { - tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">'; - } - return tag; -} -function _formatCss(css) { - var str = ''; - _each(_getCssList(css), function(key, val) { - str += key + ':' + val + ';'; - }); - return str; -} -function _formatUrl(url, mode, host, pathname) { - mode = _undef(mode, '').toLowerCase(); - if (url.substr(0, 5) != 'data:') { - url = url.replace(/([^:])\/\//g, '$1/'); - } - if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) { - return url; - } - host = host || location.protocol + '//' + location.host; - if (pathname === undefined) { - var m = location.pathname.match(/^(\/.*)\//); - pathname = m ? m[1] : ''; - } - var match; - if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) { - if (match[1] !== host) { - return url; - } - } else if (/^\w+:/.test(url)) { - return url; - } - function getRealPath(path) { - var parts = path.split('/'), paths = []; - for (var i = 0, len = parts.length; i < len; i++) { - var part = parts[i]; - if (part == '..') { - if (paths.length > 0) { - paths.pop(); - } - } else if (part !== '' && part != '.') { - paths.push(part); - } - } - return '/' + paths.join('/'); - } - if (/^\//.test(url)) { - url = host + getRealPath(url.substr(1)); - } else if (!/^\w+:\/\//.test(url)) { - url = host + getRealPath(pathname + '/' + url); - } - function getRelativePath(path, depth) { - if (url.substr(0, path.length) === path) { - var arr = []; - for (var i = 0; i < depth; i++) { - arr.push('..'); - } - var prefix = '.'; - if (arr.length > 0) { - prefix += '/' + arr.join('/'); - } - if (pathname == '/') { - prefix += '/'; - } - return prefix + url.substr(path.length); - } else { - if ((match = /^(.*)\//.exec(path))) { - return getRelativePath(match[1], ++depth); - } - } - } - if (mode === 'relative') { - url = getRelativePath(host + pathname, 0).substr(2); - } else if (mode === 'absolute') { - if (url.substr(0, host.length) === host) { - url = url.substr(host.length); - } - } - return url; -} -function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) { - if (html == null) { - html = ''; - } - urlType = urlType || ''; - wellFormatted = _undef(wellFormatted, false); - indentChar = _undef(indentChar, '\t'); - var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(','); - html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) { - return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3; - }); - html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '

'); - html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1
$2'); - html = html.replace(/\u200B/g, ''); - html = html.replace(/\u00A9/g, '©'); - html = html.replace(/\u00AE/g, '®'); - html = html.replace(/<[^>]+/g, function($0) { - return $0.replace(/\s+/g, ' '); - }); - var htmlTagMap = {}; - if (htmlTags) { - _each(htmlTags, function(key, val) { - var arr = key.split(','); - for (var i = 0, len = arr.length; i < len; i++) { - htmlTagMap[arr[i]] = _toMap(val); - } - }); - if (!htmlTagMap.script) { - html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, ''); - } - if (!htmlTagMap.style) { - html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, ''); - } - } - var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g; - var tagStack = []; - html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) { - var full = $0, - startNewline = $1 || '', - startSlash = $2 || '', - tagName = $3.toLowerCase(), - attr = $4 || '', - endSlash = $5 ? ' ' + $5 : '', - endNewline = $6 || ''; - if (htmlTags && !htmlTagMap[tagName]) { - return ''; - } - if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) { - endSlash = ' /'; - } - if (_INLINE_TAG_MAP[tagName]) { - if (startNewline) { - startNewline = ' '; - } - if (endNewline) { - endNewline = ' '; - } - } - if (_PRE_TAG_MAP[tagName]) { - if (startSlash) { - endNewline = '\n'; - } else { - startNewline = '\n'; - } - } - if (wellFormatted && tagName == 'br') { - endNewline = '\n'; - } - if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) { - if (wellFormatted) { - if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) { - tagStack.pop(); - } else { - tagStack.push(tagName); - } - startNewline = '\n'; - endNewline = '\n'; - for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) { - startNewline += indentChar; - if (!startSlash) { - endNewline += indentChar; - } - } - if (endSlash) { - tagStack.pop(); - } else if (!startSlash) { - endNewline += indentChar; - } - } else { - startNewline = endNewline = ''; - } - } - if (attr !== '') { - var attrMap = _getAttrList(full); - if (tagName === 'font') { - var fontStyleMap = {}, fontStyle = ''; - _each(attrMap, function(key, val) { - if (key === 'color') { - fontStyleMap.color = val; - delete attrMap[key]; - } - if (key === 'size') { - fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || ''; - delete attrMap[key]; - } - if (key === 'face') { - fontStyleMap['font-family'] = val; - delete attrMap[key]; - } - if (key === 'style') { - fontStyle = val; - } - }); - if (fontStyle && !/;$/.test(fontStyle)) { - fontStyle += ';'; - } - _each(fontStyleMap, function(key, val) { - if (val === '') { - return; - } - if (/\s/.test(val)) { - val = "'" + val + "'"; - } - fontStyle += key + ':' + val + ';'; - }); - attrMap.style = fontStyle; - } - _each(attrMap, function(key, val) { - if (_FILL_ATTR_MAP[key]) { - attrMap[key] = key; - } - if (_inArray(key, ['src', 'href']) >= 0) { - attrMap[key] = _formatUrl(val, urlType); - } - if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] || - tagName === 'body' && key === 'contenteditable' || - /^kindeditor_\d+$/.test(key)) { - delete attrMap[key]; - } - if (key === 'style' && val !== '') { - var styleMap = _getCssList(val); - _each(styleMap, function(k, v) { - if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) { - delete styleMap[k]; - } - }); - var style = ''; - _each(styleMap, function(k, v) { - style += k + ':' + v + ';'; - }); - attrMap.style = style; - } - }); - attr = ''; - _each(attrMap, function(key, val) { - if (key === 'style' && val === '') { - return; - } - val = val.replace(/"/g, '"'); - attr += ' ' + key + '="' + val + '"'; - }); - } - if (tagName === 'font') { - tagName = 'span'; - } - return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline; - }); - html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) { - return $1 + $2.replace(/\n/g, '\n') + $3; - }); - html = html.replace(/\n\s*\n/g, '\n'); - html = html.replace(/\n/g, '\n'); - return _trim(html); -} -function _clearMsWord(html, htmlTags) { - html = html.replace(//ig, '') - .replace(//ig, '') - .replace(/]*>[\s\S]*?<\/style>/ig, '') - .replace(/]*>[\s\S]*?<\/script>/ig, '') - .replace(/]+>[\s\S]*?<\/w:[^>]+>/ig, '') - .replace(/]+>[\s\S]*?<\/o:[^>]+>/ig, '') - .replace(/[\s\S]*?<\/xml>/ig, '') - .replace(/<(?:table|td)[^>]*>/ig, function(full) { - return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1'); - }); - return _formatHtml(html, htmlTags); -} -function _mediaType(src) { - if (/\.(rm|rmvb)(\?|$)/i.test(src)) { - return 'audio/x-pn-realaudio-plugin'; - } - if (/\.(swf|flv)(\?|$)/i.test(src)) { - return 'application/x-shockwave-flash'; - } - return 'video/x-ms-asf-plugin'; -} -function _mediaClass(type) { - if (/realaudio/i.test(type)) { - return 'ke-rm'; - } - if (/flash/i.test(type)) { - return 'ke-flash'; - } - return 'ke-media'; -} -function _mediaAttrs(srcTag) { - return _getAttrList(unescape(srcTag)); -} -function _mediaEmbed(attrs) { - var html = ' 0) { - style += 'width:' + width + 'px;'; - } - if (/\D/.test(height)) { - style += 'height:' + height + ';'; - } else if (height > 0) { - style += 'height:' + height + 'px;'; - } - var html = ''; - return html; -} -function _tmpl(str, data) { - var fn = new Function("obj", - "var p=[],print=function(){p.push.apply(p,arguments);};" + - "with(obj){p.push('" + - str.replace(/[\r\t\n]/g, " ") - .split("<%").join("\t") - .replace(/((^|%>)[^\t]*)'/g, "$1\r") - .replace(/\t=(.*?)%>/g, "',$1,'") - .split("\t").join("');") - .split("%>").join("p.push('") - .split("\r").join("\\'") + "');}return p.join('');"); - return data ? fn(data) : fn; -} -K.formatUrl = _formatUrl; -K.formatHtml = _formatHtml; -K.getCssList = _getCssList; -K.getAttrList = _getAttrList; -K.mediaType = _mediaType; -K.mediaAttrs = _mediaAttrs; -K.mediaEmbed = _mediaEmbed; -K.mediaImg = _mediaImg; -K.clearMsWord = _clearMsWord; -K.tmpl = _tmpl; -function _contains(nodeA, nodeB) { - if (nodeA.nodeType == 9 && nodeB.nodeType != 9) { - return true; - } - while ((nodeB = nodeB.parentNode)) { - if (nodeB == nodeA) { - return true; - } - } - return false; -} -var _getSetAttrDiv = document.createElement('div'); -_getSetAttrDiv.setAttribute('className', 't'); -var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't'; -function _getAttr(el, key) { - key = key.toLowerCase(); - var val = null; - if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') { - var div = el.ownerDocument.createElement('div'); - div.appendChild(el.cloneNode(false)); - var list = _getAttrList(_unescape(div.innerHTML)); - if (key in list) { - val = list[key]; - } - } else { - try { - val = el.getAttribute(key, 2); - } catch(e) { - val = el.getAttribute(key, 1); - } - } - if (key === 'style' && val !== null) { - val = _formatCss(val); - } - return val; -} -function _queryAll(expr, root) { - var exprList = expr.split(','); - if (exprList.length > 1) { - var mergedResults = []; - _each(exprList, function() { - _each(_queryAll(this, root), function() { - if (_inArray(this, mergedResults) < 0) { - mergedResults.push(this); - } - }); - }); - return mergedResults; - } - root = root || document; - function escape(str) { - if (typeof str != 'string') { - return str; - } - return str.replace(/([^\w\-])/g, '\\$1'); - } - function stripslashes(str) { - return str.replace(/\\/g, ''); - } - function cmpTag(tagA, tagB) { - return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase()); - } - function byId(id, tag, root) { - var arr = [], - doc = root.ownerDocument || root, - el = doc.getElementById(stripslashes(id)); - if (el) { - if (cmpTag(tag, el.nodeName) && _contains(root, el)) { - arr.push(el); - } - } - return arr; - } - function byClass(className, tag, root) { - var doc = root.ownerDocument || root, arr = [], els, i, len, el; - if (root.getElementsByClassName) { - els = root.getElementsByClassName(stripslashes(className)); - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (cmpTag(tag, el.nodeName)) { - arr.push(el); - } - } - } else if (doc.querySelectorAll) { - els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className); - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (_contains(root, el)) { - arr.push(el); - } - } - } else { - els = root.getElementsByTagName(tag); - className = ' ' + className + ' '; - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - var cls = el.className; - if (cls && (' ' + cls + ' ').indexOf(className) > -1) { - arr.push(el); - } - } - } - } - return arr; - } - function byName(name, tag, root) { - var arr = [], doc = root.ownerDocument || root, - els = doc.getElementsByName(stripslashes(name)), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (cmpTag(tag, el.nodeName) && _contains(root, el)) { - if (el.getAttribute('name') !== null) { - arr.push(el); - } - } - } - return arr; - } - function byAttr(key, val, tag, root) { - var arr = [], els = root.getElementsByTagName(tag), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - if (val === null) { - if (_getAttr(el, key) !== null) { - arr.push(el); - } - } else { - if (val === escape(_getAttr(el, key))) { - arr.push(el); - } - } - } - } - return arr; - } - function select(expr, root) { - var arr = [], matches; - matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr); - var tag = matches ? matches[1] : '*'; - if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) { - arr = byId(matches[1], tag, root); - } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) { - arr = byClass(matches[1], tag, root); - } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) { - arr = byAttr(matches[1].toLowerCase(), null, tag, root); - } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) { - var key = matches[1].toLowerCase(), val = matches[2]; - if (key === 'id') { - arr = byId(val, tag, root); - } else if (key === 'class') { - arr = byClass(val, tag, root); - } else if (key === 'name') { - arr = byName(val, tag, root); - } else { - arr = byAttr(key, val, tag, root); - } - } else { - var els = root.getElementsByTagName(tag), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - arr.push(el); - } - } - } - return arr; - } - var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g; - while ((arr = re.exec(expr))) { - if (arr[1] !== ' ') { - parts.push(arr[1]); - } - } - var results = []; - if (parts.length == 1) { - return select(parts[0], root); - } - var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l; - for (i = 0, lenth = parts.length; i < lenth; i++) { - part = parts[i]; - if (part === '>') { - isChild = true; - continue; - } - if (i > 0) { - els = []; - for (j = 0, len = results.length; j < len; j++) { - val = results[j]; - subResults = select(part, val); - for (k = 0, l = subResults.length; k < l; k++) { - v = subResults[k]; - if (isChild) { - if (val === v.parentNode) { - els.push(v); - } - } else { - els.push(v); - } - } - } - results = els; - } else { - results = select(part, root); - } - if (results.length === 0) { - return []; - } - } - return results; -} -function _query(expr, root) { - var arr = _queryAll(expr, root); - return arr.length > 0 ? arr[0] : null; -} -K.query = _query; -K.queryAll = _queryAll; -function _get(val) { - return K(val)[0]; -} -function _getDoc(node) { - if (!node) { - return document; - } - return node.ownerDocument || node.document || node; -} -function _getWin(node) { - if (!node) { - return window; - } - var doc = _getDoc(node); - return doc.parentWindow || doc.defaultView; -} -function _setHtml(el, html) { - if (el.nodeType != 1) { - return; - } - var doc = _getDoc(el); - try { - el.innerHTML = '' + html; - var temp = doc.getElementById('__kindeditor_temp_tag__'); - temp.parentNode.removeChild(temp); - } catch(e) { - K(el).empty(); - K('@' + html, doc).each(function() { - el.appendChild(this); - }); - } -} -function _hasClass(el, cls) { - return _inString(cls, el.className, ' '); -} -function _setAttr(el, key, val) { - if (_IE && _V < 8 && key.toLowerCase() == 'class') { - key = 'className'; - } - el.setAttribute(key, '' + val); -} -function _removeAttr(el, key) { - if (_IE && _V < 8 && key.toLowerCase() == 'class') { - key = 'className'; - } - _setAttr(el, key, ''); - el.removeAttribute(key); -} -function _getNodeName(node) { - if (!node || !node.nodeName) { - return ''; - } - return node.nodeName.toLowerCase(); -} -function _computedCss(el, key) { - var self = this, win = _getWin(el), camelKey = _toCamel(key), val = ''; - if (win.getComputedStyle) { - var style = win.getComputedStyle(el, null); - val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey]; - } else if (el.currentStyle) { - val = el.currentStyle[camelKey] || el.style[camelKey]; - } - return val; -} -function _hasVal(node) { - return !!_VALUE_TAG_MAP[_getNodeName(node)]; -} -function _docElement(doc) { - doc = doc || document; - return _QUIRKS ? doc.body : doc.documentElement; -} -function _docHeight(doc) { - var el = _docElement(doc); - return Math.max(el.scrollHeight, el.clientHeight); -} -function _docWidth(doc) { - var el = _docElement(doc); - return Math.max(el.scrollWidth, el.clientWidth); -} -function _getScrollPos(doc) { - doc = doc || document; - var x, y; - if (_IE || _NEWIE || _OPERA) { - x = _docElement(doc).scrollLeft; - y = _docElement(doc).scrollTop; - } else { - x = _getWin(doc).scrollX; - y = _getWin(doc).scrollY; - } - return {x : x, y : y}; -} -function KNode(node) { - this.init(node); -} -_extend(KNode, { - init : function(node) { - var self = this; - node = _isArray(node) ? node : [node]; - var length = 0; - for (var i = 0, len = node.length; i < len; i++) { - if (node[i]) { - self[i] = node[i].constructor === KNode ? node[i][0] : node[i]; - length++; - } - } - self.length = length; - self.doc = _getDoc(self[0]); - self.name = _getNodeName(self[0]); - self.type = self.length > 0 ? self[0].nodeType : null; - self.win = _getWin(self[0]); - }, - each : function(fn) { - var self = this; - for (var i = 0; i < self.length; i++) { - if (fn.call(self[i], i, self[i]) === false) { - return self; - } - } - return self; - }, - bind : function(type, fn) { - this.each(function() { - _bind(this, type, fn); - }); - return this; - }, - unbind : function(type, fn) { - this.each(function() { - _unbind(this, type, fn); - }); - return this; - }, - fire : function(type) { - if (this.length < 1) { - return this; - } - _fire(this[0], type); - return this; - }, - hasAttr : function(key) { - if (this.length < 1) { - return false; - } - return !!_getAttr(this[0], key); - }, - attr : function(key, val) { - var self = this; - if (key === undefined) { - return _getAttrList(self.outer()); - } - if (typeof key === 'object') { - _each(key, function(k, v) { - self.attr(k, v); - }); - return self; - } - if (val === undefined) { - val = self.length < 1 ? null : _getAttr(self[0], key); - return val === null ? '' : val; - } - self.each(function() { - _setAttr(this, key, val); - }); - return self; - }, - removeAttr : function(key) { - this.each(function() { - _removeAttr(this, key); - }); - return this; - }, - get : function(i) { - if (this.length < 1) { - return null; - } - return this[i || 0]; - }, - eq : function(i) { - if (this.length < 1) { - return null; - } - return this[i] ? new KNode(this[i]) : null; - }, - hasClass : function(cls) { - if (this.length < 1) { - return false; - } - return _hasClass(this[0], cls); - }, - addClass : function(cls) { - this.each(function() { - if (!_hasClass(this, cls)) { - this.className = _trim(this.className + ' ' + cls); - } - }); - return this; - }, - removeClass : function(cls) { - this.each(function() { - if (_hasClass(this, cls)) { - this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' ')); - } - }); - return this; - }, - html : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1 || self.type != 1) { - return ''; - } - return _formatHtml(self[0].innerHTML); - } - self.each(function() { - _setHtml(this, val); - }); - return self; - }, - text : function() { - var self = this; - if (self.length < 1) { - return ''; - } - return _IE ? self[0].innerText : self[0].textContent; - }, - hasVal : function() { - if (this.length < 1) { - return false; - } - return _hasVal(this[0]); - }, - val : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return ''; - } - return self.hasVal() ? self[0].value : self.attr('value'); - } else { - self.each(function() { - if (_hasVal(this)) { - this.value = val; - } else { - _setAttr(this, 'value' , val); - } - }); - return self; - } - }, - css : function(key, val) { - var self = this; - if (key === undefined) { - return _getCssList(self.attr('style')); - } - if (typeof key === 'object') { - _each(key, function(k, v) { - self.css(k, v); - }); - return self; - } - if (val === undefined) { - if (self.length < 1) { - return ''; - } - return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || ''; - } - self.each(function() { - this.style[_toCamel(key)] = val; - }); - return self; - }, - width : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return 0; - } - return self[0].offsetWidth; - } - return self.css('width', _addUnit(val)); - }, - height : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return 0; - } - return self[0].offsetHeight; - } - return self.css('height', _addUnit(val)); - }, - opacity : function(val) { - this.each(function() { - if (this.style.opacity === undefined) { - this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')'; - } else { - this.style.opacity = val == 1 ? '' : val; - } - }); - return this; - }, - data : function(key, val) { - var self = this; - key = 'kindeditor_data_' + key; - if (val === undefined) { - if (self.length < 1) { - return null; - } - return self[0][key]; - } - this.each(function() { - this[key] = val; - }); - return self; - }, - pos : function() { - var self = this, node = self[0], x = 0, y = 0; - if (node) { - if (node.getBoundingClientRect) { - var box = node.getBoundingClientRect(), - pos = _getScrollPos(self.doc); - x = box.left + pos.x; - y = box.top + pos.y; - } else { - while (node) { - x += node.offsetLeft; - y += node.offsetTop; - node = node.offsetParent; - } - } - } - return {x : _round(x), y : _round(y)}; - }, - clone : function(bool) { - if (this.length < 1) { - return new KNode([]); - } - return new KNode(this[0].cloneNode(bool)); - }, - append : function(expr) { - this.each(function() { - if (this.appendChild) { - this.appendChild(_get(expr)); - } - }); - return this; - }, - appendTo : function(expr) { - this.each(function() { - _get(expr).appendChild(this); - }); - return this; - }, - before : function(expr) { - this.each(function() { - this.parentNode.insertBefore(_get(expr), this); - }); - return this; - }, - after : function(expr) { - this.each(function() { - if (this.nextSibling) { - this.parentNode.insertBefore(_get(expr), this.nextSibling); - } else { - this.parentNode.appendChild(_get(expr)); - } - }); - return this; - }, - replaceWith : function(expr) { - var nodes = []; - this.each(function(i, node) { - _unbind(node); - var newNode = _get(expr); - node.parentNode.replaceChild(newNode, node); - nodes.push(newNode); - }); - return K(nodes); - }, - empty : function() { - var self = this; - self.each(function(i, node) { - var child = node.firstChild; - while (child) { - if (!node.parentNode) { - return; - } - var next = child.nextSibling; - child.parentNode.removeChild(child); - child = next; - } - }); - return self; - }, - remove : function(keepChilds) { - var self = this; - self.each(function(i, node) { - if (!node.parentNode) { - return; - } - _unbind(node); - if (keepChilds) { - var child = node.firstChild; - while (child) { - var next = child.nextSibling; - node.parentNode.insertBefore(child, node); - child = next; - } - } - node.parentNode.removeChild(node); - delete self[i]; - }); - self.length = 0; - return self; - }, - show : function(val) { - var self = this; - if (val === undefined) { - val = self._originDisplay || ''; - } - if (self.css('display') != 'none') { - return self; - } - return self.css('display', val); - }, - hide : function() { - var self = this; - if (self.length < 1) { - return self; - } - self._originDisplay = self[0].style.display; - return self.css('display', 'none'); - }, - outer : function() { - var self = this; - if (self.length < 1) { - return ''; - } - var div = self.doc.createElement('div'), html; - div.appendChild(self[0].cloneNode(true)); - html = _formatHtml(div.innerHTML); - div = null; - return html; - }, - isSingle : function() { - return !!_SINGLE_TAG_MAP[this.name]; - }, - isInline : function() { - return !!_INLINE_TAG_MAP[this.name]; - }, - isBlock : function() { - return !!_BLOCK_TAG_MAP[this.name]; - }, - isStyle : function() { - return !!_STYLE_TAG_MAP[this.name]; - }, - isControl : function() { - return !!_CONTROL_TAG_MAP[this.name]; - }, - contains : function(otherNode) { - if (this.length < 1) { - return false; - } - return _contains(this[0], _get(otherNode)); - }, - parent : function() { - if (this.length < 1) { - return null; - } - var node = this[0].parentNode; - return node ? new KNode(node) : null; - }, - children : function() { - if (this.length < 1) { - return new KNode([]); - } - var list = [], child = this[0].firstChild; - while (child) { - if (child.nodeType != 3 || _trim(child.nodeValue) !== '') { - list.push(child); - } - child = child.nextSibling; - } - return new KNode(list); - }, - first : function() { - var list = this.children(); - return list.length > 0 ? list.eq(0) : null; - }, - last : function() { - var list = this.children(); - return list.length > 0 ? list.eq(list.length - 1) : null; - }, - index : function() { - if (this.length < 1) { - return -1; - } - var i = -1, sibling = this[0]; - while (sibling) { - i++; - sibling = sibling.previousSibling; - } - return i; - }, - prev : function() { - if (this.length < 1) { - return null; - } - var node = this[0].previousSibling; - return node ? new KNode(node) : null; - }, - next : function() { - if (this.length < 1) { - return null; - } - var node = this[0].nextSibling; - return node ? new KNode(node) : null; - }, - scan : function(fn, order) { - if (this.length < 1) { - return; - } - order = (order === undefined) ? true : order; - function walk(node) { - var n = order ? node.firstChild : node.lastChild; - while (n) { - var next = order ? n.nextSibling : n.previousSibling; - if (fn(n) === false) { - return false; - } - if (walk(n) === false) { - return false; - } - n = next; - } - } - walk(this[0]); - return this; - } -}); -_each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' + - 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' + - 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) { - KNode.prototype[type] = function(fn) { - return fn ? this.bind(type, fn) : this.fire(type); - }; -}); -var _K = K; -K = function(expr, root) { - if (expr === undefined || expr === null) { - return; - } - function newNode(node) { - if (!node[0]) { - node = []; - } - return new KNode(node); - } - if (typeof expr === 'string') { - if (root) { - root = _get(root); - } - var length = expr.length; - if (expr.charAt(0) === '@') { - expr = expr.substr(1); - } - if (expr.length !== length || /<.+>/.test(expr)) { - var doc = root ? root.ownerDocument || root : document, - div = doc.createElement('div'), list = []; - div.innerHTML = '' + expr; - for (var i = 0, len = div.childNodes.length; i < len; i++) { - var child = div.childNodes[i]; - if (child.id == '__kindeditor_temp_tag__') { - continue; - } - list.push(child); - } - return newNode(list); - } - return newNode(_queryAll(expr, root)); - } - if (expr && expr.constructor === KNode) { - return expr; - } - if (expr.toArray) { - expr = expr.toArray(); - } - if (_isArray(expr)) { - return newNode(expr); - } - return newNode(_toArray(arguments)); -}; -_each(_K, function(key, val) { - K[key] = val; -}); -K.NodeClass = KNode; -window.KindEditor = K; -var _START_TO_START = 0, - _START_TO_END = 1, - _END_TO_END = 2, - _END_TO_START = 3, - _BOOKMARK_ID = 0; -function _updateCollapsed(range) { - range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset); - return range; -} -function _copyAndDelete(range, isCopy, isDelete) { - var doc = range.doc, nodeList = []; - function splitTextNode(node, startOffset, endOffset) { - var length = node.nodeValue.length, centerNode; - if (isCopy) { - var cloneNode = node.cloneNode(true); - if (startOffset > 0) { - centerNode = cloneNode.splitText(startOffset); - } else { - centerNode = cloneNode; - } - if (endOffset < length) { - centerNode.splitText(endOffset - startOffset); - } - } - if (isDelete) { - var center = node; - if (startOffset > 0) { - center = node.splitText(startOffset); - range.setStart(node, startOffset); - } - if (endOffset < length) { - var right = center.splitText(endOffset - startOffset); - range.setEnd(right, 0); - } - nodeList.push(center); - } - return centerNode; - } - function removeNodes() { - if (isDelete) { - range.up().collapse(true); - } - for (var i = 0, len = nodeList.length; i < len; i++) { - var node = nodeList[i]; - if (node.parentNode) { - node.parentNode.removeChild(node); - } - } - } - var copyRange = range.cloneRange().down(); - var start = -1, incStart = -1, incEnd = -1, end = -1, - ancestor = range.commonAncestor(), frag = doc.createDocumentFragment(); - if (ancestor.nodeType == 3) { - var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset); - if (isCopy) { - frag.appendChild(textNode); - } - removeNodes(); - return isCopy ? frag : range; - } - function extractNodes(parent, frag) { - var node = parent.firstChild, nextNode; - while (node) { - var testRange = new KRange(doc).selectNode(node); - start = testRange.compareBoundaryPoints(_START_TO_END, range); - if (start >= 0 && incStart <= 0) { - incStart = testRange.compareBoundaryPoints(_START_TO_START, range); - } - if (incStart >= 0 && incEnd <= 0) { - incEnd = testRange.compareBoundaryPoints(_END_TO_END, range); - } - if (incEnd >= 0 && end <= 0) { - end = testRange.compareBoundaryPoints(_END_TO_START, range); - } - if (end >= 0) { - return false; - } - nextNode = node.nextSibling; - if (start > 0) { - if (node.nodeType == 1) { - if (incStart >= 0 && incEnd <= 0) { - if (isCopy) { - frag.appendChild(node.cloneNode(true)); - } - if (isDelete) { - nodeList.push(node); - } - } else { - var childFlag; - if (isCopy) { - childFlag = node.cloneNode(false); - frag.appendChild(childFlag); - } - if (extractNodes(node, childFlag) === false) { - return false; - } - } - } else if (node.nodeType == 3) { - var textNode; - if (node == copyRange.startContainer) { - textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length); - } else if (node == copyRange.endContainer) { - textNode = splitTextNode(node, 0, copyRange.endOffset); - } else { - textNode = splitTextNode(node, 0, node.nodeValue.length); - } - if (isCopy) { - try { - frag.appendChild(textNode); - } catch(e) {} - } - } - } - node = nextNode; - } - } - extractNodes(ancestor, frag); - if (isDelete) { - range.up().collapse(true); - } - for (var i = 0, len = nodeList.length; i < len; i++) { - var node = nodeList[i]; - if (node.parentNode) { - node.parentNode.removeChild(node); - } - } - return isCopy ? frag : range; -} -function _moveToElementText(range, el) { - var node = el; - while (node) { - var knode = K(node); - if (knode.name == 'marquee' || knode.name == 'select') { - return; - } - node = node.parentNode; - } - try { - range.moveToElementText(el); - } catch(e) {} -} -function _getStartEnd(rng, isStart) { - var doc = rng.parentElement().ownerDocument, - pointRange = rng.duplicate(); - pointRange.collapse(isStart); - var parent = pointRange.parentElement(), - nodes = parent.childNodes; - if (nodes.length === 0) { - return {node: parent.parentNode, offset: K(parent).index()}; - } - var startNode = doc, startPos = 0, cmp = -1; - var testRange = rng.duplicate(); - _moveToElementText(testRange, parent); - for (var i = 0, len = nodes.length; i < len; i++) { - var node = nodes[i]; - cmp = testRange.compareEndPoints('StartToStart', pointRange); - if (cmp === 0) { - return {node: node.parentNode, offset: i}; - } - if (node.nodeType == 1) { - var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node; - if (knode.isControl()) { - dummy = doc.createElement('span'); - knode.after(dummy); - newNode = dummy; - startPos += knode.text().replace(/\r\n|\n|\r/g, '').length; - } - _moveToElementText(nodeRange, newNode); - testRange.setEndPoint('StartToEnd', nodeRange); - if (cmp > 0) { - startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length; - } else { - startPos = 0; - } - if (dummy) { - K(dummy).remove(); - } - } else if (node.nodeType == 3) { - testRange.moveStart('character', node.nodeValue.length); - startPos += node.nodeValue.length; - } - if (cmp < 0) { - startNode = node; - } - } - if (cmp < 0 && startNode.nodeType == 1) { - return {node: parent, offset: K(parent.lastChild).index() + 1}; - } - if (cmp > 0) { - while (startNode.nextSibling && startNode.nodeType == 1) { - startNode = startNode.nextSibling; - } - } - testRange = rng.duplicate(); - _moveToElementText(testRange, parent); - testRange.setEndPoint('StartToEnd', pointRange); - startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length; - if (cmp > 0 && startNode.nodeType == 3) { - var prevNode = startNode.previousSibling; - while (prevNode && prevNode.nodeType == 3) { - startPos -= prevNode.nodeValue.length; - prevNode = prevNode.previousSibling; - } - } - return {node: startNode, offset: startPos}; -} -function _getEndRange(node, offset) { - var doc = node.ownerDocument || node, - range = doc.body.createTextRange(); - if (doc == node) { - range.collapse(true); - return range; - } - if (node.nodeType == 1 && node.childNodes.length > 0) { - var children = node.childNodes, isStart, child; - if (offset === 0) { - child = children[0]; - isStart = true; - } else { - child = children[offset - 1]; - isStart = false; - } - if (!child) { - return range; - } - if (K(child).name === 'head') { - if (offset === 1) { - isStart = true; - } - if (offset === 2) { - isStart = false; - } - range.collapse(isStart); - return range; - } - if (child.nodeType == 1) { - var kchild = K(child), span; - if (kchild.isControl()) { - span = doc.createElement('span'); - if (isStart) { - kchild.before(span); - } else { - kchild.after(span); - } - child = span; - } - _moveToElementText(range, child); - range.collapse(isStart); - if (span) { - K(span).remove(); - } - return range; - } - node = child; - offset = isStart ? 0 : child.nodeValue.length; - } - var dummy = doc.createElement('span'); - K(node).before(dummy); - _moveToElementText(range, dummy); - range.moveStart('character', offset); - K(dummy).remove(); - return range; -} -function _toRange(rng) { - var doc, range; - function tr2td(start) { - if (K(start.node).name == 'tr') { - start.node = start.node.cells[start.offset]; - start.offset = 0; - } - } - if (_IERANGE) { - if (rng.item) { - doc = _getDoc(rng.item(0)); - range = new KRange(doc); - range.selectNode(rng.item(0)); - return range; - } - doc = rng.parentElement().ownerDocument; - var start = _getStartEnd(rng, true), - end = _getStartEnd(rng, false); - tr2td(start); - tr2td(end); - range = new KRange(doc); - range.setStart(start.node, start.offset); - range.setEnd(end.node, end.offset); - return range; - } - var startContainer = rng.startContainer; - doc = startContainer.ownerDocument || startContainer; - range = new KRange(doc); - range.setStart(startContainer, rng.startOffset); - range.setEnd(rng.endContainer, rng.endOffset); - return range; -} -function KRange(doc) { - this.init(doc); -} -_extend(KRange, { - init : function(doc) { - var self = this; - self.startContainer = doc; - self.startOffset = 0; - self.endContainer = doc; - self.endOffset = 0; - self.collapsed = true; - self.doc = doc; - }, - commonAncestor : function() { - function getParents(node) { - var parents = []; - while (node) { - parents.push(node); - node = node.parentNode; - } - return parents; - } - var parentsA = getParents(this.startContainer), - parentsB = getParents(this.endContainer), - i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB; - while (++i) { - parentA = parentsA[lenA - i]; - parentB = parentsB[lenB - i]; - if (!parentA || !parentB || parentA !== parentB) { - break; - } - } - return parentsA[lenA - i + 1]; - }, - setStart : function(node, offset) { - var self = this, doc = self.doc; - self.startContainer = node; - self.startOffset = offset; - if (self.endContainer === doc) { - self.endContainer = node; - self.endOffset = offset; - } - return _updateCollapsed(this); - }, - setEnd : function(node, offset) { - var self = this, doc = self.doc; - self.endContainer = node; - self.endOffset = offset; - if (self.startContainer === doc) { - self.startContainer = node; - self.startOffset = offset; - } - return _updateCollapsed(this); - }, - setStartBefore : function(node) { - return this.setStart(node.parentNode || this.doc, K(node).index()); - }, - setStartAfter : function(node) { - return this.setStart(node.parentNode || this.doc, K(node).index() + 1); - }, - setEndBefore : function(node) { - return this.setEnd(node.parentNode || this.doc, K(node).index()); - }, - setEndAfter : function(node) { - return this.setEnd(node.parentNode || this.doc, K(node).index() + 1); - }, - selectNode : function(node) { - return this.setStartBefore(node).setEndAfter(node); - }, - selectNodeContents : function(node) { - var knode = K(node); - if (knode.type == 3 || knode.isSingle()) { - return this.selectNode(node); - } - var children = knode.children(); - if (children.length > 0) { - return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]); - } - return this.setStart(node, 0).setEnd(node, 0); - }, - collapse : function(toStart) { - if (toStart) { - return this.setEnd(this.startContainer, this.startOffset); - } - return this.setStart(this.endContainer, this.endOffset); - }, - compareBoundaryPoints : function(how, range) { - var rangeA = this.get(), rangeB = range.get(); - if (_IERANGE) { - var arr = {}; - arr[_START_TO_START] = 'StartToStart'; - arr[_START_TO_END] = 'EndToStart'; - arr[_END_TO_END] = 'EndToEnd'; - arr[_END_TO_START] = 'StartToEnd'; - var cmp = rangeA.compareEndPoints(arr[how], rangeB); - if (cmp !== 0) { - return cmp; - } - var nodeA, nodeB, nodeC, posA, posB; - if (how === _START_TO_START || how === _END_TO_START) { - nodeA = this.startContainer; - posA = this.startOffset; - } - if (how === _START_TO_END || how === _END_TO_END) { - nodeA = this.endContainer; - posA = this.endOffset; - } - if (how === _START_TO_START || how === _START_TO_END) { - nodeB = range.startContainer; - posB = range.startOffset; - } - if (how === _END_TO_END || how === _END_TO_START) { - nodeB = range.endContainer; - posB = range.endOffset; - } - if (nodeA === nodeB) { - var diff = posA - posB; - return diff > 0 ? 1 : (diff < 0 ? -1 : 0); - } - nodeC = nodeB; - while (nodeC && nodeC.parentNode !== nodeA) { - nodeC = nodeC.parentNode; - } - if (nodeC) { - return K(nodeC).index() >= posA ? -1 : 1; - } - nodeC = nodeA; - while (nodeC && nodeC.parentNode !== nodeB) { - nodeC = nodeC.parentNode; - } - if (nodeC) { - return K(nodeC).index() >= posB ? 1 : -1; - } - nodeC = K(nodeB).next(); - if (nodeC && nodeC.contains(nodeA)) { - return 1; - } - nodeC = K(nodeA).next(); - if (nodeC && nodeC.contains(nodeB)) { - return -1; - } - } else { - return rangeA.compareBoundaryPoints(how, rangeB); - } - }, - cloneRange : function() { - return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset); - }, - toString : function() { - var rng = this.get(), str = _IERANGE ? rng.text : rng.toString(); - return str.replace(/\r\n|\n|\r/g, ''); - }, - cloneContents : function() { - return _copyAndDelete(this, true, false); - }, - deleteContents : function() { - return _copyAndDelete(this, false, true); - }, - extractContents : function() { - return _copyAndDelete(this, true, true); - }, - insertNode : function(node) { - var self = this, - sc = self.startContainer, so = self.startOffset, - ec = self.endContainer, eo = self.endOffset, - firstChild, lastChild, c, nodeCount = 1; - if (node.nodeName.toLowerCase() === '#document-fragment') { - firstChild = node.firstChild; - lastChild = node.lastChild; - nodeCount = node.childNodes.length; - } - if (sc.nodeType == 1) { - c = sc.childNodes[so]; - if (c) { - sc.insertBefore(node, c); - if (sc === ec) { - eo += nodeCount; - } - } else { - sc.appendChild(node); - } - } else if (sc.nodeType == 3) { - if (so === 0) { - sc.parentNode.insertBefore(node, sc); - if (sc.parentNode === ec) { - eo += nodeCount; - } - } else if (so >= sc.nodeValue.length) { - if (sc.nextSibling) { - sc.parentNode.insertBefore(node, sc.nextSibling); - } else { - sc.parentNode.appendChild(node); - } - } else { - if (so > 0) { - c = sc.splitText(so); - } else { - c = sc; - } - sc.parentNode.insertBefore(node, c); - if (sc === ec) { - ec = c; - eo -= so; - } - } - } - if (firstChild) { - self.setStartBefore(firstChild).setEndAfter(lastChild); - } else { - self.selectNode(node); - } - if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) { - return self; - } - return self.setEnd(ec, eo); - }, - surroundContents : function(node) { - node.appendChild(this.extractContents()); - return this.insertNode(node).selectNode(node); - }, - isControl : function() { - var self = this, - sc = self.startContainer, so = self.startOffset, - ec = self.endContainer, eo = self.endOffset, rng; - return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl(); - }, - get : function(hasControlRange) { - var self = this, doc = self.doc, node, rng; - if (!_IERANGE) { - rng = doc.createRange(); - try { - rng.setStart(self.startContainer, self.startOffset); - rng.setEnd(self.endContainer, self.endOffset); - } catch (e) {} - return rng; - } - if (hasControlRange && self.isControl()) { - rng = doc.body.createControlRange(); - rng.addElement(self.startContainer.childNodes[self.startOffset]); - return rng; - } - var range = self.cloneRange().down(); - rng = doc.body.createTextRange(); - rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset)); - rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset)); - return rng; - }, - html : function() { - return K(this.cloneContents()).outer(); - }, - down : function() { - var self = this; - function downPos(node, pos, isStart) { - if (node.nodeType != 1) { - return; - } - var children = K(node).children(); - if (children.length === 0) { - return; - } - var left, right, child, offset; - if (pos > 0) { - left = children.eq(pos - 1); - } - if (pos < children.length) { - right = children.eq(pos); - } - if (left && left.type == 3) { - child = left[0]; - offset = child.nodeValue.length; - } - if (right && right.type == 3) { - child = right[0]; - offset = 0; - } - if (!child) { - return; - } - if (isStart) { - self.setStart(child, offset); - } else { - self.setEnd(child, offset); - } - } - downPos(self.startContainer, self.startOffset, true); - downPos(self.endContainer, self.endOffset, false); - return self; - }, - up : function() { - var self = this; - function upPos(node, pos, isStart) { - if (node.nodeType != 3) { - return; - } - if (pos === 0) { - if (isStart) { - self.setStartBefore(node); - } else { - self.setEndBefore(node); - } - } else if (pos == node.nodeValue.length) { - if (isStart) { - self.setStartAfter(node); - } else { - self.setEndAfter(node); - } - } - } - upPos(self.startContainer, self.startOffset, true); - upPos(self.endContainer, self.endOffset, false); - return self; - }, - enlarge : function(toBlock) { - var self = this; - self.up(); - function enlargePos(node, pos, isStart) { - var knode = K(node), parent; - if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) { - return; - } - if (pos === 0) { - while (!knode.prev()) { - parent = knode.parent(); - if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) { - break; - } - knode = parent; - } - if (isStart) { - self.setStartBefore(knode[0]); - } else { - self.setEndBefore(knode[0]); - } - } else if (pos == knode.children().length) { - while (!knode.next()) { - parent = knode.parent(); - if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) { - break; - } - knode = parent; - } - if (isStart) { - self.setStartAfter(knode[0]); - } else { - self.setEndAfter(knode[0]); - } - } - } - enlargePos(self.startContainer, self.startOffset, true); - enlargePos(self.endContainer, self.endOffset, false); - return self; - }, - shrink : function() { - var self = this, child, collapsed = self.collapsed; - while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) { - self.setStart(child, 0); - } - if (collapsed) { - return self.collapse(collapsed); - } - while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) { - self.setEnd(child, child.childNodes.length); - } - return self; - }, - createBookmark : function(serialize) { - var self = this, doc = self.doc, endNode, - startNode = K('', doc)[0]; - startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__'; - if (!self.collapsed) { - endNode = startNode.cloneNode(true); - endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__'; - } - if (endNode) { - self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode); - } - self.insertNode(startNode).setStartAfter(startNode); - return { - start : serialize ? '#' + startNode.id : startNode, - end : endNode ? (serialize ? '#' + endNode.id : endNode) : null - }; - }, - moveToBookmark : function(bookmark) { - var self = this, doc = self.doc, - start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null; - if (!start || start.length < 1) { - return self; - } - self.setStartBefore(start[0]); - start.remove(); - if (end && end.length > 0) { - self.setEndBefore(end[0]); - end.remove(); - } else { - self.collapse(true); - } - return self; - }, - dump : function() { - console.log('--------------------'); - console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset); - console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset); - } -}); -function _range(mixed) { - if (!mixed.nodeName) { - return mixed.constructor === KRange ? mixed : _toRange(mixed); - } - return new KRange(mixed); -} -K.RangeClass = KRange; -K.range = _range; -K.START_TO_START = _START_TO_START; -K.START_TO_END = _START_TO_END; -K.END_TO_END = _END_TO_END; -K.END_TO_START = _END_TO_START; -function _nativeCommand(doc, key, val) { - try { - doc.execCommand(key, false, val); - } catch(e) {} -} -function _nativeCommandValue(doc, key) { - var val = ''; - try { - val = doc.queryCommandValue(key); - } catch (e) {} - if (typeof val !== 'string') { - val = ''; - } - return val; -} -function _getSel(doc) { - var win = _getWin(doc); - return _IERANGE ? doc.selection : win.getSelection(); -} -function _getRng(doc) { - var sel = _getSel(doc), rng; - try { - if (sel.rangeCount > 0) { - rng = sel.getRangeAt(0); - } else { - rng = sel.createRange(); - } - } catch(e) {} - if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) { - return null; - } - return rng; -} -function _singleKeyMap(map) { - var newMap = {}, arr, v; - _each(map, function(key, val) { - arr = key.split(','); - for (var i = 0, len = arr.length; i < len; i++) { - v = arr[i]; - newMap[v] = val; - } - }); - return newMap; -} -function _hasAttrOrCss(knode, map) { - return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map); -} -function _hasAttrOrCssByKey(knode, map, mapKey) { - mapKey = mapKey || knode.name; - if (knode.type !== 1) { - return false; - } - var newMap = _singleKeyMap(map); - if (!newMap[mapKey]) { - return false; - } - var arr = newMap[mapKey].split(','); - for (var i = 0, len = arr.length; i < len; i++) { - var key = arr[i]; - if (key === '*') { - return true; - } - var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key); - var method = match[1] ? 'css' : 'attr'; - key = match[2]; - var val = match[3] || ''; - if (val === '' && knode[method](key) !== '') { - return true; - } - if (val !== '' && knode[method](key) === val) { - return true; - } - } - return false; -} -function _removeAttrOrCss(knode, map) { - if (knode.type != 1) { - return; - } - _removeAttrOrCssByKey(knode, map, '*'); - _removeAttrOrCssByKey(knode, map); -} -function _removeAttrOrCssByKey(knode, map, mapKey) { - mapKey = mapKey || knode.name; - if (knode.type !== 1) { - return; - } - var newMap = _singleKeyMap(map); - if (!newMap[mapKey]) { - return; - } - var arr = newMap[mapKey].split(','), allFlag = false; - for (var i = 0, len = arr.length; i < len; i++) { - var key = arr[i]; - if (key === '*') { - allFlag = true; - break; - } - var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key); - key = match[2]; - if (match[1]) { - key = _toCamel(key); - if (knode[0].style[key]) { - knode[0].style[key] = ''; - } - } else { - knode.removeAttr(key); - } - } - if (allFlag) { - knode.remove(true); - } -} -function _getInnerNode(knode) { - var inner = knode; - while (inner.first()) { - inner = inner.first(); - } - return inner; -} -function _isEmptyNode(knode) { - if (knode.type != 1 || knode.isSingle()) { - return false; - } - return knode.html().replace(/<[^>]+>/g, '') === ''; -} -function _mergeWrapper(a, b) { - a = a.clone(true); - var lastA = _getInnerNode(a), childA = a, merged = false; - while (b) { - while (childA) { - if (childA.name === b.name) { - _mergeAttrs(childA, b.attr(), b.css()); - merged = true; - } - childA = childA.first(); - } - if (!merged) { - lastA.append(b.clone(false)); - } - merged = false; - b = b.first(); - } - return a; -} -function _wrapNode(knode, wrapper) { - wrapper = wrapper.clone(true); - if (knode.type == 3) { - _getInnerNode(wrapper).append(knode.clone(false)); - knode.replaceWith(wrapper); - return wrapper; - } - var nodeWrapper = knode, child; - while ((child = knode.first()) && child.children().length == 1) { - knode = child; - } - child = knode.first(); - var frag = knode.doc.createDocumentFragment(); - while (child) { - frag.appendChild(child[0]); - child = child.next(); - } - wrapper = _mergeWrapper(nodeWrapper, wrapper); - if (frag.firstChild) { - _getInnerNode(wrapper).append(frag); - } - nodeWrapper.replaceWith(wrapper); - return wrapper; -} -function _mergeAttrs(knode, attrs, styles) { - _each(attrs, function(key, val) { - if (key !== 'style') { - knode.attr(key, val); - } - }); - _each(styles, function(key, val) { - knode.css(key, val); - }); -} -function _inPreElement(knode) { - while (knode && knode.name != 'body') { - if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) { - return true; - } - knode = knode.parent(); - } - return false; -} -function KCmd(range) { - this.init(range); -} -_extend(KCmd, { - init : function(range) { - var self = this, doc = range.doc; - self.doc = doc; - self.win = _getWin(doc); - self.sel = _getSel(doc); - self.range = range; - }, - selection : function(forceReset) { - var self = this, doc = self.doc, rng = _getRng(doc); - self.sel = _getSel(doc); - if (rng) { - self.range = _range(rng); - if (K(self.range.startContainer).name == 'html') { - self.range.selectNodeContents(doc.body).collapse(false); - } - return self; - } - if (forceReset) { - self.range.selectNodeContents(doc.body).collapse(false); - } - return self; - }, - select : function(hasDummy) { - hasDummy = _undef(hasDummy, true); - var self = this, sel = self.sel, range = self.range.cloneRange().shrink(), - sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset, - doc = _getDoc(sc), win = self.win, rng, hasU200b = false; - if (hasDummy && sc.nodeType == 1 && range.collapsed) { - if (_IERANGE) { - var dummy = K(' ', doc); - range.insertNode(dummy[0]); - rng = doc.body.createTextRange(); - try { - rng.moveToElementText(dummy[0]); - } catch(ex) {} - rng.collapse(false); - rng.select(); - dummy.remove(); - win.focus(); - return self; - } - if (_WEBKIT) { - var children = sc.childNodes; - if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) { - range.insertNode(doc.createTextNode('\u200B')); - hasU200b = true; - } - } - } - if (_IERANGE) { - try { - rng = range.get(true); - rng.select(); - } catch(e) {} - } else { - if (hasU200b) { - range.collapse(false); - } - rng = range.get(true); - sel.removeAllRanges(); - sel.addRange(rng); - if (doc !== document) { - var pos = K(rng.endContainer).pos(); - win.scrollTo(pos.x, pos.y); - } - } - win.focus(); - return self; - }, - wrap : function(val) { - var self = this, doc = self.doc, range = self.range, wrapper; - wrapper = K(val, doc); - if (range.collapsed) { - range.shrink(); - range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]); - return self; - } - if (wrapper.isBlock()) { - var copyWrapper = wrapper.clone(true), child = copyWrapper; - while (child.first()) { - child = child.first(); - } - child.append(range.extractContents()); - range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]); - return self; - } - range.enlarge(); - var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false; - K(ancestor).scan(function(node) { - if (!isStart && node == bookmark.start) { - isStart = true; - return; - } - if (isStart) { - if (node == bookmark.end) { - return false; - } - var knode = K(node); - if (_inPreElement(knode)) { - return; - } - if (knode.type == 3 && _trim(node.nodeValue).length > 0) { - var parent; - while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) { - knode = parent; - } - _wrapNode(knode, wrapper); - } - } - }); - range.moveToBookmark(bookmark); - return self; - }, - split : function(isStart, map) { - var range = this.range, doc = range.doc; - var tempRange = range.cloneRange().collapse(isStart); - var node = tempRange.startContainer, pos = tempRange.startOffset, - parent = node.nodeType == 3 ? node.parentNode : node, - needSplit = false, knode; - while (parent && parent.parentNode) { - knode = K(parent); - if (map) { - if (!knode.isStyle()) { - break; - } - if (!_hasAttrOrCss(knode, map)) { - break; - } - } else { - if (_NOSPLIT_TAG_MAP[knode.name]) { - break; - } - } - needSplit = true; - parent = parent.parentNode; - } - if (needSplit) { - var dummy = doc.createElement('span'); - range.cloneRange().collapse(!isStart).insertNode(dummy); - if (isStart) { - tempRange.setStartBefore(parent.firstChild).setEnd(node, pos); - } else { - tempRange.setStart(node, pos).setEndAfter(parent.lastChild); - } - var frag = tempRange.extractContents(), - first = frag.firstChild, last = frag.lastChild; - if (isStart) { - tempRange.insertNode(frag); - range.setStartAfter(last).setEndBefore(dummy); - } else { - parent.appendChild(frag); - range.setStartBefore(dummy).setEndBefore(first); - } - var dummyParent = dummy.parentNode; - if (dummyParent == range.endContainer) { - var prev = K(dummy).prev(), next = K(dummy).next(); - if (prev && next && prev.type == 3 && next.type == 3) { - range.setEnd(prev[0], prev[0].nodeValue.length); - } else if (!isStart) { - range.setEnd(range.endContainer, range.endOffset - 1); - } - } - dummyParent.removeChild(dummy); - } - return this; - }, - remove : function(map) { - var self = this, doc = self.doc, range = self.range; - range.enlarge(); - if (range.startOffset === 0) { - var ksc = K(range.startContainer), parent; - while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) { - ksc = parent; - } - range.setStart(ksc[0], 0); - ksc = K(range.startContainer); - if (ksc.isBlock()) { - _removeAttrOrCss(ksc, map); - } - var kscp = ksc.parent(); - if (kscp && kscp.isBlock()) { - _removeAttrOrCss(kscp, map); - } - } - var sc, so; - if (range.collapsed) { - self.split(true, map); - sc = range.startContainer; - so = range.startOffset; - if (so > 0) { - var sb = K(sc.childNodes[so - 1]); - if (sb && _isEmptyNode(sb)) { - sb.remove(); - range.setStart(sc, so - 1); - } - } - var sa = K(sc.childNodes[so]); - if (sa && _isEmptyNode(sa)) { - sa.remove(); - } - if (_isEmptyNode(sc)) { - range.startBefore(sc); - sc.remove(); - } - range.collapse(true); - return self; - } - self.split(true, map); - self.split(false, map); - var startDummy = doc.createElement('span'), endDummy = doc.createElement('span'); - range.cloneRange().collapse(false).insertNode(endDummy); - range.cloneRange().collapse(true).insertNode(startDummy); - var nodeList = [], cmpStart = false; - K(range.commonAncestor()).scan(function(node) { - if (!cmpStart && node == startDummy) { - cmpStart = true; - return; - } - if (node == endDummy) { - return false; - } - if (cmpStart) { - nodeList.push(node); - } - }); - K(startDummy).remove(); - K(endDummy).remove(); - sc = range.startContainer; - so = range.startOffset; - var ec = range.endContainer, eo = range.endOffset; - if (so > 0) { - var startBefore = K(sc.childNodes[so - 1]); - if (startBefore && _isEmptyNode(startBefore)) { - startBefore.remove(); - range.setStart(sc, so - 1); - if (sc == ec) { - range.setEnd(ec, eo - 1); - } - } - var startAfter = K(sc.childNodes[so]); - if (startAfter && _isEmptyNode(startAfter)) { - startAfter.remove(); - if (sc == ec) { - range.setEnd(ec, eo - 1); - } - } - } - var endAfter = K(ec.childNodes[range.endOffset]); - if (endAfter && _isEmptyNode(endAfter)) { - endAfter.remove(); - } - var bookmark = range.createBookmark(true); - _each(nodeList, function(i, node) { - _removeAttrOrCss(K(node), map); - }); - range.moveToBookmark(bookmark); - return self; - }, - commonNode : function(map) { - var range = this.range; - var ec = range.endContainer, eo = range.endOffset, - node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1]; - function find(node) { - var child = node, parent = node; - while (parent) { - if (_hasAttrOrCss(K(parent), map)) { - return K(parent); - } - parent = parent.parentNode; - } - while (child && (child = child.lastChild)) { - if (_hasAttrOrCss(K(child), map)) { - return K(child); - } - } - return null; - } - var cNode = find(node); - if (cNode) { - return cNode; - } - if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) { - var prev = K(node).prev(); - if (prev) { - return find(prev); - } - } - return null; - }, - commonAncestor : function(tagName) { - var range = this.range, - sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset, - startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1], - endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1]; - function find(node) { - while (node) { - if (node.nodeType == 1) { - if (node.tagName.toLowerCase() === tagName) { - return node; - } - } - node = node.parentNode; - } - return null; - } - var start = find(startNode), end = find(endNode); - if (start && end && start === end) { - return K(start); - } - return null; - }, - state : function(key) { - var self = this, doc = self.doc, bool = false; - try { - bool = doc.queryCommandState(key); - } catch (e) {} - return bool; - }, - val : function(key) { - var self = this, doc = self.doc, range = self.range; - function lc(val) { - return val.toLowerCase(); - } - key = lc(key); - var val = '', knode; - if (key === 'fontfamily' || key === 'fontname') { - val = _nativeCommandValue(doc, 'fontname'); - val = val.replace(/['"]/g, ''); - return lc(val); - } - if (key === 'formatblock') { - val = _nativeCommandValue(doc, key); - if (val === '') { - knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'}); - if (knode) { - val = knode.name; - } - } - if (val === 'Normal') { - val = 'p'; - } - return lc(val); - } - if (key === 'fontsize') { - knode = self.commonNode({'*' : '.font-size'}); - if (knode) { - val = knode.css('font-size'); - } - return lc(val); - } - if (key === 'forecolor') { - knode = self.commonNode({'*' : '.color'}); - if (knode) { - val = knode.css('color'); - } - val = _toHex(val); - if (val === '') { - val = 'default'; - } - return lc(val); - } - if (key === 'hilitecolor') { - knode = self.commonNode({'*' : '.background-color'}); - if (knode) { - val = knode.css('background-color'); - } - val = _toHex(val); - if (val === '') { - val = 'default'; - } - return lc(val); - } - return val; - }, - toggle : function(wrapper, map) { - var self = this; - if (self.commonNode(map)) { - self.remove(map); - } else { - self.wrap(wrapper); - } - return self.select(); - }, - bold : function() { - return this.toggle('', { - span : '.font-weight=bold', - strong : '*', - b : '*' - }); - }, - italic : function() { - return this.toggle('', { - span : '.font-style=italic', - em : '*', - i : '*' - }); - }, - underline : function() { - return this.toggle('', { - span : '.text-decoration=underline', - u : '*' - }); - }, - strikethrough : function() { - return this.toggle('', { - span : '.text-decoration=line-through', - s : '*' - }); - }, - forecolor : function(val) { - return this.wrap('').select(); - }, - hilitecolor : function(val) { - return this.wrap('').select(); - }, - fontsize : function(val) { - return this.wrap('').select(); - }, - fontname : function(val) { - return this.fontfamily(val); - }, - fontfamily : function(val) { - return this.wrap('').select(); - }, - removeformat : function() { - var map = { - '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent' - }, - tags = _STYLE_TAG_MAP; - _each(tags, function(key, val) { - map[key] = '*'; - }); - this.remove(map); - return this.select(); - }, - inserthtml : function(val, quickMode) { - var self = this, range = self.range; - if (val === '') { - return self; - } - function pasteHtml(range, val) { - val = '' + val; - var rng = range.get(); - if (rng.item) { - rng.item(0).outerHTML = val; - } else { - rng.pasteHTML(val); - } - var temp = range.doc.getElementById('__kindeditor_temp_tag__'); - temp.parentNode.removeChild(temp); - var newRange = _toRange(rng); - range.setEnd(newRange.endContainer, newRange.endOffset); - range.collapse(false); - self.select(false); - } - function insertHtml(range, val) { - var doc = range.doc, - frag = doc.createDocumentFragment(); - K('@' + val, doc).each(function() { - frag.appendChild(this); - }); - range.deleteContents(); - range.insertNode(frag); - range.collapse(false); - self.select(false); - } - if (_IERANGE && quickMode) { - try { - pasteHtml(range, val); - } catch(e) { - insertHtml(range, val); - } - return self; - } - insertHtml(range, val); - return self; - }, - hr : function() { - return this.inserthtml('
'); - }, - print : function() { - this.win.print(); - return this; - }, - insertimage : function(url, title, width, height, border, align) { - title = _undef(title, ''); - border = _undef(border, 0); - var html = ''; - return self.inserthtml(html); - } - if (range.isControl()) { - var node = K(range.startContainer.childNodes[range.startOffset]); - html += '>'; - node.after(K(html, doc)); - node.next().append(node); - range.selectNode(node[0]); - return self.select(); - } - function setAttr(node, url, type) { - K(node).attr('href', url).attr('data-ke-src', url); - if (type) { - K(node).attr('target', type); - } else { - K(node).removeAttr('target'); - } - } - var sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset; - if (sc.nodeType == 1 && sc === ec && so + 1 === eo) { - var child = sc.childNodes[so]; - if (child.nodeName.toLowerCase() == 'a') { - setAttr(child, url, type); - return self; - } - } - _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__'); - K('a[href="__kindeditor_temp_url__"]', doc).each(function() { - setAttr(this, url, type); - }); - return self; - }, - unlink : function() { - var self = this, doc = self.doc, range = self.range; - self.select(); - if (range.collapsed) { - var a = self.commonNode({ a : '*' }); - if (a) { - range.selectNode(a.get()); - self.select(); - } - _nativeCommand(doc, 'unlink', null); - if (_WEBKIT && K(range.startContainer).name === 'img') { - var parent = K(range.startContainer).parent(); - if (parent.name === 'a') { - parent.remove(true); - } - } - } else { - _nativeCommand(doc, 'unlink', null); - } - return self; - } -}); -_each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' + - 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) { - KCmd.prototype[name] = function(val) { - var self = this; - self.select(); - _nativeCommand(self.doc, name, val); - if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) { - self.selection(); - } - if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) { - self.selection(); - } - return self; - }; -}); -_each('cut,copy,paste'.split(','), function(i, name) { - KCmd.prototype[name] = function() { - var self = this; - if (!self.doc.queryCommandSupported(name)) { - throw 'not supported'; - } - self.select(); - _nativeCommand(self.doc, name, null); - return self; - }; -}); -function _cmd(mixed) { - if (mixed.nodeName) { - var doc = _getDoc(mixed); - mixed = _range(doc).selectNodeContents(doc.body).collapse(false); - } - return new KCmd(mixed); -} -K.CmdClass = KCmd; -K.cmd = _cmd; -function _drag(options) { - var moveEl = options.moveEl, - moveFn = options.moveFn, - clickEl = options.clickEl || moveEl, - beforeDrag = options.beforeDrag, - iframeFix = options.iframeFix === undefined ? true : options.iframeFix; - var docs = [document]; - if (iframeFix) { - K('iframe').each(function() { - var src = _formatUrl(this.src || '', 'absolute'); - if (/^https?:\/\//.test(src)) { - return; - } - var doc; - try { - doc = _iframeDoc(this); - } catch(e) {} - if (doc) { - var pos = K(this).pos(); - K(doc).data('pos-x', pos.x); - K(doc).data('pos-y', pos.y); - docs.push(doc); - } - }); - } - clickEl.mousedown(function(e) { - e.stopPropagation(); - var self = clickEl.get(), - x = _removeUnit(moveEl.css('left')), - y = _removeUnit(moveEl.css('top')), - width = moveEl.width(), - height = moveEl.height(), - pageX = e.pageX, - pageY = e.pageY; - if (beforeDrag) { - beforeDrag(); - } - function moveListener(e) { - e.preventDefault(); - var kdoc = K(_getDoc(e.target)); - var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX); - var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY); - moveFn.call(clickEl, x, y, width, height, diffX, diffY); - } - function selectListener(e) { - e.preventDefault(); - } - function upListener(e) { - e.preventDefault(); - K(docs).unbind('mousemove', moveListener) - .unbind('mouseup', upListener) - .unbind('selectstart', selectListener); - if (self.releaseCapture) { - self.releaseCapture(); - } - } - K(docs).mousemove(moveListener) - .mouseup(upListener) - .bind('selectstart', selectListener); - if (self.setCapture) { - self.setCapture(); - } - }); -} -function KWidget(options) { - this.init(options); -} -_extend(KWidget, { - init : function(options) { - var self = this; - self.name = options.name || ''; - self.doc = options.doc || document; - self.win = _getWin(self.doc); - self.x = _addUnit(options.x); - self.y = _addUnit(options.y); - self.z = options.z; - self.width = _addUnit(options.width); - self.height = _addUnit(options.height); - self.div = K('
'); - self.options = options; - self._alignEl = options.alignEl; - if (self.width) { - self.div.css('width', self.width); - } - if (self.height) { - self.div.css('height', self.height); - } - if (self.z) { - self.div.css({ - position : 'absolute', - left : self.x, - top : self.y, - 'z-index' : self.z - }); - } - if (self.z && (self.x === undefined || self.y === undefined)) { - self.autoPos(self.width, self.height); - } - if (options.cls) { - self.div.addClass(options.cls); - } - if (options.shadowMode) { - self.div.addClass('ke-shadow'); - } - if (options.css) { - self.div.css(options.css); - } - if (options.src) { - K(options.src).replaceWith(self.div); - } else { - K(self.doc.body).append(self.div); - } - if (options.html) { - self.div.html(options.html); - } - if (options.autoScroll) { - if (_IE && _V < 7 || _QUIRKS) { - var scrollPos = _getScrollPos(); - K(self.win).bind('scroll', function(e) { - var pos = _getScrollPos(), - diffX = pos.x - scrollPos.x, - diffY = pos.y - scrollPos.y; - self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false); - }); - } else { - self.div.css('position', 'fixed'); - } - } - }, - pos : function(x, y, updateProp) { - var self = this; - updateProp = _undef(updateProp, true); - if (x !== null) { - x = x < 0 ? 0 : _addUnit(x); - self.div.css('left', x); - if (updateProp) { - self.x = x; - } - } - if (y !== null) { - y = y < 0 ? 0 : _addUnit(y); - self.div.css('top', y); - if (updateProp) { - self.y = y; - } - } - return self; - }, - autoPos : function(width, height) { - var self = this, - w = _removeUnit(width) || 0, - h = _removeUnit(height) || 0, - scrollPos = _getScrollPos(); - if (self._alignEl) { - var knode = K(self._alignEl), - pos = knode.pos(), - diffX = _round(knode[0].clientWidth / 2 - w / 2), - diffY = _round(knode[0].clientHeight / 2 - h / 2); - x = diffX < 0 ? pos.x : pos.x + diffX; - y = diffY < 0 ? pos.y : pos.y + diffY; - } else { - var docEl = _docElement(self.doc); - x = _round(scrollPos.x + (docEl.clientWidth - w) / 2); - y = _round(scrollPos.y + (docEl.clientHeight - h) / 2); - } - if (!(_IE && _V < 7 || _QUIRKS)) { - x -= scrollPos.x; - y -= scrollPos.y; - } - return self.pos(x, y); - }, - remove : function() { - var self = this; - if (_IE && _V < 7 || _QUIRKS) { - K(self.win).unbind('scroll'); - } - self.div.remove(); - _each(self, function(i) { - self[i] = null; - }); - return this; - }, - show : function() { - this.div.show(); - return this; - }, - hide : function() { - this.div.hide(); - return this; - }, - draggable : function(options) { - var self = this; - options = options || {}; - options.moveEl = self.div; - options.moveFn = function(x, y, width, height, diffX, diffY) { - if ((x = x + diffX) < 0) { - x = 0; - } - if ((y = y + diffY) < 0) { - y = 0; - } - self.pos(x, y); - }; - _drag(options); - return self; - } -}); -function _widget(options) { - return new KWidget(options); -} -K.WidgetClass = KWidget; -K.widget = _widget; -function _iframeDoc(iframe) { - iframe = _get(iframe); - return iframe.contentDocument || iframe.contentWindow.document; -} -var html, _direction = ''; -if ((html = document.getElementsByTagName('html'))) { - _direction = html[0].dir; -} - -function _getInitHtml(themesPath, bodyClass, cssPath, cssData) { - var arr = [ - (_direction === '' ? '' : ''), - '', - '' - ]; - if (!_isArray(cssPath)) { - cssPath = [cssPath]; - } - _each(cssPath, function(i, path) { - if (path) { - arr.push(''); - } - }); - if (cssData) { - arr.push(''); - } - arr.push(''); - return arr.join('\n'); -} -function _elementVal(knode, val) { - if (knode.hasVal()) { - if (val === undefined) { - var html = knode.val(); - html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, ''); - return html; - } - return knode.val(val); - } - return knode.html(val); -} -function KEdit(options) { - this.init(options); -} -_extend(KEdit, KWidget, { - init : function(options) { - var self = this; - KEdit.parent.init.call(self, options); - self.srcElement = K(options.srcElement); - self.div.addClass('ke-edit'); - self.designMode = _undef(options.designMode, true); - self.beforeGetHtml = options.beforeGetHtml; - self.beforeSetHtml = options.beforeSetHtml; - self.afterSetHtml = options.afterSetHtml; - var themesPath = _undef(options.themesPath, ''), - bodyClass = options.bodyClass, - cssPath = options.cssPath, - cssData = options.cssData, - isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain, - srcScript = ('document.open();' + - (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') + - 'document.close();'), - iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : ''; - self.iframe = K('').css('width', '100%'); - self.textarea = K('').css('width', '100%'); - self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10); - self.iframe.attr('tabindex', self.tabIndex); - self.textarea.attr('tabindex', self.tabIndex); - if (self.width) { - self.setWidth(self.width); - } - if (self.height) { - self.setHeight(self.height); - } - if (self.designMode) { - self.textarea.hide(); - } else { - self.iframe.hide(); - } - function ready() { - var doc = _iframeDoc(self.iframe); - doc.open(); - if (isDocumentDomain) { - doc.domain = document.domain; - } - doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData)); - doc.close(); - self.win = self.iframe[0].contentWindow; - self.doc = doc; - var cmd = _cmd(doc); - self.afterChange(function(e) { - cmd.selection(); - }); - if (_WEBKIT) { - K(doc).click(function(e) { - if (K(e.target).name === 'img') { - cmd.selection(true); - cmd.range.selectNode(e.target); - cmd.select(); - } - }); - } - if (_IE) { - self._mousedownHandler = function() { - var newRange = cmd.range.cloneRange(); - newRange.shrink(); - if (newRange.isControl()) { - self.blur(); - } - }; - K(document).mousedown(self._mousedownHandler); - K(doc).keydown(function(e) { - if (e.which == 8) { - cmd.selection(); - var rng = cmd.range; - if (rng.isControl()) { - rng.collapse(true); - K(rng.startContainer.childNodes[rng.startOffset]).remove(); - e.preventDefault(); - } - } - }); - } - self.cmd = cmd; - self.html(_elementVal(self.srcElement)); - if (_IE) { - doc.body.disabled = true; - doc.body.contentEditable = true; - doc.body.removeAttribute('disabled'); - } else { - doc.designMode = 'on'; - } - if (options.afterCreate) { - options.afterCreate.call(self); - } - } - if (isDocumentDomain) { - self.iframe.bind('load', function(e) { - self.iframe.unbind('load'); - if (_IE) { - ready(); - } else { - setTimeout(ready, 0); - } - }); - } - self.div.append(self.iframe); - self.div.append(self.textarea); - self.srcElement.hide(); - !isDocumentDomain && ready(); - }, - setWidth : function(val) { - var self = this; - val = _addUnit(val); - self.width = val; - self.div.css('width', val); - return self; - }, - setHeight : function(val) { - var self = this; - val = _addUnit(val); - self.height = val; - self.div.css('height', val); - self.iframe.css('height', val); - if ((_IE && _V < 8) || _QUIRKS) { - val = _addUnit(_removeUnit(val) - 2); - } - self.textarea.css('height', val); - return self; - }, - remove : function() { - var self = this, doc = self.doc; - K(doc.body).unbind(); - K(doc).unbind(); - K(self.win).unbind(); - if (self._mousedownHandler) { - K(document).unbind('mousedown', self._mousedownHandler); - } - _elementVal(self.srcElement, self.html()); - self.srcElement.show(); - doc.write(''); - self.iframe.unbind(); - self.textarea.unbind(); - KEdit.parent.remove.call(self); - }, - html : function(val, isFull) { - var self = this, doc = self.doc; - if (self.designMode) { - var body = doc.body; - if (val === undefined) { - if (isFull) { - val = '' + body.parentNode.innerHTML + ''; - } else { - val = body.innerHTML; - } - if (self.beforeGetHtml) { - val = self.beforeGetHtml(val); - } - if (_GECKO && val == '
') { - val = ''; - } - return val; - } - if (self.beforeSetHtml) { - val = self.beforeSetHtml(val); - } - if (_IE && _V >= 9) { - val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2'); - } - K(body).html(val); - if (self.afterSetHtml) { - self.afterSetHtml(); - } - return self; - } - if (val === undefined) { - return self.textarea.val(); - } - self.textarea.val(val); - return self; - }, - design : function(bool) { - var self = this, val; - if (bool === undefined ? !self.designMode : bool) { - if (!self.designMode) { - val = self.html(); - self.designMode = true; - self.html(val); - self.textarea.hide(); - self.iframe.show(); - } - } else { - if (self.designMode) { - val = self.html(); - self.designMode = false; - self.html(val); - self.iframe.hide(); - self.textarea.show(); - } - } - return self.focus(); - }, - focus : function() { - var self = this; - self.designMode ? self.win.focus() : self.textarea[0].focus(); - return self; - }, - blur : function() { - var self = this; - if (_IE) { - var input = K('', self.div); - self.div.append(input); - input[0].focus(); - input.remove(); - } else { - self.designMode ? self.win.blur() : self.textarea[0].blur(); - } - return self; - }, - afterChange : function(fn) { - var self = this, doc = self.doc, body = doc.body; - K(doc).keyup(function(e) { - if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) { - fn(e); - } - }); - K(doc).mouseup(fn).contextmenu(fn); - K(self.win).blur(fn); - function timeoutHandler(e) { - setTimeout(function() { - fn(e); - }, 1); - } - K(body).bind('paste', timeoutHandler); - K(body).bind('cut', timeoutHandler); - return self; - } -}); -function _edit(options) { - return new KEdit(options); -} -K.EditClass = KEdit; -K.edit = _edit; -K.iframeDoc = _iframeDoc; -function _selectToolbar(name, fn) { - var self = this, - knode = self.get(name); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - fn(knode); - } -} -function KToolbar(options) { - this.init(options); -} -_extend(KToolbar, KWidget, { - init : function(options) { - var self = this; - KToolbar.parent.init.call(self, options); - self.disableMode = _undef(options.disableMode, false); - self.noDisableItemMap = _toMap(_undef(options.noDisableItems, [])); - self._itemMap = {}; - self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) { - e.preventDefault(); - }).attr('unselectable', 'on'); - function find(target) { - var knode = K(target); - if (knode.hasClass('ke-outline')) { - return knode; - } - if (knode.hasClass('ke-toolbar-icon')) { - return knode.parent(); - } - } - function hover(e, method) { - var knode = find(e.target); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - if (knode.hasClass('ke-selected')) { - return; - } - knode[method]('ke-on'); - } - } - self.div.mouseover(function(e) { - hover(e, 'addClass'); - }) - .mouseout(function(e) { - hover(e, 'removeClass'); - }) - .click(function(e) { - var knode = find(e.target); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - self.options.click.call(this, e, knode.attr('data-name')); - } - }); - }, - get : function(name) { - //if(this._itemMap[name])return this._itemMap[name]; - //return this._itemMap[name]=K("span.ke-icon-"+name,this.div).parent() -// if (this._itemMap[name]) { -// return this._itemMap[name]; -// } -// if($("#define").css('display') == 'block'){ -// pdiv = $("#define") -// }else if($("#full").css('display') == 'block'){ -// pdiv = $("#full") -// } - var container = this.div; - if(!$("#define",container).is(':hidden')){ - pdiv = $("#define",container); - }else if(!$("#full",container).is(':hidden')){ - pdiv = $("#full",container); - } - return (this._itemMap[name] = K('span.ke-icon-' + name, pdiv).parent()); - }, - select : function(name) { - _selectToolbar.call(this, name, function(knode) { - knode.addClass('ke-selected'); - }); - return self; - }, - unselect : function(name) { - _selectToolbar.call(this, name, function(knode) { - knode.removeClass('ke-selected').removeClass('ke-on'); - }); - return self; - }, - enable : function(name) { - var self = this, - knode = name.get ? name : self.get(name); - if (knode) { - knode.removeClass('ke-disabled'); - knode.opacity(1); - } - return self; - }, - disable : function(name) { - var self = this, - knode = name.get ? name : self.get(name); - if (knode) { - knode.removeClass('ke-selected').addClass('ke-disabled'); - knode.opacity(0.5); - } - return self; - }, - disableAll : function(bool, noDisableItems) { - var self = this, map = self.noDisableItemMap, item; - if (noDisableItems) { - map = _toMap(noDisableItems); - } - if (bool === undefined ? !self.disableMode : bool) { - K('span.ke-outline', self.div).each(function() { - var knode = K(this), - name = knode[0].getAttribute('data-name', 2); - if (!map[name]) { - self.disable(knode); - } - }); - self.disableMode = true; - } else { - K('span.ke-outline', self.div).each(function() { - var knode = K(this), - name = knode[0].getAttribute('data-name', 2); - if (!map[name]) { - self.enable(knode); - } - }); - self.disableMode = false; - } - return self; - } -}); -function _toolbar(options) { - return new KToolbar(options); -} -K.ToolbarClass = KToolbar; -K.toolbar = _toolbar; -function KMenu(options) { - this.init(options); -} -_extend(KMenu, KWidget, { - init : function(options) { - var self = this; - options.z = options.z || 811213; - KMenu.parent.init.call(self, options); - self.centerLineMode = _undef(options.centerLineMode, true); - self.div.addClass('ke-menu').bind('click,mousedown', function(e){ - e.stopPropagation(); - }).attr('unselectable', 'on'); - }, - addItem : function(item) { - var self = this; - if (item.title === '-') { - self.div.append(K('
')); - return; - } - var itemDiv = K('
'), - leftDiv = K('
'), - rightDiv = K('
'), - height = _addUnit(item.height), - iconClass = _undef(item.iconClass, ''); - self.div.append(itemDiv); - if (height) { - itemDiv.css('height', height); - rightDiv.css('line-height', height); - } - var centerDiv; - if (self.centerLineMode) { - centerDiv = K('
'); - if (height) { - centerDiv.css('height', height); - } - } - itemDiv.mouseover(function(e) { - K(this).addClass('ke-menu-item-on'); - if (centerDiv) { - centerDiv.addClass('ke-menu-item-center-on'); - } - }) - .mouseout(function(e) { - K(this).removeClass('ke-menu-item-on'); - if (centerDiv) { - centerDiv.removeClass('ke-menu-item-center-on'); - } - }) - .click(function(e) { - item.click.call(K(this)); - e.stopPropagation(); - }) - .append(leftDiv); - if (centerDiv) { - itemDiv.append(centerDiv); - } - itemDiv.append(rightDiv); - if (item.checked) { - iconClass = 'ke-icon-checked'; - } - if (iconClass !== '') { - leftDiv.html(''); - } - rightDiv.html(item.title); - return self; - }, - remove : function() { - var self = this; - if (self.options.beforeRemove) { - self.options.beforeRemove.call(self); - } - K('.ke-menu-item', self.div[0]).unbind(); - KMenu.parent.remove.call(self); - return self; - } -}); -function _menu(options) { - return new KMenu(options); -} -K.MenuClass = KMenu; -K.menu = _menu; -function KColorPicker(options) { - this.init(options); -} -_extend(KColorPicker, KWidget, { - init : function(options) { - var self = this; - options.z = options.z || 811213; - KColorPicker.parent.init.call(self, options); - var colors = options.colors || [ - ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], - ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], - ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], - ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] - ]; - self.selectedColor = (options.selectedColor || '').toLowerCase(); - self._cells = []; - self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){ - e.stopPropagation(); - }).attr('unselectable', 'on'); - var table = self.doc.createElement('table'); - self.div.append(table); - table.className = 'ke-colorpicker-table'; - table.cellPadding = 0; - table.cellSpacing = 0; - table.border = 0; - var row = table.insertRow(0), cell = row.insertCell(0); - cell.colSpan = colors[0].length; - self._addAttr(cell, '', 'ke-colorpicker-cell-top'); - for (var i = 0; i < colors.length; i++) { - row = table.insertRow(i + 1); - for (var j = 0; j < colors[i].length; j++) { - cell = row.insertCell(j); - self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell'); - } - } - }, - _addAttr : function(cell, color, cls) { - var self = this; - cell = K(cell).addClass(cls); - if (self.selectedColor === color.toLowerCase()) { - cell.addClass('ke-colorpicker-cell-selected'); - } - cell.attr('title', color || self.options.noColor); - cell.mouseover(function(e) { - K(this).addClass('ke-colorpicker-cell-on'); - }); - cell.mouseout(function(e) { - K(this).removeClass('ke-colorpicker-cell-on'); - }); - cell.click(function(e) { - e.stop(); - self.options.click.call(K(this), color); - }); - if (color) { - cell.append(K('
').css('background-color', color)); - } else { - cell.html(self.options.noColor); - } - K(cell).attr('unselectable', 'on'); - self._cells.push(cell); - }, - remove : function() { - var self = this; - _each(self._cells, function() { - this.unbind(); - }); - KColorPicker.parent.remove.call(self); - return self; - } -}); -function _colorpicker(options) { - return new KColorPicker(options); -} -K.ColorPickerClass = KColorPicker; -K.colorpicker = _colorpicker; -function KUploadButton(options) { - this.init(options); -} -_extend(KUploadButton, { - init : function(options) { - //dump_obj(options); - var self = this, - button = K(options.button), - fieldName = options.fieldName || 'file', - url = options.url || '', - title = button.val(), - extraParams = options.extraParams || {}, - cls = button[0].className || '', - target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime(); - options.afterError = options.afterError || function(str) { - alert(str); - }; - var hiddenElements = []; - for(var k in extraParams){ - hiddenElements.push(''); - } - var html = [ - '
', - (options.target ? '' : ''), - (options.form ? '
' : '
'), - '', - hiddenElements.join(''), - '', - '', - '', - (options.form ? '
' : ''), - '
'].join(''); - var div = K(html, button.doc); - $(div).hide()// 如果 以后要用根据 http://kindeditor.net/docs/uploadbutton.html#k-uploadbutton-options来使用uploadButton,那么这里的button会 是隐藏的 - button.hide(); - button.before(div); - self.div = div; - if(options.ops!=undefined)options.ops.up_file_div = div;//options.ops是KindEditor.create()的options参数 - self.button = button; - self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div); - self.form = options.form ? K(options.form) : K('form', div); - self.fileBox = K('.ke-upload-file', div); - var width = options.width || K('.ke-button-common', div).width(); - K('.ke-upload-area', div).width(width); - self.options = options; - }, - submit : function() { - var self = this, - iframe = self.iframe; - iframe.bind('load', function() { - iframe.unbind(); - var tempForm = document.createElement('form'); - self.fileBox.before(tempForm); - K(tempForm).append(self.fileBox); - tempForm.reset(); - K(tempForm).remove(true); - var doc = K.iframeDoc(iframe), - pre = doc.getElementsByTagName('pre')[0], - str = '', data; - if (pre) { - str = pre.innerHTML; - } else { - str = doc.body.innerHTML; - } - str = _unescape(str); - iframe[0].src = 'javascript:false'; - try { - data = K.json(str); - } catch (e) { - self.options.afterError.call(self, '' + doc.body.parentNode.innerHTML + ''); - } - if (data) { - self.options.afterUpload.call(self, data); - } - }); - self.form[0].submit(); - return self; - }, - remove : function() { - var self = this; - if (self.fileBox) { - self.fileBox.unbind(); - } - self.iframe.remove(); - self.div.remove(); - self.button.show(); - return self; - } -}); -function _uploadbutton(options) { - return new KUploadButton(options); -} -K.UploadButtonClass = KUploadButton; -K.uploadbutton = _uploadbutton; -function _createButton(arg) { - arg = arg || {}; - var name = arg.name || '', - span = K(''), - btn = K(''); - if (arg.click) { - btn.click(arg.click); - } - span.append(btn); - return span; -} -function KDialog(options) { - this.init(options); -} -_extend(KDialog, KWidget, { - init : function(options) { - var self = this; - var shadowMode = _undef(options.shadowMode, true); - options.z = options.z || 811213; - options.shadowMode = false; - options.autoScroll = _undef(options.autoScroll, true); - KDialog.parent.init.call(self, options); - var title = options.title, - body = K(options.body, self.doc), - previewBtn = options.previewBtn, - yesBtn = options.yesBtn, - noBtn = options.noBtn, - closeBtn = options.closeBtn, - showMask = _undef(options.showMask, true); - self.div.addClass('ke-dialog').bind('click,mousedown', function(e){ - e.stopPropagation(); - }); - var contentDiv = K('
').appendTo(self.div); - if (_IE && _V < 7) { - self.iframeMask = K('').appendTo(self.div); - } else if (shadowMode) { - K('
').appendTo(self.div); - } - var headerDiv = K('
'); - contentDiv.append(headerDiv); - headerDiv.html(title); - self.closeIcon = K('').click(closeBtn.click); - headerDiv.append(self.closeIcon); - self.draggable({ - clickEl : headerDiv, - beforeDrag : options.beforeDrag - }); - var bodyDiv = K('
'); - contentDiv.append(bodyDiv); - bodyDiv.append(body); - var footerDiv = K(''); - if (previewBtn || yesBtn || noBtn) { - contentDiv.append(footerDiv); - } - _each([ - { btn : previewBtn, name : 'preview' }, - { btn : yesBtn, name : 'yes' }, - { btn : noBtn, name : 'no' } - ], function() { - if (this.btn) { - var button = _createButton(this.btn); - button.addClass('ke-dialog-' + this.name); - footerDiv.append(button); - } - }); - if (self.height) { - bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height()); - } - self.div.width(self.div.width()); - self.div.height(self.div.height()); - self.mask = null; - if (showMask) { - var docEl = _docElement(self.doc), - docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth), - docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight); - self.mask = _widget({ - x : 0, - y : 0, - z : self.z - 1, - cls : 'ke-dialog-mask', - width : docWidth, - height : docHeight - }); - } - self.autoPos(self.div.width(), self.div.height()); - self.footerDiv = footerDiv; - self.bodyDiv = bodyDiv; - self.headerDiv = headerDiv; - self.isLoading = false; - }, - setMaskIndex : function(z) { - var self = this; - self.mask.div.css('z-index', z); - }, - showLoading : function(msg) { - msg = _undef(msg, ''); - var self = this, body = self.bodyDiv; - self.loading = K('
' + msg + '
') - .width(body.width()).height(body.height()) - .css('top', self.headerDiv.height() + 'px'); - body.css('visibility', 'hidden').after(self.loading); - self.isLoading = true; - return self; - }, - hideLoading : function() { - this.loading && this.loading.remove(); - this.bodyDiv.css('visibility', 'visible'); - this.isLoading = false; - return this; - }, - remove : function() { - var self = this; - if (self.options.beforeRemove) { - self.options.beforeRemove.call(self); - } - self.mask && self.mask.remove(); - self.iframeMask && self.iframeMask.remove(); - self.closeIcon.unbind(); - K('input', self.div).unbind(); - K('button', self.div).unbind(); - self.footerDiv.unbind(); - self.bodyDiv.unbind(); - self.headerDiv.unbind(); - K('iframe', self.div).each(function() { - K(this).remove(); - }); - KDialog.parent.remove.call(self); - return self; - } -}); -function _dialog(options) { - return new KDialog(options); -} -K.DialogClass = KDialog; -K.dialog = _dialog; -function _tabs(options) { - var self = _widget(options), - remove = self.remove, - afterSelect = options.afterSelect, - div = self.div, - liList = []; - div.addClass('ke-tabs') - .bind('contextmenu,mousedown,mousemove', function(e) { - e.preventDefault(); - }); - var ul = K('
    '); - div.append(ul); - self.add = function(tab) { - var li = K('
  • ' + tab.title + '
  • '); - li.data('tab', tab); - liList.push(li); - ul.append(li); - }; - self.selectedIndex = 0; - self.select = function(index) { - self.selectedIndex = index; - _each(liList, function(i, li) { - li.unbind(); - if (i === index) { - li.addClass('ke-tabs-li-selected'); - K(li.data('tab').panel).show(''); - } else { - li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on') - .mouseover(function() { - K(this).addClass('ke-tabs-li-on'); - }) - .mouseout(function() { - K(this).removeClass('ke-tabs-li-on'); - }) - .click(function() { - self.select(i); - }); - K(li.data('tab').panel).hide(); - } - }); - if (afterSelect) { - afterSelect.call(self, index); - } - }; - self.remove = function() { - _each(liList, function() { - this.remove(); - }); - ul.remove(); - remove.call(self); - }; - return self; -} -K.tabs = _tabs; -function _loadScript(url, fn) { - var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), - script = document.createElement('script'); - head.appendChild(script); - script.src = url; - script.charset = 'utf-8'; - script.onload = script.onreadystatechange = function() { - if (!this.readyState || this.readyState === 'loaded') { - if (fn) { - fn(); - } - script.onload = script.onreadystatechange = null; - head.removeChild(script); - } - }; -} -function _chopQuery(url) { - var index = url.indexOf('?'); - return index > 0 ? url.substr(0, index) : url; -} -function _loadStyle(url) { - var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), - link = document.createElement('link'), - absoluteUrl = _chopQuery(_formatUrl(url, 'absolute')); - var links = K('link[rel="stylesheet"]', head); - for (var i = 0, len = links.length; i < len; i++) { - if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) { - return; - } - } - head.appendChild(link); - link.href = url; - link.rel = 'stylesheet'; -} -function _ajax(url, fn, method, param, dataType) { - method = method || 'GET'; - dataType = dataType || 'json'; - var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); - xhr.open(method, url, true); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && xhr.status == 200) { - if (fn) { - var data = _trim(xhr.responseText); - if (dataType == 'json') { - data = _json(data); - } - fn(data); - } - } - }; - if (method == 'POST') { - var params = []; - _each(param, function(key, val) { - params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); - }); - try { - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - } catch (e) {} - xhr.send(params.join('&')); - } else { - xhr.send(null); - } -} -K.loadScript = _loadScript; -K.loadStyle = _loadStyle; -K.ajax = _ajax; -var _plugins = {}; -function _plugin(name, fn) { - if (name === undefined) { - return _plugins; - } - if (!fn) { - return _plugins[name]; - } - _plugins[name] = fn; -} -var _language = {}; -function _parseLangKey(key) { - var match, ns = 'core'; - if ((match = /^(\w+)\.(\w+)$/.exec(key))) { - ns = match[1]; - key = match[2]; - } - return { ns : ns, key : key }; -} -function _lang(mixed, langType) { - langType = langType === undefined ? K.options.langType : langType; - if (typeof mixed === 'string') { - if (!_language[langType]) { - return 'no language'; - } - var pos = mixed.length - 1; - if (mixed.substr(pos) === '.') { - return _language[langType][mixed.substr(0, pos)]; - } - var obj = _parseLangKey(mixed); - return _language[langType][obj.ns][obj.key]; - } - _each(mixed, function(key, val) { - var obj = _parseLangKey(key); - if (!_language[langType]) { - _language[langType] = {}; - } - if (!_language[langType][obj.ns]) { - _language[langType][obj.ns] = {}; - } - _language[langType][obj.ns][obj.key] = val; - }); -} -function _getImageFromRange(range, fn) { - if (range.collapsed) { - return; - } - range = range.cloneRange().up(); - var sc = range.startContainer, so = range.startOffset; - if (!_WEBKIT && !range.isControl()) { - return; - } - var img = K(sc.childNodes[so]); - if (!img || img.name != 'img') { - return; - } - if (fn(img)) { - return img; - } -} -function _bindContextmenuEvent() { - var self = this, doc = self.edit.doc; - K(doc).contextmenu(function(e) { - if (self.menu) { - self.hideMenu(); - } - if (!self.useContextmenu) { - e.preventDefault(); - return; - } - if (self._contextmenus.length === 0) { - return; - } - var maxWidth = 0, items = []; - _each(self._contextmenus, function() { - if (this.title == '-') { - items.push(this); - return; - } - if (this.cond && this.cond()) { - items.push(this); - if (this.width && this.width > maxWidth) { - maxWidth = this.width; - } - } - }); - while (items.length > 0 && items[0].title == '-') { - items.shift(); - } - while (items.length > 0 && items[items.length - 1].title == '-') { - items.pop(); - } - var prevItem = null; - _each(items, function(i) { - if (this.title == '-' && prevItem.title == '-') { - delete items[i]; - } - prevItem = this; - }); - if (items.length > 0) { - e.preventDefault(); - var pos = K(self.edit.iframe).pos(), - menu = _menu({ - x : pos.x + e.clientX, - y : pos.y + e.clientY, - width : maxWidth, - css : { visibility: 'hidden' }, - shadowMode : self.shadowMode - }); - _each(items, function() { - if (this.title) { - menu.addItem(this); - } - }); - var docEl = _docElement(menu.doc), - menuHeight = menu.div.height(); - if (e.clientY + menuHeight >= docEl.clientHeight - 100) { - menu.pos(menu.x, _removeUnit(menu.y) - menuHeight); - } - menu.div.css('visibility', 'visible'); - self.menu = menu; - } - }); -} -function _bindNewlineEvent() { - var self = this, doc = self.edit.doc, newlineTag = self.newlineTag; - if (_IE && newlineTag !== 'br') { - return; - } - if (_GECKO && _V < 3 && newlineTag !== 'p') { - return; - } - if (_OPERA && _V < 9) { - return; - } - var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'), - pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote'); - function getAncestorTagName(range) { - var ancestor = K(range.commonAncestor()); - while (ancestor) { - if (ancestor.type == 1 && !ancestor.isStyle()) { - break; - } - ancestor = ancestor.parent(); - } - return ancestor.name; - } - K(doc).keydown(function(e) { - if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { - return; - } - self.cmd.selection(); - var tagName = getAncestorTagName(self.cmd.range); - if (tagName == 'marquee' || tagName == 'select') { - return; - } - if (newlineTag === 'br' && !brSkipTagMap[tagName]) { - e.preventDefault(); - self.insertHtml('
    ' + (_IE && _V < 9 ? '' : '\u200B')); - return; - } - if (!pSkipTagMap[tagName]) { - _nativeCommand(doc, 'formatblock', '

    '); - } - }); - K(doc).keyup(function(e) { - if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { - return; - } - if (newlineTag == 'br') { - return; - } - if (_GECKO) { - var root = self.cmd.commonAncestor('p'); - var a = self.cmd.commonAncestor('a'); - if (a && a.text() == '') { - a.remove(true); - self.cmd.range.selectNodeContents(root[0]).collapse(true); - self.cmd.select(); - } - return; - } - self.cmd.selection(); - var tagName = getAncestorTagName(self.cmd.range); - if (tagName == 'marquee' || tagName == 'select') { - return; - } - if (!pSkipTagMap[tagName]) { - _nativeCommand(doc, 'formatblock', '

    '); - } - var div = self.cmd.commonAncestor('div'); - if (div) { - var p = K('

    '), - child = div[0].firstChild; - while (child) { - var next = child.nextSibling; - p.append(child); - child = next; - } - div.before(p); - div.remove(); - self.cmd.range.selectNodeContents(p[0]); - self.cmd.select(); - } - }); -} -function _bindTabEvent() { - var self = this, doc = self.edit.doc; - K(doc).keydown(function(e) { - if (e.which == 9) { - e.preventDefault(); - if (self.afterTab) { - self.afterTab.call(self, e); - return; - } - var cmd = self.cmd, range = cmd.range; - range.shrink(); - if (range.collapsed && range.startContainer.nodeType == 1) { - range.insertNode(K('@ ', doc)[0]); - cmd.select(); - } - self.insertHtml('    '); - } - }); -} -function _bindFocusEvent() { - var self = this; - K(self.edit.textarea[0], self.edit.win).focus(function(e) { - if(typeof self.options.enable_at === 'function'){ - self.options.enable_at(); - } - if (self.afterFocus) { - self.afterFocus.call(self, e); - } - }).blur(function(e) { - if (self.afterBlur) { - self.afterBlur.call(self, e); - } - }); -} -function _removeBookmarkTag(html) { - return _trim(html.replace(/]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, '')); -} -function _removeTempTag(html) { - return html.replace(/]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, ''); -} -function _addBookmarkToStack(stack, bookmark) { - if (stack.length === 0) { - stack.push(bookmark); - return; - } - var prev = stack[stack.length - 1]; - if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) { - stack.push(bookmark); - } -} -function _undoToRedo(fromStack, toStack) { - var self = this, edit = self.edit, - body = edit.doc.body, - range, bookmark; - if (fromStack.length === 0) { - return self; - } - if (edit.designMode) { - range = self.cmd.range; - bookmark = range.createBookmark(true); - bookmark.html = body.innerHTML; - } else { - bookmark = { - html : body.innerHTML - }; - } - _addBookmarkToStack(toStack, bookmark); - var prev = fromStack.pop(); - if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) { - prev = fromStack.pop(); - } - if (edit.designMode) { - edit.html(prev.html); - if (prev.start) { - range.moveToBookmark(prev); - self.select(); - } - } else { - K(body).html(_removeBookmarkTag(prev.html)); - } - return self; -} -function KEditor(options) { - var self = this; - self.options = {}; - function setOption(key, val) { - if (KEditor.prototype[key] === undefined) { - self[key] = val; - } - self.options[key] = val; - } - _each(options, function(key, val) { - setOption(key, options[key]); - }); - _each(K.options, function(key, val) { - if (self[key] === undefined) { - setOption(key, val); - } - }); - var se = K(self.srcElement || '').css('width', '100%'); + self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10); + self.iframe.attr('tabindex', self.tabIndex); + self.textarea.attr('tabindex', self.tabIndex); + if (self.width) { + self.setWidth(self.width); + } + if (self.height) { + self.setHeight(self.height); + } + if (self.designMode) { + self.textarea.hide(); + } else { + self.iframe.hide(); + } + function ready() { + var doc = _iframeDoc(self.iframe); + doc.open(); + if (isDocumentDomain) { + doc.domain = document.domain; + } + doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData)); + doc.close(); + self.win = self.iframe[0].contentWindow; + self.doc = doc; + var cmd = _cmd(doc); + self.afterChange(function(e) { + cmd.selection(); + }); + if (_WEBKIT) { + K(doc).click(function(e) { + if (K(e.target).name === 'img') { + cmd.selection(true); + cmd.range.selectNode(e.target); + cmd.select(); + } + }); + } + if (_IE) { + self._mousedownHandler = function() { + var newRange = cmd.range.cloneRange(); + newRange.shrink(); + if (newRange.isControl()) { + self.blur(); + } + }; + K(document).mousedown(self._mousedownHandler); + K(doc).keydown(function(e) { + if (e.which == 8) { + cmd.selection(); + var rng = cmd.range; + if (rng.isControl()) { + rng.collapse(true); + K(rng.startContainer.childNodes[rng.startOffset]).remove(); + e.preventDefault(); + } + } + }); + } + self.cmd = cmd; + self.html(_elementVal(self.srcElement)); + if (_IE) { + doc.body.disabled = true; + doc.body.contentEditable = true; + doc.body.removeAttribute('disabled'); + } else { + doc.designMode = 'on'; + } + if (options.afterCreate) { + options.afterCreate.call(self); + } + } + if (isDocumentDomain) { + self.iframe.bind('load', function(e) { + self.iframe.unbind('load'); + if (_IE) { + ready(); + } else { + setTimeout(ready, 0); + } + }); + } + self.div.append(self.iframe); + self.div.append(self.textarea); + self.srcElement.hide(); + !isDocumentDomain && ready(); + }, + setWidth : function(val) { + var self = this; + val = _addUnit(val); + self.width = val; + self.div.css('width', val); + return self; + }, + setHeight : function(val) { + var self = this; + val = _addUnit(val); + self.height = val; + self.div.css('height', val); + self.iframe.css('height', val); + if ((_IE && _V < 8) || _QUIRKS) { + val = _addUnit(_removeUnit(val) - 2); + } + self.textarea.css('height', val); + return self; + }, + remove : function() { + var self = this, doc = self.doc; + K(doc.body).unbind(); + K(doc).unbind(); + K(self.win).unbind(); + if (self._mousedownHandler) { + K(document).unbind('mousedown', self._mousedownHandler); + } + _elementVal(self.srcElement, self.html()); + self.srcElement.show(); + doc.write(''); + self.iframe.unbind(); + self.textarea.unbind(); + KEdit.parent.remove.call(self); + }, + html : function(val, isFull) { + var self = this, doc = self.doc; + if (self.designMode) { + var body = doc.body; + if (val === undefined) { + if (isFull) { + val = '' + body.parentNode.innerHTML + ''; + } else { + val = body.innerHTML; + } + if (self.beforeGetHtml) { + val = self.beforeGetHtml(val); + } + if (_GECKO && val == '
    ') { + val = ''; + } + return val; + } + if (self.beforeSetHtml) { + val = self.beforeSetHtml(val); + } + if (_IE && _V >= 9) { + val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2'); + } + K(body).html(val); + if (self.afterSetHtml) { + self.afterSetHtml(); + } + return self; + } + if (val === undefined) { + return self.textarea.val(); + } + self.textarea.val(val); + return self; + }, + design : function(bool) { + var self = this, val; + if (bool === undefined ? !self.designMode : bool) { + if (!self.designMode) { + val = self.html(); + self.designMode = true; + self.html(val); + self.textarea.hide(); + self.iframe.show(); + } + } else { + if (self.designMode) { + val = self.html(); + self.designMode = false; + self.html(val); + self.iframe.hide(); + self.textarea.show(); + } + } + return self.focus(); + }, + focus : function() { + var self = this; + self.designMode ? self.win.focus() : self.textarea[0].focus(); + return self; + }, + blur : function() { + var self = this; + if (_IE) { + var input = K('', self.div); + self.div.append(input); + input[0].focus(); + input.remove(); + } else { + self.designMode ? self.win.blur() : self.textarea[0].blur(); + } + return self; + }, + afterChange : function(fn) { + var self = this, doc = self.doc, body = doc.body; + K(doc).keyup(function(e) { + if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) { + fn(e); + } + }); + K(doc).mouseup(fn).contextmenu(fn); + K(self.win).blur(fn); + function timeoutHandler(e) { + setTimeout(function() { + fn(e); + }, 1); + } + K(body).bind('paste', timeoutHandler); + K(body).bind('cut', timeoutHandler); + return self; + } +}); +function _edit(options) { + return new KEdit(options); +} +K.EditClass = KEdit; +K.edit = _edit; +K.iframeDoc = _iframeDoc; +function _selectToolbar(name, fn) { + var self = this, + knode = self.get(name); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + fn(knode); + } +} +function KToolbar(options) { + this.init(options); +} +_extend(KToolbar, KWidget, { + init : function(options) { + var self = this; + KToolbar.parent.init.call(self, options); + self.disableMode = _undef(options.disableMode, false); + self.noDisableItemMap = _toMap(_undef(options.noDisableItems, [])); + self._itemMap = {}; + self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) { + e.preventDefault(); + }).attr('unselectable', 'on'); + function find(target) { + var knode = K(target); + if (knode.hasClass('ke-outline')) { + return knode; + } + if (knode.hasClass('ke-toolbar-icon')) { + return knode.parent(); + } + } + function hover(e, method) { + var knode = find(e.target); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + if (knode.hasClass('ke-selected')) { + return; + } + knode[method]('ke-on'); + } + } + self.div.mouseover(function(e) { + hover(e, 'addClass'); + }) + .mouseout(function(e) { + hover(e, 'removeClass'); + }) + .click(function(e) { + var knode = find(e.target); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + self.options.click.call(this, e, knode.attr('data-name')); + } + }); + }, + get : function(name) { + //if(this._itemMap[name])return this._itemMap[name]; + //return this._itemMap[name]=K("span.ke-icon-"+name,this.div).parent() +// if (this._itemMap[name]) { +// return this._itemMap[name]; +// } +// if($("#define").css('display') == 'block'){ +// pdiv = $("#define") +// }else if($("#full").css('display') == 'block'){ +// pdiv = $("#full") +// } + var container = this.div; + if(!$("#define",container).is(':hidden')){ + pdiv = $("#define",container); + }else if(!$("#full",container).is(':hidden')){ + pdiv = $("#full",container); + } + return (this._itemMap[name] = K('span.ke-icon-' + name, pdiv).parent()); + }, + select : function(name) { + _selectToolbar.call(this, name, function(knode) { + knode.addClass('ke-selected'); + }); + return self; + }, + unselect : function(name) { + _selectToolbar.call(this, name, function(knode) { + knode.removeClass('ke-selected').removeClass('ke-on'); + }); + return self; + }, + enable : function(name) { + var self = this, + knode = name.get ? name : self.get(name); + if (knode) { + knode.removeClass('ke-disabled'); + knode.opacity(1); + } + return self; + }, + disable : function(name) { + var self = this, + knode = name.get ? name : self.get(name); + if (knode) { + knode.removeClass('ke-selected').addClass('ke-disabled'); + knode.opacity(0.5); + } + return self; + }, + disableAll : function(bool, noDisableItems) { + var self = this, map = self.noDisableItemMap, item; + if (noDisableItems) { + map = _toMap(noDisableItems); + } + if (bool === undefined ? !self.disableMode : bool) { + K('span.ke-outline', self.div).each(function() { + var knode = K(this), + name = knode[0].getAttribute('data-name', 2); + if (!map[name]) { + self.disable(knode); + } + }); + self.disableMode = true; + } else { + K('span.ke-outline', self.div).each(function() { + var knode = K(this), + name = knode[0].getAttribute('data-name', 2); + if (!map[name]) { + self.enable(knode); + } + }); + self.disableMode = false; + } + return self; + } +}); +function _toolbar(options) { + return new KToolbar(options); +} +K.ToolbarClass = KToolbar; +K.toolbar = _toolbar; +function KMenu(options) { + this.init(options); +} +_extend(KMenu, KWidget, { + init : function(options) { + var self = this; + options.z = options.z || 811213; + KMenu.parent.init.call(self, options); + self.centerLineMode = _undef(options.centerLineMode, true); + self.div.addClass('ke-menu').bind('click,mousedown', function(e){ + e.stopPropagation(); + }).attr('unselectable', 'on'); + }, + addItem : function(item) { + var self = this; + if (item.title === '-') { + self.div.append(K('
    ')); + return; + } + var itemDiv = K('
    '), + leftDiv = K('
    '), + rightDiv = K('
    '), + height = _addUnit(item.height), + iconClass = _undef(item.iconClass, ''); + self.div.append(itemDiv); + if (height) { + itemDiv.css('height', height); + rightDiv.css('line-height', height); + } + var centerDiv; + if (self.centerLineMode) { + centerDiv = K('
    '); + if (height) { + centerDiv.css('height', height); + } + } + itemDiv.mouseover(function(e) { + K(this).addClass('ke-menu-item-on'); + if (centerDiv) { + centerDiv.addClass('ke-menu-item-center-on'); + } + }) + .mouseout(function(e) { + K(this).removeClass('ke-menu-item-on'); + if (centerDiv) { + centerDiv.removeClass('ke-menu-item-center-on'); + } + }) + .click(function(e) { + item.click.call(K(this)); + e.stopPropagation(); + }) + .append(leftDiv); + if (centerDiv) { + itemDiv.append(centerDiv); + } + itemDiv.append(rightDiv); + if (item.checked) { + iconClass = 'ke-icon-checked'; + } + if (iconClass !== '') { + leftDiv.html(''); + } + rightDiv.html(item.title); + return self; + }, + remove : function() { + var self = this; + if (self.options.beforeRemove) { + self.options.beforeRemove.call(self); + } + K('.ke-menu-item', self.div[0]).unbind(); + KMenu.parent.remove.call(self); + return self; + } +}); +function _menu(options) { + return new KMenu(options); +} +K.MenuClass = KMenu; +K.menu = _menu; +function KColorPicker(options) { + this.init(options); +} +_extend(KColorPicker, KWidget, { + init : function(options) { + var self = this; + options.z = options.z || 811213; + KColorPicker.parent.init.call(self, options); + var colors = options.colors || [ + ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], + ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], + ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], + ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] + ]; + self.selectedColor = (options.selectedColor || '').toLowerCase(); + self._cells = []; + self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){ + e.stopPropagation(); + }).attr('unselectable', 'on'); + var table = self.doc.createElement('table'); + self.div.append(table); + table.className = 'ke-colorpicker-table'; + table.cellPadding = 0; + table.cellSpacing = 0; + table.border = 0; + var row = table.insertRow(0), cell = row.insertCell(0); + cell.colSpan = colors[0].length; + self._addAttr(cell, '', 'ke-colorpicker-cell-top'); + for (var i = 0; i < colors.length; i++) { + row = table.insertRow(i + 1); + for (var j = 0; j < colors[i].length; j++) { + cell = row.insertCell(j); + self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell'); + } + } + }, + _addAttr : function(cell, color, cls) { + var self = this; + cell = K(cell).addClass(cls); + if (self.selectedColor === color.toLowerCase()) { + cell.addClass('ke-colorpicker-cell-selected'); + } + cell.attr('title', color || self.options.noColor); + cell.mouseover(function(e) { + K(this).addClass('ke-colorpicker-cell-on'); + }); + cell.mouseout(function(e) { + K(this).removeClass('ke-colorpicker-cell-on'); + }); + cell.click(function(e) { + e.stop(); + self.options.click.call(K(this), color); + }); + if (color) { + cell.append(K('
    ').css('background-color', color)); + } else { + cell.html(self.options.noColor); + } + K(cell).attr('unselectable', 'on'); + self._cells.push(cell); + }, + remove : function() { + var self = this; + _each(self._cells, function() { + this.unbind(); + }); + KColorPicker.parent.remove.call(self); + return self; + } +}); +function _colorpicker(options) { + return new KColorPicker(options); +} +K.ColorPickerClass = KColorPicker; +K.colorpicker = _colorpicker; +function KUploadButton(options) { + this.init(options); +} +_extend(KUploadButton, { + init : function(options) { + //dump_obj(options); + var self = this, + button = K(options.button), + fieldName = options.fieldName || 'file', + url = options.url || '', + title = button.val(), + extraParams = options.extraParams || {}, + cls = button[0].className || '', + target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime(); + options.afterError = options.afterError || function(str) { + alert(str); + }; + var hiddenElements = []; + for(var k in extraParams){ + hiddenElements.push(''); + } + var html = [ + '
    ', + (options.target ? '' : ''), + (options.form ? '
    ' : '
    '), + '', + hiddenElements.join(''), + '', + '', + '', + (options.form ? '
    ' : ''), + '
    '].join(''); + var div = K(html, button.doc); + $(div).hide()// 如果 以后要用根据 http://kindeditor.net/docs/uploadbutton.html#k-uploadbutton-options来使用uploadButton,那么这里的button会 是隐藏的 + button.hide(); + button.before(div); + self.div = div; + if(options.ops!=undefined)options.ops.up_file_div = div;//options.ops是KindEditor.create()的options参数 + self.button = button; + self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div); + self.form = options.form ? K(options.form) : K('form', div); + self.fileBox = K('.ke-upload-file', div); + var width = options.width || K('.ke-button-common', div).width(); + K('.ke-upload-area', div).width(width); + self.options = options; + }, + submit : function() { + var self = this, + iframe = self.iframe; + iframe.bind('load', function() { + iframe.unbind(); + var tempForm = document.createElement('form'); + self.fileBox.before(tempForm); + K(tempForm).append(self.fileBox); + tempForm.reset(); + K(tempForm).remove(true); + var doc = K.iframeDoc(iframe), + pre = doc.getElementsByTagName('pre')[0], + str = '', data; + if (pre) { + str = pre.innerHTML; + } else { + str = doc.body.innerHTML; + } + str = _unescape(str); + iframe[0].src = 'javascript:false'; + try { + data = K.json(str); + } catch (e) { + self.options.afterError.call(self, '' + doc.body.parentNode.innerHTML + ''); + } + if (data) { + self.options.afterUpload.call(self, data); + } + }); + self.form[0].submit(); + return self; + }, + remove : function() { + var self = this; + if (self.fileBox) { + self.fileBox.unbind(); + } + self.iframe.remove(); + self.div.remove(); + self.button.show(); + return self; + } +}); +function _uploadbutton(options) { + return new KUploadButton(options); +} +K.UploadButtonClass = KUploadButton; +K.uploadbutton = _uploadbutton; +function _createButton(arg) { + arg = arg || {}; + var name = arg.name || '', + span = K(''), + btn = K(''); + if (arg.click) { + btn.click(arg.click); + } + span.append(btn); + return span; +} +function KDialog(options) { + this.init(options); +} +_extend(KDialog, KWidget, { + init : function(options) { + var self = this; + var shadowMode = _undef(options.shadowMode, true); + options.z = options.z || 811213; + options.shadowMode = false; + options.autoScroll = _undef(options.autoScroll, true); + KDialog.parent.init.call(self, options); + var title = options.title, + body = K(options.body, self.doc), + previewBtn = options.previewBtn, + yesBtn = options.yesBtn, + noBtn = options.noBtn, + closeBtn = options.closeBtn, + showMask = _undef(options.showMask, true); + self.div.addClass('ke-dialog').bind('click,mousedown', function(e){ + e.stopPropagation(); + }); + var contentDiv = K('
    ').appendTo(self.div); + if (_IE && _V < 7) { + self.iframeMask = K('').appendTo(self.div); + } else if (shadowMode) { + K('
    ').appendTo(self.div); + } + var headerDiv = K('
    '); + contentDiv.append(headerDiv); + headerDiv.html(title); + self.closeIcon = K('').click(closeBtn.click); + headerDiv.append(self.closeIcon); + self.draggable({ + clickEl : headerDiv, + beforeDrag : options.beforeDrag + }); + var bodyDiv = K('
    '); + contentDiv.append(bodyDiv); + bodyDiv.append(body); + var footerDiv = K(''); + if (previewBtn || yesBtn || noBtn) { + contentDiv.append(footerDiv); + } + _each([ + { btn : previewBtn, name : 'preview' }, + { btn : yesBtn, name : 'yes' }, + { btn : noBtn, name : 'no' } + ], function() { + if (this.btn) { + var button = _createButton(this.btn); + button.addClass('ke-dialog-' + this.name); + footerDiv.append(button); + } + }); + if (self.height) { + bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height()); + } + self.div.width(self.div.width()); + self.div.height(self.div.height()); + self.mask = null; + if (showMask) { + var docEl = _docElement(self.doc), + docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth), + docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight); + self.mask = _widget({ + x : 0, + y : 0, + z : self.z - 1, + cls : 'ke-dialog-mask', + width : docWidth, + height : docHeight + }); + } + self.autoPos(self.div.width(), self.div.height()); + self.footerDiv = footerDiv; + self.bodyDiv = bodyDiv; + self.headerDiv = headerDiv; + self.isLoading = false; + }, + setMaskIndex : function(z) { + var self = this; + self.mask.div.css('z-index', z); + }, + showLoading : function(msg) { + msg = _undef(msg, ''); + var self = this, body = self.bodyDiv; + self.loading = K('
    ' + msg + '
    ') + .width(body.width()).height(body.height()) + .css('top', self.headerDiv.height() + 'px'); + body.css('visibility', 'hidden').after(self.loading); + self.isLoading = true; + return self; + }, + hideLoading : function() { + this.loading && this.loading.remove(); + this.bodyDiv.css('visibility', 'visible'); + this.isLoading = false; + return this; + }, + remove : function() { + var self = this; + if (self.options.beforeRemove) { + self.options.beforeRemove.call(self); + } + self.mask && self.mask.remove(); + self.iframeMask && self.iframeMask.remove(); + self.closeIcon.unbind(); + K('input', self.div).unbind(); + K('button', self.div).unbind(); + self.footerDiv.unbind(); + self.bodyDiv.unbind(); + self.headerDiv.unbind(); + K('iframe', self.div).each(function() { + K(this).remove(); + }); + KDialog.parent.remove.call(self); + return self; + } +}); +function _dialog(options) { + return new KDialog(options); +} +K.DialogClass = KDialog; +K.dialog = _dialog; +function _tabs(options) { + var self = _widget(options), + remove = self.remove, + afterSelect = options.afterSelect, + div = self.div, + liList = []; + div.addClass('ke-tabs') + .bind('contextmenu,mousedown,mousemove', function(e) { + e.preventDefault(); + }); + var ul = K('
      '); + div.append(ul); + self.add = function(tab) { + var li = K('
    • ' + tab.title + '
    • '); + li.data('tab', tab); + liList.push(li); + ul.append(li); + }; + self.selectedIndex = 0; + self.select = function(index) { + self.selectedIndex = index; + _each(liList, function(i, li) { + li.unbind(); + if (i === index) { + li.addClass('ke-tabs-li-selected'); + K(li.data('tab').panel).show(''); + } else { + li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on') + .mouseover(function() { + K(this).addClass('ke-tabs-li-on'); + }) + .mouseout(function() { + K(this).removeClass('ke-tabs-li-on'); + }) + .click(function() { + self.select(i); + }); + K(li.data('tab').panel).hide(); + } + }); + if (afterSelect) { + afterSelect.call(self, index); + } + }; + self.remove = function() { + _each(liList, function() { + this.remove(); + }); + ul.remove(); + remove.call(self); + }; + return self; +} +K.tabs = _tabs; +function _loadScript(url, fn) { + var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), + script = document.createElement('script'); + head.appendChild(script); + script.src = url; + script.charset = 'utf-8'; + script.onload = script.onreadystatechange = function() { + if (!this.readyState || this.readyState === 'loaded') { + if (fn) { + fn(); + } + script.onload = script.onreadystatechange = null; + head.removeChild(script); + } + }; +} +function _chopQuery(url) { + var index = url.indexOf('?'); + return index > 0 ? url.substr(0, index) : url; +} +function _loadStyle(url) { + var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), + link = document.createElement('link'), + absoluteUrl = _chopQuery(_formatUrl(url, 'absolute')); + var links = K('link[rel="stylesheet"]', head); + for (var i = 0, len = links.length; i < len; i++) { + if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) { + return; + } + } + head.appendChild(link); + link.href = url; + link.rel = 'stylesheet'; +} +function _ajax(url, fn, method, param, dataType) { + method = method || 'GET'; + dataType = dataType || 'json'; + var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); + xhr.open(method, url, true); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && xhr.status == 200) { + if (fn) { + var data = _trim(xhr.responseText); + if (dataType == 'json') { + data = _json(data); + } + fn(data); + } + } + }; + if (method == 'POST') { + var params = []; + _each(param, function(key, val) { + params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); + }); + try { + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + } catch (e) {} + xhr.send(params.join('&')); + } else { + xhr.send(null); + } +} +K.loadScript = _loadScript; +K.loadStyle = _loadStyle; +K.ajax = _ajax; +var _plugins = {}; +function _plugin(name, fn) { + if (name === undefined) { + return _plugins; + } + if (!fn) { + return _plugins[name]; + } + _plugins[name] = fn; +} +var _language = {}; +function _parseLangKey(key) { + var match, ns = 'core'; + if ((match = /^(\w+)\.(\w+)$/.exec(key))) { + ns = match[1]; + key = match[2]; + } + return { ns : ns, key : key }; +} +function _lang(mixed, langType) { + langType = langType === undefined ? K.options.langType : langType; + if (typeof mixed === 'string') { + if (!_language[langType]) { + return 'no language'; + } + var pos = mixed.length - 1; + if (mixed.substr(pos) === '.') { + return _language[langType][mixed.substr(0, pos)]; + } + var obj = _parseLangKey(mixed); + return _language[langType][obj.ns][obj.key]; + } + _each(mixed, function(key, val) { + var obj = _parseLangKey(key); + if (!_language[langType]) { + _language[langType] = {}; + } + if (!_language[langType][obj.ns]) { + _language[langType][obj.ns] = {}; + } + _language[langType][obj.ns][obj.key] = val; + }); +} +function _getImageFromRange(range, fn) { + if (range.collapsed) { + return; + } + range = range.cloneRange().up(); + var sc = range.startContainer, so = range.startOffset; + if (!_WEBKIT && !range.isControl()) { + return; + } + var img = K(sc.childNodes[so]); + if (!img || img.name != 'img') { + return; + } + if (fn(img)) { + return img; + } +} +function _bindContextmenuEvent() { + var self = this, doc = self.edit.doc; + K(doc).contextmenu(function(e) { + if (self.menu) { + self.hideMenu(); + } + if (!self.useContextmenu) { + e.preventDefault(); + return; + } + if (self._contextmenus.length === 0) { + return; + } + var maxWidth = 0, items = []; + _each(self._contextmenus, function() { + if (this.title == '-') { + items.push(this); + return; + } + if (this.cond && this.cond()) { + items.push(this); + if (this.width && this.width > maxWidth) { + maxWidth = this.width; + } + } + }); + while (items.length > 0 && items[0].title == '-') { + items.shift(); + } + while (items.length > 0 && items[items.length - 1].title == '-') { + items.pop(); + } + var prevItem = null; + _each(items, function(i) { + if (this.title == '-' && prevItem.title == '-') { + delete items[i]; + } + prevItem = this; + }); + if (items.length > 0) { + e.preventDefault(); + var pos = K(self.edit.iframe).pos(), + menu = _menu({ + x : pos.x + e.clientX, + y : pos.y + e.clientY, + width : maxWidth, + css : { visibility: 'hidden' }, + shadowMode : self.shadowMode + }); + _each(items, function() { + if (this.title) { + menu.addItem(this); + } + }); + var docEl = _docElement(menu.doc), + menuHeight = menu.div.height(); + if (e.clientY + menuHeight >= docEl.clientHeight - 100) { + menu.pos(menu.x, _removeUnit(menu.y) - menuHeight); + } + menu.div.css('visibility', 'visible'); + self.menu = menu; + } + }); +} +function _bindNewlineEvent() { + var self = this, doc = self.edit.doc, newlineTag = self.newlineTag; + if (_IE && newlineTag !== 'br') { + return; + } + if (_GECKO && _V < 3 && newlineTag !== 'p') { + return; + } + if (_OPERA && _V < 9) { + return; + } + var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'), + pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote'); + function getAncestorTagName(range) { + var ancestor = K(range.commonAncestor()); + while (ancestor) { + if (ancestor.type == 1 && !ancestor.isStyle()) { + break; + } + ancestor = ancestor.parent(); + } + return ancestor.name; + } + K(doc).keydown(function(e) { + if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { + return; + } + self.cmd.selection(); + var tagName = getAncestorTagName(self.cmd.range); + if (tagName == 'marquee' || tagName == 'select') { + return; + } + if (newlineTag === 'br' && !brSkipTagMap[tagName]) { + e.preventDefault(); + self.insertHtml('
      ' + (_IE && _V < 9 ? '' : '\u200B')); + return; + } + if (!pSkipTagMap[tagName]) { + _nativeCommand(doc, 'formatblock', '

      '); + } + }); + K(doc).keyup(function(e) { + if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { + return; + } + if (newlineTag == 'br') { + return; + } + if (_GECKO) { + var root = self.cmd.commonAncestor('p'); + var a = self.cmd.commonAncestor('a'); + if (a && a.text() == '') { + a.remove(true); + self.cmd.range.selectNodeContents(root[0]).collapse(true); + self.cmd.select(); + } + return; + } + self.cmd.selection(); + var tagName = getAncestorTagName(self.cmd.range); + if (tagName == 'marquee' || tagName == 'select') { + return; + } + if (!pSkipTagMap[tagName]) { + _nativeCommand(doc, 'formatblock', '

      '); + } + var div = self.cmd.commonAncestor('div'); + if (div) { + var p = K('

      '), + child = div[0].firstChild; + while (child) { + var next = child.nextSibling; + p.append(child); + child = next; + } + div.before(p); + div.remove(); + self.cmd.range.selectNodeContents(p[0]); + self.cmd.select(); + } + }); +} +function _bindTabEvent() { + var self = this, doc = self.edit.doc; + K(doc).keydown(function(e) { + if (e.which == 9) { + e.preventDefault(); + if (self.afterTab) { + self.afterTab.call(self, e); + return; + } + var cmd = self.cmd, range = cmd.range; + range.shrink(); + if (range.collapsed && range.startContainer.nodeType == 1) { + range.insertNode(K('@ ', doc)[0]); + cmd.select(); + } + self.insertHtml('    '); + } + }); +} +function _bindFocusEvent() { + var self = this; + K(self.edit.textarea[0], self.edit.win).focus(function(e) { + if(typeof self.options.enable_at === 'function'){ + self.options.enable_at(); + } + if (self.afterFocus) { + self.afterFocus.call(self, e); + } + }).blur(function(e) { + if (self.afterBlur) { + self.afterBlur.call(self, e); + } + }); +} +function _removeBookmarkTag(html) { + return _trim(html.replace(/]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, '')); +} +function _removeTempTag(html) { + return html.replace(/]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, ''); +} +function _addBookmarkToStack(stack, bookmark) { + if (stack.length === 0) { + stack.push(bookmark); + return; + } + var prev = stack[stack.length - 1]; + if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) { + stack.push(bookmark); + } +} +function _undoToRedo(fromStack, toStack) { + var self = this, edit = self.edit, + body = edit.doc.body, + range, bookmark; + if (fromStack.length === 0) { + return self; + } + if (edit.designMode) { + range = self.cmd.range; + bookmark = range.createBookmark(true); + bookmark.html = body.innerHTML; + } else { + bookmark = { + html : body.innerHTML + }; + } + _addBookmarkToStack(toStack, bookmark); + var prev = fromStack.pop(); + if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) { + prev = fromStack.pop(); + } + if (edit.designMode) { + edit.html(prev.html); + if (prev.start) { + range.moveToBookmark(prev); + self.select(); + } + } else { + K(body).html(_removeBookmarkTag(prev.html)); + } + return self; +} +function KEditor(options) { + var self = this; + self.options = {}; + function setOption(key, val) { + if (KEditor.prototype[key] === undefined) { + self[key] = val; + } + self.options[key] = val; + } + _each(options, function(key, val) { + setOption(key, options[key]); + }); + _each(K.options, function(key, val) { + if (self[key] === undefined) { + setOption(key, val); + } + }); + var se = K(self.srcElement || ' - -
      -

      - <% end%> - -
      - -
      +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
      +
      +
      + <%= form_for @blog_comment, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => @blogComment.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> + + <% if course_id%> + + <% end %> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 858fefb08..a5aa8b780 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -1,226 +1,226 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
      -
      - <% if activity.author.id == User.current.id%> - - <%end%> -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% end %> - TO - <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%> - <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> - 已设为首页 - <% end %> -
      -
      - - <% if activity.sticky == 1%> - 置顶 - <% end%> - <% if activity.locked%> -        - <% end%> -
      -
      - 发帖时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(activity.updated_on) %> -
      -
      - <% if activity.parent_id.nil? %> - <% content= activity.content%> - <% else %> - <% content= activity.parent.content%> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> - -
      - - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      - -
      -
      -
      - <% count=0 %> - <% if activity.parent %> - <% count=activity.parent.children.count%> - <% else %> - <% count=activity.children.count%> - <% end %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#=format_date(activity.updated_on)%>
      - <%if count > 3 %> - - <% end %> -
      - - <% activity= activity.parent ? activity.parent : activity%> - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.children.reorder("created_on desc").each do |reply|%> - - <% replies_all_i=replies_all_i+1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= reply.content.html_safe %> -
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - - <% if !activity.locked? %> -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller=>'blog_comments',:action => 'reply', :id => activity.id, :blog_id => activity.blog.id, :user_id => activity.author_id},:method => "post",:remote=>true) do |f|%> - - - - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      - <% end %> -
      -
      - +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
      +
      + <% if activity.author.id == User.current.id%> + + <%end%> +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%> + <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> + 已设为首页 + <% end %> +
      +
      + + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
      +
      + 发帖时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(activity.updated_on) %> +
      +
      + <% if activity.parent_id.nil? %> + <% content= activity.content%> + <% else %> + <% content= activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> + +
      + + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      + +
      +
      +
      + <% count=0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#=format_date(activity.updated_on)%>
      + <%if count > 3 %> + + <% end %> +
      + + <% activity= activity.parent ? activity.parent : activity%> + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.children.reorder("created_on desc").each do |reply|%> + + <% replies_all_i=replies_all_i+1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= reply.content.html_safe %> +
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + + <% if !activity.locked? %> +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller=>'blog_comments',:action => 'reply', :id => activity.id, :blog_id => activity.blog.id, :user_id => activity.author_id},:method => "post",:remote=>true) do |f|%> + + + + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      + <% end %> +
      +
      + diff --git a/app/views/courses/syllabus.html.erb b/app/views/courses/syllabus.html.erb index e9d735900..8be245958 100644 --- a/app/views/courses/syllabus.html.erb +++ b/app/views/courses/syllabus.html.erb @@ -1,218 +1,218 @@ - -<%= content_for(:header_tags) do %> - <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> - <%= javascript_include_tag 'blog' %> -<% end %> - - - -
      -
      -
      - <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %> -
      -
      - <% if User.current && @article.author.id == User.current.id%> -
      -
        -
      • -
          -
        • - 重设大纲 -
        • -
        • - <%= link_to( - '取消大纲', - {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id}, - :method => :delete, - :data => {:confirm => '您确定要取消么?'}, - :class => 'postOptionLink' - ) if User.current && User.current.id == @article.author.id %> -
        • -
        -
      • -
      -
      - - - - - - - - - <%end%> - -
      - -
      - <% if @article.try(:author).try(:realname) == ' ' %> - <%= link_to @article.try(:author), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> - <% else %> - <%= link_to @article.try(:author).try(:realname), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> - <% end %> -
      -
      <%= format_time( @article.created_on)%>
      -
      -
      - <%= @article.content.html_safe%> -
      -
      -
      - <%#= link_to_attachments_course @topic, :author => false %> - <% if @article.attachments.any?%> - <% options = {:author => true, :deletable => false} %> - <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => @article.attachments, :options => options, :is_float => true} %> - <% end %> -
      -
      -
      -
      -
      - <% count=0 %> - <% if @article.parent %> - <% count=@article.parent.children.count%> - <% else %> - <% count=@article.children.count%> - <% end %> -
      - <% unless count == 0 %> -
      -
      回复(<%=count %>)
      -
      - -
      -
      - <%@article.children.reorder('created_on desc').each_with_index do |reply,i| %> - -
      -
      - <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> -
      -
      -
      - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> -
      -
      - <%= reply.content.html_safe%> -
      -
      - <%= format_time(reply.created_on) %> - -
      -

      -
      -
      -
      - <% end %> -
      - - <% end %> -
      - <% if !@article.locked? && User.current.logged?%> - - - - - - - - - - - - - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for 'blog_comment',:url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%> - - - - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - <% end %> -
      -
      - + +
      +
      +
      + <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %> +
      +
      + <% if User.current && @article.author.id == User.current.id%> +
      +
        +
      • +
          +
        • + 重设大纲 +
        • +
        • + <%= link_to( + '取消大纲', + {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id}, + :method => :delete, + :data => {:confirm => '您确定要取消么?'}, + :class => 'postOptionLink' + ) if User.current && User.current.id == @article.author.id %> +
        • +
        +
      • +
      +
      + + + + + + + + + <%end%> + +
      + +
      + <% if @article.try(:author).try(:realname) == ' ' %> + <%= link_to @article.try(:author), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% else %> + <%= link_to @article.try(:author).try(:realname), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% end %> +
      +
      <%= format_time( @article.created_on)%>
      +
      +
      + <%= @article.content.html_safe%> +
      +
      +
      + <%#= link_to_attachments_course @topic, :author => false %> + <% if @article.attachments.any?%> + <% options = {:author => true, :deletable => false} %> + <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => @article.attachments, :options => options, :is_float => true} %> + <% end %> +
      +
      +
      +
      +
      + <% count=0 %> + <% if @article.parent %> + <% count=@article.parent.children.count%> + <% else %> + <% count=@article.children.count%> + <% end %> +
      + <% unless count == 0 %> +
      +
      回复(<%=count %>)
      +
      + +
      +
      + <%@article.children.reorder('created_on desc').each_with_index do |reply,i| %> + +
      +
      + <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> +
      +
      +
      + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> +
      +
      + <%= reply.content.html_safe%> +
      +
      + <%= format_time(reply.created_on) %> + +
      +

      +
      +
      +
      + <% end %> +
      + + <% end %> +
      + <% if !@article.locked? && User.current.logged?%> + + + + + + + + + + + + + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for 'blog_comment',:url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%> + + + + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      + <% end %> +
      +
      + \ No newline at end of file diff --git a/app/views/issues/_issue_replies.html.erb b/app/views/issues/_issue_replies.html.erb index a1a567101..4c8dfa1d9 100644 --- a/app/views/issues/_issue_replies.html.erb +++ b/app/views/issues/_issue_replies.html.erb @@ -1,86 +1,86 @@ -
        - <% issue.journals.reorder("created_on desc").each do |reply| %> - - <% replies_all_i=replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_path(reply.user_id), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:user).try(:realname) == ' ' %> - <%= link_to reply.try(:user), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:user).try(:realname), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%#= format_time(reply.created_on) %> -
        -
        - <% if reply.details.any? %> - <% details_to_strings(reply.details).each do |string| %> -

        <%= string %>

        - <% end %> - <% end %> -

        <%= reply.notes.html_safe %>

        -
        -
        - <%= format_time(reply.created_on) %> - -
        -

        -
        -
        -
      • - <% end %> -
      -
      - -
      - <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> -
      - -
      -
      - <%= form_for('new_form',:url => add_journal_issue_path(@issue.id),:method => "post", :remote => true) do |f| %> - <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> - - -
      -
      - -
      -
      - <%= render :partial => 'attachments/issue_reply', :locals => {:container => @issue} %> -
      - - -
      - <% end %> -
      - -
      - -
      -
      +
        + <% issue.journals.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_path(reply.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:user).try(:realname) == ' ' %> + <%= link_to reply.try(:user), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:user).try(:realname), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%#= format_time(reply.created_on) %> +
        +
        + <% if reply.details.any? %> + <% details_to_strings(reply.details).each do |string| %> +

        <%= string %>

        + <% end %> + <% end %> +

        <%= reply.notes.html_safe %>

        +
        +
        + <%= format_time(reply.created_on) %> + +
        +

        +
        +
        +
      • + <% end %> +
      +
      + +
      + <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> +
      + +
      +
      + <%= form_for('new_form',:url => add_journal_issue_path(@issue.id),:method => "post", :remote => true) do |f| %> + <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> + + +
      +
      + +
      +
      + <%= render :partial => 'attachments/issue_reply', :locals => {:container => @issue} %> +
      + + +
      + <% end %> +
      + +
      + +
      +
      \ No newline at end of file diff --git a/app/views/issues/_issue_reply_ke_form.html.erb b/app/views/issues/_issue_reply_ke_form.html.erb index 16bdade05..a2975237b 100644 --- a/app/views/issues/_issue_reply_ke_form.html.erb +++ b/app/views/issues/_issue_reply_ke_form.html.erb @@ -1,27 +1,27 @@ -
      - -
      - <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> -
      - -
      -
      - <%= form_for('new_form',:url => add_reply_issue_path(@issue.id),:method => "post", :remote => true) do |f|%> - <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> - - - -
      -
      - -
      - - -
      - <% end %> -
      - -
      - -
      +
      + +
      + <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> +
      + +
      +
      + <%= form_for('new_form',:url => add_reply_issue_path(@issue.id),:method => "post", :remote => true) do |f|%> + <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> + + + +
      +
      + +
      + + +
      + <% end %> +
      + +
      + +
      \ No newline at end of file diff --git a/app/views/messages/_reply_message.html.erb b/app/views/messages/_reply_message.html.erb index d0cec9e62..faa0bd0ce 100644 --- a/app/views/messages/_reply_message.html.erb +++ b/app/views/messages/_reply_message.html.erb @@ -1,19 +1,19 @@ - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
      -
      -
      - <%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'new_form'} do |f| %> - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
      +
      +
      + <%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'new_form'} do |f| %> + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/org_document_comments/_simple_ke_reply_form.html.erb b/app/views/org_document_comments/_simple_ke_reply_form.html.erb index 6280db653..1813f5b5f 100644 --- a/app/views/org_document_comments/_simple_ke_reply_form.html.erb +++ b/app/views/org_document_comments/_simple_ke_reply_form.html.erb @@ -1,18 +1,18 @@ -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
      -
      -
      - <%= form_for @org_comment, :as => :reply, :url => {:controller => 'org_document_comments',:action => 'reply', :id => @org_comment.id}, :method => 'post', :html => {:multipart => true, :id => 'new_form'} do |f| %> - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
      +
      +
      + <%= form_for @org_comment, :as => :reply, :url => {:controller => 'org_document_comments',:action => 'reply', :id => @org_comment.id}, :method => 'post', :html => {:multipart => true, :id => 'new_form'} do |f| %> + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/organizations/_org_course_news.html.erb b/app/views/organizations/_org_course_news.html.erb index 213fc0e0b..3da0887ed 100644 --- a/app/views/organizations/_org_course_news.html.erb +++ b/app/views/organizations/_org_course_news.html.erb @@ -1,123 +1,123 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if @ctivity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> -
      - - <% if activity.sticky == 1%> - 置顶 - <% end%> -
      -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
      -
      - <% count=activity.comments.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.comments.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_url_in_org(comment.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:author).try(:realname) == ' ' %> - <%= link_to comment.try(:author), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:author).try(:realname), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= comment.comments.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if @ctivity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> +
      + + <% if activity.sticky == 1%> + 置顶 + <% end%> +
      +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
      +
      + <% count=activity.comments.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_url_in_org(comment.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= comment.comments.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      +
      diff --git a/app/views/organizations/_org_project_issue.html.erb b/app/views/organizations/_org_project_issue.html.erb index e403e86a3..782412e43 100644 --- a/app/views/organizations/_org_project_issue.html.erb +++ b/app/views/organizations/_org_project_issue.html.erb @@ -1,141 +1,141 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.project.name.to_s+" | 项目问题", project_issues_path(activity.project), :class => "newsBlue ml15"%> -
      -
      - <%= link_to activity.subject.to_s, issue_path(activity), :class => "postGrey" %> - - <%#= get_issue_priority(activity.priority_id)[1] %> - -
      -
      -
      指派给   - <% unless activity.assigned_to_id.nil? %> - <% if activity.try(:assigned_to).try(:realname) == ' ' %> - <%= link_to activity.try(:assigned_to), user_url_in_org(activity.assigned_to_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:assigned_to).try(:realname), user_url_in_org(activity.assigned_to_id), :class => "newsBlue mr15" %> - <% end %> - <% end %> -
      -
      - 发布时间: - <%=format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> -
      -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
      -
      - <% count = activity.journals.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <% if count > 3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.journals.reorder("created_on desc").each do |reply| %> - - <% replies_all_i=replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_url_in_org(reply.user_id), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:user).try(:realname) == ' ' %> - <%= link_to reply.try(:user), user_url_in_org(reply.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:user).try(:realname), user_url_in_org(reply.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
        -
        - <% if reply.details.any? %> - <% details_to_strings(reply.details).each do |string| %> -

        <%= string %>

        - <% end %> - <% end %> -

        <%= reply.notes.nil? ? "" : reply.notes.html_safe %>

        -
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => add_journal_in_org_issue_path(activity.id),:method => "post", :remote => true) do |f|%> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.project.name.to_s+" | 项目问题", project_issues_path(activity.project), :class => "newsBlue ml15"%> +
      +
      + <%= link_to activity.subject.to_s, issue_path(activity), :class => "postGrey" %> + + <%#= get_issue_priority(activity.priority_id)[1] %> + +
      +
      +
      指派给   + <% unless activity.assigned_to_id.nil? %> + <% if activity.try(:assigned_to).try(:realname) == ' ' %> + <%= link_to activity.try(:assigned_to), user_url_in_org(activity.assigned_to_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:assigned_to).try(:realname), user_url_in_org(activity.assigned_to_id), :class => "newsBlue mr15" %> + <% end %> + <% end %> +
      +
      + 发布时间: + <%=format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> +
      +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
      +
      + <% count = activity.journals.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <% if count > 3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.journals.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_url_in_org(reply.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:user).try(:realname) == ' ' %> + <%= link_to reply.try(:user), user_url_in_org(reply.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:user).try(:realname), user_url_in_org(reply.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
        +
        + <% if reply.details.any? %> + <% details_to_strings(reply.details).each do |string| %> +

        <%= string %>

        + <% end %> + <% end %> +

        <%= reply.notes.nil? ? "" : reply.notes.html_safe %>

        +
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => add_journal_in_org_issue_path(activity.id),:method => "post", :remote => true) do |f|%> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      + +
      +
      diff --git a/app/views/organizations/_org_subfield_message.html.erb b/app/views/organizations/_org_subfield_message.html.erb index a89b37b46..bf0cc8734 100644 --- a/app/views/organizations/_org_subfield_message.html.erb +++ b/app/views/organizations/_org_subfield_message.html.erb @@ -1,161 +1,161 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% end %> - TO - <%= link_to activity.board.org_subfield.name.to_s+" | 帖子栏目讨论区",organization_path(activity.board.org_subfield.organization, :org_subfield_id => activity.board.org_subfield.id), :class => "newsBlue ml15 mr5"%> -
      -
      - <% if activity.parent_id.nil? %> - <%= link_to activity.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" - %> - <% else %> - <%= link_to activity.parent.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" - %> - <% end %> -
      -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(OrgActivity.where("org_act_type='#{activity.class}' and org_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <% if activity.parent_id.nil? %> - <% content = activity.content%> - <% else %> - <% content = activity.parent.content%> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
        -
      • - <% if User.current.logged? %> -
          -
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'message')") %>
        • -
        • - <%= link_to( - l(:button_edit), - {:controller => 'messages', :action => 'edit', :id => activity, :board_id => activity.board_id}, - :class => 'postOptionLink' - ) if activity.org_subfield_editable_by?(User.current) %> -
        • -
        • - <%= link_to( - l(:button_delete), - {:controller => 'messages', :action => 'destroy', :id => activity, :board_id => activity.board_id}, - :method => 'post', - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'postOptionLink' - ) if activity.org_subfield_editable_by?(User.current) %> -
        • -
        - <% end %> -
      • -
      -
      -
      -
      -
      - <% count = 0 %> - <% if activity.parent %> - <% count=activity.parent.children.count%> - <% else %> - <% count=activity.children.count%> - <% end %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      - <%if count>3 %> - - <% end %> -
      - - <% activity= activity.parent_id.nil? ? activity : activity.parent %> - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.children.reorder("created_on desc").each do |reply| %> - - <% replies_all_i=replies_all_i+1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_url_in_org(reply.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= reply.content.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.board.org_subfield.name.to_s+" | 帖子栏目讨论区",organization_path(activity.board.org_subfield.organization, :org_subfield_id => activity.board.org_subfield.id), :class => "newsBlue ml15 mr5"%> +
      +
      + <% if activity.parent_id.nil? %> + <%= link_to activity.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% else %> + <%= link_to activity.parent.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% end %> +
      +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(OrgActivity.where("org_act_type='#{activity.class}' and org_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <% if activity.parent_id.nil? %> + <% content = activity.content%> + <% else %> + <% content = activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
        +
      • + <% if User.current.logged? %> +
          +
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'message')") %>
        • +
        • + <%= link_to( + l(:button_edit), + {:controller => 'messages', :action => 'edit', :id => activity, :board_id => activity.board_id}, + :class => 'postOptionLink' + ) if activity.org_subfield_editable_by?(User.current) %> +
        • +
        • + <%= link_to( + l(:button_delete), + {:controller => 'messages', :action => 'destroy', :id => activity, :board_id => activity.board_id}, + :method => 'post', + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'postOptionLink' + ) if activity.org_subfield_editable_by?(User.current) %> +
        • +
        + <% end %> +
      • +
      +
      +
      +
      +
      + <% count = 0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      + <%if count>3 %> + + <% end %> +
      + + <% activity= activity.parent_id.nil? ? activity : activity.parent %> + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.children.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i+1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_url_in_org(reply.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= reply.content.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      + +
      +
      diff --git a/app/views/organizations/_org_subfield_news.html.erb b/app/views/organizations/_org_subfield_news.html.erb index 5a96a1449..3d2a316cf 100644 --- a/app/views/organizations/_org_subfield_news.html.erb +++ b/app/views/organizations/_org_subfield_news.html.erb @@ -1,146 +1,146 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.org_subfield.name.to_s+" | 帖子栏目通知", organization_path(activity.org_subfield.organization, :org_subfield_id => activity.org_subfield.id), :class => "newsBlue ml15" %> -
      - - -
      -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
        -
      • - <% if User.current.logged? %> -
          -
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'news')") %>
        • -
        • - <%= link_to( - l(:button_edit), - {:controller => 'news', :action => 'edit', :id => activity}, - :class => 'postOptionLink' - ) if activity.author == User.current %> -
        • -
        • - <%= delete_link( - news_path(activity), - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'postOptionLink' - ) if activity.author == User.current %> -
        • -
        - <% end %> -
      • -
      -
      -
      -
      -
      - <% count=activity.comments.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.comments.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_url_in_org(comment.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:author).try(:realname) == ' ' %> - <%= link_to comment.try(:author), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:author).try(:realname), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= comment.comments.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      -
      - +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.org_subfield.name.to_s+" | 帖子栏目通知", organization_path(activity.org_subfield.organization, :org_subfield_id => activity.org_subfield.id), :class => "newsBlue ml15" %> +
      + + +
      +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
        +
      • + <% if User.current.logged? %> +
          +
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'news')") %>
        • +
        • + <%= link_to( + l(:button_edit), + {:controller => 'news', :action => 'edit', :id => activity}, + :class => 'postOptionLink' + ) if activity.author == User.current %> +
        • +
        • + <%= delete_link( + news_path(activity), + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'postOptionLink' + ) if activity.author == User.current %> +
        • +
        + <% end %> +
      • +
      +
      +
      +
      +
      + <% count=activity.comments.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_url_in_org(comment.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_url_in_org(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= comment.comments.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      +
      + diff --git a/app/views/organizations/_project_message.html.erb b/app/views/organizations/_project_message.html.erb index fef6a5651..99a067dfb 100644 --- a/app/views/organizations/_project_message.html.erb +++ b/app/views/organizations/_project_message.html.erb @@ -1,136 +1,136 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> - <% end %> - TO - <%= link_to activity.project.name.to_s+" | 项目讨论区",project_boards_path(activity.project), :class => "newsBlue ml15 mr5"%> - -
      -
      - <% if activity.parent_id.nil? %> - <%= link_to activity.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" - %> - <% else %> - <%= link_to activity.parent.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" - %> - <% end %> -
      -
      - 发帖时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <% if activity.parent_id.nil? %> - <% content = activity.content%> - <% else %> - <% content = activity.parent.content%> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
      -
      - <% count = 0 %> - <% if activity.parent %> - <% count=activity.parent.children.count%> - <% else %> - <% count=activity.children.count%> - <% end %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#=format_date(activity.updated_on)%>
      - <%if count>3 %> - - <% end %> -
      - - <% activity= activity.parent_id.nil? ? activity : activity.parent %> - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.children.reorder("created_on desc").each do |reply| %> - - <% replies_all_i=replies_all_i+1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_url_in_org(reply.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= reply.content.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_url_in_org(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_url_in_org(activity.author_id), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.project.name.to_s+" | 项目讨论区",project_boards_path(activity.project), :class => "newsBlue ml15 mr5"%> + +
      +
      + <% if activity.parent_id.nil? %> + <%= link_to activity.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% else %> + <%= link_to activity.parent.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% end %> +
      +
      + 发帖时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <% if activity.parent_id.nil? %> + <% content = activity.content%> + <% else %> + <% content = activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
      +
      + <% count = 0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#=format_date(activity.updated_on)%>
      + <%if count>3 %> + + <% end %> +
      + + <% activity= activity.parent_id.nil? ? activity : activity.parent %> + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.children.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i+1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_url_in_org(reply.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_url_in_org(reply.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= reply.content.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_url_in_org(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      + +
      +
      diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index d053341e1..ed6e1e092 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -1,152 +1,152 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(User.find(document.creator_id)), :width => 45, :heigth => 45), user_url_in_org(document.creator_id) %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => User.find(document.creator_id)} %> -
      -
      -
      - <%= link_to User.find(document.creator_id), user_url_in_org(document.creator.id), :class => "newsBlue mr15" %> - TO  <%= link_to document.organization.name, organization_path(document.organization), :class => "newsBlue" %> - | - <%= document.org_subfield_id.nil? ? "组织文章" :"#{OrgSubfield.find(document.org_subfield_id).name}" %> -
      -
      <%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id) %>
      -
      - 发布时间:<%= format_activity_day(document.created_at) %> <%= format_time(document.created_at, false) %> -
      -
      - 更新时间:<%= format_time(OrgActivity.where("org_act_type='#{document.class}' and org_act_id =#{document.id}").first.updated_at) %> -
      -
      - <% unless document.content.blank? %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>document.id, :content=>document.content} %> - <% end %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => document} %> -
      - - <% if User.current.admin? || User.current.admin_of_org?(Organization.find(document.organization_id)) || User.current.id == document.creator_id %> -
      -
        -
      • -
          -
        • - <%= form_for('new_form', :url => {:controller => 'organizations', :action => 'set_homepage', :id => document.organization_id, :home_id => document.id, :show_homepage => 1}, :method => "put", :remote => true) do |f| %> - 设为首页 - <% end %> -
        • -
        • - <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id, :flag => flag, :org_subfield_id => params[:org_subfield_id] ), :class => "postOptionLink" %> -
        • -
        • - <%= link_to "删除文章", org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :method => 'delete', - :data => {:confirm => l(:text_are_you_sure)}, - :remote => true, :class => 'postOptionLink' %> -
        • -
        -
      • -
      -
      -
      - <% end %> -
      -
      - <% comments_for_doc = document.children.reorder("created_at desc") %> - <% count = document.children.count() %> - -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if document.creator_id.to_i == User.current.id.to_i %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>document, :user_activity_id=>document.id,:type=>"activity"}%> - <% end %> - -
      - <% if count > 3 %> - - <% end %> -
      -
      -
        - <% reply_id = 0 %> - <% comments_for_doc.each do |comment| %> - <% reply_id += 1 %> -
      • -
        <%= link_to image_tag(url_to_avatar(User.find(comment.creator_id)), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_id) %>
        -
        -
        - <%= link_to User.find(comment.creator_id), user_url_in_org(comment.creator_id), :class => "newsBlue mr10 f14" %> - <%= format_activity_day(comment.created_at) %> <%= format_time(comment.created_at, false) %> - - <% if comment.creator_id.to_i == User.current.id.to_i %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        - <% unless comment.content.blank? %> -
        <%= comment.content.html_safe %>
        - <% end %> -
        -
        -
      • - <% end %> -
      -
      -
      -
      - <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33", :alt => "用户头像"), user_url_in_org(User.current) %> -
      -
      -
      - <%= form_for('new_form', :url => add_reply_org_document_comment_path(:id => document.id, :act_id => act.id, :flag => flag), :method => "post", :remote => true) do |f| %> - -
      - - - -
      -

      - <% end %> -
      -
      -
      -
      -
      -
      -
      - - \ No newline at end of file diff --git a/app/views/projects/_project_news.html.erb b/app/views/projects/_project_news.html.erb index c3d4d5bfb..4ea0e9f17 100644 --- a/app/views/projects/_project_news.html.erb +++ b/app/views/projects/_project_news.html.erb @@ -1,123 +1,123 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.project.name.to_s+" | 项目新闻", project_news_index_path(activity.project), :class => "newsBlue ml15" %> -
      - - <% if activity.sticky == 1%> - 置顶 - <% end%> -
      -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
      -
      - <% count=activity.comments.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.comments.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:author).try(:realname) == ' ' %> - <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= comment.comments.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.project.name.to_s+" | 项目新闻", project_news_index_path(activity.project), :class => "newsBlue ml15" %> +
      + + <% if activity.sticky == 1%> + 置顶 + <% end%> +
      +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
      +
      + <% count=activity.comments.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= comment.comments.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 51918d2d7..750a3c6ec 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -1,81 +1,81 @@ -<%= call_hook(:view_repositories_show_contextual, {:repository => @repository, :project => @project}) %> -
      -

      <%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

      -
      -
      - <% if @entries.nil? %> - <%# 未提交代码提示 %> -
      - <% if @entries.nil? && authorize_for('repositories', 'browse') %> -
      - 该版本库还没有上传代码! -
      - <% end %> - <% if @repository.type.to_s=="Repository::Gitlab" %> - 版本库地址:<%= @repos_url %> - <% else %> - 版本库地址:<%= h @repository.url %> - <% end %> - -
      -
      - <% else %> - <%= render :partial => 'navigation' %> -
      克隆网址:
      - - - - <%# 针对公开项目:用户必须创建了项目,否则用户无法同步 %> - <% if User.current.id != @project.user_id %> -
      <%= link_to "".html_safe+"Fork", {:controller => 'repositories', :action => 'forked'}, :class=>"vl_btn", :target => "_blank", :confirm=>"平台将为您创建一个新的同名项目和版本库,请问是否继续?" %> - <%= @project.forked_count.to_i %> -
      - <% end %> -
      -
      - <% if @changesets && !@changesets.empty? %> - <% if !user_commit_rep(@changesets_latest_coimmit.author_email).nil? %> - <%= image_tag(url_to_avatar(user_commit_rep(@changesets_latest_coimmit.author_email)), :width => "25", :height => "25", :class => "fl portraitRadius mt2 ml4 mr5") %> - -
      提交于<%= time_tag(@changesets_latest_coimmit.created_at) %>:
      -
      <%= @changesets_latest_coimmit.message %>
      -
      - <% else %> - -
      提交于<%= time_tag(@changesets_latest_coimmit.created_at) %>:
      -
      <%= @changesets_latest_coimmit.message %>
      -
      - <%end%> - <% end %> - - <%= @repository.branches.count %> 个分支 - - - - <%=link_to @changesets_all_count, {:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param, :rev => @rev,:page=>1 ,:commit_count =>"#{@changesets_all_count}"} %> 提交 - - -
      - <% end %> - - - -<% if !@entries.nil? && authorize_for('repositories', 'browse') %> - <%# 数据统计 %> - <%#= render :partial => 'summary' %> - <%# end %> - <%= render :partial => 'dir_list' %> -<% end %> -<%#= render_properties(@properties) %> - - -<%#= render_properties(@properties) %> - - -如何提交代码 -
      -<% content_for :header_tags do %> - <%= stylesheet_link_tag "scm" %> -<% end %> - -<% html_title(l(:label_repository)) -%> +<%= call_hook(:view_repositories_show_contextual, {:repository => @repository, :project => @project}) %> +
      +

      <%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

      +
      +
      + <% if @entries.nil? %> + <%# 未提交代码提示 %> +
      + <% if @entries.nil? && authorize_for('repositories', 'browse') %> +
      + 该版本库还没有上传代码! +
      + <% end %> + <% if @repository.type.to_s=="Repository::Gitlab" %> + 版本库地址:<%= @repos_url %> + <% else %> + 版本库地址:<%= h @repository.url %> + <% end %> + +
      +
      + <% else %> + <%= render :partial => 'navigation' %> +
      克隆网址:
      + + + + <%# 针对公开项目:用户必须创建了项目,否则用户无法同步 %> + <% if User.current.id != @project.user_id %> +
      <%= link_to "".html_safe+"Fork", {:controller => 'repositories', :action => 'forked'}, :class=>"vl_btn", :target => "_blank", :confirm=>"平台将为您创建一个新的同名项目和版本库,请问是否继续?" %> + <%= @project.forked_count.to_i %> +
      + <% end %> +
      +
      + <% if @changesets && !@changesets.empty? %> + <% if !user_commit_rep(@changesets_latest_coimmit.author_email).nil? %> + <%= image_tag(url_to_avatar(user_commit_rep(@changesets_latest_coimmit.author_email)), :width => "25", :height => "25", :class => "fl portraitRadius mt2 ml4 mr5") %> + +
      提交于<%= time_tag(@changesets_latest_coimmit.created_at) %>:
      +
      <%= @changesets_latest_coimmit.message %>
      +
      + <% else %> + +
      提交于<%= time_tag(@changesets_latest_coimmit.created_at) %>:
      +
      <%= @changesets_latest_coimmit.message %>
      +
      + <%end%> + <% end %> + + <%= @repository.branches.count %> 个分支 + + + + <%=link_to @changesets_all_count, {:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param, :rev => @rev,:page=>1 ,:commit_count =>"#{@changesets_all_count}"} %> 提交 + + +
      + <% end %> + + + +<% if !@entries.nil? && authorize_for('repositories', 'browse') %> + <%# 数据统计 %> + <%#= render :partial => 'summary' %> + <%# end %> + <%= render :partial => 'dir_list' %> +<% end %> +<%#= render_properties(@properties) %> + + +<%#= render_properties(@properties) %> + + +如何提交代码 +
      +<% content_for :header_tags do %> + <%= stylesheet_link_tag "scm" %> +<% end %> + +<% html_title(l(:label_repository)) -%> diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index 8ed5f077b..884bb8eb1 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -1,102 +1,102 @@ - -
        -
      • -
          -
        • - <%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40"),user_activities_path(student_work.user)) %> -
        • -
          -
        • - <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%> -
          - <%= link_to student_work_name,"javascript:void(0)" ,:title => student_work_name, :class => "linkGrey f14 StudentName break_word #{@homework.homework_type == 2 ? '' : 'width165'}"%> -
          -
        • -
        • - <% if @homework.homework_type != 3 %> -
            -
          • - <%= student_work.user.show_name%> -
          • -
          • "> - <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> -
          • -
          - <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> -
            -
          • - <%= student_work.project.name %> -
          • -
          - <% end %> -
        • -
          -
        -
      • -
      • - <% if student_work.created_at && @homework.end_time%> - <%= Time.parse(format_time(student_work.created_at)).strftime("%m-%d %H:%M")%>  - <% if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(format_time(student_work.created_at)).strftime("%Y-%m-%d") %> - [迟交] - <% end %> - <% end %> -
      • -
      • - <%= student_work.teacher_score.nil? ? "--" : format("%.1f",student_work.teacher_score)%> -
      • -
      • - <%= student_work.teaching_asistant_score.nil? ? "--" : format("%.1f",student_work.teaching_asistant_score)%> -
      • - - <% if @homework.homework_type == 2%> - -
      • - <%= student_work.system_score.nil? ? "--" : format("%.1f",student_work.system_score)%> -
      • - <% end%> - - <% if @homework.anonymous_comment == 0%> -
      • - <%= student_work.student_score.nil? ? "未参与" : format("%.1f",student_work.student_score)%> - <% unless student_work.student_score.nil?%> - - (<%= student_work.student_works_scores.where(:reviewer_role => 3).count%>) - -
        - 现共有 -  <%= student_work.student_works_scores.where(:reviewer_role => 3).count%>  - 名学生进行了匿评,平均分为 -  <%= format("%.1f",student_work.student_score)%> 分。 -
        - <% end%> -
      • - <% end %> - - <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty%> -
      • - <%= score.nil? ? "--" : format("%.1f",score<0 ? 0 : score)%> - <% unless score.nil?%> -
        - 作品最终评分为 -  <%= student_work.final_score%> 分。 - 迟交扣分 -  <%= student_work.late_penalty%> 分, - 缺评扣分 -  <%= student_work.absence_penalty%> 分, - 最终成绩为 -  <%= format("%.1f",score<0 ? 0 : score)%> 分。 -
        - <% end%> -
      • - -
      - - + +
        +
      • +
          +
        • + <%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40"),user_activities_path(student_work.user)) %> +
        • +
          +
        • + <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%> +
          + <%= link_to student_work_name,"javascript:void(0)" ,:title => student_work_name, :class => "linkGrey f14 StudentName break_word #{@homework.homework_type == 2 ? '' : 'width165'}"%> +
          +
        • +
        • + <% if @homework.homework_type != 3 %> +
            +
          • + <%= student_work.user.show_name%> +
          • +
          • "> + <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> +
          • +
          + <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> +
            +
          • + <%= student_work.project.name %> +
          • +
          + <% end %> +
        • +
          +
        +
      • +
      • + <% if student_work.created_at && @homework.end_time%> + <%= Time.parse(format_time(student_work.created_at)).strftime("%m-%d %H:%M")%>  + <% if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(format_time(student_work.created_at)).strftime("%Y-%m-%d") %> + [迟交] + <% end %> + <% end %> +
      • +
      • + <%= student_work.teacher_score.nil? ? "--" : format("%.1f",student_work.teacher_score)%> +
      • +
      • + <%= student_work.teaching_asistant_score.nil? ? "--" : format("%.1f",student_work.teaching_asistant_score)%> +
      • + + <% if @homework.homework_type == 2%> + +
      • + <%= student_work.system_score.nil? ? "--" : format("%.1f",student_work.system_score)%> +
      • + <% end%> + + <% if @homework.anonymous_comment == 0%> +
      • + <%= student_work.student_score.nil? ? "未参与" : format("%.1f",student_work.student_score)%> + <% unless student_work.student_score.nil?%> + + (<%= student_work.student_works_scores.where(:reviewer_role => 3).count%>) + +
        + 现共有 +  <%= student_work.student_works_scores.where(:reviewer_role => 3).count%>  + 名学生进行了匿评,平均分为 +  <%= format("%.1f",student_work.student_score)%> 分。 +
        + <% end%> +
      • + <% end %> + + <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty%> +
      • + <%= score.nil? ? "--" : format("%.1f",score<0 ? 0 : score)%> + <% unless score.nil?%> +
        + 作品最终评分为 +  <%= student_work.final_score%> 分。 + 迟交扣分 +  <%= student_work.late_penalty%> 分, + 缺评扣分 +  <%= student_work.absence_penalty%> 分, + 最终成绩为 +  <%= format("%.1f",score<0 ? 0 : score)%> 分。 +
        + <% end%> +
      • + +
      + + diff --git a/app/views/student_work/show.js.erb b/app/views/student_work/show.js.erb index afa03bff8..c89180b16 100644 --- a/app/views/student_work/show.js.erb +++ b/app/views/student_work/show.js.erb @@ -1,36 +1,36 @@ -if($("#about_hwork_<%= @work.id%>").children().length > 0){ - $("#about_hwork_<%= @work.id%>").html(""); -} -else{ - <% if @homework.homework_type == 2%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - - var program_name = "text/x-csrc"; - var language = <%= @homework.language %>; - if (language == 1) { - program_name = 'text/x-csrc'; - } else if(language==2){ - program_name = 'text/x-c++src'; - }else if(language==3){ - program_name = 'text/x-cython'; - } else if(language==4){ - program_name = 'text/x-java'; - } - - var editor = CodeMirror(document.getElementById("work-code_<%= @work.id%>"), { - mode: {name: program_name, - version: 2, - singleLineStringErrors: false}, - lineNumbers: true, - indentUnit: 2, - matchBrackets: true, - readOnly: true, - value: $("#work-src").text() - } - ); - - <% else%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - <% end%> - $('#score_<%= @work.id%>').peSlider({range: 'min'}); +if($("#about_hwork_<%= @work.id%>").children().length > 0){ + $("#about_hwork_<%= @work.id%>").html(""); +} +else{ + <% if @homework.homework_type == 2%> + $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); + + var program_name = "text/x-csrc"; + var language = <%= @homework.language %>; + if (language == 1) { + program_name = 'text/x-csrc'; + } else if(language==2){ + program_name = 'text/x-c++src'; + }else if(language==3){ + program_name = 'text/x-cython'; + } else if(language==4){ + program_name = 'text/x-java'; + } + + var editor = CodeMirror(document.getElementById("work-code_<%= @work.id%>"), { + mode: {name: program_name, + version: 2, + singleLineStringErrors: false}, + lineNumbers: true, + indentUnit: 2, + matchBrackets: true, + readOnly: true, + value: $("#work-src").text() + } + ); + + <% else%> + $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); + <% end%> + $('#score_<%= @work.id%>').peSlider({range: 'min'}); } \ No newline at end of file diff --git a/app/views/users/_course_journalsformessage.html.erb b/app/views/users/_course_journalsformessage.html.erb index 79d609182..f9a59f024 100644 --- a/app/views/users/_course_journalsformessage.html.erb +++ b/app/views/users/_course_journalsformessage.html.erb @@ -1,110 +1,110 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> -
      -
      -
      - <% if activity.try(:user).try(:realname) == ' ' %> - <%= link_to activity.try(:user), user_path(activity.user_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id), :class => "newsBlue mr15" %> - <% end %> TO - <% course=Course.find(activity.jour_id) %> - <%= link_to course.name.to_s+" | 课程留言", course_feedback_path(course), :class => "newsBlue ml15" %> -
      -
      - <% if activity.parent %> - <%= link_to activity.parent.notes.html_safe, course_feedback_path(course), :class => "postGrey" %> - <% else %> - <%= link_to activity.notes.html_safe, course_feedback_path(course), :class => "postGrey" %> - <% end %> -
      -
      - 留言时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> -
      -
      -
      -
      -
      - <% count = fetch_user_leaveWord_reply(activity).count %> -
      -
      -
      -
      - 回复(<%= count %>) -
      -
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% fetch_user_leaveWord_reply(activity).each do |comment| unless fetch_user_leaveWord_reply(activity).nil? %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:user).try(:realname) == ' ' %> - <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> -
        -
        - <%= comment.notes.html_safe %> -
        -
        -
        -
      • - <% end %> - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'words', :action => 'create_reply', :id => activity.id}, :method => "post", :remote => true) do |f|%> - <%= hidden_field_tag 'reference_id', params[:reference_id], :value => activity.id %> - <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => activity.user.id %> - <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => activity.id %> - <%= hidden_field_tag 'show_name',params[:show_name],:value =>true %> - <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      -
      - +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> +
      +
      +
      + <% if activity.try(:user).try(:realname) == ' ' %> + <%= link_to activity.try(:user), user_path(activity.user_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id), :class => "newsBlue mr15" %> + <% end %> TO + <% course=Course.find(activity.jour_id) %> + <%= link_to course.name.to_s+" | 课程留言", course_feedback_path(course), :class => "newsBlue ml15" %> +
      +
      + <% if activity.parent %> + <%= link_to activity.parent.notes.html_safe, course_feedback_path(course), :class => "postGrey" %> + <% else %> + <%= link_to activity.notes.html_safe, course_feedback_path(course), :class => "postGrey" %> + <% end %> +
      +
      + 留言时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> +
      +
      +
      +
      +
      + <% count = fetch_user_leaveWord_reply(activity).count %> +
      +
      +
      +
      + 回复(<%= count %>) +
      +
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% fetch_user_leaveWord_reply(activity).each do |comment| unless fetch_user_leaveWord_reply(activity).nil? %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> +
        +
        + <%= comment.notes.html_safe %> +
        +
        +
        +
      • + <% end %> + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'words', :action => 'create_reply', :id => activity.id}, :method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'reference_id', params[:reference_id], :value => activity.id %> + <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => activity.user.id %> + <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => activity.id %> + <%= hidden_field_tag 'show_name',params[:show_name],:value =>true %> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      +
      + diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index 560b76fd4..efaa72beb 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -1,148 +1,148 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if @ctivity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> -
      - - <% if activity.sticky == 1%> - 置顶 - <% end%> -
      -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
        -
      • - <% if User.current.logged? %> -
          -
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'news')") %>
        • -
        • - <%= link_to( - l(:button_edit), - {controller:'news', :action => 'edit', :id => activity.id}, - :class => 'postOptionLink' - ) if User.current.allowed_to?(:manage_news, activity.course) %> -
        • -
        • - <%= delete_link( - news_path(activity), - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'postOptionLink' - ) if User.current.allowed_to?(:manage_news, activity.course) %> -
        • -
        - <% end %> -
      • -
      -
      -
      -
      -
      - <% count=activity.comments.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.comments.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:author).try(:realname) == ' ' %> - <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= comment.comments.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if @ctivity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> +
      + + <% if activity.sticky == 1%> + 置顶 + <% end%> +
      +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
        +
      • + <% if User.current.logged? %> +
          +
        • <%= link_to("发送", 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}',#{User.current.id},'news')") %>
        • +
        • + <%= link_to( + l(:button_edit), + {controller:'news', :action => 'edit', :id => activity.id}, + :class => 'postOptionLink' + ) if User.current.allowed_to?(:manage_news, activity.course) %> +
        • +
        • + <%= delete_link( + news_path(activity), + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'postOptionLink' + ) if User.current.allowed_to?(:manage_news, activity.course) %> +
        • +
        + <% end %> +
      • +
      +
      +
      +
      +
      + <% count=activity.comments.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= comment.comments.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      +
      diff --git a/app/views/users/_project_issue_reply.html.erb b/app/views/users/_project_issue_reply.html.erb index d76913e23..16d681dc9 100644 --- a/app/views/users/_project_issue_reply.html.erb +++ b/app/views/users/_project_issue_reply.html.erb @@ -1,89 +1,89 @@ -<% count = activity.journals.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <% if count > 3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.journals.reorder("created_on desc").each do |reply| %> - - <% replies_all_i=replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_path(reply.user_id), :alt => "用户头像" %> -
        -
        -
        - <% if reply.try(:user).try(:realname) == ' ' %> - <%= link_to reply.try(:user), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:user).try(:realname), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
        -
        - <% if reply.details.any? %> - <% details_to_strings(reply.details).each do |string| %> -

        <%= string %>

        - <% end %> - <% end %> -

        <%= reply.notes.html_safe %>

        -
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => add_journal_issue_path(activity.id, :user_activity_id => user_activity_id),:method => "post", :remote => true) do |f| %> - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - +<% count = activity.journals.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <% if count > 3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.journals.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(reply.user), :width => "33", :height => "33"), user_path(reply.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if reply.try(:user).try(:realname) == ' ' %> + <%= link_to reply.try(:user), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:user).try(:realname), user_path(reply.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
        +
        + <% if reply.details.any? %> + <% details_to_strings(reply.details).each do |string| %> +

        <%= string %>

        + <% end %> + <% end %> +

        <%= reply.notes.html_safe %>

        +
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => add_journal_issue_path(activity.id, :user_activity_id => user_activity_id),:method => "post", :remote => true) do |f| %> + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/users/_user_at_message.html.erb b/app/views/users/_user_at_message.html.erb index 343741cd4..d8649cabe 100644 --- a/app/views/users/_user_at_message.html.erb +++ b/app/views/users/_user_at_message.html.erb @@ -1,33 +1,33 @@ -<% if AtMessage === ma && ma.at_valid? %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.author), :width => "30", :height => "30"),user_path(ma.author) %>
      • -
      • - <%= ma.author.login %>提到了你: -
      • -
      • - <% if ma.at_message_type == "Message" && !ma.at_message.course.nil? %> - <%= link_to ma.subject.html_safe, course_boards_path(ma.at_message.course, - :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), - :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> - <% elsif ma.at_message_type == "Message" && !ma.at_message.project.nil? %> - <%= link_to ma.subject.html_safe, project_boards_path(ma.at_message.project, - :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), - :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> - <% else %> - <%= link_to ma.subject.html_safe, ma.url, :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", :onmouseover =>"message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %> - <% end %> -
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      +<% if AtMessage === ma && ma.at_valid? %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.author), :width => "30", :height => "30"),user_path(ma.author) %>
      • +
      • + <%= ma.author.login %>提到了你: +
      • +
      • + <% if ma.at_message_type == "Message" && !ma.at_message.course.nil? %> + <%= link_to ma.subject.html_safe, course_boards_path(ma.at_message.course, + :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), + :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> + <% elsif ma.at_message_type == "Message" && !ma.at_message.project.nil? %> + <%= link_to ma.subject.html_safe, project_boards_path(ma.at_message.project, + :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), + :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> + <% else %> + <%= link_to ma.subject.html_safe, ma.url, :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", :onmouseover =>"message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %> + <% end %> +
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      <% end %> \ No newline at end of file diff --git a/app/views/users/_user_blog.html.erb b/app/views/users/_user_blog.html.erb index 032f6b9a9..841fd9377 100644 --- a/app/views/users/_user_blog.html.erb +++ b/app/views/users/_user_blog.html.erb @@ -1,147 +1,147 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> -
      -
      -
      - <% if @ctivity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.author.name.to_s+" | 博客", user_blogs_path(:user_id=>activity.author_id), :class => "newsBlue ml15" %> -
      -
      -
      - <%= link_to activity.title.to_s, user_blog_blog_comment_path(:user_id=>activity.author_id,:blog_id=>activity.blog_id,:id=>activity.id,:in_act => true), :class => "postGrey" %> -
      - <% if activity.sticky == 1%> - 置顶 - <% end%> - <% if activity.locked%> -        - <% end%> -
      -
      - -
      - 发布时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(UserActivity.where("act_type='#{activity.class}' and act_id =#{activity.id}").first.updated_at) %> -
      -
      - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.content} %> -
      - - -
      -
      - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
      -
      -
      -
      - <% count=activity.children.count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      <%#= format_date(activity.updated_on) %>
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% activity.children.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:author).try(:realname) == ' ' %> - <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - -
        -
        - <%= comment.content.html_safe %>
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - - <% if activity.locked == false && User.current.logged?%> -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'blog_comments', :action => 'reply', :user_id=>activity.author_id,:blog_id=>activity.blog_id,:id=>activity.id},:method => "post", :remote => true) do |f|%> - - - - - - -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      - <% end %> -
      -
      - +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
      +
      +
      + <% if @ctivity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.author.name.to_s+" | 博客", user_blogs_path(:user_id=>activity.author_id), :class => "newsBlue ml15" %> +
      +
      +
      + <%= link_to activity.title.to_s, user_blog_blog_comment_path(:user_id=>activity.author_id,:blog_id=>activity.blog_id,:id=>activity.id,:in_act => true), :class => "postGrey" %> +
      + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
      +
      + +
      + 发布时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(UserActivity.where("act_type='#{activity.class}' and act_id =#{activity.id}").first.updated_at) %> +
      +
      + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.content} %> +
      + + +
      +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
      +
      +
      +
      + <% count=activity.children.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      <%#= format_date(activity.updated_on) %>
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% activity.children.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
        +
        + <%= comment.content.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + + <% if activity.locked == false && User.current.logged?%> +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'blog_comments', :action => 'reply', :user_id=>activity.author_id,:blog_id=>activity.blog_id,:id=>activity.id},:method => "post", :remote => true) do |f|%> + + + + + + +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      + <% end %> +
      +
      + diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index c53f90273..dde4f34ce 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -1,152 +1,152 @@ -
      -
      -
      - <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> -
      -
      -
      - <%= link_to activity.user.show_name, user_path(activity.user_id), :class => "newsBlue mr15" %> - TO - <% if activity.jour %> - <%= link_to activity.jour.show_name+"("+(activity.jour.login ? activity.jour.login : activity.jour.show_name ).to_s+")的"+ (activity.private == 1? "私信":"留言"), - feedback_path(activity.jour, :host=> Setting.host_user), :class => "newsBlue ml15" %> - <% if activity.private == 1 %> - 私信 - <% end %> - <% end %> -
      - <% if is_activity.to_i == 1 %> -
      - <% if activity.parent %> - <%= link_to activity.parent.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> - <% else %> - <%= link_to activity.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> - <% end %> -
      - <% else %> - <% if activity.parent %> - <% content = activity.parent.notes %> - <% else %> - <% content = activity.notes %> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> - <% end %> -
      - 留言时间:<%= format_time(activity.created_on) %> -
      -
      - 更新时间:<%= format_time(PrincipalActivity.where("principal_act_type='#{activity.class}' and principal_act_id =#{activity.id}").first.updated_at) %> -
      -
      - <% if activity.user == User.current || User.current.admin?%> -
      -
        -
      • -
          -
        • - <%= link_to(l(:label_bid_respond_delete), - {:controller => 'words', :action => 'destroy', :object_id => activity, :user_id => activity.user,:user_activity_id => user_activity_id,:is_activity=>is_activity}, - :confirm => l(:text_are_you_sure), :method => 'delete', - :class => "postOptionLink", :title => l(:button_delete)) %> -
        • -
        -
      • -
      -
      - <% end%> -
      -
      -
      - <% count=fetch_user_leaveWord_reply(activity).count %> -
      -
      -
      回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
      -
      - <%if count>3 %> - - <% end %> -
      - - <% replies_all_i = 0 %> - <% if count > 0 %> -
      -
        - <% fetch_user_leaveWord_reply(activity).reorder("created_on desc").each do |comment| %> - <% replies_all_i = replies_all_i + 1 %> -
      • -
        - <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> -
        -
        -
        - <% if comment.try(:user).try(:realname) == ' ' %> - <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - - -
        -
        - <%= comment.notes.html_safe %> -
        -
        -
        -
      • - <% end %> -
      -
      - <% end %> - -
      -
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
      -
      -
      - <%= form_for('new_form',:url => {:controller => 'words', :action => 'create_reply', :id => activity.id},:method => "post", :remote => true) do |f|%> - <%= hidden_field_tag 'reference_id', params[:reference_id], :value => activity.id %> - <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => activity.user.id %> - <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => activity.id %> - <%= hidden_field_tag 'show_name',params[:show_name],:value =>true %> - <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> - <%= hidden_field_tag 'is_activity',params[:is_activity],:value =>is_activity %> -
      - - -
      -

      - <% end%> -
      -
      -
      -
      -
      -
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> +
      +
      +
      + <%= link_to activity.user.show_name, user_path(activity.user_id), :class => "newsBlue mr15" %> + TO + <% if activity.jour %> + <%= link_to activity.jour.show_name+"("+(activity.jour.login ? activity.jour.login : activity.jour.show_name ).to_s+")的"+ (activity.private == 1? "私信":"留言"), + feedback_path(activity.jour, :host=> Setting.host_user), :class => "newsBlue ml15" %> + <% if activity.private == 1 %> + 私信 + <% end %> + <% end %> +
      + <% if is_activity.to_i == 1 %> +
      + <% if activity.parent %> + <%= link_to activity.parent.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> + <% else %> + <%= link_to activity.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> + <% end %> +
      + <% else %> + <% if activity.parent %> + <% content = activity.parent.notes %> + <% else %> + <% content = activity.notes %> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> + <% end %> +
      + 留言时间:<%= format_time(activity.created_on) %> +
      +
      + 更新时间:<%= format_time(PrincipalActivity.where("principal_act_type='#{activity.class}' and principal_act_id =#{activity.id}").first.updated_at) %> +
      +
      + <% if activity.user == User.current || User.current.admin?%> +
      +
        +
      • +
          +
        • + <%= link_to(l(:label_bid_respond_delete), + {:controller => 'words', :action => 'destroy', :object_id => activity, :user_id => activity.user,:user_activity_id => user_activity_id,:is_activity=>is_activity}, + :confirm => l(:text_are_you_sure), :method => 'delete', + :class => "postOptionLink", :title => l(:button_delete)) %> +
        • +
        +
      • +
      +
      + <% end%> +
      +
      +
      + <% count=fetch_user_leaveWord_reply(activity).count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
      +
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% fetch_user_leaveWord_reply(activity).reorder("created_on desc").each do |comment| %> + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + + +
        +
        + <%= comment.notes.html_safe %> +
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'words', :action => 'create_reply', :id => activity.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'reference_id', params[:reference_id], :value => activity.id %> + <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => activity.user.id %> + <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => activity.id %> + <%= hidden_field_tag 'show_name',params[:show_name],:value =>true %> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> + <%= hidden_field_tag 'is_activity',params[:is_activity],:value =>is_activity %> +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index bb9fc1174..62568d505 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -1,692 +1,692 @@ -<% if ma.class == CourseMessage %> - <% if ma.course_message_type == "News" %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.author), :width => "30", :height => "30"),user_path(ma.course_message.author) %>
      • -
      • <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher" %>">发布了通知:
      • -
      • - <%= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %>
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - <% if ma.course_message_type == "Comment" %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.author), :width => "30", :height => "30"), user_path(ma.course_message.author) %>
      • -
      • <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher" %>">评论了通知:
      • -
      • - <%= link_to ma.course_message.commented.title, {:controller => 'news', :action => 'show', :id => ma.course_message.commented.id }, - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %>
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - <% if ma.course_message_type == "HomeworkCommon" && ma.status.nil?%> - - <% end %> - <% if ma.course_message_type == "HomeworkCommon" && ma.status == 1 %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • -
      • <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + '老师', - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :title => "#{ma.course_message.user.lastname + ma.course_message.user.firstname}老师" %> - ">发布的作业:
      • -
      • - <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), - :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover => "message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> -
      • - -
      •    截止时间快到啦
      • -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - - <% if ma.course_message_type == "HomeworkCommon" && ma.status == 2 %> -
        -
      • - <%= link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> -
      • -
      • - <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> - ">启动了作业匿评: -
      • -
      • - <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover => "message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> -
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - - <% if ma.course_message_type == "HomeworkCommon" && ma.status == 3 %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • -
      • - <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">关闭了作业匿评:
      • -
      • - <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))"%> -
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - - <% if ma.course_message_type == "HomeworkCommon" && ma.status == 4 %> -
        -
      • - <%= link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> -
      • -
      • - <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> - ">启动作业匿评失败 -
      • -
      • - <%= link_to truncate(ma.course_message.name,:length=>25)+'(失败原因:提交作品的人数低于2人)', student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "c_red" : "newsGrey "}", - :onmouseover => "message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> -
      • - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - - <% if ma.course_message_type == "Poll" %> - - <% end %> - <% if ma.course_message_type == "Message" %> - - <% end %> - <% if ma.course_message_type == "StudentWorksScore" %> -
        -
      • - <% if ma.course_message.reviewer_role == 3 %> - <%=link_to image_tag(url_to_avatar(""), :width => "30", :height => "30") %> - <% else %> - <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> - <% end %> -
      • -
      • - <% if ma.course_message.reviewer_role == 3 %> - 匿名用户 - <% else %> - <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> - <% end %> - "> - <%= ma.status == 0 ? "评阅了您的作品:" : "重新评阅了您的作品:" %> - -
      • -
      • - <% unless ma.content.nil? %> - <%= link_to ma.content.html_safe, student_work_index_path(:homework => ma.course_message.student_work.homework_common_id), - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %>
      • - - <% end %> -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - <% if ma.course_message_type == "JournalsForMessage" %> - <% if ma.course_message.jour_type == 'Course' %> - <% if params[:type] != 'homework' %> - - <% end %> - <% else %> - - <% end %> - <% end %> - - <% if ma.course_message_type == "StudentWork" && !ma.course_message.homework_common.nil? %> - - <% end %> - - <% if ma.course_message_type == "Course" %> - - <% end %> - <% if ma.course_message_type == "JoinCourseRequest" %> - - <% end %> - <% if ma.course_message_type == "CourseRequestDealResult" %> - - <% end %> - - - <% if ma.course_message_type == "JoinCourse" and ma.status == 0 %> - - <% end %> - - - <% if ma.course_message_type == "JoinCourse" and ma.status == 1 %> - - <% end %> - - - <% if ma.course_message_type == "RemoveFromCourse" %> - - <% end %> - - - <% if ma.course_message_type == "Exercise" && ma.status == 2 %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • -
      • - <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">发布了课程测验 :
      • -
      • - <%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))"%> -
      • - - -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> - - - <% if ma.course_message_type == "Exercise" && ma.status == 3 %> -
        -
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • -
      • - <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", - user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">发布的测验:
      • -
      • - <%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))"%> - -
      • - - -
      • 截止时间快到啦
      • -
      • <%= time_tag(ma.created_at).html_safe %>
      • -
      - <% end %> +<% if ma.class == CourseMessage %> + <% if ma.course_message_type == "News" %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.author), :width => "30", :height => "30"),user_path(ma.course_message.author) %>
      • +
      • <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher" %>">发布了通知:
      • +
      • + <%= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %>
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + <% if ma.course_message_type == "Comment" %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.author), :width => "30", :height => "30"), user_path(ma.course_message.author) %>
      • +
      • <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher" %>">评论了通知:
      • +
      • + <%= link_to ma.course_message.commented.title, {:controller => 'news', :action => 'show', :id => ma.course_message.commented.id }, + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %>
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + <% if ma.course_message_type == "HomeworkCommon" && ma.status.nil?%> + + <% end %> + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 1 %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • +
      • <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + '老师', + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :title => "#{ma.course_message.user.lastname + ma.course_message.user.firstname}老师" %> + ">发布的作业:
      • +
      • + <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), + :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover => "message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> +
      • + +
      •    截止时间快到啦
      • +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 2 %> +
        +
      • + <%= link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> +
      • +
      • + <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> + ">启动了作业匿评: +
      • +
      • + <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover => "message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> +
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 3 %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • +
      • + <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">关闭了作业匿评:
      • +
      • + <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))"%> +
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 4 %> +
        +
      • + <%= link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> +
      • +
      • + <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> + ">启动作业匿评失败 +
      • +
      • + <%= link_to truncate(ma.course_message.name,:length=>25)+'(失败原因:提交作品的人数低于2人)', student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "c_red" : "newsGrey "}", + :onmouseover => "message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> +
      • + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + + <% if ma.course_message_type == "Poll" %> + + <% end %> + <% if ma.course_message_type == "Message" %> + + <% end %> + <% if ma.course_message_type == "StudentWorksScore" %> +
        +
      • + <% if ma.course_message.reviewer_role == 3 %> + <%=link_to image_tag(url_to_avatar(""), :width => "30", :height => "30") %> + <% else %> + <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %> + <% end %> +
      • +
      • + <% if ma.course_message.reviewer_role == 3 %> + 匿名用户 + <% else %> + <%= link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> + <% end %> + "> + <%= ma.status == 0 ? "评阅了您的作品:" : "重新评阅了您的作品:" %> + +
      • +
      • + <% unless ma.content.nil? %> + <%= link_to ma.content.html_safe, student_work_index_path(:homework => ma.course_message.student_work.homework_common_id), + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %>
      • + + <% end %> +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + <% if ma.course_message_type == "JournalsForMessage" %> + <% if ma.course_message.jour_type == 'Course' %> + <% if params[:type] != 'homework' %> + + <% end %> + <% else %> + + <% end %> + <% end %> + + <% if ma.course_message_type == "StudentWork" && !ma.course_message.homework_common.nil? %> + + <% end %> + + <% if ma.course_message_type == "Course" %> + + <% end %> + <% if ma.course_message_type == "JoinCourseRequest" %> + + <% end %> + <% if ma.course_message_type == "CourseRequestDealResult" %> + + <% end %> + + + <% if ma.course_message_type == "JoinCourse" and ma.status == 0 %> + + <% end %> + + + <% if ma.course_message_type == "JoinCourse" and ma.status == 1 %> + + <% end %> + + + <% if ma.course_message_type == "RemoveFromCourse" %> + + <% end %> + + + <% if ma.course_message_type == "Exercise" && ma.status == 2 %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • +
      • + <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">发布了课程测验 :
      • +
      • + <%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))"%> +
      • + + +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> + + + <% if ma.course_message_type == "Exercise" && ma.status == 3 %> +
        +
      • <%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
      • +
      • + <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师", + user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">发布的测验:
      • +
      • + <%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))"%> + +
      • + + +
      • 截止时间快到啦
      • +
      • <%= time_tag(ma.created_at).html_safe %>
      • +
      + <% end %> <% end %> \ No newline at end of file diff --git a/db/migrate/20160309024051_update_homework_common_updated_at.rb b/db/migrate/20160309024051_update_homework_common_updated_at.rb index 89a0e992d..37accdc6e 100644 --- a/db/migrate/20160309024051_update_homework_common_updated_at.rb +++ b/db/migrate/20160309024051_update_homework_common_updated_at.rb @@ -1,18 +1,18 @@ -class UpdateHomeworkCommonUpdatedAt < ActiveRecord::Migration - def up - count = HomeworkCommon.all.count / 30 + 2 - transaction do - for i in 1 ... count do i - HomeworkCommon.page(i).per(30).each do |hw| - ca = CourseActivity.where("course_act_type = 'HomeworkCommon' and course_act_id = #{hw.id}").first - unless ca.nil? - hw.update_attributes(:updated_at => ca.updated_at) - end - end - end - end - end - - def down - end -end +class UpdateHomeworkCommonUpdatedAt < ActiveRecord::Migration + def up + count = HomeworkCommon.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + HomeworkCommon.page(i).per(30).each do |hw| + ca = CourseActivity.where("course_act_type = 'HomeworkCommon' and course_act_id = #{hw.id}").first + unless ca.nil? + hw.update_attributes(:updated_at => ca.updated_at) + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20160309072649_update_contributor_after_delete.rb b/db/migrate/20160309072649_update_contributor_after_delete.rb index 33d89b113..01f91105a 100644 --- a/db/migrate/20160309072649_update_contributor_after_delete.rb +++ b/db/migrate/20160309072649_update_contributor_after_delete.rb @@ -1,50 +1,50 @@ -class UpdateContributorAfterDelete < ActiveRecord::Migration - def up - Course.all.each do |course| - if course.course_activities.count > 1 - course.members.each do |s| - puts course.id - puts course.name - puts s.user_id - # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 - # 发帖数 - board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count - # 回帖数 - message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is not null").count * 1 - # 新闻回复 - common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 - # 通知 - common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1 - # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 - # 附件数 - attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count - # 课程留言数 - journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1 - # 作业留言 - journal_homework_count = JournalsForMessage.find_by_sql("SELECT jfm.* FROM `journals_for_messages` jfm, homework_commons hc where hc.id = jfm.jour_id and hc.course_id =#{course.id} and jfm.user_id =#{s.user_id} and jfm.jour_type ='HomeworkCommon';").count * 1 - # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1 - # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1 - total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count - course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first - if course_contributor.nil? - CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count, - :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, - :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) - else - course_contributor.message_num = board_count - course_contributor.message_reply_num = message_reply_count - course_contributor.news_reply_num = common_reply_count - course_contributor.news_num = common_count - course_contributor.resource_num = attachment_count - course_contributor.journal_num = journal_count - course_contributor.homework_journal_num = journal_homework_count - course_contributor.save - end - end - end - end - end - - def down - end -end +class UpdateContributorAfterDelete < ActiveRecord::Migration + def up + Course.all.each do |course| + if course.course_activities.count > 1 + course.members.each do |s| + puts course.id + puts course.name + puts s.user_id + # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 + # 发帖数 + board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count + # 回帖数 + message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is not null").count * 1 + # 新闻回复 + common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 + # 通知 + common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1 + # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 + # 附件数 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count + # 课程留言数 + journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1 + # 作业留言 + journal_homework_count = JournalsForMessage.find_by_sql("SELECT jfm.* FROM `journals_for_messages` jfm, homework_commons hc where hc.id = jfm.jour_id and hc.course_id =#{course.id} and jfm.user_id =#{s.user_id} and jfm.jour_type ='HomeworkCommon';").count * 1 + # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1 + # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1 + total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count + course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first + if course_contributor.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count, + :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, + :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) + else + course_contributor.message_num = board_count + course_contributor.message_reply_num = message_reply_count + course_contributor.news_reply_num = common_reply_count + course_contributor.news_num = common_count + course_contributor.resource_num = attachment_count + course_contributor.journal_num = journal_count + course_contributor.homework_journal_num = journal_homework_count + course_contributor.save + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20160310033019_delete_student_work_data.rb b/db/migrate/20160310033019_delete_student_work_data.rb index a7ce60953..9cb952064 100644 --- a/db/migrate/20160310033019_delete_student_work_data.rb +++ b/db/migrate/20160310033019_delete_student_work_data.rb @@ -1,8 +1,8 @@ -class DeleteStudentWorkData < ActiveRecord::Migration - def up - StudentWork.where("homework_common_id = 2604 AND user_id = 10763 AND final_score = 0").destroy_all - end - - def down - end -end +class DeleteStudentWorkData < ActiveRecord::Migration + def up + StudentWork.where("homework_common_id = 2604 AND user_id = 10763 AND final_score = 0").destroy_all + end + + def down + end +end diff --git a/lib/trustie/gitlab/helper.rb b/lib/trustie/gitlab/helper.rb index 54bc4620e..c9cbcee26 100644 --- a/lib/trustie/gitlab/helper.rb +++ b/lib/trustie/gitlab/helper.rb @@ -1,78 +1,78 @@ -#coding=utf-8 - -module Trustie - module Gitlab - module Helper - GUEST = 10 - REPORTER = 20 - DEVELOPER = 30 - MASTER = 40 - OWNER = 50 - # 项目公开和私有 - PUBLIC = 20 - PRIVATE = 0 - - def change_password(uid, en_pwd, salt) - return unless uid - options = {:encrypted_password=>en_pwd, :password_salt=>salt} - self.g.put("/users/ext/#{uid}", :body => options) - # g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt) - end - - def find_user(user) - us = self.g.get("/users?search=#{user.mail}") - if Array === us - us.each do |u| - return u if u.email == user.mail - end - end - return nil - end - - def add_user(user) - u = nil - begin - u = find_user(user) - unless u - u = self.g.create_user(user.mail, - user.hashed_password, - name: user.show_name, - username: user.login, - confirm: "true") - user.gid = u.id - user.save - end - if user.gid.nil? - user.gid = u.id - user.save - end - change_password(u.id, user.hashed_password, user.salt) - rescue => e - puts e - end - return u - end - - def del_user(user) - return unless user.gid - self.g.delete_user(user.gid) - end - - def get_gitlab_role m - case m.roles.first.position - when 1,2 - GUEST - when 5 - REPORTER - when 4 - DEVELOPER - when 3 - MASTER - else - GUEST - end - end - - end - end +#coding=utf-8 + +module Trustie + module Gitlab + module Helper + GUEST = 10 + REPORTER = 20 + DEVELOPER = 30 + MASTER = 40 + OWNER = 50 + # 项目公开和私有 + PUBLIC = 20 + PRIVATE = 0 + + def change_password(uid, en_pwd, salt) + return unless uid + options = {:encrypted_password=>en_pwd, :password_salt=>salt} + self.g.put("/users/ext/#{uid}", :body => options) + # g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt) + end + + def find_user(user) + us = self.g.get("/users?search=#{user.mail}") + if Array === us + us.each do |u| + return u if u.email == user.mail + end + end + return nil + end + + def add_user(user) + u = nil + begin + u = find_user(user) + unless u + u = self.g.create_user(user.mail, + user.hashed_password, + name: user.show_name, + username: user.login, + confirm: "true") + user.gid = u.id + user.save + end + if user.gid.nil? + user.gid = u.id + user.save + end + change_password(u.id, user.hashed_password, user.salt) + rescue => e + puts e + end + return u + end + + def del_user(user) + return unless user.gid + self.g.delete_user(user.gid) + end + + def get_gitlab_role m + case m.roles.first.position + when 1,2 + GUEST + when 5 + REPORTER + when 4 + DEVELOPER + when 3 + MASTER + else + GUEST + end + end + + end + end end \ No newline at end of file diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index bb52ee067..3a0150e18 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -1,6115 +1,6115 @@ -//function dump_obj(myObject) { -// var s = ""; -// for (var property in myObject) { -// s = s + "\n "+property +": " + myObject[property] ; -// } -// alert(s); -//} -/******************************************************************************* -* KindEditor - WYSIWYG HTML Editor for Internet -* Copyright (C) 2006-2013 kindsoft.net -* -* @author Roddy -* @website http://www.kindsoft.net/ -* @licence http://www.kindsoft.net/license.php -* @version 4.1.10 (2013-11-23) -*******************************************************************************/ -(function (window, undefined) { - if (window.KindEditor) { - return; - } -if (!window.console) { - window.console = {}; -} -if (!console.log) { - console.log = function () {}; -} -var _VERSION = '4.1.10 (2013-11-23)', - _ua = navigator.userAgent.toLowerCase(), - _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1, - _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1, - _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1, - _WEBKIT = _ua.indexOf('applewebkit') > -1, - _OPERA = _ua.indexOf('opera') > -1, - _MOBILE = _ua.indexOf('mobile') > -1, - _IOS = /ipad|iphone|ipod/.test(_ua), - _QUIRKS = document.compatMode != 'CSS1Compat', - _IERANGE = !window.getSelection, - _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua), - _V = _matches ? _matches[1] : '0', - _TIME = new Date().getTime(); -function _isArray(val) { - if (!val) { - return false; - } - return Object.prototype.toString.call(val) === '[object Array]'; -} -function _isFunction(val) { - if (!val) { - return false; - } - return Object.prototype.toString.call(val) === '[object Function]'; -} -function _inArray(val, arr) { - for (var i = 0, len = arr.length; i < len; i++) { - if (val === arr[i]) { - return i; - } - } - return -1; -} -function _each(obj, fn) { - if (_isArray(obj)) { - for (var i = 0, len = obj.length; i < len; i++) { - if (fn.call(obj[i], i, obj[i]) === false) { - break; - } - } - } else { - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - if (fn.call(obj[key], key, obj[key]) === false) { - break; - } - } - } - } -} -function _trim(str) { - return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, ''); -} -function _inString(val, str, delimiter) { - delimiter = delimiter === undefined ? ',' : delimiter; - return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0; -} -function _addUnit(val, unit) { - unit = unit || 'px'; - return val && /^\d+$/.test(val) ? val + unit : val; -} -function _removeUnit(val) { - var match; - return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0; -} -function _escape(val) { - return val.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); -} -function _unescape(val) { - return val.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&'); -} -function _toCamel(str) { - var arr = str.split('-'); - str = ''; - _each(arr, function(key, val) { - str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val; - }); - return str; -} -function _toHex(val) { - function hex(d) { - var s = parseInt(d, 10).toString(16).toUpperCase(); - return s.length > 1 ? s : '0' + s; - } - return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig, - function($0, $1, $2, $3) { - return '#' + hex($1) + hex($2) + hex($3); - } - ); -} -function _toMap(val, delimiter) { - delimiter = delimiter === undefined ? ',' : delimiter; - var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match; - _each(arr, function(key, val) { - if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) { - for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) { - map[i.toString()] = true; - } - } else { - map[val] = true; - } - }); - return map; -} -function _toArray(obj, offset) { - return Array.prototype.slice.call(obj, offset || 0); -} -function _undef(val, defaultVal) { - return val === undefined ? defaultVal : val; -} -function _invalidUrl(url) { - return !url || /[<>"]/.test(url); -} -function _addParam(url, param) { - return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param; -} -function _extend(child, parent, proto) { - if (!proto) { - proto = parent; - parent = null; - } - var childProto; - if (parent) { - var fn = function () {}; - fn.prototype = parent.prototype; - childProto = new fn(); - _each(proto, function(key, val) { - childProto[key] = val; - }); - } else { - childProto = proto; - } - childProto.constructor = child; - child.prototype = childProto; - child.parent = parent ? parent.prototype : null; -} -function _json(text) { - var match; - if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) { - text = match[0]; - } - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; - cx.lastIndex = 0; - if (cx.test(text)) { - text = text.replace(cx, function (a) { - return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); - }); - } - if (/^[\],:{}\s]*$/. - test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). - replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). - replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { - return eval('(' + text + ')'); - } - throw 'JSON parse error'; -} -var _round = Math.round; -var K = { - DEBUG : false, - VERSION : _VERSION, - IE : _IE, - GECKO : _GECKO, - WEBKIT : _WEBKIT, - OPERA : _OPERA, - V : _V, - TIME : _TIME, - each : _each, - isArray : _isArray, - isFunction : _isFunction, - inArray : _inArray, - inString : _inString, - trim : _trim, - addUnit : _addUnit, - removeUnit : _removeUnit, - escape : _escape, - unescape : _unescape, - toCamel : _toCamel, - toHex : _toHex, - toMap : _toMap, - toArray : _toArray, - undef : _undef, - invalidUrl : _invalidUrl, - addParam : _addParam, - extend : _extend, - json : _json -}; -var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'), - _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'), - _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'), - _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'), - _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'), - _PRE_TAG_MAP = _toMap('pre,style,script'), - _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'), - _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'), - _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'), - _VALUE_TAG_MAP = _toMap('input,button,textarea,select'); -// Begining of modification by Macrow -function _getBasePath() { - var refPath = '/assets/kindeditor/'; - var els = document.getElementsByTagName('script'), src; - for (var i = 0, len = els.length; i < len; i++) { - src = els[i].src || ''; - if (/(kindeditor|application)[\w\-\.]*\.js/.test(src)) { - return src.substring(0, src.indexOf('assets')) + refPath; - } - } - return refPath; -} -// End of modification by Macrow -K.basePath = _getBasePath(); -K.options = { - designMode : true, - fullscreenMode : false, - filterMode : true, - wellFormatMode : true, - shadowMode : true, - loadStyleMode : true, - basePath : K.basePath, - emotionsBasePath: 'http://forge.trustie.net', //TODO - themesPath : K.basePath + 'themes/', - langPath : K.basePath + 'lang/', - pluginsPath : K.basePath + 'plugins/', - themeType : 'default', - langType : 'zh_CN', - urlType : '', - newlineTag : 'p', - resizeType : 2, - syncType : 'form', - pasteType : 2, - dialogAlignType : 'page', - useContextmenu : true, - fullscreenShortcut : false, - bodyClass : 'ke-content', - indentChar : '\t', - cssPath : K.basePath +'plugins/code/previewcode.css', - cssData : 'font{color:black;}', - minWidth : 650, - minHeight : 100, - minChangeSize : 1, - zIndex : 811213, - items : ['code','emoticons','fontname', - 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', - 'formatblock', 'fontsize', '|','indent', 'outdent', - '|','imagedirectupload','table', 'media', 'preview',"more" - ], - noDisableItems : ['source', 'fullscreen'], - colorTable : [ - ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], - ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], - ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], - ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] - ], - fontSizeTable : ['选中的字体大小:','9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'], - htmlTags : { - font : ['id', 'class', 'color', 'size', 'face', '.background-color'], - span : [ - 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background', - '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height', 'data-user-id' - ], - div : [ - 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color', - '.background-color', '.font-size', '.font-family', '.font-weight', '.background', - '.font-style', '.text-decoration', '.vertical-align', '.margin-left' - ], - table: [ - 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor', - '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color', - '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background', - '.width', '.height', '.border-collapse' - ], - 'td,th': [ - 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', - '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight', - '.font-style', '.text-decoration', '.vertical-align', '.background', '.border' - ], - a : ['id', 'class', 'href', 'target', 'name'], - embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'], - img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'], - 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ - 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', - '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' - ], - pre : ['id', 'class'], - hr : ['id', 'class', '.page-break-after'], - 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'], - iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height'] - }, - layout : '
      ' -}; -var _useCapture = false; -var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222'); -var _CURSORMOVE_KEY_MAP = _toMap('33..40'); -var _CHANGE_KEY_MAP = {}; -_each(_INPUT_KEY_MAP, function(key, val) { - _CHANGE_KEY_MAP[key] = val; -}); -_each(_CURSORMOVE_KEY_MAP, function(key, val) { - _CHANGE_KEY_MAP[key] = val; -}); -function _bindEvent(el, type, fn) { - if (el.addEventListener){ - el.addEventListener(type, fn, _useCapture); - } else if (el.attachEvent){ - el.attachEvent('on' + type, fn); - } -} -function _unbindEvent(el, type, fn) { - if (el.removeEventListener){ - el.removeEventListener(type, fn, _useCapture); - } else if (el.detachEvent){ - el.detachEvent('on' + type, fn); - } -} -var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' + - 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' + - 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(','); -function KEvent(el, event) { - this.init(el, event); -} -_extend(KEvent, { - init : function(el, event) { - var self = this, doc = el.ownerDocument || el.document || el; - self.event = event; - _each(_EVENT_PROPS, function(key, val) { - self[val] = event[val]; - }); - if (!self.target) { - self.target = self.srcElement || doc; - } - if (self.target.nodeType === 3) { - self.target = self.target.parentNode; - } - if (!self.relatedTarget && self.fromElement) { - self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement; - } - if (self.pageX == null && self.clientX != null) { - var d = doc.documentElement, body = doc.body; - self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0); - self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0); - } - if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) { - self.which = self.charCode || self.keyCode; - } - if (!self.metaKey && self.ctrlKey) { - self.metaKey = self.ctrlKey; - } - if (!self.which && self.button !== undefined) { - self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0))); - } - switch (self.which) { - case 186 : - self.which = 59; - break; - case 187 : - case 107 : - case 43 : - self.which = 61; - break; - case 189 : - case 45 : - self.which = 109; - break; - case 42 : - self.which = 106; - break; - case 47 : - self.which = 111; - break; - case 78 : - self.which = 110; - break; - } - if (self.which >= 96 && self.which <= 105) { - self.which -= 48; - } - }, - preventDefault : function() { - var ev = this.event; - if (ev.preventDefault) { - ev.preventDefault(); - } else { - ev.returnValue = false; - } - }, - stopPropagation : function() { - var ev = this.event; - if (ev.stopPropagation) { - ev.stopPropagation(); - } else { - ev.cancelBubble = true; - } - }, - stop : function() { - this.preventDefault(); - this.stopPropagation(); - } -}); -var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {}; -function _getId(el) { - return el[_eventExpendo] || null; -} -function _setId(el) { - el[_eventExpendo] = ++_eventId; - return _eventId; -} -function _removeId(el) { - try { - delete el[_eventExpendo]; - } catch(e) { - if (el.removeAttribute) { - el.removeAttribute(_eventExpendo); - } - } -} -function _bind(el, type, fn) { - if (type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _bind(el, this, fn); - }); - return; - } - var id = _getId(el); - if (!id) { - id = _setId(el); - } - if (_eventData[id] === undefined) { - _eventData[id] = {}; - } - var events = _eventData[id][type]; - if (events && events.length > 0) { - _unbindEvent(el, type, events[0]); - } else { - _eventData[id][type] = []; - _eventData[id].el = el; - } - events = _eventData[id][type]; - if (events.length === 0) { - events[0] = function(e) { - var kevent = e ? new KEvent(el, e) : undefined; - _each(events, function(i, event) { - if (i > 0 && event) { - event.call(el, kevent); - } - }); - }; - } - if (_inArray(fn, events) < 0) { - events.push(fn); - } - _bindEvent(el, type, events[0]); -} -function _unbind(el, type, fn) { - if (type && type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _unbind(el, this, fn); - }); - return; - } - var id = _getId(el); - if (!id) { - return; - } - if (type === undefined) { - if (id in _eventData) { - _each(_eventData[id], function(key, events) { - if (key != 'el' && events.length > 0) { - _unbindEvent(el, key, events[0]); - } - }); - delete _eventData[id]; - _removeId(el); - } - return; - } - if (!_eventData[id]) { - return; - } - var events = _eventData[id][type]; - if (events && events.length > 0) { - if (fn === undefined) { - _unbindEvent(el, type, events[0]); - delete _eventData[id][type]; - } else { - _each(events, function(i, event) { - if (i > 0 && event === fn) { - events.splice(i, 1); - } - }); - if (events.length == 1) { - _unbindEvent(el, type, events[0]); - delete _eventData[id][type]; - } - } - var count = 0; - _each(_eventData[id], function() { - count++; - }); - if (count < 2) { - delete _eventData[id]; - _removeId(el); - } - } -} -function _fire(el, type) { - if (type.indexOf(',') >= 0) { - _each(type.split(','), function() { - _fire(el, this); - }); - return; - } - var id = _getId(el); - if (!id) { - return; - } - var events = _eventData[id][type]; - if (_eventData[id] && events && events.length > 0) { - events[0](); - } -} -function _ctrl(el, key, fn) { - var self = this; - key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0); - _bind(el, 'keydown', function(e) { - if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) { - fn.call(el); - e.stop(); - } - }); -} -var _readyFinished = false; -function _ready(fn) { - if (_readyFinished) { - fn(KindEditor); - return; - } - var loaded = false; - function readyFunc() { - if (!loaded) { - loaded = true; - fn(KindEditor); - _readyFinished = true; - } - } - function ieReadyFunc() { - if (!loaded) { - try { - document.documentElement.doScroll('left'); - } catch(e) { - setTimeout(ieReadyFunc, 100); - return; - } - readyFunc(); - } - } - function ieReadyStateFunc() { - if (document.readyState === 'complete') { - readyFunc(); - } - } - if (document.addEventListener) { - _bind(document, 'DOMContentLoaded', readyFunc); - } else if (document.attachEvent) { - _bind(document, 'readystatechange', ieReadyStateFunc); - var toplevel = false; - try { - toplevel = window.frameElement == null; - } catch(e) {} - if (document.documentElement.doScroll && toplevel) { - ieReadyFunc(); - } - } - _bind(window, 'load', readyFunc); -} -if (_IE) { - window.attachEvent('onunload', function() { - _each(_eventData, function(key, events) { - if (events.el) { - _unbind(events.el); - } - }); - }); -} -K.ctrl = _ctrl; -K.ready = _ready; -function _getCssList(css) { - var list = {}, - reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g, - match; - while ((match = reg.exec(css))) { - var key = _trim(match[1].toLowerCase()), - val = _trim(_toHex(match[2])); - list[key] = val; - } - return list; -} -function _getAttrList(tag) { - var list = {}, - reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g, - match; - while ((match = reg.exec(tag))) { - var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(), - val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || ''; - list[key] = val; - } - return list; -} -function _addClassToTag(tag, className) { - if (/\s+class\s*=/.test(tag)) { - tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) { - if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) { - return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3; - } else { - return $0; - } - }); - } else { - tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">'; - } - return tag; -} -function _formatCss(css) { - var str = ''; - _each(_getCssList(css), function(key, val) { - str += key + ':' + val + ';'; - }); - return str; -} -function _formatUrl(url, mode, host, pathname) { - mode = _undef(mode, '').toLowerCase(); - if (url.substr(0, 5) != 'data:') { - url = url.replace(/([^:])\/\//g, '$1/'); - } - if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) { - return url; - } - host = host || location.protocol + '//' + location.host; - if (pathname === undefined) { - var m = location.pathname.match(/^(\/.*)\//); - pathname = m ? m[1] : ''; - } - var match; - if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) { - if (match[1] !== host) { - return url; - } - } else if (/^\w+:/.test(url)) { - return url; - } - function getRealPath(path) { - var parts = path.split('/'), paths = []; - for (var i = 0, len = parts.length; i < len; i++) { - var part = parts[i]; - if (part == '..') { - if (paths.length > 0) { - paths.pop(); - } - } else if (part !== '' && part != '.') { - paths.push(part); - } - } - return '/' + paths.join('/'); - } - if (/^\//.test(url)) { - url = host + getRealPath(url.substr(1)); - } else if (!/^\w+:\/\//.test(url)) { - url = host + getRealPath(pathname + '/' + url); - } - function getRelativePath(path, depth) { - if (url.substr(0, path.length) === path) { - var arr = []; - for (var i = 0; i < depth; i++) { - arr.push('..'); - } - var prefix = '.'; - if (arr.length > 0) { - prefix += '/' + arr.join('/'); - } - if (pathname == '/') { - prefix += '/'; - } - return prefix + url.substr(path.length); - } else { - if ((match = /^(.*)\//.exec(path))) { - return getRelativePath(match[1], ++depth); - } - } - } - if (mode === 'relative') { - url = getRelativePath(host + pathname, 0).substr(2); - } else if (mode === 'absolute') { - if (url.substr(0, host.length) === host) { - url = url.substr(host.length); - } - } - return url; -} -function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) { - if (html == null) { - html = ''; - } - urlType = urlType || ''; - wellFormatted = _undef(wellFormatted, false); - indentChar = _undef(indentChar, '\t'); - var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(','); - html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) { - return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3; - }); - html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '

      '); - html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1
      $2'); - html = html.replace(/\u200B/g, ''); - html = html.replace(/\u00A9/g, '©'); - html = html.replace(/\u00AE/g, '®'); - html = html.replace(/<[^>]+/g, function($0) { - return $0.replace(/\s+/g, ' '); - }); - var htmlTagMap = {}; - if (htmlTags) { - _each(htmlTags, function(key, val) { - var arr = key.split(','); - for (var i = 0, len = arr.length; i < len; i++) { - htmlTagMap[arr[i]] = _toMap(val); - } - }); - if (!htmlTagMap.script) { - html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, ''); - } - if (!htmlTagMap.style) { - html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, ''); - } - } - var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g; - var tagStack = []; - html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) { - var full = $0, - startNewline = $1 || '', - startSlash = $2 || '', - tagName = $3.toLowerCase(), - attr = $4 || '', - endSlash = $5 ? ' ' + $5 : '', - endNewline = $6 || ''; - if (htmlTags && !htmlTagMap[tagName]) { - return ''; - } - if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) { - endSlash = ' /'; - } - if (_INLINE_TAG_MAP[tagName]) { - if (startNewline) { - startNewline = ' '; - } - if (endNewline) { - endNewline = ' '; - } - } - if (_PRE_TAG_MAP[tagName]) { - if (startSlash) { - endNewline = '\n'; - } else { - startNewline = '\n'; - } - } - if (wellFormatted && tagName == 'br') { - endNewline = '\n'; - } - if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) { - if (wellFormatted) { - if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) { - tagStack.pop(); - } else { - tagStack.push(tagName); - } - startNewline = '\n'; - endNewline = '\n'; - for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) { - startNewline += indentChar; - if (!startSlash) { - endNewline += indentChar; - } - } - if (endSlash) { - tagStack.pop(); - } else if (!startSlash) { - endNewline += indentChar; - } - } else { - startNewline = endNewline = ''; - } - } - if (attr !== '') { - var attrMap = _getAttrList(full); - if (tagName === 'font') { - var fontStyleMap = {}, fontStyle = ''; - _each(attrMap, function(key, val) { - if (key === 'color') { - fontStyleMap.color = val; - delete attrMap[key]; - } - if (key === 'size') { - fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || ''; - delete attrMap[key]; - } - if (key === 'face') { - fontStyleMap['font-family'] = val; - delete attrMap[key]; - } - if (key === 'style') { - fontStyle = val; - } - }); - if (fontStyle && !/;$/.test(fontStyle)) { - fontStyle += ';'; - } - _each(fontStyleMap, function(key, val) { - if (val === '') { - return; - } - if (/\s/.test(val)) { - val = "'" + val + "'"; - } - fontStyle += key + ':' + val + ';'; - }); - attrMap.style = fontStyle; - } - _each(attrMap, function(key, val) { - if (_FILL_ATTR_MAP[key]) { - attrMap[key] = key; - } - if (_inArray(key, ['src', 'href']) >= 0) { - attrMap[key] = _formatUrl(val, urlType); - } - if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] || - tagName === 'body' && key === 'contenteditable' || - /^kindeditor_\d+$/.test(key)) { - delete attrMap[key]; - } - if (key === 'style' && val !== '') { - var styleMap = _getCssList(val); - _each(styleMap, function(k, v) { - if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) { - delete styleMap[k]; - } - }); - var style = ''; - _each(styleMap, function(k, v) { - style += k + ':' + v + ';'; - }); - attrMap.style = style; - } - }); - attr = ''; - _each(attrMap, function(key, val) { - if (key === 'style' && val === '') { - return; - } - val = val.replace(/"/g, '"'); - attr += ' ' + key + '="' + val + '"'; - }); - } - if (tagName === 'font') { - tagName = 'span'; - } - return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline; - }); - html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) { - return $1 + $2.replace(/\n/g, '\n') + $3; - }); - html = html.replace(/\n\s*\n/g, '\n'); - html = html.replace(/\n/g, '\n'); - return _trim(html); -} -function _clearMsWord(html, htmlTags) { - html = html.replace(//ig, '') - .replace(//ig, '') - .replace(/]*>[\s\S]*?<\/style>/ig, '') - .replace(/]*>[\s\S]*?<\/script>/ig, '') - .replace(/]+>[\s\S]*?<\/w:[^>]+>/ig, '') - .replace(/]+>[\s\S]*?<\/o:[^>]+>/ig, '') - .replace(/[\s\S]*?<\/xml>/ig, '') - .replace(/<(?:table|td)[^>]*>/ig, function(full) { - return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1'); - }); - return _formatHtml(html, htmlTags); -} -function _mediaType(src) { - if (/\.(rm|rmvb)(\?|$)/i.test(src)) { - return 'audio/x-pn-realaudio-plugin'; - } - if (/\.(swf|flv)(\?|$)/i.test(src)) { - return 'application/x-shockwave-flash'; - } - return 'video/x-ms-asf-plugin'; -} -function _mediaClass(type) { - if (/realaudio/i.test(type)) { - return 'ke-rm'; - } - if (/flash/i.test(type)) { - return 'ke-flash'; - } - return 'ke-media'; -} -function _mediaAttrs(srcTag) { - return _getAttrList(unescape(srcTag)); -} -function _mediaEmbed(attrs) { - var html = ' 0) { - style += 'width:' + width + 'px;'; - } - if (/\D/.test(height)) { - style += 'height:' + height + ';'; - } else if (height > 0) { - style += 'height:' + height + 'px;'; - } - var html = ''; - return html; -} -function _tmpl(str, data) { - var fn = new Function("obj", - "var p=[],print=function(){p.push.apply(p,arguments);};" + - "with(obj){p.push('" + - str.replace(/[\r\t\n]/g, " ") - .split("<%").join("\t") - .replace(/((^|%>)[^\t]*)'/g, "$1\r") - .replace(/\t=(.*?)%>/g, "',$1,'") - .split("\t").join("');") - .split("%>").join("p.push('") - .split("\r").join("\\'") + "');}return p.join('');"); - return data ? fn(data) : fn; -} -K.formatUrl = _formatUrl; -K.formatHtml = _formatHtml; -K.getCssList = _getCssList; -K.getAttrList = _getAttrList; -K.mediaType = _mediaType; -K.mediaAttrs = _mediaAttrs; -K.mediaEmbed = _mediaEmbed; -K.mediaImg = _mediaImg; -K.clearMsWord = _clearMsWord; -K.tmpl = _tmpl; -function _contains(nodeA, nodeB) { - if (nodeA.nodeType == 9 && nodeB.nodeType != 9) { - return true; - } - while ((nodeB = nodeB.parentNode)) { - if (nodeB == nodeA) { - return true; - } - } - return false; -} -var _getSetAttrDiv = document.createElement('div'); -_getSetAttrDiv.setAttribute('className', 't'); -var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't'; -function _getAttr(el, key) { - key = key.toLowerCase(); - var val = null; - if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') { - var div = el.ownerDocument.createElement('div'); - div.appendChild(el.cloneNode(false)); - var list = _getAttrList(_unescape(div.innerHTML)); - if (key in list) { - val = list[key]; - } - } else { - try { - val = el.getAttribute(key, 2); - } catch(e) { - val = el.getAttribute(key, 1); - } - } - if (key === 'style' && val !== null) { - val = _formatCss(val); - } - return val; -} -function _queryAll(expr, root) { - var exprList = expr.split(','); - if (exprList.length > 1) { - var mergedResults = []; - _each(exprList, function() { - _each(_queryAll(this, root), function() { - if (_inArray(this, mergedResults) < 0) { - mergedResults.push(this); - } - }); - }); - return mergedResults; - } - root = root || document; - function escape(str) { - if (typeof str != 'string') { - return str; - } - return str.replace(/([^\w\-])/g, '\\$1'); - } - function stripslashes(str) { - return str.replace(/\\/g, ''); - } - function cmpTag(tagA, tagB) { - return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase()); - } - function byId(id, tag, root) { - var arr = [], - doc = root.ownerDocument || root, - el = doc.getElementById(stripslashes(id)); - if (el) { - if (cmpTag(tag, el.nodeName) && _contains(root, el)) { - arr.push(el); - } - } - return arr; - } - function byClass(className, tag, root) { - var doc = root.ownerDocument || root, arr = [], els, i, len, el; - if (root.getElementsByClassName) { - els = root.getElementsByClassName(stripslashes(className)); - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (cmpTag(tag, el.nodeName)) { - arr.push(el); - } - } - } else if (doc.querySelectorAll) { - els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className); - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (_contains(root, el)) { - arr.push(el); - } - } - } else { - els = root.getElementsByTagName(tag); - className = ' ' + className + ' '; - for (i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - var cls = el.className; - if (cls && (' ' + cls + ' ').indexOf(className) > -1) { - arr.push(el); - } - } - } - } - return arr; - } - function byName(name, tag, root) { - var arr = [], doc = root.ownerDocument || root, - els = doc.getElementsByName(stripslashes(name)), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (cmpTag(tag, el.nodeName) && _contains(root, el)) { - if (el.getAttribute('name') !== null) { - arr.push(el); - } - } - } - return arr; - } - function byAttr(key, val, tag, root) { - var arr = [], els = root.getElementsByTagName(tag), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - if (val === null) { - if (_getAttr(el, key) !== null) { - arr.push(el); - } - } else { - if (val === escape(_getAttr(el, key))) { - arr.push(el); - } - } - } - } - return arr; - } - function select(expr, root) { - var arr = [], matches; - matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr); - var tag = matches ? matches[1] : '*'; - if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) { - arr = byId(matches[1], tag, root); - } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) { - arr = byClass(matches[1], tag, root); - } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) { - arr = byAttr(matches[1].toLowerCase(), null, tag, root); - } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) { - var key = matches[1].toLowerCase(), val = matches[2]; - if (key === 'id') { - arr = byId(val, tag, root); - } else if (key === 'class') { - arr = byClass(val, tag, root); - } else if (key === 'name') { - arr = byName(val, tag, root); - } else { - arr = byAttr(key, val, tag, root); - } - } else { - var els = root.getElementsByTagName(tag), el; - for (var i = 0, len = els.length; i < len; i++) { - el = els[i]; - if (el.nodeType == 1) { - arr.push(el); - } - } - } - return arr; - } - var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g; - while ((arr = re.exec(expr))) { - if (arr[1] !== ' ') { - parts.push(arr[1]); - } - } - var results = []; - if (parts.length == 1) { - return select(parts[0], root); - } - var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l; - for (i = 0, lenth = parts.length; i < lenth; i++) { - part = parts[i]; - if (part === '>') { - isChild = true; - continue; - } - if (i > 0) { - els = []; - for (j = 0, len = results.length; j < len; j++) { - val = results[j]; - subResults = select(part, val); - for (k = 0, l = subResults.length; k < l; k++) { - v = subResults[k]; - if (isChild) { - if (val === v.parentNode) { - els.push(v); - } - } else { - els.push(v); - } - } - } - results = els; - } else { - results = select(part, root); - } - if (results.length === 0) { - return []; - } - } - return results; -} -function _query(expr, root) { - var arr = _queryAll(expr, root); - return arr.length > 0 ? arr[0] : null; -} -K.query = _query; -K.queryAll = _queryAll; -function _get(val) { - return K(val)[0]; -} -function _getDoc(node) { - if (!node) { - return document; - } - return node.ownerDocument || node.document || node; -} -function _getWin(node) { - if (!node) { - return window; - } - var doc = _getDoc(node); - return doc.parentWindow || doc.defaultView; -} -function _setHtml(el, html) { - if (el.nodeType != 1) { - return; - } - var doc = _getDoc(el); - try { - el.innerHTML = '' + html; - var temp = doc.getElementById('__kindeditor_temp_tag__'); - temp.parentNode.removeChild(temp); - } catch(e) { - K(el).empty(); - K('@' + html, doc).each(function() { - el.appendChild(this); - }); - } -} -function _hasClass(el, cls) { - return _inString(cls, el.className, ' '); -} -function _setAttr(el, key, val) { - if (_IE && _V < 8 && key.toLowerCase() == 'class') { - key = 'className'; - } - el.setAttribute(key, '' + val); -} -function _removeAttr(el, key) { - if (_IE && _V < 8 && key.toLowerCase() == 'class') { - key = 'className'; - } - _setAttr(el, key, ''); - el.removeAttribute(key); -} -function _getNodeName(node) { - if (!node || !node.nodeName) { - return ''; - } - return node.nodeName.toLowerCase(); -} -function _computedCss(el, key) { - var self = this, win = _getWin(el), camelKey = _toCamel(key), val = ''; - if (win.getComputedStyle) { - var style = win.getComputedStyle(el, null); - val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey]; - } else if (el.currentStyle) { - val = el.currentStyle[camelKey] || el.style[camelKey]; - } - return val; -} -function _hasVal(node) { - return !!_VALUE_TAG_MAP[_getNodeName(node)]; -} -function _docElement(doc) { - doc = doc || document; - return _QUIRKS ? doc.body : doc.documentElement; -} -function _docHeight(doc) { - var el = _docElement(doc); - return Math.max(el.scrollHeight, el.clientHeight); -} -function _docWidth(doc) { - var el = _docElement(doc); - return Math.max(el.scrollWidth, el.clientWidth); -} -function _getScrollPos(doc) { - doc = doc || document; - var x, y; - if (_IE || _NEWIE || _OPERA) { - x = _docElement(doc).scrollLeft; - y = _docElement(doc).scrollTop; - } else { - x = _getWin(doc).scrollX; - y = _getWin(doc).scrollY; - } - return {x : x, y : y}; -} -function KNode(node) { - this.init(node); -} -_extend(KNode, { - init : function(node) { - var self = this; - node = _isArray(node) ? node : [node]; - var length = 0; - for (var i = 0, len = node.length; i < len; i++) { - if (node[i]) { - self[i] = node[i].constructor === KNode ? node[i][0] : node[i]; - length++; - } - } - self.length = length; - self.doc = _getDoc(self[0]); - self.name = _getNodeName(self[0]); - self.type = self.length > 0 ? self[0].nodeType : null; - self.win = _getWin(self[0]); - }, - each : function(fn) { - var self = this; - for (var i = 0; i < self.length; i++) { - if (fn.call(self[i], i, self[i]) === false) { - return self; - } - } - return self; - }, - bind : function(type, fn) { - this.each(function() { - _bind(this, type, fn); - }); - return this; - }, - unbind : function(type, fn) { - this.each(function() { - _unbind(this, type, fn); - }); - return this; - }, - fire : function(type) { - if (this.length < 1) { - return this; - } - _fire(this[0], type); - return this; - }, - hasAttr : function(key) { - if (this.length < 1) { - return false; - } - return !!_getAttr(this[0], key); - }, - attr : function(key, val) { - var self = this; - if (key === undefined) { - return _getAttrList(self.outer()); - } - if (typeof key === 'object') { - _each(key, function(k, v) { - self.attr(k, v); - }); - return self; - } - if (val === undefined) { - val = self.length < 1 ? null : _getAttr(self[0], key); - return val === null ? '' : val; - } - self.each(function() { - _setAttr(this, key, val); - }); - return self; - }, - removeAttr : function(key) { - this.each(function() { - _removeAttr(this, key); - }); - return this; - }, - get : function(i) { - if (this.length < 1) { - return null; - } - return this[i || 0]; - }, - eq : function(i) { - if (this.length < 1) { - return null; - } - return this[i] ? new KNode(this[i]) : null; - }, - hasClass : function(cls) { - if (this.length < 1) { - return false; - } - return _hasClass(this[0], cls); - }, - addClass : function(cls) { - this.each(function() { - if (!_hasClass(this, cls)) { - this.className = _trim(this.className + ' ' + cls); - } - }); - return this; - }, - removeClass : function(cls) { - this.each(function() { - if (_hasClass(this, cls)) { - this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' ')); - } - }); - return this; - }, - html : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1 || self.type != 1) { - return ''; - } - return _formatHtml(self[0].innerHTML); - } - self.each(function() { - _setHtml(this, val); - }); - return self; - }, - text : function() { - var self = this; - if (self.length < 1) { - return ''; - } - return _IE ? self[0].innerText : self[0].textContent; - }, - hasVal : function() { - if (this.length < 1) { - return false; - } - return _hasVal(this[0]); - }, - val : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return ''; - } - return self.hasVal() ? self[0].value : self.attr('value'); - } else { - self.each(function() { - if (_hasVal(this)) { - this.value = val; - } else { - _setAttr(this, 'value' , val); - } - }); - return self; - } - }, - css : function(key, val) { - var self = this; - if (key === undefined) { - return _getCssList(self.attr('style')); - } - if (typeof key === 'object') { - _each(key, function(k, v) { - self.css(k, v); - }); - return self; - } - if (val === undefined) { - if (self.length < 1) { - return ''; - } - return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || ''; - } - self.each(function() { - this.style[_toCamel(key)] = val; - }); - return self; - }, - width : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return 0; - } - return self[0].offsetWidth; - } - return self.css('width', _addUnit(val)); - }, - height : function(val) { - var self = this; - if (val === undefined) { - if (self.length < 1) { - return 0; - } - return self[0].offsetHeight; - } - return self.css('height', _addUnit(val)); - }, - opacity : function(val) { - this.each(function() { - if (this.style.opacity === undefined) { - this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')'; - } else { - this.style.opacity = val == 1 ? '' : val; - } - }); - return this; - }, - data : function(key, val) { - var self = this; - key = 'kindeditor_data_' + key; - if (val === undefined) { - if (self.length < 1) { - return null; - } - return self[0][key]; - } - this.each(function() { - this[key] = val; - }); - return self; - }, - pos : function() { - var self = this, node = self[0], x = 0, y = 0; - if (node) { - if (node.getBoundingClientRect) { - var box = node.getBoundingClientRect(), - pos = _getScrollPos(self.doc); - x = box.left + pos.x; - y = box.top + pos.y; - } else { - while (node) { - x += node.offsetLeft; - y += node.offsetTop; - node = node.offsetParent; - } - } - } - return {x : _round(x), y : _round(y)}; - }, - clone : function(bool) { - if (this.length < 1) { - return new KNode([]); - } - return new KNode(this[0].cloneNode(bool)); - }, - append : function(expr) { - this.each(function() { - if (this.appendChild) { - this.appendChild(_get(expr)); - } - }); - return this; - }, - appendTo : function(expr) { - this.each(function() { - _get(expr).appendChild(this); - }); - return this; - }, - before : function(expr) { - this.each(function() { - this.parentNode.insertBefore(_get(expr), this); - }); - return this; - }, - after : function(expr) { - this.each(function() { - if (this.nextSibling) { - this.parentNode.insertBefore(_get(expr), this.nextSibling); - } else { - this.parentNode.appendChild(_get(expr)); - } - }); - return this; - }, - replaceWith : function(expr) { - var nodes = []; - this.each(function(i, node) { - _unbind(node); - var newNode = _get(expr); - node.parentNode.replaceChild(newNode, node); - nodes.push(newNode); - }); - return K(nodes); - }, - empty : function() { - var self = this; - self.each(function(i, node) { - var child = node.firstChild; - while (child) { - if (!node.parentNode) { - return; - } - var next = child.nextSibling; - child.parentNode.removeChild(child); - child = next; - } - }); - return self; - }, - remove : function(keepChilds) { - var self = this; - self.each(function(i, node) { - if (!node.parentNode) { - return; - } - _unbind(node); - if (keepChilds) { - var child = node.firstChild; - while (child) { - var next = child.nextSibling; - node.parentNode.insertBefore(child, node); - child = next; - } - } - node.parentNode.removeChild(node); - delete self[i]; - }); - self.length = 0; - return self; - }, - show : function(val) { - var self = this; - if (val === undefined) { - val = self._originDisplay || ''; - } - if (self.css('display') != 'none') { - return self; - } - return self.css('display', val); - }, - hide : function() { - var self = this; - if (self.length < 1) { - return self; - } - self._originDisplay = self[0].style.display; - return self.css('display', 'none'); - }, - outer : function() { - var self = this; - if (self.length < 1) { - return ''; - } - var div = self.doc.createElement('div'), html; - div.appendChild(self[0].cloneNode(true)); - html = _formatHtml(div.innerHTML); - div = null; - return html; - }, - isSingle : function() { - return !!_SINGLE_TAG_MAP[this.name]; - }, - isInline : function() { - return !!_INLINE_TAG_MAP[this.name]; - }, - isBlock : function() { - return !!_BLOCK_TAG_MAP[this.name]; - }, - isStyle : function() { - return !!_STYLE_TAG_MAP[this.name]; - }, - isControl : function() { - return !!_CONTROL_TAG_MAP[this.name]; - }, - contains : function(otherNode) { - if (this.length < 1) { - return false; - } - return _contains(this[0], _get(otherNode)); - }, - parent : function() { - if (this.length < 1) { - return null; - } - var node = this[0].parentNode; - return node ? new KNode(node) : null; - }, - children : function() { - if (this.length < 1) { - return new KNode([]); - } - var list = [], child = this[0].firstChild; - while (child) { - if (child.nodeType != 3 || _trim(child.nodeValue) !== '') { - list.push(child); - } - child = child.nextSibling; - } - return new KNode(list); - }, - first : function() { - var list = this.children(); - return list.length > 0 ? list.eq(0) : null; - }, - last : function() { - var list = this.children(); - return list.length > 0 ? list.eq(list.length - 1) : null; - }, - index : function() { - if (this.length < 1) { - return -1; - } - var i = -1, sibling = this[0]; - while (sibling) { - i++; - sibling = sibling.previousSibling; - } - return i; - }, - prev : function() { - if (this.length < 1) { - return null; - } - var node = this[0].previousSibling; - return node ? new KNode(node) : null; - }, - next : function() { - if (this.length < 1) { - return null; - } - var node = this[0].nextSibling; - return node ? new KNode(node) : null; - }, - scan : function(fn, order) { - if (this.length < 1) { - return; - } - order = (order === undefined) ? true : order; - function walk(node) { - var n = order ? node.firstChild : node.lastChild; - while (n) { - var next = order ? n.nextSibling : n.previousSibling; - if (fn(n) === false) { - return false; - } - if (walk(n) === false) { - return false; - } - n = next; - } - } - walk(this[0]); - return this; - } -}); -_each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' + - 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' + - 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) { - KNode.prototype[type] = function(fn) { - return fn ? this.bind(type, fn) : this.fire(type); - }; -}); -var _K = K; -K = function(expr, root) { - if (expr === undefined || expr === null) { - return; - } - function newNode(node) { - if (!node[0]) { - node = []; - } - return new KNode(node); - } - if (typeof expr === 'string') { - if (root) { - root = _get(root); - } - var length = expr.length; - if (expr.charAt(0) === '@') { - expr = expr.substr(1); - } - if (expr.length !== length || /<.+>/.test(expr)) { - var doc = root ? root.ownerDocument || root : document, - div = doc.createElement('div'), list = []; - div.innerHTML = '' + expr; - for (var i = 0, len = div.childNodes.length; i < len; i++) { - var child = div.childNodes[i]; - if (child.id == '__kindeditor_temp_tag__') { - continue; - } - list.push(child); - } - return newNode(list); - } - return newNode(_queryAll(expr, root)); - } - if (expr && expr.constructor === KNode) { - return expr; - } - if (expr.toArray) { - expr = expr.toArray(); - } - if (_isArray(expr)) { - return newNode(expr); - } - return newNode(_toArray(arguments)); -}; -_each(_K, function(key, val) { - K[key] = val; -}); -K.NodeClass = KNode; -window.KindEditor = K; -var _START_TO_START = 0, - _START_TO_END = 1, - _END_TO_END = 2, - _END_TO_START = 3, - _BOOKMARK_ID = 0; -function _updateCollapsed(range) { - range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset); - return range; -} -function _copyAndDelete(range, isCopy, isDelete) { - var doc = range.doc, nodeList = []; - function splitTextNode(node, startOffset, endOffset) { - var length = node.nodeValue.length, centerNode; - if (isCopy) { - var cloneNode = node.cloneNode(true); - if (startOffset > 0) { - centerNode = cloneNode.splitText(startOffset); - } else { - centerNode = cloneNode; - } - if (endOffset < length) { - centerNode.splitText(endOffset - startOffset); - } - } - if (isDelete) { - var center = node; - if (startOffset > 0) { - center = node.splitText(startOffset); - range.setStart(node, startOffset); - } - if (endOffset < length) { - var right = center.splitText(endOffset - startOffset); - range.setEnd(right, 0); - } - nodeList.push(center); - } - return centerNode; - } - function removeNodes() { - if (isDelete) { - range.up().collapse(true); - } - for (var i = 0, len = nodeList.length; i < len; i++) { - var node = nodeList[i]; - if (node.parentNode) { - node.parentNode.removeChild(node); - } - } - } - var copyRange = range.cloneRange().down(); - var start = -1, incStart = -1, incEnd = -1, end = -1, - ancestor = range.commonAncestor(), frag = doc.createDocumentFragment(); - if (ancestor.nodeType == 3) { - var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset); - if (isCopy) { - frag.appendChild(textNode); - } - removeNodes(); - return isCopy ? frag : range; - } - function extractNodes(parent, frag) { - var node = parent.firstChild, nextNode; - while (node) { - var testRange = new KRange(doc).selectNode(node); - start = testRange.compareBoundaryPoints(_START_TO_END, range); - if (start >= 0 && incStart <= 0) { - incStart = testRange.compareBoundaryPoints(_START_TO_START, range); - } - if (incStart >= 0 && incEnd <= 0) { - incEnd = testRange.compareBoundaryPoints(_END_TO_END, range); - } - if (incEnd >= 0 && end <= 0) { - end = testRange.compareBoundaryPoints(_END_TO_START, range); - } - if (end >= 0) { - return false; - } - nextNode = node.nextSibling; - if (start > 0) { - if (node.nodeType == 1) { - if (incStart >= 0 && incEnd <= 0) { - if (isCopy) { - frag.appendChild(node.cloneNode(true)); - } - if (isDelete) { - nodeList.push(node); - } - } else { - var childFlag; - if (isCopy) { - childFlag = node.cloneNode(false); - frag.appendChild(childFlag); - } - if (extractNodes(node, childFlag) === false) { - return false; - } - } - } else if (node.nodeType == 3) { - var textNode; - if (node == copyRange.startContainer) { - textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length); - } else if (node == copyRange.endContainer) { - textNode = splitTextNode(node, 0, copyRange.endOffset); - } else { - textNode = splitTextNode(node, 0, node.nodeValue.length); - } - if (isCopy) { - try { - frag.appendChild(textNode); - } catch(e) {} - } - } - } - node = nextNode; - } - } - extractNodes(ancestor, frag); - if (isDelete) { - range.up().collapse(true); - } - for (var i = 0, len = nodeList.length; i < len; i++) { - var node = nodeList[i]; - if (node.parentNode) { - node.parentNode.removeChild(node); - } - } - return isCopy ? frag : range; -} -function _moveToElementText(range, el) { - var node = el; - while (node) { - var knode = K(node); - if (knode.name == 'marquee' || knode.name == 'select') { - return; - } - node = node.parentNode; - } - try { - range.moveToElementText(el); - } catch(e) {} -} -function _getStartEnd(rng, isStart) { - var doc = rng.parentElement().ownerDocument, - pointRange = rng.duplicate(); - pointRange.collapse(isStart); - var parent = pointRange.parentElement(), - nodes = parent.childNodes; - if (nodes.length === 0) { - return {node: parent.parentNode, offset: K(parent).index()}; - } - var startNode = doc, startPos = 0, cmp = -1; - var testRange = rng.duplicate(); - _moveToElementText(testRange, parent); - for (var i = 0, len = nodes.length; i < len; i++) { - var node = nodes[i]; - cmp = testRange.compareEndPoints('StartToStart', pointRange); - if (cmp === 0) { - return {node: node.parentNode, offset: i}; - } - if (node.nodeType == 1) { - var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node; - if (knode.isControl()) { - dummy = doc.createElement('span'); - knode.after(dummy); - newNode = dummy; - startPos += knode.text().replace(/\r\n|\n|\r/g, '').length; - } - _moveToElementText(nodeRange, newNode); - testRange.setEndPoint('StartToEnd', nodeRange); - if (cmp > 0) { - startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length; - } else { - startPos = 0; - } - if (dummy) { - K(dummy).remove(); - } - } else if (node.nodeType == 3) { - testRange.moveStart('character', node.nodeValue.length); - startPos += node.nodeValue.length; - } - if (cmp < 0) { - startNode = node; - } - } - if (cmp < 0 && startNode.nodeType == 1) { - return {node: parent, offset: K(parent.lastChild).index() + 1}; - } - if (cmp > 0) { - while (startNode.nextSibling && startNode.nodeType == 1) { - startNode = startNode.nextSibling; - } - } - testRange = rng.duplicate(); - _moveToElementText(testRange, parent); - testRange.setEndPoint('StartToEnd', pointRange); - startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length; - if (cmp > 0 && startNode.nodeType == 3) { - var prevNode = startNode.previousSibling; - while (prevNode && prevNode.nodeType == 3) { - startPos -= prevNode.nodeValue.length; - prevNode = prevNode.previousSibling; - } - } - return {node: startNode, offset: startPos}; -} -function _getEndRange(node, offset) { - var doc = node.ownerDocument || node, - range = doc.body.createTextRange(); - if (doc == node) { - range.collapse(true); - return range; - } - if (node.nodeType == 1 && node.childNodes.length > 0) { - var children = node.childNodes, isStart, child; - if (offset === 0) { - child = children[0]; - isStart = true; - } else { - child = children[offset - 1]; - isStart = false; - } - if (!child) { - return range; - } - if (K(child).name === 'head') { - if (offset === 1) { - isStart = true; - } - if (offset === 2) { - isStart = false; - } - range.collapse(isStart); - return range; - } - if (child.nodeType == 1) { - var kchild = K(child), span; - if (kchild.isControl()) { - span = doc.createElement('span'); - if (isStart) { - kchild.before(span); - } else { - kchild.after(span); - } - child = span; - } - _moveToElementText(range, child); - range.collapse(isStart); - if (span) { - K(span).remove(); - } - return range; - } - node = child; - offset = isStart ? 0 : child.nodeValue.length; - } - var dummy = doc.createElement('span'); - K(node).before(dummy); - _moveToElementText(range, dummy); - range.moveStart('character', offset); - K(dummy).remove(); - return range; -} -function _toRange(rng) { - var doc, range; - function tr2td(start) { - if (K(start.node).name == 'tr') { - start.node = start.node.cells[start.offset]; - start.offset = 0; - } - } - if (_IERANGE) { - if (rng.item) { - doc = _getDoc(rng.item(0)); - range = new KRange(doc); - range.selectNode(rng.item(0)); - return range; - } - doc = rng.parentElement().ownerDocument; - var start = _getStartEnd(rng, true), - end = _getStartEnd(rng, false); - tr2td(start); - tr2td(end); - range = new KRange(doc); - range.setStart(start.node, start.offset); - range.setEnd(end.node, end.offset); - return range; - } - var startContainer = rng.startContainer; - doc = startContainer.ownerDocument || startContainer; - range = new KRange(doc); - range.setStart(startContainer, rng.startOffset); - range.setEnd(rng.endContainer, rng.endOffset); - return range; -} -function KRange(doc) { - this.init(doc); -} -_extend(KRange, { - init : function(doc) { - var self = this; - self.startContainer = doc; - self.startOffset = 0; - self.endContainer = doc; - self.endOffset = 0; - self.collapsed = true; - self.doc = doc; - }, - commonAncestor : function() { - function getParents(node) { - var parents = []; - while (node) { - parents.push(node); - node = node.parentNode; - } - return parents; - } - var parentsA = getParents(this.startContainer), - parentsB = getParents(this.endContainer), - i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB; - while (++i) { - parentA = parentsA[lenA - i]; - parentB = parentsB[lenB - i]; - if (!parentA || !parentB || parentA !== parentB) { - break; - } - } - return parentsA[lenA - i + 1]; - }, - setStart : function(node, offset) { - var self = this, doc = self.doc; - self.startContainer = node; - self.startOffset = offset; - if (self.endContainer === doc) { - self.endContainer = node; - self.endOffset = offset; - } - return _updateCollapsed(this); - }, - setEnd : function(node, offset) { - var self = this, doc = self.doc; - self.endContainer = node; - self.endOffset = offset; - if (self.startContainer === doc) { - self.startContainer = node; - self.startOffset = offset; - } - return _updateCollapsed(this); - }, - setStartBefore : function(node) { - return this.setStart(node.parentNode || this.doc, K(node).index()); - }, - setStartAfter : function(node) { - return this.setStart(node.parentNode || this.doc, K(node).index() + 1); - }, - setEndBefore : function(node) { - return this.setEnd(node.parentNode || this.doc, K(node).index()); - }, - setEndAfter : function(node) { - return this.setEnd(node.parentNode || this.doc, K(node).index() + 1); - }, - selectNode : function(node) { - return this.setStartBefore(node).setEndAfter(node); - }, - selectNodeContents : function(node) { - var knode = K(node); - if (knode.type == 3 || knode.isSingle()) { - return this.selectNode(node); - } - var children = knode.children(); - if (children.length > 0) { - return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]); - } - return this.setStart(node, 0).setEnd(node, 0); - }, - collapse : function(toStart) { - if (toStart) { - return this.setEnd(this.startContainer, this.startOffset); - } - return this.setStart(this.endContainer, this.endOffset); - }, - compareBoundaryPoints : function(how, range) { - var rangeA = this.get(), rangeB = range.get(); - if (_IERANGE) { - var arr = {}; - arr[_START_TO_START] = 'StartToStart'; - arr[_START_TO_END] = 'EndToStart'; - arr[_END_TO_END] = 'EndToEnd'; - arr[_END_TO_START] = 'StartToEnd'; - var cmp = rangeA.compareEndPoints(arr[how], rangeB); - if (cmp !== 0) { - return cmp; - } - var nodeA, nodeB, nodeC, posA, posB; - if (how === _START_TO_START || how === _END_TO_START) { - nodeA = this.startContainer; - posA = this.startOffset; - } - if (how === _START_TO_END || how === _END_TO_END) { - nodeA = this.endContainer; - posA = this.endOffset; - } - if (how === _START_TO_START || how === _START_TO_END) { - nodeB = range.startContainer; - posB = range.startOffset; - } - if (how === _END_TO_END || how === _END_TO_START) { - nodeB = range.endContainer; - posB = range.endOffset; - } - if (nodeA === nodeB) { - var diff = posA - posB; - return diff > 0 ? 1 : (diff < 0 ? -1 : 0); - } - nodeC = nodeB; - while (nodeC && nodeC.parentNode !== nodeA) { - nodeC = nodeC.parentNode; - } - if (nodeC) { - return K(nodeC).index() >= posA ? -1 : 1; - } - nodeC = nodeA; - while (nodeC && nodeC.parentNode !== nodeB) { - nodeC = nodeC.parentNode; - } - if (nodeC) { - return K(nodeC).index() >= posB ? 1 : -1; - } - nodeC = K(nodeB).next(); - if (nodeC && nodeC.contains(nodeA)) { - return 1; - } - nodeC = K(nodeA).next(); - if (nodeC && nodeC.contains(nodeB)) { - return -1; - } - } else { - return rangeA.compareBoundaryPoints(how, rangeB); - } - }, - cloneRange : function() { - return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset); - }, - toString : function() { - var rng = this.get(), str = _IERANGE ? rng.text : rng.toString(); - return str.replace(/\r\n|\n|\r/g, ''); - }, - cloneContents : function() { - return _copyAndDelete(this, true, false); - }, - deleteContents : function() { - return _copyAndDelete(this, false, true); - }, - extractContents : function() { - return _copyAndDelete(this, true, true); - }, - insertNode : function(node) { - var self = this, - sc = self.startContainer, so = self.startOffset, - ec = self.endContainer, eo = self.endOffset, - firstChild, lastChild, c, nodeCount = 1; - if (node.nodeName.toLowerCase() === '#document-fragment') { - firstChild = node.firstChild; - lastChild = node.lastChild; - nodeCount = node.childNodes.length; - } - if (sc.nodeType == 1) { - c = sc.childNodes[so]; - if (c) { - sc.insertBefore(node, c); - if (sc === ec) { - eo += nodeCount; - } - } else { - sc.appendChild(node); - } - } else if (sc.nodeType == 3) { - if (so === 0) { - sc.parentNode.insertBefore(node, sc); - if (sc.parentNode === ec) { - eo += nodeCount; - } - } else if (so >= sc.nodeValue.length) { - if (sc.nextSibling) { - sc.parentNode.insertBefore(node, sc.nextSibling); - } else { - sc.parentNode.appendChild(node); - } - } else { - if (so > 0) { - c = sc.splitText(so); - } else { - c = sc; - } - sc.parentNode.insertBefore(node, c); - if (sc === ec) { - ec = c; - eo -= so; - } - } - } - if (firstChild) { - self.setStartBefore(firstChild).setEndAfter(lastChild); - } else { - self.selectNode(node); - } - if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) { - return self; - } - return self.setEnd(ec, eo); - }, - surroundContents : function(node) { - node.appendChild(this.extractContents()); - return this.insertNode(node).selectNode(node); - }, - isControl : function() { - var self = this, - sc = self.startContainer, so = self.startOffset, - ec = self.endContainer, eo = self.endOffset, rng; - return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl(); - }, - get : function(hasControlRange) { - var self = this, doc = self.doc, node, rng; - if (!_IERANGE) { - rng = doc.createRange(); - try { - rng.setStart(self.startContainer, self.startOffset); - rng.setEnd(self.endContainer, self.endOffset); - } catch (e) {} - return rng; - } - if (hasControlRange && self.isControl()) { - rng = doc.body.createControlRange(); - rng.addElement(self.startContainer.childNodes[self.startOffset]); - return rng; - } - var range = self.cloneRange().down(); - rng = doc.body.createTextRange(); - rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset)); - rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset)); - return rng; - }, - html : function() { - return K(this.cloneContents()).outer(); - }, - down : function() { - var self = this; - function downPos(node, pos, isStart) { - if (node.nodeType != 1) { - return; - } - var children = K(node).children(); - if (children.length === 0) { - return; - } - var left, right, child, offset; - if (pos > 0) { - left = children.eq(pos - 1); - } - if (pos < children.length) { - right = children.eq(pos); - } - if (left && left.type == 3) { - child = left[0]; - offset = child.nodeValue.length; - } - if (right && right.type == 3) { - child = right[0]; - offset = 0; - } - if (!child) { - return; - } - if (isStart) { - self.setStart(child, offset); - } else { - self.setEnd(child, offset); - } - } - downPos(self.startContainer, self.startOffset, true); - downPos(self.endContainer, self.endOffset, false); - return self; - }, - up : function() { - var self = this; - function upPos(node, pos, isStart) { - if (node.nodeType != 3) { - return; - } - if (pos === 0) { - if (isStart) { - self.setStartBefore(node); - } else { - self.setEndBefore(node); - } - } else if (pos == node.nodeValue.length) { - if (isStart) { - self.setStartAfter(node); - } else { - self.setEndAfter(node); - } - } - } - upPos(self.startContainer, self.startOffset, true); - upPos(self.endContainer, self.endOffset, false); - return self; - }, - enlarge : function(toBlock) { - var self = this; - self.up(); - function enlargePos(node, pos, isStart) { - var knode = K(node), parent; - if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) { - return; - } - if (pos === 0) { - while (!knode.prev()) { - parent = knode.parent(); - if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) { - break; - } - knode = parent; - } - if (isStart) { - self.setStartBefore(knode[0]); - } else { - self.setEndBefore(knode[0]); - } - } else if (pos == knode.children().length) { - while (!knode.next()) { - parent = knode.parent(); - if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) { - break; - } - knode = parent; - } - if (isStart) { - self.setStartAfter(knode[0]); - } else { - self.setEndAfter(knode[0]); - } - } - } - enlargePos(self.startContainer, self.startOffset, true); - enlargePos(self.endContainer, self.endOffset, false); - return self; - }, - shrink : function() { - var self = this, child, collapsed = self.collapsed; - while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) { - self.setStart(child, 0); - } - if (collapsed) { - return self.collapse(collapsed); - } - while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) { - self.setEnd(child, child.childNodes.length); - } - return self; - }, - createBookmark : function(serialize) { - var self = this, doc = self.doc, endNode, - startNode = K('', doc)[0]; - startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__'; - if (!self.collapsed) { - endNode = startNode.cloneNode(true); - endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__'; - } - if (endNode) { - self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode); - } - self.insertNode(startNode).setStartAfter(startNode); - return { - start : serialize ? '#' + startNode.id : startNode, - end : endNode ? (serialize ? '#' + endNode.id : endNode) : null - }; - }, - moveToBookmark : function(bookmark) { - var self = this, doc = self.doc, - start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null; - if (!start || start.length < 1) { - return self; - } - self.setStartBefore(start[0]); - start.remove(); - if (end && end.length > 0) { - self.setEndBefore(end[0]); - end.remove(); - } else { - self.collapse(true); - } - return self; - }, - dump : function() { - console.log('--------------------'); - console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset); - console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset); - } -}); -function _range(mixed) { - if (!mixed.nodeName) { - return mixed.constructor === KRange ? mixed : _toRange(mixed); - } - return new KRange(mixed); -} -K.RangeClass = KRange; -K.range = _range; -K.START_TO_START = _START_TO_START; -K.START_TO_END = _START_TO_END; -K.END_TO_END = _END_TO_END; -K.END_TO_START = _END_TO_START; -function _nativeCommand(doc, key, val) { - try { - doc.execCommand(key, false, val); - } catch(e) {} -} -function _nativeCommandValue(doc, key) { - var val = ''; - try { - val = doc.queryCommandValue(key); - } catch (e) {} - if (typeof val !== 'string') { - val = ''; - } - return val; -} -function _getSel(doc) { - var win = _getWin(doc); - return _IERANGE ? doc.selection : win.getSelection(); -} -function _getRng(doc) { - var sel = _getSel(doc), rng; - try { - if (sel.rangeCount > 0) { - rng = sel.getRangeAt(0); - } else { - rng = sel.createRange(); - } - } catch(e) {} - if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) { - return null; - } - return rng; -} -function _singleKeyMap(map) { - var newMap = {}, arr, v; - _each(map, function(key, val) { - arr = key.split(','); - for (var i = 0, len = arr.length; i < len; i++) { - v = arr[i]; - newMap[v] = val; - } - }); - return newMap; -} -function _hasAttrOrCss(knode, map) { - return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map); -} -function _hasAttrOrCssByKey(knode, map, mapKey) { - mapKey = mapKey || knode.name; - if (knode.type !== 1) { - return false; - } - var newMap = _singleKeyMap(map); - if (!newMap[mapKey]) { - return false; - } - var arr = newMap[mapKey].split(','); - for (var i = 0, len = arr.length; i < len; i++) { - var key = arr[i]; - if (key === '*') { - return true; - } - var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key); - var method = match[1] ? 'css' : 'attr'; - key = match[2]; - var val = match[3] || ''; - if (val === '' && knode[method](key) !== '') { - return true; - } - if (val !== '' && knode[method](key) === val) { - return true; - } - } - return false; -} -function _removeAttrOrCss(knode, map) { - if (knode.type != 1) { - return; - } - _removeAttrOrCssByKey(knode, map, '*'); - _removeAttrOrCssByKey(knode, map); -} -function _removeAttrOrCssByKey(knode, map, mapKey) { - mapKey = mapKey || knode.name; - if (knode.type !== 1) { - return; - } - var newMap = _singleKeyMap(map); - if (!newMap[mapKey]) { - return; - } - var arr = newMap[mapKey].split(','), allFlag = false; - for (var i = 0, len = arr.length; i < len; i++) { - var key = arr[i]; - if (key === '*') { - allFlag = true; - break; - } - var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key); - key = match[2]; - if (match[1]) { - key = _toCamel(key); - if (knode[0].style[key]) { - knode[0].style[key] = ''; - } - } else { - knode.removeAttr(key); - } - } - if (allFlag) { - knode.remove(true); - } -} -function _getInnerNode(knode) { - var inner = knode; - while (inner.first()) { - inner = inner.first(); - } - return inner; -} -function _isEmptyNode(knode) { - if (knode.type != 1 || knode.isSingle()) { - return false; - } - return knode.html().replace(/<[^>]+>/g, '') === ''; -} -function _mergeWrapper(a, b) { - a = a.clone(true); - var lastA = _getInnerNode(a), childA = a, merged = false; - while (b) { - while (childA) { - if (childA.name === b.name) { - _mergeAttrs(childA, b.attr(), b.css()); - merged = true; - } - childA = childA.first(); - } - if (!merged) { - lastA.append(b.clone(false)); - } - merged = false; - b = b.first(); - } - return a; -} -function _wrapNode(knode, wrapper) { - wrapper = wrapper.clone(true); - if (knode.type == 3) { - _getInnerNode(wrapper).append(knode.clone(false)); - knode.replaceWith(wrapper); - return wrapper; - } - var nodeWrapper = knode, child; - while ((child = knode.first()) && child.children().length == 1) { - knode = child; - } - child = knode.first(); - var frag = knode.doc.createDocumentFragment(); - while (child) { - frag.appendChild(child[0]); - child = child.next(); - } - wrapper = _mergeWrapper(nodeWrapper, wrapper); - if (frag.firstChild) { - _getInnerNode(wrapper).append(frag); - } - nodeWrapper.replaceWith(wrapper); - return wrapper; -} -function _mergeAttrs(knode, attrs, styles) { - _each(attrs, function(key, val) { - if (key !== 'style') { - knode.attr(key, val); - } - }); - _each(styles, function(key, val) { - knode.css(key, val); - }); -} -function _inPreElement(knode) { - while (knode && knode.name != 'body') { - if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) { - return true; - } - knode = knode.parent(); - } - return false; -} -function KCmd(range) { - this.init(range); -} -_extend(KCmd, { - init : function(range) { - var self = this, doc = range.doc; - self.doc = doc; - self.win = _getWin(doc); - self.sel = _getSel(doc); - self.range = range; - }, - selection : function(forceReset) { - var self = this, doc = self.doc, rng = _getRng(doc); - self.sel = _getSel(doc); - if (rng) { - self.range = _range(rng); - if (K(self.range.startContainer).name == 'html') { - self.range.selectNodeContents(doc.body).collapse(false); - } - return self; - } - if (forceReset) { - self.range.selectNodeContents(doc.body).collapse(false); - } - return self; - }, - select : function(hasDummy) { - hasDummy = _undef(hasDummy, true); - var self = this, sel = self.sel, range = self.range.cloneRange().shrink(), - sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset, - doc = _getDoc(sc), win = self.win, rng, hasU200b = false; - if (hasDummy && sc.nodeType == 1 && range.collapsed) { - if (_IERANGE) { - var dummy = K(' ', doc); - range.insertNode(dummy[0]); - rng = doc.body.createTextRange(); - try { - rng.moveToElementText(dummy[0]); - } catch(ex) {} - rng.collapse(false); - rng.select(); - dummy.remove(); - win.focus(); - return self; - } - if (_WEBKIT) { - var children = sc.childNodes; - if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) { - range.insertNode(doc.createTextNode('\u200B')); - hasU200b = true; - } - } - } - if (_IERANGE) { - try { - rng = range.get(true); - rng.select(); - } catch(e) {} - } else { - if (hasU200b) { - range.collapse(false); - } - rng = range.get(true); - sel.removeAllRanges(); - sel.addRange(rng); - if (doc !== document) { - var pos = K(rng.endContainer).pos(); - //win.scrollTo(pos.x, pos.y); - } - } - win.focus(); - return self; - }, - wrap : function(val) { - var self = this, doc = self.doc, range = self.range, wrapper; - wrapper = K(val, doc); - if (range.collapsed) { - range.shrink(); - range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]); - return self; - } - if (wrapper.isBlock()) { - var copyWrapper = wrapper.clone(true), child = copyWrapper; - while (child.first()) { - child = child.first(); - } - child.append(range.extractContents()); - range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]); - return self; - } - range.enlarge(); - var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false; - K(ancestor).scan(function(node) { - if (!isStart && node == bookmark.start) { - isStart = true; - return; - } - if (isStart) { - if (node == bookmark.end) { - return false; - } - var knode = K(node); - if (_inPreElement(knode)) { - return; - } - if (knode.type == 3 && _trim(node.nodeValue).length > 0) { - var parent; - while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) { - knode = parent; - } - _wrapNode(knode, wrapper); - } - } - }); - range.moveToBookmark(bookmark); - return self; - }, - split : function(isStart, map) { - var range = this.range, doc = range.doc; - var tempRange = range.cloneRange().collapse(isStart); - var node = tempRange.startContainer, pos = tempRange.startOffset, - parent = node.nodeType == 3 ? node.parentNode : node, - needSplit = false, knode; - while (parent && parent.parentNode) { - knode = K(parent); - if (map) { - if (!knode.isStyle()) { - break; - } - if (!_hasAttrOrCss(knode, map)) { - break; - } - } else { - if (_NOSPLIT_TAG_MAP[knode.name]) { - break; - } - } - needSplit = true; - parent = parent.parentNode; - } - if (needSplit) { - var dummy = doc.createElement('span'); - range.cloneRange().collapse(!isStart).insertNode(dummy); - if (isStart) { - tempRange.setStartBefore(parent.firstChild).setEnd(node, pos); - } else { - tempRange.setStart(node, pos).setEndAfter(parent.lastChild); - } - var frag = tempRange.extractContents(), - first = frag.firstChild, last = frag.lastChild; - if (isStart) { - tempRange.insertNode(frag); - range.setStartAfter(last).setEndBefore(dummy); - } else { - parent.appendChild(frag); - range.setStartBefore(dummy).setEndBefore(first); - } - var dummyParent = dummy.parentNode; - if (dummyParent == range.endContainer) { - var prev = K(dummy).prev(), next = K(dummy).next(); - if (prev && next && prev.type == 3 && next.type == 3) { - range.setEnd(prev[0], prev[0].nodeValue.length); - } else if (!isStart) { - range.setEnd(range.endContainer, range.endOffset - 1); - } - } - dummyParent.removeChild(dummy); - } - return this; - }, - remove : function(map) { - var self = this, doc = self.doc, range = self.range; - range.enlarge(); - if (range.startOffset === 0) { - var ksc = K(range.startContainer), parent; - while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) { - ksc = parent; - } - range.setStart(ksc[0], 0); - ksc = K(range.startContainer); - if (ksc.isBlock()) { - _removeAttrOrCss(ksc, map); - } - var kscp = ksc.parent(); - if (kscp && kscp.isBlock()) { - _removeAttrOrCss(kscp, map); - } - } - var sc, so; - if (range.collapsed) { - self.split(true, map); - sc = range.startContainer; - so = range.startOffset; - if (so > 0) { - var sb = K(sc.childNodes[so - 1]); - if (sb && _isEmptyNode(sb)) { - sb.remove(); - range.setStart(sc, so - 1); - } - } - var sa = K(sc.childNodes[so]); - if (sa && _isEmptyNode(sa)) { - sa.remove(); - } - if (_isEmptyNode(sc)) { - range.startBefore(sc); - sc.remove(); - } - range.collapse(true); - return self; - } - self.split(true, map); - self.split(false, map); - var startDummy = doc.createElement('span'), endDummy = doc.createElement('span'); - range.cloneRange().collapse(false).insertNode(endDummy); - range.cloneRange().collapse(true).insertNode(startDummy); - var nodeList = [], cmpStart = false; - K(range.commonAncestor()).scan(function(node) { - if (!cmpStart && node == startDummy) { - cmpStart = true; - return; - } - if (node == endDummy) { - return false; - } - if (cmpStart) { - nodeList.push(node); - } - }); - K(startDummy).remove(); - K(endDummy).remove(); - sc = range.startContainer; - so = range.startOffset; - var ec = range.endContainer, eo = range.endOffset; - if (so > 0) { - var startBefore = K(sc.childNodes[so - 1]); - if (startBefore && _isEmptyNode(startBefore)) { - startBefore.remove(); - range.setStart(sc, so - 1); - if (sc == ec) { - range.setEnd(ec, eo - 1); - } - } - var startAfter = K(sc.childNodes[so]); - if (startAfter && _isEmptyNode(startAfter)) { - startAfter.remove(); - if (sc == ec) { - range.setEnd(ec, eo - 1); - } - } - } - var endAfter = K(ec.childNodes[range.endOffset]); - if (endAfter && _isEmptyNode(endAfter)) { - endAfter.remove(); - } - var bookmark = range.createBookmark(true); - _each(nodeList, function(i, node) { - _removeAttrOrCss(K(node), map); - }); - range.moveToBookmark(bookmark); - return self; - }, - commonNode : function(map) { - var range = this.range; - var ec = range.endContainer, eo = range.endOffset, - node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1]; - function find(node) { - var child = node, parent = node; - while (parent) { - if (_hasAttrOrCss(K(parent), map)) { - return K(parent); - } - parent = parent.parentNode; - } - while (child && (child = child.lastChild)) { - if (_hasAttrOrCss(K(child), map)) { - return K(child); - } - } - return null; - } - var cNode = find(node); - if (cNode) { - return cNode; - } - if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) { - var prev = K(node).prev(); - if (prev) { - return find(prev); - } - } - return null; - }, - commonAncestor : function(tagName) { - var range = this.range, - sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset, - startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1], - endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1]; - function find(node) { - while (node) { - if (node.nodeType == 1) { - if (node.tagName.toLowerCase() === tagName) { - return node; - } - } - node = node.parentNode; - } - return null; - } - var start = find(startNode), end = find(endNode); - if (start && end && start === end) { - return K(start); - } - return null; - }, - state : function(key) { - var self = this, doc = self.doc, bool = false; - try { - bool = doc.queryCommandState(key); - } catch (e) {} - return bool; - }, - val : function(key) { - var self = this, doc = self.doc, range = self.range; - function lc(val) { - return val.toLowerCase(); - } - key = lc(key); - var val = '', knode; - if (key === 'fontfamily' || key === 'fontname') { - val = _nativeCommandValue(doc, 'fontname'); - val = val.replace(/['"]/g, ''); - return lc(val); - } - if (key === 'formatblock') { - val = _nativeCommandValue(doc, key); - if (val === '') { - knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'}); - if (knode) { - val = knode.name; - } - } - if (val === 'Normal') { - val = 'p'; - } - return lc(val); - } - if (key === 'fontsize') { - knode = self.commonNode({'*' : '.font-size'}); - if (knode) { - val = knode.css('font-size'); - } - return lc(val); - } - if (key === 'forecolor') { - knode = self.commonNode({'*' : '.color'}); - if (knode) { - val = knode.css('color'); - } - val = _toHex(val); - if (val === '') { - val = 'default'; - } - return lc(val); - } - if (key === 'hilitecolor') { - knode = self.commonNode({'*' : '.background-color'}); - if (knode) { - val = knode.css('background-color'); - } - val = _toHex(val); - if (val === '') { - val = 'default'; - } - return lc(val); - } - return val; - }, - toggle : function(wrapper, map) { - var self = this; - if (self.commonNode(map)) { - self.remove(map); - } else { - self.wrap(wrapper); - } - return self.select(); - }, - bold : function() { - return this.toggle('', { - span : '.font-weight=bold', - strong : '*', - b : '*' - }); - }, - italic : function() { - return this.toggle('', { - span : '.font-style=italic', - em : '*', - i : '*' - }); - }, - underline : function() { - return this.toggle('', { - span : '.text-decoration=underline', - u : '*' - }); - }, - strikethrough : function() { - return this.toggle('', { - span : '.text-decoration=line-through', - s : '*' - }); - }, - forecolor : function(val) { - return this.wrap('').select(); - }, - hilitecolor : function(val) { - return this.wrap('').select(); - }, - fontsize : function(val) { - return this.wrap('').select(); - }, - fontname : function(val) { - return this.fontfamily(val); - }, - fontfamily : function(val) { - return this.wrap('').select(); - }, - removeformat : function() { - var map = { - '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent' - }, - tags = _STYLE_TAG_MAP; - _each(tags, function(key, val) { - map[key] = '*'; - }); - this.remove(map); - return this.select(); - }, - inserthtml : function(val, quickMode) { - var self = this, range = self.range; - if (val === '') { - return self; - } - function pasteHtml(range, val) { - val = '' + val; - var rng = range.get(); - if (rng.item) { - rng.item(0).outerHTML = val; - } else { - rng.pasteHTML(val); - } - var temp = range.doc.getElementById('__kindeditor_temp_tag__'); - temp.parentNode.removeChild(temp); - var newRange = _toRange(rng); - range.setEnd(newRange.endContainer, newRange.endOffset); - range.collapse(false); - self.select(false); - } - function insertHtml(range, val) { - var doc = range.doc, - frag = doc.createDocumentFragment(); - K('@' + val, doc).each(function() { - frag.appendChild(this); - }); - range.deleteContents(); - range.insertNode(frag); - range.collapse(false); - self.select(false); - } - if (_IERANGE && quickMode) { - try { - pasteHtml(range, val); - } catch(e) { - insertHtml(range, val); - } - return self; - } - insertHtml(range, val); - return self; - }, - hr : function() { - return this.inserthtml('
      '); - }, - print : function() { - this.win.print(); - return this; - }, - insertimage : function(url, title, width, height, border, align) { - title = _undef(title, ''); - border = _undef(border, 0); - var html = ''; - return self.inserthtml(html); - } - if (range.isControl()) { - var node = K(range.startContainer.childNodes[range.startOffset]); - html += '>'; - node.after(K(html, doc)); - node.next().append(node); - range.selectNode(node[0]); - return self.select(); - } - function setAttr(node, url, type) { - K(node).attr('href', url).attr('data-ke-src', url); - if (type) { - K(node).attr('target', type); - } else { - K(node).removeAttr('target'); - } - } - var sc = range.startContainer, so = range.startOffset, - ec = range.endContainer, eo = range.endOffset; - if (sc.nodeType == 1 && sc === ec && so + 1 === eo) { - var child = sc.childNodes[so]; - if (child.nodeName.toLowerCase() == 'a') { - setAttr(child, url, type); - return self; - } - } - _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__'); - K('a[href="__kindeditor_temp_url__"]', doc).each(function() { - setAttr(this, url, type); - }); - return self; - }, - unlink : function() { - var self = this, doc = self.doc, range = self.range; - self.select(); - if (range.collapsed) { - var a = self.commonNode({ a : '*' }); - if (a) { - range.selectNode(a.get()); - self.select(); - } - _nativeCommand(doc, 'unlink', null); - if (_WEBKIT && K(range.startContainer).name === 'img') { - var parent = K(range.startContainer).parent(); - if (parent.name === 'a') { - parent.remove(true); - } - } - } else { - _nativeCommand(doc, 'unlink', null); - } - return self; - } -}); -_each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' + - 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) { - KCmd.prototype[name] = function(val) { - var self = this; - self.select(); - _nativeCommand(self.doc, name, val); - if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) { - self.selection(); - } - if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) { - self.selection(); - } - return self; - }; -}); -_each('cut,copy,paste'.split(','), function(i, name) { - KCmd.prototype[name] = function() { - var self = this; - if (!self.doc.queryCommandSupported(name)) { - throw 'not supported'; - } - self.select(); - _nativeCommand(self.doc, name, null); - return self; - }; -}); -function _cmd(mixed) { - if (mixed.nodeName) { - var doc = _getDoc(mixed); - mixed = _range(doc).selectNodeContents(doc.body).collapse(false); - } - return new KCmd(mixed); -} -K.CmdClass = KCmd; -K.cmd = _cmd; -function _drag(options) { - var moveEl = options.moveEl, - moveFn = options.moveFn, - clickEl = options.clickEl || moveEl, - beforeDrag = options.beforeDrag, - iframeFix = options.iframeFix === undefined ? true : options.iframeFix; - var docs = [document]; - if (iframeFix) { - K('iframe').each(function() { - var src = _formatUrl(this.src || '', 'absolute'); - if (/^https?:\/\//.test(src)) { - return; - } - var doc; - try { - doc = _iframeDoc(this); - } catch(e) {} - if (doc) { - var pos = K(this).pos(); - K(doc).data('pos-x', pos.x); - K(doc).data('pos-y', pos.y); - docs.push(doc); - } - }); - } - clickEl.mousedown(function(e) { - e.stopPropagation(); - var self = clickEl.get(), - x = _removeUnit(moveEl.css('left')), - y = _removeUnit(moveEl.css('top')), - width = moveEl.width(), - height = moveEl.height(), - pageX = e.pageX, - pageY = e.pageY; - if (beforeDrag) { - beforeDrag(); - } - function moveListener(e) { - e.preventDefault(); - var kdoc = K(_getDoc(e.target)); - var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX); - var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY); - moveFn.call(clickEl, x, y, width, height, diffX, diffY); - } - function selectListener(e) { - e.preventDefault(); - } - function upListener(e) { - e.preventDefault(); - K(docs).unbind('mousemove', moveListener) - .unbind('mouseup', upListener) - .unbind('selectstart', selectListener); - if (self.releaseCapture) { - self.releaseCapture(); - } - } - K(docs).mousemove(moveListener) - .mouseup(upListener) - .bind('selectstart', selectListener); - if (self.setCapture) { - self.setCapture(); - } - }); -} -function KWidget(options) { - this.init(options); -} -_extend(KWidget, { - init : function(options) { - var self = this; - self.name = options.name || ''; - self.doc = options.doc || document; - self.win = _getWin(self.doc); - self.x = _addUnit(options.x); - self.y = _addUnit(options.y); - self.z = options.z; - self.width = _addUnit(options.width); - self.height = _addUnit(options.height); - self.div = K('
      '); - self.options = options; - self._alignEl = options.alignEl; - if (self.width) { - self.div.css('width', self.width); - } - if (self.height) { - self.div.css('height', self.height); - } - if (self.z) { - self.div.css({ - position : 'absolute', - left : self.x, - top : self.y, - 'z-index' : self.z - }); - } - if (self.z && (self.x === undefined || self.y === undefined)) { - self.autoPos(self.width, self.height); - } - if (options.cls) { - self.div.addClass(options.cls); - } - if (options.shadowMode) { - self.div.addClass('ke-shadow'); - } - if (options.css) { - self.div.css(options.css); - } - if (options.src) { - K(options.src).replaceWith(self.div); - } else { - K(self.doc.body).append(self.div); - } - if (options.html) { - self.div.html(options.html); - } - if (options.autoScroll) { - if (_IE && _V < 7 || _QUIRKS) { - var scrollPos = _getScrollPos(); - K(self.win).bind('scroll', function(e) { - var pos = _getScrollPos(), - diffX = pos.x - scrollPos.x, - diffY = pos.y - scrollPos.y; - self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false); - }); - } else { - self.div.css('position', 'fixed'); - } - } - }, - pos : function(x, y, updateProp) { - var self = this; - updateProp = _undef(updateProp, true); - if (x !== null) { - x = x < 0 ? 0 : _addUnit(x); - self.div.css('left', x); - if (updateProp) { - self.x = x; - } - } - if (y !== null) { - y = y < 0 ? 0 : _addUnit(y); - self.div.css('top', y); - if (updateProp) { - self.y = y; - } - } - return self; - }, - autoPos : function(width, height) { - var self = this, - w = _removeUnit(width) || 0, - h = _removeUnit(height) || 0, - scrollPos = _getScrollPos(); - if (self._alignEl) { - var knode = K(self._alignEl), - pos = knode.pos(), - diffX = _round(knode[0].clientWidth / 2 - w / 2), - diffY = _round(knode[0].clientHeight / 2 - h / 2); - x = diffX < 0 ? pos.x : pos.x + diffX; - y = diffY < 0 ? pos.y : pos.y + diffY; - } else { - var docEl = _docElement(self.doc); - x = _round(scrollPos.x + (docEl.clientWidth - w) / 2); - y = _round(scrollPos.y + (docEl.clientHeight - h) / 2); - } - if (!(_IE && _V < 7 || _QUIRKS)) { - x -= scrollPos.x; - y -= scrollPos.y; - } - return self.pos(x, y); - }, - remove : function() { - var self = this; - if (_IE && _V < 7 || _QUIRKS) { - K(self.win).unbind('scroll'); - } - self.div.remove(); - _each(self, function(i) { - self[i] = null; - }); - return this; - }, - show : function() { - this.div.show(); - return this; - }, - hide : function() { - this.div.hide(); - return this; - }, - draggable : function(options) { - var self = this; - options = options || {}; - options.moveEl = self.div; - options.moveFn = function(x, y, width, height, diffX, diffY) { - if ((x = x + diffX) < 0) { - x = 0; - } - if ((y = y + diffY) < 0) { - y = 0; - } - self.pos(x, y); - }; - _drag(options); - return self; - } -}); -function _widget(options) { - return new KWidget(options); -} -K.WidgetClass = KWidget; -K.widget = _widget; -function _iframeDoc(iframe) { - iframe = _get(iframe); - return iframe.contentDocument || iframe.contentWindow.document; -} -var html, _direction = ''; -if ((html = document.getElementsByTagName('html'))) { - _direction = html[0].dir; -} - -function _getInitHtml(themesPath, bodyClass, cssPath, cssData) { - var arr = [ - (_direction === '' ? '' : ''), - '', - '' - ]; - if (!_isArray(cssPath)) { - cssPath = [cssPath]; - } - _each(cssPath, function(i, path) { - if (path) { - arr.push(''); - } - }); - if (cssData) { - arr.push(''); - } - arr.push(''); - return arr.join('\n'); -} -function _elementVal(knode, val) { - if (knode.hasVal()) { - if (val === undefined) { - var html = knode.val(); - html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, ''); - return html; - } - return knode.val(val); - } - return knode.html(val); -} -function KEdit(options) { - this.init(options); -} -_extend(KEdit, KWidget, { - init : function(options) { - var self = this; - KEdit.parent.init.call(self, options); - self.srcElement = K(options.srcElement); - self.div.addClass('ke-edit'); - self.designMode = _undef(options.designMode, true); - self.beforeGetHtml = options.beforeGetHtml; - self.beforeSetHtml = options.beforeSetHtml; - self.afterSetHtml = options.afterSetHtml; - var themesPath = _undef(options.themesPath, ''), - bodyClass = options.bodyClass, - cssPath = options.cssPath, - cssData = options.cssData, - isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain, - srcScript = ('document.open();' + - (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') + - 'document.close();'), - iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : ''; - self.iframe = K('').css('width', '100%'); - self.textarea = K('').css('width', '100%'); - self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10); - self.iframe.attr('tabindex', self.tabIndex); - self.textarea.attr('tabindex', self.tabIndex); - if (self.width) { - self.setWidth(self.width); - } - if (self.height) { - self.setHeight(self.height); - } - if (self.designMode) { - self.textarea.hide(); - } else { - self.iframe.hide(); - } - function ready() { - var doc = _iframeDoc(self.iframe); - doc.open(); - if (isDocumentDomain) { - doc.domain = document.domain; - } - doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData)); - doc.close(); - self.win = self.iframe[0].contentWindow; - self.doc = doc; - var cmd = _cmd(doc); - self.afterChange(function(e) { - cmd.selection(); - }); - if (_WEBKIT) { - K(doc).click(function(e) { - if (K(e.target).name === 'img') { - cmd.selection(true); - cmd.range.selectNode(e.target); - cmd.select(); - } - }); - } - if (_IE) { - self._mousedownHandler = function() { - var newRange = cmd.range.cloneRange(); - newRange.shrink(); - if (newRange.isControl()) { - self.blur(); - } - }; - K(document).mousedown(self._mousedownHandler); - K(doc).keydown(function(e) { - if (e.which == 8) { - cmd.selection(); - var rng = cmd.range; - if (rng.isControl()) { - rng.collapse(true); - K(rng.startContainer.childNodes[rng.startOffset]).remove(); - e.preventDefault(); - } - } - }); - } - self.cmd = cmd; - self.html(_elementVal(self.srcElement)); - if (_IE) { - doc.body.disabled = true; - doc.body.contentEditable = true; - doc.body.removeAttribute('disabled'); - } else { - doc.designMode = 'on'; - } - if (options.afterCreate) { - options.afterCreate.call(self); - } - } - if (isDocumentDomain) { - self.iframe.bind('load', function(e) { - self.iframe.unbind('load'); - if (_IE) { - ready(); - } else { - setTimeout(ready, 0); - } - }); - } - self.div.append(self.iframe); - self.div.append(self.textarea); - self.srcElement.hide(); - !isDocumentDomain && ready(); - }, - setWidth : function(val) { - var self = this; - val = _addUnit(val); - self.width = val; - self.div.css('width', val); - return self; - }, - setHeight : function(val) { - var self = this; - val = _addUnit(val); - self.height = val; - self.div.css('height', val); - self.iframe.css('height', val); - if ((_IE && _V < 8) || _QUIRKS) { - val = _addUnit(_removeUnit(val) - 2); - } - self.textarea.css('height', val); - return self; - }, - remove : function() { - var self = this, doc = self.doc; - K(doc.body).unbind(); - K(doc).unbind(); - K(self.win).unbind(); - if (self._mousedownHandler) { - K(document).unbind('mousedown', self._mousedownHandler); - } - _elementVal(self.srcElement, self.html()); - self.srcElement.show(); - doc.write(''); - self.iframe.unbind(); - self.textarea.unbind(); - KEdit.parent.remove.call(self); - }, - html : function(val, isFull) { - var self = this, doc = self.doc; - if (self.designMode) { - var body = doc.body; - if (val === undefined) { - if (isFull) { - val = '' + body.parentNode.innerHTML + ''; - } else { - val = body.innerHTML; - } - if (self.beforeGetHtml) { - val = self.beforeGetHtml(val); - } - if (_GECKO && val == '
      ') { - val = ''; - } - return val; - } - if (self.beforeSetHtml) { - val = self.beforeSetHtml(val); - } - if (_IE && _V >= 9) { - val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2'); - } - K(body).html(val); - if (self.afterSetHtml) { - self.afterSetHtml(); - } - return self; - } - if (val === undefined) { - return self.textarea.val(); - } - self.textarea.val(val); - return self; - }, - design : function(bool) { - var self = this, val; - if (bool === undefined ? !self.designMode : bool) { - if (!self.designMode) { - val = self.html(); - self.designMode = true; - self.html(val); - self.textarea.hide(); - self.iframe.show(); - } - } else { - if (self.designMode) { - val = self.html(); - self.designMode = false; - self.html(val); - self.iframe.hide(); - self.textarea.show(); - } - } - return self.focus(); - }, - focus : function() { - var self = this; - self.designMode ? self.win.focus() : self.textarea[0].focus(); - return self; - }, - blur : function() { - var self = this; - if (_IE) { - var input = K('', self.div); - self.div.append(input); - input[0].focus(); - input.remove(); - } else { - self.designMode ? self.win.blur() : self.textarea[0].blur(); - } - return self; - }, - afterChange : function(fn) { - var self = this, doc = self.doc, body = doc.body; - K(doc).keyup(function(e) { - if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) { - fn(e); - } - }); - K(doc).mouseup(fn).contextmenu(fn); - K(self.win).blur(fn); - function timeoutHandler(e) { - setTimeout(function() { - fn(e); - }, 1); - } - K(body).bind('paste', timeoutHandler); - K(body).bind('cut', timeoutHandler); - return self; - } -}); -function _edit(options) { - return new KEdit(options); -} -K.EditClass = KEdit; -K.edit = _edit; -K.iframeDoc = _iframeDoc; -function _selectToolbar(name, fn) { - var self = this, - knode = self.get(name); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - fn(knode); - } -} -function KToolbar(options) { - this.init(options); -} -_extend(KToolbar, KWidget, { - init : function(options) { - var self = this; - KToolbar.parent.init.call(self, options); - self.disableMode = _undef(options.disableMode, false); - self.noDisableItemMap = _toMap(_undef(options.noDisableItems, [])); - self._itemMap = {}; - self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) { - e.preventDefault(); - }).attr('unselectable', 'on'); - function find(target) { - var knode = K(target); - if (knode.hasClass('ke-outline')) { - return knode; - } - if (knode.hasClass('ke-toolbar-icon')) { - return knode.parent(); - } - } - function hover(e, method) { - var knode = find(e.target); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - if (knode.hasClass('ke-selected')) { - return; - } - knode[method]('ke-on'); - } - } - self.div.mouseover(function(e) { - hover(e, 'addClass'); - }) - .mouseout(function(e) { - hover(e, 'removeClass'); - }) - .click(function(e) { - var knode = find(e.target); - if (knode) { - if (knode.hasClass('ke-disabled')) { - return; - } - self.options.click.call(this, e, knode.attr('data-name')); - } - }); - }, - get : function(name) { - //if(this._itemMap[name])return this._itemMap[name]; - //return this._itemMap[name]=K("span.ke-icon-"+name,this.div).parent() -// if (this._itemMap[name]) { -// return this._itemMap[name]; -// } -// if($("#define").css('display') == 'block'){ -// pdiv = $("#define") -// }else if($("#full").css('display') == 'block'){ -// pdiv = $("#full") -// } - var container = this.div; - if(!$("#define",container).is(':hidden')){ - pdiv = $("#define",container); - }else if(!$("#full",container).is(':hidden')){ - pdiv = $("#full",container); - } - return (this._itemMap[name] = K('span.ke-icon-' + name, pdiv).parent()); - }, - select : function(name) { - _selectToolbar.call(this, name, function(knode) { - knode.addClass('ke-selected'); - }); - return self; - }, - unselect : function(name) { - _selectToolbar.call(this, name, function(knode) { - knode.removeClass('ke-selected').removeClass('ke-on'); - }); - return self; - }, - enable : function(name) { - var self = this, - knode = name.get ? name : self.get(name); - if (knode) { - knode.removeClass('ke-disabled'); - knode.opacity(1); - } - return self; - }, - disable : function(name) { - var self = this, - knode = name.get ? name : self.get(name); - if (knode) { - knode.removeClass('ke-selected').addClass('ke-disabled'); - knode.opacity(0.5); - } - return self; - }, - disableAll : function(bool, noDisableItems) { - var self = this, map = self.noDisableItemMap, item; - if (noDisableItems) { - map = _toMap(noDisableItems); - } - if (bool === undefined ? !self.disableMode : bool) { - K('span.ke-outline', self.div).each(function() { - var knode = K(this), - name = knode[0].getAttribute('data-name', 2); - if (!map[name]) { - self.disable(knode); - } - }); - self.disableMode = true; - } else { - K('span.ke-outline', self.div).each(function() { - var knode = K(this), - name = knode[0].getAttribute('data-name', 2); - if (!map[name]) { - self.enable(knode); - } - }); - self.disableMode = false; - } - return self; - } -}); -function _toolbar(options) { - return new KToolbar(options); -} -K.ToolbarClass = KToolbar; -K.toolbar = _toolbar; -function KMenu(options) { - this.init(options); -} -_extend(KMenu, KWidget, { - init : function(options) { - var self = this; - options.z = options.z || 811213; - KMenu.parent.init.call(self, options); - self.centerLineMode = _undef(options.centerLineMode, true); - self.div.addClass('ke-menu').bind('click,mousedown', function(e){ - e.stopPropagation(); - }).attr('unselectable', 'on'); - }, - addItem : function(item) { - var self = this; - if (item.title === '-') { - self.div.append(K('
      ')); - return; - } - var itemDiv = K('
      '), - leftDiv = K('
      '), - rightDiv = K('
      '), - height = _addUnit(item.height), - iconClass = _undef(item.iconClass, ''); - self.div.append(itemDiv); - if (height) { - itemDiv.css('height', height); - rightDiv.css('line-height', height); - } - var centerDiv; - if (self.centerLineMode) { - centerDiv = K('
      '); - if (height) { - centerDiv.css('height', height); - } - } - itemDiv.mouseover(function(e) { - K(this).addClass('ke-menu-item-on'); - if (centerDiv) { - centerDiv.addClass('ke-menu-item-center-on'); - } - }) - .mouseout(function(e) { - K(this).removeClass('ke-menu-item-on'); - if (centerDiv) { - centerDiv.removeClass('ke-menu-item-center-on'); - } - }) - .click(function(e) { - item.click.call(K(this)); - e.stopPropagation(); - }) - .append(leftDiv); - if (centerDiv) { - itemDiv.append(centerDiv); - } - itemDiv.append(rightDiv); - if (item.checked) { - iconClass = 'ke-icon-checked'; - } - if (iconClass !== '') { - leftDiv.html(''); - } - rightDiv.html(item.title); - return self; - }, - remove : function() { - var self = this; - if (self.options.beforeRemove) { - self.options.beforeRemove.call(self); - } - K('.ke-menu-item', self.div[0]).unbind(); - KMenu.parent.remove.call(self); - return self; - } -}); -function _menu(options) { - return new KMenu(options); -} -K.MenuClass = KMenu; -K.menu = _menu; -function KColorPicker(options) { - this.init(options); -} -_extend(KColorPicker, KWidget, { - init : function(options) { - var self = this; - options.z = options.z || 811213; - KColorPicker.parent.init.call(self, options); - var colors = options.colors || [ - ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], - ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], - ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], - ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] - ]; - self.selectedColor = (options.selectedColor || '').toLowerCase(); - self._cells = []; - self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){ - e.stopPropagation(); - }).attr('unselectable', 'on'); - var table = self.doc.createElement('table'); - self.div.append(table); - table.className = 'ke-colorpicker-table'; - table.cellPadding = 0; - table.cellSpacing = 0; - table.border = 0; - var row = table.insertRow(0), cell = row.insertCell(0); - cell.colSpan = colors[0].length; - self._addAttr(cell, '', 'ke-colorpicker-cell-top'); - for (var i = 0; i < colors.length; i++) { - row = table.insertRow(i + 1); - for (var j = 0; j < colors[i].length; j++) { - cell = row.insertCell(j); - self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell'); - } - } - }, - _addAttr : function(cell, color, cls) { - var self = this; - cell = K(cell).addClass(cls); - if (self.selectedColor === color.toLowerCase()) { - cell.addClass('ke-colorpicker-cell-selected'); - } - cell.attr('title', color || self.options.noColor); - cell.mouseover(function(e) { - K(this).addClass('ke-colorpicker-cell-on'); - }); - cell.mouseout(function(e) { - K(this).removeClass('ke-colorpicker-cell-on'); - }); - cell.click(function(e) { - e.stop(); - self.options.click.call(K(this), color); - }); - if (color) { - cell.append(K('
      ').css('background-color', color)); - } else { - cell.html(self.options.noColor); - } - K(cell).attr('unselectable', 'on'); - self._cells.push(cell); - }, - remove : function() { - var self = this; - _each(self._cells, function() { - this.unbind(); - }); - KColorPicker.parent.remove.call(self); - return self; - } -}); -function _colorpicker(options) { - return new KColorPicker(options); -} -K.ColorPickerClass = KColorPicker; -K.colorpicker = _colorpicker; -function KUploadButton(options) { - this.init(options); -} -_extend(KUploadButton, { - init : function(options) { - //dump_obj(options); - var self = this, - button = K(options.button), - fieldName = options.fieldName || 'file', - url = options.url || '', - title = button.val(), - extraParams = options.extraParams || {}, - cls = button[0].className || '', - target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime(); - options.afterError = options.afterError || function(str) { - alert(str); - }; - var hiddenElements = []; - for(var k in extraParams){ - hiddenElements.push(''); - } - var html = [ - '
      ', - (options.target ? '' : ''), - (options.form ? '
      ' : '
      '), - '', - hiddenElements.join(''), - '', - '', - '', - (options.form ? '
      ' : ''), - '
      '].join(''); - var div = K(html, button.doc); - $(div).hide()// 如果 以后要用根据 http://kindeditor.net/docs/uploadbutton.html#k-uploadbutton-options来使用uploadButton,那么这里的button会 是隐藏的 - button.hide(); - button.before(div); - self.div = div; - if(options.ops!=undefined)options.ops.up_file_div = div;//options.ops是KindEditor.create()的options参数 - self.button = button; - self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div); - self.form = options.form ? K(options.form) : K('form', div); - self.fileBox = K('.ke-upload-file', div); - var width = options.width || K('.ke-button-common', div).width(); - K('.ke-upload-area', div).width(width); - self.options = options; - }, - submit : function() { - var self = this, - iframe = self.iframe; - iframe.bind('load', function() { - iframe.unbind(); - var tempForm = document.createElement('form'); - self.fileBox.before(tempForm); - K(tempForm).append(self.fileBox); - tempForm.reset(); - K(tempForm).remove(true); - var doc = K.iframeDoc(iframe), - pre = doc.getElementsByTagName('pre')[0], - str = '', data; - if (pre) { - str = pre.innerHTML; - } else { - str = doc.body.innerHTML; - } - str = _unescape(str); - iframe[0].src = 'javascript:false'; - try { - data = K.json(str); - } catch (e) { - self.options.afterError.call(self, '' + doc.body.parentNode.innerHTML + ''); - } - if (data) { - self.options.afterUpload.call(self, data); - } - }); - self.form[0].submit(); - return self; - }, - remove : function() { - var self = this; - if (self.fileBox) { - self.fileBox.unbind(); - } - self.iframe.remove(); - self.div.remove(); - self.button.show(); - return self; - } -}); -function _uploadbutton(options) { - return new KUploadButton(options); -} -K.UploadButtonClass = KUploadButton; -K.uploadbutton = _uploadbutton; -function _createButton(arg) { - arg = arg || {}; - var name = arg.name || '', - span = K(''), - btn = K(''); - if (arg.click) { - btn.click(arg.click); - } - span.append(btn); - return span; -} -function KDialog(options) { - this.init(options); -} -_extend(KDialog, KWidget, { - init : function(options) { - var self = this; - var shadowMode = _undef(options.shadowMode, true); - options.z = options.z || 811213; - options.shadowMode = false; - options.autoScroll = _undef(options.autoScroll, true); - KDialog.parent.init.call(self, options); - var title = options.title, - body = K(options.body, self.doc), - previewBtn = options.previewBtn, - yesBtn = options.yesBtn, - noBtn = options.noBtn, - closeBtn = options.closeBtn, - showMask = _undef(options.showMask, true); - self.div.addClass('ke-dialog').bind('click,mousedown', function(e){ - e.stopPropagation(); - }); - var contentDiv = K('
      ').appendTo(self.div); - if (_IE && _V < 7) { - self.iframeMask = K('').appendTo(self.div); - } else if (shadowMode) { - K('
      ').appendTo(self.div); - } - var headerDiv = K('
      '); - contentDiv.append(headerDiv); - headerDiv.html(title); - self.closeIcon = K('').click(closeBtn.click); - headerDiv.append(self.closeIcon); - self.draggable({ - clickEl : headerDiv, - beforeDrag : options.beforeDrag - }); - var bodyDiv = K('
      '); - contentDiv.append(bodyDiv); - bodyDiv.append(body); - var footerDiv = K(''); - if (previewBtn || yesBtn || noBtn) { - contentDiv.append(footerDiv); - } - _each([ - { btn : previewBtn, name : 'preview' }, - { btn : yesBtn, name : 'yes' }, - { btn : noBtn, name : 'no' } - ], function() { - if (this.btn) { - var button = _createButton(this.btn); - button.addClass('ke-dialog-' + this.name); - footerDiv.append(button); - } - }); - if (self.height) { - bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height()); - } - self.div.width(self.div.width()); - self.div.height(self.div.height()); - self.mask = null; - if (showMask) { - var docEl = _docElement(self.doc), - docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth), - docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight); - self.mask = _widget({ - x : 0, - y : 0, - z : self.z - 1, - cls : 'ke-dialog-mask', - width : docWidth, - height : docHeight - }); - } - self.autoPos(self.div.width(), self.div.height()); - self.footerDiv = footerDiv; - self.bodyDiv = bodyDiv; - self.headerDiv = headerDiv; - self.isLoading = false; - }, - setMaskIndex : function(z) { - var self = this; - self.mask.div.css('z-index', z); - }, - showLoading : function(msg) { - msg = _undef(msg, ''); - var self = this, body = self.bodyDiv; - self.loading = K('
      ' + msg + '
      ') - .width(body.width()).height(body.height()) - .css('top', self.headerDiv.height() + 'px'); - body.css('visibility', 'hidden').after(self.loading); - self.isLoading = true; - return self; - }, - hideLoading : function() { - this.loading && this.loading.remove(); - this.bodyDiv.css('visibility', 'visible'); - this.isLoading = false; - return this; - }, - remove : function() { - var self = this; - if (self.options.beforeRemove) { - self.options.beforeRemove.call(self); - } - self.mask && self.mask.remove(); - self.iframeMask && self.iframeMask.remove(); - self.closeIcon.unbind(); - K('input', self.div).unbind(); - K('button', self.div).unbind(); - self.footerDiv.unbind(); - self.bodyDiv.unbind(); - self.headerDiv.unbind(); - K('iframe', self.div).each(function() { - K(this).remove(); - }); - KDialog.parent.remove.call(self); - return self; - } -}); -function _dialog(options) { - return new KDialog(options); -} -K.DialogClass = KDialog; -K.dialog = _dialog; -function _tabs(options) { - var self = _widget(options), - remove = self.remove, - afterSelect = options.afterSelect, - div = self.div, - liList = []; - div.addClass('ke-tabs') - .bind('contextmenu,mousedown,mousemove', function(e) { - e.preventDefault(); - }); - var ul = K('
        '); - div.append(ul); - self.add = function(tab) { - var li = K('
      • ' + tab.title + '
      • '); - li.data('tab', tab); - liList.push(li); - ul.append(li); - }; - self.selectedIndex = 0; - self.select = function(index) { - self.selectedIndex = index; - _each(liList, function(i, li) { - li.unbind(); - if (i === index) { - li.addClass('ke-tabs-li-selected'); - K(li.data('tab').panel).show(''); - } else { - li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on') - .mouseover(function() { - K(this).addClass('ke-tabs-li-on'); - }) - .mouseout(function() { - K(this).removeClass('ke-tabs-li-on'); - }) - .click(function() { - self.select(i); - }); - K(li.data('tab').panel).hide(); - } - }); - if (afterSelect) { - afterSelect.call(self, index); - } - }; - self.remove = function() { - _each(liList, function() { - this.remove(); - }); - ul.remove(); - remove.call(self); - }; - return self; -} -K.tabs = _tabs; -function _loadScript(url, fn) { - var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), - script = document.createElement('script'); - head.appendChild(script); - script.src = url; - script.charset = 'utf-8'; - script.onload = script.onreadystatechange = function() { - if (!this.readyState || this.readyState === 'loaded') { - if (fn) { - fn(); - } - script.onload = script.onreadystatechange = null; - head.removeChild(script); - } - }; -} -function _chopQuery(url) { - var index = url.indexOf('?'); - return index > 0 ? url.substr(0, index) : url; -} -function _loadStyle(url) { - var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), - link = document.createElement('link'), - absoluteUrl = _chopQuery(_formatUrl(url, 'absolute')); - var links = K('link[rel="stylesheet"]', head); - for (var i = 0, len = links.length; i < len; i++) { - if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) { - return; - } - } - head.appendChild(link); - link.href = url; - link.rel = 'stylesheet'; -} -function _ajax(url, fn, method, param, dataType) { - method = method || 'GET'; - dataType = dataType || 'json'; - var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); - xhr.open(method, url, true); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && xhr.status == 200) { - if (fn) { - var data = _trim(xhr.responseText); - if (dataType == 'json') { - data = _json(data); - } - fn(data); - } - } - }; - if (method == 'POST') { - var params = []; - _each(param, function(key, val) { - params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); - }); - try { - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - } catch (e) {} - xhr.send(params.join('&')); - } else { - xhr.send(null); - } -} -K.loadScript = _loadScript; -K.loadStyle = _loadStyle; -K.ajax = _ajax; -var _plugins = {}; -function _plugin(name, fn) { - if (name === undefined) { - return _plugins; - } - if (!fn) { - return _plugins[name]; - } - _plugins[name] = fn; -} -var _language = {}; -function _parseLangKey(key) { - var match, ns = 'core'; - if ((match = /^(\w+)\.(\w+)$/.exec(key))) { - ns = match[1]; - key = match[2]; - } - return { ns : ns, key : key }; -} -function _lang(mixed, langType) { - langType = langType === undefined ? K.options.langType : langType; - if (typeof mixed === 'string') { - if (!_language[langType]) { - return 'no language'; - } - var pos = mixed.length - 1; - if (mixed.substr(pos) === '.') { - return _language[langType][mixed.substr(0, pos)]; - } - var obj = _parseLangKey(mixed); - return _language[langType][obj.ns][obj.key]; - } - _each(mixed, function(key, val) { - var obj = _parseLangKey(key); - if (!_language[langType]) { - _language[langType] = {}; - } - if (!_language[langType][obj.ns]) { - _language[langType][obj.ns] = {}; - } - _language[langType][obj.ns][obj.key] = val; - }); -} -function _getImageFromRange(range, fn) { - if (range.collapsed) { - return; - } - range = range.cloneRange().up(); - var sc = range.startContainer, so = range.startOffset; - if (!_WEBKIT && !range.isControl()) { - return; - } - var img = K(sc.childNodes[so]); - if (!img || img.name != 'img') { - return; - } - if (fn(img)) { - return img; - } -} -function _bindContextmenuEvent() { - var self = this, doc = self.edit.doc; - K(doc).contextmenu(function(e) { - if (self.menu) { - self.hideMenu(); - } - if (!self.useContextmenu) { - e.preventDefault(); - return; - } - if (self._contextmenus.length === 0) { - return; - } - var maxWidth = 0, items = []; - _each(self._contextmenus, function() { - if (this.title == '-') { - items.push(this); - return; - } - if (this.cond && this.cond()) { - items.push(this); - if (this.width && this.width > maxWidth) { - maxWidth = this.width; - } - } - }); - while (items.length > 0 && items[0].title == '-') { - items.shift(); - } - while (items.length > 0 && items[items.length - 1].title == '-') { - items.pop(); - } - var prevItem = null; - _each(items, function(i) { - if (this.title == '-' && prevItem.title == '-') { - delete items[i]; - } - prevItem = this; - }); - if (items.length > 0) { - e.preventDefault(); - var pos = K(self.edit.iframe).pos(), - menu = _menu({ - x : pos.x + e.clientX, - y : pos.y + e.clientY, - width : maxWidth, - css : { visibility: 'hidden' }, - shadowMode : self.shadowMode - }); - _each(items, function() { - if (this.title) { - menu.addItem(this); - } - }); - var docEl = _docElement(menu.doc), - menuHeight = menu.div.height(); - if (e.clientY + menuHeight >= docEl.clientHeight - 100) { - menu.pos(menu.x, _removeUnit(menu.y) - menuHeight); - } - menu.div.css('visibility', 'visible'); - self.menu = menu; - } - }); -} -function _bindNewlineEvent() { - var self = this, doc = self.edit.doc, newlineTag = self.newlineTag; - if (_IE && newlineTag !== 'br') { - return; - } - if (_GECKO && _V < 3 && newlineTag !== 'p') { - return; - } - if (_OPERA && _V < 9) { - return; - } - var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'), - pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote'); - function getAncestorTagName(range) { - var ancestor = K(range.commonAncestor()); - while (ancestor) { - if (ancestor.type == 1 && !ancestor.isStyle()) { - break; - } - ancestor = ancestor.parent(); - } - return ancestor.name; - } - K(doc).keydown(function(e) { - if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { - return; - } - self.cmd.selection(); - var tagName = getAncestorTagName(self.cmd.range); - if (tagName == 'marquee' || tagName == 'select') { - return; - } - if (newlineTag === 'br' && !brSkipTagMap[tagName]) { - e.preventDefault(); - self.insertHtml('
        ' + (_IE && _V < 9 ? '' : '\u200B')); - return; - } - if (!pSkipTagMap[tagName]) { - _nativeCommand(doc, 'formatblock', '

        '); - } - }); - K(doc).keyup(function(e) { - if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { - return; - } - if (newlineTag == 'br') { - return; - } - if (_GECKO) { - var root = self.cmd.commonAncestor('p'); - var a = self.cmd.commonAncestor('a'); - if (a && a.text() == '') { - a.remove(true); - self.cmd.range.selectNodeContents(root[0]).collapse(true); - self.cmd.select(); - } - return; - } - self.cmd.selection(); - var tagName = getAncestorTagName(self.cmd.range); - if (tagName == 'marquee' || tagName == 'select') { - return; - } - if (!pSkipTagMap[tagName]) { - _nativeCommand(doc, 'formatblock', '

        '); - } - var div = self.cmd.commonAncestor('div'); - if (div) { - var p = K('

        '), - child = div[0].firstChild; - while (child) { - var next = child.nextSibling; - p.append(child); - child = next; - } - div.before(p); - div.remove(); - self.cmd.range.selectNodeContents(p[0]); - self.cmd.select(); - } - }); -} -function _bindTabEvent() { - var self = this, doc = self.edit.doc; - K(doc).keydown(function(e) { - if (e.which == 9) { - e.preventDefault(); - if (self.afterTab) { - self.afterTab.call(self, e); - return; - } - var cmd = self.cmd, range = cmd.range; - range.shrink(); - if (range.collapsed && range.startContainer.nodeType == 1) { - range.insertNode(K('@ ', doc)[0]); - cmd.select(); - } - self.insertHtml('    '); - } - }); -} -function _bindFocusEvent() { - var self = this; - K(self.edit.textarea[0], self.edit.win).focus(function(e) { - if(typeof self.options.enable_at === 'function'){ - self.options.enable_at(); - } - if (self.afterFocus) { - self.afterFocus.call(self, e); - } - }).blur(function(e) { - if (self.afterBlur) { - self.afterBlur.call(self, e); - } - }); -} -function _removeBookmarkTag(html) { - return _trim(html.replace(/]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, '')); -} -function _removeTempTag(html) { - return html.replace(/]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, ''); -} -function _addBookmarkToStack(stack, bookmark) { - if (stack.length === 0) { - stack.push(bookmark); - return; - } - var prev = stack[stack.length - 1]; - if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) { - stack.push(bookmark); - } -} -function _undoToRedo(fromStack, toStack) { - var self = this, edit = self.edit, - body = edit.doc.body, - range, bookmark; - if (fromStack.length === 0) { - return self; - } - if (edit.designMode) { - range = self.cmd.range; - bookmark = range.createBookmark(true); - bookmark.html = body.innerHTML; - } else { - bookmark = { - html : body.innerHTML - }; - } - _addBookmarkToStack(toStack, bookmark); - var prev = fromStack.pop(); - if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) { - prev = fromStack.pop(); - } - if (edit.designMode) { - edit.html(prev.html); - if (prev.start) { - range.moveToBookmark(prev); - self.select(); - } - } else { - K(body).html(_removeBookmarkTag(prev.html)); - } - return self; -} -function KEditor(options) { - var self = this; - self.options = {}; - function setOption(key, val) { - if (KEditor.prototype[key] === undefined) { - self[key] = val; - } - self.options[key] = val; - } - _each(options, function(key, val) { - setOption(key, options[key]); - }); - _each(K.options, function(key, val) { - if (self[key] === undefined) { - setOption(key, val); - } - }); - var se = K(self.srcElement || '').css('width', '100%'); + self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10); + self.iframe.attr('tabindex', self.tabIndex); + self.textarea.attr('tabindex', self.tabIndex); + if (self.width) { + self.setWidth(self.width); + } + if (self.height) { + self.setHeight(self.height); + } + if (self.designMode) { + self.textarea.hide(); + } else { + self.iframe.hide(); + } + function ready() { + var doc = _iframeDoc(self.iframe); + doc.open(); + if (isDocumentDomain) { + doc.domain = document.domain; + } + doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData)); + doc.close(); + self.win = self.iframe[0].contentWindow; + self.doc = doc; + var cmd = _cmd(doc); + self.afterChange(function(e) { + cmd.selection(); + }); + if (_WEBKIT) { + K(doc).click(function(e) { + if (K(e.target).name === 'img') { + cmd.selection(true); + cmd.range.selectNode(e.target); + cmd.select(); + } + }); + } + if (_IE) { + self._mousedownHandler = function() { + var newRange = cmd.range.cloneRange(); + newRange.shrink(); + if (newRange.isControl()) { + self.blur(); + } + }; + K(document).mousedown(self._mousedownHandler); + K(doc).keydown(function(e) { + if (e.which == 8) { + cmd.selection(); + var rng = cmd.range; + if (rng.isControl()) { + rng.collapse(true); + K(rng.startContainer.childNodes[rng.startOffset]).remove(); + e.preventDefault(); + } + } + }); + } + self.cmd = cmd; + self.html(_elementVal(self.srcElement)); + if (_IE) { + doc.body.disabled = true; + doc.body.contentEditable = true; + doc.body.removeAttribute('disabled'); + } else { + doc.designMode = 'on'; + } + if (options.afterCreate) { + options.afterCreate.call(self); + } + } + if (isDocumentDomain) { + self.iframe.bind('load', function(e) { + self.iframe.unbind('load'); + if (_IE) { + ready(); + } else { + setTimeout(ready, 0); + } + }); + } + self.div.append(self.iframe); + self.div.append(self.textarea); + self.srcElement.hide(); + !isDocumentDomain && ready(); + }, + setWidth : function(val) { + var self = this; + val = _addUnit(val); + self.width = val; + self.div.css('width', val); + return self; + }, + setHeight : function(val) { + var self = this; + val = _addUnit(val); + self.height = val; + self.div.css('height', val); + self.iframe.css('height', val); + if ((_IE && _V < 8) || _QUIRKS) { + val = _addUnit(_removeUnit(val) - 2); + } + self.textarea.css('height', val); + return self; + }, + remove : function() { + var self = this, doc = self.doc; + K(doc.body).unbind(); + K(doc).unbind(); + K(self.win).unbind(); + if (self._mousedownHandler) { + K(document).unbind('mousedown', self._mousedownHandler); + } + _elementVal(self.srcElement, self.html()); + self.srcElement.show(); + doc.write(''); + self.iframe.unbind(); + self.textarea.unbind(); + KEdit.parent.remove.call(self); + }, + html : function(val, isFull) { + var self = this, doc = self.doc; + if (self.designMode) { + var body = doc.body; + if (val === undefined) { + if (isFull) { + val = '' + body.parentNode.innerHTML + ''; + } else { + val = body.innerHTML; + } + if (self.beforeGetHtml) { + val = self.beforeGetHtml(val); + } + if (_GECKO && val == '
        ') { + val = ''; + } + return val; + } + if (self.beforeSetHtml) { + val = self.beforeSetHtml(val); + } + if (_IE && _V >= 9) { + val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2'); + } + K(body).html(val); + if (self.afterSetHtml) { + self.afterSetHtml(); + } + return self; + } + if (val === undefined) { + return self.textarea.val(); + } + self.textarea.val(val); + return self; + }, + design : function(bool) { + var self = this, val; + if (bool === undefined ? !self.designMode : bool) { + if (!self.designMode) { + val = self.html(); + self.designMode = true; + self.html(val); + self.textarea.hide(); + self.iframe.show(); + } + } else { + if (self.designMode) { + val = self.html(); + self.designMode = false; + self.html(val); + self.iframe.hide(); + self.textarea.show(); + } + } + return self.focus(); + }, + focus : function() { + var self = this; + self.designMode ? self.win.focus() : self.textarea[0].focus(); + return self; + }, + blur : function() { + var self = this; + if (_IE) { + var input = K('', self.div); + self.div.append(input); + input[0].focus(); + input.remove(); + } else { + self.designMode ? self.win.blur() : self.textarea[0].blur(); + } + return self; + }, + afterChange : function(fn) { + var self = this, doc = self.doc, body = doc.body; + K(doc).keyup(function(e) { + if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) { + fn(e); + } + }); + K(doc).mouseup(fn).contextmenu(fn); + K(self.win).blur(fn); + function timeoutHandler(e) { + setTimeout(function() { + fn(e); + }, 1); + } + K(body).bind('paste', timeoutHandler); + K(body).bind('cut', timeoutHandler); + return self; + } +}); +function _edit(options) { + return new KEdit(options); +} +K.EditClass = KEdit; +K.edit = _edit; +K.iframeDoc = _iframeDoc; +function _selectToolbar(name, fn) { + var self = this, + knode = self.get(name); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + fn(knode); + } +} +function KToolbar(options) { + this.init(options); +} +_extend(KToolbar, KWidget, { + init : function(options) { + var self = this; + KToolbar.parent.init.call(self, options); + self.disableMode = _undef(options.disableMode, false); + self.noDisableItemMap = _toMap(_undef(options.noDisableItems, [])); + self._itemMap = {}; + self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) { + e.preventDefault(); + }).attr('unselectable', 'on'); + function find(target) { + var knode = K(target); + if (knode.hasClass('ke-outline')) { + return knode; + } + if (knode.hasClass('ke-toolbar-icon')) { + return knode.parent(); + } + } + function hover(e, method) { + var knode = find(e.target); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + if (knode.hasClass('ke-selected')) { + return; + } + knode[method]('ke-on'); + } + } + self.div.mouseover(function(e) { + hover(e, 'addClass'); + }) + .mouseout(function(e) { + hover(e, 'removeClass'); + }) + .click(function(e) { + var knode = find(e.target); + if (knode) { + if (knode.hasClass('ke-disabled')) { + return; + } + self.options.click.call(this, e, knode.attr('data-name')); + } + }); + }, + get : function(name) { + //if(this._itemMap[name])return this._itemMap[name]; + //return this._itemMap[name]=K("span.ke-icon-"+name,this.div).parent() +// if (this._itemMap[name]) { +// return this._itemMap[name]; +// } +// if($("#define").css('display') == 'block'){ +// pdiv = $("#define") +// }else if($("#full").css('display') == 'block'){ +// pdiv = $("#full") +// } + var container = this.div; + if(!$("#define",container).is(':hidden')){ + pdiv = $("#define",container); + }else if(!$("#full",container).is(':hidden')){ + pdiv = $("#full",container); + } + return (this._itemMap[name] = K('span.ke-icon-' + name, pdiv).parent()); + }, + select : function(name) { + _selectToolbar.call(this, name, function(knode) { + knode.addClass('ke-selected'); + }); + return self; + }, + unselect : function(name) { + _selectToolbar.call(this, name, function(knode) { + knode.removeClass('ke-selected').removeClass('ke-on'); + }); + return self; + }, + enable : function(name) { + var self = this, + knode = name.get ? name : self.get(name); + if (knode) { + knode.removeClass('ke-disabled'); + knode.opacity(1); + } + return self; + }, + disable : function(name) { + var self = this, + knode = name.get ? name : self.get(name); + if (knode) { + knode.removeClass('ke-selected').addClass('ke-disabled'); + knode.opacity(0.5); + } + return self; + }, + disableAll : function(bool, noDisableItems) { + var self = this, map = self.noDisableItemMap, item; + if (noDisableItems) { + map = _toMap(noDisableItems); + } + if (bool === undefined ? !self.disableMode : bool) { + K('span.ke-outline', self.div).each(function() { + var knode = K(this), + name = knode[0].getAttribute('data-name', 2); + if (!map[name]) { + self.disable(knode); + } + }); + self.disableMode = true; + } else { + K('span.ke-outline', self.div).each(function() { + var knode = K(this), + name = knode[0].getAttribute('data-name', 2); + if (!map[name]) { + self.enable(knode); + } + }); + self.disableMode = false; + } + return self; + } +}); +function _toolbar(options) { + return new KToolbar(options); +} +K.ToolbarClass = KToolbar; +K.toolbar = _toolbar; +function KMenu(options) { + this.init(options); +} +_extend(KMenu, KWidget, { + init : function(options) { + var self = this; + options.z = options.z || 811213; + KMenu.parent.init.call(self, options); + self.centerLineMode = _undef(options.centerLineMode, true); + self.div.addClass('ke-menu').bind('click,mousedown', function(e){ + e.stopPropagation(); + }).attr('unselectable', 'on'); + }, + addItem : function(item) { + var self = this; + if (item.title === '-') { + self.div.append(K('
        ')); + return; + } + var itemDiv = K('
        '), + leftDiv = K('
        '), + rightDiv = K('
        '), + height = _addUnit(item.height), + iconClass = _undef(item.iconClass, ''); + self.div.append(itemDiv); + if (height) { + itemDiv.css('height', height); + rightDiv.css('line-height', height); + } + var centerDiv; + if (self.centerLineMode) { + centerDiv = K('
        '); + if (height) { + centerDiv.css('height', height); + } + } + itemDiv.mouseover(function(e) { + K(this).addClass('ke-menu-item-on'); + if (centerDiv) { + centerDiv.addClass('ke-menu-item-center-on'); + } + }) + .mouseout(function(e) { + K(this).removeClass('ke-menu-item-on'); + if (centerDiv) { + centerDiv.removeClass('ke-menu-item-center-on'); + } + }) + .click(function(e) { + item.click.call(K(this)); + e.stopPropagation(); + }) + .append(leftDiv); + if (centerDiv) { + itemDiv.append(centerDiv); + } + itemDiv.append(rightDiv); + if (item.checked) { + iconClass = 'ke-icon-checked'; + } + if (iconClass !== '') { + leftDiv.html(''); + } + rightDiv.html(item.title); + return self; + }, + remove : function() { + var self = this; + if (self.options.beforeRemove) { + self.options.beforeRemove.call(self); + } + K('.ke-menu-item', self.div[0]).unbind(); + KMenu.parent.remove.call(self); + return self; + } +}); +function _menu(options) { + return new KMenu(options); +} +K.MenuClass = KMenu; +K.menu = _menu; +function KColorPicker(options) { + this.init(options); +} +_extend(KColorPicker, KWidget, { + init : function(options) { + var self = this; + options.z = options.z || 811213; + KColorPicker.parent.init.call(self, options); + var colors = options.colors || [ + ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'], + ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'], + ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'], + ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'] + ]; + self.selectedColor = (options.selectedColor || '').toLowerCase(); + self._cells = []; + self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){ + e.stopPropagation(); + }).attr('unselectable', 'on'); + var table = self.doc.createElement('table'); + self.div.append(table); + table.className = 'ke-colorpicker-table'; + table.cellPadding = 0; + table.cellSpacing = 0; + table.border = 0; + var row = table.insertRow(0), cell = row.insertCell(0); + cell.colSpan = colors[0].length; + self._addAttr(cell, '', 'ke-colorpicker-cell-top'); + for (var i = 0; i < colors.length; i++) { + row = table.insertRow(i + 1); + for (var j = 0; j < colors[i].length; j++) { + cell = row.insertCell(j); + self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell'); + } + } + }, + _addAttr : function(cell, color, cls) { + var self = this; + cell = K(cell).addClass(cls); + if (self.selectedColor === color.toLowerCase()) { + cell.addClass('ke-colorpicker-cell-selected'); + } + cell.attr('title', color || self.options.noColor); + cell.mouseover(function(e) { + K(this).addClass('ke-colorpicker-cell-on'); + }); + cell.mouseout(function(e) { + K(this).removeClass('ke-colorpicker-cell-on'); + }); + cell.click(function(e) { + e.stop(); + self.options.click.call(K(this), color); + }); + if (color) { + cell.append(K('
        ').css('background-color', color)); + } else { + cell.html(self.options.noColor); + } + K(cell).attr('unselectable', 'on'); + self._cells.push(cell); + }, + remove : function() { + var self = this; + _each(self._cells, function() { + this.unbind(); + }); + KColorPicker.parent.remove.call(self); + return self; + } +}); +function _colorpicker(options) { + return new KColorPicker(options); +} +K.ColorPickerClass = KColorPicker; +K.colorpicker = _colorpicker; +function KUploadButton(options) { + this.init(options); +} +_extend(KUploadButton, { + init : function(options) { + //dump_obj(options); + var self = this, + button = K(options.button), + fieldName = options.fieldName || 'file', + url = options.url || '', + title = button.val(), + extraParams = options.extraParams || {}, + cls = button[0].className || '', + target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime(); + options.afterError = options.afterError || function(str) { + alert(str); + }; + var hiddenElements = []; + for(var k in extraParams){ + hiddenElements.push(''); + } + var html = [ + '
        ', + (options.target ? '' : ''), + (options.form ? '
        ' : '
        '), + '', + hiddenElements.join(''), + '', + '', + '', + (options.form ? '
        ' : ''), + '
        '].join(''); + var div = K(html, button.doc); + $(div).hide()// 如果 以后要用根据 http://kindeditor.net/docs/uploadbutton.html#k-uploadbutton-options来使用uploadButton,那么这里的button会 是隐藏的 + button.hide(); + button.before(div); + self.div = div; + if(options.ops!=undefined)options.ops.up_file_div = div;//options.ops是KindEditor.create()的options参数 + self.button = button; + self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div); + self.form = options.form ? K(options.form) : K('form', div); + self.fileBox = K('.ke-upload-file', div); + var width = options.width || K('.ke-button-common', div).width(); + K('.ke-upload-area', div).width(width); + self.options = options; + }, + submit : function() { + var self = this, + iframe = self.iframe; + iframe.bind('load', function() { + iframe.unbind(); + var tempForm = document.createElement('form'); + self.fileBox.before(tempForm); + K(tempForm).append(self.fileBox); + tempForm.reset(); + K(tempForm).remove(true); + var doc = K.iframeDoc(iframe), + pre = doc.getElementsByTagName('pre')[0], + str = '', data; + if (pre) { + str = pre.innerHTML; + } else { + str = doc.body.innerHTML; + } + str = _unescape(str); + iframe[0].src = 'javascript:false'; + try { + data = K.json(str); + } catch (e) { + self.options.afterError.call(self, '' + doc.body.parentNode.innerHTML + ''); + } + if (data) { + self.options.afterUpload.call(self, data); + } + }); + self.form[0].submit(); + return self; + }, + remove : function() { + var self = this; + if (self.fileBox) { + self.fileBox.unbind(); + } + self.iframe.remove(); + self.div.remove(); + self.button.show(); + return self; + } +}); +function _uploadbutton(options) { + return new KUploadButton(options); +} +K.UploadButtonClass = KUploadButton; +K.uploadbutton = _uploadbutton; +function _createButton(arg) { + arg = arg || {}; + var name = arg.name || '', + span = K(''), + btn = K(''); + if (arg.click) { + btn.click(arg.click); + } + span.append(btn); + return span; +} +function KDialog(options) { + this.init(options); +} +_extend(KDialog, KWidget, { + init : function(options) { + var self = this; + var shadowMode = _undef(options.shadowMode, true); + options.z = options.z || 811213; + options.shadowMode = false; + options.autoScroll = _undef(options.autoScroll, true); + KDialog.parent.init.call(self, options); + var title = options.title, + body = K(options.body, self.doc), + previewBtn = options.previewBtn, + yesBtn = options.yesBtn, + noBtn = options.noBtn, + closeBtn = options.closeBtn, + showMask = _undef(options.showMask, true); + self.div.addClass('ke-dialog').bind('click,mousedown', function(e){ + e.stopPropagation(); + }); + var contentDiv = K('
        ').appendTo(self.div); + if (_IE && _V < 7) { + self.iframeMask = K('').appendTo(self.div); + } else if (shadowMode) { + K('
        ').appendTo(self.div); + } + var headerDiv = K('
        '); + contentDiv.append(headerDiv); + headerDiv.html(title); + self.closeIcon = K('').click(closeBtn.click); + headerDiv.append(self.closeIcon); + self.draggable({ + clickEl : headerDiv, + beforeDrag : options.beforeDrag + }); + var bodyDiv = K('
        '); + contentDiv.append(bodyDiv); + bodyDiv.append(body); + var footerDiv = K(''); + if (previewBtn || yesBtn || noBtn) { + contentDiv.append(footerDiv); + } + _each([ + { btn : previewBtn, name : 'preview' }, + { btn : yesBtn, name : 'yes' }, + { btn : noBtn, name : 'no' } + ], function() { + if (this.btn) { + var button = _createButton(this.btn); + button.addClass('ke-dialog-' + this.name); + footerDiv.append(button); + } + }); + if (self.height) { + bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height()); + } + self.div.width(self.div.width()); + self.div.height(self.div.height()); + self.mask = null; + if (showMask) { + var docEl = _docElement(self.doc), + docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth), + docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight); + self.mask = _widget({ + x : 0, + y : 0, + z : self.z - 1, + cls : 'ke-dialog-mask', + width : docWidth, + height : docHeight + }); + } + self.autoPos(self.div.width(), self.div.height()); + self.footerDiv = footerDiv; + self.bodyDiv = bodyDiv; + self.headerDiv = headerDiv; + self.isLoading = false; + }, + setMaskIndex : function(z) { + var self = this; + self.mask.div.css('z-index', z); + }, + showLoading : function(msg) { + msg = _undef(msg, ''); + var self = this, body = self.bodyDiv; + self.loading = K('
        ' + msg + '
        ') + .width(body.width()).height(body.height()) + .css('top', self.headerDiv.height() + 'px'); + body.css('visibility', 'hidden').after(self.loading); + self.isLoading = true; + return self; + }, + hideLoading : function() { + this.loading && this.loading.remove(); + this.bodyDiv.css('visibility', 'visible'); + this.isLoading = false; + return this; + }, + remove : function() { + var self = this; + if (self.options.beforeRemove) { + self.options.beforeRemove.call(self); + } + self.mask && self.mask.remove(); + self.iframeMask && self.iframeMask.remove(); + self.closeIcon.unbind(); + K('input', self.div).unbind(); + K('button', self.div).unbind(); + self.footerDiv.unbind(); + self.bodyDiv.unbind(); + self.headerDiv.unbind(); + K('iframe', self.div).each(function() { + K(this).remove(); + }); + KDialog.parent.remove.call(self); + return self; + } +}); +function _dialog(options) { + return new KDialog(options); +} +K.DialogClass = KDialog; +K.dialog = _dialog; +function _tabs(options) { + var self = _widget(options), + remove = self.remove, + afterSelect = options.afterSelect, + div = self.div, + liList = []; + div.addClass('ke-tabs') + .bind('contextmenu,mousedown,mousemove', function(e) { + e.preventDefault(); + }); + var ul = K('
          '); + div.append(ul); + self.add = function(tab) { + var li = K('
        • ' + tab.title + '
        • '); + li.data('tab', tab); + liList.push(li); + ul.append(li); + }; + self.selectedIndex = 0; + self.select = function(index) { + self.selectedIndex = index; + _each(liList, function(i, li) { + li.unbind(); + if (i === index) { + li.addClass('ke-tabs-li-selected'); + K(li.data('tab').panel).show(''); + } else { + li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on') + .mouseover(function() { + K(this).addClass('ke-tabs-li-on'); + }) + .mouseout(function() { + K(this).removeClass('ke-tabs-li-on'); + }) + .click(function() { + self.select(i); + }); + K(li.data('tab').panel).hide(); + } + }); + if (afterSelect) { + afterSelect.call(self, index); + } + }; + self.remove = function() { + _each(liList, function() { + this.remove(); + }); + ul.remove(); + remove.call(self); + }; + return self; +} +K.tabs = _tabs; +function _loadScript(url, fn) { + var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), + script = document.createElement('script'); + head.appendChild(script); + script.src = url; + script.charset = 'utf-8'; + script.onload = script.onreadystatechange = function() { + if (!this.readyState || this.readyState === 'loaded') { + if (fn) { + fn(); + } + script.onload = script.onreadystatechange = null; + head.removeChild(script); + } + }; +} +function _chopQuery(url) { + var index = url.indexOf('?'); + return index > 0 ? url.substr(0, index) : url; +} +function _loadStyle(url) { + var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement), + link = document.createElement('link'), + absoluteUrl = _chopQuery(_formatUrl(url, 'absolute')); + var links = K('link[rel="stylesheet"]', head); + for (var i = 0, len = links.length; i < len; i++) { + if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) { + return; + } + } + head.appendChild(link); + link.href = url; + link.rel = 'stylesheet'; +} +function _ajax(url, fn, method, param, dataType) { + method = method || 'GET'; + dataType = dataType || 'json'; + var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); + xhr.open(method, url, true); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && xhr.status == 200) { + if (fn) { + var data = _trim(xhr.responseText); + if (dataType == 'json') { + data = _json(data); + } + fn(data); + } + } + }; + if (method == 'POST') { + var params = []; + _each(param, function(key, val) { + params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); + }); + try { + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + } catch (e) {} + xhr.send(params.join('&')); + } else { + xhr.send(null); + } +} +K.loadScript = _loadScript; +K.loadStyle = _loadStyle; +K.ajax = _ajax; +var _plugins = {}; +function _plugin(name, fn) { + if (name === undefined) { + return _plugins; + } + if (!fn) { + return _plugins[name]; + } + _plugins[name] = fn; +} +var _language = {}; +function _parseLangKey(key) { + var match, ns = 'core'; + if ((match = /^(\w+)\.(\w+)$/.exec(key))) { + ns = match[1]; + key = match[2]; + } + return { ns : ns, key : key }; +} +function _lang(mixed, langType) { + langType = langType === undefined ? K.options.langType : langType; + if (typeof mixed === 'string') { + if (!_language[langType]) { + return 'no language'; + } + var pos = mixed.length - 1; + if (mixed.substr(pos) === '.') { + return _language[langType][mixed.substr(0, pos)]; + } + var obj = _parseLangKey(mixed); + return _language[langType][obj.ns][obj.key]; + } + _each(mixed, function(key, val) { + var obj = _parseLangKey(key); + if (!_language[langType]) { + _language[langType] = {}; + } + if (!_language[langType][obj.ns]) { + _language[langType][obj.ns] = {}; + } + _language[langType][obj.ns][obj.key] = val; + }); +} +function _getImageFromRange(range, fn) { + if (range.collapsed) { + return; + } + range = range.cloneRange().up(); + var sc = range.startContainer, so = range.startOffset; + if (!_WEBKIT && !range.isControl()) { + return; + } + var img = K(sc.childNodes[so]); + if (!img || img.name != 'img') { + return; + } + if (fn(img)) { + return img; + } +} +function _bindContextmenuEvent() { + var self = this, doc = self.edit.doc; + K(doc).contextmenu(function(e) { + if (self.menu) { + self.hideMenu(); + } + if (!self.useContextmenu) { + e.preventDefault(); + return; + } + if (self._contextmenus.length === 0) { + return; + } + var maxWidth = 0, items = []; + _each(self._contextmenus, function() { + if (this.title == '-') { + items.push(this); + return; + } + if (this.cond && this.cond()) { + items.push(this); + if (this.width && this.width > maxWidth) { + maxWidth = this.width; + } + } + }); + while (items.length > 0 && items[0].title == '-') { + items.shift(); + } + while (items.length > 0 && items[items.length - 1].title == '-') { + items.pop(); + } + var prevItem = null; + _each(items, function(i) { + if (this.title == '-' && prevItem.title == '-') { + delete items[i]; + } + prevItem = this; + }); + if (items.length > 0) { + e.preventDefault(); + var pos = K(self.edit.iframe).pos(), + menu = _menu({ + x : pos.x + e.clientX, + y : pos.y + e.clientY, + width : maxWidth, + css : { visibility: 'hidden' }, + shadowMode : self.shadowMode + }); + _each(items, function() { + if (this.title) { + menu.addItem(this); + } + }); + var docEl = _docElement(menu.doc), + menuHeight = menu.div.height(); + if (e.clientY + menuHeight >= docEl.clientHeight - 100) { + menu.pos(menu.x, _removeUnit(menu.y) - menuHeight); + } + menu.div.css('visibility', 'visible'); + self.menu = menu; + } + }); +} +function _bindNewlineEvent() { + var self = this, doc = self.edit.doc, newlineTag = self.newlineTag; + if (_IE && newlineTag !== 'br') { + return; + } + if (_GECKO && _V < 3 && newlineTag !== 'p') { + return; + } + if (_OPERA && _V < 9) { + return; + } + var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'), + pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote'); + function getAncestorTagName(range) { + var ancestor = K(range.commonAncestor()); + while (ancestor) { + if (ancestor.type == 1 && !ancestor.isStyle()) { + break; + } + ancestor = ancestor.parent(); + } + return ancestor.name; + } + K(doc).keydown(function(e) { + if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { + return; + } + self.cmd.selection(); + var tagName = getAncestorTagName(self.cmd.range); + if (tagName == 'marquee' || tagName == 'select') { + return; + } + if (newlineTag === 'br' && !brSkipTagMap[tagName]) { + e.preventDefault(); + self.insertHtml('
          ' + (_IE && _V < 9 ? '' : '\u200B')); + return; + } + if (!pSkipTagMap[tagName]) { + _nativeCommand(doc, 'formatblock', '

          '); + } + }); + K(doc).keyup(function(e) { + if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { + return; + } + if (newlineTag == 'br') { + return; + } + if (_GECKO) { + var root = self.cmd.commonAncestor('p'); + var a = self.cmd.commonAncestor('a'); + if (a && a.text() == '') { + a.remove(true); + self.cmd.range.selectNodeContents(root[0]).collapse(true); + self.cmd.select(); + } + return; + } + self.cmd.selection(); + var tagName = getAncestorTagName(self.cmd.range); + if (tagName == 'marquee' || tagName == 'select') { + return; + } + if (!pSkipTagMap[tagName]) { + _nativeCommand(doc, 'formatblock', '

          '); + } + var div = self.cmd.commonAncestor('div'); + if (div) { + var p = K('

          '), + child = div[0].firstChild; + while (child) { + var next = child.nextSibling; + p.append(child); + child = next; + } + div.before(p); + div.remove(); + self.cmd.range.selectNodeContents(p[0]); + self.cmd.select(); + } + }); +} +function _bindTabEvent() { + var self = this, doc = self.edit.doc; + K(doc).keydown(function(e) { + if (e.which == 9) { + e.preventDefault(); + if (self.afterTab) { + self.afterTab.call(self, e); + return; + } + var cmd = self.cmd, range = cmd.range; + range.shrink(); + if (range.collapsed && range.startContainer.nodeType == 1) { + range.insertNode(K('@ ', doc)[0]); + cmd.select(); + } + self.insertHtml('    '); + } + }); +} +function _bindFocusEvent() { + var self = this; + K(self.edit.textarea[0], self.edit.win).focus(function(e) { + if(typeof self.options.enable_at === 'function'){ + self.options.enable_at(); + } + if (self.afterFocus) { + self.afterFocus.call(self, e); + } + }).blur(function(e) { + if (self.afterBlur) { + self.afterBlur.call(self, e); + } + }); +} +function _removeBookmarkTag(html) { + return _trim(html.replace(/]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, '')); +} +function _removeTempTag(html) { + return html.replace(/]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, ''); +} +function _addBookmarkToStack(stack, bookmark) { + if (stack.length === 0) { + stack.push(bookmark); + return; + } + var prev = stack[stack.length - 1]; + if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) { + stack.push(bookmark); + } +} +function _undoToRedo(fromStack, toStack) { + var self = this, edit = self.edit, + body = edit.doc.body, + range, bookmark; + if (fromStack.length === 0) { + return self; + } + if (edit.designMode) { + range = self.cmd.range; + bookmark = range.createBookmark(true); + bookmark.html = body.innerHTML; + } else { + bookmark = { + html : body.innerHTML + }; + } + _addBookmarkToStack(toStack, bookmark); + var prev = fromStack.pop(); + if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) { + prev = fromStack.pop(); + } + if (edit.designMode) { + edit.html(prev.html); + if (prev.start) { + range.moveToBookmark(prev); + self.select(); + } + } else { + K(body).html(_removeBookmarkTag(prev.html)); + } + return self; +} +function KEditor(options) { + var self = this; + self.options = {}; + function setOption(key, val) { + if (KEditor.prototype[key] === undefined) { + self[key] = val; + } + self.options[key] = val; + } + _each(options, function(key, val) { + setOption(key, options[key]); + }); + _each(K.options, function(key, val) { + if (self[key] === undefined) { + setOption(key, val); + } + }); + var se = K(self.srcElement || '