Skip to content

Commit

Permalink
Merge pull request #56 from Quji/master
Browse files Browse the repository at this point in the history
On load argument
  • Loading branch information
acornejo committed Feb 22, 2015
2 parents 20ee85a + 086e11f commit e8c91bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ api.
$('yourimage').cropbox({
width: 200,
height: 200
}, function() {
//on load
console.log('Url: ' + this.getDataURL());
}).on('cropbox', function(e, data) {
console.log('crop window: ' + data);
});
Expand Down Expand Up @@ -167,6 +170,12 @@ A reference to the cropbox object can be accessed like so:
var crop = $('yourimage').data('cropbox');
console.log(crop.result);
```
or inside the onload function:
```javascript
var crop = $('yourimage').cropbox({}, function() {
console.log(this.result);
});
```

You then have access to all the properties and methods used for that specific element.

Expand Down
8 changes: 5 additions & 3 deletions jquery.cropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
var pluginName = 'cropbox';

function factory($) {
function Crop($image, options) {
function Crop($image, options, on_load) {
this.width = null;
this.height = null;
this.img_width = null;
Expand All @@ -40,6 +40,7 @@
this.$image = $image;
this.$image.hide().prop('draggable', false).addClass('cropImage').wrap('<div class="cropFrame" />'); // wrap image in frame;
this.$frame = this.$image.parent();
this.on_load = on_load || function() {};
this.init();
}

Expand Down Expand Up @@ -149,6 +150,7 @@
else
self.zoom.call(self, self.minPercent);
self.$image.fadeIn('fast');
self.on_load.call(self);
};
// onload has to be set before src for IE8
// otherwise it never fires
Expand Down Expand Up @@ -251,12 +253,12 @@
},
};

$.fn[pluginName] = function(options) {
$.fn[pluginName] = function(options, on_load) {
return this.each(function() {
var $this = $(this), inst = $this.data(pluginName);
if (!inst) {
var opts = $.extend({}, $.fn[pluginName].defaultOptions, options);
$this.data(pluginName, new Crop($this, opts));
$this.data(pluginName, new Crop($this, opts, on_load));
} else if (options) {
$.extend(inst.options, options);
inst.updateOptions();
Expand Down

0 comments on commit e8c91bc

Please sign in to comment.