1
0
This repository has been archived on 2021-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
gallery3-contrib/3.1/modules/twitter/js/twitter.js

50 lines
1.3 KiB
JavaScript

/**
* @todo Add shorten/expand urls toggle button
*/
(function($) {
$.widget("ui.gallery_twitter", {
_init: function() {
var self = this;
this._set_count();
this.element.keyup(function(event) {
self._set_count(event.currentTarget);
return false;
});
},
_set_count: function() {
var self = this;
var character_array = $("#g-tweet").val().split("");
var count = character_array.length;
var remaining = self.options.max_count - count;
var count_container = $("#g-twitter-character-count");
var color = "#000000";
if (remaining < 10) {
color = self.options.error_color;
} else if (remaining < 20) {
color = self.options.warn_color;
}
if (remaining < 0) {
$("#g-dialog form :submit").addClass("ui-state-disabled")
.attr("disabled", "disabled");
} else {
$("#g-dialog form :submit").removeClass("ui-state-disabled")
.attr("disabled", null);
}
$(count_container).css("color", color);
$(count_container).html(remaining);
}
});
$.extend($.ui.gallery_twitter, {
defaults: {
max_count: 140,
warn_color: "#7F0005",
error_color: "#FF0000"
}
});
})(jQuery);