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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
$(document).ready(function() {
$( function () {
  // 클릭 이벤트 핸들러
'use strict';
  $('.mw-collapsible').click(function() {
var articleNamespaces, talkNamespaces, isArticleTab, limit;
    var content = $(this).find('.mw-collapsible-content');
    var currentHeight = content.height(); // 현재 높이
    var targetHeight = content[0].scrollHeight; // 실제 콘텐츠의 전체 높이
   
    // 표가 접혀 있으면 펼치고, 펼쳐져 있으면 접기
    if (currentHeight === 0) {
      // 펼칠 때: 애니메이션으로 높이 변경
      animateHeight(content, 0, targetHeight);
    } else {
      // 접을 때: 애니메이션으로 높이 변경
      animateHeight(content, currentHeight, 0);
    }
  });


  // 애니메이션 함수
articleNamespaces = $( '.live-recent' ).attr( 'data-article-ns' );
  function animateHeight(element, startHeight, endHeight) {
talkNamespaces = $( '.live-recent' ).attr( 'data-talk-ns' );
    var startTime = null;
isArticleTab = true;
    var duration = 500; // 애니메이션 지속 시간 (밀리초)
limit = $( '#live-recent-list' )[ 0 ].childElementCount;


    function step(timestamp) {
function timeFormat( timestamp ) {
      if (!startTime) startTime = timestamp;
var now = new Date();
      var progress = (timestamp - startTime) / duration;
var time = new Date( timestamp );
      if (progress < 1) {
var diffInSeconds = Math.floor((now - time) / 1000);
        var newHeight = startHeight + (endHeight - startHeight) * progress;
var diffInMinutes = Math.floor(diffInSeconds / 60);
        element.height(newHeight); // 새로운 높이 설정
var diffInHours = Math.floor(diffInMinutes / 60);
        requestAnimationFrame(step); // 계속 애니메이션 진행
var diffInDays = Math.floor(diffInHours / 24);
      } else {
        element.height(endHeight); // 마지막에 정확한 높이 설정
if (diffInSeconds < 60) {
      }
return diffInSeconds + '珥� ��';
    }
} else if (diffInMinutes < 60) {
    requestAnimationFrame(step); // 애니메이션 시작
return diffInMinutes + '遺� ��';
  }
} else if (diffInHours < 24) {
});
return diffInHours + '�쒓컙 ��';
} else {
return diffInDays + '�� ��';
}
}
function refreshLiveRecent() {
var getParameter;
 
if ( !$( '#live-recent-list' ).length || $( '#live-recent-list' ).is( ':hidden' ) ) {
return;
}
 
getParameter = {
action: 'query',
list: 'recentchanges',
rcprop: 'title|timestamp',
rcshow: '!bot|!redirect',
rctype: 'edit|new',
rclimit: limit,
format: 'json',
rcnamespace: isArticleTab ? articleNamespaces : talkNamespaces,
rctoponly: true
};
 
mw.loader.using( 'mediawiki.api' ).then( function () {
var api = new mw.Api();
api.get( getParameter ).then( function ( data ) {
var recentChanges, html, time, line, text;
recentChanges = data.query.recentchanges;
 
function cutTitle(title, maxLength) {
let length = 0;
let cutOffIndex = title.length;
for (let i = 0; i < title.length; i++) {
// �곸뼱 �뚰뙆踰녠낵 �レ옄, 怨듬갚�� 1濡� 移댁슫��, 洹� �몃� 2濡� 移댁슫��
length += title.charCodeAt(i) > 127 ? 2 : 1;
if (length > maxLength) {
cutOffIndex = i;
break;
}
}
// �꾩슂�� 寃쎌슦 "..."�� 異붽�
return title.length > cutOffIndex ? title.slice(0, cutOffIndex) + "..." : title;
}
// �댄썑, �� �⑥닔瑜� �ъ슜�� �쒕ぉ�� 泥섎━
html = recentChanges.map(function (item) {
time = new Date(item.timestamp);
// cutTitle �⑥닔瑜� �ъ슜�� �쒕ぉ 泥섎━
var title = cutTitle(item.title, 30);
// �쒕ぉ怨� �쒓컙�� <div>濡� 媛먯떥 媛곴컖 block �붿냼濡� 留뚮뱾�� 以꾨컮轅� �④낵瑜� 以띾땲��.
line = '<li>';
line += '<a class="recent-item" href="' + mw.util.getUrl(item.title) + '" title="' + item.title + '">';
line += '<div class="item-title">' + title + '</div>'; // �섏젙�� �쒕ぉ�� �ъ슜
line += '<div class="item-time">' + timeFormat(time) + '</div>'; // �쒓컙�� �꾪븳 <div>
line += '</a>';
line += '</li>';
return line;
}).join('\n');
$( '#live-recent-list' ).html( html );
} )
.catch( function () {} );
});
}
 
$( '#liberty-recent-tab1' ).click( function () {
$( this ).addClass( 'active' );
$( '#liberty-recent-tab2' ).removeClass( 'active' );
isArticleTab = true;
refreshLiveRecent();
} );
 
$( '#liberty-recent-tab2' ).click( function () {
$( this ).addClass( 'active' );
$( '#liberty-recent-tab1' ).removeClass( 'active' );
isArticleTab = false;
refreshLiveRecent();
} );
 
setInterval( refreshLiveRecent, 5 * 60 * 1000 );
refreshLiveRecent();
} );

