TimeTrex/interface/html5/dist/filebrowser-TImageCutArea.bundle.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2022-12-13 07:10:06 +01:00
(self.webpackChunktimetrex=self.webpackChunktimetrex||[]).push([["filebrowser-TImageCutArea"],{8453:(__unused_webpack_module,__unused_webpack_exports,__webpack_require__)=>{eval("/* provided dependency */ var jQuery = __webpack_require__(9755);\n( function( $ ) {\n\n\t$.fn.TImageCutArea = function( options ) {\n\n\t\tGlobal.addCss( 'global/widgets/filebrowser/TImageBrowser.css' );\n\t\tvar opts = $.extend( {}, $.fn.TImageCutArea.defaults, options );\n\n\t\tvar $this = this;\n\t\tvar field;\n\t\tvar name = 'filedata';\n\n\t\tvar default_width = 400;\n\t\tvar default_height = 300;\n\n\t\tvar default_after_width = 200;\n\t\tvar default_after_height = 150;\n\n\t\tthis.clearErrorStyle = function() {\n\n\t\t};\n\n\t\tthis.getField = function() {\n\t\t\treturn field;\n\t\t};\n\n\t\tthis.getValue = function() {\n\n\t\t};\n\n\t\tvar setAfterImage = function( val ) {\n\t\t\tvar image = $this.children().eq( 1 ).children().eq( 1 );\n\n\t\t\tif ( !val ) {\n\t\t\t\timage.attr( 'src', '' );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar d = new Date();\n\t\t\timage.attr( 'src', val );\n\n\t\t};\n\n\t\tthis.setImage = function( val ) {\n\t\t\tvar image = $this.children().eq( 0 ).children().eq( 1 );\n\n\t\t\tif ( !val ) {\n\t\t\t\timage.attr( 'src', '' );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar d = new Date();\n\t\t\timage.attr( 'src', val );\n\n\t\t\tsetAfterImage( val );\n\n\t\t\tsetTimeout( function() {\n\t\t\t\t$( image ).imgAreaSelect( {\n\t\t\t\t\thandles: true,\n\t\t\t\t\tx1: 0,\n\t\t\t\t\ty1: 0,\n\t\t\t\t\tx2: $( image ).width(),\n\t\t\t\t\ty2: $( image ).height(),\n\t\t\t\t\tonSelectEnd: function( img, selection ) {\n\n\t\t\t\t\t\tvar rate = image[0].naturalWidth / image.width();\n\t\t\t\t\t\tvar sx = selection.x1 * rate;\n\t\t\t\t\t\tvar sy = selection.y1 * rate;\n\t\t\t\t\t\tvar tx = selection.x2 * rate;\n\t\t\t\t\t\tvar ty = selection.y2 * rate - 1;\n\t\t\t\t\t\tvar width = selection.width * rate;\n\t\t\t\t\t\tvar height = selection.height * rate;\n\n\t\t\t\t\t\tvar canvas = $( '<canvas></canvas>' );\n\t\t\t\t\t\tcanvas = canvas[0];\n\t\t\t\t\t\tcanvas.width = width;\n\t\t\t\t\t\tcanvas.height = height;\n\t\t\t\t\t\tvar ctx = canvas.getContext( '2d' );\n\n\t\t\t\t\t\tctx.drawImage( image[0], sx, sy, width - 1, height - 1, 0, 0, width, height );\n\t\t\t\t\t\tsetAfterImage( '' );\n\t\t\t\t\t\tsetAfterImage( canvas.toDataURL() );\n\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}, 100 );\n\n\t\t};\n\n\t\tthis.getAfterImageSrc = function() {\n\t\t\tvar image = $this.children().eq( 1 ).children().eq( 1 );\n\n\t\t\treturn image.attr( 'src' );\n\t\t};\n\n\t\tthis.clearSelect = function() {\n\t\t\tvar image = $this.children().eq( 0 ).children().eq( 1 );\n\n\t\t\t$( image ).imgAreaSelect( { remove: true } );\n\n\t\t};\n\n\t\tvar onImageLoad = function( image ) {\n\n//\t\t\tif ( $( image ).height() > default_height ) {\n//\t\t\t\t$( image ).css( 'height', default_height );\n//\n//\t\t\t}\n//\n//\t\t\tif ( $( image ).width() > default_width ) {\n//\t\t\t\t$( image ).css( 'width', default_width );\n//\n//\t\t\t\t$( image ).css( 'height', 'auto' );\n//\t\t\t}\n\n//\t\t\t$( image ).show();\n\n\t\t};\n\n\t\tvar onAfterImageLoad = function( image ) {\n\n//\t\t\tif ( $( image ).height() > default_after_height ) {\n//\t\t\t\t$( image ).css( 'height', default_after_height );\n//\n//\t\t\t}\n//\n//\t\t\tif ( $( image ).width() > default_after_width ) {\n//\t\t\t\t$( image ).css( 'width', default_after_width );\n//\n//\t\t\t\t$( image ).css( 'height', 'auto' );\n//\t\t\t}\n\n//\t\t\t$( image ).show();\n\n\t\t};\n\n\t\tthis.setValue = function( val ) {\n\n\t\t\tif ( !val ) {\n\t\t\t\tval = '';\n\t\t\t}\n\n\t\t};\n\n\t\tfor ( var i = 0; i < this.length; i++ ) {\n\t\t\tvar $item = this[i];\n\n\t\t\tvar o = $.meta ? $.extend( {}, opts, $( $item ).data() ) : opts;\n\n\t\t\tfield = o.field;\n\n\t\t\tif ( o.default_width > 0 ) {\n\t\t\t\tdefault_width = o.default_width;\n\t\t\t}\n\n\t\t\tif ( o.default_height > 0 ) {\n\t\t\t\tdefault_height = o.default_height;\n\t\t\t}\n\n\t\t\tif ( Global.isSet( o.name ) ) {\n\t\t\t\tname = o.name;\n\t\t\t}\n\n\t\t\tvar image = $( $item ).chil