미디어위키:Gadget-InputForm.js

리버티게임(개발), 모두가 만들어가는 자유로운 게임
둘러보기로 이동 검색으로 이동

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
/** 플러그인 inputform
* 완전한 입력기를 구현합니다. (베타)
* 작성자 : [[사용자:Gustmd7410|Gustmd7410]] 
*/ 
function plugin_inputform(){
		  // 이부분에 코드 입력 //
mw.loader.using('oojs-ui-core').done(function () {
    function toBool(value) {
        switch (value) {
            case undefined: return false;
            case '': return true;
        }
    }
    function toArray(value) {
        if (value)
            return value.split(' ');
        else
            return undefined;
    }
    function InpTable(table) {
        this["case"] = {};
        this["default"] = Object.assign({
            prefix: '',
            value: undefined,
            suffix: '',
            replace: [],
            sub: [0]
        }, table["default"]);
        if (table["case"]) {
            for (var value in table["case"]) {
                this["case"][value] = Object.assign({}, this["default"], { value: this["default"].value || value }, table["case"][value]);
            }
        }
    }
    $('.input-form').each(function () {
        var container = this;
        $(this).html(new $('<form />', {
            "class": $(this).data('class'),
            id: $(this).data('id'),
            style: $(this).data('style'),
            'accept-charset': 'UTF-8',
            autocomplete: toBool($(this).data('autocomplete')),
            novalidate: toBool($(this).data('novalidate')),
            html: $(this).html()
        }));
        $(this).children('form').submit(function (event) {
            event.preventDefault();
            var action = new URL('/w/index.php', location);
            if (toBool($(container).data('pass')))
                action.search = location.search;
            if ($(container).data('get'))
                new URLSearchParams($(container).data('get')).forEach(function (value, key) {
                    action.searchParams.set(key, value);
                });
            action.searchParams.set('title', $(container).data('title'));
            $(this).children('.input-field').each(function () {
                if (typeof ($(this).data('table')) == 'object') {
                    var name = $(this).data('name');
                    var rawval = $(this).find('input').val();
                    var table = new InpTable($(this).data('table'));
                    var cvttbl = table["case"][rawval] || table["default"];
                    var cvtval = (cvttbl.value || rawval).slice(cvttbl.sub[0], cvttbl.sub[1]);
                    cvttbl.replace.forEach(function (reparr) {
                        var regex = reparr[0].substr(1).split('/');
                        regex.pop();
                        regex = regex.join('/');
                        var flag = reparr[0].substr(1).split('/').reverse()[0];
                        cvtval = cvtval.replace(new RegExp(regex, flag), reparr[1]);
                    });
                    action.searchParams.set(name, cvttbl.prefix + cvtval + cvttbl.suffix);
                }
                else
                    action.searchParams.set($(this).data('name'), $(this).find('input').val());
            });
            location.href = action.href;
        });
    });
    $('.input-field').each(function () {
        $(this).html(new OO.ui.TextInputWidget({
            accessKey: $(this).data('accessKey'),
            autocomplete: toBool($(this).data('autocomplete')),
            autofocus: toBool($(this).data('autofocus')),
            classes: toArray($(this).data('classes')),
            disabled: toBool($(this).data('disabled')),
            flags: toArray($(this).data('flags')),
            icon: $(this).data('icon'),
            iconTitle: $(this).data('iconTitle'),
            id: $(this).data('id'),
            indicator: $(this).data('indicator'),
            indicatorTitle: $(this).data('indicatorTitle'),
            inputId: $(this).data('inputId'),
            maxLength: Number($(this).data('maxLength')),
            name: $(this).data('name'),
            placeholder: $(this).data('placeholder'),
            readOnly: toBool($(this).data('readOnly')),
            required: toBool($(this).data('required')),
            spellcheck: toBool($(this).data('spellcheck')),
            tabIndex: Number($(this).data('tabIndex')),
            text: $(this).data('text'),
            title: $(this).data('title'),
            type: $(this).data('type'),
	        validate: (function(container) {
	            if ($(container).data('validatetype') == 'RegExp') {
	                var value = $(container).data('validate').substr(1).split('/');
	                return RegExp(value[0], value[1]);
	            }
	            else
	                return $(container).data('validate');
	        })(this),
            value: this.dataset.value || ''
        }).$element);
        
        if(toBool($(this).data('inline'))) $(this).find('*').css({
            display: 'inline',
            width: 'auto'
        });
    });
    $('.input-button').each(function () {
        $(this).html(new OO.ui.ButtonInputWidget({
            accessKey: $(this).data('accessKey'),
            classes: toArray($(this).data('classes')),
            disabled: toBool($(this).data('disabled')),
            flags: toArray($(this).data('flags')),
            framed: toBool($(this).data('framed')),
            icon: $(this).data('icon'),
            iconTitle: $(this).data('iconTitle'),
            id: $(this).data('id'),
            indicator: $(this).data('indicator'),
            indicatorTitle: $(this).data('indicatorTitle'),
            inputId: $(this).data('inputId'),
            label: $(this).data('label'),
            name: $(this).data('name'),
            tabIndex: Number($(this).data('tabIndex')),
            text: $(this).data('text'),
            title: $(this).data('title'),
            type: $(this).data('type'),
            value: $(this).data('value')
        }).$element);
    });
    noPlugin('input');
});
}
$( plugin_inputform );
/* inputform 끝 */