1(function() { 2 var ASPxClientImageControlBase = ASPx.CreateClass(null, { 3 constructor: function(control) { 4 this.control = control; 5 this.Initialize(); 6 this.CreateControlHierarchy(); 7 this.PrepareControlHierarchy(); 8 if(this.IsEnabled()) 9 this.InitializeHandlers(); 10 }, 11 Initialize: function() { 12 }, 13 CreateControlHierarchy: function() { 14 }, 15 PrepareControlHierarchy: function() { 16 }, 17 AdjustControl: function() { 18 }, 19 InitializeHandlers: function() { 20 }, 21 IsEnabled: function() { 22 return this.control.enabled; 23 } 24 }); 25 var ImageSizeModeEnum = { 26 ActualSizeOrFit: 0, 27 FitProportional: 1, 28 FitAndCrop: 2 29 }; 30 var RenderMode = { 31 Image: 0, 32 Canvas: 1 33 }; 34 var Utils = { 35 versions: {}, 36 GetKey: function(image) { 37 return image.id + image.className; 38 }, 39 RemoveLoadingGif: function(element) { 40 ASPx.SetStyles(element, { backgroundImage: "url(" + ASPx.EmptyImageUrl + ")" }); 41 }, 42 IsImageLoaded: function(image) { 43 return image.complete && image.naturalWidth !== undefined; 44 }, 45 IsEmptyImageSource: function(image) { 46 return !ASPx.Attr.GetAttribute(image, "src"); 47 }, 48 IsNotEmptyImageSize: function(image) { 49 return image.naturalWidth && image.naturalHeight || image.width && image.height ? true : false; 50 }, 51 TryGetImageSize: function(image, onComplete) { 52 var fakeImage = new Image(); 53 ASPx.Evt.AttachEventToElement(fakeImage, "load", function(evt) { 54 image.width = fakeImage.width; 55 image.height = fakeImage.height; 56 image.naturalWidth = fakeImage.width; 57 image.naturalHeight = fakeImage.height; 58 onComplete(); 59 }); 60 fakeImage.src = image.src; 61 }, 62 ChangeImageSource: function(image, src, onComplete, onError) { 63 var keyVersion = Utils.GetKey(image); 64 Utils.versions[keyVersion] = (Utils.versions[keyVersion] + 1) || 0; 65 var currentVersion = Utils.versions[keyVersion]; 66 var newImage = document.createElement("IMG"); 67 newImage.id = image.id; 68 newImage.className = image.className; 69 newImage.alt = image.alt; 70 ASPx.Evt.AttachEventToElement(newImage, "load", function(evt) { 71 if(Utils.versions[keyVersion] == currentVersion) { 72 image.parentNode.appendChild(newImage); 73 ASPx.RemoveElement(image); 74 onComplete(); 75 } 76 }); 77 if(onError) 78 ASPx.Evt.AttachEventToElement(newImage, "error", function(evt) { onError(); }); 79 newImage.src = src; 80 } 81 }; 82 var ResizeUtils = { 83 ResizeImage: function(image, options) { 84 if(!Utils.IsNotEmptyImageSize(image)) 85 Utils.TryGetImageSize(image, function() { ResizeUtils.ResizeImageCore(image, options); }); 86 else 87 ResizeUtils.ResizeImageCore(image, options); 88 }, 89 ResizeImageCore: function(image, options) { 90 var parent = image.parentNode; 91 var canvas = ResizeUtils.GetCanvas(parent); 92 var sizeMode = options.sizeMode == undefined ? ImageSizeModeEnum.ActualSizeOrFit : options.sizeMode; 93 var properties = ResizeUtils.GetImageProperties(image.naturalWidth || image.width, image.naturalHeight || image.height, options.width, options.height, sizeMode); 94 var useCanvas = properties.renderMode == RenderMode.Canvas && (options.canUseCanvas == undefined ? true : options.canUseCanvas); 95 if(useCanvas) { 96 if(canvas) { 97 canvas.width = options.width; 98 canvas.height = options.height; 99 ResizeUtils.DrawImage(canvas, image, properties); 100 } 101 else {
102 canvas = ResizeUtils.CreateCanvas(parent, options.width, options.height, image, properties); 103 ASPx.RemoveElement(image); 104 } 105 } 106 else { 107 if(canvas) 108 ASPx.RemoveElement(canvas); 109 ResizeUtils.SetImageProperties(image, properties, options.rtl); 110 } 111 if(options.onEndResize) 112 options.onEndResize(canvas || image, useCanvas); 113 }, 114 SetImageProperties: function(image, properties, rtl) { 115 var style = { 116 marginTop: properties.y, display: "" 117 }; 118 if(rtl) 119 style.marginRight = properties.x; 120 else 121 style.marginLeft = properties.x; 122 image.width = properties.w; 123 image.height = properties.h; 124 ASPx.SetStyles(image, style); 125 }, 126 GetImageProperties: function(naturalWidth, naturalHeight, width, height, sizeMode) { 127 var properties = {}; 128 switch (sizeMode) { 129 case ImageSizeModeEnum.FitAndCrop: 130 properties = ResizeUtils.GetFitAndCropImageProperties(naturalWidth, naturalHeight, width, height); 131 break; 132 case ImageSizeModeEnum.FitProportional: 133 properties = ResizeUtils.GetFitProportionalImageProperties(naturalWidth, naturalHeight, width, height); 134 break; 135 case ImageSizeModeEnum.ActualSizeOrFit: 136 properties = ResizeUtils.GetActualSizeOrFitImageProperties(naturalWidth, naturalHeight, width, height); 137 break; 138 } 139 properties.renderMode = RenderMode.Image;
140 if(window.HTMLCanvasElement && (naturalWidth > width * 2 || naturalHeight > height * 2)) { 141 if(ASPx.Browser.MacOSMobilePlatform && (naturalWidth > 2200 || naturalHeight > 2200)) 142 properties.renderMode = RenderMode.Image; 143 else 144 properties.renderMode = RenderMode.Canvas; 145 } 146 return properties; 147 }, 148 GetFitAndCropImageProperties: function(naturalWidth, naturalHeight, width, height) { 149 var ratio = naturalWidth / naturalHeight; 150 naturalWidth = width; 151 naturalHeight = naturalWidth / ratio; 152 if(naturalHeight < height) { 153 naturalHeight = height; 154 naturalWidth = naturalHeight * ratio; 155 } 156 var left = -(naturalWidth - width) / 2; 157 var top = -(naturalHeight - height) / 2; 158 return ResizeUtils.CreateImagePropertiesObject(naturalWidth, naturalHeight, left, top); 159 }, 160 GetFitProportionalImageProperties: function(naturalWidth, naturalHeight, width, height) { 161 var ratio = naturalWidth / naturalHeight; 162 naturalWidth = width; 163 naturalHeight = naturalWidth / ratio; 164 if(naturalHeight > height) { 165 naturalHeight = height; 166 naturalWidth = naturalHeight * ratio; 167 } 168 var left = (width - naturalWidth) / 2; 169 var top = (height - naturalHeight) / 2; 170 return ResizeUtils.CreateImagePropertiesObject(naturalWidth, naturalHeight, left, top); 171 }, 172 GetActualSizeOrFitImageProperties: function(naturalWidth, naturalHeight, width, height) { 173 if(naturalWidth > width || naturalHeight > height) 174 return ResizeUtils.GetFitProportionalImageProperties(naturalWidth, naturalHeight, width, height); 175 return ResizeUtils.CreateImagePropertiesObject(naturalWidth, naturalHeight, (width - naturalWidth) / 2, (height - naturalHeight) / 2); 176 }, 177 CreateImagePropertiesObject: function(w, h, x, y) { 178 var obj = { w: w, h: h, x: x, y: y }; 179 obj.w = Math.round(obj.w); 180 obj.h = Math.round(obj.h); 181 obj.x = Math.round(obj.x); 182 obj.y = Math.round(obj.y); 183 return obj; 184 }, 185 GetCanvas: function (container) { 186 return ASPx.GetChildByTagName(container, "CANVAS"); 187 }, 188 CreateCanvas: function(container, width, height, image, properties) { 189 var canvas = document.createElement("CANVAS"); 190 canvas.width = width; 191 canvas.height = height; 192 container.appendChild(canvas); 193 if(image && properties) 194 ResizeUtils.DrawImage(canvas, image, properties); 195 return canvas; 196 }, 197 DrawImage: function(canvas, image, properties) { 198 var context = canvas.getContext("2d"); 199 context.drawImage(image, properties.x, properties.y, properties.w, properties.h); 200 } 201 }; 202 ASPx.ImageControlUtils = {}; 203 ASPx.ImageControlUtils.ResizeImage = ResizeUtils.ResizeImage; 204 ASPx.ImageControlUtils.RemoveLoadingGif = Utils.RemoveLoadingGif; 205 ASPx.ImageControlUtils.IsImageLoaded = Utils.IsImageLoaded; 206 ASPx.ImageControlUtils.IsEmptyImageSource = Utils.IsEmptyImageSource; 207 ASPx.ImageControlUtils.IsNotEmptyImageSize = Utils.IsNotEmptyImageSize; 208 ASPx.ImageControlUtils.ChangeImageSource = Utils.ChangeImageSource; 209 ASPx.ImageControlUtils.TryGetImageSize = Utils.TryGetImageSize; 210 ASPx.ImageControlUtils.ImageSizeModeEnum = ImageSizeModeEnum; 211 window.ASPxClientImageControlBase = ASPxClientImageControlBase; 212})(); 213
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.