app.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4. var _srcCore = require('../../../src/core');
  5. var _srcCore2 = _interopRequireDefault(_srcCore);
  6. var _srcPlugins = require('../../../src/plugins');
  7. _srcPlugins.DropboxPlugin.connect('target');
  8. },{"../../../src/core":3,"../../../src/plugins":9}],2:[function(require,module,exports){
  9. 'use strict';
  10. Object.defineProperty(exports, '__esModule', {
  11. value: true
  12. });
  13. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  14. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  15. var _default = (function () {
  16. function _default(opts) {
  17. _classCallCheck(this, _default);
  18. // Dictates in what order different plugin types are ran:
  19. this.types = ['presetter', 'selecter', 'uploader'];
  20. // Container for different types of plugins
  21. this.plugins = {};
  22. }
  23. _createClass(_default, [{
  24. key: 'use',
  25. value: function use(Plugin, opts) {
  26. // Instantiate
  27. var plugin = new Plugin(this, opts);
  28. // Save in plugin container
  29. if (!this.plugins[plugin.type]) {
  30. this.plugins[plugin.type] = [];
  31. }
  32. this.plugins[plugin.type].push(plugin);
  33. return this;
  34. }
  35. }, {
  36. key: 'setProgress',
  37. value: function setProgress(plugin, percentage) {
  38. // Any plugin can call this via `this.core.setProgress(this, precentage)`
  39. console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
  40. return this;
  41. }
  42. }, {
  43. key: 'run',
  44. value: function run() {
  45. // Walk over plugins in the order as defined by this.types.
  46. var files = [];
  47. for (var j in this.types) {
  48. var type = this.types[j];
  49. // Walk over all plugins of this type, passing & modifying the files array as we go
  50. for (var i in this.plugins[type]) {
  51. var plugin = this.plugins[type][i];
  52. console.log('--> Now running ' + plugin.type + ' plugin ' + plugin.name + ': ');
  53. files = plugin.run(files);
  54. console.dir(files);
  55. console.log('');
  56. }
  57. }
  58. // core.run is the final step and retuns the results (vs every other method, returning `this`)
  59. // for chainability
  60. return files;
  61. }
  62. }]);
  63. return _default;
  64. })();
  65. exports['default'] = _default;
  66. module.exports = exports['default'];
  67. },{}],3:[function(require,module,exports){
  68. 'use strict';
  69. Object.defineProperty(exports, '__esModule', {
  70. value: true
  71. });
  72. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  73. var _Transloadit = require('./Transloadit');
  74. var _Transloadit2 = _interopRequireDefault(_Transloadit);
  75. exports['default'] = _Transloadit2['default'];
  76. module.exports = exports['default'];
  77. },{"./Transloadit":2}],4:[function(require,module,exports){
  78. 'use strict';
  79. Object.defineProperty(exports, '__esModule', {
  80. value: true
  81. });
  82. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  83. var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
  84. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  85. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  86. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  87. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  88. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  89. // This is how we roll $('.element').toggleClass in non-jQuery world
  90. function toggleClass(el, className) {
  91. // console.log(el);
  92. if (el.classList) {
  93. el.classList.toggle(className);
  94. } else {
  95. var classes = el.className.split(' ');
  96. var existingIndex = classes.indexOf(className);
  97. if (existingIndex >= 0) {
  98. classes.splice(existingIndex, 1);
  99. } else {
  100. classes.push(className);
  101. el.className = classes.join(' ');
  102. }
  103. }
  104. }
  105. var DragDrop = (function (_TransloaditPlugin) {
  106. _inherits(DragDrop, _TransloaditPlugin);
  107. function DragDrop(core, opts) {
  108. _classCallCheck(this, DragDrop);
  109. _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts);
  110. this.type = 'selecter';
  111. this.opts = opts;
  112. console.log(this.opts);
  113. // get the element where Drag & Drop event will occur
  114. this.dropzone = document.querySelectorAll(this.opts.selector)[0];
  115. // crazy stuff so that ‘this’ will behave in class
  116. this.handleDragEnter = this.handleDragEnter.bind(this);
  117. this.handleDragOver = this.handleDragOver.bind(this);
  118. this.handleDrop = this.handleDrop.bind(this);
  119. }
  120. _createClass(DragDrop, [{
  121. key: 'listenForEvents',
  122. value: function listenForEvents() {
  123. this.dropzone.addEventListener('dragenter', this.handleDragEnter);
  124. this.dropzone.addEventListener('dragover', this.handleDragOver);
  125. this.dropzone.addEventListener('drop', this.handleDrop);
  126. console.log('waiting for some files to be dropped on ' + this.opts.selector);
  127. }
  128. }, {
  129. key: 'handleDragEnter',
  130. value: function handleDragEnter(e) {
  131. event.stopPropagation();
  132. event.preventDefault();
  133. toggleClass(this.dropzone, 'is-dragover');
  134. }
  135. }, {
  136. key: 'handleDragOver',
  137. value: function handleDragOver(e) {
  138. e.stopPropagation();
  139. e.preventDefault();
  140. }
  141. }, {
  142. key: 'handleDrop',
  143. value: function handleDrop(e) {
  144. console.log('all right, someone dropped something here...');
  145. e.preventDefault();
  146. toggleClass(this.dropzone, 'is-dragover');
  147. var files = e.dataTransfer.files;
  148. console.log(files);
  149. this.handleFiles(files);
  150. }
  151. }, {
  152. key: 'handleFiles',
  153. value: function handleFiles(files) {
  154. return files;
  155. }
  156. }, {
  157. key: 'run',
  158. value: function run(files) {
  159. this.listenForEvents();
  160. // this.core.setProgress(this, 0);
  161. var selected = [{ name: 'lolcat.jpeg' }];
  162. // this.core.setProgress(this, 100);
  163. // return selected;
  164. }
  165. }]);
  166. return DragDrop;
  167. })(_TransloaditPlugin3['default']);
  168. exports['default'] = DragDrop;
  169. module.exports = exports['default'];
  170. },{"./TransloaditPlugin":7}],5:[function(require,module,exports){
  171. 'use strict';
  172. Object.defineProperty(exports, '__esModule', {
  173. value: true
  174. });
  175. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  176. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  177. var DropboxPlugin = (function () {
  178. function DropboxPlugin() {
  179. _classCallCheck(this, DropboxPlugin);
  180. this.connect = this.connect.bind(this);
  181. this.render = this.render.bind(this);
  182. this.files = [];
  183. this.currentDir = '/';
  184. }
  185. _createClass(DropboxPlugin, [{
  186. key: 'connect',
  187. value: function connect(target) {
  188. this._target = document.getElementById(target);
  189. this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' });
  190. this.client.authDriver(new Dropbox.AuthDriver.Redirect());
  191. this.client.authenticate();
  192. if (this.client.credentials().token) {
  193. this.getDirectory();
  194. }
  195. }
  196. }, {
  197. key: 'authenticate',
  198. value: function authenticate() {}
  199. }, {
  200. key: 'addFile',
  201. value: function addFile() {}
  202. }, {
  203. key: 'getDirectory',
  204. value: function getDirectory() {
  205. var _this = this;
  206. return this.client.readdir(this.currentDir, function (error, entries, stat, statFiles) {
  207. if (error) {
  208. return showError(error); // Something went wrong.
  209. }
  210. return _this.render(statFiles);
  211. });
  212. }
  213. }, {
  214. key: 'run',
  215. value: function run() {}
  216. }, {
  217. key: 'render',
  218. value: function render(files) {
  219. var _this2 = this;
  220. // for each file in the directory, create a list item element
  221. var elems = files.map(function (file, i) {
  222. var icon = file.isFolder ? 'folder' : 'file';
  223. return '<li data-type="' + icon + '" data-name="' + file.name + '"><span>' + icon + ' : </span><span> ' + file.name + '</span></li>';
  224. });
  225. // appends the list items to the target
  226. this._target.innerHTML = elems.sort().join('');
  227. if (this.currentDir.length > 1) {
  228. var _parent = document.createElement('LI');
  229. _parent.setAttribute('data-type', 'parent');
  230. _parent.innerHTML = '<span>...</span>';
  231. this._target.appendChild(_parent);
  232. }
  233. // add an onClick to each list item
  234. var fileElems = this._target.querySelectorAll('li');
  235. Array.prototype.forEach.call(fileElems, function (element) {
  236. var type = element.getAttribute('data-type');
  237. if (type === 'file') {
  238. element.addEventListener('click', function () {
  239. _this2.files.push(element.getAttribute('data-name'));
  240. console.dir('files: ' + _this2.files);
  241. });
  242. } else {
  243. element.addEventListener('dblclick', function () {
  244. var length = _this2.currentDir.split('/').length;
  245. if (type === 'folder') {
  246. _this2.currentDir = '' + _this2.currentDir + element.getAttribute('data-name') + '/';
  247. } else if (type === 'parent') {
  248. _this2.currentDir = _this2.currentDir.split('/').slice(0, length - 2).join('/') + '/';
  249. }
  250. console.log(_this2.currentDir);
  251. _this2.getDirectory();
  252. });
  253. }
  254. });
  255. }
  256. }]);
  257. return DropboxPlugin;
  258. })();
  259. exports['default'] = new DropboxPlugin();
  260. module.exports = exports['default'];
  261. },{}],6:[function(require,module,exports){
  262. 'use strict';
  263. var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
  264. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  265. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  266. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  267. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  268. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  269. var TransloaditBasic = (function (_TransloaditPlugin) {
  270. _inherits(TransloaditBasic, _TransloaditPlugin);
  271. function TransloaditBasic(core, opts) {
  272. _classCallCheck(this, TransloaditBasic);
  273. _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
  274. this.type = 'presetter';
  275. this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' });
  276. }
  277. return TransloaditBasic;
  278. })(_TransloaditPlugin3['default']);
  279. },{"./TransloaditPlugin":7}],7:[function(require,module,exports){
  280. "use strict";
  281. Object.defineProperty(exports, "__esModule", {
  282. value: true
  283. });
  284. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  285. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  286. var TransloaditPlugin = (function () {
  287. // This contains boilerplate that all TransloaditPlugins share - and should not be used
  288. // directly. It also shows which methods final plugins should implement/override,
  289. // this deciding on structure.
  290. function TransloaditPlugin(core, opts) {
  291. _classCallCheck(this, TransloaditPlugin);
  292. this.core = core;
  293. this.opts = opts;
  294. this.name = this.constructor.name;
  295. }
  296. _createClass(TransloaditPlugin, [{
  297. key: "run",
  298. value: function run(files) {
  299. return files;
  300. }
  301. }]);
  302. return TransloaditPlugin;
  303. })();
  304. exports["default"] = TransloaditPlugin;
  305. module.exports = exports["default"];
  306. },{}],8:[function(require,module,exports){
  307. 'use strict';
  308. Object.defineProperty(exports, '__esModule', {
  309. value: true
  310. });
  311. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  312. var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
  313. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  314. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  315. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  316. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  317. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  318. var Tus10 = (function (_TransloaditPlugin) {
  319. _inherits(Tus10, _TransloaditPlugin);
  320. function Tus10(core, opts) {
  321. _classCallCheck(this, Tus10);
  322. _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
  323. this.type = 'uploader';
  324. }
  325. _createClass(Tus10, [{
  326. key: 'run',
  327. value: function run(files) {
  328. this.core.setProgress(this, 0);
  329. var uploaded = [];
  330. for (var i in files) {
  331. var file = files[i];
  332. this.core.setProgress(this, i * 1 + 1);
  333. uploaded[i] = file;
  334. uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name;
  335. }
  336. this.core.setProgress(this, 100);
  337. return uploaded;
  338. }
  339. }]);
  340. return Tus10;
  341. })(_TransloaditPlugin3['default']);
  342. exports['default'] = Tus10;
  343. module.exports = exports['default'];
  344. },{"./TransloaditPlugin":7}],9:[function(require,module,exports){
  345. 'use strict';
  346. Object.defineProperty(exports, '__esModule', {
  347. value: true
  348. });
  349. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  350. var _TransloaditPlugin = require('./TransloaditPlugin');
  351. var _TransloaditPlugin2 = _interopRequireDefault(_TransloaditPlugin);
  352. var _DragDrop = require('./DragDrop');
  353. var _DragDrop2 = _interopRequireDefault(_DragDrop);
  354. var _Dropbox = require('./Dropbox');
  355. var _Dropbox2 = _interopRequireDefault(_Dropbox);
  356. var _TransloaditBasic = require('./TransloaditBasic');
  357. var _TransloaditBasic2 = _interopRequireDefault(_TransloaditBasic);
  358. var _Tus10 = require('./Tus10');
  359. var _Tus102 = _interopRequireDefault(_Tus10);
  360. exports['default'] = {
  361. TransloaditPlugin: _TransloaditPlugin2['default'],
  362. DropboxPlugin: _Dropbox2['default'],
  363. DragDrop: _DragDrop2['default'],
  364. TransloaditBasic: _TransloaditBasic2['default'],
  365. Tus10: _Tus102['default']
  366. };
  367. module.exports = exports['default'];
  368. },{"./DragDrop":4,"./Dropbox":5,"./TransloaditBasic":6,"./TransloaditPlugin":7,"./Tus10":8}]},{},[1]);