Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4144175
FavoriteButton.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
FavoriteButton.js
View Options
const
FavoritesStore
=
require
(
'./FavoritesStore.js'
);
/**
* @class
* @extends OO.ui.ButtonInputWidget
*
* @constructor
* @param {Object} config Configuration options.
* @param {string} config.pageId The wiki page ID of the page to favorite/unfavorite. If `"-1"`
* then the button will be disabled.
* @param {FavoritesStore} config.favoritesStore The store to use.
*/
function
FavoriteButton
(
config
)
{
this
.
pageId
=
config
.
pageId
;
this
.
favoritesStore
=
config
.
favoritesStore
||
new
FavoritesStore
();
this
.
isFavorite
=
this
.
favoritesStore
.
isFavorite
(
this
.
pageId
);
const
label
=
mw
.
msg
(
this
.
isFavorite
?
'templatedata-favorite-remove'
:
'templatedata-favorite-add'
);
config
=
Object
.
assign
(
{
icon
:
this
.
isFavorite
?
'bookmark'
:
'bookmarkOutline'
,
framed
:
false
,
invisibleLabel
:
true
,
label
:
label
,
title
:
label
,
type
:
'button'
},
config
);
FavoriteButton
.
super
.
call
(
this
,
config
);
OO
.
ui
.
mixin
.
PendingElement
.
call
(
this
,
config
);
// Don't let temp and anon users favorite.
if
(
!
mw
.
user
.
isNamed
()
)
{
this
.
setDisabled
(
true
);
this
.
setTitle
(
mw
.
msg
(
'templatedata-favorite-disabled'
)
);
}
// Configure non-existing templates.
if
(
config
.
pageId
===
'-1'
)
{
this
.
setDisabled
(
true
);
this
.
setLabel
(
''
);
}
}
/* Setup */
OO
.
inheritClass
(
FavoriteButton
,
OO
.
ui
.
ButtonInputWidget
);
OO
.
mixinClass
(
FavoriteButton
,
OO
.
ui
.
mixin
.
PendingElement
);
/* Methods */
FavoriteButton
.
prototype
.
onClick
=
function
()
{
this
.
pushPending
();
if
(
!
this
.
isFavorite
)
{
// Add to favorites
this
.
favoritesStore
.
addFavorite
(
this
.
pageId
).
then
(
()
=>
{
this
.
setFavoriteState
(
true
);
this
.
popPending
();
},
()
=>
{
this
.
popPending
();
}
);
}
else
{
// Remove from favorites
this
.
favoritesStore
.
removeFavorite
(
this
.
pageId
).
then
(
()
=>
{
this
.
setFavoriteState
(
false
);
this
.
popPending
();
},
()
=>
{
this
.
popPending
();
}
);
}
};
/**
* Update the visible state of the button (icon, label, and title).
*
* @param {boolean} isFavorite The new state to set to.
*/
FavoriteButton
.
prototype
.
setFavoriteState
=
function
(
isFavorite
)
{
this
.
isFavorite
=
isFavorite
;
if
(
this
.
getIcon
()
)
{
this
.
setIcon
(
isFavorite
?
'bookmark'
:
'bookmarkOutline'
);
}
this
.
setLabel
(
isFavorite
?
mw
.
msg
(
'templatedata-favorite-remove'
)
:
mw
.
msg
(
'templatedata-favorite-add'
)
);
this
.
setTitle
(
this
.
getLabel
()
);
};
module
.
exports
=
FavoriteButton
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 19 2026, 17:07 (4 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0d/3a/4e1575d2a1c41b5259e9695d6124
Default Alt Text
FavoriteButton.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment