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,14 +352,19 @@ 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)) {
@ -367,11 +372,15 @@ function onBackgroundImagePropertyChanged(data: observable.PropertyChangeData) {
} }
} else if (utils.isFileOrResourcePath(url)) { } else if (utils.isFileOrResourcePath(url)) {
style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local); style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
} else { } else if (url.indexOf("http") !== -1) {
imageSource.fromUrl(url).then(r=> { if (view) {
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local); view["_url"] = url;
});
} }
imageSource.fromUrl(url).then(r=> {
if (view && view["_url"] === url) {
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local);
}
});
} }
} }
} }