| Total Complexity | 259 |
| Complexity/F | 2.73 |
| Lines of Code | 1341 |
| Function Count | 95 |
| Duplicated Lines | 422 |
| Ratio | 31.47 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like vendors/jua/jua.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /* RainLoop Webmail (c) RainLoop Team | MIT */ |
||
| 2 | (function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})(); |
||
| 3 | /******/ (function(modules) { // webpackBootstrap |
||
| 4 | /******/ // The module cache |
||
| 5 | /******/ var installedModules = {}; |
||
| 6 | |||
| 7 | /******/ // The require function |
||
| 8 | /******/ function __webpack_require__(moduleId) { |
||
| 9 | |||
| 10 | /******/ // Check if module is in cache |
||
| 11 | /******/ if(installedModules[moduleId]) |
||
| 12 | /******/ return installedModules[moduleId].exports; |
||
| 13 | |||
| 14 | /******/ // Create a new module (and put it into the cache) |
||
| 15 | /******/ var module = installedModules[moduleId] = { |
||
| 16 | /******/ exports: {}, |
||
| 17 | /******/ id: moduleId, |
||
| 18 | /******/ loaded: false |
||
| 19 | /******/ }; |
||
| 20 | |||
| 21 | /******/ // Execute the module function |
||
| 22 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
||
| 23 | |||
| 24 | /******/ // Flag the module as loaded |
||
| 25 | /******/ module.loaded = true; |
||
| 26 | |||
| 27 | /******/ // Return the exports of the module |
||
| 28 | /******/ return module.exports; |
||
| 29 | /******/ } |
||
| 30 | |||
| 31 | |||
| 32 | /******/ // expose the modules object (__webpack_modules__) |
||
| 33 | /******/ __webpack_require__.m = modules; |
||
| 34 | |||
| 35 | /******/ // expose the module cache |
||
| 36 | /******/ __webpack_require__.c = installedModules; |
||
| 37 | |||
| 38 | /******/ // __webpack_public_path__ |
||
| 39 | /******/ __webpack_require__.p = ""; |
||
| 40 | |||
| 41 | /******/ // Load entry module and return exports |
||
| 42 | /******/ return __webpack_require__(0); |
||
| 43 | /******/ }) |
||
| 44 | /************************************************************************/ |
||
| 45 | /******/ ([ |
||
| 46 | /* 0 */ |
||
| 47 | /***/ function(module, exports, __webpack_require__) { |
||
| 48 | |||
| 49 | (function () { |
||
| 50 | 'use strict'; |
||
| 51 | __webpack_require__(1).Jua = __webpack_require__(7); |
||
| 52 | }()); |
||
| 53 | |||
| 54 | /***/ }, |
||
| 55 | /* 1 */ |
||
| 56 | /***/ function(module, exports, __webpack_require__) { |
||
| 57 | |||
| 58 | module.exports = window; |
||
| 59 | |||
| 60 | /***/ }, |
||
| 61 | /* 2 */ |
||
| 62 | /***/ function(module, exports, __webpack_require__) { |
||
| 63 | |||
| 64 | |||
| 65 | (function () { |
||
| 66 | |||
| 67 | 'use strict'; |
||
| 68 | |||
| 69 | var Globals = {}; |
||
| 70 | |||
| 71 | Globals.iDefLimit = 20; |
||
| 72 | |||
| 73 | Globals.bIsAjaxUploaderSupported = (function () { |
||
| 74 | |||
| 75 | var |
||
| 76 | window = __webpack_require__(1), |
||
| 77 | oInput = window.document.createElement('input') |
||
| 78 | ; |
||
| 79 | |||
| 80 | oInput.type = 'file'; |
||
| 81 | return !!('XMLHttpRequest' in window && 'multiple' in oInput && 'FormData' in window && (new window.XMLHttpRequest()).upload && true); |
||
| 82 | }()); |
||
| 83 | |||
| 84 | module.exports = Globals; |
||
| 85 | |||
| 86 | }()); |
||
| 87 | |||
| 88 | /***/ }, |
||
| 89 | /* 3 */ |
||
| 90 | /***/ function(module, exports, __webpack_require__) { |
||
| 91 | |||
| 92 | module.exports = jQuery; |
||
| 93 | |||
| 94 | /***/ }, |
||
| 95 | /* 4 */ |
||
| 96 | /***/ function(module, exports, __webpack_require__) { |
||
| 97 | |||
| 98 | |||
| 99 | (function () { |
||
| 100 | |||
| 101 | 'use strict'; |
||
| 102 | |||
| 103 | var |
||
| 104 | Utils = {}, |
||
| 105 | |||
| 106 | window = __webpack_require__(1), |
||
| 107 | $ = __webpack_require__(3), |
||
| 108 | |||
| 109 | Globals = __webpack_require__(2) |
||
| 110 | ; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param {*} mValue |
||
| 114 | * @return {boolean} |
||
| 115 | */ |
||
| 116 | Utils.isUndefined = function (mValue) |
||
| 117 | { |
||
| 118 | return 'undefined' === typeof mValue; |
||
| 119 | }; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param {Object} mObjectFirst |
||
| 123 | * @param {Object=} mObjectSecond |
||
| 124 | * @return {Object} |
||
| 125 | */ |
||
| 126 | Utils.extend = function (mObjectFirst, mObjectSecond) |
||
| 127 | { |
||
| 128 | if (mObjectSecond) |
||
| 129 | { |
||
| 130 | for (var sProp in mObjectSecond) |
||
| 131 | { |
||
| 132 | if (mObjectSecond.hasOwnProperty(sProp)) |
||
| 133 | { |
||
| 134 | mObjectFirst[sProp] = mObjectSecond[sProp]; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | return mObjectFirst; |
||
| 140 | }; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param {*} oParent |
||
| 144 | * @param {*} oDescendant |
||
| 145 | * |
||
| 146 | * @return {boolean} |
||
| 147 | */ |
||
| 148 | Utils.contains = function (oParent, oDescendant) |
||
| 149 | { |
||
| 150 | var bResult = false; |
||
| 151 | if (oParent && oDescendant) |
||
| 152 | { |
||
| 153 | if (oParent === oDescendant) |
||
| 154 | { |
||
| 155 | bResult = true; |
||
| 156 | } |
||
| 157 | else if (oParent.contains) |
||
| 158 | { |
||
| 159 | bResult = oParent.contains(oDescendant); |
||
| 160 | } |
||
| 161 | else |
||
| 162 | { |
||
| 163 | /*jshint bitwise: false*/ |
||
| 164 | bResult = oDescendant.compareDocumentPosition ? |
||
| 165 | !!(oDescendant.compareDocumentPosition(oParent) & 8) : false; |
||
| 166 | /*jshint bitwise: true*/ |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | return bResult; |
||
| 171 | }; |
||
| 172 | |||
| 173 | Utils.mainClearTimeout = function(iTimer) |
||
| 174 | { |
||
| 175 | if (0 < iTimer) |
||
| 176 | { |
||
| 177 | clearTimeout(iTimer); |
||
| 178 | } |
||
| 179 | |||
| 180 | iTimer = 0; |
||
| 181 | }; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param {Event} oEvent |
||
| 185 | * @return {?Event} |
||
| 186 | */ |
||
| 187 | Utils.getEvent = function(oEvent) |
||
| 188 | { |
||
| 189 | oEvent = (oEvent && (oEvent.originalEvent ? |
||
| 190 | oEvent.originalEvent : oEvent)) || window.event; |
||
| 191 | |||
| 192 | return oEvent.dataTransfer ? oEvent : null; |
||
| 193 | }; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param {Object} oValues |
||
| 197 | * @param {string} sKey |
||
| 198 | * @param {?} mDefault |
||
| 199 | * @return {?} |
||
| 200 | */ |
||
| 201 | Utils.getValue = function (oValues, sKey, mDefault) |
||
| 202 | { |
||
| 203 | return (!oValues || !sKey || Utils.isUndefined(oValues[sKey])) ? mDefault : oValues[sKey]; |
||
| 204 | }; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param {Object} oOwner |
||
| 208 | * @param {string} sPublicName |
||
| 209 | * @param {*} mObject |
||
| 210 | */ |
||
| 211 | Utils.setValue = function(oOwner, sPublicName, mObject) |
||
| 212 | { |
||
| 213 | oOwner[sPublicName] = mObject; |
||
| 214 | }; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param {*} aData |
||
| 218 | * @return {boolean} |
||
| 219 | */ |
||
| 220 | Utils.isNonEmptyArray = function (aData) |
||
| 221 | { |
||
| 222 | return aData && aData.length && 0 < aData.length ? true : false; |
||
| 223 | }; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param {*} mValue |
||
| 227 | * @return {number} |
||
| 228 | */ |
||
| 229 | Utils.pInt = function (mValue) |
||
| 230 | { |
||
| 231 | return parseInt(mValue || 0, 10); |
||
| 232 | }; |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param {Function} fFunction |
||
| 236 | * @param {Object=} oScope |
||
| 237 | * @return {Function} |
||
| 238 | */ |
||
| 239 | Utils.scopeBind = function (fFunction, oScope) |
||
| 240 | { |
||
| 241 | return function () { |
||
| 242 | return fFunction.apply(Utils.isUndefined(oScope) ? null : oScope, |
||
| 243 | Array.prototype.slice.call(arguments)); |
||
| 244 | }; |
||
| 245 | }; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @param {number=} iLen |
||
| 249 | * @return {string} |
||
| 250 | */ |
||
| 251 | Utils.fakeMd5 = function (iLen) |
||
| 252 | { |
||
| 253 | var |
||
| 254 | sResult = '', |
||
| 255 | sLine = '0123456789abcdefghijklmnopqrstuvwxyz' |
||
| 256 | ; |
||
| 257 | |||
| 258 | iLen = Utils.isUndefined(iLen) ? 32 : Utils.pInt(iLen); |
||
| 259 | |||
| 260 | while (sResult.length < iLen) |
||
| 261 | { |
||
| 262 | sResult += sLine.substr(window.Math.round(window.Math.random() * sLine.length), 1); |
||
| 263 | } |
||
| 264 | |||
| 265 | return sResult; |
||
| 266 | }; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @return {string} |
||
| 270 | */ |
||
| 271 | Utils.getNewUid = function () |
||
| 272 | { |
||
| 273 | return 'jua-uid-' + Utils.fakeMd5(16) + '-' + (new window.Date()).getTime().toString(); |
||
| 274 | }; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param {*} oFile |
||
| 278 | * @return {Object} |
||
| 279 | */ |
||
| 280 | Utils.getDataFromFile = function (oFile) |
||
| 281 | { |
||
| 282 | var |
||
| 283 | sFileName = Utils.isUndefined(oFile.fileName) ? (Utils.isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName, |
||
| 284 | iSize = Utils.isUndefined(oFile.fileSize) ? (Utils.isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize, |
||
| 285 | sType = Utils.isUndefined(oFile.type) ? null : oFile.type |
||
| 286 | ; |
||
| 287 | |||
| 288 | if (sFileName.charAt(0) === '/') |
||
| 289 | { |
||
| 290 | sFileName = sFileName.substr(1); |
||
| 291 | } |
||
| 292 | |||
| 293 | if ('' === sType && 0 === iSize) |
||
| 294 | { |
||
| 295 | return null; // Folder |
||
| 296 | } |
||
| 297 | |||
| 298 | return { |
||
| 299 | 'FileName': sFileName, |
||
| 300 | 'Size': iSize, |
||
| 301 | 'Type': sType, |
||
| 302 | 'Folder': '', |
||
| 303 | 'File' : oFile |
||
| 304 | }; |
||
| 305 | }; |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @param {*} aItems |
||
| 309 | * @param {Function} fFileCallback |
||
| 310 | * @param {number=} iLimit = 20 |
||
| 311 | * @param {Function=} fLimitCallback |
||
| 312 | */ |
||
| 313 | Utils.getDataFromFiles = function (aItems, fFileCallback, iLimit, fLimitCallback) |
||
| 314 | { |
||
| 315 | var |
||
| 316 | iInputLimit = 0, |
||
| 317 | iLen = 0, |
||
| 318 | iIndex = 0, |
||
| 319 | oItem = null, |
||
| 320 | oFile = null, |
||
| 321 | bUseLimit = false, |
||
| 322 | bCallLimit = false |
||
| 323 | ; |
||
| 324 | |||
| 325 | iLimit = Utils.isUndefined(iLimit) ? Globals.iDefLimit : Utils.pInt(iLimit); |
||
| 326 | iInputLimit = iLimit; |
||
| 327 | bUseLimit = 0 < iLimit; |
||
| 328 | |||
| 329 | aItems = aItems && 0 < aItems.length ? aItems : null; |
||
| 330 | if (aItems) |
||
| 331 | { |
||
| 332 | for (iIndex = 0, iLen = aItems.length; iIndex < iLen; iIndex++) |
||
| 333 | { |
||
| 334 | oItem = aItems[iIndex]; |
||
| 335 | if (oItem) |
||
| 336 | { |
||
| 337 | if (!bUseLimit || 0 <= --iLimit) |
||
| 338 | { |
||
| 339 | oFile = Utils.getDataFromFile(oItem); |
||
| 340 | if (oFile) |
||
| 341 | { |
||
| 342 | fFileCallback(oFile); |
||
| 343 | } |
||
| 344 | } |
||
| 345 | else if (bUseLimit && !bCallLimit) |
||
| 346 | { |
||
| 347 | if (0 > iLimit && fLimitCallback) |
||
| 348 | { |
||
| 349 | bCallLimit = true; |
||
| 350 | fLimitCallback(iInputLimit); |
||
| 351 | } |
||
| 352 | } |
||
| 353 | } |
||
| 354 | } |
||
| 355 | } |
||
| 356 | }; |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param {*} oInput |
||
| 360 | * @param {Function} fFileCallback |
||
| 361 | * @param {number=} iLimit = 20 |
||
| 362 | * @param {Function=} fLimitCallback |
||
| 363 | */ |
||
| 364 | Utils.getDataFromInput = function (oInput, fFileCallback, iLimit, fLimitCallback) |
||
| 365 | { |
||
| 366 | var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null; |
||
| 367 | if (aFiles) |
||
| 368 | { |
||
| 369 | Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); |
||
| 370 | } |
||
| 371 | else |
||
| 372 | { |
||
| 373 | fFileCallback({ |
||
| 374 | 'FileName': oInput.value.split('\\').pop().split('/').pop(), |
||
| 375 | 'Size': null, |
||
| 376 | 'Type': null, |
||
| 377 | 'Folder': '', |
||
| 378 | 'File' : null |
||
| 379 | }); |
||
| 380 | } |
||
| 381 | }; |
||
| 382 | |||
| 383 | Utils.eventContainsFiles = function (oEvent) |
||
| 384 | { |
||
| 385 | var bResult = false; |
||
| 386 | if (oEvent && oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length) |
||
| 387 | { |
||
| 388 | var |
||
| 389 | iIindex = 0, |
||
| 390 | iLen = oEvent.dataTransfer.types.length |
||
| 391 | ; |
||
| 392 | |||
| 393 | for (; iIindex < iLen; iIindex++) |
||
| 394 | { |
||
| 395 | if (oEvent.dataTransfer.types[iIindex].toLowerCase() === 'files') |
||
| 396 | { |
||
| 397 | bResult = true; |
||
| 398 | break; |
||
| 399 | } |
||
| 400 | } |
||
| 401 | } |
||
| 402 | |||
| 403 | return bResult; |
||
| 404 | }; |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @param {Event} oEvent |
||
| 408 | * @param {Function} fFileCallback |
||
| 409 | * @param {number=} iLimit = 20 |
||
| 410 | * @param {Function=} fLimitCallback |
||
| 411 | */ |
||
| 412 | Utils.getDataFromDragEvent = function (oEvent, fFileCallback, iLimit, fLimitCallback) |
||
| 413 | { |
||
| 414 | var aFiles = null; |
||
| 415 | |||
| 416 | oEvent = Utils.getEvent(oEvent); |
||
| 417 | if (oEvent && Utils.eventContainsFiles(oEvent)) |
||
| 418 | { |
||
| 419 | aFiles = (Utils.getValue(oEvent, 'files', null) || (oEvent.dataTransfer ? |
||
| 420 | Utils.getValue(oEvent.dataTransfer, 'files', null) : null)); |
||
| 421 | |||
| 422 | if (aFiles && 0 < aFiles.length) |
||
| 423 | { |
||
| 424 | Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); |
||
| 425 | } |
||
| 426 | } |
||
| 427 | }; |
||
| 428 | |||
| 429 | Utils.createNextLabel = function () |
||
| 430 | { |
||
| 431 | return $('<label style="' + |
||
| 432 | 'position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;' + |
||
| 433 | '"></label>').css({ |
||
| 434 | 'opacity': 0 |
||
| 435 | }); |
||
| 436 | }; |
||
| 437 | |||
| 438 | Utils.createNextInput = function () |
||
| 439 | { |
||
| 440 | return $('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />'); |
||
| 441 | }; |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param {string=} sName |
||
| 445 | * @param {boolean=} bMultiple = true |
||
| 446 | * @return {?Object} |
||
| 447 | */ |
||
| 448 | Utils.getNewInput = function (sName, bMultiple) |
||
| 449 | { |
||
| 450 | sName = Utils.isUndefined(sName) ? '' : sName.toString(); |
||
| 451 | |||
| 452 | var oLocal = Utils.createNextInput(); |
||
| 453 | if (0 < sName.length) |
||
| 454 | { |
||
| 455 | oLocal.attr('name', sName); |
||
| 456 | } |
||
| 457 | |||
| 458 | if (Utils.isUndefined(bMultiple) ? true : bMultiple) |
||
| 459 | { |
||
| 460 | oLocal.prop('multiple', true); |
||
| 461 | } |
||
| 462 | |||
| 463 | return oLocal; |
||
| 464 | }; |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @param {?} mStringOrFunction |
||
| 468 | * @param {Array=} aFunctionParams |
||
| 469 | * @return {string} |
||
| 470 | */ |
||
| 471 | Utils.getStringOrCallFunction = function (mStringOrFunction, aFunctionParams) |
||
| 472 | { |
||
| 473 | return $.isFunction(mStringOrFunction) ? |
||
| 474 | mStringOrFunction.apply(null, $.isArray(aFunctionParams) ? aFunctionParams : []).toString() : |
||
| 475 | mStringOrFunction.toString(); |
||
| 476 | }; |
||
| 477 | |||
| 478 | module.exports = Utils; |
||
| 479 | |||
| 480 | }()); |
||
| 481 | |||
| 482 | /***/ }, |
||
| 483 | /* 5 */ |
||
| 484 | /***/ function(module, exports, __webpack_require__) { |
||
| 485 | |||
| 486 | |||
| 487 | (function () { |
||
| 488 | |||
| 489 | 'use strict'; |
||
| 490 | |||
| 491 | var |
||
| 492 | $ = __webpack_require__(3), |
||
| 493 | |||
| 494 | Globals = __webpack_require__(2), |
||
| 495 | Utils = __webpack_require__(4) |
||
| 496 | ; |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @constructor |
||
| 500 | * @param {Jua} oJua |
||
| 501 | * @param {Object} oOptions |
||
| 502 | */ |
||
| 503 | function AjaxDriver(oJua, oOptions) |
||
| 504 | { |
||
| 505 | this.oXhrs = {}; |
||
| 506 | this.oUids = {}; |
||
| 507 | this.oJua = oJua; |
||
| 508 | this.oOptions = oOptions; |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @type {Object} |
||
| 513 | */ |
||
| 514 | AjaxDriver.prototype.oXhrs = {}; |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @type {Object} |
||
| 518 | */ |
||
| 519 | AjaxDriver.prototype.oUids = {}; |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @type {?Jua} |
||
| 523 | */ |
||
| 524 | AjaxDriver.prototype.oJua = null; |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @type {Object} |
||
| 528 | */ |
||
| 529 | AjaxDriver.prototype.oOptions = {}; |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @return {boolean} |
||
| 533 | */ |
||
| 534 | AjaxDriver.prototype.isDragAndDropSupported = function () |
||
| 535 | { |
||
| 536 | return true; |
||
| 537 | }; |
||
| 538 | |||
| 539 | /** |
||
| 540 | * @param {string} sUid |
||
| 541 | */ |
||
| 542 | AjaxDriver.prototype.regTaskUid = function (sUid) |
||
| 543 | { |
||
| 544 | this.oUids[sUid] = true; |
||
| 545 | }; |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @param {string} sUid |
||
| 549 | * @param {?} oFileInfo |
||
| 550 | * @param {Function} fCallback |
||
| 551 | */ |
||
| 552 | AjaxDriver.prototype.uploadTask = function (sUid, oFileInfo, fCallback) |
||
| 553 | { |
||
| 554 | if (false === this.oUids[sUid] || !oFileInfo || !oFileInfo['File']) |
||
| 555 | { |
||
| 556 | fCallback(null, sUid); |
||
| 557 | return false; |
||
| 558 | } |
||
| 559 | |||
| 560 | try |
||
| 561 | { |
||
| 562 | var |
||
| 563 | self = this, |
||
| 564 | oXhr = new XMLHttpRequest(), |
||
| 565 | oFormData = new FormData(), |
||
| 566 | sAction = Utils.getValue(this.oOptions, 'action', ''), |
||
| 567 | aHidden = Utils.getValue(this.oOptions, 'hidden', {}), |
||
| 568 | fStartFunction = this.oJua.getEvent('onStart'), |
||
| 569 | fCompleteFunction = this.oJua.getEvent('onComplete'), |
||
| 570 | fProgressFunction = this.oJua.getEvent('onProgress') |
||
| 571 | ; |
||
| 572 | |||
| 573 | oXhr.open('POST', sAction, true); |
||
| 574 | |||
| 575 | if (fProgressFunction && oXhr.upload) |
||
| 576 | { |
||
| 577 | oXhr.upload.onprogress = function (oEvent) { |
||
| 578 | if (oEvent && oEvent.lengthComputable && !Utils.isUndefined(oEvent.loaded) && !Utils.isUndefined(oEvent.total)) |
||
| 579 | { |
||
| 580 | fProgressFunction(sUid, oEvent.loaded, oEvent.total); |
||
| 581 | } |
||
| 582 | }; |
||
| 583 | } |
||
| 584 | |||
| 585 | oXhr.onreadystatechange = function () { |
||
| 586 | if (4 === oXhr.readyState && 200 === oXhr.status) |
||
| 587 | { |
||
| 588 | if (fCompleteFunction) |
||
| 589 | { |
||
| 590 | var |
||
| 591 | bResult = false, |
||
| 592 | oResult = null |
||
| 593 | ; |
||
| 594 | |||
| 595 | try |
||
| 596 | { |
||
| 597 | oResult = $.parseJSON(oXhr.responseText); |
||
| 598 | bResult = true; |
||
| 599 | } |
||
| 600 | catch (oException) |
||
| 601 | { |
||
| 602 | oResult = null; |
||
| 603 | } |
||
| 604 | |||
| 605 | fCompleteFunction(sUid, bResult, oResult); |
||
| 606 | } |
||
| 607 | |||
| 608 | if (!Utils.isUndefined(self.oXhrs[sUid])) |
||
| 609 | { |
||
| 610 | self.oXhrs[sUid] = null; |
||
| 611 | } |
||
| 612 | |||
| 613 | fCallback(null, sUid); |
||
| 614 | } |
||
| 615 | else |
||
| 616 | { |
||
| 617 | if (4 === oXhr.readyState) |
||
| 618 | { |
||
| 619 | fCompleteFunction(sUid, false, null); |
||
| 620 | fCallback(null, sUid); |
||
| 621 | } |
||
| 622 | } |
||
| 623 | }; |
||
| 624 | |||
| 625 | if (fStartFunction) |
||
| 626 | { |
||
| 627 | fStartFunction(sUid); |
||
| 628 | } |
||
| 629 | |||
| 630 | oFormData.append('jua-post-type', 'ajax'); |
||
| 631 | oFormData.append(Utils.getValue(this.oOptions, 'name', 'juaFile'), oFileInfo['File']); |
||
| 632 | $.each(aHidden, function (sKey, sValue) { |
||
| 633 | oFormData.append(sKey, Utils.getStringOrCallFunction(sValue, [oFileInfo])); |
||
| 634 | }); |
||
| 635 | |||
| 636 | oXhr.send(oFormData); |
||
| 637 | |||
| 638 | this.oXhrs[sUid] = oXhr; |
||
| 639 | return true; |
||
| 640 | } |
||
| 641 | catch (oError) |
||
| 642 | { |
||
| 643 | } |
||
| 644 | |||
| 645 | fCallback(null, sUid); |
||
| 646 | return false; |
||
| 647 | }; |
||
| 648 | |||
| 649 | AjaxDriver.prototype.generateNewInput = function (oClickElement) |
||
| 650 | { |
||
| 651 | var |
||
| 652 | self = this, |
||
| 653 | oLabel = null, |
||
| 654 | oInput = null |
||
| 655 | ; |
||
| 656 | |||
| 657 | if (oClickElement) |
||
| 658 | { |
||
| 659 | oInput = Utils.getNewInput('', !Utils.getValue(this.oOptions, 'disableMultiple', false)); |
||
| 660 | oLabel = Utils.createNextLabel(); |
||
| 661 | oLabel.append(oInput); |
||
| 662 | |||
| 663 | $(oClickElement).append(oLabel); |
||
| 664 | |||
| 665 | oInput |
||
| 666 | .on('click', function () { |
||
| 667 | var fOn = self.oJua.getEvent('onDialog'); |
||
| 668 | if (fOn) |
||
| 669 | { |
||
| 670 | fOn(); |
||
| 671 | } |
||
| 672 | }) |
||
| 673 | .on('change', function () { |
||
| 674 | Utils.getDataFromInput(this, function (oFile) { |
||
| 675 | self.oJua.addNewFile(oFile); |
||
| 676 | self.generateNewInput(oClickElement); |
||
| 677 | |||
| 678 | setTimeout(function () { |
||
| 679 | oLabel.remove(); |
||
| 680 | }, 10); |
||
| 681 | }, |
||
| 682 | Utils.getValue(self.oOptions, 'multipleSizeLimit', Globals.iDefLimit), |
||
| 683 | self.oJua.getEvent('onLimitReached') |
||
| 684 | ); |
||
| 685 | }) |
||
| 686 | ; |
||
| 687 | } |
||
| 688 | }; |
||
| 689 | |||
| 690 | AjaxDriver.prototype.cancel = function (sUid) |
||
| 691 | { |
||
| 692 | this.oUids[sUid] = false; |
||
| 693 | if (this.oXhrs[sUid]) |
||
| 694 | { |
||
| 695 | try |
||
| 696 | { |
||
| 697 | if (this.oXhrs[sUid].abort) |
||
| 698 | { |
||
| 699 | this.oXhrs[sUid].abort(); |
||
| 700 | } |
||
| 701 | } |
||
| 702 | catch (oError) |
||
| 703 | { |
||
| 704 | } |
||
| 705 | |||
| 706 | this.oXhrs[sUid] = null; |
||
| 707 | } |
||
| 708 | }; |
||
| 709 | |||
| 710 | module.exports = AjaxDriver; |
||
| 711 | |||
| 712 | }()); |
||
| 713 | |||
| 714 | |||
| 715 | /***/ }, |
||
| 716 | /* 6 */ |
||
| 717 | /***/ function(module, exports, __webpack_require__) { |
||
| 718 | |||
| 719 | |||
| 720 | (function () { |
||
| 721 | |||
| 722 | 'use strict'; |
||
| 723 | |||
| 724 | var |
||
| 725 | window = __webpack_require__(1), |
||
| 726 | $ = __webpack_require__(3), |
||
| 727 | |||
| 728 | Globals = __webpack_require__(2), |
||
| 729 | Utils = __webpack_require__(4) |
||
| 730 | ; |
||
| 731 | |||
| 732 | /** |
||
| 733 | * @constructor |
||
| 734 | * @param {Jua} oJua |
||
| 735 | * @param {Object} oOptions |
||
| 736 | */ |
||
| 737 | function IframeDriver(oJua, oOptions) |
||
| 738 | { |
||
| 739 | this.oUids = {}; |
||
| 740 | this.oForms = {}; |
||
| 741 | this.oJua = oJua; |
||
| 742 | this.oOptions = oOptions; |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * @type {Object} |
||
| 747 | */ |
||
| 748 | IframeDriver.prototype.oUids = {}; |
||
| 749 | |||
| 750 | /** |
||
| 751 | * @type {Object} |
||
| 752 | */ |
||
| 753 | IframeDriver.prototype.oForms = {}; |
||
| 754 | |||
| 755 | /** |
||
| 756 | * @type {?Jua} |
||
| 757 | */ |
||
| 758 | IframeDriver.prototype.oJua = null; |
||
| 759 | |||
| 760 | /** |
||
| 761 | * @type {Object} |
||
| 762 | */ |
||
| 763 | IframeDriver.prototype.oOptions = {}; |
||
| 764 | |||
| 765 | /** |
||
| 766 | * @return {boolean} |
||
| 767 | */ |
||
| 768 | IframeDriver.prototype.isDragAndDropSupported = function () |
||
| 769 | { |
||
| 770 | return false; |
||
| 771 | }; |
||
| 772 | |||
| 773 | /** |
||
| 774 | * @param {string} sUid |
||
| 775 | */ |
||
| 776 | IframeDriver.prototype.regTaskUid = function (sUid) |
||
| 777 | { |
||
| 778 | this.oUids[sUid] = true; |
||
| 779 | }; |
||
| 780 | |||
| 781 | /** |
||
| 782 | * @param {string} sUid |
||
| 783 | * @param {?} oFileInfo |
||
| 784 | * @param {Function} fCallback |
||
| 785 | */ |
||
| 786 | IframeDriver.prototype.uploadTask = function (sUid, oFileInfo, fCallback) |
||
| 787 | { |
||
| 788 | if (false === this.oUids[sUid]) |
||
| 789 | { |
||
| 790 | fCallback(null, sUid); |
||
| 791 | return false; |
||
| 792 | } |
||
| 793 | |||
| 794 | var |
||
| 795 | oForm = this.oForms[sUid], |
||
| 796 | aHidden = Utils.getValue(this.oOptions, 'hidden', {}), |
||
| 797 | fStartFunction = this.oJua.getEvent('onStart'), |
||
| 798 | fCompleteFunction = this.oJua.getEvent('onComplete') |
||
| 799 | ; |
||
| 800 | |||
| 801 | if (oForm) |
||
| 802 | { |
||
| 803 | oForm.append($('<input type="hidden" />').attr('name', 'jua-post-type').val('iframe')); |
||
| 804 | $.each(aHidden, function (sKey, sValue) { |
||
| 805 | oForm.append($('<input type="hidden" />').attr('name', sKey).val(Utils.getStringOrCallFunction(sValue, [oFileInfo]))); |
||
| 806 | }); |
||
| 807 | |||
| 808 | oForm.trigger('submit'); |
||
| 809 | if (fStartFunction) |
||
| 810 | { |
||
| 811 | fStartFunction(sUid); |
||
| 812 | } |
||
| 813 | |||
| 814 | oForm.find('iframe').on('load', function () { |
||
| 815 | |||
| 816 | var |
||
| 817 | bResult = false, |
||
| 818 | oIframeDoc = null, |
||
| 819 | oResult = {} |
||
| 820 | ; |
||
| 821 | |||
| 822 | if (fCompleteFunction) |
||
| 823 | { |
||
| 824 | try |
||
| 825 | { |
||
| 826 | oIframeDoc = this.contentDocument ? this.contentDocument: this.contentWindow.document; |
||
| 827 | oResult = $.parseJSON(oIframeDoc.body.innerHTML); |
||
| 828 | bResult = true; |
||
| 829 | } |
||
| 830 | catch (oErr) |
||
| 831 | { |
||
| 832 | oResult = {}; |
||
| 833 | } |
||
| 834 | |||
| 835 | fCompleteFunction(sUid, bResult, oResult); |
||
| 836 | } |
||
| 837 | |||
| 838 | fCallback(null, sUid); |
||
| 839 | |||
| 840 | window.setTimeout(function () { |
||
| 841 | oForm.remove(); |
||
| 842 | }, 100); |
||
| 843 | }); |
||
| 844 | } |
||
| 845 | else |
||
| 846 | { |
||
| 847 | fCallback(null, sUid); |
||
| 848 | } |
||
| 849 | |||
| 850 | return true; |
||
| 851 | }; |
||
| 852 | |||
| 853 | IframeDriver.prototype.generateNewInput = function (oClickElement) |
||
| 854 | { |
||
| 855 | var |
||
| 856 | self = this, |
||
| 857 | sUid = '', |
||
| 858 | oInput = null, |
||
| 859 | oIframe = null, |
||
| 860 | sAction = Utils.getValue(this.oOptions, 'action', ''), |
||
| 861 | oForm = null |
||
| 862 | ; |
||
| 863 | |||
| 864 | if (oClickElement) |
||
| 865 | { |
||
| 866 | sUid = Utils.getNewUid(); |
||
| 867 | |||
| 868 | oInput = Utils.getNewInput(Utils.getValue(this.oOptions, 'name', 'juaFile'), !Utils.getValue(this.oOptions, 'disableMultiple', false)); |
||
| 869 | |||
| 870 | oForm = $('<form action="' + sAction + '" target="iframe-' + sUid + '" ' + |
||
| 871 | ' method="POST" enctype="multipart/form-data" style="display: block; cursor: pointer;"></form>'); |
||
| 872 | |||
| 873 | oIframe = $('<iframe name="iframe-' + sUid + '" tabindex="-1" src="javascript:void(0);" ' + |
||
| 874 | ' style="position: absolute; top: -1000px; left: -1000px; cursor: pointer;" />').css({'opacity': 0}); |
||
| 875 | |||
| 876 | oForm.append(Utils.createNextLabel().append(oInput)).append(oIframe); |
||
| 877 | |||
| 878 | $(oClickElement).append(oForm); |
||
| 879 | |||
| 880 | this.oForms[sUid] = oForm; |
||
| 881 | |||
| 882 | oInput |
||
| 883 | .on('click', function () { |
||
| 884 | var fOn = self.oJua.getEvent('onDialog'); |
||
| 885 | if (fOn) |
||
| 886 | { |
||
| 887 | fOn(); |
||
| 888 | } |
||
| 889 | }) |
||
| 890 | .on('change', function () { |
||
| 891 | Utils.getDataFromInput(this, function (oFile) { |
||
| 892 | if (oFile) |
||
| 893 | { |
||
| 894 | oForm.css({ |
||
| 895 | 'position': 'absolute', |
||
| 896 | 'top': -1000, |
||
| 897 | 'left': -1000 |
||
| 898 | }); |
||
| 899 | |||
| 900 | self.oJua.addFile(sUid, oFile); |
||
| 901 | self.generateNewInput(oClickElement); |
||
| 902 | } |
||
| 903 | |||
| 904 | }, |
||
| 905 | Utils.getValue(self.oOptions, 'multipleSizeLimit', Globals.iDefLimit), |
||
| 906 | self.oJua.getEvent('onLimitReached') |
||
| 907 | ); |
||
| 908 | }) |
||
| 909 | ; |
||
| 910 | } |
||
| 911 | }; |
||
| 912 | |||
| 913 | IframeDriver.prototype.cancel = function (sUid) |
||
| 914 | { |
||
| 915 | this.oUids[sUid] = false; |
||
| 916 | if (this.oForms[sUid]) |
||
| 917 | { |
||
| 918 | this.oForms[sUid].remove(); |
||
| 919 | this.oForms[sUid] = false; |
||
| 920 | } |
||
| 921 | }; |
||
| 922 | |||
| 923 | module.exports = IframeDriver; |
||
| 924 | |||
| 925 | }()); |
||
| 926 | |||
| 927 | /***/ }, |
||
| 928 | /* 7 */ |
||
| 929 | /***/ function(module, exports, __webpack_require__) { |
||
| 930 | |||
| 931 | |||
| 932 | (function () { |
||
| 933 | |||
| 934 | 'use strict'; |
||
| 935 | |||
| 936 | var |
||
| 937 | Utils = __webpack_require__(4), |
||
| 938 | Globals = __webpack_require__(2) |
||
| 939 | ; |
||
| 940 | |||
| 941 | /** |
||
| 942 | * @constructor |
||
| 943 | * @param {Object=} oOptions |
||
| 944 | */ |
||
| 945 | function Jua(oOptions) |
||
| 946 | { |
||
| 947 | oOptions = Utils.isUndefined(oOptions) ? {} : oOptions; |
||
| 948 | |||
| 949 | var |
||
| 950 | self = this, |
||
| 951 | |||
| 952 | Driver = null, |
||
| 953 | |||
| 954 | window = __webpack_require__(1), |
||
| 955 | $ = __webpack_require__(3), |
||
| 956 | |||
| 957 | queue = __webpack_require__(8) |
||
| 958 | ; |
||
| 959 | |||
| 960 | self.bEnableDnD = true; |
||
| 961 | |||
| 962 | self.oEvents = { |
||
| 963 | 'onDialog': null, |
||
| 964 | 'onSelect': null, |
||
| 965 | 'onStart': null, |
||
| 966 | 'onComplete': null, |
||
| 967 | 'onCompleteAll': null, |
||
| 968 | 'onProgress': null, |
||
| 969 | 'onDragEnter': null, |
||
| 970 | 'onDragLeave': null, |
||
| 971 | 'onDrop': null, |
||
| 972 | 'onBodyDragEnter': null, |
||
| 973 | 'onBodyDragLeave': null, |
||
| 974 | 'onLimitReached': null |
||
| 975 | }; |
||
| 976 | |||
| 977 | self.oOptions = Utils.extend({ |
||
| 978 | 'action': '', |
||
| 979 | 'name': '', |
||
| 980 | 'hidden': {}, |
||
| 981 | 'queueSize': 10, |
||
| 982 | 'clickElement': false, |
||
| 983 | 'dragAndDropElement': false, |
||
| 984 | 'dragAndDropBodyElement': false, |
||
| 985 | 'disableAjaxUpload': false, |
||
| 986 | 'disableDragAndDrop': false, |
||
| 987 | 'disableMultiple': false, |
||
| 988 | 'disableDocumentDropPrevent': false, |
||
| 989 | 'multipleSizeLimit': 50 |
||
| 990 | }, oOptions); |
||
| 991 | |||
| 992 | self.oQueue = queue(Utils.pInt(Utils.getValue(self.oOptions, 'queueSize', 10))); |
||
| 993 | if (self.runEvent('onCompleteAll')) |
||
| 994 | { |
||
| 995 | self.oQueue.await(function () { |
||
| 996 | self.runEvent('onCompleteAll'); |
||
| 997 | }); |
||
| 998 | } |
||
| 999 | |||
| 1000 | Driver = (self.isAjaxUploaderSupported() && !Utils.getValue(self.oOptions, 'disableAjaxUpload', false) ? |
||
| 1001 | __webpack_require__(5) : __webpack_require__(6)); |
||
| 1002 | |||
| 1003 | self.oDriver = new Driver(self, self.oOptions); |
||
| 1004 | |||
| 1005 | self.oClickElement = Utils.getValue(self.oOptions, 'clickElement', null); |
||
| 1006 | |||
| 1007 | if (self.oClickElement) |
||
| 1008 | { |
||
| 1009 | $(self.oClickElement).css({ |
||
| 1010 | 'position': 'relative', |
||
| 1011 | 'overflow': 'hidden' |
||
| 1012 | }); |
||
| 1013 | |||
| 1014 | if ('inline' === $(this.oClickElement).css('display')) |
||
| 1015 | { |
||
| 1016 | $(this.oClickElement).css('display', 'inline-block'); |
||
| 1017 | } |
||
| 1018 | |||
| 1019 | this.oDriver.generateNewInput(this.oClickElement); |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | if (this.oDriver.isDragAndDropSupported() && Utils.getValue(this.oOptions, 'dragAndDropElement', false) && |
||
| 1023 | !Utils.getValue(this.oOptions, 'disableAjaxUpload', false)) |
||
| 1024 | { |
||
| 1025 | (function (self) { |
||
| 1026 | var |
||
| 1027 | $doc = $(window.document), |
||
| 1028 | oBigDropZone = $(Utils.getValue(self.oOptions, 'dragAndDropBodyElement', false) || $doc), |
||
| 1029 | oDragAndDropElement = Utils.getValue(self.oOptions, 'dragAndDropElement', false), |
||
| 1030 | fHandleDragOver = function (oEvent) { |
||
| 1031 | if (self.bEnableDnD && oEvent) |
||
| 1032 | { |
||
| 1033 | oEvent = Utils.getEvent(oEvent); |
||
| 1034 | if (oEvent && oEvent.dataTransfer && Utils.eventContainsFiles(oEvent)) |
||
| 1035 | { |
||
| 1036 | try |
||
| 1037 | { |
||
| 1038 | var sEffect = oEvent.dataTransfer.effectAllowed; |
||
| 1039 | |||
| 1040 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1041 | |||
| 1042 | oEvent.dataTransfer.dropEffect = (sEffect === 'move' || sEffect === 'linkMove') ? 'move' : 'copy'; |
||
| 1043 | |||
| 1044 | oEvent.stopPropagation(); |
||
| 1045 | oEvent.preventDefault(); |
||
| 1046 | |||
| 1047 | oBigDropZone.trigger('dragover', oEvent); |
||
| 1048 | } |
||
| 1049 | catch (oExc) {} |
||
| 1050 | } |
||
| 1051 | } |
||
| 1052 | }, |
||
| 1053 | fHandleDrop = function (oEvent) { |
||
| 1054 | if (self.bEnableDnD && oEvent) |
||
| 1055 | { |
||
| 1056 | oEvent = Utils.getEvent(oEvent); |
||
| 1057 | if (oEvent && Utils.eventContainsFiles(oEvent)) |
||
| 1058 | { |
||
| 1059 | oEvent.preventDefault(); |
||
| 1060 | |||
| 1061 | Utils.getDataFromDragEvent(oEvent, function (oFile) { |
||
| 1062 | if (oFile) |
||
| 1063 | { |
||
| 1064 | self.runEvent('onDrop', [oFile, oEvent]); |
||
| 1065 | self.addNewFile(oFile); |
||
| 1066 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1067 | } |
||
| 1068 | }, |
||
| 1069 | Utils.getValue(self.oOptions, 'multipleSizeLimit', Globals.iDefLimit), |
||
| 1070 | self.getEvent('onLimitReached') |
||
| 1071 | ); |
||
| 1072 | } |
||
| 1073 | } |
||
| 1074 | |||
| 1075 | self.runEvent('onDragLeave', [oEvent]); |
||
| 1076 | }, |
||
| 1077 | fHandleDragEnter = function (oEvent) { |
||
| 1078 | if (self.bEnableDnD && oEvent) |
||
| 1079 | { |
||
| 1080 | oEvent = Utils.getEvent(oEvent); |
||
| 1081 | if (oEvent && Utils.eventContainsFiles(oEvent)) |
||
| 1082 | { |
||
| 1083 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1084 | |||
| 1085 | oEvent.preventDefault(); |
||
| 1086 | self.runEvent('onDragEnter', [oDragAndDropElement, oEvent]); |
||
| 1087 | } |
||
| 1088 | } |
||
| 1089 | }, |
||
| 1090 | fHandleDragLeave = function (oEvent) { |
||
| 1091 | if (self.bEnableDnD && oEvent) |
||
| 1092 | { |
||
| 1093 | oEvent = Utils.getEvent(oEvent); |
||
| 1094 | if (oEvent) |
||
| 1095 | { |
||
| 1096 | var oRelatedTarget = window.document['elementFromPoint'] ? window.document['elementFromPoint'](oEvent['clientX'], oEvent['clientY']) : null; |
||
| 1097 | if (oRelatedTarget && Utils.contains(this, oRelatedTarget)) |
||
| 1098 | { |
||
| 1099 | return; |
||
| 1100 | } |
||
| 1101 | |||
| 1102 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1103 | self.runEvent('onDragLeave', [oDragAndDropElement, oEvent]); |
||
| 1104 | } |
||
| 1105 | |||
| 1106 | return; |
||
| 1107 | } |
||
| 1108 | } |
||
| 1109 | ; |
||
| 1110 | |||
| 1111 | if (oDragAndDropElement) |
||
| 1112 | { |
||
| 1113 | if (!Utils.getValue(self.oOptions, 'disableDocumentDropPrevent', false)) |
||
| 1114 | { |
||
| 1115 | $doc.on('dragover', function (oEvent) { |
||
| 1116 | if (self.bEnableDnD && oEvent) |
||
| 1117 | { |
||
| 1118 | oEvent = Utils.getEvent(oEvent); |
||
| 1119 | if (oEvent && oEvent.dataTransfer && Utils.eventContainsFiles(oEvent)) |
||
| 1120 | { |
||
| 1121 | try |
||
| 1122 | { |
||
| 1123 | oEvent.dataTransfer.dropEffect = 'none'; |
||
| 1124 | oEvent.preventDefault(); |
||
| 1125 | } |
||
| 1126 | catch (oExc) {} |
||
| 1127 | } |
||
| 1128 | } |
||
| 1129 | }); |
||
| 1130 | } |
||
| 1131 | |||
| 1132 | if (oBigDropZone && oBigDropZone[0]) |
||
| 1133 | { |
||
| 1134 | oBigDropZone |
||
| 1135 | .on('dragover', function (oEvent) { |
||
| 1136 | if (self.bEnableDnD && oEvent) |
||
| 1137 | { |
||
| 1138 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1139 | } |
||
| 1140 | }) |
||
| 1141 | .on('dragenter', function (oEvent) { |
||
| 1142 | if (self.bEnableDnD && oEvent) |
||
| 1143 | { |
||
| 1144 | oEvent = Utils.getEvent(oEvent); |
||
| 1145 | if (oEvent && Utils.eventContainsFiles(oEvent)) |
||
| 1146 | { |
||
| 1147 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1148 | oEvent.preventDefault(); |
||
| 1149 | |||
| 1150 | self.runEvent('onBodyDragEnter', [oEvent]); |
||
| 1151 | } |
||
| 1152 | } |
||
| 1153 | }) |
||
| 1154 | .on('dragleave', function (oEvent) { |
||
| 1155 | if (self.bEnableDnD && oEvent) |
||
| 1156 | { |
||
| 1157 | oEvent = Utils.getEvent(oEvent); |
||
| 1158 | if (oEvent) |
||
| 1159 | { |
||
| 1160 | Utils.mainClearTimeout(self.iDocTimer); |
||
| 1161 | self.iDocTimer = setTimeout(function () { |
||
| 1162 | self.runEvent('onBodyDragLeave', [oEvent]); |
||
| 1163 | }, 200); |
||
| 1164 | } |
||
| 1165 | } |
||
| 1166 | }) |
||
| 1167 | .on('drop', function (oEvent) { |
||
| 1168 | if (self.bEnableDnD && oEvent) |
||
| 1169 | { |
||
| 1170 | oEvent = Utils.getEvent(oEvent); |
||
| 1171 | if (oEvent) |
||
| 1172 | { |
||
| 1173 | var bFiles = Utils.eventContainsFiles(oEvent); |
||
| 1174 | if (bFiles) |
||
| 1175 | { |
||
| 1176 | oEvent.preventDefault(); |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | self.runEvent('onBodyDragLeave', [oEvent]); |
||
| 1180 | |||
| 1181 | return !bFiles; |
||
| 1182 | } |
||
| 1183 | } |
||
| 1184 | |||
| 1185 | return false; |
||
| 1186 | }) |
||
| 1187 | ; |
||
| 1188 | } |
||
| 1189 | |||
| 1190 | $(oDragAndDropElement) |
||
| 1191 | .bind('dragenter', fHandleDragEnter) |
||
| 1192 | .bind('dragover', fHandleDragOver) |
||
| 1193 | .bind('dragleave', fHandleDragLeave) |
||
| 1194 | .bind('drop', fHandleDrop) |
||
| 1195 | ; |
||
| 1196 | } |
||
| 1197 | |||
| 1198 | }(self)); |
||
| 1199 | } |
||
| 1200 | else |
||
| 1201 | { |
||
| 1202 | self.bEnableDnD = false; |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | Utils.setValue(self, 'on', self.on); |
||
| 1206 | Utils.setValue(self, 'cancel', self.cancel); |
||
| 1207 | Utils.setValue(self, 'isDragAndDropSupported', self.isDragAndDropSupported); |
||
| 1208 | Utils.setValue(self, 'isAjaxUploaderSupported', self.isAjaxUploaderSupported); |
||
| 1209 | Utils.setValue(self, 'setDragAndDropEnabledStatus', self.setDragAndDropEnabledStatus); |
||
| 1210 | } |
||
| 1211 | |||
| 1212 | /** |
||
| 1213 | * @type {boolean} |
||
| 1214 | */ |
||
| 1215 | Jua.prototype.bEnableDnD = true; |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * @type {number} |
||
| 1219 | */ |
||
| 1220 | Jua.prototype.iDocTimer = 0; |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * @type {Object} |
||
| 1224 | */ |
||
| 1225 | Jua.prototype.oOptions = {}; |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * @type {Object} |
||
| 1229 | */ |
||
| 1230 | Jua.prototype.oEvents = {}; |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * @type {?Object} |
||
| 1234 | */ |
||
| 1235 | Jua.prototype.oQueue = null; |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * @type {?Object} |
||
| 1239 | */ |
||
| 1240 | Jua.prototype.oDriver = null; |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * @param {string} sName |
||
| 1244 | * @param {Function} fFunc |
||
| 1245 | */ |
||
| 1246 | Jua.prototype.on = function (sName, fFunc) |
||
| 1247 | { |
||
| 1248 | this.oEvents[sName] = fFunc; |
||
| 1249 | return this; |
||
| 1250 | }; |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | * @param {string} sName |
||
| 1254 | * @param {string=} aArgs |
||
| 1255 | */ |
||
| 1256 | Jua.prototype.runEvent = function (sName, aArgs) |
||
| 1257 | { |
||
| 1258 | if (this.oEvents[sName]) |
||
| 1259 | { |
||
| 1260 | this.oEvents[sName].apply(null, aArgs || []); |
||
| 1261 | } |
||
| 1262 | }; |
||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * @param {string} sName |
||
| 1266 | */ |
||
| 1267 | Jua.prototype.getEvent = function (sName) |
||
| 1268 | { |
||
| 1269 | return this.oEvents[sName] || null; |
||
| 1270 | }; |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * @param {string} sUid |
||
| 1274 | */ |
||
| 1275 | Jua.prototype.cancel = function (sUid) |
||
| 1276 | { |
||
| 1277 | this.oDriver.cancel(sUid); |
||
| 1278 | }; |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * @return {boolean} |
||
| 1282 | */ |
||
| 1283 | Jua.prototype.isAjaxUploaderSupported = function () |
||
| 1284 | { |
||
| 1285 | return Globals.bIsAjaxUploaderSupported; |
||
| 1286 | }; |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * @param {boolean} bEnabled |
||
| 1290 | */ |
||
| 1291 | Jua.prototype.setDragAndDropEnabledStatus = function (bEnabled) |
||
| 1292 | { |
||
| 1293 | this.bEnableDnD = !!bEnabled; |
||
| 1294 | }; |
||
| 1295 | |||
| 1296 | /** |
||
| 1297 | * @return {boolean} |
||
| 1298 | */ |
||
| 1299 | Jua.prototype.isDragAndDropSupported = function () |
||
| 1300 | { |
||
| 1301 | return this.oDriver.isDragAndDropSupported(); |
||
| 1302 | }; |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * @param {Object} oFileInfo |
||
| 1306 | */ |
||
| 1307 | Jua.prototype.addNewFile = function (oFileInfo) |
||
| 1308 | { |
||
| 1309 | this.addFile(Utils.getNewUid(), oFileInfo); |
||
| 1310 | }; |
||
| 1311 | |||
| 1312 | /** |
||
| 1313 | * @param {string} sUid |
||
| 1314 | * @param {Object} oFileInfo |
||
| 1315 | */ |
||
| 1316 | Jua.prototype.addFile = function (sUid, oFileInfo) |
||
| 1317 | { |
||
| 1318 | var fOnSelect = this.getEvent('onSelect'); |
||
| 1319 | if (oFileInfo && (!fOnSelect || (false !== fOnSelect(sUid, oFileInfo)))) |
||
| 1320 | { |
||
| 1321 | this.oDriver.regTaskUid(sUid); |
||
| 1322 | this.oQueue.defer(Utils.scopeBind(this.oDriver.uploadTask, this.oDriver), sUid, oFileInfo); |
||
| 1323 | } |
||
| 1324 | else |
||
| 1325 | { |
||
| 1326 | this.oDriver.cancel(sUid); |
||
| 1327 | } |
||
| 1328 | }; |
||
| 1329 | |||
| 1330 | module.exports = Jua; |
||
| 1331 | |||
| 1332 | }()); |
||
| 1333 | |||
| 1334 | |||
| 1335 | /***/ }, |
||
| 1336 | /* 8 */ |
||
| 1337 | /***/ function(module, exports, __webpack_require__) { |
||
| 1338 | |||
| 1339 | module.exports = queue; |
||
| 1340 | |||
| 1341 | /***/ } |
||
| 1342 | /******/ ]); |