2025년 1월 13일 (월) 16:22 판

 $( function () {
	'use strict';
	var articleNamespaces, talkNamespaces, isArticleTab, limit;

	articleNamespaces = $( '.live-recent' ).attr( 'data-article-ns' );
	talkNamespaces = $( '.live-recent' ).attr( 'data-talk-ns' );
	isArticleTab = true;
	limit = $( '#live-recent-list' )[ 0 ].childElementCount;

	function timeFormat( timestamp ) {
		var now = new Date();
		var time = new Date( timestamp );
		var diffInSeconds = Math.floor((now - time) / 1000);
		var diffInMinutes = Math.floor(diffInSeconds / 60);
		var diffInHours = Math.floor(diffInMinutes / 60);
		var diffInDays = Math.floor(diffInHours / 24);
	
		if (diffInSeconds < 60) {
			return diffInSeconds + '珥� ��';
		} else if (diffInMinutes < 60) {
			return diffInMinutes + '遺� ��';
		} else if (diffInHours < 24) {
			return diffInHours + '�쒓컙 ��';
		} else {
			return diffInDays + '�� ��';
		}
	}
	
	function refreshLiveRecent() {
		var getParameter;

		if ( !$( '#live-recent-list' ).length || $( '#live-recent-list' ).is( ':hidden' ) ) {
			return;
		}

		getParameter = {
			action: 'query',
			list: 'recentchanges',
			rcprop: 'title|timestamp',
			rcshow: '!bot|!redirect',
			rctype: 'edit|new',
			rclimit: limit,
			format: 'json',
			rcnamespace: isArticleTab ? articleNamespaces : talkNamespaces,
			rctoponly: true
		};

		mw.loader.using( 'mediawiki.api' ).then( function () {
			var api = new mw.Api();
			api.get( getParameter ).then( function ( data ) {
				var recentChanges, html, time, line, text;
				recentChanges = data.query.recentchanges;

				function cutTitle(title, maxLength) {
					let length = 0;
					let cutOffIndex = title.length;
				
					for (let i = 0; i < title.length; i++) {
						// �곸뼱 �뚰뙆踰녠낵 �レ옄, 怨듬갚�� 1濡� 移댁슫��, 洹� �몃� 2濡� 移댁슫��
						length += title.charCodeAt(i) > 127 ? 2 : 1;
				
						if (length > maxLength) {
							cutOffIndex = i;
							break;
						}
					}
				
					// �꾩슂�� 寃쎌슦 "..."�� 異붽�
					return title.length > cutOffIndex ? title.slice(0, cutOffIndex) + "..." : title;
				}
				
				// �댄썑, �� �⑥닔瑜� �ъ슜�� �쒕ぉ�� 泥섎━
				html = recentChanges.map(function (item) {
					time = new Date(item.timestamp);
					// cutTitle �⑥닔瑜� �ъ슜�� �쒕ぉ 泥섎━
					var title = cutTitle(item.title, 30);
					
					// �쒕ぉ怨� �쒓컙�� <div>濡� 媛먯떥 媛곴컖 block �붿냼濡� 留뚮뱾�� 以꾨컮轅� �④낵瑜� 以띾땲��.
					line = '<li>';
					line += '<a class="recent-item" href="' + mw.util.getUrl(item.title) + '" title="' + item.title + '">';
					line += '<div class="item-title">' + title + '</div>'; // �섏젙�� �쒕ぉ�� �ъ슜
					line += '<div class="item-time">' + timeFormat(time) + '</div>'; // �쒓컙�� �꾪븳 <div>
					line += '</a>';
					line += '</li>';
					return line;
				}).join('\n');
							
				
				$( '#live-recent-list' ).html( html );
			} )
			.catch( function () {} );
		});
	}

	$( '#liberty-recent-tab1' ).click( function () {
		$( this ).addClass( 'active' );
		$( '#liberty-recent-tab2' ).removeClass( 'active' );
		isArticleTab = true;
		refreshLiveRecent();
	} );

	$( '#liberty-recent-tab2' ).click( function () {
		$( this ).addClass( 'active' );
		$( '#liberty-recent-tab1' ).removeClass( 'active' );
		isArticleTab = false;
		refreshLiveRecent();
	} );

	setInterval( refreshLiveRecent, 5 * 60 * 1000 );
	refreshLiveRecent();
} );