添加队列
This commit is contained in:
parent
2a5996e6c1
commit
f855bdbb2b
6
.gitignore
vendored
6
.gitignore
vendored
@ -10,3 +10,9 @@ Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.env
|
||||
_ide_helper.php
|
||||
_ide_helper_models.php
|
||||
public/fonts/
|
||||
public/mix-manifest.json
|
||||
public/uploads/
|
||||
storage/debugbar/.gitignore
|
||||
|
43
app/Jobs/TranslateSlug.php
Normal file
43
app/Jobs/TranslateSlug.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Topic;
|
||||
use App\Tools\SlugTranslateHandler;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class TranslateSlug implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
protected $topic;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
* @param $topic
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Topic $topic)
|
||||
{
|
||||
$this->topic = $topic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// 请求百度 API 接口进行翻译
|
||||
$slug = app(SlugTranslateHandler::class)->translate($this->topic->title);
|
||||
|
||||
// 为了避免模型监控器死循环调用,我们使用 DB 类直接对数据库进行操作
|
||||
\DB::table('topics')->where('id', $this->topic->id)->update(['slug' => $slug]);
|
||||
}
|
||||
}
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Jobs\TranslateSlug;
|
||||
use App\Models\Topic;
|
||||
use App\Tools\SlugTranslateHandler;
|
||||
|
||||
// creating, created, updating, updated, saving,
|
||||
// saved, deleting, deleted, restoring, restored
|
||||
@ -19,9 +19,13 @@ class TopicObserver
|
||||
{
|
||||
$topic->body = clean($topic->body, 'user_topic_body');
|
||||
$topic->excerpt = make_excerpt($topic->body);
|
||||
}
|
||||
|
||||
public function saved(Topic $topic)
|
||||
{
|
||||
// 如 slug 字段无内容,即使用翻译器对 title 进行翻译
|
||||
if (!$topic->slug) {
|
||||
$topic->slug = app(SlugTranslateHandler::class)->translate($topic->title);
|
||||
dispatch(new TranslateSlug($topic));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
||||
"hieu-le/active": "~3.5",
|
||||
"intervention/image": "^2.4",
|
||||
"laravel/framework": "5.5.*",
|
||||
"laravel/horizon": "~1.0",
|
||||
"laravel/tinker": "~1.0",
|
||||
"mews/captcha": "~2.0",
|
||||
"mews/purifier": "~2.0",
|
||||
"overtrue/laravel-lang": "^3.0",
|
||||
"overtrue/pinyin": "~3.0"
|
||||
"overtrue/pinyin": "~3.0",
|
||||
"predis/predis": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.1",
|
||||
|
177
composer.lock
generated
177
composer.lock
generated
@ -4,8 +4,65 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "8d5baf0bc06734b3359648bb624b4f3c",
|
||||
"content-hash": "bb49e11516bee32d2564761364c776dd",
|
||||
"packages": [
|
||||
{
|
||||
"name": "cakephp/chronos",
|
||||
"version": "1.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/chronos.git",
|
||||
"reference": "56d98330d366a469745848b07540373846c40561"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/chronos/zipball/56d98330d366a469745848b07540373846c40561",
|
||||
"reference": "56d98330d366a469745848b07540373846c40561",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.5.9|^7"
|
||||
},
|
||||
"require-dev": {
|
||||
"athletic/athletic": "~0.1",
|
||||
"cakephp/cakephp-codesniffer": "~2.3",
|
||||
"phpbench/phpbench": "@dev",
|
||||
"phpstan/phpstan": "^0.6.4",
|
||||
"phpunit/phpunit": "<6.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Cake\\Chronos\\": "src"
|
||||
},
|
||||
"files": [
|
||||
"src/carbon_compat.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Brian Nesbitt",
|
||||
"email": "brian@nesbot.com",
|
||||
"homepage": "http://nesbot.com"
|
||||
},
|
||||
{
|
||||
"name": "The CakePHP Team",
|
||||
"homepage": "http://cakephp.org"
|
||||
}
|
||||
],
|
||||
"description": "A simple API extension for DateTime.",
|
||||
"homepage": "http://cakephp.org",
|
||||
"keywords": [
|
||||
"date",
|
||||
"datetime",
|
||||
"time"
|
||||
],
|
||||
"time": "2017-12-25T22:42:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "caouecs/laravel-lang",
|
||||
"version": "3.0.39",
|
||||
@ -1298,6 +1355,74 @@
|
||||
],
|
||||
"time": "2017-12-26T16:24:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/horizon",
|
||||
"version": "v1.0.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/horizon.git",
|
||||
"reference": "20ec777c3f007a4b026b93f63be6672b2fa3b43b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/horizon/zipball/20ec777c3f007a4b026b93f63be6672b2fa3b43b",
|
||||
"reference": "20ec777c3f007a4b026b93f63be6672b2fa3b43b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"cakephp/chronos": "^1.0",
|
||||
"ext-pcntl": "*",
|
||||
"ext-posix": "*",
|
||||
"illuminate/contracts": "~5.5",
|
||||
"illuminate/queue": "~5.5",
|
||||
"illuminate/support": "~5.5",
|
||||
"php": ">=7.1.0",
|
||||
"predis/predis": "^1.1",
|
||||
"ramsey/uuid": "^3.5",
|
||||
"symfony/debug": "~3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "~1.0",
|
||||
"orchestra/database": "~3.5",
|
||||
"orchestra/testbench": "~3.5",
|
||||
"phpunit/phpunit": "~6.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Horizon\\HorizonServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Horizon": "Laravel\\Horizon\\Horizon"
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Horizon\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "Dashboard and code-driven configuration for Laravel queues.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"queue"
|
||||
],
|
||||
"time": "2017-11-04T18:13:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/tinker",
|
||||
"version": "v1.0.3",
|
||||
@ -1956,6 +2081,56 @@
|
||||
],
|
||||
"time": "2017-09-27T21:40:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "predis/predis",
|
||||
"version": "v1.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nrk/predis.git",
|
||||
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
|
||||
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Allows access to Webdis when paired with phpiredis",
|
||||
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Predis\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniele Alessandri",
|
||||
"email": "suppakilla@gmail.com",
|
||||
"homepage": "http://clorophilla.net"
|
||||
}
|
||||
],
|
||||
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
|
||||
"homepage": "http://github.com/nrk/predis",
|
||||
"keywords": [
|
||||
"nosql",
|
||||
"predis",
|
||||
"redis"
|
||||
],
|
||||
"time": "2016-06-16T16:22:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.0.0",
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
}
|
865
resources/assets/editor/css/simditor.css
vendored
Normal file
865
resources/assets/editor/css/simditor.css
vendored
Normal file
File diff suppressed because one or more lines are too long
254
resources/assets/editor/js/hotkeys.js
vendored
Normal file
254
resources/assets/editor/js/hotkeys.js
vendored
Normal file
@ -0,0 +1,254 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module unless amdModuleId is set
|
||||
define('simple-hotkeys', ["jquery", "simple-module"], function ($, SimpleModule) {
|
||||
return (root['hotkeys'] = factory($, SimpleModule));
|
||||
});
|
||||
} 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"));
|
||||
} else {
|
||||
root.simple = root.simple || {};
|
||||
root.simple['hotkeys'] = factory(jQuery, SimpleModule);
|
||||
}
|
||||
}(this, function ($, SimpleModule) {
|
||||
|
||||
var Hotkeys, hotkeys,
|
||||
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;
|
||||
|
||||
Hotkeys = (function (superClass) {
|
||||
extend(Hotkeys, superClass);
|
||||
|
||||
function Hotkeys() {
|
||||
return Hotkeys.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Hotkeys.count = 0;
|
||||
|
||||
Hotkeys.keyNameMap = {
|
||||
8: "Backspace",
|
||||
9: "Tab",
|
||||
13: "Enter",
|
||||
16: "Shift",
|
||||
17: "Control",
|
||||
18: "Alt",
|
||||
19: "Pause",
|
||||
20: "CapsLock",
|
||||
27: "Esc",
|
||||
32: "Spacebar",
|
||||
33: "PageUp",
|
||||
34: "PageDown",
|
||||
35: "End",
|
||||
36: "Home",
|
||||
37: "Left",
|
||||
38: "Up",
|
||||
39: "Right",
|
||||
40: "Down",
|
||||
45: "Insert",
|
||||
46: "Del",
|
||||
91: "Meta",
|
||||
93: "Meta",
|
||||
48: "0",
|
||||
49: "1",
|
||||
50: "2",
|
||||
51: "3",
|
||||
52: "4",
|
||||
53: "5",
|
||||
54: "6",
|
||||
55: "7",
|
||||
56: "8",
|
||||
57: "9",
|
||||
65: "A",
|
||||
66: "B",
|
||||
67: "C",
|
||||
68: "D",
|
||||
69: "E",
|
||||
70: "F",
|
||||
71: "G",
|
||||
72: "H",
|
||||
73: "I",
|
||||
74: "J",
|
||||
75: "K",
|
||||
76: "L",
|
||||
77: "M",
|
||||
78: "N",
|
||||
79: "O",
|
||||
80: "P",
|
||||
81: "Q",
|
||||
82: "R",
|
||||
83: "S",
|
||||
84: "T",
|
||||
85: "U",
|
||||
86: "V",
|
||||
87: "W",
|
||||
88: "X",
|
||||
89: "Y",
|
||||
90: "Z",
|
||||
96: "0",
|
||||
97: "1",
|
||||
98: "2",
|
||||
99: "3",
|
||||
100: "4",
|
||||
101: "5",
|
||||
102: "6",
|
||||
103: "7",
|
||||
104: "8",
|
||||
105: "9",
|
||||
106: "Multiply",
|
||||
107: "Add",
|
||||
109: "Subtract",
|
||||
110: "Decimal",
|
||||
111: "Divide",
|
||||
112: "F1",
|
||||
113: "F2",
|
||||
114: "F3",
|
||||
115: "F4",
|
||||
116: "F5",
|
||||
117: "F6",
|
||||
118: "F7",
|
||||
119: "F8",
|
||||
120: "F9",
|
||||
121: "F10",
|
||||
122: "F11",
|
||||
123: "F12",
|
||||
124: "F13",
|
||||
125: "F14",
|
||||
126: "F15",
|
||||
127: "F16",
|
||||
128: "F17",
|
||||
129: "F18",
|
||||
130: "F19",
|
||||
131: "F20",
|
||||
132: "F21",
|
||||
133: "F22",
|
||||
134: "F23",
|
||||
135: "F24",
|
||||
59: ";",
|
||||
61: "=",
|
||||
186: ";",
|
||||
187: "=",
|
||||
188: ",",
|
||||
190: ".",
|
||||
191: "/",
|
||||
192: "`",
|
||||
219: "[",
|
||||
220: "\\",
|
||||
221: "]",
|
||||
222: "'"
|
||||
};
|
||||
|
||||
Hotkeys.aliases = {
|
||||
"escape": "esc",
|
||||
"delete": "del",
|
||||
"return": "enter",
|
||||
"ctrl": "control",
|
||||
"space": "spacebar",
|
||||
"ins": "insert",
|
||||
"cmd": "meta",
|
||||
"command": "meta",
|
||||
"wins": "meta",
|
||||
"windows": "meta"
|
||||
};
|
||||
|
||||
Hotkeys.normalize = function (shortcut) {
|
||||
var i, j, key, keyname, keys, len;
|
||||
keys = shortcut.toLowerCase().replace(/\s+/gi, "").split("+");
|
||||
for (i = j = 0, len = keys.length; j < len; i = ++j) {
|
||||
key = keys[i];
|
||||
keys[i] = this.aliases[key] || key;
|
||||
}
|
||||
keyname = keys.pop();
|
||||
keys.sort().push(keyname);
|
||||
return keys.join("_");
|
||||
};
|
||||
|
||||
Hotkeys.prototype.opts = {
|
||||
el: document
|
||||
};
|
||||
|
||||
Hotkeys.prototype._init = function () {
|
||||
this.id = ++this.constructor.count;
|
||||
this._map = {};
|
||||
this._delegate = typeof this.opts.el === "string" ? document : this.opts.el;
|
||||
return $(this._delegate).on("keydown.simple-hotkeys-" + this.id, this.opts.el, (function (_this) {
|
||||
return function (e) {
|
||||
var ref;
|
||||
return (ref = _this._getHander(e)) != null ? ref.call(_this, e) : void 0;
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
Hotkeys.prototype._getHander = function (e) {
|
||||
var keyname, shortcut;
|
||||
if (!(keyname = this.constructor.keyNameMap[e.which])) {
|
||||
return;
|
||||
}
|
||||
shortcut = "";
|
||||
if (e.altKey) {
|
||||
shortcut += "alt_";
|
||||
}
|
||||
if (e.ctrlKey) {
|
||||
shortcut += "control_";
|
||||
}
|
||||
if (e.metaKey) {
|
||||
shortcut += "meta_";
|
||||
}
|
||||
if (e.shiftKey) {
|
||||
shortcut += "shift_";
|
||||
}
|
||||
shortcut += keyname.toLowerCase();
|
||||
return this._map[shortcut];
|
||||
};
|
||||
|
||||
Hotkeys.prototype.respondTo = function (subject) {
|
||||
if (typeof subject === 'string') {
|
||||
return this._map[this.constructor.normalize(subject)] != null;
|
||||
} else {
|
||||
return this._getHander(subject) != null;
|
||||
}
|
||||
};
|
||||
|
||||
Hotkeys.prototype.add = function (shortcut, handler) {
|
||||
this._map[this.constructor.normalize(shortcut)] = handler;
|
||||
return this;
|
||||
};
|
||||
|
||||
Hotkeys.prototype.remove = function (shortcut) {
|
||||
delete this._map[this.constructor.normalize(shortcut)];
|
||||
return this;
|
||||
};
|
||||
|
||||
Hotkeys.prototype.destroy = function () {
|
||||
$(this._delegate).off(".simple-hotkeys-" + this.id);
|
||||
this._map = {};
|
||||
return this;
|
||||
};
|
||||
|
||||
return Hotkeys;
|
||||
|
||||
})(SimpleModule);
|
||||
|
||||
hotkeys = function (opts) {
|
||||
return new Hotkeys(opts);
|
||||
};
|
||||
|
||||
return hotkeys;
|
||||
|
||||
}));
|
||||
|
173
resources/assets/editor/js/module.js
vendored
Normal file
173
resources/assets/editor/js/module.js
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module unless amdModuleId is set
|
||||
define('simple-module', ["jquery"], function (a0) {
|
||||
return (root['Module'] = factory(a0));
|
||||
});
|
||||
} 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"));
|
||||
} else {
|
||||
root['SimpleModule'] = factory(jQuery);
|
||||
}
|
||||
}(this, function ($) {
|
||||
|
||||
var Module,
|
||||
slice = [].slice;
|
||||
|
||||
Module = (function () {
|
||||
Module.extend = function (obj) {
|
||||
var key, ref, val;
|
||||
if (!((obj != null) && typeof obj === 'object')) {
|
||||
return;
|
||||
}
|
||||
for (key in obj) {
|
||||
val = obj[key];
|
||||
if (key !== 'included' && key !== 'extended') {
|
||||
this[key] = val;
|
||||
}
|
||||
}
|
||||
return (ref = obj.extended) != null ? ref.call(this) : void 0;
|
||||
};
|
||||
|
||||
Module.include = function (obj) {
|
||||
var key, ref, val;
|
||||
if (!((obj != null) && typeof obj === 'object')) {
|
||||
return;
|
||||
}
|
||||
for (key in obj) {
|
||||
val = obj[key];
|
||||
if (key !== 'included' && key !== 'extended') {
|
||||
this.prototype[key] = val;
|
||||
}
|
||||
}
|
||||
return (ref = obj.included) != null ? ref.call(this) : void 0;
|
||||
};
|
||||
|
||||
Module.connect = function (cls) {
|
||||
if (typeof cls !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (!cls.pluginName) {
|
||||
throw new Error('Module.connect: cannot connect plugin without pluginName');
|
||||
return;
|
||||
}
|
||||
cls.prototype._connected = true;
|
||||
if (!this._connectedClasses) {
|
||||
this._connectedClasses = [];
|
||||
}
|
||||
this._connectedClasses.push(cls);
|
||||
if (cls.pluginName) {
|
||||
return this[cls.pluginName] = cls;
|
||||
}
|
||||
};
|
||||
|
||||
Module.prototype.opts = {};
|
||||
|
||||
function Module(opts) {
|
||||
var base, cls, i, instance, instances, len, name;
|
||||
this.opts = $.extend({}, this.opts, opts);
|
||||
(base = this.constructor)._connectedClasses || (base._connectedClasses = []);
|
||||
instances = (function () {
|
||||
var i, len, ref, results;
|
||||
ref = this.constructor._connectedClasses;
|
||||
results = [];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
cls = ref[i];
|
||||
name = cls.pluginName.charAt(0).toLowerCase() + cls.pluginName.slice(1);
|
||||
if (cls.prototype._connected) {
|
||||
cls.prototype._module = this;
|
||||
}
|
||||
results.push(this[name] = new cls());
|
||||
}
|
||||
return results;
|
||||
}).call(this);
|
||||
if (this._connected) {
|
||||
this.opts = $.extend({}, this.opts, this._module.opts);
|
||||
} else {
|
||||
this._init();
|
||||
for (i = 0, len = instances.length; i < len; i++) {
|
||||
instance = instances[i];
|
||||
if (typeof instance._init === "function") {
|
||||
instance._init();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.trigger('initialized');
|
||||
}
|
||||
|
||||
Module.prototype._init = function () {
|
||||
};
|
||||
|
||||
Module.prototype.on = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
(ref = $(this)).on.apply(ref, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
Module.prototype.one = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
(ref = $(this)).one.apply(ref, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
Module.prototype.off = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
(ref = $(this)).off.apply(ref, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
Module.prototype.trigger = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
(ref = $(this)).trigger.apply(ref, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
Module.prototype.triggerHandler = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
return (ref = $(this)).triggerHandler.apply(ref, args);
|
||||
};
|
||||
|
||||
Module.prototype._t = function () {
|
||||
var args, ref;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
return (ref = this.constructor)._t.apply(ref, args);
|
||||
};
|
||||
|
||||
Module._t = function () {
|
||||
var args, key, ref, result;
|
||||
key = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||
result = ((ref = this.i18n[this.locale]) != null ? ref[key] : void 0) || '';
|
||||
if (!(args.length > 0)) {
|
||||
return result;
|
||||
}
|
||||
result = result.replace(/([^%]|^)%(?:(\d+)\$)?s/g, function (p0, p, position) {
|
||||
if (position) {
|
||||
return p + args[parseInt(position) - 1];
|
||||
} else {
|
||||
return p + args.shift();
|
||||
}
|
||||
});
|
||||
return result.replace(/%%s/g, '%s');
|
||||
};
|
||||
|
||||
Module.i18n = {
|
||||
'zh-CN': {}
|
||||
};
|
||||
|
||||
Module.locale = 'zh-CN';
|
||||
|
||||
return Module;
|
||||
|
||||
})();
|
||||
|
||||
return Module;
|
||||
|
||||
}));
|
5639
resources/assets/editor/js/simditor.js
vendored
Normal file
5639
resources/assets/editor/js/simditor.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
274
resources/assets/editor/js/uploader.js
vendored
Normal file
274
resources/assets/editor/js/uploader.js
vendored
Normal file
@ -0,0 +1,274 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module unless amdModuleId is set
|
||||
define('simple-uploader', ["jquery", "simple-module"], function ($, SimpleModule) {
|
||||
return (root['uploader'] = factory($, SimpleModule));
|
||||
});
|
||||
} 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"));
|
||||
} else {
|
||||
root.simple = root.simple || {};
|
||||
root.simple['uploader'] = factory(jQuery, SimpleModule);
|
||||
}
|
||||
}(this, function ($, SimpleModule) {
|
||||
|
||||
var Uploader, uploader,
|
||||
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;
|
||||
|
||||
Uploader = (function (superClass) {
|
||||
extend(Uploader, superClass);
|
||||
|
||||
function Uploader() {
|
||||
return Uploader.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Uploader.count = 0;
|
||||
|
||||
Uploader.prototype.opts = {
|
||||
url: '',
|
||||
params: null,
|
||||
fileKey: 'upload_file',
|
||||
connectionCount: 3
|
||||
};
|
||||
|
||||
Uploader.prototype._init = function () {
|
||||
this.files = [];
|
||||
this.queue = [];
|
||||
this.id = ++Uploader.count;
|
||||
this.on('uploadcomplete', (function (_this) {
|
||||
return function (e, file) {
|
||||
_this.files.splice($.inArray(file, _this.files), 1);
|
||||
if (_this.queue.length > 0 && _this.files.length < _this.opts.connectionCount) {
|
||||
return _this.upload(_this.queue.shift());
|
||||
} else if (_this.files.length === 0) {
|
||||
return _this.uploading = false;
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
return $(window).on('beforeunload.uploader-' + this.id, (function (_this) {
|
||||
return function (e) {
|
||||
if (!_this.uploading) {
|
||||
return;
|
||||
}
|
||||
e.originalEvent.returnValue = _this._t('leaveConfirm');
|
||||
return _this._t('leaveConfirm');
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
Uploader.prototype.generateId = (function () {
|
||||
var id;
|
||||
id = 0;
|
||||
return function () {
|
||||
return id += 1;
|
||||
};
|
||||
})();
|
||||
|
||||
Uploader.prototype.upload = function (file, opts) {
|
||||
var f, i, key, len;
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
if ($.isArray(file) || file instanceof FileList) {
|
||||
for (i = 0, len = file.length; i < len; i++) {
|
||||
f = file[i];
|
||||
this.upload(f, opts);
|
||||
}
|
||||
} else if ($(file).is('input:file')) {
|
||||
key = $(file).attr('name');
|
||||
if (key) {
|
||||
opts.fileKey = key;
|
||||
}
|
||||
this.upload($.makeArray($(file)[0].files), opts);
|
||||
} else if (!file.id || !file.obj) {
|
||||
file = this.getFile(file);
|
||||
}
|
||||
if (!(file && file.obj)) {
|
||||
return;
|
||||
}
|
||||
$.extend(file, opts);
|
||||
if (this.files.length >= this.opts.connectionCount) {
|
||||
this.queue.push(file);
|
||||
return;
|
||||
}
|
||||
if (this.triggerHandler('beforeupload', [file]) === false) {
|
||||
return;
|
||||
}
|
||||
this.files.push(file);
|
||||
this._xhrUpload(file);
|
||||
return this.uploading = true;
|
||||
};
|
||||
|
||||
Uploader.prototype.getFile = function (fileObj) {
|
||||
var name, ref, ref1;
|
||||
if (fileObj instanceof window.File || fileObj instanceof window.Blob) {
|
||||
name = (ref = fileObj.fileName) != null ? ref : fileObj.name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: this.generateId(),
|
||||
url: this.opts.url,
|
||||
params: this.opts.params,
|
||||
fileKey: this.opts.fileKey,
|
||||
name: name,
|
||||
size: (ref1 = fileObj.fileSize) != null ? ref1 : fileObj.size,
|
||||
ext: name ? name.split('.').pop().toLowerCase() : '',
|
||||
obj: fileObj
|
||||
};
|
||||
};
|
||||
|
||||
Uploader.prototype._xhrUpload = function (file) {
|
||||
var formData, k, ref, v;
|
||||
formData = new FormData();
|
||||
formData.append(file.fileKey, file.obj);
|
||||
formData.append("original_filename", file.name);
|
||||
if (file.params) {
|
||||
ref = file.params;
|
||||
for (k in ref) {
|
||||
v = ref[k];
|
||||
formData.append(k, v);
|
||||
}
|
||||
}
|
||||
return file.xhr = $.ajax({
|
||||
url: file.url,
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'X-File-Name': encodeURIComponent(file.name)
|
||||
},
|
||||
xhr: function () {
|
||||
var req;
|
||||
req = $.ajaxSettings.xhr();
|
||||
if (req) {
|
||||
req.upload.onprogress = (function (_this) {
|
||||
return function (e) {
|
||||
return _this.progress(e);
|
||||
};
|
||||
})(this);
|
||||
}
|
||||
return req;
|
||||
},
|
||||
progress: (function (_this) {
|
||||
return function (e) {
|
||||
if (!e.lengthComputable) {
|
||||
return;
|
||||
}
|
||||
return _this.trigger('uploadprogress', [file, e.loaded, e.total]);
|
||||
};
|
||||
})(this),
|
||||
error: (function (_this) {
|
||||
return function (xhr, status, err) {
|
||||
return _this.trigger('uploaderror', [file, xhr, status]);
|
||||
};
|
||||
})(this),
|
||||
success: (function (_this) {
|
||||
return function (result) {
|
||||
_this.trigger('uploadprogress', [file, file.size, file.size]);
|
||||
_this.trigger('uploadsuccess', [file, result]);
|
||||
return $(document).trigger('uploadsuccess', [file, result, _this]);
|
||||
};
|
||||
})(this),
|
||||
complete: (function (_this) {
|
||||
return function (xhr, status) {
|
||||
return _this.trigger('uploadcomplete', [file, xhr.responseText]);
|
||||
};
|
||||
})(this)
|
||||
});
|
||||
};
|
||||
|
||||
Uploader.prototype.cancel = function (file) {
|
||||
var f, i, len, ref;
|
||||
if (!file.id) {
|
||||
ref = this.files;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
f = ref[i];
|
||||
if (f.id === file * 1) {
|
||||
file = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.trigger('uploadcancel', [file]);
|
||||
if (file.xhr) {
|
||||
file.xhr.abort();
|
||||
}
|
||||
return file.xhr = null;
|
||||
};
|
||||
|
||||
Uploader.prototype.readImageFile = function (fileObj, callback) {
|
||||
var fileReader, img;
|
||||
if (!$.isFunction(callback)) {
|
||||
return;
|
||||
}
|
||||
img = new Image();
|
||||
img.onload = function () {
|
||||
return callback(img);
|
||||
};
|
||||
img.onerror = function () {
|
||||
return callback();
|
||||
};
|
||||
if (window.FileReader && FileReader.prototype.readAsDataURL && /^image/.test(fileObj.type)) {
|
||||
fileReader = new FileReader();
|
||||
fileReader.onload = function (e) {
|
||||
return img.src = e.target.result;
|
||||
};
|
||||
return fileReader.readAsDataURL(fileObj);
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
};
|
||||
|
||||
Uploader.prototype.destroy = function () {
|
||||
var file, i, len, ref;
|
||||
this.queue.length = 0;
|
||||
ref = this.files;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
file = ref[i];
|
||||
this.cancel(file);
|
||||
}
|
||||
$(window).off('.uploader-' + this.id);
|
||||
return $(document).off('.uploader-' + this.id);
|
||||
};
|
||||
|
||||
Uploader.i18n = {
|
||||
'zh-CN': {
|
||||
leaveConfirm: '正在上传文件,如果离开上传会自动取消'
|
||||
}
|
||||
};
|
||||
|
||||
Uploader.locale = 'zh-CN';
|
||||
|
||||
return Uploader;
|
||||
|
||||
})(SimpleModule);
|
||||
|
||||
uploader = function (opts) {
|
||||
return new Uploader(opts);
|
||||
};
|
||||
|
||||
return uploader;
|
||||
|
||||
}));
|
Loading…
Reference in New Issue
Block a user