미디어위키:Liberty.js: 두 판 사이의 차이

편집 요약 없음
태그: 수동 되돌리기 되돌려진 기여
편집 요약 없음
태그: 되돌려진 기여
1번째 줄: 1번째 줄:
$( function () {
$( function () {
'use strict';
'use strict';
var articleNamespaces, talkNamespaces, isArticleTab, limit;


articleNamespaces = $( '.live-recent' ).attr( 'data-article-ns' );
/* Dropdown fade in */
talkNamespaces = $( '.live-recent' ).attr( 'data-talk-ns' );
$( '.dropdown' ).on( 'show.bs.dropdown', function () {
isArticleTab = true;
$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
limit = $( '#live-recent-list' )[ 0 ].childElementCount;
} );


function formatTimeAgo(time) {
$( '.dropdown' ).on( 'hide.bs.dropdown', function () {
var now = new Date();
$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
var diff = now.getTime() - time.getTime();
} );
var seconds = Math.floor(diff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var weeks = Math.floor(days / 7);
var months = Math.floor(days / 30);
var years = Math.floor(days / 365);
if (years > 0) {
return years + "년 전";
} else if (months > 0) {
return months + "개월 전";
} else if (weeks > 0) {
return weeks + "주 전";
} else if (days > 0) {
return days + "일 전";
} else if (hours > 0) {
return hours + "시간 전";
} else if (minutes > 0) {
return minutes + "분 전";
} else {
return seconds + "초 전";
}
}


function refreshLiveRecent() {
$( '.btn-group' ).on( 'show.bs.dropdown', function () {
var getParameter;
$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
} );


if ( !$( '#live-recent-list' ).length || $( '#live-recent-list' ).is( ':hidden' ) ) {
$( '.btn-group' ).on( 'hide.bs.dropdown', function () {
return;
$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
}
} );
/* Dropdown fade in End */


getParameter = {
/* Modal Focus */
action: 'query',
$( '#login-modal' ).on( 'shown.bs.modal', function () {
list: 'recentchanges',
$( '#wpName1' ).focus();
rcprop: 'title|timestamp',
} );
rcshow: '!bot|!redirect',
/* Modal Focus End */
rctype: 'edit|new',
} );
rclimit: limit,
format: 'json',
rcnamespace: isArticleTab ? articleNamespaces : talkNamespaces,
rctoponly: true
};


mw.loader.using( 'mediawiki.api' ).then( function () {
/* Sub menu */
var api = new mw.Api();
$( function () {
api.get( getParameter ).then( function ( data ) {
var display;
var recentChanges, html, time, line, text;
recentChanges = data.query.recentchanges;
html = recentChanges.map( function ( item ) {
time = new Date( item.timestamp );
line = '<li class="flex justify-between"><a class="recent-item w-full flex items-center" href="' + mw.util.getUrl( item.title ) + '" title="' + item.title + '"><span class="flex-1 text-ellipsis text-nowrap overflow-hidden">';
text = '';
if ( item.type === 'new' ) {
line = line.replace('<span class="flex-1 text-ellipsis text-nowrap overflow-hidden">','<div class="flex justify-center items-center mr-1 w-3 h-3 bg-red-500 rounded-2xl text-[0.5rem] text-white font-black">N</div><span class="flex-1 text-ellipsis text-nowrap overflow-hidden">');
}
text += item.title;
if ( text.length > 9999 ) {
text = text.substr( 0, 9999 );
text += '...';
}
line += text;
line += '</span><time class="ml-4 recent-item-timestamp">' + formatTimeAgo(time) + '</time></a></li>';
return line;
} ).join( '\n' );
$( '#live-recent-list' ).html( html );
} )
.catch( function () {} );
});
}


$( '#liberty-recent-tab1' ).click( function () {
$( '.dropdown-toggle-sub' ).on( 'click', function ( element ) {
$( this ).addClass( 'active' );
display = $( this ).next( 'div.dropdown-menu' );
$( '#liberty-recent-tab2' ).removeClass( 'active' );
display.toggle();
isArticleTab = true;
element.stopPropagation();
refreshLiveRecent();
element.preventDefault();
} );
} );


$( '#liberty-recent-tab2' ).click( function () {
$( 'html' ).on( 'click', function () {
$( this ).addClass( 'active' );
if ( display !== undefined ) {
$( '#liberty-recent-tab1' ).removeClass( 'active' );
display.hide();
isArticleTab = false;
}
refreshLiveRecent();
} );
} );
setInterval( refreshLiveRecent, 5 * 60 * 1000 );
refreshLiveRecent();
} );
} );
/* Sub menu end */

2025년 2월 22일 (토) 07:06 판

$( function () {
	'use strict';

	/* Dropdown fade in */
	$( '.dropdown' ).on( 'show.bs.dropdown', function () {
		$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
	} );

	$( '.dropdown' ).on( 'hide.bs.dropdown', function () {
		$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
	} );

	$( '.btn-group' ).on( 'show.bs.dropdown', function () {
		$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
	} );

	$( '.btn-group' ).on( 'hide.bs.dropdown', function () {
		$( this ).find( '.dropdown-menu' ).first().stop( true, true ).fadeToggle( 200 );
	} );
	/* Dropdown fade in End */

	/* Modal Focus */
	$( '#login-modal' ).on( 'shown.bs.modal', function () {
		$( '#wpName1' ).focus();
	} );
	/* Modal Focus End */
} );

/* Sub menu */
$( function () {
	var display;

	$( '.dropdown-toggle-sub' ).on( 'click', function ( element ) {
		display = $( this ).next( 'div.dropdown-menu' );
		display.toggle();
		element.stopPropagation();
		element.preventDefault();
	} );

	$( 'html' ).on( 'click', function () {
		if ( display !== undefined ) {
			display.hide();
		}
	} );
} );
/* Sub menu end */