📄 admin.js
字号:
this.items=new Array();
},
appendChild:function(e){
this.container.appendChild(e);
},
getBox:function(){
return this.container;
},
show:function(){
Element.show(this.container);
this.onShow();
},
hide:function(){
Element.hide(this.container);
this.onHide();
},
getValue:function(name){
var e=this.items[name];
if(!e)return false;
if(!e.tagName)return false;
var tagName=e.tagName.toLowerCase()
if(tagName=="input"){
if(e.type=="radio" || e.type=="checkbox"){
return e.checked?1:0;
}else if(e.type=="text" || e.type=="password" || e.type=="hidden"){
return e.value;
}else return false;
}else if(tagName=="select"){
for(var i=0;i<e.length;i++){
if(e.options[i].selected)return e.options[i].value;
}
}else if(tagName=="textarea"){
if(e.id.match("fckeditor")){
var oEditor = FCKeditorAPI.GetInstance(e.id) ;
return oEditor.GetXHTML();
}else{
return e.value;
}
}
return false;
},
setValue:function(name,value){
var e=this.items[name];
var tagName=e.tagName.toLowerCase()
if(tagName=="input"){
if(e.type=="radio" || e.type=="checkbox"){
e.checked=value=='1';
}else{
e.value=value;
}
}else if(tagName=="select"){
if(!value){
e.selectedIndex=0;
return;
}
for(var i=0;i<e.length;i++){
var o=e.options[i];
if(o.value==value){e.selectedIndex=i;return;}
}
}else if(tagName=="textarea"){
if(e.id.match("fckeditor")){
var oEditor = FCKeditorAPI.GetInstance(e.id) ;
oEditor.SetHTML(value);
}else{
e.value=value;
}
}
},
addSelectValue:function(name,text,value){
var e=this.items[name];
var opt=new Option(text,value);
e.options[e.length]=opt;
/*var opt=$se("option");
opt.innerHTML=text;
opt.value=value;
e.appendChild(opt);*/
},
deleteSelectValue:function(name,value){
var e=this.items[name];
for(var i=0;i<e.length;i++){
if(e.options[i].value==value){
e.options[i]=null;
e.selectedIndex=0;
break;
}
}
},
setSelectTextByValue:function(name,value,text){
var e=this.items[name];
for(var i=0;i<e.length;i++){
if(e.options[i].value==value)e.childNodes[i].text=text;
}
},
clearSelect:function(name){
var e=this.items[name];
var len=e.length;
for(var i=0;i<len;i++){
e.options[0]=null;
}
},
insertItem:function(type,name,_option){
var e=this.getElement(type);
var option={
}.extend(_option || {});
var li;
if(option.sameLine){
li=this.ul.lastChild;
}else{
li=$se("li");
this.ul.appendChild(li);
}
li.appendChild(e);
if(option.liClassName)li.className=option.liClassName;
if(option.className)e.className=option.className;
if(option.foreLabel)this.setLabel(e,option.foreLabel,true);
if(option.backLabel)this.setLabel(e,option.backLabel,false);
if(option.value)e.value=option.value;
if(option.selectArray){
var arr=option.selectArray;
var opt;
for(var i=0;i<arr.length;i++){
opt=$se("option");
opt.innerHTML=arr[i].split(",")[0];
opt.value=arr[i].split(",")[1];
e.appendChild(opt);
}
//e.selectedIndex=0;
}
if(option.tip){
var span=$se("span");
span.className="tip";
span.innerHTML=option.tip;
li.appendChild(span);
}
if(option.attributes){
for(var p in option.attributes){
e.setAttribute(p,eval("option.attributes."+p));
//e[p]=option.attributes[p];
}
}
this.items[name]=e;
},
getElement:function(type){
var e;
switch(type){
case "text":
e=$se("input");
e.type="text";
break;
case "hidden":
e=$se("input");
e.type="hidden";
break;
case "password":
e=$se("input");
e.type="password";
break;
case "button":
e=$se("input");
e.type="button";
break;
case "checkbox":
e=$se("input");
e.type="checkBox";
break;
case "radio":
e=$se("input");
e.type="radio";
break;
case "textarea":
e=$se("textarea");
e.cols=e.rows=3;
break;
case "select":
case "option":
e=$se(type);
break;
case "":
e=$se("b");
break;
default:
e=null;
break;
}
return e;
},
setLabel:function(target,text,before,hideFocus){
target.id="t"+Math.random().toString().split(".")[1];
lbl=$se("label");
lbl.innerHTML=text;
lbl.htmlFor=target.id;
if(before){
target.parentNode.insertBefore(lbl,target);
}else{
target.parentNode.insertBefore(lbl,target.nextSibling);
}
if(hideFocus)lbl.hideFocus=true;
else lbl.hideFocus=false;
},
toXml:function(){
var xml,value;
xml="<topicInfo>";
for(var p in this.items){
value=this.getValue(p);
if(value){
xml+="<"+p+"><![CDATA["+value+"]]></"+p+">";
}
}
xml+="</topicInfo>";
return xml;
},
loadXml:function(xml){
this.reset();
var doc=new X2Doc(xml);
for(var i=0;i<doc.root.contents.length;i++){
if(this.items[doc.root.contents[i].name]){
var value="";
if(doc.root.contents[i].contents[0])value=doc.root.contents[i].contents[0].value;
this.setValue(doc.root.contents[i].name,value);
}
}
},
loadXmlNode:function(xn){
for(var i=0;i<xn.contents.length;i++){
if(this.items[xn.contents[i].name]){
var value="";
if(xn.contents[i].contents[0])value=xn.contents[i].contents[0].value;
this.setValue(xn.contents[i].name,value);
}
}
},
reset:function(){
for(var p in this.items){
var e=eval("this.items['"+p+"']");
if(!this.getValue(p))continue;
this.setValue(p,"");
}
this.customReset();
},
customReset:function(){},
onShow:function(){},
onHide:function(){}
}
var ItemList=Class.create();
ItemList.prototype={
initialize:function(className,_items){
this.container=$se("div");
if(className)this.container.className=className;
if(_items)this.items=_items;
this.rows=new Array();
},
insertRow:function(rowName,rowValue){
var ul=$se("ul");
this.container.appendChild(ul);
this.rows[rowName]=ul;
var li,span;
for(var i=0;i<this.items.length;i++){
if(this.items[i][2]){
li=$se("li");
ul.appendChild(li);
}
if(this.items[i][3])li.className=this.items[i][3];
span=$se("span");
li.appendChild(span);
if(this.items[i][1]!='none'){
span.className=this.items[i][1];
}else{
span.style.display="none";
}
span.innerHTML=eval("rowValue."+this.items[i][0]);
}
},
removeRow:function(rowName){
this.rows[rowName].parentNode.removeChild(this.rows[rowName]);
},
getBox:function(){
return this.container;
},
show:function(){
Element.show(this.container);
this.onShow();
},
hide:function(){
Element.hide(this.container);
this.onHide();
},
onShow:function(){},
onHide:function(){}
}
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
{
// Properties
this.InstanceName = instanceName || "temp";
this.Width = width || '100%' ;
this.Height = height || '200' ;
this.ToolbarSet = toolbarSet || 'Default' ;
this.Value = value || '' ;
this.BasePath = '/fckeditor/' ;
this.CheckBrowser = true ;
this.DisplayErrors = true ;
this.EnableSafari = false ; // This is a temporary property, while Safari support is under development.
this.Config = new Object() ;
// Events
this.OnError = null ; // function( source, errorNumber, errorDescription )
this.TextArea=null;
}
FCKeditor.prototype.Create = function()
{
// Check for errors
if ( !this.InstanceName || this.InstanceName.length == 0 )
{
this._ThrowError( 701, 'You must specify a instance name.' ) ;
return ;
}
//document.write( '<div>' ) ;
var eb=$se("div") ;
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
{
eb.innerHTML+=( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" />' ) ;
eb.innerHTML+=( this._GetConfigHtml() ) ;
eb.innerHTML+=( this._GetIFrameHtml() ) ;
}
else
{
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ;
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
eb.innerHTML+=('<textarea id="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" wrap="virtual">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
}
return eb;
}
FCKeditor.prototype.ReplaceTextarea = function()
{
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
{
var oTextarea = document.getElementById( this.InstanceName ) ;
if ( !oTextarea )
oTextarea = document.getElementsByName( this.InstanceName )[0] ;
if ( !oTextarea || oTextarea.tagName != 'TEXTAREA' )
{
alert( 'Error: The TEXTAREA id "' + this.InstanceName + '" was not found' ) ;
return ;
}
oTextarea.style.display = 'none' ;
this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
}
}
FCKeditor.prototype.ReplaceTextarea2 = function(e)
{
this.InstanceName=e.id="fckeditor"+Math.random().toString().split('.')[1]
this.ReplaceTextarea();
}
FCKeditor.prototype._InsertHtmlBefore = function( html, element )
{
if ( element.insertAdjacentHTML ) // IE
element.insertAdjacentHTML( 'beforeBegin', html ) ;
else // Gecko
{
var oRange = document.createRange() ;
oRange.setStartBefore( element ) ;
var oFragment = oRange.createContextualFragment( html );
element.parentNode.insertBefore( oFragment, element ) ;
}
}
FCKeditor.prototype._GetConfigHtml = function()
{
var sConfig = '' ;
for ( var o in this.Config )
{
if ( sConfig.length > 0 ) sConfig += '&' ;
sConfig += escape2(o) + '=' + escape2( this.Config[o] ) ;
}
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" />' ;
}
FCKeditor.prototype._GetIFrameHtml = function()
{
var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="no" scrolling="no"></iframe>' ;
}
FCKeditor.prototype._IsCompatibleBrowser = function()
{
var sAgent = navigator.userAgent.toLowerCase() ;
// Internet Explorer
if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
{
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
return ( sBrowserVersion >= 5.5 ) ;
}
// Gecko
else if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
return true ;
// Safari
else if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ; // Build must be at least 312 (1.3)
else
return false ;
}
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
{
this.ErrorNumber = errorNumber ;
this.ErrorDescription = errorDescription ;
if ( this.DisplayErrors )
{
document.write( '<div style="COLOR: #ff0000">' ) ;
document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
document.write( '</div>' ) ;
}
if ( typeof( this.OnError ) == 'function' )
this.OnError( this, errorNumber, errorDescription ) ;
}
FCKeditor.prototype._HTMLEncode = function( text )
{
if ( typeof( text ) != "string" )
text = text.toString() ;
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/'/g, "'") ;
return text ;
}
FCKeditor.prototype.GetValue=function(){
var oEditor = FCKeditorAPI.GetInstance(this.InstanceName) ;
return oEditor.GetXHTML();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -