Skip to content
This repository
Browse code

JavaScript: Update binaries.

  • Loading branch information...
commit 8b6f4dbbd5163ad6b52617efec9539bce42886f9 1 parent 4d85daf
Davit Barbakadze authored March 31, 2013
4  bin/js/moxie.dev.js
@@ -125,6 +125,7 @@
125 125
 	load('../../src/javascript/core/utils/Dom.js');
126 126
 	load('../../src/javascript/core/Exceptions.js');
127 127
 	load('../../src/javascript/core/EventTarget.js');
  128
+	load('../../src/javascript/core/utils/Encode.js');
128 129
 	load('../../src/javascript/runtime/Runtime.js');
129 130
 	load('../../src/javascript/runtime/RuntimeClient.js');
130 131
 	load('../../src/javascript/file/Blob.js');
@@ -132,7 +133,6 @@
132 133
 	load('../../src/javascript/file/FileInput.js');
133 134
 	load('../../src/javascript/file/FileDrop.js');
134 135
 	load('../../src/javascript/file/FileReader.js');
135  
-	load('../../src/javascript/core/utils/Encode.js');
136 136
 	load('../../src/javascript/core/utils/Url.js');
137 137
 	load('../../src/javascript/runtime/RuntimeTarget.js');
138 138
 	load('../../src/javascript/xhr/FormData.js');
@@ -179,7 +179,7 @@
179 179
 	load('../../src/javascript/runtime/html4/xhr/XMLHttpRequest.js');
180 180
 	load('../../src/javascript/runtime/html4/image/Image.js');
181 181
 
182  
-	expose(["moxie/core/utils/Basic","moxie/core/I18n","moxie/core/utils/Mime","moxie/core/utils/Env","moxie/core/utils/Dom","moxie/core/Exceptions","moxie/core/EventTarget","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/file/File","moxie/file/FileInput","moxie/file/FileDrop","moxie/file/FileReader","moxie/core/utils/Encode","moxie/core/utils/Url","moxie/runtime/RuntimeTarget","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/file/FileReaderSync","moxie/runtime/Transporter","moxie/core/JSON","moxie/image/Image","moxie/core/utils/Events"]);
  182
+	expose(["moxie/core/utils/Basic","moxie/core/I18n","moxie/core/utils/Mime","moxie/core/utils/Env","moxie/core/utils/Dom","moxie/core/Exceptions","moxie/core/EventTarget","moxie/core/utils/Encode","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/file/File","moxie/file/FileInput","moxie/file/FileDrop","moxie/file/FileReader","moxie/core/utils/Url","moxie/runtime/RuntimeTarget","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/file/FileReaderSync","moxie/runtime/Transporter","moxie/core/JSON","moxie/image/Image","moxie/core/utils/Events"]);
183 183
 
184 184
 
185 185
 	writeScripts();
