acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
31 lines • 1.21 kB
JavaScript
(function ($, angular, underscore, window, document, undefined) {
'use strict';
angular.module('frontend.services').factory('fileService', [function () {
return {
getExtention: function (path) {
var index = (path || '').lastIndexOf('.');
if (index === -1)
return path.toLowerCase();
return path.substring(index).toLowerCase();
},
isImage: function (path) {
return /\.(gif|jpg|bmp|jpeg|tiff|png)$/i.test(path);
},
download: function (path, options) {
var form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', path);
form.setAttribute('target', '_blank');
Object.keys(options || {}).forEach(function (key) {
var hiddenField = document.createElement('input');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', options[key]);
form.appendChild(hiddenField);
});
document.body.appendChild(form);
form.submit();
$(form).remove();
}
};
}]);
}(jQuery, angular, _, window, document));