Skip to content

Commit

Permalink
AMD support
Browse files Browse the repository at this point in the history
  • Loading branch information
TalLevAmi committed Mar 2, 2014
1 parent cfc39eb commit e3d4ae3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Optional:

To set these configuration parameters use the `$.cloudinary.config` function (see below)

Note:

If jquery.cloudinary is loaded as an AMD, you need to initialize the Cloudinary fileupload fields e.g., by calling `$("input.cloudinary-fileupload[type=file]").cloudinary_fileupload();`

## Usage ######################################################################

The following blog post details the process of setting up jQuery based file upload.
Expand Down
36 changes: 24 additions & 12 deletions js/jquery.cloudinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@
* see https://github.com/cloudinary/cloudinary_js
*/

(function( $ ) {
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'jquery.ui.widget',
'jquery.iframe-transport',
'jquery.fileupload',
], factory);
} else {
// Browser globals:
var $ = window.jQuery;
factory($);
$(function() {
$("input.cloudinary-fileupload[type=file]").cloudinary_fileupload();
});
}
}(function ($) {
'use strict';
var CF_SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net";
var OLD_AKAMAI_SHARED_CDN = "cloudinary-a.akamaihd.net";
var AKAMAI_SHARED_CDN = "res.cloudinary.com";
Expand Down Expand Up @@ -243,7 +262,7 @@
prefix += secure_distribution;
} else {
var subdomain = cdn_subdomain ? "a" + ((crc32(public_id) % 5) + 1) + "." : "";
host = cname || (private_cdn ? cloud_name + "-res.cloudinary.com" : "res.cloudinary.com" );
var host = cname || (private_cdn ? cloud_name + "-res.cloudinary.com" : "res.cloudinary.com" );
prefix += subdomain + host;
}
if (shared_domain) prefix += "/" + cloud_name;
Expand Down Expand Up @@ -355,13 +374,10 @@
$(that).cloudinary(options);
});
});
}
};
$.fn.fetchify = function(options) {
return this.cloudinary($.extend(options, {'type': 'fetch'}));
};
})( jQuery );

(function( $ ) {
if (!$.fn.fileupload) {
return;
}
Expand Down Expand Up @@ -423,9 +439,5 @@
this.fileupload('option', 'formData').file = remote_url;
this.fileupload('add', { files: [ remote_url ] });
delete(this.fileupload('option', 'formData').file);
}

$(function() {
$("input.cloudinary-fileupload[type=file]").cloudinary_fileupload();
});
})( jQuery );
}
}));

0 comments on commit e3d4ae3

Please sign in to comment.