Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
image upload: added strict mode
Browse files Browse the repository at this point in the history
Using:
add attr source-strict="true"
  • Loading branch information
rokerkony committed Aug 26, 2013
1 parent 0208766 commit 908f583
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/modules/ui/imageupload/imageupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@
* Image display handler (when image loaded)
* @param sourceImage
*/
function showSourceImage(sourceImage) {
function showSourceImage(sourceImage, strict) {
var $sourceImage = $(sourceImage),
sourceWidth = ($sourceImage.data('width') ? $sourceImage.data('width') : sourceImage.width),
sourceHeight = ($sourceImage.data('height') ? $sourceImage.data('height') : sourceImage.height);

if (strict && !(resultScale[0] < sourceWidth && resultScale[1] < sourceHeight)) {
window.alert(ngxDictionary('NGX_UI_IMAGEUPLOAD_INCORRECT_IMAGE_SIZE'));
return;
}

// set isSource flag
scope.isSource = (sourceImage ? true : false);

Expand Down Expand Up @@ -269,7 +274,7 @@
$(image).hide();

image.onload = function() {
showSourceImage(this);
showSourceImage(this, $element.attr('source-strict'));
scope.$apply();
};
image.onerror = function() {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/ui/imageupload/lang/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
NGX_UI_IMAGEUPLOAD_DIALOG_SUBMIT: 'Nahrát',
NGX_UI_IMAGEUPLOAD_DIALOG_CANCEL: 'Zrušit',
NGX_UI_IMAGEUPLOAD_INVALID_IMAGE: 'Neplatný obrázek',
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Chyba při zpracování obrázku anebo neplatný obrázek'
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Chyba při zpracování obrázku anebo neplatný obrázek',
NGX_UI_IMAGEUPLOAD_INCORRECT_IMAGE_SIZE: 'Obrázek nesplňuje minimální rozměry'
});
}]);

Expand Down
3 changes: 2 additions & 1 deletion src/modules/ui/imageupload/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
NGX_UI_IMAGEUPLOAD_DIALOG_SUBMIT: 'Submit',
NGX_UI_IMAGEUPLOAD_DIALOG_CANCEL: 'Cancel',
NGX_UI_IMAGEUPLOAD_INVALID_IMAGE: 'Invalid image',
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Error processing image or invalid image'
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Error processing image or invalid image',
NGX_UI_IMAGEUPLOAD_INCORRECT_IMAGE_SIZE: 'Image does not meet the minimum dimensions'
});
}]);

Expand Down
3 changes: 2 additions & 1 deletion src/modules/ui/imageupload/lang/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
NGX_UI_IMAGEUPLOAD_DIALOG_SUBMIT: 'Wgraj',
NGX_UI_IMAGEUPLOAD_DIALOG_CANCEL: 'Anulować',
NGX_UI_IMAGEUPLOAD_INVALID_IMAGE: 'Nieprawidłowy obraz',
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Błąd przy przetwarzaniu obrazu lub nieprawidłowy obraz'
NGX_UI_IMAGEUPLOAD_PROCESS_ERROR: 'Błąd przy przetwarzaniu obrazu lub nieprawidłowy obraz',
NGX_UI_IMAGEUPLOAD_INCORRECT_IMAGE_SIZE: 'Obraz nie spełnia minimalne wymiary'
});
}]);

Expand Down

0 comments on commit 908f583

Please sign in to comment.