mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 16:33:22 +00:00
增加 simditor 的自动板寸
This commit is contained in:
parent
5f45c32045
commit
489383c920
@ -60,6 +60,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator", "pag
|
|||||||
if (!data.code) {
|
if (!data.code) {
|
||||||
bsAlert("修改成功");
|
bsAlert("修改成功");
|
||||||
vm.isEditing = false;
|
vm.isEditing = false;
|
||||||
|
localStorage.removeItem("/admin/autosave/edit-announcement-editor/");
|
||||||
getPage(1);
|
getPage(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -119,6 +120,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator", "pag
|
|||||||
bsAlert("提交成功!");
|
bsAlert("提交成功!");
|
||||||
$("#title").val("");
|
$("#title").val("");
|
||||||
createAnnouncementEditor.setValue("");
|
createAnnouncementEditor.setValue("");
|
||||||
|
localStorage.removeItem("/admin/autosave/create-announcement-editor/");
|
||||||
getPage(1);
|
getPage(1);
|
||||||
} else {
|
} else {
|
||||||
bsAlert(data.data);
|
bsAlert(data.data);
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
"simple-module": "lib/simditor/module",
|
"simple-module": "lib/simditor/module",
|
||||||
"simple-hotkeys": "lib/simditor/hotkeys",
|
"simple-hotkeys": "lib/simditor/hotkeys",
|
||||||
"simple-uploader": "lib/simditor/uploader",
|
"simple-uploader": "lib/simditor/uploader",
|
||||||
|
"simditor-autosave": "lib/simditor/simditor-autosave",
|
||||||
|
|
||||||
//code mirror 代码编辑器 ->codeMirror
|
//code mirror 代码编辑器 ->codeMirror
|
||||||
_codeMirror: "lib/codeMirror/codemirror",
|
_codeMirror: "lib/codeMirror/codemirror",
|
||||||
|
@ -34,6 +34,7 @@ var require = {
|
|||||||
"simple-module": "lib/simditor/module",
|
"simple-module": "lib/simditor/module",
|
||||||
"simple-hotkeys": "lib/simditor/hotkeys",
|
"simple-hotkeys": "lib/simditor/hotkeys",
|
||||||
"simple-uploader": "lib/simditor/uploader",
|
"simple-uploader": "lib/simditor/uploader",
|
||||||
|
"simditor-autosave": "lib/simditor/simditor-autosave",
|
||||||
|
|
||||||
//code mirror 代码编辑器 ->codeMirror
|
//code mirror 代码编辑器 ->codeMirror
|
||||||
_codeMirror: "lib/codeMirror/codemirror",
|
_codeMirror: "lib/codeMirror/codemirror",
|
||||||
|
138
static/src/js/lib/simditor/simditor-autosave.js
Normal file
138
static/src/js/lib/simditor/simditor-autosave.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
(function (root, factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD. Register as an anonymous module unless amdModuleId is set
|
||||||
|
define('simditor-autosave', ["jquery","simple-module","simditor"], function (a0,b1,c2) {
|
||||||
|
return (root['SimditorAutosave'] = factory(a0,b1,c2));
|
||||||
|
});
|
||||||
|
} else if (typeof exports === 'object') {
|
||||||
|
// Node. Does not work with strict CommonJS, but
|
||||||
|
// only CommonJS-like environments that support module.exports,
|
||||||
|
// like Node.
|
||||||
|
module.exports = factory(require("jquery"),require("simple-module"),require("simditor"));
|
||||||
|
} else {
|
||||||
|
root['SimditorAutosave'] = factory(jQuery,SimpleModule,Simditor);
|
||||||
|
}
|
||||||
|
}(this, function ($, SimpleModule, Simditor) {
|
||||||
|
|
||||||
|
var SimditorAutosave,
|
||||||
|
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||||
|
hasProp = {}.hasOwnProperty;
|
||||||
|
|
||||||
|
SimditorAutosave = (function(superClass) {
|
||||||
|
extend(SimditorAutosave, superClass);
|
||||||
|
|
||||||
|
function SimditorAutosave() {
|
||||||
|
return SimditorAutosave.__super__.constructor.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimditorAutosave.pluginName = 'Autosave';
|
||||||
|
|
||||||
|
SimditorAutosave.prototype.opts = {
|
||||||
|
autosave: true,
|
||||||
|
autosavePath: null
|
||||||
|
};
|
||||||
|
|
||||||
|
SimditorAutosave.prototype._init = function() {
|
||||||
|
var currentVal, link, name, val;
|
||||||
|
this.editor = this._module;
|
||||||
|
if (!this.opts.autosave) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.name = typeof this.opts.autosave === 'string' ? this.opts.autosave : 'simditor';
|
||||||
|
if (this.opts.autosavePath) {
|
||||||
|
this.path = this.opts.autosavePath;
|
||||||
|
} else {
|
||||||
|
link = $("<a/>", {
|
||||||
|
href: location.href
|
||||||
|
});
|
||||||
|
name = this.editor.textarea.data('autosave') || this.name;
|
||||||
|
this.path = "/" + (link[0].pathname.replace(/\/$/g, "").replace(/^\//g, "")) + "/autosave/" + name + "/";
|
||||||
|
}
|
||||||
|
if (!this.path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.editor.on("valuechanged", (function(_this) {
|
||||||
|
return function() {
|
||||||
|
return _this.storage.set(_this.path, _this.editor.getValue());
|
||||||
|
};
|
||||||
|
})(this));
|
||||||
|
this.editor.el.closest('form').on('ajax:success.simditor-' + this.editor.id, (function(_this) {
|
||||||
|
return function(e) {
|
||||||
|
return _this.storage.remove(_this.path);
|
||||||
|
};
|
||||||
|
})(this));
|
||||||
|
val = this.storage.get(this.path);
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentVal = this.editor.textarea.val();
|
||||||
|
if (val === currentVal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.editor.textarea.is('[data-autosave-confirm]')) {
|
||||||
|
if (confirm(this.editor.textarea.data('autosave-confirm') || 'Are you sure to restore unsaved changes?')) {
|
||||||
|
return this.editor.setValue(val);
|
||||||
|
} else {
|
||||||
|
return this.storage.remove(this.path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return this.editor.setValue(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SimditorAutosave.prototype.storage = {
|
||||||
|
supported: function() {
|
||||||
|
var error;
|
||||||
|
try {
|
||||||
|
localStorage.setItem('_storageSupported', 'yes');
|
||||||
|
localStorage.removeItem('_storageSupported');
|
||||||
|
return true;
|
||||||
|
} catch (_error) {
|
||||||
|
error = _error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
set: function(key, val, session) {
|
||||||
|
var storage;
|
||||||
|
if (session == null) {
|
||||||
|
session = false;
|
||||||
|
}
|
||||||
|
if (!this.supported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storage = session ? sessionStorage : localStorage;
|
||||||
|
return storage.setItem(key, val);
|
||||||
|
},
|
||||||
|
get: function(key, session) {
|
||||||
|
var storage;
|
||||||
|
if (session == null) {
|
||||||
|
session = false;
|
||||||
|
}
|
||||||
|
if (!this.supported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storage = session ? sessionStorage : localStorage;
|
||||||
|
return storage[key];
|
||||||
|
},
|
||||||
|
remove: function(key, session) {
|
||||||
|
var storage;
|
||||||
|
if (session == null) {
|
||||||
|
session = false;
|
||||||
|
}
|
||||||
|
if (!this.supported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storage = session ? sessionStorage : localStorage;
|
||||||
|
return storage.removeItem(key);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return SimditorAutosave;
|
||||||
|
|
||||||
|
})(SimpleModule);
|
||||||
|
|
||||||
|
Simditor.connect(SimditorAutosave);
|
||||||
|
|
||||||
|
return SimditorAutosave;
|
||||||
|
|
||||||
|
}));
|
@ -1,4 +1,4 @@
|
|||||||
define("editor", ["simditor"], function(Simditor){
|
define("editor", ["simditor", "simditor-autosave"], function(Simditor){
|
||||||
function editor(selector){
|
function editor(selector){
|
||||||
return new Simditor({
|
return new Simditor({
|
||||||
textarea: $(selector),
|
textarea: $(selector),
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
ms-duplex="newTitle"></div>
|
ms-duplex="newTitle"></div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>内容</label>
|
<label>内容</label>
|
||||||
<textarea id="edit-announcement-editor"></textarea>
|
<textarea id="edit-announcement-editor" data-autosave="edit-announcement-editor"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>可见 <input ms-duplex-checked="announcementVisible" type="checkbox"/></label>
|
<label>可见 <input ms-duplex-checked="announcementVisible" type="checkbox"/></label>
|
||||||
@ -62,7 +62,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>内容</label>
|
<label>内容</label>
|
||||||
<textarea id="create-announcement-editor" placeholder="公告内容" maxlength="10000" required>
|
<textarea id="create-announcement-editor" placeholder="公告内容" maxlength="10000" data-autosave="create-announcement-editor" required>
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user