RAN1 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/68613
Change subject: Remove unnecessary closure from JS module
......................................................................
Remove unnecessary closure from JS module
As it so turns out, ResourceLoader already provides closures for JavaScript
modules, eliminating the
need for a closure since one is already provided. Therefore, the self-invoked
function code has been
removed, with the enclosed code unchanged. A note has been added in the JS file
to explain this to
prevent future goof-ups.
Change-Id: I45b4a110defd9b102adcadbae1215c25e450facf
---
M js/ext.CommunityTwitter.updatecount.js
1 file changed, 25 insertions(+), 24 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommunityTwitter
refs/changes/13/68613/1
diff --git a/js/ext.CommunityTwitter.updatecount.js
b/js/ext.CommunityTwitter.updatecount.js
index 588c31e..5c3d795 100644
--- a/js/ext.CommunityTwitter.updatecount.js
+++ b/js/ext.CommunityTwitter.updatecount.js
@@ -1,37 +1,38 @@
/**
- * A simple self-invoked function that updates the characters remaining count
for tweeters so that they
- * don't end up going over the 140-character limit. Adds some colors to grab
the user's attention too.
+ * A simple function that updates the characters remaining count for tweeters
so that they don't
+ * end up going over the 140-character limit. Adds some colors to grab the
user's attention too.
*
* Notes for the gets: 'status_update_form' refers to the form element that
contains all relevant
* elements for updating the Twitter status, the textarea element is the
textbox for inputting the status
* update, the strong element encloses the "number of characters remaining"
output (140 by default),
* and the input element is the "Tweet" button.
+ *
+ * Notes about scope: ResourceLoader already provides a closure for JavaScript
modules, so the variables
+ * which are defined below are not actually in the global scope. There is no
need to rewrite them in
+ * a closure to keep them outside of the global scope.
**/
-(function() {
+// get the text box, count output, and tweet button via DOM and store as
variables
- // get the text box, count output, and tweet button via DOM and store
as variables
+var ctStatusForm = document.getElementById( 'status_update_form' );
+var ctStatusTextarea = ctStatusForm.getElementsByTagName( 'textarea' )[0];
+var ctCountOutput = ctStatusForm.getElementsByTagName( 'strong' )[0];
+var ctTweetButton = ctStatusForm.getElementsByTagName( 'input' )[0];
+ctStatusTextarea.onkeyup = function () {
+ var ctCharsLeft = 140 - ctStatusTextarea.value.length; // get the
number of characters left from the text box
- var ctStatusForm = document.getElementById('status_update_form');
- var ctStatusTextarea = ctStatusForm.getElementsByTagName('textarea')[0];
- var ctCountOutput = ctStatusForm.getElementsByTagName('strong')[0];
- var ctTweetButton = ctStatusForm.getElementsByTagName('input')[0];
- ctStatusTextarea.onkeyup = function () {
- var ctCharsLeft = 140 - ctStatusTextarea.value.length; // get
the number of characters left from the text box
+ // using the number of chars, change count output color and
disable/enable tweet button as needed
- // using the number of chars, change count output color and
disable/enable tweet button as needed
-
- if ( ctCharsLeft < 0 ) {
- ctCountOutput.style.color = 'red'; // red means bad
- ctTweetButton.setAttribute( 'disabled', 'disabled' );
// disables Tweet button
+ if ( ctCharsLeft < 0 ) {
+ ctCountOutput.style.color = 'red'; // red means bad
+ ctTweetButton.setAttribute( 'disabled', 'disabled' ); //
disables Tweet button
+ } else {
+ ctTweetButton.removeAttribute( 'disabled' ); // enables Tweet
button
+ if ( ctCharsLeft < 25 ) {
+ ctCountOutput.style.color = '#CC0'; // yellow
} else {
- ctTweetButton.removeAttribute( 'disabled' ); // enables
Tweet button
- if ( ctCharsLeft < 25 ) {
- ctCountOutput.style.color = '#CC0'; // yellow
- } else {
- ctCountOutput.style.color = 'inherit'; //
default
- }
+ ctCountOutput.style.color = 'inherit'; // default
}
- ctCountOutput.innerHTML = ctCharsLeft; // output the count
- };
-})();
+ }
+ ctCountOutput.innerHTML = ctCharsLeft; // output the count
+};
--
To view, visit https://gerrit.wikimedia.org/r/68613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45b4a110defd9b102adcadbae1215c25e450facf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommunityTwitter
Gerrit-Branch: master
Gerrit-Owner: RAN1 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits