' ).data( 'last-err', id );
+ '' + pluploadL10n.dismiss + '' +
+ '' + pluploadL10n.error_uploading.replace( '%s', jQuery.trim( filename )) + ' ' +
+ message +
+ '' ).data( 'last-err', id );
}
function deleteSuccess( data ) {
@@ -323,10 +323,10 @@ function uploadError( fileObj, errorCode, message, up ) {
case plupload.SECURITY_ERROR:
wpQueueError( pluploadL10n.security_error );
break;
-/* case plupload.UPLOAD_ERROR.UPLOAD_STOPPED:
- case plupload.UPLOAD_ERROR.FILE_CANCELLED:
- jQuery( '#media-item-' + fileObj.id ).remove();
- break;*/
+ /* case plupload.UPLOAD_ERROR.UPLOAD_STOPPED:
+ case plupload.UPLOAD_ERROR.FILE_CANCELLED:
+ jQuery( '#media-item-' + fileObj.id ).remove();
+ break;*/
default:
wpFileError( fileObj, pluploadL10n.default_error );
}
@@ -461,7 +461,7 @@ jQuery( document ).ready( function( $ ) {
action: 'media-create-image-subsizes',
_wpnonce: wpUploaderInit.multipart_params._wpnonce,
attachment_id: id,
- _wp_upload_failed_cleanup: true,
+ _wp_upload_failed_cleanup: true
}
});
@@ -489,7 +489,7 @@ jQuery( document ).ready( function( $ ) {
action: 'media-create-image-subsizes',
_wpnonce: wpUploaderInit.multipart_params._wpnonce,
attachment_id: id,
- _legacy_support: 'true',
+ _legacy_support: 'true'
}
}).done( function( response ) {
var message;
@@ -512,7 +512,7 @@ jQuery( document ).ready( function( $ ) {
wpQueueError( pluploadL10n.http_error_image );
});
- }
+ };
// init and set the uploader
uploader_init = function() {
diff --git a/wp-includes/js/plupload/license.txt b/wp-includes/js/plupload/license.txt
deleted file mode 100644
index d511905c16..0000000000
--- a/wp-includes/js/plupload/license.txt
+++ /dev/null
@@ -1,339 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
diff --git a/wp-includes/js/plupload/moxie.js b/wp-includes/js/plupload/moxie.js
index c7d26f4c4e..7568395346 100644
--- a/wp-includes/js/plupload/moxie.js
+++ b/wp-includes/js/plupload/moxie.js
@@ -1,7 +1,7 @@
;var MXI_DEBUG = false;
/**
* mOxie - multi-runtime File API & XMLHttpRequest L2 Polyfill
- * v1.3.5
+ * v1.5.7
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
@@ -9,17 +9,27 @@
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
- * Date: 2016-05-15
+ * Date: 2017-11-03
*/
+;(function (global, factory) {
+ var extract = function() {
+ var ctx = {};
+ factory.apply(ctx, arguments);
+ return ctx.moxie;
+ };
+
+ if (typeof define === "function" && define.amd) {
+ define("moxie", [], extract);
+ } else if (typeof module === "object" && module.exports) {
+ module.exports = extract();
+ } else {
+ global.moxie = extract();
+ }
+}(this || window, function() {
/**
* Compiled inline version. (Library mode)
*/
-/**
- * Modified for WordPress, Silverlight and Flash runtimes support was removed.
- * See https://core.trac.wordpress.org/ticket/41755.
- */
-
/*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
/*globals $code */
@@ -110,18 +120,23 @@
* Contributing: http://www.plupload.com/contributing
*/
+/**
+@class moxie/core/utils/Basic
+@public
+@static
+*/
+
define('moxie/core/utils/Basic', [], function() {
/**
Gets the true type of the built-in object (better version of typeof).
@author Angus Croll (http://javascriptweblog.wordpress.com/)
@method typeOf
- @for Utils
@static
@param {Object} o Object to check.
@return {String} Object [[Class]]
*/
- var typeOf = function(o) {
+ function typeOf(o) {
var undef;
if (o === undef) {
@@ -134,10 +149,10 @@ define('moxie/core/utils/Basic', [], function() {
// the snippet below is awesome, however it fails to detect null, undefined and arguments types in IE lte 8
return ({}).toString.call(o).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
- };
-
+ }
+
/**
- Extends the specified object with another object.
+ Extends the specified object with another object(s).
@method extend
@static
@@ -145,25 +160,131 @@ define('moxie/core/utils/Basic', [], function() {
@param {Object} [obj]* Multiple objects to extend with.
@return {Object} Same as target, the extended object.
*/
- var extend = function(target) {
- var undef;
+ function extend() {
+ return merge(false, false, arguments);
+ }
- each(arguments, function(arg, i) {
+
+ /**
+ Extends the specified object with another object(s), but only if the property exists in the target.
+
+ @method extendIf
+ @static
+ @param {Object} target Object to extend.
+ @param {Object} [obj]* Multiple objects to extend with.
+ @return {Object} Same as target, the extended object.
+ */
+ function extendIf() {
+ return merge(true, false, arguments);
+ }
+
+
+ function extendImmutable() {
+ return merge(false, true, arguments);
+ }
+
+
+ function extendImmutableIf() {
+ return merge(true, true, arguments);
+ }
+
+
+ function clone(value) {
+ switch (typeOf(value)) {
+ case 'array':
+ return merge(false, true, [[], value]);
+
+ case 'object':
+ return merge(false, true, [{}, value]);
+
+ default:
+ return value;
+ }
+ }
+
+
+ function shallowCopy(obj) {
+ switch (typeOf(obj)) {
+ case 'array':
+ return Array.prototype.slice.call(obj);
+
+ case 'object':
+ return extend({}, obj);
+ }
+ return obj;
+ }
+
+
+ function merge(strict, immutable, args) {
+ var undef;
+ var target = args[0];
+
+ each(args, function(arg, i) {
if (i > 0) {
each(arg, function(value, key) {
- if (value !== undef) {
- if (typeOf(target[key]) === typeOf(value) && !!~inArray(typeOf(value), ['array', 'object'])) {
- extend(target[key], value);
- } else {
- target[key] = value;
- }
+ var isComplex = inArray(typeOf(value), ['array', 'object']) !== -1;
+
+ if (value === undef || strict && target[key] === undef) {
+ return true;
+ }
+
+ if (isComplex && immutable) {
+ value = shallowCopy(value);
+ }
+
+ if (typeOf(target[key]) === typeOf(value) && isComplex) {
+ merge(strict, immutable, [target[key], value]);
+ } else {
+ target[key] = value;
}
});
}
});
+
return target;
- };
-
+ }
+
+
+ /**
+ A way to inherit one `class` from another in a consisstent way (more or less)
+
+ @method inherit
+ @static
+ @since >1.4.1
+ @param {Function} child
+ @param {Function} parent
+ @return {Function} Prepared constructor
+ */
+ function inherit(child, parent) {
+ // copy over all parent properties
+ for (var key in parent) {
+ if ({}.hasOwnProperty.call(parent, key)) {
+ child[key] = parent[key];
+ }
+ }
+
+ // give child `class` a place to define its own methods
+ function ctor() {
+ this.constructor = child;
+
+ if (MXI_DEBUG) {
+ var getCtorName = function(fn) {
+ var m = fn.toString().match(/^function\s([^\(\s]+)/);
+ return m ? m[1] : false;
+ };
+
+ this.ctorName = getCtorName(child);
+ }
+ }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+
+ // keep a way to reference parent methods
+ child.parent = parent.prototype;
+ return child;
+ }
+
+
/**
Executes the callback function for each item in array/object. If you return false in the
callback it will break the loop.
@@ -173,18 +294,17 @@ define('moxie/core/utils/Basic', [], function() {
@param {Object} obj Object to iterate.
@param {function} callback Callback function to execute for each item.
*/
- var each = function(obj, callback) {
+ function each(obj, callback) {
var length, key, i, undef;
if (obj) {
- if (typeOf(obj.length) === 'number') { // it might be Array, FileList or even arguments object
- // Loop array items
- for (i = 0, length = obj.length; i < length; i++) {
- if (callback(obj[i], i) === false) {
- return;
- }
- }
- } else if (typeOf(obj) === 'object') {
+ try {
+ length = obj.length;
+ } catch(ex) {
+ length = undef;
+ }
+
+ if (length === undef || typeof(length) !== 'number') {
// Loop object items
for (key in obj) {
if (obj.hasOwnProperty(key)) {
@@ -193,19 +313,26 @@ define('moxie/core/utils/Basic', [], function() {
}
}
}
+ } else {
+ // Loop array items
+ for (i = 0; i < length; i++) {
+ if (callback(obj[i], i) === false) {
+ return;
+ }
+ }
}
}
- };
+ }
/**
Checks if object is empty.
-
+
@method isEmptyObj
@static
@param {Object} o Object to check.
@return {Boolean}
*/
- var isEmptyObj = function(obj) {
+ function isEmptyObj(obj) {
var prop;
if (!obj || typeOf(obj) !== 'object') {
@@ -217,7 +344,7 @@ define('moxie/core/utils/Basic', [], function() {
}
return true;
- };
+ }
/**
Recieve an array of functions (usually async) to call in sequence, each function
@@ -231,7 +358,7 @@ define('moxie/core/utils/Basic', [], function() {
@param {Array} queue Array of functions to call in sequence
@param {Function} cb Main callback that is called in the end, or in case of error
*/
- var inSeries = function(queue, cb) {
+ function inSeries(queue, cb) {
var i = 0, length = queue.length;
if (typeOf(cb) !== 'function') {
@@ -251,12 +378,12 @@ define('moxie/core/utils/Basic', [], function() {
}
}
callNext(i);
- };
+ }
/**
Recieve an array of functions (usually async) to call in parallel, each function
- receives a callback as first argument that it should call, when it completes. After
+ receives a callback as first argument that it should call, when it completes. After
everything is complete, main callback is called. Passing truthy value to the
callback as a first argument will interrupt the process and invoke main callback
immediately.
@@ -264,9 +391,9 @@ define('moxie/core/utils/Basic', [], function() {
@method inParallel
@static
@param {Array} queue Array of functions to call in sequence
- @param {Function} cb Main callback that is called in the end, or in case of error
+ @param {Function} cb Main callback that is called in the end, or in case of erro
*/
- var inParallel = function(queue, cb) {
+ function inParallel(queue, cb) {
var count = 0, num = queue.length, cbArgs = new Array(num);
each(queue, function(fn, i) {
@@ -274,7 +401,7 @@ define('moxie/core/utils/Basic', [], function() {
if (error) {
return cb(error);
}
-
+
var args = [].slice.call(arguments);
args.shift(); // strip error - undefined or not
@@ -284,27 +411,27 @@ define('moxie/core/utils/Basic', [], function() {
if (count === num) {
cbArgs.unshift(null);
cb.apply(this, cbArgs);
- }
+ }
});
});
- };
-
-
+ }
+
+
/**
Find an element in array and return it's index if present, otherwise return -1.
-
+
@method inArray
@static
@param {Mixed} needle Element to find
@param {Array} array
@return {Int} Index of the element, or -1 if not found
*/
- var inArray = function(needle, array) {
+ function inArray(needle, array) {
if (array) {
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(array, needle);
}
-
+
for (var i = 0, length = array.length; i < length; i++) {
if (array[i] === needle) {
return i;
@@ -312,7 +439,7 @@ define('moxie/core/utils/Basic', [], function() {
}
}
return -1;
- };
+ }
/**
@@ -324,7 +451,7 @@ define('moxie/core/utils/Basic', [], function() {
@param {Array} array
@return {Array|Boolean}
*/
- var arrayDiff = function(needles, array) {
+ function arrayDiff(needles, array) {
var diff = [];
if (typeOf(needles) !== 'array') {
@@ -338,10 +465,10 @@ define('moxie/core/utils/Basic', [], function() {
for (var i in needles) {
if (inArray(needles[i], array) === -1) {
diff.push(needles[i]);
- }
+ }
}
return diff.length ? diff : false;
- };
+ }
/**
@@ -353,7 +480,7 @@ define('moxie/core/utils/Basic', [], function() {
@param {Array} array2
@return {Array} Intersection of two arrays or null if there is none
*/
- var arrayIntersect = function(array1, array2) {
+ function arrayIntersect(array1, array2) {
var result = [];
each(array1, function(item) {
if (inArray(item, array2) !== -1) {
@@ -361,18 +488,18 @@ define('moxie/core/utils/Basic', [], function() {
}
});
return result.length ? result : null;
- };
-
-
+ }
+
+
/**
Forces anything into an array.
-
+
@method toArray
@static
@param {Object} obj Object with length field.
@return {Array} Array object containing all items.
*/
- var toArray = function(obj) {
+ function toArray(obj) {
var i, arr = [];
for (i = 0; i < obj.length; i++) {
@@ -380,15 +507,15 @@ define('moxie/core/utils/Basic', [], function() {
}
return arr;
- };
-
-
+ }
+
+
/**
Generates an unique ID. The only way a user would be able to get the same ID is if the two persons
- at the same exact millisecond manage to get the same 5 random numbers between 0-65535; it also uses
- a counter so each ID is guaranteed to be unique for the given page. It is more probable for the earth
+ at the same exact millisecond manage to get the same 5 random numbers between 0-65535; it also uses
+ a counter so each ID is guaranteed to be unique for the given page. It is more probable for the earth
to be hit with an asteroid.
-
+
@method guid
@static
@param {String} prefix to prepend (by default 'o' will be prepended).
@@ -397,48 +524,48 @@ define('moxie/core/utils/Basic', [], function() {
*/
var guid = (function() {
var counter = 0;
-
+
return function(prefix) {
var guid = new Date().getTime().toString(32), i;
for (i = 0; i < 5; i++) {
guid += Math.floor(Math.random() * 65535).toString(32);
}
-
+
return (prefix || 'o_') + guid + (counter++).toString(32);
};
}());
-
+
/**
Trims white spaces around the string
-
+
@method trim
@static
@param {String} str
@return {String}
*/
- var trim = function(str) {
+ function trim(str) {
if (!str) {
return str;
}
return String.prototype.trim ? String.prototype.trim.call(str) : str.toString().replace(/^\s*/, '').replace(/\s*$/, '');
- };
+ }
/**
Parses the specified size string into a byte value. For example 10kb becomes 10240.
-
+
@method parseSizeStr
@static
@param {String/Number} size String to parse or number to just pass through.
@return {Number} Size in bytes.
*/
- var parseSizeStr = function(size) {
+ function parseSizeStr(size) {
if (typeof(size) !== 'string') {
return size;
}
-
+
var muls = {
t: 1099511627776,
g: 1073741824,
@@ -447,16 +574,15 @@ define('moxie/core/utils/Basic', [], function() {
},
mul;
-
size = /^([0-9\.]+)([tmgk]?)$/.exec(size.toLowerCase().replace(/[^0-9\.tmkg]/g, ''));
mul = size[2];
size = +size[1];
-
+
if (muls.hasOwnProperty(mul)) {
size *= muls[mul];
}
return Math.floor(size);
- };
+ }
/**
@@ -465,20 +591,50 @@ define('moxie/core/utils/Basic', [], function() {
* @param {String} str String with tokens
* @return {String} String with replaced tokens
*/
- var sprintf = function(str) {
+ function sprintf(str) {
var args = [].slice.call(arguments, 1);
- return str.replace(/%[a-z]/g, function() {
+ return str.replace(/%([a-z])/g, function($0, $1) {
var value = args.shift();
- return typeOf(value) !== 'undefined' ? value : '';
+
+ switch ($1) {
+ case 's':
+ return value + '';
+
+ case 'd':
+ return parseInt(value, 10);
+
+ case 'f':
+ return parseFloat(value);
+
+ case 'c':
+ return '';
+
+ default:
+ return value;
+ }
});
- };
-
+ }
+
+
+
+ function delay(cb, timeout) {
+ var self = this;
+ setTimeout(function() {
+ cb.call(self);
+ }, timeout || 1);
+ }
+
return {
guid: guid,
typeOf: typeOf,
extend: extend,
+ extendIf: extendIf,
+ extendImmutable: extendImmutable,
+ extendImmutableIf: extendImmutableIf,
+ clone: clone,
+ inherit: inherit,
each: each,
isEmptyObj: isEmptyObj,
inSeries: inSeries,
@@ -489,7 +645,193 @@ define('moxie/core/utils/Basic', [], function() {
toArray: toArray,
trim: trim,
sprintf: sprintf,
- parseSizeStr: parseSizeStr
+ parseSizeStr: parseSizeStr,
+ delay: delay
+ };
+});
+
+// Included from: src/javascript/core/utils/Encode.js
+
+/**
+ * Encode.js
+ *
+ * Copyright 2013, Moxiecode Systems AB
+ * Released under GPL License.
+ *
+ * License: http://www.plupload.com/license
+ * Contributing: http://www.plupload.com/contributing
+ */
+
+/**
+@class moxie/core/utils/Encode
+@public
+@static
+*/
+
+define('moxie/core/utils/Encode', [], function() {
+
+ /**
+ Encode string with UTF-8
+
+ @method utf8_encode
+ @static
+ @param {String} str String to encode
+ @return {String} UTF-8 encoded string
+ */
+ var utf8_encode = function(str) {
+ return unescape(encodeURIComponent(str));
+ };
+
+ /**
+ Decode UTF-8 encoded string
+
+ @method utf8_decode
+ @static
+ @param {String} str String to decode
+ @return {String} Decoded string
+ */
+ var utf8_decode = function(str_data) {
+ return decodeURIComponent(escape(str_data));
+ };
+
+ /**
+ Decode Base64 encoded string (uses browser's default method if available),
+ from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_decode.js
+
+ @method atob
+ @static
+ @param {String} data String to decode
+ @return {String} Decoded string
+ */
+ var atob = function(data, utf8) {
+ if (typeof(window.atob) === 'function') {
+ return utf8 ? utf8_decode(window.atob(data)) : window.atob(data);
+ }
+
+ // http://kevin.vanzonneveld.net
+ // + original by: Tyler Akins (http://rumkin.com)
+ // + improved by: Thunder.m
+ // + input by: Aman Gupta
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + bugfixed by: Onno Marsman
+ // + bugfixed by: Pellentesque Malesuada
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + input by: Brett Zamir (http://brett-zamir.me)
+ // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // * example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
+ // * returns 1: 'Kevin van Zonneveld'
+ // mozilla has this native
+ // - but breaks in 2.0.0.12!
+ //if (typeof this.window.atob == 'function') {
+ // return atob(data);
+ //}
+ var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
+ ac = 0,
+ dec = "",
+ tmp_arr = [];
+
+ if (!data) {
+ return data;
+ }
+
+ data += '';
+
+ do { // unpack four hexets into three octets using index points in b64
+ h1 = b64.indexOf(data.charAt(i++));
+ h2 = b64.indexOf(data.charAt(i++));
+ h3 = b64.indexOf(data.charAt(i++));
+ h4 = b64.indexOf(data.charAt(i++));
+
+ bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
+
+ o1 = bits >> 16 & 0xff;
+ o2 = bits >> 8 & 0xff;
+ o3 = bits & 0xff;
+
+ if (h3 == 64) {
+ tmp_arr[ac++] = String.fromCharCode(o1);
+ } else if (h4 == 64) {
+ tmp_arr[ac++] = String.fromCharCode(o1, o2);
+ } else {
+ tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
+ }
+ } while (i < data.length);
+
+ dec = tmp_arr.join('');
+
+ return utf8 ? utf8_decode(dec) : dec;
+ };
+
+ /**
+ Base64 encode string (uses browser's default method if available),
+ from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_encode.js
+
+ @method btoa
+ @static
+ @param {String} data String to encode
+ @return {String} Base64 encoded string
+ */
+ var btoa = function(data, utf8) {
+ if (utf8) {
+ data = utf8_encode(data);
+ }
+
+ if (typeof(window.btoa) === 'function') {
+ return window.btoa(data);
+ }
+
+ // http://kevin.vanzonneveld.net
+ // + original by: Tyler Akins (http://rumkin.com)
+ // + improved by: Bayron Guevara
+ // + improved by: Thunder.m
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + bugfixed by: Pellentesque Malesuada
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + improved by: RafaĆ Kukawski (http://kukawski.pl)
+ // * example 1: base64_encode('Kevin van Zonneveld');
+ // * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
+ // mozilla has this native
+ // - but breaks in 2.0.0.12!
+ var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
+ ac = 0,
+ enc = "",
+ tmp_arr = [];
+
+ if (!data) {
+ return data;
+ }
+
+ do { // pack three octets into four hexets
+ o1 = data.charCodeAt(i++);
+ o2 = data.charCodeAt(i++);
+ o3 = data.charCodeAt(i++);
+
+ bits = o1 << 16 | o2 << 8 | o3;
+
+ h1 = bits >> 18 & 0x3f;
+ h2 = bits >> 12 & 0x3f;
+ h3 = bits >> 6 & 0x3f;
+ h4 = bits & 0x3f;
+
+ // use hexets to index into b64, and append result to encoded string
+ tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
+ } while (i < data.length);
+
+ enc = tmp_arr.join('');
+
+ var r = data.length % 3;
+
+ return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
+ };
+
+
+ return {
+ utf8_encode: utf8_encode,
+ utf8_decode: utf8_decode,
+ atob: atob,
+ btoa: btoa
};
});
@@ -505,10 +847,16 @@ define('moxie/core/utils/Basic', [], function() {
* Contributing: http://www.plupload.com/contributing
*/
+/**
+@class moxie/core/utils/Env
+@public
+@static
+*/
+
define("moxie/core/utils/Env", [
"moxie/core/utils/Basic"
], function(Basic) {
-
+
/**
* UAParser.js v0.7.7
* Lightweight JavaScript-based User-Agent string parser
@@ -711,7 +1059,7 @@ define("moxie/core/utils/Env", [
var regexes = {
browser : [[
-
+
// Presto based
/(opera\smini)\/([\w\.-]+)/i, // Opera Mini
/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
@@ -1046,85 +1394,119 @@ define("moxie/core/utils/Env", [
var can = (function() {
var caps = {
- define_property: (function() {
- /* // currently too much extra code required, not exactly worth it
- try { // as of IE8, getters/setters are supported only on DOM elements
- var obj = {};
- if (Object.defineProperty) {
- Object.defineProperty(obj, 'prop', {
- enumerable: true,
- configurable: true
- });
- return true;
- }
- } catch(ex) {}
+ access_global_ns: function () {
+ return !!window.moxie;
+ },
- if (Object.prototype.__defineGetter__ && Object.prototype.__defineSetter__) {
+ define_property: (function() {
+ /* // currently too much extra code required, not exactly worth it
+ try { // as of IE8, getters/setters are supported only on DOM elements
+ var obj = {};
+ if (Object.defineProperty) {
+ Object.defineProperty(obj, 'prop', {
+ enumerable: true,
+ configurable: true
+ });
return true;
- }*/
- return false;
- }()),
-
- create_canvas: (function() {
- // On the S60 and BB Storm, getContext exists, but always returns undefined
- // so we actually have to call getContext() to verify
- // github.com/Modernizr/Modernizr/issues/issue/97/
- var el = document.createElement('canvas');
- return !!(el.getContext && el.getContext('2d'));
- }()),
-
- return_response_type: function(responseType) {
- try {
- if (Basic.inArray(responseType, ['', 'text', 'document']) !== -1) {
- return true;
- } else if (window.XMLHttpRequest) {
- var xhr = new XMLHttpRequest();
- xhr.open('get', '/'); // otherwise Gecko throws an exception
- if ('responseType' in xhr) {
- xhr.responseType = responseType;
- // as of 23.0.1271.64, Chrome switched from throwing exception to merely logging it to the console (why? o why?)
- if (xhr.responseType !== responseType) {
- return false;
- }
- return true;
- }
- }
- } catch (ex) {}
- return false;
- },
-
- // ideas for this heavily come from Modernizr (http://modernizr.com/)
- use_data_uri: (function() {
- var du = new Image();
-
- du.onload = function() {
- caps.use_data_uri = (du.width === 1 && du.height === 1);
- };
-
- setTimeout(function() {
- du.src = "data:image/gif;base64,R0lGODlhAQABAIAAAP8AAAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==";
- }, 1);
- return false;
- }()),
-
- use_data_uri_over32kb: function() { // IE8
- return caps.use_data_uri && (Env.browser !== 'IE' || Env.version >= 9);
- },
-
- use_data_uri_of: function(bytes) {
- return (caps.use_data_uri && bytes < 33000 || caps.use_data_uri_over32kb());
- },
-
- use_fileinput: function() {
- if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) {
- return false;
}
+ } catch(ex) {}
- var el = document.createElement('input');
- el.setAttribute('type', 'file');
- return !el.disabled;
+ if (Object.prototype.__defineGetter__ && Object.prototype.__defineSetter__) {
+ return true;
+ }*/
+ return false;
+ }()),
+
+ create_canvas: function() {
+ // On the S60 and BB Storm, getContext exists, but always returns undefined
+ // so we actually have to call getContext() to verify
+ // github.com/Modernizr/Modernizr/issues/issue/97/
+ var el = document.createElement('canvas');
+ var isSupported = !!(el.getContext && el.getContext('2d'));
+ caps.create_canvas = isSupported;
+ return isSupported;
+ },
+
+ return_response_type: function(responseType) {
+ try {
+ if (Basic.inArray(responseType, ['', 'text', 'document']) !== -1) {
+ return true;
+ } else if (window.XMLHttpRequest) {
+ var xhr = new XMLHttpRequest();
+ xhr.open('get', '/'); // otherwise Gecko throws an exception
+ if ('responseType' in xhr) {
+ xhr.responseType = responseType;
+ // as of 23.0.1271.64, Chrome switched from throwing exception to merely logging it to the console (why? o why?)
+ if (xhr.responseType !== responseType) {
+ return false;
+ }
+ return true;
+ }
+ }
+ } catch (ex) {}
+ return false;
+ },
+
+ use_blob_uri: function() {
+ var URL = window.URL;
+ caps.use_blob_uri = (URL &&
+ 'createObjectURL' in URL &&
+ 'revokeObjectURL' in URL &&
+ (Env.browser !== 'IE' || Env.verComp(Env.version, '11.0.46', '>=')) // IE supports createObjectURL, but not fully, for example it fails to use it as a src for the image
+ );
+ return caps.use_blob_uri;
+ },
+
+ // ideas for this heavily come from Modernizr (http://modernizr.com/)
+ use_data_uri: (function() {
+ var du = new Image();
+
+ du.onload = function() {
+ caps.use_data_uri = (du.width === 1 && du.height === 1);
+ };
+
+ setTimeout(function() {
+ du.src = "data:image/gif;base64,R0lGODlhAQABAIAAAP8AAAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==";
+ }, 1);
+ return false;
+ }()),
+
+ use_data_uri_over32kb: function() { // IE8
+ return caps.use_data_uri && (Env.browser !== 'IE' || Env.version >= 9);
+ },
+
+ use_data_uri_of: function(bytes) {
+ return (caps.use_data_uri && bytes < 33000 || caps.use_data_uri_over32kb());
+ },
+
+ use_fileinput: function() {
+ if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) {
+ return false;
}
- };
+
+ var el = document.createElement('input');
+ el.setAttribute('type', 'file');
+ return caps.use_fileinput = !el.disabled;
+ },
+
+ use_webgl: function() {
+ var canvas = document.createElement('canvas');
+ var gl = null, isSupported;
+ try {
+ gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
+ }
+ catch(e) {}
+
+ if (!gl) { // it seems that sometimes it doesn't throw exception, but still fails to get context
+ gl = null;
+ }
+
+ isSupported = !!gl;
+ caps.use_webgl = isSupported; // save result of our check
+ canvas = undefined;
+ return isSupported;
+ }
+ };
return function(cap) {
var args = [].slice.call(arguments);
@@ -1141,7 +1523,7 @@ define("moxie/core/utils/Env", [
can: can,
uaParser: UAParser,
-
+
browser: uaResult.browser.name,
version: uaResult.browser.version,
os: uaResult.os.name, // everybody intuitively types it in a lowercase for some reason
@@ -1149,6 +1531,8 @@ define("moxie/core/utils/Env", [
verComp: version_compare,
+ swf_url: "../flash/Moxie.swf",
+ xap_url: "../silverlight/Moxie.xap",
global_event_dispatcher: "moxie.core.EventTarget.instance.dispatchEvent"
};
@@ -1163,20 +1547,15 @@ define("moxie/core/utils/Env", [
};
Env.log = function() {
-
+
function logObj(data) {
// TODO: this should recursively print out the object in a pretty way
console.appendChild(document.createTextNode(data + "\n"));
}
- var data = arguments[0];
-
- if (Basic.typeOf(data) === 'string') {
- data = Basic.sprintf.apply(this, arguments);
- }
-
- if (window && window.console && window.console.log) {
- window.console.log(data);
+ // if debugger present, IE8 might have window.console.log method, but not be able to apply on it (why...)
+ if (window && window.console && window.console.log && window.console.log.apply) {
+ window.console.log.apply(window.console, arguments);
} else if (document) {
var console = document.getElementById('moxie-console');
if (!console) {
@@ -1186,11 +1565,15 @@ define("moxie/core/utils/Env", [
document.body.appendChild(console);
}
- if (Basic.inArray(Basic.typeOf(data), ['object', 'array']) !== -1) {
+ var data = arguments[0];
+ if (Basic.typeOf(data) === 'string') {
+ data = Basic.sprintf.apply(this, arguments);
+ } else if (Basic.inArray(Basic.typeOf(data), ['object', 'array']) !== -1) {
logObj(data);
- } else {
- console.appendChild(document.createTextNode(data + "\n"));
+ return;
}
+
+ console.appendChild(document.createTextNode(data + "\n"));
}
};
}
@@ -1198,10 +1581,10 @@ define("moxie/core/utils/Env", [
return Env;
});
-// Included from: src/javascript/core/I18n.js
+// Included from: src/javascript/core/Exceptions.js
/**
- * I18n.js
+ * Exceptions.js
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
@@ -1210,254 +1593,158 @@ define("moxie/core/utils/Env", [
* Contributing: http://www.plupload.com/contributing
*/
-define("moxie/core/I18n", [
- "moxie/core/utils/Basic"
+define('moxie/core/Exceptions', [
+ 'moxie/core/utils/Basic'
], function(Basic) {
- var i18n = {};
+
+ function _findKey(obj, value) {
+ var key;
+ for (key in obj) {
+ if (obj[key] === value) {
+ return key;
+ }
+ }
+ return null;
+ }
+ /**
+ @class moxie/core/Exception
+ */
return {
- /**
- * Extends the language pack object with new items.
- *
- * @param {Object} pack Language pack items to add.
- * @return {Object} Extended language pack object.
- */
- addI18n: function(pack) {
- return Basic.extend(i18n, pack);
- },
+ RuntimeError: (function() {
+ var namecodes = {
+ NOT_INIT_ERR: 1,
+ EXCEPTION_ERR: 3,
+ NOT_SUPPORTED_ERR: 9,
+ JS_ERR: 4
+ };
- /**
- * Translates the specified string by checking for the english string in the language pack lookup.
- *
- * @param {String} str String to look for.
- * @return {String} Translated string or the input string if it wasn't found.
- */
- translate: function(str) {
- return i18n[str] || str;
- },
-
- /**
- * Shortcut for translate function
- *
- * @param {String} str String to look for.
- * @return {String} Translated string or the input string if it wasn't found.
- */
- _: function(str) {
- return this.translate(str);
- },
-
- /**
- * Pseudo sprintf implementation - simple way to replace tokens with specified values.
- *
- * @param {String} str String with tokens
- * @return {String} String with replaced tokens
- */
- sprintf: function(str) {
- var args = [].slice.call(arguments, 1);
-
- return str.replace(/%[a-z]/g, function() {
- var value = args.shift();
- return Basic.typeOf(value) !== 'undefined' ? value : '';
+ function RuntimeError(code, message) {
+ this.code = code;
+ this.name = _findKey(namecodes, code);
+ this.message = this.name + (message || ": RuntimeError " + this.code);
+ }
+
+ Basic.extend(RuntimeError, namecodes);
+ RuntimeError.prototype = Error.prototype;
+ return RuntimeError;
+ }()),
+
+ OperationNotAllowedException: (function() {
+
+ function OperationNotAllowedException(code) {
+ this.code = code;
+ this.name = 'OperationNotAllowedException';
+ }
+
+ Basic.extend(OperationNotAllowedException, {
+ NOT_ALLOWED_ERR: 1
});
- }
+
+ OperationNotAllowedException.prototype = Error.prototype;
+
+ return OperationNotAllowedException;
+ }()),
+
+ ImageError: (function() {
+ var namecodes = {
+ WRONG_FORMAT: 1,
+ MAX_RESOLUTION_ERR: 2,
+ INVALID_META_ERR: 3
+ };
+
+ function ImageError(code) {
+ this.code = code;
+ this.name = _findKey(namecodes, code);
+ this.message = this.name + ": ImageError " + this.code;
+ }
+
+ Basic.extend(ImageError, namecodes);
+ ImageError.prototype = Error.prototype;
+
+ return ImageError;
+ }()),
+
+ FileException: (function() {
+ var namecodes = {
+ NOT_FOUND_ERR: 1,
+ SECURITY_ERR: 2,
+ ABORT_ERR: 3,
+ NOT_READABLE_ERR: 4,
+ ENCODING_ERR: 5,
+ NO_MODIFICATION_ALLOWED_ERR: 6,
+ INVALID_STATE_ERR: 7,
+ SYNTAX_ERR: 8
+ };
+
+ function FileException(code) {
+ this.code = code;
+ this.name = _findKey(namecodes, code);
+ this.message = this.name + ": FileException " + this.code;
+ }
+
+ Basic.extend(FileException, namecodes);
+ FileException.prototype = Error.prototype;
+ return FileException;
+ }()),
+
+ DOMException: (function() {
+ var namecodes = {
+ INDEX_SIZE_ERR: 1,
+ DOMSTRING_SIZE_ERR: 2,
+ HIERARCHY_REQUEST_ERR: 3,
+ WRONG_DOCUMENT_ERR: 4,
+ INVALID_CHARACTER_ERR: 5,
+ NO_DATA_ALLOWED_ERR: 6,
+ NO_MODIFICATION_ALLOWED_ERR: 7,
+ NOT_FOUND_ERR: 8,
+ NOT_SUPPORTED_ERR: 9,
+ INUSE_ATTRIBUTE_ERR: 10,
+ INVALID_STATE_ERR: 11,
+ SYNTAX_ERR: 12,
+ INVALID_MODIFICATION_ERR: 13,
+ NAMESPACE_ERR: 14,
+ INVALID_ACCESS_ERR: 15,
+ VALIDATION_ERR: 16,
+ TYPE_MISMATCH_ERR: 17,
+ SECURITY_ERR: 18,
+ NETWORK_ERR: 19,
+ ABORT_ERR: 20,
+ URL_MISMATCH_ERR: 21,
+ QUOTA_EXCEEDED_ERR: 22,
+ TIMEOUT_ERR: 23,
+ INVALID_NODE_TYPE_ERR: 24,
+ DATA_CLONE_ERR: 25
+ };
+
+ function DOMException(code) {
+ this.code = code;
+ this.name = _findKey(namecodes, code);
+ this.message = this.name + ": DOMException " + this.code;
+ }
+
+ Basic.extend(DOMException, namecodes);
+ DOMException.prototype = Error.prototype;
+ return DOMException;
+ }()),
+
+ EventException: (function() {
+ function EventException(code) {
+ this.code = code;
+ this.name = 'EventException';
+ }
+
+ Basic.extend(EventException, {
+ UNSPECIFIED_EVENT_TYPE_ERR: 0
+ });
+
+ EventException.prototype = Error.prototype;
+
+ return EventException;
+ }())
};
});
-// Included from: src/javascript/core/utils/Mime.js
-
-/**
- * Mime.js
- *
- * Copyright 2013, Moxiecode Systems AB
- * Released under GPL License.
- *
- * License: http://www.plupload.com/license
- * Contributing: http://www.plupload.com/contributing
- */
-
-define("moxie/core/utils/Mime", [
- "moxie/core/utils/Basic",
- "moxie/core/I18n"
-], function(Basic, I18n) {
-
- var mimeData = "" +
- "application/msword,doc dot," +
- "application/pdf,pdf," +
- "application/pgp-signature,pgp," +
- "application/postscript,ps ai eps," +
- "application/rtf,rtf," +
- "application/vnd.ms-excel,xls xlb," +
- "application/vnd.ms-powerpoint,ppt pps pot," +
- "application/zip,zip," +
- "application/x-shockwave-flash,swf swfl," +
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document,docx," +
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template,dotx," +
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,xlsx," +
- "application/vnd.openxmlformats-officedocument.presentationml.presentation,pptx," +
- "application/vnd.openxmlformats-officedocument.presentationml.template,potx," +
- "application/vnd.openxmlformats-officedocument.presentationml.slideshow,ppsx," +
- "application/x-javascript,js," +
- "application/json,json," +
- "audio/mpeg,mp3 mpga mpega mp2," +
- "audio/x-wav,wav," +
- "audio/x-m4a,m4a," +
- "audio/ogg,oga ogg," +
- "audio/aiff,aiff aif," +
- "audio/flac,flac," +
- "audio/aac,aac," +
- "audio/ac3,ac3," +
- "audio/x-ms-wma,wma," +
- "image/bmp,bmp," +
- "image/gif,gif," +
- "image/jpeg,jpg jpeg jpe," +
- "image/photoshop,psd," +
- "image/png,png," +
- "image/svg+xml,svg svgz," +
- "image/tiff,tiff tif," +
- "text/plain,asc txt text diff log," +
- "text/html,htm html xhtml," +
- "text/css,css," +
- "text/csv,csv," +
- "text/rtf,rtf," +
- "video/mpeg,mpeg mpg mpe m2v," +
- "video/quicktime,qt mov," +
- "video/mp4,mp4," +
- "video/x-m4v,m4v," +
- "video/x-flv,flv," +
- "video/x-ms-wmv,wmv," +
- "video/avi,avi," +
- "video/webm,webm," +
- "video/3gpp,3gpp 3gp," +
- "video/3gpp2,3g2," +
- "video/vnd.rn-realvideo,rv," +
- "video/ogg,ogv," +
- "video/x-matroska,mkv," +
- "application/vnd.oasis.opendocument.formula-template,otf," +
- "application/octet-stream,exe";
-
-
- var Mime = {
-
- mimes: {},
-
- extensions: {},
-
- // Parses the default mime types string into a mimes and extensions lookup maps
- addMimeType: function (mimeData) {
- var items = mimeData.split(/,/), i, ii, ext;
-
- for (i = 0; i < items.length; i += 2) {
- ext = items[i + 1].split(/ /);
-
- // extension to mime lookup
- for (ii = 0; ii < ext.length; ii++) {
- this.mimes[ext[ii]] = items[i];
- }
- // mime to extension lookup
- this.extensions[items[i]] = ext;
- }
- },
-
-
- extList2mimes: function (filters, addMissingExtensions) {
- var self = this, ext, i, ii, type, mimes = [];
-
- // convert extensions to mime types list
- for (i = 0; i < filters.length; i++) {
- ext = filters[i].extensions.split(/\s*,\s*/);
-
- for (ii = 0; ii < ext.length; ii++) {
-
- // if there's an asterisk in the list, then accept attribute is not required
- if (ext[ii] === '*') {
- return [];
- }
-
- type = self.mimes[ext[ii]];
- if (type && Basic.inArray(type, mimes) === -1) {
- mimes.push(type);
- }
-
- // future browsers should filter by extension, finally
- if (addMissingExtensions && /^\w+$/.test(ext[ii])) {
- mimes.push('.' + ext[ii]);
- } else if (!type) {
- // if we have no type in our map, then accept all
- return [];
- }
- }
- }
- return mimes;
- },
-
-
- mimes2exts: function(mimes) {
- var self = this, exts = [];
-
- Basic.each(mimes, function(mime) {
- if (mime === '*') {
- exts = [];
- return false;
- }
-
- // check if this thing looks like mime type
- var m = mime.match(/^(\w+)\/(\*|\w+)$/);
- if (m) {
- if (m[2] === '*') {
- // wildcard mime type detected
- Basic.each(self.extensions, function(arr, mime) {
- if ((new RegExp('^' + m[1] + '/')).test(mime)) {
- [].push.apply(exts, self.extensions[mime]);
- }
- });
- } else if (self.extensions[mime]) {
- [].push.apply(exts, self.extensions[mime]);
- }
- }
- });
- return exts;
- },
-
-
- mimes2extList: function(mimes) {
- var accept = [], exts = [];
-
- if (Basic.typeOf(mimes) === 'string') {
- mimes = Basic.trim(mimes).split(/\s*,\s*/);
- }
-
- exts = this.mimes2exts(mimes);
-
- accept.push({
- title: I18n.translate('Files'),
- extensions: exts.length ? exts.join(',') : '*'
- });
-
- // save original mimes string
- accept.mimes = mimes;
-
- return accept;
- },
-
-
- getFileExtension: function(fileName) {
- var matches = fileName && fileName.match(/\.([^.]+)$/);
- if (matches) {
- return matches[1].toLowerCase();
- }
- return '';
- },
-
- getFileMime: function(fileName) {
- return this.mimes[this.getFileExtension(fileName)] || '';
- }
- };
-
- Mime.addMimeType(mimeData);
-
- return Mime;
-});
-
// Included from: src/javascript/core/utils/Dom.js
/**
@@ -1470,13 +1757,18 @@ define("moxie/core/utils/Mime", [
* Contributing: http://www.plupload.com/contributing
*/
+/**
+@class moxie/core/utils/Dom
+@public
+@static
+*/
+
define('moxie/core/utils/Dom', ['moxie/core/utils/Env'], function(Env) {
/**
Get DOM Element by it's id.
@method get
- @for Utils
@param {String} id Identifier of the DOM Element
@return {DOMElement}
*/
@@ -1641,165 +1933,6 @@ define('moxie/core/utils/Dom', ['moxie/core/utils/Env'], function(Env) {
};
});
-// Included from: src/javascript/core/Exceptions.js
-
-/**
- * Exceptions.js
- *
- * Copyright 2013, Moxiecode Systems AB
- * Released under GPL License.
- *
- * License: http://www.plupload.com/license
- * Contributing: http://www.plupload.com/contributing
- */
-
-define('moxie/core/Exceptions', [
- 'moxie/core/utils/Basic'
-], function(Basic) {
- function _findKey(obj, value) {
- var key;
- for (key in obj) {
- if (obj[key] === value) {
- return key;
- }
- }
- return null;
- }
-
- return {
- RuntimeError: (function() {
- var namecodes = {
- NOT_INIT_ERR: 1,
- NOT_SUPPORTED_ERR: 9,
- JS_ERR: 4
- };
-
- function RuntimeError(code) {
- this.code = code;
- this.name = _findKey(namecodes, code);
- this.message = this.name + ": RuntimeError " + this.code;
- }
-
- Basic.extend(RuntimeError, namecodes);
- RuntimeError.prototype = Error.prototype;
- return RuntimeError;
- }()),
-
- OperationNotAllowedException: (function() {
-
- function OperationNotAllowedException(code) {
- this.code = code;
- this.name = 'OperationNotAllowedException';
- }
-
- Basic.extend(OperationNotAllowedException, {
- NOT_ALLOWED_ERR: 1
- });
-
- OperationNotAllowedException.prototype = Error.prototype;
-
- return OperationNotAllowedException;
- }()),
-
- ImageError: (function() {
- var namecodes = {
- WRONG_FORMAT: 1,
- MAX_RESOLUTION_ERR: 2,
- INVALID_META_ERR: 3
- };
-
- function ImageError(code) {
- this.code = code;
- this.name = _findKey(namecodes, code);
- this.message = this.name + ": ImageError " + this.code;
- }
-
- Basic.extend(ImageError, namecodes);
- ImageError.prototype = Error.prototype;
-
- return ImageError;
- }()),
-
- FileException: (function() {
- var namecodes = {
- NOT_FOUND_ERR: 1,
- SECURITY_ERR: 2,
- ABORT_ERR: 3,
- NOT_READABLE_ERR: 4,
- ENCODING_ERR: 5,
- NO_MODIFICATION_ALLOWED_ERR: 6,
- INVALID_STATE_ERR: 7,
- SYNTAX_ERR: 8
- };
-
- function FileException(code) {
- this.code = code;
- this.name = _findKey(namecodes, code);
- this.message = this.name + ": FileException " + this.code;
- }
-
- Basic.extend(FileException, namecodes);
- FileException.prototype = Error.prototype;
- return FileException;
- }()),
-
- DOMException: (function() {
- var namecodes = {
- INDEX_SIZE_ERR: 1,
- DOMSTRING_SIZE_ERR: 2,
- HIERARCHY_REQUEST_ERR: 3,
- WRONG_DOCUMENT_ERR: 4,
- INVALID_CHARACTER_ERR: 5,
- NO_DATA_ALLOWED_ERR: 6,
- NO_MODIFICATION_ALLOWED_ERR: 7,
- NOT_FOUND_ERR: 8,
- NOT_SUPPORTED_ERR: 9,
- INUSE_ATTRIBUTE_ERR: 10,
- INVALID_STATE_ERR: 11,
- SYNTAX_ERR: 12,
- INVALID_MODIFICATION_ERR: 13,
- NAMESPACE_ERR: 14,
- INVALID_ACCESS_ERR: 15,
- VALIDATION_ERR: 16,
- TYPE_MISMATCH_ERR: 17,
- SECURITY_ERR: 18,
- NETWORK_ERR: 19,
- ABORT_ERR: 20,
- URL_MISMATCH_ERR: 21,
- QUOTA_EXCEEDED_ERR: 22,
- TIMEOUT_ERR: 23,
- INVALID_NODE_TYPE_ERR: 24,
- DATA_CLONE_ERR: 25
- };
-
- function DOMException(code) {
- this.code = code;
- this.name = _findKey(namecodes, code);
- this.message = this.name + ": DOMException " + this.code;
- }
-
- Basic.extend(DOMException, namecodes);
- DOMException.prototype = Error.prototype;
- return DOMException;
- }()),
-
- EventException: (function() {
- function EventException(code) {
- this.code = code;
- this.name = 'EventException';
- }
-
- Basic.extend(EventException, {
- UNSPECIFIED_EVENT_TYPE_ERR: 0
- });
-
- EventException.prototype = Error.prototype;
-
- return EventException;
- }())
- };
-});
-
// Included from: src/javascript/core/EventTarget.js
/**
@@ -1817,289 +1950,326 @@ define('moxie/core/EventTarget', [
'moxie/core/Exceptions',
'moxie/core/utils/Basic'
], function(Env, x, Basic) {
+
+ // hash of event listeners by object uid
+ var eventpool = {};
+
/**
Parent object for all event dispatching components and objects
- @class EventTarget
+ @class moxie/core/EventTarget
@constructor EventTarget
*/
function EventTarget() {
- // hash of event listeners by object uid
- var eventpool = {};
-
- Basic.extend(this, {
-
- /**
- Unique id of the event dispatcher, usually overriden by children
+ /**
+ Unique id of the event dispatcher, usually overriden by children
- @property uid
- @type String
- */
- uid: null,
-
- /**
- Can be called from within a child in order to acquire uniqie id in automated manner
-
- @method init
- */
- init: function() {
- if (!this.uid) {
- this.uid = Basic.guid('uid_');
- }
- },
-
- /**
- Register a handler to a specific event dispatched by the object
-
- @method addEventListener
- @param {String} type Type or basically a name of the event to subscribe to
- @param {Function} fn Callback function that will be called when event happens
- @param {Number} [priority=0] Priority of the event handler - handlers with higher priorities will be called first
- @param {Object} [scope=this] A scope to invoke event handler in
- */
- addEventListener: function(type, fn, priority, scope) {
- var self = this, list;
-
- // without uid no event handlers can be added, so make sure we got one
- if (!this.hasOwnProperty('uid')) {
- this.uid = Basic.guid('uid_');
- }
-
- type = Basic.trim(type);
-
- if (/\s/.test(type)) {
- // multiple event types were passed for one handler
- Basic.each(type.split(/\s+/), function(type) {
- self.addEventListener(type, fn, priority, scope);
- });
- return;
- }
-
- type = type.toLowerCase();
- priority = parseInt(priority, 10) || 0;
-
- list = eventpool[this.uid] && eventpool[this.uid][type] || [];
- list.push({fn : fn, priority : priority, scope : scope || this});
-
- if (!eventpool[this.uid]) {
- eventpool[this.uid] = {};
- }
- eventpool[this.uid][type] = list;
- },
-
- /**
- Check if any handlers were registered to the specified event
-
- @method hasEventListener
- @param {String} type Type or basically a name of the event to check
- @return {Mixed} Returns a handler if it was found and false, if - not
- */
- hasEventListener: function(type) {
- var list = type ? eventpool[this.uid] && eventpool[this.uid][type] : eventpool[this.uid];
- return list ? list : false;
- },
-
- /**
- Unregister the handler from the event, or if former was not specified - unregister all handlers
-
- @method removeEventListener
- @param {String} type Type or basically a name of the event
- @param {Function} [fn] Handler to unregister
- */
- removeEventListener: function(type, fn) {
- type = type.toLowerCase();
-
- var list = eventpool[this.uid] && eventpool[this.uid][type], i;
-
- if (list) {
- if (fn) {
- for (i = list.length - 1; i >= 0; i--) {
- if (list[i].fn === fn) {
- list.splice(i, 1);
- break;
- }
- }
- } else {
- list = [];
- }
-
- // delete event list if it has become empty
- if (!list.length) {
- delete eventpool[this.uid][type];
-
- // and object specific entry in a hash if it has no more listeners attached
- if (Basic.isEmptyObj(eventpool[this.uid])) {
- delete eventpool[this.uid];
- }
- }
- }
- },
-
- /**
- Remove all event handlers from the object
-
- @method removeAllEventListeners
- */
- removeAllEventListeners: function() {
- if (eventpool[this.uid]) {
- delete eventpool[this.uid];
- }
- },
-
- /**
- Dispatch the event
-
- @method dispatchEvent
- @param {String/Object} Type of event or event object to dispatch
- @param {Mixed} [...] Variable number of arguments to be passed to a handlers
- @return {Boolean} true by default and false if any handler returned false
- */
- dispatchEvent: function(type) {
- var uid, list, args, tmpEvt, evt = {}, result = true, undef;
-
- if (Basic.typeOf(type) !== 'string') {
- // we can't use original object directly (because of Silverlight)
- tmpEvt = type;
-
- if (Basic.typeOf(tmpEvt.type) === 'string') {
- type = tmpEvt.type;
-
- if (tmpEvt.total !== undef && tmpEvt.loaded !== undef) { // progress event
- evt.total = tmpEvt.total;
- evt.loaded = tmpEvt.loaded;
- }
- evt.async = tmpEvt.async || false;
- } else {
- throw new x.EventException(x.EventException.UNSPECIFIED_EVENT_TYPE_ERR);
- }
- }
-
- // check if event is meant to be dispatched on an object having specific uid
- if (type.indexOf('::') !== -1) {
- (function(arr) {
- uid = arr[0];
- type = arr[1];
- }(type.split('::')));
- } else {
- uid = this.uid;
- }
-
- type = type.toLowerCase();
-
- list = eventpool[uid] && eventpool[uid][type];
-
- if (list) {
- // sort event list by prority
- list.sort(function(a, b) { return b.priority - a.priority; });
-
- args = [].slice.call(arguments);
-
- // first argument will be pseudo-event object
- args.shift();
- evt.type = type;
- args.unshift(evt);
-
- if (MXI_DEBUG && Env.debug.events) {
- Env.log("Event '%s' fired on %u", evt.type, uid);
- }
-
- // Dispatch event to all listeners
- var queue = [];
- Basic.each(list, function(handler) {
- // explicitly set the target, otherwise events fired from shims do not get it
- args[0].target = handler.scope;
- // if event is marked as async, detach the handler
- if (evt.async) {
- queue.push(function(cb) {
- setTimeout(function() {
- cb(handler.fn.apply(handler.scope, args) === false);
- }, 1);
- });
- } else {
- queue.push(function(cb) {
- cb(handler.fn.apply(handler.scope, args) === false); // if handler returns false stop propagation
- });
- }
- });
- if (queue.length) {
- Basic.inSeries(queue, function(err) {
- result = !err;
- });
- }
- }
- return result;
- },
-
- /**
- Alias for addEventListener
-
- @method bind
- @protected
- */
- bind: function() {
- this.addEventListener.apply(this, arguments);
- },
-
- /**
- Alias for removeEventListener
-
- @method unbind
- @protected
- */
- unbind: function() {
- this.removeEventListener.apply(this, arguments);
- },
-
- /**
- Alias for removeAllEventListeners
-
- @method unbindAll
- @protected
- */
- unbindAll: function() {
- this.removeAllEventListeners.apply(this, arguments);
- },
-
- /**
- Alias for dispatchEvent
-
- @method trigger
- @protected
- */
- trigger: function() {
- return this.dispatchEvent.apply(this, arguments);
- },
-
-
- /**
- Handle properties of on[event] type.
-
- @method handleEventProps
- @private
- */
- handleEventProps: function(dispatches) {
- var self = this;
-
- this.bind(dispatches.join(' '), function(e) {
- var prop = 'on' + e.type.toLowerCase();
- if (Basic.typeOf(this[prop]) === 'function') {
- this[prop].apply(this, arguments);
- }
- });
-
- // object must have defined event properties, even if it doesn't make use of them
- Basic.each(dispatches, function(prop) {
- prop = 'on' + prop.toLowerCase(prop);
- if (Basic.typeOf(self[prop]) === 'undefined') {
- self[prop] = null;
- }
- });
- }
-
- });
+ @property uid
+ @type String
+ */
+ this.uid = Basic.guid();
}
- EventTarget.instance = new EventTarget();
+
+ Basic.extend(EventTarget.prototype, {
+
+ /**
+ Can be called from within a child in order to acquire uniqie id in automated manner
+
+ @method init
+ */
+ init: function() {
+ if (!this.uid) {
+ this.uid = Basic.guid('uid_');
+ }
+ },
+
+ /**
+ Register a handler to a specific event dispatched by the object
+
+ @method addEventListener
+ @param {String} type Type or basically a name of the event to subscribe to
+ @param {Function} fn Callback function that will be called when event happens
+ @param {Number} [priority=0] Priority of the event handler - handlers with higher priorities will be called first
+ @param {Object} [scope=this] A scope to invoke event handler in
+ */
+ addEventListener: function(type, fn, priority, scope) {
+ var self = this, list;
+
+ // without uid no event handlers can be added, so make sure we got one
+ if (!this.hasOwnProperty('uid')) {
+ this.uid = Basic.guid('uid_');
+ }
+
+ type = Basic.trim(type);
+
+ if (/\s/.test(type)) {
+ // multiple event types were passed for one handler
+ Basic.each(type.split(/\s+/), function(type) {
+ self.addEventListener(type, fn, priority, scope);
+ });
+ return;
+ }
+
+ type = type.toLowerCase();
+ priority = parseInt(priority, 10) || 0;
+
+ list = eventpool[this.uid] && eventpool[this.uid][type] || [];
+ list.push({fn : fn, priority : priority, scope : scope || this});
+
+ if (!eventpool[this.uid]) {
+ eventpool[this.uid] = {};
+ }
+ eventpool[this.uid][type] = list;
+ },
+
+ /**
+ Check if any handlers were registered to the specified event
+
+ @method hasEventListener
+ @param {String} [type] Type or basically a name of the event to check
+ @return {Mixed} Returns a handler if it was found and false, if - not
+ */
+ hasEventListener: function(type) {
+ var list;
+ if (type) {
+ type = type.toLowerCase();
+ list = eventpool[this.uid] && eventpool[this.uid][type];
+ } else {
+ list = eventpool[this.uid];
+ }
+ return list ? list : false;
+ },
+
+ /**
+ Unregister the handler from the event, or if former was not specified - unregister all handlers
+
+ @method removeEventListener
+ @param {String} type Type or basically a name of the event
+ @param {Function} [fn] Handler to unregister
+ */
+ removeEventListener: function(type, fn) {
+ var self = this, list, i;
+
+ type = type.toLowerCase();
+
+ if (/\s/.test(type)) {
+ // multiple event types were passed for one handler
+ Basic.each(type.split(/\s+/), function(type) {
+ self.removeEventListener(type, fn);
+ });
+ return;
+ }
+
+ list = eventpool[this.uid] && eventpool[this.uid][type];
+
+ if (list) {
+ if (fn) {
+ for (i = list.length - 1; i >= 0; i--) {
+ if (list[i].fn === fn) {
+ list.splice(i, 1);
+ break;
+ }
+ }
+ } else {
+ list = [];
+ }
+
+ // delete event list if it has become empty
+ if (!list.length) {
+ delete eventpool[this.uid][type];
+
+ // and object specific entry in a hash if it has no more listeners attached
+ if (Basic.isEmptyObj(eventpool[this.uid])) {
+ delete eventpool[this.uid];
+ }
+ }
+ }
+ },
+
+ /**
+ Remove all event handlers from the object
+
+ @method removeAllEventListeners
+ */
+ removeAllEventListeners: function() {
+ if (eventpool[this.uid]) {
+ delete eventpool[this.uid];
+ }
+ },
+
+ /**
+ Dispatch the event
+
+ @method dispatchEvent
+ @param {String/Object} Type of event or event object to dispatch
+ @param {Mixed} [...] Variable number of arguments to be passed to a handlers
+ @return {Boolean} true by default and false if any handler returned false
+ */
+ dispatchEvent: function(type) {
+ var uid, list, args, tmpEvt, evt = {}, result = true, undef;
+
+ if (Basic.typeOf(type) !== 'string') {
+ // we can't use original object directly (because of Silverlight)
+ tmpEvt = type;
+
+ if (Basic.typeOf(tmpEvt.type) === 'string') {
+ type = tmpEvt.type;
+
+ if (tmpEvt.total !== undef && tmpEvt.loaded !== undef) { // progress event
+ evt.total = tmpEvt.total;
+ evt.loaded = tmpEvt.loaded;
+ }
+ evt.async = tmpEvt.async || false;
+ } else {
+ throw new x.EventException(x.EventException.UNSPECIFIED_EVENT_TYPE_ERR);
+ }
+ }
+
+ // check if event is meant to be dispatched on an object having specific uid
+ if (type.indexOf('::') !== -1) {
+ (function(arr) {
+ uid = arr[0];
+ type = arr[1];
+ }(type.split('::')));
+ } else {
+ uid = this.uid;
+ }
+
+ type = type.toLowerCase();
+
+ list = eventpool[uid] && eventpool[uid][type];
+
+ if (list) {
+ // sort event list by prority
+ list.sort(function(a, b) { return b.priority - a.priority; });
+
+ args = [].slice.call(arguments);
+
+ // first argument will be pseudo-event object
+ args.shift();
+ evt.type = type;
+ args.unshift(evt);
+
+ if (MXI_DEBUG && Env.debug.events) {
+ Env.log("%cEvent '%s' fired on %s", 'color: #999;', evt.type, (this.ctorName ? this.ctorName + '::' : '') + uid);
+ }
+
+ // Dispatch event to all listeners
+ var queue = [];
+ Basic.each(list, function(handler) {
+ // explicitly set the target, otherwise events fired from shims do not get it
+ args[0].target = handler.scope;
+ // if event is marked as async, detach the handler
+ if (evt.async) {
+ queue.push(function(cb) {
+ setTimeout(function() {
+ cb(handler.fn.apply(handler.scope, args) === false);
+ }, 1);
+ });
+ } else {
+ queue.push(function(cb) {
+ cb(handler.fn.apply(handler.scope, args) === false); // if handler returns false stop propagation
+ });
+ }
+ });
+ if (queue.length) {
+ Basic.inSeries(queue, function(err) {
+ result = !err;
+ });
+ }
+ }
+ return result;
+ },
+
+ /**
+ Register a handler to the event type that will run only once
+
+ @method bindOnce
+ @since >1.4.1
+ @param {String} type Type or basically a name of the event to subscribe to
+ @param {Function} fn Callback function that will be called when event happens
+ @param {Number} [priority=0] Priority of the event handler - handlers with higher priorities will be called first
+ @param {Object} [scope=this] A scope to invoke event handler in
+ */
+ bindOnce: function(type, fn, priority, scope) {
+ var self = this;
+ self.bind.call(this, type, function cb() {
+ self.unbind(type, cb);
+ return fn.apply(this, arguments);
+ }, priority, scope);
+ },
+
+ /**
+ Alias for addEventListener
+
+ @method bind
+ @protected
+ */
+ bind: function() {
+ this.addEventListener.apply(this, arguments);
+ },
+
+ /**
+ Alias for removeEventListener
+
+ @method unbind
+ @protected
+ */
+ unbind: function() {
+ this.removeEventListener.apply(this, arguments);
+ },
+
+ /**
+ Alias for removeAllEventListeners
+
+ @method unbindAll
+ @protected
+ */
+ unbindAll: function() {
+ this.removeAllEventListeners.apply(this, arguments);
+ },
+
+ /**
+ Alias for dispatchEvent
+
+ @method trigger
+ @protected
+ */
+ trigger: function() {
+ return this.dispatchEvent.apply(this, arguments);
+ },
+
+
+ /**
+ Handle properties of on[event] type.
+
+ @method handleEventProps
+ @private
+ */
+ handleEventProps: function(dispatches) {
+ var self = this;
+
+ this.bind(dispatches.join(' '), function(e) {
+ var prop = 'on' + e.type.toLowerCase();
+ if (Basic.typeOf(this[prop]) === 'function') {
+ this[prop].apply(this, arguments);
+ }
+ });
+
+ // object must have defined event properties, even if it doesn't make use of them
+ Basic.each(dispatches, function(prop) {
+ prop = 'on' + prop.toLowerCase(prop);
+ if (Basic.typeOf(self[prop]) === 'undefined') {
+ self[prop] = null;
+ }
+ });
+ }
+
+ });
+
+
+ EventTarget.instance = new EventTarget();
return EventTarget;
});
@@ -2127,7 +2297,7 @@ define('moxie/runtime/Runtime', [
/**
Common set of methods and properties for every runtime instance
- @class Runtime
+ @class moxie/runtime/Runtime
@param {Object} options
@param {String} type Sanitized name of the runtime
@@ -2371,7 +2541,7 @@ define('moxie/runtime/Runtime', [
// if no container for shim, create one
if (!shimContainer) {
- container = this.options.container ? Dom.get(this.options.container) : document.body;
+ container = Dom.get(this.options.container) || document.body;
// create shim container and insert it at an absolute position into the outer container
shimContainer = document.createElement('div');
@@ -2475,7 +2645,7 @@ define('moxie/runtime/Runtime', [
@type String
@static
*/
- Runtime.order = 'html5,html4';
+ Runtime.order = 'html5,flash,silverlight,html4';
/**
@@ -2646,7 +2816,7 @@ define('moxie/runtime/Runtime', [
// if cap requires conflicting mode - runtime cannot fulfill required caps
if (MXI_DEBUG && Env.debug.runtime) {
- Env.log("\t\t%c: %v (conflicting mode requested: %s)", cap, value, capMode);
+ Env.log("\t\t%s: %s (conflicting mode requested: %s)", cap, value, capMode);
}
return (mode = false);
@@ -2654,7 +2824,7 @@ define('moxie/runtime/Runtime', [
}
if (MXI_DEBUG && Env.debug.runtime) {
- Env.log("\t\t%c: %v (compatible modes: %s)", cap, value, mode);
+ Env.log("\t\t%s: %s (compatible modes: %s)", cap, value, mode);
}
});
@@ -2668,6 +2838,30 @@ define('moxie/runtime/Runtime', [
};
+ /**
+ * Third party shims (Flash and Silverlight) require global event target against which they
+ * will fire their events. However when moxie is not loaded to global namespace, default
+ * event target is not accessible and we have to create artificial ones.
+ *
+ * @method getGlobalEventTarget
+ * @static
+ * @return {String} Name of the global event target
+ */
+ Runtime.getGlobalEventTarget = function() {
+ if (/^moxie\./.test(Env.global_event_dispatcher) && !Env.can('access_global_ns')) {
+ var uniqueCallbackName = Basic.guid('moxie_event_target_');
+
+ window[uniqueCallbackName] = function(e, data) {
+ EventTarget.instance.dispatchEvent(e, data);
+ };
+
+ Env.global_event_dispatcher = uniqueCallbackName;
+ }
+
+ return Env.global_event_dispatcher;
+ };
+
+
/**
Capability check that always returns true
@@ -2728,7 +2922,7 @@ define('moxie/runtime/RuntimeClient', [
/**
Set of methods and properties, required by a component to acquire ability to connect to a runtime
- @class RuntimeClient
+ @class moxie/runtime/RuntimeClient
*/
return function RuntimeClient() {
var runtime;
@@ -2758,6 +2952,9 @@ define('moxie/runtime/RuntimeClient', [
type = items.shift().toLowerCase();
constructor = Runtime.getConstructor(type);
if (!constructor) {
+ if (MXI_DEBUG && Env.debug.runtime) {
+ Env.log("Constructor for '%s' runtime is not available.", type);
+ }
initialize(items);
return;
}
@@ -2781,6 +2978,7 @@ define('moxie/runtime/RuntimeClient', [
// jailbreak ...
setTimeout(function() {
runtime.clients++;
+ comp.ruid = runtime.uid;
// this will be triggered on component
comp.trigger('RuntimeInit', runtime);
}, 1);
@@ -2795,7 +2993,14 @@ define('moxie/runtime/RuntimeClient', [
initialize(items);
});
- /*runtime.bind('Exception', function() { });*/
+ runtime.bind('Exception', function(e, err) {
+ var message = err.name + "(#" + err.code + ")" + (err.message ? ", from: " + err.message : '');
+
+ if (MXI_DEBUG && Env.debug.runtime) {
+ Env.log("Runtime '%s' has thrown an exception: %s", this.type, message);
+ }
+ comp.trigger('RuntimeError', new x.RuntimeError(x.RuntimeError.EXCEPTION_ERR, message));
+ });
if (MXI_DEBUG && Env.debug.runtime) {
Env.log("\tselected mode: %s", runtime.mode);
@@ -2820,6 +3025,7 @@ define('moxie/runtime/RuntimeClient', [
if (ruid) {
runtime = Runtime.getRuntime(ruid);
if (runtime) {
+ comp.ruid = ruid;
runtime.clients++;
return runtime;
} else {
@@ -2871,10 +3077,19 @@ define('moxie/runtime/RuntimeClient', [
@return {Mixed} Whatever runtime extension method returns
*/
exec: function() {
- if (runtime) {
- return runtime.exec.apply(this, arguments);
- }
- return null;
+ return runtime ? runtime.exec.apply(this, arguments) : null;
+ },
+
+
+ /**
+ Test runtime client for specific capability
+
+ @method can
+ @param {String} cap
+ @return {Bool}
+ */
+ can: function(cap) {
+ return runtime ? runtime.can(cap) : false;
}
});
@@ -2883,515 +3098,6 @@ define('moxie/runtime/RuntimeClient', [
});
-// Included from: src/javascript/file/FileInput.js
-
-/**
- * FileInput.js
- *
- * Copyright 2013, Moxiecode Systems AB
- * Released under GPL License.
- *
- * License: http://www.plupload.com/license
- * Contributing: http://www.plupload.com/contributing
- */
-
-define('moxie/file/FileInput', [
- 'moxie/core/utils/Basic',
- 'moxie/core/utils/Env',
- 'moxie/core/utils/Mime',
- 'moxie/core/utils/Dom',
- 'moxie/core/Exceptions',
- 'moxie/core/EventTarget',
- 'moxie/core/I18n',
- 'moxie/runtime/Runtime',
- 'moxie/runtime/RuntimeClient'
-], function(Basic, Env, Mime, Dom, x, EventTarget, I18n, Runtime, RuntimeClient) {
- /**
- Provides a convenient way to create cross-browser file-picker. Generates file selection dialog on click,
- converts selected files to _File_ objects, to be used in conjunction with _Image_, preloaded in memory
- with _FileReader_ or uploaded to a server through _XMLHttpRequest_.
-
- @class FileInput
- @constructor
- @extends EventTarget
- @uses RuntimeClient
- @param {Object|String|DOMElement} options If options is string or node, argument is considered as _browse\_button_.
- @param {String|DOMElement} options.browse_button DOM Element to turn into file picker.
- @param {Array} [options.accept] Array of mime types to accept. By default accepts all.
- @param {String} [options.file='file'] Name of the file field (not the filename).
- @param {Boolean} [options.multiple=false] Enable selection of multiple files.
- @param {Boolean} [options.directory=false] Turn file input into the folder input (cannot be both at the same time).
- @param {String|DOMElement} [options.container] DOM Element to use as a container for file-picker. Defaults to parentNode
- for _browse\_button_.
- @param {Object|String} [options.required_caps] Set of required capabilities, that chosen runtime must support.
-
- @example
-