Skip to content

Commit 7ed9b93

Browse files
committed
Merge branch 'feature/new-js'
2 parents 81d241b + 40a2b72 commit 7ed9b93

28 files changed

+916
-137
lines changed

.gitignore

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
config.js
7+
8+
# Coverage directory used by tools like istanbul
9+
coverage
10+
11+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
12+
.grunt
13+
14+
# Dependency directory
15+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
116
node_modules
217
bower_components
3-
config.js
4-
*.log
18+
doc/
19+
build/
20+
21+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
22+
*.iml
23+
24+
## Directory-based project format:
25+
.idea/

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
"dependencies": {
3030
"angular": ">=1.3.10",
31-
"cloudinary_js": ">=1.0.17"
31+
"cloudinary-core": "^2.0.4"
3232
},
3333
"repository": {
3434
"type": "git",

js/angular.cloudinary.js

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,48 @@
33
if (typeof define === 'function' && define.amd) {
44
// Register as an anonymous AMD module:
55
define([
6-
'jquery.cloudinary',
6+
'cloudinary',
77
'angular'
88
], factory);
99
} else {
1010
// Browser globals:
11-
factory(window.jQuery, angular);
11+
factory(cloudinary, angular);
1212
}
13-
}(function ($, angular) {
13+
})(function (cloudinary, angular) {
1414

15-
var angularModule = angular.module('cloudinary', []);
15+
var cloudinaryModule = angular.module('cloudinary', []);
1616

1717
var cloudinaryAttr = function(attr){
1818
if (attr.match(/cl[A-Z]/)) attr = attr.substring(2);
1919
return attr.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
2020
};
2121

22+
/**
23+
* Returns an array of attributes for cloudinary.
24+
* @function toCloudinaryAttributes
25+
* @param {Object} source - an object containing attributes
26+
* @param {(RegExp|string)} [filter] - copy only attributes whose name matches the filter
27+
* @return {Object} attributes for cloudinary functions
28+
*/
29+
var toCloudinaryAttributes = function( source, filter) {
30+
var attributes = {};
31+
var isNamedNodeMap = source && (source.constructor.name === "NamedNodeMap" || source instanceof NamedNodeMap);
32+
angular.forEach(source, function(value, name){
33+
if( isNamedNodeMap) {
34+
name = value.name;
35+
value = value.value;
36+
}
37+
if (!filter || filter.exec(name)) {
38+
attributes[cloudinaryAttr(name)] = value;
39+
}
40+
});
41+
return attributes;
42+
};
2243

2344
['Src', 'Srcset', 'Href'].forEach(function(attrName) {
2445
var normalized = 'cl' + attrName;
2546
attrName = attrName.toLowerCase();
26-
angularModule.directive(normalized, ['$sniffer', function($sniffer) {
47+
cloudinaryModule.directive(normalized, ['$sniffer', 'cloudinary', function($sniffer, cloudinary) {
2748
return {
2849
priority: 99, // it needs to run after the attributes are interpolated
2950
link: function(scope, element, attr) {
@@ -41,9 +62,7 @@
4162
if (!value)
4263
return;
4364

44-
var attributes = {};
45-
$.each(element[0].attributes, function(){attributes[cloudinaryAttr(this.name)] = this.value});
46-
value = $.cloudinary.url(value, attributes);
65+
value = cloudinary.url(value, toCloudinaryAttributes(element[0].attributes));
4766
attr.$set(name, value);
4867

4968
// on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
@@ -57,24 +76,18 @@
5776
}]);
5877
});
5978

60-
angularModule.directive('clTransformation', [function() {
79+
cloudinaryModule.directive('clTransformation', [function() {
6180
return {
6281
restrict : 'E',
6382
transclude : false,
6483
require: '^clImage',
6584
link : function (scope, element, attrs, clImageCtrl) {
66-
var attributes = {};
67-
$.each(attrs, function(name,value){
68-
if (name[0] !== '$') {
69-
attributes[cloudinaryAttr(name)] = value;
70-
}
71-
});
72-
clImageCtrl.addTransformation(attributes);
85+
clImageCtrl.addTransformation(toCloudinaryAttributes(attrs, /^[^$]/));
7386
}
7487
}
7588
}]);
7689

77-
angularModule.directive('clImage', [function() {
90+
cloudinaryModule.directive('clImage', ['cloudinary', function(cloudinary) {
7891
var Controller = function($scope) {
7992
this.addTransformation = function(ts) {
8093
$scope.transformations = $scope.transformations || [];
@@ -92,11 +105,9 @@
92105
controller: Controller,
93106
// The linking function will add behavior to the template
94107
link : function(scope, element, attrs) {
95-
var attributes = {};
108+
var attributes = toCloudinaryAttributes(attrs);
96109
var publicId = null;
97110

98-
$.each(attrs, function(name, value){attributes[cloudinaryAttr(name)] = value});
99-
100111
if (scope.transformations) {
101112
attributes.transformation = scope.transformations;
102113
}
@@ -127,11 +138,31 @@
127138
}
128139

129140
var loadImage = function() {
130-
var url = $.cloudinary.url(publicId, attributes);
141+
var url = cloudinary.url(publicId, attributes);
131142
element.attr('src', url);
132143
}
133144

134145
}
135146
};
136147
}]);
137-
}));
148+
149+
cloudinaryModule.provider( 'cloudinary', function(){
150+
var configuration = new cloudinary.Configuration();
151+
this.set = function(name, value){
152+
configuration.set(name, value);
153+
return this;
154+
};
155+
this.get = function(name){
156+
return configuration.get(name);
157+
};
158+
this.$get = [function cloudinaryFactory(){
159+
if(cloudinary.CloudinaryJQuery && jQuery) {
160+
// cloudinary is attached to the global `jQuery` object
161+
jQuery.cloudinary.config(configuration.config());
162+
return jQuery.cloudinary;
163+
} else {
164+
return new cloudinary.Cloudinary(configuration.config());
165+
}
166+
}]
167+
});
168+
});

karma.conf.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = function (config) {
2+
return config.set({
3+
basePath: '',
4+
frameworks: ['jasmine'],
5+
files: [
6+
'bower_components/lodash/lodash.js',
7+
'bower_components/angular/angular.js',
8+
'bower_components/angular-mocks/angular-mocks.js',
9+
'bower_components/cloudinary-core/cloudinary-core.js',
10+
'js/angular.cloudinary.js',
11+
'spec/cloudinary_spec.js'],
12+
preprocessors: {
13+
},
14+
reporters: ['story'],
15+
port: 9876,
16+
colors: true,
17+
logLevel: config.LOG_DEBUG,
18+
autoWatch: false,
19+
//browsers: ['Chrome', 'Firefox', 'Safari'],
20+
browsers: ['PhantomJS', "Chrome"],
21+
//browsers: ['Chrome'],
22+
singleRun: true,
23+
plugins: [
24+
'karma-jasmine',
25+
'karma-coverage',
26+
'karma-story-reporter',
27+
'karma-chrome-launcher',
28+
'karma-phantomjs-launcher'
29+
]
30+
});
31+
};
32+

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "cloudinary_ng",
3+
"version": "0.1.4",
4+
"description": "A set of AngularJS directives/helpers for using Cloudinary with AngularJS",
5+
"main": "js/angular.cloudinary.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git://github.com/cloudinary/cloudinary_angular.git"
15+
},
16+
"author": "Cloudinary",
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/cloudinary/cloudinary_angular/issues"
20+
},
21+
"homepage": "https://github.com/cloudinary/cloudinary_angular",
22+
"devDependencies": {
23+
"coffee-script": "~1.10",
24+
"grunt": "~0.4",
25+
"grunt-karma": "~0.12",
26+
"grunt-version": "~1.0",
27+
"jasmine-core": "~2.4",
28+
"karma": "~0.13",
29+
"karma-chrome-launcher": "^0.2.2",
30+
"karma-coverage": "~0.5",
31+
"karma-jasmine": "~0.3",
32+
"karma-phantomjs-launcher": "~0.2",
33+
"karma-story-reporter": "~0.3",
34+
"phantomjs": "~1.9"
35+
}
36+
}

samples/photo_album/app/index.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010
<link rel="stylesheet" href="css/app.css">
1111
<link rel="stylesheet" href="css/animations.css">
1212

13-
<script src="../bower_components/jquery/dist/jquery.js"></script>
14-
<!-- jquery file upload related. only needed if jquery file upload is used -->
15-
<script src="../bower_components/blueimp-file-upload/js/vendor/jquery.ui.widget.js"></script>
16-
<script src="../bower_components/blueimp-file-upload/js/jquery.iframe-transport.js"></script>
17-
<script src="../bower_components/blueimp-file-upload/js/jquery.fileupload.js"></script>
18-
<!-- end jquery file upload related -->
19-
<script src="../bower_components/cloudinary_js/js/jquery.cloudinary.js"></script>
13+
<script src="../bower_components/lodash/lodash.js"></script>
14+
<script src="../bower_components/cloudinary-core/cloudinary-core.js"></script>
2015
<!-- angular file upload -->
2116
<script src="../bower_components/ng-file-upload/ng-file-upload-shim.js"></script>
2217
<!-- angular dependencies -->

samples/photo_album/app/js/app.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,26 @@ var photoAlbumApp = angular.module('photoAlbumApp', [
1010
]);
1111

1212
photoAlbumApp.config(['$routeProvider',
13-
function($routeProvider) {
14-
$routeProvider.
15-
when('/photos', {
16-
templateUrl: 'partials/photo-list.html',
17-
resolve: {
18-
photoList: function($q, $rootScope, album) {
19-
if (!$rootScope.serviceCalled) {
20-
return album.photos({}, function(v){
21-
$rootScope.serviceCalled = true;
22-
$rootScope.photos = v.resources;
23-
});
24-
} else {
25-
return $q.when(true);
26-
}
13+
function ($routeProvider) {
14+
$routeProvider.when('/photos', {
15+
templateUrl: 'partials/photo-list.html',
16+
resolve: {
17+
photoList: function ($q, $rootScope, album) {
18+
if (!$rootScope.serviceCalled) {
19+
return album.photos({}, function (v) {
20+
$rootScope.serviceCalled = true;
21+
$rootScope.photos = v.resources;
22+
});
23+
} else {
24+
return $q.when(true);
2725
}
2826
}
29-
}).
30-
when('/photos/new', {
31-
templateUrl: 'partials/photo-upload.html',
32-
controller: 'photoUploadCtrl'
33-
}).
34-
when('/photos/new_jquery', {
35-
templateUrl: 'partials/photo-upload-jquery.html',
36-
controller: 'photoUploadCtrlJQuery'
37-
}).
38-
otherwise({
39-
redirectTo: '/photos'
40-
});
27+
}
28+
}).when('/photos/new', {
29+
templateUrl: 'partials/photo-upload.html',
30+
controller: 'photoUploadCtrl'
31+
}).otherwise({
32+
redirectTo: '/photos'
33+
});
4134
}]);
4235

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
$.cloudinary.config().cloud_name = 'XXXXXXXXX';
2-
$.cloudinary.config().upload_preset = 'YYYYYYYY';
1+
photoAlbumApp.config(['cloudinaryProvider', function (cloudinaryProvider) {
2+
cloudinaryProvider
3+
.set("cloud_name", "CCCCCCC")
4+
.set("upload_preset", "UUUUUUUU");
5+
}]);

0 commit comments

Comments
 (0)