570  bin/js/moxie.js
@@ -1268,7 +1268,6 @@ define('moxie/core/EventTarget', [
1268 1268
 					Basic.each(type.split(/\s+/), function(type) {
1269 1269
 						self.addEventListener(type, fn, priority, scope);
1270 1270
 					});
1271  
-
1272 1271
 					return;
1273 1272
 				}
1274 1273
 				
@@ -1493,6 +1492,184 @@ define('moxie/core/EventTarget', [
1493 1492
 	return EventTarget;
1494 1493
 });
1495 1494
 
  1495
+// Included from: /Users/jagga/Sites/mxi/plupload/www/plupload/src/moxie/src/javascript/core/utils/Encode.js
  1496
+
  1497
+/**
  1498
+ * Encode.js
  1499
+ *
  1500
+ * Copyright 2013, Moxiecode Systems AB
  1501
+ * Released under GPL License.
  1502
+ *
  1503
+ * License: http://www.plupload.com/license
  1504
+ * Contributing: http://www.plupload.com/contributing
  1505
+ */
  1506
+
  1507
+/*jshint smarttabs:true, undef:true, unused:true, latedef:true, curly:true, bitwise:false, scripturl:true, browser:true */
  1508
+/*global define:true, escape: true, unescape: true */
  1509
+
  1510
+define('moxie/core/utils/Encode', [], function() {
  1511
+
  1512
+	/**
  1513
+	Encode string with UTF-8
  1514
+
  1515
+	@method utf8_encode
  1516
+	@static
  1517
+	@param {String} str String to encode
  1518
+	@return {String} UTF-8 encoded string
  1519
+	*/
  1520
+	var utf8_encode = function(str) {
  1521
+		return unescape(encodeURIComponent(str));
  1522
+	};
  1523
+	
  1524
+	/**
  1525
+	Decode UTF-8 encoded string
  1526
+
  1527
+	@method utf8_decode
  1528
+	@static
  1529
+	@param {String} str String to decode
  1530
+	@return {String} Decoded string
  1531
+	*/
  1532
+	var utf8_decode = function(str_data) {
  1533
+		return decodeURIComponent(escape(str_data));
  1534
+	};
  1535
+	
  1536
+	/**
  1537
+	Decode Base64 encoded string (uses browser's default method if available),
  1538
+	from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_decode.js
  1539
+
  1540
+	@method atob
  1541
+	@static
  1542
+	@param {String} data String to decode
  1543
+	@return {String} Decoded string
  1544
+	*/
  1545
+	var atob = function(data) {
  1546
+		if (typeof(window.atob) === 'function') {
  1547
+			return window.atob(data);
  1548
+		}
  1549
+
  1550
+		// http://kevin.vanzonneveld.net
  1551
+	    // +   original by: Tyler Akins (http://rumkin.com)
  1552
+	    // +   improved by: Thunder.m
  1553
+	    // +      input by: Aman Gupta
  1554
+	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1555
+	    // +   bugfixed by: Onno Marsman
  1556
+	    // +   bugfixed by: Pellentesque Malesuada
  1557
+	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1558
+	    // +      input by: Brett Zamir (http://brett-zamir.me)
  1559
+	    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1560
+	    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
  1561
+	    // *     returns 1: 'Kevin van Zonneveld'
  1562
+	    // mozilla has this native
  1563
+	    // - but breaks in 2.0.0.12!
  1564
+	    //if (typeof this.window.atob == 'function') {
  1565
+	    //    return atob(data);
  1566
+	    //}
  1567
+	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1568
+	    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
  1569
+	        ac = 0,
  1570
+	        dec = "",
  1571
+	        tmp_arr = [];
  1572
+
  1573
+	    if (!data) {
  1574
+	        return data;
  1575
+	    }
  1576
+
  1577
+	    data += '';
  1578
+
  1579
+	    do { // unpack four hexets into three octets using index points in b64
  1580
+	        h1 = b64.indexOf(data.charAt(i++));
  1581
+	        h2 = b64.indexOf(data.charAt(i++));
  1582
+	        h3 = b64.indexOf(data.charAt(i++));
  1583
+	        h4 = b64.indexOf(data.charAt(i++));
  1584
+
  1585
+	        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
  1586
+
  1587
+	        o1 = bits >> 16 & 0xff;
  1588
+	        o2 = bits >> 8 & 0xff;
  1589
+	        o3 = bits & 0xff;
  1590
+
  1591
+	        if (h3 == 64) {
  1592
+	            tmp_arr[ac++] = String.fromCharCode(o1);
  1593
+	        } else if (h4 == 64) {
  1594
+	            tmp_arr[ac++] = String.fromCharCode(o1, o2);
  1595
+	        } else {
  1596
+	            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
  1597
+	        }
  1598
+	    } while (i < data.length);
  1599
+
  1600
+	    dec = tmp_arr.join('');
  1601
+
  1602
+	    return dec;
  1603
+	};
  1604
+	
  1605
+	/**
  1606
+	Base64 encode string (uses browser's default method if available),
  1607
+	from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_encode.js
  1608
+
  1609
+	@method btoa
  1610
+	@static
  1611
+	@param {String} data String to encode
  1612
+	@return {String} Base64 encoded string
  1613
+	*/
  1614
+	var btoa = function(data) {
  1615
+		if (typeof(window.btoa) === 'function') {
  1616
+			return window.btoa(data);
  1617
+		}
  1618
+		
  1619
+		// http://kevin.vanzonneveld.net
  1620
+	    // +   original by: Tyler Akins (http://rumkin.com)
  1621
+	    // +   improved by: Bayron Guevara
  1622
+	    // +   improved by: Thunder.m
  1623
+	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1624
+	    // +   bugfixed by: Pellentesque Malesuada
  1625
+	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1626
+	    // +   improved by: Rafał Kukawski (http://kukawski.pl)
  1627
+	    // *     example 1: base64_encode('Kevin van Zonneveld');
  1628
+	    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
  1629
+	    // mozilla has this native
  1630
+	    // - but breaks in 2.0.0.12!
  1631
+	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1632
+	    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
  1633
+	        ac = 0,
  1634
+	        enc = "",
  1635
+	        tmp_arr = [];
  1636
+
  1637
+	    if (!data) {
  1638
+	        return data;
  1639
+	    }
  1640
+
  1641
+	    do { // pack three octets into four hexets
  1642
+	        o1 = data.charCodeAt(i++);
  1643
+	        o2 = data.charCodeAt(i++);
  1644
+	        o3 = data.charCodeAt(i++);
  1645
+
  1646
+	        bits = o1 << 16 | o2 << 8 | o3;
  1647
+
  1648
+	        h1 = bits >> 18 & 0x3f;
  1649
+	        h2 = bits >> 12 & 0x3f;
  1650
+	        h3 = bits >> 6 & 0x3f;
  1651
+	        h4 = bits & 0x3f;
  1652
+
  1653
+	        // use hexets to index into b64, and append result to encoded string
  1654
+	        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
  1655
+	    } while (i < data.length);
  1656
+
  1657
+	    enc = tmp_arr.join('');
  1658
+	    
  1659
+	    var r = data.length % 3;
  1660
+	    
  1661
+	    return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
  1662
+	};
  1663
+
  1664
+
  1665
+	return {
  1666
+		utf8_encode: utf8_encode,
  1667
+		utf8_decode: utf8_decode,
  1668
+		atob: atob,
  1669
+		btoa: btoa
  1670
+	};
  1671
+});
  1672
+
1496 1673
 // Included from: /Users/jagga/Sites/mxi/plupload/www/plupload/src/moxie/src/javascript/runtime/Runtime.js
1497 1674
 
1498 1675
 /**
@@ -1908,7 +2085,6 @@ define('moxie/runtime/RuntimeClient', [
1908 2085
 
1909 2086
 					runtime.bind('Error', function(e, err) {
1910 2087
 						runtime.destroy(); // runtime cannot destroy itself from inside at a right moment, thus we do it here
1911  
-						comp.trigger('RuntimeError', type, err);
1912 2088
 						initialize(items);
1913 2089
 					});
1914 2090
 
@@ -1984,8 +2160,9 @@ define('moxie/runtime/RuntimeClient', [
1984 2160
 
1985 2161
 define('moxie/file/Blob', [
1986 2162
 	'moxie/core/utils/Basic',
  2163
+	'moxie/core/utils/Encode',
1987 2164
 	'moxie/runtime/RuntimeClient'
1988  
-], function(Basic, RuntimeClient) {
  2165
+], function(Basic, Encode, RuntimeClient) {
1989 2166
 	
1990 2167
 	var blobpool = {};
1991 2168
 
@@ -2101,6 +2278,14 @@ define('moxie/file/Blob', [
2101 2278
 				}
2102 2279
 
2103 2280
 				data = data || '';
  2281
+
  2282
+				// if dataUrl, convert to binary string
  2283
+				var matches = data.match(/^data:([^;]*);base64,/);
  2284
+				if (matches) {
  2285
+					this.type = matches[1];
  2286
+					data = Encode.atob(data.substring(data.indexOf('base64,') + 7));
  2287
+				}
  2288
+
2104 2289
 				this.size = data.length;
2105 2290
 
2106 2291
 				blobpool[this.uid] = data;
@@ -2858,184 +3043,6 @@ define('moxie/file/FileReader', [
2858 3043
 	return FileReader;
2859 3044
 });
2860 3045
 
2861  
-// Included from: /Users/jagga/Sites/mxi/plupload/www/plupload/src/moxie/src/javascript/core/utils/Encode.js
2862  
-
2863  
-/**
2864  
- * Encode.js
2865  
- *
2866  
- * Copyright 2013, Moxiecode Systems AB
2867  
- * Released under GPL License.
2868  
- *
2869  
- * License: http://www.plupload.com/license
2870  
- * Contributing: http://www.plupload.com/contributing
2871  
- */
2872  
-
2873  
-/*jshint smarttabs:true, undef:true, unused:true, latedef:true, curly:true, bitwise:false, scripturl:true, browser:true */
2874  
-/*global define:true, escape: true, unescape: true */
2875  
-
2876  
-define('moxie/core/utils/Encode', [], function() {
2877  
-
2878  
-	/**
2879  
-	Encode string with UTF-8
2880  
-
2881  
-	@method utf8_encode
2882  
-	@static
2883  
-	@param {String} str String to encode
2884  
-	@return {String} UTF-8 encoded string
2885  
-	*/
2886  
-	var utf8_encode = function(str) {
2887  
-		return unescape(encodeURIComponent(str));
2888  
-	};
2889  
-	
2890  
-	/**
2891  
-	Decode UTF-8 encoded string
2892  
-
2893  
-	@method utf8_decode
2894  
-	@static
2895  
-	@param {String} str String to decode
2896  
-	@return {String} Decoded string
2897  
-	*/
2898  
-	var utf8_decode = function(str_data) {
2899  
-		return decodeURIComponent(escape(str_data));
2900  
-	};
2901  
-	
2902  
-	/**
2903  
-	Decode Base64 encoded string (uses browser's default method if available),
2904  
-	from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_decode.js
2905  
-
2906  
-	@method atob
2907  
-	@static
2908  
-	@param {String} data String to decode
2909  
-	@return {String} Decoded string
2910  
-	*/
2911  
-	var atob = function(data) {
2912  
-		if (typeof(window.atob) === 'function') {
2913  
-			return window.atob(data);
2914  
-		}
2915  
-
2916  
-		// http://kevin.vanzonneveld.net
2917  
-	    // +   original by: Tyler Akins (http://rumkin.com)
2918  
-	    // +   improved by: Thunder.m
2919  
-	    // +      input by: Aman Gupta
2920  
-	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2921  
-	    // +   bugfixed by: Onno Marsman
2922  
-	    // +   bugfixed by: Pellentesque Malesuada
2923  
-	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2924  
-	    // +      input by: Brett Zamir (http://brett-zamir.me)
2925  
-	    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2926  
-	    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
2927  
-	    // *     returns 1: 'Kevin van Zonneveld'
2928  
-	    // mozilla has this native
2929  
-	    // - but breaks in 2.0.0.12!
2930  
-	    //if (typeof this.window.atob == 'function') {
2931  
-	    //    return atob(data);
2932  
-	    //}
2933  
-	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
2934  
-	    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
2935  
-	        ac = 0,
2936  
-	        dec = "",
2937  
-	        tmp_arr = [];
2938  
-
2939  
-	    if (!data) {
2940  
-	        return data;
2941  
-	    }
2942  
-
2943  
-	    data += '';
2944  
-
2945  
-	    do { // unpack four hexets into three octets using index points in b64
2946  
-	        h1 = b64.indexOf(data.charAt(i++));
2947  
-	        h2 = b64.indexOf(data.charAt(i++));
2948  
-	        h3 = b64.indexOf(data.charAt(i++));
2949  
-	        h4 = b64.indexOf(data.charAt(i++));
2950  
-
2951  
-	        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
2952  
-
2953  
-	        o1 = bits >> 16 & 0xff;
2954  
-	        o2 = bits >> 8 & 0xff;
2955  
-	        o3 = bits & 0xff;
2956  
-
2957  
-	        if (h3 == 64) {
2958  
-	            tmp_arr[ac++] = String.fromCharCode(o1);
2959  
-	        } else if (h4 == 64) {
2960  
-	            tmp_arr[ac++] = String.fromCharCode(o1, o2);
2961  
-	        } else {
2962  
-	            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
2963  
-	        }
2964  
-	    } while (i < data.length);
2965  
-
2966  
-	    dec = tmp_arr.join('');
2967  
-
2968  
-	    return dec;
2969  
-	};
2970  
-	
2971  
-	/**
2972  
-	Base64 encode string (uses browser's default method if available),
2973  
-	from: https://raw.github.com/kvz/phpjs/master/functions/url/base64_encode.js
2974  
-
2975  
-	@method btoa
2976  
-	@static
2977  
-	@param {String} data String to encode
2978  
-	@return {String} Base64 encoded string
2979  
-	*/
2980  
-	var btoa = function(data) {
2981  
-		if (typeof(window.btoa) === 'function') {
2982  
-			return window.btoa(data);
2983  
-		}
2984  
-		
2985  
-		// http://kevin.vanzonneveld.net
2986  
-	    // +   original by: Tyler Akins (http://rumkin.com)
2987  
-	    // +   improved by: Bayron Guevara
2988  
-	    // +   improved by: Thunder.m
2989  
-	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2990  
-	    // +   bugfixed by: Pellentesque Malesuada
2991  
-	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2992  
-	    // +   improved by: Rafał Kukawski (http://kukawski.pl)
2993  
-	    // *     example 1: base64_encode('Kevin van Zonneveld');
2994  
-	    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
2995  
-	    // mozilla has this native
2996  
-	    // - but breaks in 2.0.0.12!
2997  
-	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
2998  
-	    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
2999  
-	        ac = 0,
3000  
-	        enc = "",
3001  
-	        tmp_arr = [];
3002  
-
3003  
-	    if (!data) {
3004  
-	        return data;
3005  
-	    }
3006  
-
3007  
-	    do { // pack three octets into four hexets
3008  
-	        o1 = data.charCodeAt(i++);
3009  
-	        o2 = data.charCodeAt(i++);
3010  
-	        o3 = data.charCodeAt(i++);
3011  
-
3012  
-	        bits = o1 << 16 | o2 << 8 | o3;
3013  
-
3014  
-	        h1 = bits >> 18 & 0x3f;
3015  
-	        h2 = bits >> 12 & 0x3f;
3016  
-	        h3 = bits >> 6 & 0x3f;
3017  
-	        h4 = bits & 0x3f;
3018  
-
3019  
-	        // use hexets to index into b64, and append result to encoded string
3020  
-	        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
3021  
-	    } while (i < data.length);
3022  
-
3023  
-	    enc = tmp_arr.join('');
3024  
-	    
3025  
-	    var r = data.length % 3;
3026  
-	    
3027  
-	    return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
3028  
-	};
3029  
-
3030  
-
3031  
-	return {
3032  
-		utf8_encode: utf8_encode,
3033  
-		utf8_decode: utf8_decode,
3034  
-		atob: atob,
3035  
-		btoa: btoa
3036  
-	};
3037  
-});
3038  
-
3039 3046
 // Included from: /Users/jagga/Sites/mxi/plupload/www/plupload/src/moxie/src/javascript/core/utils/Url.js
3040 3047
 
3041 3048
 /**
@@ -3565,7 +3572,7 @@ define("moxie/xhr/XMLHttpRequest", [
3565 3572
 			@property uid
3566 3573
 			@type String
3567 3574
 			*/
3568  
-			uid: 'uid_' + Basic.guid(),
  3575
+			uid: Basic.guid('uid_'),
3569 3576
 			
3570 3577
 			/**
3571 3578
 			Target for Upload events
@@ -4465,7 +4472,7 @@ define("moxie/runtime/Transporter", [
4465 4472
 		RuntimeClient.call(this);
4466 4473
 
4467 4474
 		Basic.extend(this, {
4468  
-			uid: 'uid_' + Basic.guid(),
  4475
+			uid: Basic.guid('uid_'),
4469 4476
 
4470 4477
 			state: Transporter.IDLE,
4471 4478
 
@@ -4928,10 +4935,10 @@ define("moxie/image/Image", [
4928 4935
 		"moxie/core/utils/Env",
4929 4936
 		"moxie/core/EventTarget",
4930 4937
 		"moxie/file/Blob",
4931  
-		"moxie/core/utils/Url",
  4938
+		"moxie/file/File",
4932 4939
 		"moxie/core/utils/Encode",
4933 4940
 		"moxie/core/JSON"
4934  
-], function(Basic, Dom, x, FileReaderSync, XMLHttpRequest, RuntimeClient, Transporter, Env, EventTarget, Blob, Url, Encode, parseJSON) {
  4941
+], function(Basic, Dom, x, FileReaderSync, XMLHttpRequest, RuntimeClient, Transporter, Env, EventTarget, Blob, File, Encode, parseJSON) {
4935 4942
 	/**
4936 4943
 	Image preloading and manipulation utility. Additionally it provides access to image meta info (Exif, GPS) and raw binary data.
4937 4944
 
@@ -4971,7 +4978,6 @@ define("moxie/image/Image", [
4971 4978
 	];
4972 4979
 	
4973 4980
 	function Image() {
4974  
-		var self = this;
4975 4981
 			
4976 4982
 		RuntimeClient.call(this);
4977 4983
 		
@@ -5058,17 +5064,9 @@ define("moxie/image/Image", [
5058 5064
 			},
5059 5065
 
5060 5066
 			/**
5061  
-			Loads image from various sources. Currently the source for new image can be: mOxie.Image, mOxie.Blob/mOxie.File or URL.
5062  
-			Depending on the type of the source, arguments - differ.
5063  
-
5064  
-			When source is:
5065  
-			  - mOxie.Image: Loads image from another existing mOxie.Image object (clones it). Might be fast by default (surface clone),
5066  
-				or a bit slower, if launched in exact mode (in-depth clone). Only exact mode (enabled by passing second argument
5067  
-				as - true) will copy over meta info, like Exif, GPS, IPTC data, etc.
5068  
-			  - mOxie.Blob/mOxie.File: Loads image from mOxie.File or mOxie.Blob object.
5069  
-			  - URL: Image will be downloaded from remote destination and loaded in memory.
5070  
-
5071  
-			When source is URL, Image will be downloaded from remote destination and loaded in memory.
  5067
+			Loads image from various sources. Currently the source for new image can be: mOxie.Image, mOxie.Blob/mOxie.File, 
  5068
+			native Blob/File, dataUrl or URL. Depending on the type of the source, arguments - differ. When source is URL, 
  5069
+			Image will be downloaded from remote destination and loaded in memory.
5072 5070
 
5073 5071
 			@example
5074 5072
 				var img = new mOxie.Image();
@@ -5093,45 +5091,14 @@ define("moxie/image/Image", [
5093 5091
 			@param {Boolean|Object} [mixed]
5094 5092
 			*/
5095 5093
 			load: function(src) {
5096  
-				var el, args = [].slice.call(arguments);
5097  
-
5098  
-				this.bind('Load', function(e) {
  5094
+				// this is here because to bind properly we need an uid first, which is created above
  5095
+				this.bind('Load Resize', function(e) {
5099 5096
 					_updateInfo.call(this);
5100 5097
 				}, 999);
5101 5098
 
5102 5099
 				this.convertEventPropsToHandlers(dispatches);
5103 5100
 
5104  
-				try {
5105  
-					// if source is Image
5106  
-					if (src instanceof Image) {
5107  
-						if (!src.size) { // only preloaded image objects can be used as source
5108  
-							throw new x.DOMException(x.DOMException.INVALID_STATE_ERR);
5109  
-						}
5110  
-						_loadFromImage.apply(this, args);
5111  
-					}
5112  
-					// if source is Blob/File
5113  
-					else if (src instanceof Blob) {
5114  
-						if (!~Basic.inArray(src.type, ['image/jpeg', 'image/png'])) {
5115  
-							throw new x.ImageError(x.ImageError.WRONG_FORMAT);
5116  
-						}
5117  
-						_loadFromBlob.apply(this, args);
5118  
-					}
5119  
-					// if source looks like Url
5120  
-					else if (Basic.typeOf(src) === 'string' && /^http:\/\//.test(src)) {
5121  
-						_loadFromUrl.apply(this, args);
5122  
-					}
5123  
-					// if source seems to be an img node
5124  
-					else if ((el = Dom.get(src)) && el.nodeName === 'img') {
5125  
-						args.unshift(Url.resolveUrl(el.src));
5126  
-						_loadFromUrl.apply(this, args);
5127  
-					}
5128  
-					else {
5129  
-						throw new x.DOMException(x.DOMException.TYPE_MISMATCH_ERR);
5130  
-					}
5131  
-				} catch(ex) {
5132  
-					// for now simply trigger error event
5133  
-					this.trigger('error');
5134  
-				}
  5101
+				_load.apply(this, arguments);
5135 5102
 			},
5136 5103
 
5137 5104
 			/**
@@ -5162,9 +5129,6 @@ define("moxie/image/Image", [
5162 5129
 				preserveHeaders = (Basic.typeOf(preserveHeaders) === 'undefined' ? true : !!preserveHeaders);
5163 5130
 
5164 5131
 				runtime = this.getRuntime();
5165  
-				this.bind('Resize', function(e) {
5166  
-					_updateInfo.call(this);
5167  
-				}, 999);
5168 5132
 				runtime.exec.call(this, 'Image', 'resize', width, height, crop, preserveHeaders);
5169 5133
 			},
5170 5134
 
@@ -5186,7 +5150,7 @@ define("moxie/image/Image", [
5186 5150
 				}
5187 5151
 
5188 5152
 				var runtime = this.connectRuntime(this.ruid);
5189  
-				return runtime.exec.call(self, 'Image', 'getAsCanvas');
  5153
+				return runtime.exec.call(this, 'Image', 'getAsCanvas');
5190 5154
 			},
5191 5155
 
5192 5156
 			/**
@@ -5213,7 +5177,7 @@ define("moxie/image/Image", [
5213 5177
 					quality = 90;
5214 5178
 				}
5215 5179
 
5216  
-				return this.getRuntime().exec.call(self, 'Image', 'getAsBlob', type, quality);
  5180
+				return this.getRuntime().exec.call(this, 'Image', 'getAsBlob', type, quality);
5217 5181
 			},
5218 5182
 
5219 5183
 			/**
@@ -5231,7 +5195,7 @@ define("moxie/image/Image", [
5231 5195
 				if (!this.size) {
5232 5196
 					throw new x.DOMException(x.DOMException.INVALID_STATE_ERR);
5233 5197
 				}
5234  
-				return this.getRuntime().exec.call(self, 'Image', 'getAsDataURL', type, quality);
  5198
+				return this.getRuntime().exec.call(this, 'Image', 'getAsDataURL', type, quality);
5235 5199
 			},
5236 5200
 
5237 5201
 			/**
@@ -5261,7 +5225,9 @@ define("moxie/image/Image", [
5261 5225
 			representation
5262 5226
 			*/
5263 5227
 			embed: function(el) {
5264  
-				var image, type, quality, dimensions
  5228
+				var self = this
  5229
+				, imgCopy
  5230
+				, type, quality, crop
5265 5231
 				, options = arguments[1] || {}
5266 5232
 				, width = this.width
5267 5233
 				, height = this.height
@@ -5269,28 +5235,26 @@ define("moxie/image/Image", [
5269 5235
 				;
5270 5236
 
5271 5237
 				function onResize() {
5272  
-					var dataUrl, type = type || this.type || 'image/jpeg';
5273  
-
5274 5238
 					// if possible, embed a canvas element directly
5275 5239
 					if (Env.can('create_canvas')) {
5276  
-						var canvas = image.getAsCanvas();
  5240
+						var canvas = imgCopy.getAsCanvas();
5277 5241
 						if (canvas) {
5278 5242
 							el.appendChild(canvas);
5279 5243
 							canvas = null;
5280  
-							image.destroy();
  5244
+							imgCopy.destroy();
5281 5245
 							self.trigger('embedded');
5282 5246
 							return;
5283 5247
 						}
5284 5248
 					}
5285 5249
 
5286  
-					dataUrl = image.getAsDataURL(type, quality);
  5250
+					var dataUrl = imgCopy.getAsDataURL(type, quality);
5287 5251
 					if (!dataUrl) {
5288 5252
 						throw new x.ImageError(x.ImageError.WRONG_FORMAT);
5289 5253
 					}
5290 5254
 
5291  
-					if (Env.can('use_data_uri_of', image.size)) {
5292  
-						el.innerHTML = '<img src="' + dataUrl + '" width="' + image.width + '" height="' + image.height + '" />';
5293  
-						image.destroy();
  5255
+					if (Env.can('use_data_uri_of', dataUrl.length)) {
  5256
+						el.innerHTML = '<img src="' + dataUrl + '" width="' + imgCopy.width + '" height="' + imgCopy.height + '" />';
  5257
+						imgCopy.destroy();
5294 5258
 						self.trigger('embedded');
5295 5259
 					} else {
5296 5260
 						var tr = new Transporter();
@@ -5304,8 +5268,8 @@ define("moxie/image/Image", [
5304 5268
 									//position: 'relative',
5305 5269
 									top: '0px',
5306 5270
 									left: '0px',
5307  
-									width: image.width + 'px',
5308  
-									height: image.height + 'px'
  5271
+									width: imgCopy.width + 'px',
  5272
+									height: imgCopy.height + 'px'
5309 5273
 								});
5310 5274
 
5311 5275
 								// some shims (Flash/SilverLight) reinitialize, if parent element is hidden, reordered or it's
@@ -5317,18 +5281,18 @@ define("moxie/image/Image", [
5317 5281
 									onResize.call(self); // re-feed our image data
5318 5282
 								});*/
5319 5283
 
5320  
-								self.disconnectRuntime();
5321 5284
 								runtime = null;
5322 5285
 							}, 999);
5323 5286
 
5324  
-							runtime.exec.call(self, "ImageView", "display", this.result.getSource().id, width, height);
5325  
-							image.destroy();
  5287
+							runtime.exec.call(self, "ImageView", "display", this.result.uid, width, height);
  5288
+							imgCopy.destroy();
5326 5289
 						});
5327 5290
 
5328 5291
 						tr.transport(Encode.atob(dataUrl.substring(dataUrl.indexOf('base64,') + 7)), type, Basic.extend({}, options, {
5329 5292
 							required_caps: {
5330 5293
 								display_media: true
5331 5294
 							},
  5295
+							runtime_order: 'flash,silverlight',
5332 5296
 							container: el
5333 5297
 						}));
5334 5298
 					}
@@ -5343,9 +5307,9 @@ define("moxie/image/Image", [
5343 5307
 				}
5344 5308
 
5345 5309
 
5346  
-				type = options.type;
  5310
+				type = options.type || this.type || 'image/jpeg';
5347 5311
 				quality = options.quality || 90;
5348  
-				var crop = options.crop !== undefined ? options.crop : false;
  5312
+				crop = options.crop !== undefined ? options.crop : false;
5349 5313
 
5350 5314
 				// figure out dimensions for the thumb
5351 5315
 				if (options.width) {
@@ -5353,26 +5317,26 @@ define("moxie/image/Image", [
5353 5317
 					height = options.height || width;
5354 5318
 				} else {
5355 5319
 					// if container element has > 0 dimensions, take them
5356  
-					dimensions = Dom.getSize(el);
  5320
+					var dimensions = Dom.getSize(el);
5357 5321
 					if (dimensions.w && dimensions.h) { // both should be > 0
5358 5322
 						width = dimensions.w;
5359 5323
 						height = dimensions.h;
5360 5324
 					}
5361 5325
 				}
5362 5326
 				
5363  
-				image = new Image();
  5327
+				imgCopy = new Image();
5364 5328
 
5365  
-				image.bind("Resize", function() {
  5329
+				imgCopy.bind("Resize", function() {
5366 5330
 					onResize.call(self);
5367 5331
 				});
5368 5332
 
5369  
-				image.bind("Load", function() {
5370  
-					image.resize(width, height, crop, false);
  5333
+				imgCopy.bind("Load", function() {
  5334
+					imgCopy.resize(width, height, crop, false);
5371 5335
 				});
5372 5336
 
5373  
-				image.clone(this, false);
  5337
+				imgCopy.clone(this);
5374 5338
 
5375  
-				return image;
  5339
+				return imgCopy;
5376 5340
 			},
5377 5341
 
5378 5342
 			/**
@@ -5382,11 +5346,10 @@ define("moxie/image/Image", [
5382 5346
 			*/
5383 5347
 			destroy: function() {
5384 5348
 				if (this.ruid) {
5385  
-					this.getRuntime().exec.call(self, 'Image', 'destroy');
  5349
+					this.getRuntime().exec.call(this, 'Image', 'destroy');
5386 5350
 					this.disconnectRuntime();
5387 5351
 				}
5388 5352
 				this.unbindAll();
5389  
-				self = null;
5390 5353
 			}
5391 5354
 		});
5392 5355
 
@@ -5419,40 +5382,88 @@ define("moxie/image/Image", [
5419 5382
 			}
5420 5383
 		}
5421 5384
 
  5385
+		function _load(src) {
  5386
+			var srcType = Basic.typeOf(src);
  5387
+
  5388
+			try {
  5389
+				// if source is Image
  5390
+				if (src instanceof Image) {
  5391
+					if (!src.size) { // only preloaded image objects can be used as source
  5392
+						throw new x.DOMException(x.DOMException.INVALID_STATE_ERR);
  5393
+					}
  5394
+					_loadFromImage.apply(this, arguments);
  5395
+				}
  5396
+				// if source is o.Blob/o.File
  5397
+				else if (src instanceof Blob) {
  5398
+					if (!~Basic.inArray(src.type, ['image/jpeg', 'image/png'])) {
  5399
+						throw new x.ImageError(x.ImageError.WRONG_FORMAT);
  5400
+					}
  5401
+					_loadFromBlob.apply(this, arguments);
  5402
+				}
  5403
+				// if native blob/file
  5404
+				else if (Basic.inArray(srcType, ['blob', 'file']) !== -1) {
  5405
+					_load.call(this, new o.File(null, src), arguments[1]);
  5406
+				}
  5407
+				// if String
  5408
+				else if (srcType === 'string') {
  5409
+					// if dataUrl String
  5410
+					if (/^data:[^;]*;base64,/.test(src)) {
  5411
+						_load.call(this, new o.Blob(null, { data: src }), arguments[1]);
  5412
+					}
  5413
+					// else assume Url, either relative or absolute
  5414
+					else {
  5415
+						_loadFromUrl.apply(this, arguments);
  5416
+					}
  5417
+				}
  5418
+				// if source seems to be an img node
  5419
+				else if (srcType === 'node' && src.nodeName === 'img') {
  5420
+					_load.call(this, src.src, arguments[1]);
  5421
+				}
  5422
+				else {
  5423
+					throw new x.DOMException(x.DOMException.TYPE_MISMATCH_ERR);
  5424
+				}
  5425
+			} catch(ex) {
  5426
+				// for now simply trigger error event
  5427
+				this.trigger('error');
  5428
+			}
  5429
+		}
  5430
+
5422 5431
 
5423 5432
 		function _loadFromImage(img, exact) {
5424 5433
 			var runtime = this.connectRuntime(img.ruid);
5425 5434
 			this.ruid = runtime.uid;
5426  
-			runtime.exec.call(self, 'Image', 'loadFromImage', img, (exact === undefined ? true : exact));
  5435
+			runtime.exec.call(this, 'Image', 'loadFromImage', img, (exact === undefined ? true : exact));
5427 5436
 		}
5428 5437
 
5429 5438
 
5430  
-		function _loadFromBlob(blob, asBinary) {
  5439
+		function _loadFromBlob(blob, options) {
  5440
+			var self = this;
5431 5441
 
5432 5442
 			self.name = blob.name || '';
5433 5443
 
5434 5444
 			function exec(runtime) {
5435 5445
 				self.ruid = runtime.uid;
5436  
-				runtime.exec.call(self, 'Image', 'loadFromBlob', blob, asBinary);
  5446
+				runtime.exec.call(self, 'Image', 'loadFromBlob', blob);
5437 5447
 			}
5438 5448
 
5439 5449
 			if (blob.isDetached()) {
5440 5450
 				this.bind('RuntimeInit', function(e, runtime) {
5441 5451
 					exec(runtime);
5442 5452
 				});
5443  
-				this.connectRuntime({
  5453
+				this.connectRuntime(Basic.extend({
5444 5454
 					required_caps: {
5445 5455
 						access_image_binary: true,
5446 5456
 						resize_image: true
5447 5457
 					}
5448  
-				});
  5458
+				}, options));
5449 5459
 			} else {
5450 5460
 				exec(this.connectRuntime(blob.ruid));
5451 5461
 			}
5452 5462
 		}
5453 5463
 
  5464
+
5454 5465
 		function _loadFromUrl(url, options) {
5455  
-			var xhr;
  5466
+			var self = this, xhr;
5456 5467
 
5457 5468
 			xhr = new XMLHttpRequest();
5458 5469
 
@@ -7773,8 +7784,10 @@ define("moxie/runtime/html5/image/Image", [
7773 7784
 		;
7774 7785
 
7775 7786
 		Basic.extend(this, {
7776  
-			loadFromBlob: function(blob, asBinary) {
7777  
-				var comp = this, I = comp.getRuntime();
  7787
+			loadFromBlob: function(blob) {
  7788
+				var comp = this, I = comp.getRuntime()
  7789
+				, asBinary = arguments.length > 1 ? arguments[1] : true
  7790
+				;
7778 7791
 
7779 7792
 				if (Basic.typeOf(asBinary) === 'undefined') {
7780 7793
 					asBinary = true;
@@ -8303,9 +8316,8 @@ define("moxie/runtime/flash/Runtime", [
8303 8316
 
8304 8317
 					// Init is dispatched by the shim
8305 8318
 					initTimer = setTimeout(function() {
8306  
-						var self = I; // keep the reference, since I won't be available after destroy
8307  
-						if (!self.initialized) {
8308  
-							self.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
  8319
+						if (I && !I.initialized) { // runtime might be already destroyed by this moment
  8320
+							I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
8309 8321
 						}
8310 8322
 					}, 5000);
8311 8323
 				},
@@ -8807,7 +8819,7 @@ define("moxie/runtime/flash/image/Image", [
8807 8819
 				tr.bind("TransportingComplete", function() {
8808 8820
 					exec(tr.result.getSource());
8809 8821
 				});
8810  
-				tr.transport(blob.getSource(), blob.type, self.uid);
  8822
+				tr.transport(blob.getSource(), blob.type, { ruid: self.uid });
8811 8823
 			} else {
8812 8824
 				exec(blob.getSource());
8813 8825
 			}
@@ -8957,6 +8969,7 @@ define("moxie/runtime/silverlight/Runtime", [
8957 8969
 					// minimal requirement Flash Player 10
8958 8970
 					if (!isInstalled('2.0.31005.0') || Env.browser === 'Opera') {
8959 8971
 						this.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
  8972
+						return;
8960 8973
 					}
8961 8974
 
8962 8975
 					container = this.getShimContainer();
@@ -8971,11 +8984,10 @@ define("moxie/runtime/silverlight/Runtime", [
8971 8984
 
8972 8985
 					// Init is dispatched by the shim
8973 8986
 					initTimer = setTimeout(function() {
8974  
-						var self = I; // keep the reference, since I won't be available after destroy
8975  
-						if (!self.initialized) {
8976  
-							self.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
  8987
+						if (I && !I.initialized) { // runtime might be already destroyed by this moment
  8988
+							I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
8977 8989
 						}
8978  
-					}, 10000); // silverlight may take quite some time to initialize
  8990
+					}, 5000); // silverlight may take quite some time to initialize
8979 8991
 				},
8980 8992
 
8981 8993
 				destroy: (function(destroy) { // extend default destroy method
@@ -9965,7 +9977,7 @@ define("moxie/runtime/html4/image/Image", [
9965 9977
 	return (extensions.Image = Image);
9966 9978
 });
9967 9979
 
9968  
-expose(["moxie/core/utils/Basic","moxie/core/I18n","moxie/core/utils/Mime","moxie/core/utils/Env","moxie/core/utils/Dom","moxie/core/Exceptions","moxie/core/EventTarget","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/file/File","moxie/file/FileInput","moxie/file/FileDrop","moxie/file/FileReader","moxie/core/utils/Encode","moxie/core/utils/Url","moxie/runtime/RuntimeTarget","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/file/FileReaderSync","moxie/runtime/Transporter","moxie/core/JSON","moxie/image/Image","moxie/core/utils/Events"]);
  9980
+expose(["moxie/core/utils/Basic","moxie/core/I18n","moxie/core/utils/Mime","moxie/core/utils/Env","moxie/core/utils/Dom","moxie/core/Exceptions","moxie/core/EventTarget","moxie/core/utils/Encode","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/file/File","moxie/file/FileInput","moxie/file/FileDrop","moxie/file/FileReader","moxie/core/utils/Url","moxie/runtime/RuntimeTarget","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/file/FileReaderSync","moxie/runtime/Transporter","moxie/core/JSON","moxie/image/Image","moxie/core/utils/Events"]);
9969 9981
 })(this);
9970 9982
 /**
9971 9983
  * o.js
6  bin/js/moxie.min.js
3 additions, 3 deletions not shown

0 notes on commit 8b6f4db

Please sign in to comment.
Something went wrong with that request. Please try again.