mirror of
https://bitbucket.org/vertlach/iusethis.git
synced 2024-06-17 07:30:50 +03:00
JS and CSS fixes
This commit is contained in:
parent
a542bca15b
commit
459eb6c2a1
7
IUT.css
7
IUT.css
|
@ -3,8 +3,7 @@
|
|||
color: black;
|
||||
font-size: small;
|
||||
}
|
||||
.iut-box .count {
|
||||
}
|
||||
.iut-box .vote {
|
||||
font-weight: bold;
|
||||
.iut-vote-link,
|
||||
.iut-unvote-link {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
|
154
IUT.js
154
IUT.js
|
@ -11,94 +11,94 @@
|
|||
* @author Daniel A. R. Werner < daniel.a.r.werner@gmail.com >
|
||||
*/
|
||||
var IUT = function IUT() {
|
||||
this.clearRatingTimer = null;
|
||||
this.voted_new = [];
|
||||
this.id = 0;
|
||||
this.last_id = 0;
|
||||
this.imagePath = mw.config.get( 'wgExtensionAssetsPath' ) + '/VoteNY/images/';
|
||||
$.when( mw.loader.using( [ 'mediawiki.api.messages', 'mediawiki.jqueryMsg' ] ), $.ready ).then( function() {
|
||||
return new mw.Api().loadMessagesIfMissing( [
|
||||
'iusethis-unvote-link',
|
||||
'iusethis-link',
|
||||
'people-count'
|
||||
] );
|
||||
this.clearRatingTimer = null;
|
||||
this.voted_new = [];
|
||||
this.id = 0;
|
||||
this.last_id = 0;
|
||||
this.imagePath = mw.config.get( 'wgExtensionAssetsPath' ) + '/VoteNY/images/';
|
||||
$.when( mw.loader.using( [ 'mediawiki.api.messages', 'mediawiki.jqueryMsg' ] ), $.ready ).then( function() {
|
||||
return new mw.Api().loadMessagesIfMissing( [
|
||||
'iusethis-unvote-link',
|
||||
'iusethis-link',
|
||||
'people-count'
|
||||
] );
|
||||
})
|
||||
|
||||
/**
|
||||
* Called when voting through the green square voting box
|
||||
*
|
||||
* @param TheVote
|
||||
* @param PageID Integer: internal ID number of the current article
|
||||
*/
|
||||
this.clickVote = function( TheVote, PageID ) {
|
||||
( new mw.Api() ).postWithToken( 'edit', {
|
||||
action: 'iusethis',
|
||||
format: 'json',
|
||||
what: 'vote',
|
||||
pageId: PageID
|
||||
} ).done( function( data ) {
|
||||
$( '#iutcount' ).html( data.iusethis.result + ' ' + mw.msg('people-count') );
|
||||
$( '#iutaction' ).html(
|
||||
' <a href="javascript:void(0);" class="vote-unvote-link">' +
|
||||
mw.msg( 'iusethis-unvote-link' ) + '</a>'
|
||||
);
|
||||
} );
|
||||
};
|
||||
/**
|
||||
* Called when voting through the green square voting box
|
||||
*
|
||||
* @param TheVote
|
||||
* @param PageID Integer: internal ID number of the current article
|
||||
*/
|
||||
this.clickVote = function( TheVote, PageID ) {
|
||||
( new mw.Api() ).postWithToken( 'edit', {
|
||||
action: 'iusethis',
|
||||
format: 'json',
|
||||
what: 'vote',
|
||||
pageId: PageID
|
||||
} ).done( function( data ) {
|
||||
$( '#iutcount' ).html( data.iusethis.result + ' ' + mw.msg('people-count') );
|
||||
$( '#iutaction' ).html(
|
||||
' <a href="javascript:void(0);" class="vote-unvote-link">' +
|
||||
mw.msg( 'iusethis-unvote-link' ) + '</a>'
|
||||
);
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when removing your vote through the green square voting box
|
||||
*
|
||||
* @param PageID Integer: internal ID number of the current article
|
||||
*/
|
||||
this.unVote = function( PageID ) {
|
||||
( new mw.Api() ).postWithToken( 'edit', {
|
||||
action: 'iusethis',
|
||||
format: 'json',
|
||||
what: 'delete',
|
||||
pageId: PageID
|
||||
} ).done( function( data ) {
|
||||
$( '#iutcount' ).html( data.iusethis.result + ' ' + mw.msg('people-count') );
|
||||
$( '#iutaction' ).html(
|
||||
' <a href="javascript:void(0);" class="vote-vote-link">' +
|
||||
mw.msg( 'iusethis-link' ) + '</a>'
|
||||
);
|
||||
} );
|
||||
};
|
||||
/**
|
||||
* Called when removing your vote through the green square voting box
|
||||
*
|
||||
* @param PageID Integer: internal ID number of the current article
|
||||
*/
|
||||
this.unVote = function( PageID ) {
|
||||
( new mw.Api() ).postWithToken( 'edit', {
|
||||
action: 'iusethis',
|
||||
format: 'json',
|
||||
what: 'delete',
|
||||
pageId: PageID
|
||||
} ).done( function( data ) {
|
||||
$( '#iutcount' ).html( data.iusethis.result + ' ' + mw.msg('people-count') );
|
||||
$( '#iutaction' ).html(
|
||||
' <a href="javascript:void(0);" class="vote-vote-link">' +
|
||||
mw.msg( 'iusethis-link' ) + '</a>'
|
||||
);
|
||||
} );
|
||||
};
|
||||
|
||||
this.startClearRating = function( id, rating, voted ) {
|
||||
var voteNY = this;
|
||||
this.clearRatingTimer = setTimeout( function() {
|
||||
voteNY.clearRating( id, 0, rating, voted );
|
||||
}, 200 );
|
||||
};
|
||||
this.startClearRating = function( id, rating, voted ) {
|
||||
var voteNY = this;
|
||||
this.clearRatingTimer = setTimeout( function() {
|
||||
voteNY.clearRating( id, 0, rating, voted );
|
||||
}, 200 );
|
||||
};
|
||||
|
||||
this.clearRating = function( id, num, prev_rating, voted ) {
|
||||
if ( this.voted_new[id] ) {
|
||||
voted = this.voted_new[id];
|
||||
}
|
||||
};
|
||||
this.clearRating = function( id, num, prev_rating, voted ) {
|
||||
if ( this.voted_new[id] ) {
|
||||
voted = this.voted_new[id];
|
||||
}
|
||||
};
|
||||
|
||||
this.updateRating = function( id, num, prev_rating ) {
|
||||
if ( this.clearRatingTimer && this.last_id == id ) {
|
||||
clearTimeout( this.clearRatingTimer );
|
||||
}
|
||||
this.clearRating( id, num, prev_rating );
|
||||
this.last_id = id;
|
||||
};
|
||||
this.updateRating = function( id, num, prev_rating ) {
|
||||
if ( this.clearRatingTimer && this.last_id == id ) {
|
||||
clearTimeout( this.clearRatingTimer );
|
||||
}
|
||||
this.clearRating( id, num, prev_rating );
|
||||
this.last_id = id;
|
||||
};
|
||||
};
|
||||
|
||||
// TODO: Make event handlers part of a widget as described in the VoteNY's TODO and reduce this
|
||||
// code to instantiating such a widget for the current wiki page if required.
|
||||
$( function() {
|
||||
var vote = new IUT();
|
||||
var vote = new IUT();
|
||||
|
||||
// Green voting box's link
|
||||
$( '.iut-action' ).on( 'click', '> a', function( event ) {
|
||||
if ( $( this ).hasClass( 'vote-unvote-link' ) ) {
|
||||
vote.unVote( mw.config.get( 'wgArticleId' ) );
|
||||
} else {
|
||||
vote.clickVote( 1, mw.config.get( 'wgArticleId' ) );
|
||||
}
|
||||
} );
|
||||
// Green voting box's link
|
||||
$( '.iut-action' ).on( 'click', '> a', function( event ) {
|
||||
if ( $( this ).hasClass( 'vote-unvote-link' ) ) {
|
||||
vote.unVote( mw.config.get( 'wgArticleId' ) );
|
||||
} else {
|
||||
vote.clickVote( 1, mw.config.get( 'wgArticleId' ) );
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
||||
|
|
|
@ -179,10 +179,10 @@ class IUT {
|
|||
} else {
|
||||
if ( !wfReadOnly() ) {
|
||||
if ( $voted === false ) {
|
||||
$output .= '<a href="javascript:void(0);" class="vote-vote-link">' .
|
||||
$output .= '<a href="javascript:void(0);" class="iut-vote-link">' .
|
||||
wfMessage('iusethis-link')->parse() . '</a>';
|
||||
} else {
|
||||
$output .= '<a href="javascript:void(0);" class="vote-unvote-link">' .
|
||||
$output .= '<a href="javascript:void(0);" class="iut-unvote-link">' .
|
||||
wfMessage('iusethis-unvote-link')->parse() . '</a>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@
|
|||
"remoteExtPath": "IUT"
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.iusethis.scripts": {
|
||||
"ext.IUseThis.scripts": {
|
||||
"scripts": "IUT.js",
|
||||
"dependencies": [ "mediawiki.api" ],
|
||||
"position": "bottom"
|
||||
},
|
||||
"ext.iusethis.styles": {
|
||||
"ext.IUseThis.styles": {
|
||||
"styles": "IUT.css",
|
||||
"position": "top"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue