사용자:Senior9324/common.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
64번째 줄: 64번째 줄:
     }
     }
}
}
var temp = {}, maps = {};
maps.mainMap = {
"own": "직접 만든 저작물입니다.",
"other": "타인이 만든 저작물입니다."
};
maps.ownMap = {
"cc-by-3.0": "CC BY 3.0으로 배포합니다.",
"cc-by-sa-3.0": "CC BY-SA 3.0으로 배포합니다",
"cc-0": "CC0 1.0 퍼블릭 도메인으로 배포합니다.",
"PD-self": "저작권을 포기하여 퍼블릭 도메인으로 배포합니다."
};
maps.otherMap = {
"conditions": {
"border1": "---비자유 저작물---",
"퍼옴": "독점적 저작권이 있는 비자유 저작물을 가져왔습니다.",
"border2": "---크리에이티브 커먼즈 라이선스---",
"by": "저작자표시",
"by-sa": "저작자표시-동일조건변경허락",
"by-nd": "저작자표시-변경금지",
"by-nc": "저작자표시-비영리",
"by-nc-sa": "저작자표시-비영리-동일조건변경허락",
"by-nc-nd": "저작자표시-비영리-변경금지",
"border3": "---기타 라이선스---",
"공공누리 제1유형": "공공누리 제1유형: 출처표시",
"정보공유라이선스 허용": "정보공유라이선스 2.0: 허용",
"border4": "---퍼블릭 도메인---",
"cc-0": "CC0 1.0 퍼블릭 도메인",
"PD-author": "타인에 의해 퍼블릭 도메인으로 배포됨",
"PD-old": "저작권 보호기간이 만료되어 저작권이 소멸됨",
"PD-ineligible": "보호에 부적격하므로 저작물이 아닙니다."
},
"versions": {
"2.0": "2.0 일반",
"2.0-kr": "2.0 대한민국",
"2.5": "2.5 일반",
"3.0": "3.0 Unported",
"4.0": "4.0 국제"
}
};
function makeDropdown(map) {
var dropdown = $("<select>");
dropdown.append('<option value="">기본값</option>');
for (var i in map) {
if (map.hasOwnProperty(i)) {
if (i.indexOf("border") > -1) {
dropdown.append($("<option>").prop("disabled", true).attr("value", "").css("color", "gray").text(map[i]));
} else {
dropdown.append($("<option>").attr("value", i).text(map[i]));
}
}
}
return dropdown;
}
function LicenseDropdown() {
var licenseElem = $("<input>").attr("id", "wpLicense").attr("type", "hidden").attr("name", "wpLicense");
$("#wpLicense").replaceWith(licenseElem);
var firstLevelDropdown = makeDropdown(maps.mainMap);
var licenseDropdown, versionDropdown, authorText;
firstLevelDropdown.change(function() {
switch (firstLevelDropdown.val()) {
case "own":
licenseElem.val("");
if (licenseDropdown) {
licenseDropdown.remove();
if (versionDropdown) {
versionDropdown.remove();
}
}
licenseDropdown = makeDropdown(maps.ownMap);
licenseDropdown.change(function() {
if (!licenseDropdown.val()) {
licenseElem.val("");
return;
}
licenseElem.val("자작|" + $(this).val());
});
licenseDropdown.insertAfter(firstLevelDropdown);
break;
case "other":
licenseElem.val("");
if (licenseDropdown) {
licenseDropdown.remove();
if (versionDropdown) {
versionDropdown.remove();
}
}
licenseDropdown = makeDropdown(maps.otherMap.conditions).css("width", "70%");
versionDropdown = makeDropdown(maps.otherMap.versions).css("width", "30%").prop("disabled", true);
licenseDropdown.change(function() {
var condition = licenseDropdown.val();
if (condition.indexOf("by") == 0) {
versionDropdown.prop("disabled", false);
if (!versionDropdown.val()) {
licenseElem.val("");
return;
}
licenseElem.val("cc-" + condition + "-" + versionDropdown.val());
} else {
versionDropdown.prop("disabled", true);
licenseElem.val(condition);
}
});
versionDropdown.change(function() {
var condition = licenseDropdown.val();
if (condition.indexOf("by") == 0) {
versionDropdown.prop("disabled", false);
if (!versionDropdown.val()) {
licenseElem.val("");
return;
}
licenseElem.val("cc-" + condition + "-" + versionDropdown.val());
}
});
licenseDropdown.insertAfter(firstLevelDropdown);
versionDropdown.insertAfter(licenseDropdown);
break;
default:
}
});
firstLevelDropdown.insertAfter(licenseElem);
licenseElem.change(function() {
var tempname = licenseElem.val();
if (!tempname) {
$("#mw-license-preview").html("");
return;
}
if (temp[tempname]) {
} else {
$.ajax({
type: "GET",
url: mw.util.wikiScript("api"),
data: {
action: "query",
format: "json",
text: tempname,
contentmodel: "wikitext",
prop: "text"
},
success: function(resp) {
temp[tempname] = resp.parse.text["*"];
$("#mw-license-preview").html(tempname);
}
});
}
});
$("#mw-upload-form").submit(function(e) {
if (licenseElem.val() == "") {
if (versionDropdown && !versionDropdown.prop("disabled") && !versionDropdown.val()) {
alert("라이선스 버전을 선택해주세요.");
e.preventDefault();
} else {
licenseElem.val("퍼옴");
}
}
});
}
$(function() {
if (document.location.href.indexOf("특수:올리기") < 0) return;
LicenseDropdown();
});

2015년 11월 7일 (토) 22:18 판

importScript("User:Senior9324/Gadget-ReferenceDrawerDev.js");
importStylesheet("User:Senior9324/Gadget-ReferenceDrawerDev.css");

/*
 * written By. LiteHell
 * Warning : This script uses localStorage of your browser so BREADCUMB WILL BE DELETED IF YOU CLEAR STORAGE DATA FROM YOUR BROWSER.
 */
if (mw.config.exists("wgIsArticle") && mw.config.exists("wgPageName") && mw.config.exists("wgArticlePath") && mw.config.exists("wgNamespaceNumber")) {
    var conf = mw.config.get(["wgIsArticle", "wgPageName", "wgArticlePath", "wgNamespaceNumber"]);
    if (conf.wgIsArticle) {
        var itemName = "pageBreadcumbs";
 
        function initStorageIfRequired() {
            if (localStorage.getItem(itemName) == null)
                localStorage.setItem(itemName, "[]");
        }
 
        function setStorage(value) {
            initStorageIfRequired();
            localStorage.setItem(itemName, JSON.stringify(value.slice(-20)));
        }
 
        function getStorage() {
            initStorageIfRequired();
            return JSON.parse(localStorage.getItem(itemName));
        }
 
        function makeBreadBar(arr, active) {
            var ol = document.createElement("ol");
            ol.className = "breadcrumb";
            ol.innerHTML = '<li id="cleanBreads"><a href="javascript:(function(){})();" style="color: red;"><span class="glyphicon glyphicon-trash"></span></a></li>';
            ol.querySelector('li#cleanBreads > a').addEventListener("click", function() {
                if (confirm("진짜로 빵가루를 전부다 청소할까요?")) {
                    localStorage.setItem(itemName, "[]");
                    alert('강제 새로고침하면 지워져 있을겁니다. :)');
                }
            });
            for (var i = 0; i < arr.length; i++) {
                var now = arr[i];
                var li = document.createElement("li");
                if (now == active) {
                    li.className = "active";
                    li.textContent = now;
                } else {
                    var anchor = document.createElement("a");
                    anchor.href = conf.wgArticlePath.replace('$1', now);
                    anchor.title = now;
                    anchor.textContent = now;
                    li.appendChild(anchor);
                }
                ol.appendChild(li);
            }
            return ol;
        }
 
        var articles = getStorage(), discuss = (conf.wgNamespaceNumber % 2) || (conf.wgNamespaceNumber == 2600);
        if(!(articles.length == 0) || !discuss) {
          if((articles.length == 0 || (articles.length != 0 && articles[articles.length - 1] != conf.wgPageName)) && !discuss) articles.push(conf.wgPageName);
          setStorage(articles, conf.wgPageName);
          var breadbar = makeBreadBar(articles, conf.wgPageName);
          var contentButtons = document.querySelector(".libre_content_tools");
          contentButtons.parentNode.insertBefore(breadbar, contentButtons);
        }
    }
}

var temp = {}, maps = {};
maps.mainMap = {
	"own": "직접 만든 저작물입니다.",
	"other": "타인이 만든 저작물입니다."
};
maps.ownMap = {
	"cc-by-3.0": "CC BY 3.0으로 배포합니다.",
	"cc-by-sa-3.0": "CC BY-SA 3.0으로 배포합니다",
	"cc-0": "CC0 1.0 퍼블릭 도메인으로 배포합니다.",
	"PD-self": "저작권을 포기하여 퍼블릭 도메인으로 배포합니다."
};
maps.otherMap = {
	"conditions": {
		"border1": "---비자유 저작물---",
		"퍼옴": "독점적 저작권이 있는 비자유 저작물을 가져왔습니다.",
		"border2": "---크리에이티브 커먼즈 라이선스---",
		"by": "저작자표시",
		"by-sa": "저작자표시-동일조건변경허락",
		"by-nd": "저작자표시-변경금지",
		"by-nc": "저작자표시-비영리",
		"by-nc-sa": "저작자표시-비영리-동일조건변경허락",
		"by-nc-nd": "저작자표시-비영리-변경금지",
		"border3": "---기타 라이선스---",
		"공공누리 제1유형": "공공누리 제1유형: 출처표시",
		"정보공유라이선스 허용": "정보공유라이선스 2.0: 허용",
		"border4": "---퍼블릭 도메인---",
		"cc-0": "CC0 1.0 퍼블릭 도메인",
		"PD-author": "타인에 의해 퍼블릭 도메인으로 배포됨",
		"PD-old": "저작권 보호기간이 만료되어 저작권이 소멸됨",
		"PD-ineligible": "보호에 부적격하므로 저작물이 아닙니다."
	},
	"versions": {
		"2.0": "2.0 일반",
		"2.0-kr": "2.0 대한민국",
		"2.5": "2.5 일반",
		"3.0": "3.0 Unported",
		"4.0": "4.0 국제"
	}
};

function makeDropdown(map) {
	var dropdown = $("<select>");
	dropdown.append('<option value="">기본값</option>');
	for (var i in map) {
		if (map.hasOwnProperty(i)) {
			if (i.indexOf("border") > -1) {
				dropdown.append($("<option>").prop("disabled", true).attr("value", "").css("color", "gray").text(map[i]));
			} else {
				dropdown.append($("<option>").attr("value", i).text(map[i]));
			}
		}
	}
	return dropdown;
}

function LicenseDropdown() {
	var licenseElem = $("<input>").attr("id", "wpLicense").attr("type", "hidden").attr("name", "wpLicense");
	$("#wpLicense").replaceWith(licenseElem);
	var firstLevelDropdown = makeDropdown(maps.mainMap);
	var licenseDropdown, versionDropdown, authorText;
	firstLevelDropdown.change(function() {
		switch (firstLevelDropdown.val()) {
			case "own":
				licenseElem.val("");
				if (licenseDropdown) {
					licenseDropdown.remove();
					if (versionDropdown) {
						versionDropdown.remove();
					}
				}
				licenseDropdown = makeDropdown(maps.ownMap);
				licenseDropdown.change(function() {
					if (!licenseDropdown.val()) {
						licenseElem.val("");
						return;
					}
					licenseElem.val("자작|" + $(this).val());
				});
				licenseDropdown.insertAfter(firstLevelDropdown);
				break;
			case "other":
				licenseElem.val("");
				if (licenseDropdown) {
					licenseDropdown.remove();
					if (versionDropdown) {
						versionDropdown.remove();
					}
				}
				licenseDropdown = makeDropdown(maps.otherMap.conditions).css("width", "70%");
				versionDropdown = makeDropdown(maps.otherMap.versions).css("width", "30%").prop("disabled", true);
				licenseDropdown.change(function() {
					var condition = licenseDropdown.val();
					if (condition.indexOf("by") == 0) {
						versionDropdown.prop("disabled", false);
						if (!versionDropdown.val()) {
							licenseElem.val("");
							return;
						}
						
						licenseElem.val("cc-" + condition + "-" + versionDropdown.val());
					} else {
						versionDropdown.prop("disabled", true);
						licenseElem.val(condition);
					}
				});
				versionDropdown.change(function() {
					var condition = licenseDropdown.val();
					if (condition.indexOf("by") == 0) {
						versionDropdown.prop("disabled", false);
						if (!versionDropdown.val()) {
							licenseElem.val("");
							return;
						}
						
						licenseElem.val("cc-" + condition + "-" + versionDropdown.val());
					}
				});
				licenseDropdown.insertAfter(firstLevelDropdown);
				versionDropdown.insertAfter(licenseDropdown);
				break;
			default:
		}
	});
	firstLevelDropdown.insertAfter(licenseElem);
	licenseElem.change(function() {
		var tempname = licenseElem.val();
		if (!tempname) {
			$("#mw-license-preview").html("");
			return;
		}
		
		if (temp[tempname]) {
			
		} else {
			$.ajax({
				type: "GET",
				url: mw.util.wikiScript("api"),
				data: {
					action: "query",
					format: "json",
					text: tempname,
					contentmodel: "wikitext",
					prop: "text"
				},
				success: function(resp) {
					temp[tempname] = resp.parse.text["*"];
					$("#mw-license-preview").html(tempname);
				}
			});
		}
	});
	
	$("#mw-upload-form").submit(function(e) {
		if (licenseElem.val() == "") {
			if (versionDropdown && !versionDropdown.prop("disabled") && !versionDropdown.val()) {
				alert("라이선스 버전을 선택해주세요.");
				e.preventDefault();
			} else {
				licenseElem.val("퍼옴");
			}
		}
	});
}

$(function() {
	if (document.location.href.indexOf("특수:올리기") < 0) return;
	
	LicenseDropdown();
});