app.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 back = document.createElement('LI');
  229. back.setAttribute('data-type', 'back');
  230. back.innerHTML = '<span>...</span>';
  231. this._target.appendChild(back);
  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 (e) {
  239. _this2.files.push(element.getAttribute('data-name'));
  240. });
  241. } else {
  242. element.addEventListener('dblclick', function (e) {
  243. console.log(type);
  244. console.log(_this2.currentDir.split('/').slice(0, length - 2));
  245. console.log(_this2.currentDir.split('/').slice(0, length - 2).join('/'));
  246. var length = _this2.currentDir.split('/').length;
  247. _this2.currentDir = type === 'Folder' ? '' + _this2.currentDir + element.getAttribute('data-name') + '/' : _this2.currentDir.split('/').slice(0, length - 2).join('/');
  248. console.log(_this2.currentDir);
  249. _this2.getDirectory();
  250. });
  251. }
  252. });
  253. }
  254. }]);
  255. return DropboxPlugin;
  256. })();
  257. exports['default'] = new DropboxPlugin();
  258. module.exports = exports['default'];
  259. },{}],6:[function(require,module,exports){
  260. 'use strict';
  261. 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); } } };
  262. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  263. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  264. 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; }
  265. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  266. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  267. var TransloaditBasic = (function (_TransloaditPlugin) {
  268. _inherits(TransloaditBasic, _TransloaditPlugin);
  269. function TransloaditBasic(core, opts) {
  270. _classCallCheck(this, TransloaditBasic);
  271. _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
  272. this.type = 'presetter';
  273. this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' });
  274. }
  275. return TransloaditBasic;
  276. })(_TransloaditPlugin3['default']);
  277. },{"./TransloaditPlugin":7}],7:[function(require,module,exports){
  278. "use strict";
  279. Object.defineProperty(exports, "__esModule", {
  280. value: true
  281. });
  282. 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; }; })();
  283. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  284. var TransloaditPlugin = (function () {
  285. // This contains boilerplate that all TransloaditPlugins share - and should not be used
  286. // directly. It also shows which methods final plugins should implement/override,
  287. // this deciding on structure.
  288. function TransloaditPlugin(core, opts) {
  289. _classCallCheck(this, TransloaditPlugin);
  290. this.core = core;
  291. this.opts = opts;
  292. this.name = this.constructor.name;
  293. }
  294. _createClass(TransloaditPlugin, [{
  295. key: "run",
  296. value: function run(files) {
  297. return files;
  298. }
  299. }]);
  300. return TransloaditPlugin;
  301. })();
  302. exports["default"] = TransloaditPlugin;
  303. module.exports = exports["default"];
  304. },{}],8:[function(require,module,exports){
  305. 'use strict';
  306. Object.defineProperty(exports, '__esModule', {
  307. value: true
  308. });
  309. 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; }; })();
  310. 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); } } };
  311. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  312. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  313. 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; }
  314. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  315. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  316. var Tus10 = (function (_TransloaditPlugin) {
  317. _inherits(Tus10, _TransloaditPlugin);
  318. function Tus10(core, opts) {
  319. _classCallCheck(this, Tus10);
  320. _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
  321. this.type = 'uploader';
  322. }
  323. _createClass(Tus10, [{
  324. key: 'run',
  325. value: function run(files) {
  326. this.core.setProgress(this, 0);
  327. var uploaded = [];
  328. for (var i in files) {
  329. var file = files[i];
  330. this.core.setProgress(this, i * 1 + 1);
  331. uploaded[i] = file;
  332. uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name;
  333. }
  334. this.core.setProgress(this, 100);
  335. return uploaded;
  336. }
  337. }]);
  338. return Tus10;
  339. })(_TransloaditPlugin3['default']);
  340. exports['default'] = Tus10;
  341. module.exports = exports['default'];
  342. },{"./TransloaditPlugin":7}],9:[function(require,module,exports){
  343. 'use strict';
  344. Object.defineProperty(exports, '__esModule', {
  345. value: true
  346. });
  347. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  348. var _TransloaditPlugin = require('./TransloaditPlugin');
  349. var _TransloaditPlugin2 = _interopRequireDefault(_TransloaditPlugin);
  350. var _DragDrop = require('./DragDrop');
  351. var _DragDrop2 = _interopRequireDefault(_DragDrop);
  352. var _Dropbox = require('./Dropbox');
  353. var _Dropbox2 = _interopRequireDefault(_Dropbox);
  354. var _TransloaditBasic = require('./TransloaditBasic');
  355. var _TransloaditBasic2 = _interopRequireDefault(_TransloaditBasic);
  356. var _Tus10 = require('./Tus10');
  357. var _Tus102 = _interopRequireDefault(_Tus10);
  358. exports['default'] = {
  359. TransloaditPlugin: _TransloaditPlugin2['default'],
  360. DropboxPlugin: _Dropbox2['default'],
  361. DragDrop: _DragDrop2['default'],
  362. TransloaditBasic: _TransloaditBasic2['default'],
  363. Tus10: _Tus102['default']
  364. };
  365. module.exports = exports['default'];
  366. },{"./DragDrop":4,"./Dropbox":5,"./TransloaditBasic":6,"./TransloaditPlugin":7,"./Tus10":8}]},{},[1]);