//$Id: extwiki.js 82 2010-12-10 05:44:51Z mashiki $
Ext.onReady(function(){
var XC=Ext.util.Cookies,XD=Ext.DomHelper,XF=Ext.form,XG=Ext.grid,XJ=Ext.util.JSON,
XM=Ext.Msg,XT=Ext.tree,WL=window.location;
var P=Ext.apply(ExtWikiConf,XJ.decode(XC.get('custom_conf')||'{}'));
P.UrlWiki0=WL.protocol+'//'+WL.host+WL.pathname;
if(WL.hash!='___'&&WL.hash!='_..')P.anchor0=WL.hash;
Ext.BLANK_IMAGE_URL=P.UrlExtJS+'/resources/images/default/s.gif';
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Ext.QuickTips.init();
XD.append(
'hidden_div',{
tag:'form',
children:[{tag:'input',id:'x-history-field'},{tag:'iframe',id:'x-history-frame'}]});
Ext.History.init(function(){
if(Ext.isIE)this.add('_..');
this.on('change',function(id){
if((!id||id=='_..')&&!confirm('「戻る」の操作でExtWikiを抜けます'))this.forward();});
this.add('___');});
var stl=Ext.getDom('theme');
stl.href=stl.href.replace(/xtheme-[^\/]+[.]css$/,'xtheme-'+P.Theme+'.css');
var Xji={
main:new Ext.TabPanel({
region:'center',
tabPosition:P.TabPosition,
enableTabScroll:true,
deferredRender:false,
plain:true,
tbar:[],
listeners:{
tabchange:function(tp,pnl){Xji.onPageActive(pnl)}}}),
sub:new Ext.Panel({
region:{top:'north',bottom:'south',left:'west',right:'east'}[P.MenuPosition],
split:true,
width:200,
minSize:100,
collapsible:true,
collapseMode:'mini',
title:'Menu',
margins:0,
layout:'card',
activeItem:0,
items:[{
id:'menu',
margins:0,
layout:'accordion',
layoutConfig:{
animate:true}}],
tools:[{
id:'refresh', qtip : 'Menu リロード',
handler:function(e,el,p,c){Xji.loadMenuBar()}}],
listeners:{
resize:function(t,aW,aH,rW,rH){
if(t.items.getCount()==1){
if(t.region=='west'||t.region=='east'){
t.menuWidth=rW;}else{
t.menuHeight=rH;}}}}}),
activate:function(pnl,anchor){
if(pnl.getPI('sub')){
this.sub.setTitle('Sub Region Contents');
this.sub.getLayout().setActiveItem(1);}else{
this.main.activate(pnl);}
if(anchor)pnl.goAnchor(anchor);},
add:function(pi,reg,pnl){
pi.lastdisp=new Date;
if(!pnl){
var cfg={
title:'loading ...',
iconCls:'ewi_loading',
closable:true,
autoScroll:true,
bodyStyle:'padding: 5',
pageinfo:pi,
items:{html:'loading ...'}};
if(reg=='sub')cfg.tools=[{
id:'close', qtip : '閉じる',
handler:function(e,el,p,c){Xji.clearSub(true)}}];
pnl=new Xji.Panel(cfg);}
pnl.doLayout(false,true);
if(reg!='sub'){
this.main.add(pnl);
var p=this.sub.items.itemAt(1);
if(this.main.items.getCount()+(p&&!p.getPI('temp')?1:0)>P.MaxTabs){
var oldest;
this.main.items.each(function(pn){
if(oldest){
if(pn.getPI('lastdisp')<oldest.getPI('lastdisp'))oldest=pn;}else{
oldest=pn;}});
this.main.remove(oldest);}}else{
var sub=this.sub;
this.clearSub();
pi.sub=true;
pi.temp=true;
sub.add(pnl);
this.setSubRegionSize('half');}
return pnl;},
clearSub:function(dispMenu){
var pnl,sub=this.sub;
var cmp=sub.items.itemAt(1);
if(!cmp)return;
if(!cmp.getPI('temp')){
pnl=cmp.items.itemAt(0);
delete pnl.pageinfo.sub;
this.main.add(pnl);}
sub.remove(cmp,true);
if(dispMenu){
this.setSubRegionSize('menu');
sub.getLayout().setActiveItem(0);
sub.setTitle('Menu');}
return pnl;},
confirmWithResult:function(title,message,res,btns){
if(!btns)btns=[{
text:'Ok',
handler:function(b,e){b.ownerCt.ownerCt.ownerCt.close();}}];
(new Ext.Window({
title:title,
width:512,
height:384,
resizable:true,
closable:true,
modal:true,
layout:'border',
items:[{
region:'north',
xtype:'panel',
height:80,
html:message,
buttonAlign:'center',
buttons:btns,
autoScroll:true,
split:true},{
region:'center',
xtype:'tabpanel',
activeTab:0,
items:[{
title:'image',
contentEl:Xji.makeDiv(res.responseText),
autoScroll:true},{
title:'source',
html:res.responseText.replace(/&/g,'&amp;').replace(/</g,'&lt;'),
autoScroll:true}]}]})).show();},
doLinkAction:function(url,pnl){
var purl=url.match(/^([^?#]*)([^#]*)(.*)$/);
if((purl[1]!=P.UrlWiki&&purl[1]!=P.UrlWiki0)){
window.open(purl[0]);
return;}
var p=Xji.query2obj(purl[2]);
p.cmd=p.cmd||p.plugin||'read';
if(p.cmd=='read'&&!p.page){
p.page=P.DefaultPage;}
if(pnl&&(
p.cmd=='extwiki' && p.mode=='extwiki'||p.page==pnl.getPI('page') && p.cmd=='read' && pnl.getPI('action') == 'read')){
pnl.goAnchor(purl[3]);}else if(p.openfile||(p.cmd=='attach' && p.pcmd=='open')){
window.open(purl[0]);}else{
if(purl[3]!='')p._anchor=purl[3];
Xji.loadPluginPage(p);}},
find:function(reg,pi){
var ret=[];
if(reg!='sub'){
this.main.items.each(function(pnl){
if(cmp(pi,pnl.getPI()))ret.push(pnl);})}
if(reg!='main'){
var scp=this.sub.items.get(1);
if(scp&&(!pi||cmp(pi,scp.getPI())))ret.push(scp);}
return ret;
function cmp(p1,p2){
for(key in p1)if(p1[key]!=p2[key]){
return false;}
return true;}},
getActivePanel:function(){
return this.main.getActiveTab();},
itemHandler:function(item,e){
e.stopEvent();
var p={};
var conf=item.attributes||item.initialConfig;
for(var k in conf.params)p[k]=conf.params[k];
if(item=='-' || p.acttype=='menu'){}else if(p.acttype=='link'){
Xji.doLinkAction(p.url,Xji.getActivePanel());}else{
if(p.page=='.'){
p.page=Xji.getActivePanel().getPI('page');}
if(p.refer=='.'){
p.refer=Xji.getActivePanel().getPI('page');}
if(p.acttype=='xjf'){
Xji.require(p.xjf,function(opt){
X[p.xjf](opt);},p);}else if(p._external){
window.open(P.UrlWiki+'?'+Xji.obj2query(p));}else{
Xji.loadPluginPage(p);}}},
loadMenuBar:function(){
Xji.request({
url:P.UrlWiki+'?cmd=extwiki&mode=getTreeList&page=:ExtMenuBar',
x_action:'read',
x_page:':ExtMenuBar',
x_pnl:this.menu,
failure:Xji.onRequestFail,
success:function(data){
Xji.menu.removeAll();
for(var i=0,top; top=data[i]; ++i){
var root=new XT.TreeNode({text:top.text});
(function(parent,childs){
for(var i=0,cld; cld=childs[i]; ++i){
var p=cld.params;
var node=new XT.TreeNode({
iconCls:'ewi_'+cld.iconCls,
text:cld.text,
href:p?p.url||(p.page?P.UrlWiki+'?'+p.page:''):'',
params:cld.params,
qtip:cld.tooltip,
leaf:!cld.menu});
parent.appendChild(node);
node.on(
'click',
Xji.itemHandler,
null,
{stopEvent:true});
if(cld.menu&&cld.menu.items.length>0){
arguments.callee(node,cld.menu.items);}}})(root,top.menu?top.menu.items:[{"acttype":"menu","text":"NoMenu"}]);
var tp=new XT.TreePanel({
title:top.text,
iconCls:'ewi_'+top.iconCls,
rootVisible:false,
autoScroll:true,
root:root});
Xji.menu.add(tp);}
Xji.menu.doLayout();}});},
loadPluginPage:function(p,reg){
p.x_cmd=p.plugin||p.cmd||'read';
reg=reg||'main';
if(!p.page){
p.page=(p.x_cmd=='read')?P.DefaultPage:'';}
var pi={page:p.page,action:p.x_cmd},
pnl=Xji.find('both',pi)[0];
if(pnl&&pnl.getPI('sub'))pnl=Xji.clearSub(true);
if(pnl&&!p.reload){
Xji.activate(pnl,p._anchor);
return;}
if(!pnl)pnl=Xji.add(pi,reg);
if(p.mode)p.x_mode=p.mode;
p.mode='getPage';
p.cmd='extwiki';
delete p.plugin;
Xji.request({
url:P.UrlWiki+'?'+Xji.obj2query(p),
x_action:p.x_cmd,
x_anchor:p._anchor,
x_page:p.page,
x_pnl:pnl,
x_refer:Xji.getActivePanel(),
success:Xji.onPageLoad,
failure:Xji.onRequestFail});},
loadToolBar:function(){
Xji.request({
url:P.UrlWiki+'?cmd=extwiki&mode=getTreeList&page=:ExtToolBar',
x_action:'read',
x_page:':ExtToolBar',
failure:Xji.onRequestFail,
success:function(res){
var tb=Xji.main.getTopToolbar();
tb.removeAll(true);
for(var ii=0; ii<res.length; ++ii){
(function(item){
if(item.iconCls)item.iconCls='ewi_'+item.iconCls;
item.handler=Xji.itemHandler;
if(item.menu&&item.menu.items){
for(var ii=0; ii<item.menu.items.length; ++ii){
arguments.callee(item.menu.items[ii]);}}})(res[ii]);
tb.add(res[ii]);}
tb.doLayout();}});},
makeDiv:function(html,pnl){
var el=XD.append('hidden_div', {tag:'div', html:html}, true);
el.select('a').each(function(e){
var url=e.dom.href;
if(url)e.on(
'click',
(function(u,pn){
return function(){Xji.doLinkAction(u,pn);}})(url,pnl),
null,
{stopEvent:true});});
el.select('form').each(function(e){
e.on(
'submit',
(function(pnl){
return function(ev,form,c){Xji.postForm(pnl,form);}})(pnl),
null,{stopEvent:true});});
el.select('input').each(function(e){
if(e.dom.type=='submit')e.on(
'click',
function(a,submit,c){Ext.get(submit.form)._submit=submit;},
null,
{stopEvent:false});});
return el;},
move2sub:function(pnl){
var sub=this.sub;
this.clearSub();
pnl.pageinfo.sub=true;
sub.add(new Ext.Panel({
items:pnl,
title:pnl.getPI('title'),
iconCls:pnl.getPI('iconCls'),
layout:'fit',
getPI:function(p){return pnl.getPI(p)},
tools:[{
id:'unpin', qtip : 'タブへ',
handler:function(e,el,p,c){
Xji.clearSub(true);
if(Xji.main.items.getCount()==1)Xji.main.activate(0);}}]}));
sub.doLayout();
this.activate(pnl);
this.setSubRegionSize('half');},
obj2query:function(o){
var q='';
for(var k in o){
if(k[0]=='_')continue;
if(k!='page'&&k!='refer')o[k]=encodeURIComponent(o[k]);
q +='&'+k+'='+o[k];}
return q.substr(1);},
onPageActive:function(pnl){
var pi=pnl?pnl.getPI():{};
pi.lastdisp=new Date;
document.title=(pi.title||'') + '  --  ' + P.SightName;
Ext.getDom('top_title').innerHTML = pi.title||'';
Ext.getDom('top_count').innerHTML = pnl?pi.cntTotal:'0';
Ext.getDom('top_today').innerHTML = pnl?pi.cntToday:'0';
Ext.getDom('top_yesterday').innerHTML = pnl?pi.cntYesterday:'0';
Ext.getDom('top_url').innerHTML = P.UrlWiki +'?'+ (pi.page||'');
Ext.getDom('top_url').href = P.UrlWiki +'?'+ (pi.page||'');
Ext.getDom('top_update').innerHTML=Xji.shortDate(pi.update);
(function setDisable(items){
items.each(function(item){
if(item.ctledit){
if(item.ctledit==(pi.writable?'enable':'disable')){
item.enable();}else if(item.ctledit==(pi.writable?'disable':'enable')){
item.disable();}}
if(item.menu){
setDisable(item.menu.items);}});})(this.main.getTopToolbar().items);},
onPageLoad:function(res,opt){
if(res.body==''){
XM.confirm(
'アクション「'+opt.x_action+'」の結果',
res.title+'<br />ページの再表示をしますか',
function(btn){
if(btn=='yes'){
Xji.loadPluginPage({page:res.page,reload:true});}});
return;}
opt.x_pnl.setPI({
page:res.page,
action:opt.x_action,
title:res.title,
iconClass:'',
writable:res.writable,
update:(res.update&&res.update!='-')?new Date(res.update):'-',
cntTotal:res.cntTotal,
cntToday:res.cntToday,
cntYesterday:res.cntYesterday});
var cmpt=new Ext.Component(Xji.makeDiv(res.body,opt.x_pnl));
opt.x_pnl.write(cmpt,opt.x_anchor);},
onRequestFail:function(res,opt){
var pnl=opt.x_pnl;
if(res.err_type=='request'){
XM.alert(
'通信エラー',
'「'+opt.url+'」への通信でエラーが発生しました<br />'+XJ.encode(res));}else if(res.err_type=='app'){
if(res.decode.reason=='PageNotFound' && (opt.x_action=='read' || opt.x_action=='edit')){
Xji.confirmWithResult(
'ページ読み込み',
res.decode.message+'<br />新規ページとして作成しますか？',
res,
[{
text:'yes',
handler:function(b,e){
Xji.require('edit',function(opt){
X.edit(opt);},{page:opt.x_page,refer:opt.x_refer,force:true});
Xji.remove(pnl);
b.ownerCt.ownerCt.ownerCt.close();}},'-',{
text:'no',
handler:function(b,e){
Xji.remove(pnl);
b.ownerCt.ownerCt.ownerCt.close();}}]);}else{
Xji.confirmWithResult(
'ページ読み込み',
'ページの読み込みに失敗しました'+ (res.decode.message?'<br />'+ res.decode.message:''),
res);}}else if(res.responseText=="\n"){
XM.alert(
'編集保存エラー',
'ページ「'+opt.x_page+'」の保存で空の改行が戻りました<br />'+'スパムと見なされてエラーとなった可能性があります');}else if(opt.params&&opt.params.x_cmd=='edit'&&opt.params.write){
var pg=pnl.getPI('page');
Xji.loadPluginPage({page:pg,reload:true});
Xji.confirmWithResult(
'編集結果',
'ページ'+(opt.x_page?'「'+opt.x_page+'」':'')+'の編集はおそらく成功しました。<br />'+'古い編集ページを閉じますか？',
res,
[{
text:'yes',
handler:function(b,e){
var cont=Ext.getCmp('edit_continue').getValue();
Xji.remove(pnl);
if(cont){
Xji.require('edit',function(opt){
X.edit(opt);},{page:pg,edit_continue:cont});}
b.ownerCt.ownerCt.ownerCt.close();}},{
xtype:'checkbox',
id:'edit_continue',
checked:pnl.getPI('edit_continue'),
boxLabel:'閉じて開く'},'->',{
text:'no',
handler:function(b,e){
b.ownerCt.ownerCt.ownerCt.close();}}]);}else if(opt.params&&opt.params.x_cmd=='edit'&&opt.params.cancel){
Xji.remove(pnl);}else if(opt.params&&(opt.params.x_cmd=='tracker'||opt.params.x_cmd=='pcomment')){
Xji.confirmWithResult(
'編集結果('+opt.params.x_cmd+')',
'ページ'+(opt.x_page?'「'+opt.x_page+'」':'')+'の編集はおそらく成功しました。<br />'+'ページをリロードしますか？',
res,
[{
text:'yes',
handler:function(b,e){
Xji.loadPluginPage({page:pnl.getPI('page'),reload:true});
b.ownerCt.ownerCt.ownerCt.close();}},'-',{
text:'no',
handler:function(b,e){
b.ownerCt.ownerCt.ownerCt.close();}}]);}else if(opt.params&&opt.params.x_cmd=='rename'&&opt.form&&opt.form.pass){
var refer=opt.form.refer.value;
Xji.confirmWithResult(
'名前変更結果',
'名前変更の結果<br />変更前のパネル「'+ refer +'」を閉じて、新しい名前「'+ opt.x_page +'」を開きますか',
res,
[{
text:'yes',
handler:function(b,e){
Xji.remove(pnl);
var pnls=Xji.find('both',{page:refer});
for(var i=0,p; p=pnls[i]; ++i){
Xji.remove(p);}
Xji.loadPluginPage({page:opt.x_page,reload:true});
b.ownerCt.ownerCt.ownerCt.close();}},'-',{
text:'no',
handler:function(b,e){
b.ownerCt.ownerCt.ownerCt.close();}}]);}else{
Xji.confirmWithResult(
'想定外の結果',
'サーバーから想定外の結果が返されました',
res);}},
postForm:function(pnl,form){
var el,name,action,page,submit;
var params=Ext.urlDecode(form.action.replace(/^.*[?]/,''),true);
if(params.mode)params.x_mode=params.mode;
if((submit=Ext.get(form)._submit))params[submit.name]=submit.value;
var action=params.plugin||params.cmd;
for(var i=0; el=form.elements[i]; ++i){
name=el.name;
if(!el.disabled&&name){
if(name=='plugin' || name=='cmd'){
el.name='xx_' + name;
action=el.value;}else if(name=='mode'){
el.name='x_mode';}else if(name=='page'){
page=el.value.replace(/^\[\[(.*)\]\]$/,'$1');}
if(el.type=='submit') el.name='xx_' + name;}}
params.x_cmd=action;
delete params.cmd;
delete params.plugin;
delete params.mode;
Xji.request({
method:'POST',
url:P.UrlWiki+'?cmd=extwiki&mode=postForm',
params:params,
form:form,
x_page:page,
x_action:action,
x_anchor:'',
x_pnl:pnl,
success:Xji.onPageLoad,
failure:Xji.onRequestFail});
for(var i=0; el=form.elements[i]; ++i)el.name=el.name.replace(/^xx_/,'');},
query2obj:function(q){
var aq=q.replace(/^\?/,'').split('&');
for(var i=0,p={},s; s=aq[i]; ++i){
var v=s.split('=');
if(v.length<2){
p.page=s;}else{
p[v[0]]=(v[0]=='page'||v[0]=='refer')?v[1]:decodeURIComponent(v[1]);}}
return p;},
reload:function(){
var pagename=Xji.getActivePanel().getPI('page');
Xji.loadPluginPage({page:pagename,reload:true});},
remove:function(pnl){
this.main.remove(pnl,true);},
request:function(obj){
if(obj.x_pnl&&obj.x_pnl.el)obj.x_pnl.el.mask('loading ...', 'x-mask-loading');
obj.timeout=P.Timeout*1000;
obj.failureX=obj.failure;
obj.successX=obj.success;
delete obj.failure;
delete obj.success;
obj.callback=function(opt,success,res){
if(opt.x_pnl&&opt.x_pnl.el)opt.x_pnl.el.unmask();
if(!success){
res.err_type='request';}else{
if(res.responseText.match(/^<pre>(.*)<\/pre>$/))
res.responseText=res.responseText.replace(/^<pre>|<\/pre>$/g,'');
try{
res.decode=XJ.decode(res.responseText);}catch(e){
res.err_type='json';}
res.err_type=!res.decode?'json'
:(!res.decode.success?'app':false);}
res.err_type? opt.failureX(res,opt)
:opt.successX(res.decode.data,opt);}
Ext.Ajax.request(obj);},
require:function(target,callback,opt){
if(typeof(target)=='string')target=target.split(/[ ,]+/);
opt=opt||{};
var t=target.shift();
if(!t){
callback(opt);}else if(X[t]){
Xji.require(target,callback,opt);}else if(X._queue[t]){
X._queue[t].push({target:target,callback:callback,opt:opt});}else{
X._queue[t]=[{target:target,callback:callback,opt:opt}];
Ext.Ajax.request({
url:P.UrlExtWiki+'/xjp/'+t+'.js',
disableCaching:!!(X._list[t]),
success:function(res,opts){
var cnt=X._list[t]?X._list[t].count+1:1,
scr='/*'+t+': '+cnt+'*/\nX[t]='+ res.responseText;
if(!X._lineEval)X._lineEval=(new Error()).lineNumber+2||-1;
try{
eval(scr);}catch(e){
dispError('の評価時にエラー発生('+(e.lineNumber?'line:'+(e.lineNumber-X._lineEval)+' ':'')+e.message+')');
return;}
X._list[t]={
url:opts.url,
status:''+res.status+' '+res.statusText,
size:res.getResponseHeader('Content-Length'),
date:res.getResponseHeader('Date'),
modified:res.getResponseHeader('Last-Modified'),
count:cnt,
removed:false};
for(var i=0,o; o=X._queue[t][i]; ++i){
Xji.require(o.target,o.callback,o.opt);}
delete X._queue[t];},
failure:function(res,opts){
if(res.status==404){
dispError('が存在しない、もしくは未実装です');}else{
dispError('の読み込み中にエラー発生');}}});}
function dispError(msg){
XM.alert('xjp 読込みエラー', 'Javascriptファイル「xjp/'+t+'.js」'+msg);
delete X._queue[t];}},
setSubRegionSize:function(mode){
var sub=this.sub;
if(mode=='menu'){
if(sub.region=='west'||sub.region=='east'){
sub.setWidth(sub.menuWidth);}else{
sub.setHeight(sub.menuHeight);}
sub.getTool('refresh').show();}else{
if(sub.region=='west'||sub.region=='east'){
sub.setWidth((sub.getWidth()+this.main.getWidth())/2-10);}else{
sub.setHeight((sub.getHeight()+this.main.getHeight())/2-25);}
sub.getTool('refresh').hide();}
sub.on({
collapse:function(){sub.expand(true)},
single:true,
delay:100});
sub.collapse(true);},
shortDate:function(dt){
return(dt instanceof Date)
?dt.format((dt>(new Date)-10*24*60*60*1000)?'m/d H:i':'Y/m/d')
:'-'},
version:function(){return '1.4  $Rev: 82 $'.replace(/ \$/g,'')},
Panel:Ext.extend(Ext.Panel,{
constructor:function(config){
this.pageinfo=config.pageinfo;
Xji.Panel.superclass.constructor.apply(this,arguments);},
getPI:function(key){
return !key?this.pageinfo:(this.pageinfo[key]||'');},
setPI:function(obj){
if('title' in obj)this.setTitle(obj.title);
if('iconClass' in obj)this.setIconClass(obj.iconClass);
Ext.apply(this.pageinfo,obj);},
write:function(cmpt,anchor){
this.removeAll(true);
this.add(cmpt);
this.doLayout(false,true);
if(Xji.getActivePanel()==this){
Xji.onPageActive(this);}else{
Xji.activate(this,anchor);}},
goAnchor:function(anchor){
if(anchor){
this.body.select(anchor).each(function(el){
this.body.scrollTo('top',el.getTop(false)-this.body.getTop(false),true);},this);}}})}
var X={
_queue:{},
_list:{},
_lineEval:null}
var viewport=new Ext.Viewport({
layout:'border',
items:[
{
contentEl:'north',
region:'north',
height:53},{
region:'center',
layout:'border',
items:[Xji.sub,Xji.main]}],
listeners:{
render:function(p){
Xji.loadToolBar();
Xji.menu=Ext.getCmp('menu');
Xji.loadMenuBar(false);
Xji.loadPluginPage({page:P.FirstPage,_anchor:P.anchor0});
XD.append(
'top_logo',
{tag:'a', id:'logo_url', html:P.SightName, title:'トップページへ', href:P.UrlWiki},
true).on('click',function(){Xji.loadPluginPage({})},null,{stopEvent:true});
Ext.get('top_url').on('click',function(){},null,{stopEvent:true});
Ext.getDoc().on('keydown',function(e){
if(e.keyCode==116&&!e.ctrlKey){
if(Ext.isIE)e.browserEvent.keyCode=0;
e.stopEvent();
Xji.reload();}});},
single:true}});});