Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 8ce7e83

Browse files
committed
Theme support asafdav#24
1 parent 42be763 commit 8ce7e83

File tree

10 files changed

+128
-56
lines changed

10 files changed

+128
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bower_components
33
.idea
44
.DS_Store
55
npm-debug.log
6+
.tmp

Gruntfile.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ module.exports = function (grunt) {
66
grunt.initConfig({
77
pkg: grunt.file.readJSON('package.json'),
88
library: grunt.file.readJSON('bower.json'),
9+
ngtemplates: {
10+
app: {
11+
cwd: 'src/<%= library.name %>/templates',
12+
src: 'theme/**.html',
13+
dest: '.tmp/templates.js',
14+
options: {
15+
module: 'ngS3upload'
16+
}
17+
}
18+
},
919
concat: {
1020
options: {
1121
separator: ''
@@ -17,6 +27,7 @@ module.exports = function (grunt) {
1727
'src/<%= library.name %>/services/**/*.js',
1828
'src/<%= library.name %>/directives/**/*.js',
1929
'src/<%= library.name %>/filters/**/*.js',
30+
'<%= ngtemplates.app.dest %>',
2031
'src/<%= library.name %>/<%= library.name %>.suffix'
2132
],
2233
dest: 'build/<%= library.name %>.js'
@@ -75,6 +86,17 @@ module.exports = function (grunt) {
7586
'src/**/*'
7687
],
7788
tasks: ['default']
89+
},
90+
clean: {
91+
dist: {
92+
files: [{
93+
dot: false,
94+
src: [
95+
'.tmp',
96+
'build/'
97+
]
98+
}]
99+
}
78100
}
79101
});
80102

@@ -85,9 +107,11 @@ module.exports = function (grunt) {
85107
grunt.loadNpmTasks('grunt-contrib-jshint');
86108
grunt.loadNpmTasks('grunt-contrib-concat');
87109
grunt.loadNpmTasks('grunt-contrib-watch');
110+
grunt.loadNpmTasks('grunt-contrib-clean');
111+
grunt.loadNpmTasks('grunt-angular-templates');
88112

89113
grunt.registerTask('test', ['jshint', 'karma:unit']);
90-
grunt.registerTask('default', ['jshint:beforeConcat', 'concat', 'jshint:afterConcat', 'uglify']);
114+
grunt.registerTask('default', ['clean:dist','jshint:beforeConcat', 'ngtemplates', 'concat', 'jshint:afterConcat', 'uglify']);
91115
grunt.registerTask('livereload', ['default', 'watch']);
92116

93117
};

build/ng-s3upload.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ angular.module('ngS3upload',
2626
'ngS3upload.services',
2727
'ngSanitize'
2828
]);
29-
angular.module('ngS3upload.services', []).
29+
angular.module('ngS3upload.config', []).
30+
constant('ngS3Config', {
31+
theme: 'bootstrap2'
32+
});angular.module('ngS3upload.services', []).
3033
service('S3Uploader', ['$http', '$q', '$window', function ($http, $q, $window) {
3134
this.uploads = 0;
3235
var self = this;
@@ -139,7 +142,7 @@ angular.module('ngS3upload.services', []).
139142
};
140143
}]);
141144
angular.module('ngS3upload.directives', []).
142-
directive('s3Upload', ['$parse', 'S3Uploader', function ($parse, S3Uploader) {
145+
directive('s3Upload', ['$parse', 'S3Uploader', 'ngS3Config', function ($parse, S3Uploader, ngS3Config) {
143146
return {
144147
restrict: 'AC',
145148
require: '?ngModel',
@@ -249,14 +252,39 @@ angular.module('ngS3upload.directives', []).
249252
}
250253
};
251254
},
252-
template: '<div class="upload-wrap">' +
253-
'<button class="btn btn-primary" type="button"><span ng-if="!filename">Choose file</span><span ng-if="filename">Replace file</span></button>' +
254-
'<a ng-href="{{ filename }}" target="_blank" class="" ng-if="filename" > Stored file </a>' +
255-
'<div class="progress progress-striped" ng-class="{active: uploading}" ng-show="attempt" style="margin-top: 10px">' +
256-
'<div class="bar" style="width: {{ progress }}%;" ng-class="barClass()"></div>' +
257-
'</div>' +
258-
'<input type="file" style="display: none"/>' +
259-
'</div>'
255+
templateUrl: function(elm, attrs) {
256+
var theme = attrs.theme || ngS3Config.theme;
257+
return 'theme/' + theme + '.html';
258+
}
260259
};
261260
}]);
261+
angular.module('ngS3upload').run(['$templateCache', function($templateCache) {
262+
'use strict';
263+
264+
$templateCache.put('theme/bootstrap2.html',
265+
"<div class=\"upload-wrap\">\n" +
266+
" <button class=\"btn btn-primary\" type=\"button\"><span ng-if=\"!filename\">Choose file</span><span ng-if=\"filename\">Replace file</span></button>\n" +
267+
" <a ng-href=\"{{ filename }}\" target=\"_blank\" class=\"\" ng-if=\"filename\" > Stored file </a>\n" +
268+
" <div class=\"progress progress-striped\" ng-class=\"{active: uploading}\" ng-show=\"attempt\" style=\"margin-top: 10px\">\n" +
269+
" <div class=\"bar\" style=\"width: {{ progress }}%;\" ng-class=\"barClass()\"></div>\n" +
270+
" </div>\n" +
271+
" <input type=\"file\" style=\"display: none\"/>\n" +
272+
"</div>"
273+
);
274+
275+
276+
$templateCache.put('theme/bootstrap3.html',
277+
"<div class=\"upload-wrap\">\n" +
278+
" <button class=\"btn btn-primary\" type=\"button\"><span ng-if=\"!filename\">Choose file</span><span ng-if=\"filename\">Replace file</span></button>\n" +
279+
" <a ng-href=\"{{ filename }}\" target=\"_blank\" class=\"\" ng-if=\"filename\" > Stored file </a>\n" +
280+
" <div class=\"progress\">\n" +
281+
" <div class=\"progress-bar progress-bar-striped\" ng-class=\"{active: uploading}\" role=\"progressbar\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: {{ progress }}%; margin-top: 10px\" ng-class=\"barClass()\">\n" +
282+
" <span class=\"sr-only\">{{progress}}% Complete</span>\n" +
283+
" </div>\n" +
284+
" </div>\n" +
285+
" <input type=\"file\" style=\"display: none\"/>\n" +
286+
"</div>"
287+
);
288+
289+
}]);
262290
})(window, document);

