forceUpdate option.

master
Artem Sapegin 2014-02-12 16:22:04 +04:00
parent bd2f6f9a83
commit 82594924a5
2 changed files with 17 additions and 4 deletions

View File

@ -174,6 +174,16 @@ $('#share2').socialLikes({
});
```
### Refreshing counters
By default counters for any uniqe URL requested only once. You can force new request with `forceUpdate` option:
```javascript
$('#share2').socialLikes({
forceUpdate: true
});
```
### Events

View File

@ -145,7 +145,7 @@ var counters = {
if (!counters.promises[service]) counters.promises[service] = {};
var servicePromises = counters.promises[service];
if (servicePromises[url]) {
if (!extraOptions.forceUpdate && servicePromises[url]) {
return servicePromises[url];
}
else {
@ -292,7 +292,7 @@ SocialLikes.prototype = {
this.widget = widget;
},
update: function(options) {
if (options.url === this.options.url) return;
if (!options.forceUpdate && options.url === this.options.url) return;
// Reset counters
this.number = 0;
@ -353,7 +353,7 @@ Button.prototype = {
},
update: function(options) {
$.extend(this.options, options);
$.extend(this.options, {forceUpdate: false}, options);
this.widget.find('.' + prefix + '__counter').remove(); // Remove old counter
this.initCounter();
},
@ -442,7 +442,10 @@ Button.prototype = {
this.updateCounter(this.options.counterNumber);
}
else {
var extraOptions = this.options.counterUrl ? { counterUrl: this.options.counterUrl } : {};
var extraOptions = {
counterUrl: this.options.counterUrl,
forceUpdate: this.options.forceUpdate
};
counters.fetch(this.service, this.options.url, extraOptions)
.always($.proxy(this.updateCounter, this));
}