rabin 7 gadi atpakaļ
vecāks
revīzija
bc66480431
1 mainītis faili ar 62 papildinājumiem un 0 dzēšanām
  1. 62 0
      admin/static/js/main.js

+ 62 - 0
admin/static/js/main.js

@@ -1,6 +1,7 @@
 if (typeof(cur) == "undefined" && parent.config.cur) {
 	cur = parent.config.cur
 }
+var editors = [];
 
 function msg(value) {
 	if (!value.data) {
@@ -165,4 +166,65 @@ function request(type, url, data, callback) {
 //跳转页面
 function showPage(url) {
 	location.href = url
+}
+
+function initEditor()
+{
+	if ($('.layui-editor').length) {
+		$ ('.layui-editor').each(function() {
+			var parent = $(this).parent().parent();
+			loadEditor($(this));
+		})
+	}
+}
+function loadEditor(e)
+{	
+	if (!e.length) {
+		return;
+	}
+	var id = e.attr('id');
+	var key = e.attr('key');
+	var toolbar = [
+	  'title'
+	  ,'bold'
+	  ,'italic'
+	  ,'underline'
+	  ,'strikethrough'
+	  ,'fontScale'
+	  ,'color'
+	  ,'ol'
+	  ,'ul'
+	  ,'blockquote'
+	  ,'code'
+	  ,'table'
+	  ,'link'
+	  ,'image'
+	  ,'hr'
+	  ,'indent'
+	  ,'outdent'
+	  ,'alignment'
+	  , '|'
+	  ,'html'
+	];
+
+	if (typeof(editors[id]) == "object") {
+		editors[id].destroy();
+		editors[id] = undefined;
+	}
+
+	if (typeof(editors[id]) == "undefined") {
+		var xsrf = getCookie("_xsrf");
+        var uploadUrl = '/upload?_xsrf='+xsrf;
+		editors[id] = new Simditor( {
+			textarea: e,
+			upload: {
+				url: uploadUrl,
+				params: {key:key},
+				fileKey: 'file',
+				connectionCount: 10,
+				leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
+			},
+			toolbar : toolbar
+        });
+	}
 }