http image download fixed

This commit is contained in:
Vladimir Enchev
2015-06-10 17:14:39 +03:00
parent 77b996ea4b
commit d66cf0fab8

View File

@ -352,26 +352,35 @@ export var backgroundImageProperty = new styleProperty.Property("backgroundImage
new observable.PropertyMetadata(undefined, observable.PropertyMetadataSettings.None, onBackgroundImagePropertyChanged)); new observable.PropertyMetadata(undefined, observable.PropertyMetadataSettings.None, onBackgroundImagePropertyChanged));
function onBackgroundImagePropertyChanged(data: observable.PropertyChangeData) { function onBackgroundImagePropertyChanged(data: observable.PropertyChangeData) {
var view: view.View = (<any>data.object)._view;
var style = <Style>data.object; var style = <Style>data.object;
var url: string = data.newValue;
style._setValue(backgroundImageSourceProperty, undefined, observable.ValueSource.Local);
if (types.isString(data.newValue)) { if (types.isString(data.newValue)) {
var pattern: RegExp = /url\(('|")(.*?)\1\)/; var pattern: RegExp = /url\(('|")(.*?)\1\)/;
var match = data.newValue && (<string>data.newValue).match(pattern); var match = url.match(pattern);
var url = match && match[2] || data.newValue; if (match && match[2]) {
url = match[2];
}
if (!types.isNullOrUndefined(url)) { if (utils.isDataURI(url)) {
if (utils.isDataURI(url)) { var base64Data = url.split(",")[1];
var base64Data = url.split(",")[1]; if (types.isDefined(base64Data)) {
if (types.isDefined(base64Data)) { style._setValue(backgroundImageSourceProperty, imageSource.fromBase64(base64Data), observable.ValueSource.Local);
style._setValue(backgroundImageSourceProperty, imageSource.fromBase64(base64Data), observable.ValueSource.Local);
}
} else if (utils.isFileOrResourcePath(url)) {
style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
} else {
imageSource.fromUrl(url).then(r=> {
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local);
});
} }
} else if (utils.isFileOrResourcePath(url)) {
style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
} else if (url.indexOf("http") !== -1) {
if (view) {
view["_url"] = url;
}
imageSource.fromUrl(url).then(r=> {
if (view && view["_url"] === url) {
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local);
}
});
} }
} }
} }