build/ng-s3upload.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/upload.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
4+
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
55
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
66
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script>
77
<script src="../build/ng-s3upload.js"></script>

package.json

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
{
2-
"name": "ngs3upload",
3-
"version": "0.0.5",
4-
"dependencies": {},
5-
"devDependencies": {
6-
"grunt": "~0.4.1",
7-
"grunt-contrib-copy": "~0.4.1",
8-
"grunt-contrib-concat": "~0.3.0",
9-
"grunt-contrib-coffee": "~0.7.0",
10-
"grunt-contrib-uglify": "~0.2.0",
11-
"grunt-contrib-compass": "~0.3.0",
12-
"grunt-contrib-jshint": "~0.6.0",
13-
"grunt-contrib-cssmin": "~0.6.0",
14-
"grunt-contrib-connect": "~0.3.0",
15-
"grunt-contrib-clean": "~0.4.1",
16-
"grunt-contrib-htmlmin": "~0.1.3",
17-
"grunt-contrib-imagemin": "~0.1.4",
18-
"grunt-contrib-watch": "~0.4.0",
19-
"grunt-usemin": "~0.1.11",
20-
"grunt-svgmin": "~0.2.0",
21-
"grunt-rev": "~0.1.0",
22-
"grunt-karma": "~0.4.3",
23-
"grunt-open": "~0.2.0",
24-
"grunt-concurrent": "~0.3.0",
25-
"matchdep": "~0.1.2",
26-
"connect-livereload": "~0.2.0",
27-
"grunt-google-cdn": "~0.2.0",
28-
"grunt-ngmin": "~0.0.2",
29-
"karma": "~0.10",
30-
"karma-jasmine": "~0.1.0"
31-
},
32-
"engines": {
33-
"node": ">=0.8.0"
34-
}
2+
"name": "ngs3upload",
3+
"version": "0.0.5",
4+
"dependencies": {},
5+
"devDependencies": {
6+
"connect-livereload": "~0.2.0",
7+
"grunt": "~0.4.1",
8+
"grunt-angular-templates": "^0.5.7",
9+
"grunt-concurrent": "~0.3.0",
10+
"grunt-contrib-clean": "^0.6.0",
11+
"grunt-contrib-coffee": "~0.7.0",
12+
"grunt-contrib-compass": "~0.3.0",
13+
"grunt-contrib-concat": "~0.3.0",
14+
"grunt-contrib-connect": "~0.3.0",
15+
"grunt-contrib-copy": "~0.4.1",
16+
"grunt-contrib-cssmin": "~0.6.0",
17+
"grunt-contrib-htmlmin": "~0.1.3",
18+
"grunt-contrib-imagemin": "~0.1.4",
19+
"grunt-contrib-jshint": "~0.6.0",
20+
"grunt-contrib-uglify": "~0.2.0",
21+
"grunt-contrib-watch": "~0.4.0",
22+
"grunt-google-cdn": "~0.2.0",
23+
"grunt-karma": "~0.4.3",
24+
"grunt-ngmin": "~0.0.2",
25+
"grunt-open": "~0.2.0",
26+
"grunt-rev": "~0.1.0",
27+
"grunt-svgmin": "~0.2.0",
28+
"grunt-usemin": "~0.1.11",
29+
"karma": "~0.10",
30+
"karma-jasmine": "~0.1.0",
31+
"matchdep": "~0.1.2"
32+
},
33+
"engines": {
34+
"node": ">=0.8.0"
35+
}
3536
}

src/ng-s3upload/directives/s3-upload.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('ngS3upload.directives', []).
2-
directive('s3Upload', ['$parse', 'S3Uploader', function ($parse, S3Uploader) {
2+
directive('s3Upload', ['$parse', 'S3Uploader', 'ngS3Config', function ($parse, S3Uploader, ngS3Config) {
33
return {
44
restrict: 'AC',
55
require: '?ngModel',
@@ -109,13 +109,9 @@ angular.module('ngS3upload.directives', []).
109109
}
110110
};
111111
},
112-
template: '<div class="upload-wrap">' +
113-
'<button class="btn btn-primary" type="button"><span ng-if="!filename">Choose file</span><span ng-if="filename">Replace file</span></button>' +
114-
'<a ng-href="{{ filename }}" target="_blank" class="" ng-if="filename" > Stored file </a>' +
115-
'<div class="progress progress-striped" ng-class="{active: uploading}" ng-show="attempt" style="margin-top: 10px">' +
116-
'<div class="bar" style="width: {{ progress }}%;" ng-class="barClass()"></div>' +
117-
'</div>' +
118-
'<input type="file" style="display: none"/>' +
119-
'</div>'
112+
templateUrl: function(elm, attrs) {
113+
var theme = attrs.theme || ngS3Config.theme;
114+
return 'theme/' + theme + '.html';
115+
}
120116
};
121117
}]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
angular.module('ngS3upload.config', []).
2+
constant('ngS3Config', {
3+
theme: 'bootstrap2'
4+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="upload-wrap">
2+
<button class="btn btn-primary" type="button"><span ng-if="!filename">Choose file</span><span ng-if="filename">Replace file</span></button>
3+
<a ng-href="{{ filename }}" target="_blank" class="" ng-if="filename" > Stored file </a>
4+
<div class="progress progress-striped" ng-class="{active: uploading}" ng-show="attempt" style="margin-top: 10px">
5+
<div class="bar" style="width: {{ progress }}%;" ng-class="barClass()"></div>
6+
</div>
7+
<input type="file" style="display: none"/>
8+
</div>

0 commit comments

Comments
 (0)