-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #443 from magento-folks/product_media
[Folks] Media Gallery on Product Page
- Loading branch information
Showing
18 changed files
with
429 additions
and
329 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/code/Magento/Backend/view/adminhtml/requirejs-config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
/*eslint no-unused-vars: 0*/ | ||
var config = { | ||
map: { | ||
'*': { | ||
'mediaUploader': 'Magento_Backend/js/media-uploader' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
app/code/Magento/Backend/view/adminhtml/web/js/media-uploader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
/*global byteConvert*/ | ||
define([ | ||
'jquery', | ||
'mage/template', | ||
'Magento_Ui/js/modal/alert', | ||
'mage/translate', | ||
'jquery/file-uploader' | ||
], function ($, mageTemplate, alert) { | ||
'use strict'; | ||
|
||
$.widget('mage.mediaUploader', { | ||
|
||
/** | ||
* | ||
* @private | ||
*/ | ||
_create: function () { | ||
var | ||
self = this, | ||
progressTmpl = mageTemplate('[data-template="uploader"]'); | ||
|
||
this.element.find('input[type=file]').fileupload({ | ||
dataType: 'json', | ||
formData: { | ||
'form_key': window.FORM_KEY | ||
}, | ||
dropZone: '[data-tab-panel=image-management]', | ||
sequentialUploads: true, | ||
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, | ||
maxFileSize: this.options.maxFileSize, | ||
|
||
/** | ||
* @param {Object} e | ||
* @param {Object} data | ||
*/ | ||
add: function (e, data) { | ||
var | ||
fileSize, | ||
tmpl; | ||
|
||
$.each(data.files, function (index, file) { | ||
fileSize = typeof file.size == 'undefined' ? | ||
$.mage.__('We could not detect a size.') : | ||
byteConvert(file.size); | ||
|
||
data.fileId = Math.random().toString(33).substr(2, 18); | ||
|
||
tmpl = progressTmpl({ | ||
data: { | ||
name: file.name, | ||
size: fileSize, | ||
id: data.fileId | ||
} | ||
}); | ||
|
||
$(tmpl).appendTo(self.element); | ||
}); | ||
|
||
$(this).fileupload('process', data).done(function () { | ||
data.submit(); | ||
}); | ||
}, | ||
|
||
/** | ||
* @param {Object} e | ||
* @param {Object} data | ||
*/ | ||
done: function (e, data) { | ||
if (data.result && !data.result.error) { | ||
self.element.trigger('addItem', data.result); | ||
} else { | ||
alert({ | ||
content: $.mage.__('We don\'t recognize or support this file extension type.') | ||
}); | ||
} | ||
self.element.find('#' + data.fileId).remove(); | ||
}, | ||
|
||
/** | ||
* @param {Object} e | ||
* @param {Object} data | ||
*/ | ||
progress: function (e, data) { | ||
var progress = parseInt(data.loaded / data.total * 100, 10), | ||
progressSelector = '#' + data.fileId + ' .progressbar-container .progressbar'; | ||
|
||
self.element.find(progressSelector).css('width', progress + '%'); | ||
}, | ||
|
||
/** | ||
* @param {Object} e | ||
* @param {Object} data | ||
*/ | ||
fail: function (e, data) { | ||
var progressSelector = '#' + data.fileId; | ||
|
||
self.element.find(progressSelector).removeClass('upload-progress').addClass('upload-failure') | ||
.delay(2000) | ||
.hide('highlight') | ||
.remove(); | ||
} | ||
}); | ||
|
||
this.element.find('input[type=file]').fileupload('option', { | ||
process: [{ | ||
action: 'load', | ||
fileTypes: /^image\/(gif|jpeg|png)$/ | ||
}, { | ||
action: 'resize', | ||
maxWidth: this.options.maxWidth, | ||
maxHeight: this.options.maxHeight | ||
}, { | ||
action: 'save' | ||
}] | ||
}); | ||
} | ||
}); | ||
|
||
return $.mage.mediaUploader; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.