7 * @class Roo.bootstrap.UploadCropbox
8 * @extends Roo.bootstrap.Component
9 * Bootstrap UploadCropbox class
10 * @cfg {String} emptyText show when image has been loaded
11 * @cfg {String} rotateNotify show when image too small to rotate
12 * @cfg {Number} errorTimeout default 3000
13 * @cfg {Number} minWidth default 300
14 * @cfg {Number} minHeight default 300
15 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
18 * Create a new UploadCropbox
19 * @param {Object} config The config object
22 Roo.bootstrap.UploadCropbox = function(config){
23 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
27 * @event beforeselectfile
28 * Fire before select file
29 * @param {Roo.bootstrap.UploadCropbox} this
31 "beforeselectfile" : true,
34 * Fire after initEvent
35 * @param {Roo.bootstrap.UploadCropbox} this
40 * Fire after initEvent
41 * @param {Roo.bootstrap.UploadCropbox} this
42 * @param {String} data
47 * Fire when preparing the file data
48 * @param {Roo.bootstrap.UploadCropbox} this
49 * @param {Object} file
54 * Fire when get exception
55 * @param {Roo.bootstrap.UploadCropbox} this
56 * @param {Object} options
60 * @event beforeloadcanvas
61 * Fire before load the canvas
62 * @param {Roo.bootstrap.UploadCropbox} this
65 "beforeloadcanvas" : true,
68 * Fire when trash image
69 * @param {Roo.bootstrap.UploadCropbox} this
74 * Fire when download the image
75 * @param {Roo.bootstrap.UploadCropbox} this
79 * @event footerbuttonclick
80 * Fire when footerbuttonclick
81 * @param {Roo.bootstrap.UploadCropbox} this
82 * @param {String} type
84 "footerbuttonclick" : true,
88 * @param {Roo.bootstrap.UploadCropbox} this
94 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
97 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
99 emptyText : 'Click to upload image',
100 rotateNotify : 'Image is too small to rotate',
115 cropType : 'image/jpeg',
117 canvasLoaded : false,
119 getAutoCreate : function()
123 cls : 'roo-upload-cropbox',
127 cls : 'roo-upload-cropbox-body',
128 style : 'cursor:pointer',
132 cls : 'roo-upload-cropbox-preview'
136 cls : 'roo-upload-cropbox-thumb'
140 cls : 'roo-upload-cropbox-empty-notify',
141 html : this.emptyText
145 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
146 html : this.rotateNotify
152 cls : 'roo-upload-cropbox-footer',
155 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
165 onRender : function(ct, position)
167 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
169 if (this.buttons.length) {
171 Roo.each(this.buttons, function(bb) {
173 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
175 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
181 initEvents : function()
183 this.urlAPI = (window.createObjectURL && window) ||
184 (window.URL && URL.revokeObjectURL && URL) ||
185 (window.webkitURL && webkitURL);
187 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
188 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
190 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
191 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
193 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
194 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
197 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
198 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
200 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
201 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
204 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
205 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
206 this.footerEl.hide();
208 this.setThumbBoxSize();
214 this.fireEvent('initial', this);
221 window.addEventListener("resize", function() { _this.resize(); } );
223 this.bodyEl.on('click', this.beforeSelectFile, this);
226 this.bodyEl.on('touchstart', this.onTouchStart, this);
227 this.bodyEl.on('touchmove', this.onTouchMove, this);
228 this.bodyEl.on('touchend', this.onTouchEnd, this);
232 this.bodyEl.on('mousedown', this.onMouseDown, this);
233 this.bodyEl.on('mousemove', this.onMouseMove, this);
234 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
235 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
236 Roo.get(document).on('mouseup', this.onMouseUp, this);
246 this.dragable = false;
247 this.pinching = false;
250 this.cropData = false;
251 this.notifyEl.dom.innerHTML = this.emptyText;
257 if(this.fireEvent('resize', this) != false){
258 this.setThumbBoxPosition();
259 this.setCanvasPosition();
263 onFooterButtonClick : function(e, el, o, type)
267 this.onRotateLeft(e);
269 case 'rotate-right' :
270 this.onRotateRight(e);
273 this.beforeSelectFile(e);
288 this.fireEvent('footerbuttonclick', this, type);
291 beforeSelectFile : function(e)
293 this.fireEvent('beforeselectfile', this);
298 this.fireEvent('trash', this);
301 download : function(e)
303 this.fireEvent('download', this);
306 loadCanvas : function(src)
308 if(this.fireEvent('beforeloadcanvas', this, src) != false){
312 this.imageEl = document.createElement('img');
316 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
318 this.imageEl.src = src;
322 onLoadCanvas : function()
324 this.bodyEl.un('click', this.beforeSelectFile, this);
326 this.notifyEl.hide();
328 this.footerEl.show();
330 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
331 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
333 this.setThumbBoxPosition();
334 this.baseRotateLevel();
335 this.baseScaleLevel();
341 this.canvasLoaded = true;
345 setCanvasPosition : function()
351 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
352 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
354 this.previewEl.setLeft(pw);
355 this.previewEl.setTop(ph);
358 onMouseDown : function(e)
362 this.dragable = true;
363 this.pinching = false;
365 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
366 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
370 onMouseMove : function(e)
374 if(!this.canvasLoaded){
382 var minX = Math.ceil(this.thumbEl.getLeft(true));
383 var minY = Math.ceil(this.thumbEl.getTop(true));
385 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
386 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
388 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
389 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
394 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
395 var bgY = Math.ceil(y + this.previewEl.getTop(true));
397 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
398 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
400 this.previewEl.setLeft(bgX);
401 this.previewEl.setTop(bgY);
403 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
404 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
407 onMouseUp : function(e)
411 this.dragable = false;
414 onMouseWheel : function(e)
418 this.startScale = this.scale;
420 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
422 if(!this.zoomable()){
423 this.scale = this.startScale;
432 zoomable : function()
434 var minScale = this.thumbEl.getWidth() / this.minWidth;
436 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel());
437 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel());
440 (this.rotate == 0 || this.rotate == 180) &&
442 width / minScale < this.minWidth ||
443 width / minScale > this.imageEl.OriginWidth ||
444 height / minScale < this.minHeight ||
445 height / minScale > this.imageEl.OriginHeight
452 (this.rotate == 90 || this.rotate == 270) &&
454 width / minScale < this.minHeight ||
455 width / minScale > this.imageEl.OriginWidth ||
456 height / minScale < this.minWidth ||
457 height / minScale > this.imageEl.OriginHeight
467 onRotateLeft : function(e)
469 var minScale = this.thumbEl.getWidth() / this.minWidth;
471 if(this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight()){
473 var bw = this.canvasEl.width / this.getScaleLevel();
474 var bh = this.canvasEl.height / this.getScaleLevel();
476 this.startScale = this.scale;
478 while (this.getScaleLevel() < minScale){
480 this.scale = this.scale + 1;
482 if(!this.zoomable()){
487 bw * this.getScaleLevel() < this.thumbEl.getHeight() ||
488 bh * this.getScaleLevel() < this.thumbEl.getWidth()
493 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
500 this.scale = this.startScale;
507 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
513 onRotateRight : function(e)
515 var minScale = this.thumbEl.getWidth() / this.minWidth;
517 if(this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight()){
519 var bw = this.canvasEl.width / this.getScaleLevel();
520 var bh = this.canvasEl.height / this.getScaleLevel();
522 this.startScale = this.scale;
524 while (this.getScaleLevel() < minScale){
526 this.scale = this.scale + 1;
528 if(!this.zoomable()){
533 bw * this.getScaleLevel() < this.thumbEl.getHeight() ||
534 bh * this.getScaleLevel() < this.thumbEl.getWidth()
539 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
546 this.scale = this.startScale;
553 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
558 onRotateFail : function()
560 this.errorEl.show(true);
564 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
569 this.previewEl.dom.innerHTML = '';
571 var canvasEl = document.createElement("canvas");
573 var contextEl = canvasEl.getContext("2d");
575 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
576 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
577 var center = this.imageEl.OriginWidth / 2;
579 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
580 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
581 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
582 center = this.imageEl.OriginHeight / 2;
585 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
587 contextEl.translate(center, center);
588 contextEl.rotate(this.rotate * Math.PI / 180);
590 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
592 this.canvasEl = document.createElement("canvas");
594 this.contextEl = this.canvasEl.getContext("2d");
596 switch (this.rotate) {
599 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
600 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
602 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
607 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
608 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
610 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
611 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
615 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
620 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
621 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
623 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
624 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
628 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
633 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
634 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
636 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
637 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
641 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
648 this.previewEl.appendChild(this.canvasEl);
650 this.setCanvasPosition();
655 if(!this.canvasLoaded){
658 var canvas = document.createElement("canvas");
660 var context = canvas.getContext("2d");
662 canvas.width = this.minWidth;
663 canvas.height = this.minHeight;
665 var cropWidth = this.thumbEl.getWidth();
666 var cropHeight = this.thumbEl.getHeight();
668 var x = this.thumbEl.getLeft(true) - this.previewEl.getLeft(true);
669 var y = this.thumbEl.getTop(true) - this.previewEl.getTop(true);
671 if(this.canvasEl.width - cropWidth < x){
672 x = this.canvasEl.width - cropWidth;
675 if(this.canvasEl.height - cropHeight < y){
676 y = this.canvasEl.height - cropHeight;
682 context.drawImage(this.canvasEl, x, y, cropWidth, cropHeight, 0, 0, canvas.width, canvas.height);
684 this.cropData = canvas.toDataURL(this.cropType);
686 this.fireEvent('crop', this, this.cropData);
690 setThumbBoxSize : function()
693 var width = Math.ceil(this.minWidth * height / this.minHeight);
695 if(this.minWidth > this.minHeight){
697 height = Math.ceil(this.minHeight * width / this.minWidth);
700 this.thumbEl.setStyle({
701 width : width + 'px',
702 height : height + 'px'
709 setThumbBoxPosition : function()
711 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
712 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
714 this.thumbEl.setLeft(x);
715 this.thumbEl.setTop(y);
719 baseRotateLevel : function()
724 typeof(this.exif) != 'undefined' &&
725 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
726 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
728 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
731 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
735 baseScaleLevel : function()
739 if(this.baseRotate == 6 || this.baseRotate == 8){
741 width = this.thumbEl.getHeight();
742 this.baseScale = height / this.imageEl.OriginHeight;
744 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
745 height = this.thumbEl.getWidth();
746 this.baseScale = height / this.imageEl.OriginHeight;
749 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
750 height = this.thumbEl.getWidth();
751 this.baseScale = height / this.imageEl.OriginHeight;
753 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
754 width = this.thumbEl.getHeight();
755 this.baseScale = width / this.imageEl.OriginWidth;
762 width = this.thumbEl.getWidth();
763 this.baseScale = width / this.imageEl.OriginWidth;
765 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
766 height = this.thumbEl.getHeight();
767 this.baseScale = height / this.imageEl.OriginHeight;
771 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
773 height = this.thumbEl.getHeight();
774 this.baseScale = height / this.imageEl.OriginHeight;
776 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
777 width = this.thumbEl.getWidth();
778 this.baseScale = width / this.imageEl.OriginWidth;
786 getScaleLevel : function()
788 return this.baseScale * Math.pow(1.1, this.scale);
791 onTouchStart : function(e)
793 if(!this.canvasLoaded){
794 this.beforeSelectFile(e);
798 var touches = e.browserEvent.touches;
804 if(touches.length == 1){
809 if(touches.length != 2){
815 for(var i = 0, finger; finger = touches[i]; i++){
816 coords.push(finger.pageX, finger.pageY);
819 var x = Math.pow(coords[0] - coords[2], 2);
820 var y = Math.pow(coords[1] - coords[3], 2);
822 this.startDistance = Math.sqrt(x + y);
824 this.startScale = this.scale;
826 this.pinching = true;
827 this.dragable = false;
831 onTouchMove : function(e)
833 if(!this.pinching && !this.dragable){
837 var touches = e.browserEvent.touches;
850 for(var i = 0, finger; finger = touches[i]; i++){
851 coords.push(finger.pageX, finger.pageY);
854 var x = Math.pow(coords[0] - coords[2], 2);
855 var y = Math.pow(coords[1] - coords[3], 2);
857 this.endDistance = Math.sqrt(x + y);
859 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
861 if(!this.zoomable()){
862 this.scale = this.startScale;
870 onTouchEnd : function(e)
872 this.pinching = false;
873 this.dragable = false;
877 prepare : function(input)
882 if(typeof(input) === 'string'){
883 this.loadCanvas(input);
887 if(!input.files || !input.files[0] || !this.urlAPI){
891 this.file = input.files[0];
892 this.cropType = this.file.type;
896 if(this.fireEvent('prepare', this, this.file) != false){
898 var reader = new FileReader();
900 reader.onload = function (e) {
901 if (e.target.error) {
902 Roo.log(e.target.error);
906 var buffer = e.target.result,
907 dataView = new DataView(buffer),
909 maxOffset = dataView.byteLength - 4,
913 if (dataView.getUint16(0) === 0xffd8) {
914 while (offset < maxOffset) {
915 markerBytes = dataView.getUint16(offset);
917 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
918 markerLength = dataView.getUint16(offset + 2) + 2;
919 if (offset + markerLength > dataView.byteLength) {
920 Roo.log('Invalid meta data: Invalid segment size.');
924 if(markerBytes == 0xffe1){
932 offset += markerLength;
942 var url = _this.urlAPI.createObjectURL(_this.file);
944 _this.loadCanvas(url);
949 reader.readAsArrayBuffer(this.file);
955 parseExifData : function(dataView, offset, length)
957 var tiffOffset = offset + 10,
961 if (dataView.getUint32(offset + 4) !== 0x45786966) {
962 // No Exif data, might be XMP data instead
966 // Check for the ASCII code for "Exif" (0x45786966):
967 if (dataView.getUint32(offset + 4) !== 0x45786966) {
968 // No Exif data, might be XMP data instead
971 if (tiffOffset + 8 > dataView.byteLength) {
972 Roo.log('Invalid Exif data: Invalid segment size.');
975 // Check for the two null bytes:
976 if (dataView.getUint16(offset + 8) !== 0x0000) {
977 Roo.log('Invalid Exif data: Missing byte alignment offset.');
980 // Check the byte alignment:
981 switch (dataView.getUint16(tiffOffset)) {
986 littleEndian = false;
989 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
992 // Check for the TIFF tag marker (0x002A):
993 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
994 Roo.log('Invalid Exif data: Missing TIFF marker.');
997 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
998 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
1003 tiffOffset + dirOffset,
1008 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
1013 if (dirOffset + 6 > dataView.byteLength) {
1014 Roo.log('Invalid Exif data: Invalid directory offset.');
1017 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
1018 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
1019 if (dirEndOffset + 4 > dataView.byteLength) {
1020 Roo.log('Invalid Exif data: Invalid directory size.');
1023 for (i = 0; i < tagsNumber; i += 1) {
1027 dirOffset + 2 + 12 * i, // tag offset
1031 // Return the offset to the next directory:
1032 return dataView.getUint32(dirEndOffset, littleEndian);
1035 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
1037 var tag = dataView.getUint16(offset, littleEndian);
1039 this.exif[tag] = this.getExifValue(
1043 dataView.getUint16(offset + 2, littleEndian), // tag type
1044 dataView.getUint32(offset + 4, littleEndian), // tag length
1049 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
1051 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
1060 Roo.log('Invalid Exif data: Invalid tag type.');
1064 tagSize = tagType.size * length;
1065 // Determine if the value is contained in the dataOffset bytes,
1066 // or if the value at the dataOffset is a pointer to the actual data:
1067 dataOffset = tagSize > 4 ?
1068 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
1069 if (dataOffset + tagSize > dataView.byteLength) {
1070 Roo.log('Invalid Exif data: Invalid data offset.');
1074 return tagType.getValue(dataView, dataOffset, littleEndian);
1077 for (i = 0; i < length; i += 1) {
1078 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
1081 if (tagType.ascii) {
1083 // Concatenate the chars:
1084 for (i = 0; i < values.length; i += 1) {
1086 // Ignore the terminating NULL byte(s):
1087 if (c === '\u0000') {
1099 Roo.apply(Roo.bootstrap.UploadCropbox, {
1101 'Orientation': 0x0112
1107 3: 180, //'bottom-right',
1108 // 4: 'bottom-left',
1110 6: 90, //'right-top',
1111 // 7: 'right-bottom',
1112 8: 270 //'left-bottom'
1116 // byte, 8-bit unsigned int:
1118 getValue: function (dataView, dataOffset) {
1119 return dataView.getUint8(dataOffset);
1123 // ascii, 8-bit byte:
1125 getValue: function (dataView, dataOffset) {
1126 return String.fromCharCode(dataView.getUint8(dataOffset));
1131 // short, 16 bit int:
1133 getValue: function (dataView, dataOffset, littleEndian) {
1134 return dataView.getUint16(dataOffset, littleEndian);
1138 // long, 32 bit int:
1140 getValue: function (dataView, dataOffset, littleEndian) {
1141 return dataView.getUint32(dataOffset, littleEndian);
1145 // rational = two long values, first is numerator, second is denominator:
1147 getValue: function (dataView, dataOffset, littleEndian) {
1148 return dataView.getUint32(dataOffset, littleEndian) /
1149 dataView.getUint32(dataOffset + 4, littleEndian);
1153 // slong, 32 bit signed int:
1155 getValue: function (dataView, dataOffset, littleEndian) {
1156 return dataView.getInt32(dataOffset, littleEndian);
1160 // srational, two slongs, first is numerator, second is denominator:
1162 getValue: function (dataView, dataOffset, littleEndian) {
1163 return dataView.getInt32(dataOffset, littleEndian) /
1164 dataView.getInt32(dataOffset + 4, littleEndian);
1174 cls : 'btn-group roo-upload-cropbox-rotate-left',
1175 action : 'rotate-left',
1179 cls : 'btn btn-default',
1180 html : '<i class="fa fa-undo"></i>'
1186 cls : 'btn-group roo-upload-cropbox-picture',
1191 cls : 'btn btn-default',
1192 html : '<i class="fa fa-picture-o"></i>'
1198 cls : 'btn-group roo-upload-cropbox-rotate-right',
1199 action : 'rotate-right',
1203 cls : 'btn btn-default',
1204 html : '<i class="fa fa-repeat"></i>'
1212 cls : 'btn-group roo-upload-cropbox-rotate-left',
1213 action : 'rotate-left',
1217 cls : 'btn btn-default',
1218 html : '<i class="fa fa-undo"></i>'
1224 cls : 'btn-group roo-upload-cropbox-download',
1225 action : 'download',
1229 cls : 'btn btn-default',
1230 html : '<i class="fa fa-download"></i>'
1236 cls : 'btn-group roo-upload-cropbox-crop',
1241 cls : 'btn btn-default',
1242 html : '<i class="fa fa-crop"></i>'
1248 cls : 'btn-group roo-upload-cropbox-trash',
1253 cls : 'btn btn-default',
1254 html : '<i class="fa fa-trash"></i>'
1260 cls : 'btn-group roo-upload-cropbox-rotate-right',
1261 action : 'rotate-right',
1265 cls : 'btn btn-default',
1266 html : '<i class="fa fa-repeat"></i>'