Skip to content

Commit

Permalink
Fix #1276: More correct validation of previewContentTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jul 25, 2018
1 parent eccf511 commit 5c2f7f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
7 changes: 5 additions & 2 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Change Log: `bootstrap-fileinput`
=================================

## version 4.4.9 (_under development_)
## version 4.4.9

**Date:** _work in process_
**Date:** 25-Jul-2018

- (bug #1276): More correct validation of `previewContentTemplates`.
- (enh #1275): Update Farsi Translations.
- (enh #1272, #1273): Add Hebrew Translations.
- (enh #1269, #1270): Enhance auto orientation of images using piexif.js.
- Enhance progress bar text styling.
- (enh #1254): Enhance PDF Preview on iOS devices via external PDF renderer (PDFJS).
Expand Down
50 changes: 27 additions & 23 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
' <span aria-hidden="true">&times;</span>\n' +
'</button>';
},
getRotation: function(value) {
getRotation: function (value) {
switch (value) {
case 2:
return 'rotateY(180deg)';
Expand All @@ -456,7 +456,7 @@
return '';
}
},
setTransform: function(el, val) {
setTransform: function (el, val) {
if (!el) {
return;
}
Expand All @@ -471,7 +471,7 @@
return;
}
var ev = 'load.fileinputimageorient';
$img.off(ev).on(ev, function() {
$img.off(ev).on(ev, function () {
var img = $img.get(0), zoomImg = $zoomImg && $zoomImg.length ? $zoomImg.get(0) : null,
h = img.offsetHeight, w = img.offsetWidth, r = $h.getRotation(value);
$img.data('orientation', value);
Expand All @@ -483,8 +483,7 @@
$h.setTransform(zoomImg, r);
return;
}
var offsetAngle = Math.atan(w / h), t = img.style.webkitTransform || img.style.transform || '',
origFactor = Math.sqrt(Math.pow(h, 2) + Math.pow(w, 2)),
var offsetAngle = Math.atan(w / h), origFactor = Math.sqrt(Math.pow(h, 2) + Math.pow(w, 2)),
scale = !origFactor ? 1 : (h / Math.cos(Math.PI / 2 + offsetAngle)) / origFactor,
s = ' scale(' + Math.abs(scale) + ')';
$h.setTransform(img, r + s);
Expand Down Expand Up @@ -935,14 +934,14 @@
self._initPreviewTemplates();
},
_initPreviewTemplates: function () {
var self = this, cfg = self.defaults, tags = self.previewMarkupTags, tagBef, tagAft = tags.tagAfter;
$.each(cfg.previewContentTemplates, function (key, value) {
var self = this, tags = self.previewMarkupTags, tagBef, tagAft = tags.tagAfter;
$.each(self.previewContentTemplates, function (key, value) {
if ($h.isEmpty(self.previewTemplates[key])) {
tagBef = tags.tagBefore2;
if (key === 'generic' || key === 'image' || key === 'html' || key === 'text') {
tagBef = tags.tagBefore1;
}
if (self._isPdfRendered()) {
if (self._isPdfRendered() && key === 'pdf') {
tagBef = tagBef.replace('kv-file-content', 'kv-file-content kv-pdf-rendered');
}
self.previewTemplates[key] = tagBef + value + tagAft;
Expand Down Expand Up @@ -1132,8 +1131,8 @@
};
self.previewCache.init();
},
_isPdfRendered: function() {
var self = this, useLib = self.usePdfRenderer,
_isPdfRendered: function () {
var self = this, useLib = self.usePdfRenderer,
flag = typeof useLib === "function" ? useLib() : !!useLib;
return flag && self.pdfRendererUrl;
},
Expand All @@ -1149,7 +1148,7 @@
if (id) {
msg = '"' + id + '": ' + msg;
}
msg = 'bootstrap-fileinput: ' + msg;
msg = 'bootstrap-fileinput: ' + msg;
if (typeof window.console.log !== "undefined") {
window.console.log(msg);
} else {
Expand Down Expand Up @@ -1401,7 +1400,7 @@
},
_listen: function () {
var self = this, $el = self.$element, $form = self.$form, $cont = self.$container, fullScreenEvents;
self._handler($el, 'click', function(e) {
self._handler($el, 'click', function (e) {
if ($el.hasClass('file-no-browse')) {
if ($el.data('zoneClicked')) {
$el.data('zoneClicked', false);
Expand Down Expand Up @@ -1819,7 +1818,6 @@
});
}
$modal.data('previewId', pid);
var $img = $body.find('img');
self._handler($prev, 'click', function () {
self._zoomSlideShow('prev', pid);
});
Expand Down Expand Up @@ -1911,10 +1909,10 @@
});
});
},
_inputFileCount: function() {
_inputFileCount: function () {
return this.$element.get(0).files.length;
},
_refreshPreview: function() {
_refreshPreview: function () {
var self = this, files;
if (!self._inputFileCount() || !self.showPreview || !self.isPreviewable) {
return;
Expand Down Expand Up @@ -2962,6 +2960,7 @@
}
},
_slugDefault: function (text) {
// noinspection RegExpRedundantEscape
return $h.isEmpty(text) ? '' : String(text).replace(/[\[\]\/\{}:;#%=\(\)\*\+\?\\\^\$\|<>&"']/g, '_');
},
_updateFileDetails: function (numFiles) {
Expand Down Expand Up @@ -3078,6 +3077,7 @@
return null;
}
/** @namespace file.webkitRelativePath */
/** @namespace file.fileName */
relativePath = String(file.webkitRelativePath || file.fileName || file.name || null);
if (!relativePath) {
return null;
Expand Down Expand Up @@ -3143,7 +3143,7 @@
self._showUploadError(msg, params);
self._setPreviewError($thumb, i, null);
},
_getExifObj: function(iData) {
_getExifObj: function (iData) {
var self = this, exifObj = null;
try {
exifObj = window.piexif ? window.piexif.load(iData) : null;
Expand All @@ -3155,10 +3155,10 @@
}
return exifObj;
},
_validateImageOrientation: function($img, file, previewId, caption, ftype, fsize, iData) {
var self = this, css, exifObj = self._getExifObj(iData), value = null;
_validateImageOrientation: function ($img, file, previewId, caption, ftype, fsize, iData) {
var self = this, exifObj = self._getExifObj(iData), value = null;
if ($img.length && self.autoOrientImage && exifObj) {
value = exifObj["0th"][piexif.ImageIFD.Orientation];
value = exifObj["0th"][piexif.ImageIFD.Orientation]; // jshint ignore:line
}
if (!value) {
self._validateImage(previewId, caption, ftype, fsize, iData, exifObj);
Expand Down Expand Up @@ -3318,7 +3318,7 @@
$h.addCss($zone, 'clickable');
$zone.attr('tabindex', -1);
self._handler($zone, 'click', function (e) {
var $tar = $(e.target), $el = self.$element;
var $tar = $(e.target);
if (!$(self.elErrorContainer + ':visible').length &&
(!$tar.parents('.file-preview-thumbnails').length || $tar.parents('.file-default-preview').length)) {
self.$element.data('zoneClicked', true).trigger('click');
Expand Down Expand Up @@ -3785,7 +3785,8 @@
var node = ctr + i, previewId = previewInitId + "-" + node, file = files[i], fSizeKB, j, msg,
fnText = settings.text, fnImage = settings.image, fnHtml = settings.html, typ, chk, typ1, typ2,
caption = file && file.name ? self.slug(file.name) : '', fileSize = (file && file.size || 0) / 1000,
fileExtExpr = '', previewData = file ? $h.objUrl.createObjectURL(file) : null, fileCount = 0, strTypes = '',
fileExtExpr = '', previewData = file ? $h.objUrl.createObjectURL(file) : null, fileCount = 0,
strTypes = '',
func, knownTypes = 0, isText, isHtml, isImage, txtFlag, processFileLoaded = function () {
var msg = msgProgress.setTokens({
'index': i + 1,
Expand Down Expand Up @@ -4183,7 +4184,7 @@
options = $.extend(true, {}, self.options, options);
}
self._init(options, true);
self._listen();
self._listen();
return $el;
},
zoom: function (frameId) {
Expand Down Expand Up @@ -4310,6 +4311,8 @@
borderless: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
close: 'btn btn-sm btn-kv btn-default btn-outline-secondary'
},
previewTemplates: {},
previewContentTemplates: {},
preferIconicPreview: false,
preferIconicZoomPreview: false,
allowedPreviewTypes: undefined,
Expand Down Expand Up @@ -4383,6 +4386,7 @@
reversePreviewOrder: false
};

// noinspection HtmlUnknownAttribute
$.fn.fileinputLocales.en = {
fileSingle: 'file',
filePlural: 'files',
Expand Down Expand Up @@ -4456,7 +4460,7 @@
borderless: 'Toggle borderless mode',
close: 'Close detailed preview'
},
usePdfRenderer: function() {
usePdfRenderer: function () {
return !!navigator.userAgent.match(/(iPod|iPhone|iPad)/);
},
pdfRendererUrl: '',
Expand Down
Loading

0 comments on commit 5c2f7f1

Please sign in to comment.