Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve new upload fetching and feedback #39

Open
wants to merge 1 commit into
base: feature/cropbutton-optimize
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = function (grunt)
uglify: {
options: {
preserveComments: false,
sourceMap: true,
beautify: true
sourceMap: false,
beautify: false
},
plugins: {
files: [
Expand Down
19 changes: 14 additions & 5 deletions js/app/models/model.attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
}, this);

this.on('change:differState', this.resetAjaxState, this);

// Trigger once to handle situation where no data is given after fetching
self.setDifferState();
},

/**
Expand All @@ -60,6 +63,8 @@
{
var self = this;

this.set('ajaxState', 'fetching');

this.fetch({
url: ajaxurl + '?action=get-focuspoint',
data: $.param({id: this.id}),
Expand All @@ -71,18 +76,22 @@
self.validateFocusPoint(data);

//Store focuspoint and use 'set' for to trigger events
self.set({'src': data.src});
self.set({'focusPointOrigin': data.focusPoint});
self.set({'focusPoint': data.focusPoint});
self.set({
'src': data.src,
'focusPointOrigin': data.focusPoint,
'focusPoint': data.focusPoint
});
} catch (error) {
console.log(error);
}
}
self.set('ajaxState', false);
},
error: function (collection, response, options)
{
// you can pass additional options to the event you trigger here as well
console.log(response);
self.set('ajaxState', false);
}
});
},
Expand Down Expand Up @@ -117,8 +126,8 @@
error: function (collection, response, options)
{
// you can pass additional options to the event you trigger here as well
self.set('ajaxState', 'failed');
console.log(response);
self.set('ajaxState', 'failed');
}
});
},
Expand Down Expand Up @@ -165,7 +174,7 @@
resetAjaxState: function ()
{
if (this.differState === true) {
self.model.set('ajaxState', false);
this.model.set('ajaxState', false);
}
},

Expand Down
3 changes: 2 additions & 1 deletion js/app/views/view.attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
//Trigger once on focusPointOrigin change, called straight after an ajax call
this.model.once("change:focusPoint", this.updateDimensions, this);
this.model.on("change:focusPointOrigin", this.updateDimensions, this);
this.model.on("change:ajaxState", this.updateDimensions, this);

// Trigger also on focusInterface activeState changes to minimum display errors
this.focusInterface.on('change:activeState',this.updateDimensions, this);
this.focusInterface.on('change:activeState', this.updateDimensions, this);
},

/**
Expand Down
12 changes: 11 additions & 1 deletion js/app/views/view.cropbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
this.model.on('change:text', this.render, this);

// Update button
this.render();
this.ajaxStateHandler().differStateHandler().render();
},

render: function ()
Expand All @@ -41,6 +41,8 @@
this.$cropButton.toggleClass(IFA.css.button._disabled, disableState);
this.$cropButton.toggleClass(IFA.css.button._primary, highlightState);
this.$cropButton.text(text);

return this;
},

differStateHandler: function ()
Expand All @@ -53,6 +55,8 @@
} else {
this.disable();
}

return this;
},

ajaxStateHandler: function ()
Expand All @@ -68,13 +72,19 @@
this.model.set('text', focusPointL10n.cropButtonSuccess);
this.disable();
break;
case 'fetching':
this.model.set('text', focusPointL10n.cropButtonFetching);
this.disable();
break;
case 'failed':
this.model.set('text', focusPointL10n.cropButtonFailed);
this.activate();
break;
default:
this.model.set('text', focusPointL10n.cropButton);
}

return this;
},

highlight: function ()
Expand Down
4 changes: 4 additions & 0 deletions js/app/views/view.focusinterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
this.attachment.once('change:focusPoint', this.updateDimensionData, this);
this.attachment.once('change:focusPoint', this.updateFocusPoint, this);

// Avoid calculation errors when no data is given by triggering updateDimensionData on ajaxState changes
this.attachment.on('change:ajaxState', this.updateDimensionData, this);

// Set events for states
this.setStateEvent('hoverState','is-hover');
this.setStateEvent('activeState','is-active');
Expand Down Expand Up @@ -298,6 +301,7 @@
});

var focusPoint = this.attachment.get('focusPoint');

// Write position based on the calculation position of focuspoint of the attachment
var position = {
x: (focusPoint.x / 100) * this.attachment.get('width'),
Expand Down
58 changes: 31 additions & 27 deletions js/focuspoint.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading