- 浏览: 1290272 次
- 性别:
- 来自: 江苏
最新评论
-
honey_fansy:
的确,不要自己的支持就说完美支持,我的就不行,别说我的不是fi ...
无js实现text-overflow: ellipsis; 完美支持Firefox -
fanchengfei:
事件长微博,欢迎转发:http://weibo.com/332 ...
《在路上 …》 写代码也需要一点演技 – python2.6 的 class decorator -
blued:
没有报错,但排版效果一点都没有 咋回事。请指教
python排版工具 -
szxiaoli:
耍人呀,效果在哪儿呀
滑动效果 -
accaolei:
这个能监到控子目录吗?,我测试了一下,发现子目录里的文件监控不 ...
windows监控目录改动
http://code.google.com/p/jwysiwyg/
做些小改动
(function( $ )
{
$.fn.document = function()
{
var element = this[0];
if ( element.nodeName.toLowerCase() == 'iframe' )
return element.contentWindow.document;
/*
return ( $.browser.msie )
? document.frames[element.id].document
: element.contentWindow.document // contentDocument;
*/
else
return $(this);
};
$.fn.documentSelection = function()
{
var element = this[0];
if ( element.contentWindow.document.selection )
return element.contentWindow.document.selection.createRange().text;
else
return element.contentWindow.getSelection().toString();
};
$.fn.wysiwyg = function( options )
{
if ( arguments.length > 0 && arguments[0].constructor == String )
{
var action = arguments[0].toString();
var params = [];
for ( var i = 1; i < arguments.length; i++ )
params[i - 1] = arguments[i];
if ( action in Wysiwyg )
{ var r;
this.each(function()
{
$.data(this, 'wysiwyg')
.designMode();
r=Wysiwyg[action].apply(this, params);
});
if(r!==undefined)return r;
}
return this;
}
var controls = {};
/**
* If the user set custom controls, we catch it, and merge with the
* defaults controls later.
*/
if ( options && options.controls )
{
var controls = options.controls;
delete options.controls;
}
var options = $.extend({
html : '<'+'?xml version="1.0" encoding="UTF-8"?'+'><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">STYLE_SHEET</head><body>INITIAL_CONTENT</body></html>',
css : {},
debug : false,
autoSave : true, // http://code.google.com/p/jwysiwyg/issues/detail?id=11
rmUnwantedBr : true, // http://code.google.com/p/jwysiwyg/issues/detail?id=15
brIE : true,
controls : {},
messages : {}
}, options);
options.messages = $.extend(true, options.messages, Wysiwyg.MSGS_EN);
options.controls = $.extend(true, options.controls, Wysiwyg.TOOLBAR);
for ( var control in controls )
{
if ( control in options.controls )
$.extend(options.controls[control], controls[control]);
else
options.controls[control] = controls[control];
}
// not break the chain
return this.each(function()
{
Wysiwyg(this, options);
});
};
function Wysiwyg( element, options )
{
return this instanceof Wysiwyg
? this.init(element, options)
: new Wysiwyg(element, options);
}
$.extend(Wysiwyg, {
insertImage : function( szURL, attributes )
{
var self = $.data(this, 'wysiwyg');
if ( self.constructor == Wysiwyg && szURL && szURL.length > 0 )
{
if ( attributes )
{
self.editorDoc.execCommand('insertImage', false, '#jwysiwyg#');
var img = self.getElementByAttributeValue('img', 'src', '#jwysiwyg#');
if ( img )
{
img.src = szURL;
for ( var attribute in attributes )
{
img.setAttribute(attribute, attributes[attribute]);
}
}
}
else
{
self.editorDoc.execCommand('insertImage', false, szURL);
}
}
},
createLink : function( szURL )
{
var self = $.data(this, 'wysiwyg');
if ( self.constructor == Wysiwyg && szURL && szURL.length > 0 )
{
var selection = $(self.editor).documentSelection();
if ( selection.length > 0 )
{
self.editorDoc.execCommand('unlink', false, []);
self.editorDoc.execCommand('createLink', false, szURL);
}
else if ( self.options.messages.nonSelection )
alert(self.options.messages.nonSelection);
}
},
getContent : function (newContent){
var self = $.data(this, 'wysiwyg');
return self.getContent()
},
setContent : function( newContent )
{
var self = $.data(this, 'wysiwyg');
self.setContent( newContent );
self.saveContent();
},
clear : function()
{
var self = $.data(this, 'wysiwyg');
self.setContent('');
self.saveContent();
},
MSGS_EN : {
nonSelection : 'select the text you wish to link'
},
TOOLBAR : {
bold : { visible : true, tags : ['b', 'strong'], css : { fontWeight : 'bold' } },
italic : { visible : true, tags : ['i', 'em'], css : { fontStyle : 'italic' } },
strikeThrough : { visible : true, tags : ['s', 'strike'], css : { textDecoration : 'line-through' } },
underline : { visible : true, tags : ['u'], css : { textDecoration : 'underline' } },
separator00 : { visible : false, separator : true },
justifyLeft : { visible : true, css : { textAlign : 'left' } },
justifyCenter : { visible : true, tags : ['center'], css : { textAlign : 'center' } },
justifyRight : { visible : true, css : { textAlign : 'right' } },
justifyFull : { visible : false, css : { textAlign : 'justify' } },
separator01 : { visible : false, separator : true },
indent : { visible : false },
outdent : { visible : false },
separator02 : { visible : false, separator : true },
subscript : { visible : false, tags : ['sub'] },
superscript : { visible : false, tags : ['sup'] },
separator03 : { visible : false, separator : true },
undo : { visible : false },
redo : { visible : false },
separator04 : { visible : false, separator : true },
insertOrderedList : { visible : false, tags : ['ol'] },
insertUnorderedList : { visible : false, tags : ['ul'] },
insertHorizontalRule : { visible : false, tags : ['hr'] },
separator05 : { separator : true },
createLink : {
visible : true,
exec : function()
{
var selection = $(this.editor).documentSelection();
if ( selection.length > 0 )
{
if ( $.browser.msie )
this.editorDoc.execCommand('createLink', true, null);
else
{
var szURL = prompt('URL', 'http://');
if ( szURL && szURL.length > 0 )
{
this.editorDoc.execCommand('unlink', false, []);
this.editorDoc.execCommand('createLink', false, szURL);
}
}
}
else if ( this.options.messages.nonSelection )
alert(this.options.messages.nonSelection);
},
tags : ['a']
},
insertImage : {
visible : true,
exec : function()
{
if ( $.browser.msie )
this.editorDoc.execCommand('insertImage', true, null);
else
{
var szURL = prompt('URL', 'http://');
if ( szURL && szURL.length > 0 )
this.editorDoc.execCommand('insertImage', false, szURL);
}
},
tags : ['img']
},
separator06 : { separator : true ,visible : false},
h1mozilla : { visible : false && $.browser.mozilla, className : 'h1', command : 'heading', arguments : ['h1'], tags : ['h1'] },
h2mozilla : { visible : false && $.browser.mozilla, className : 'h2', command : 'heading', arguments : ['h2'], tags : ['h2'] },
h3mozilla : { visible : false && $.browser.mozilla, className : 'h3', command : 'heading', arguments : ['h3'], tags : ['h3'] },
h1 : { visible : false && !( $.browser.mozilla ), className : 'h1', command : 'formatBlock', arguments : ['Heading 1'], tags : ['h1'] },
h2 : { visible : false && !( $.browser.mozilla ), className : 'h2', command : 'formatBlock', arguments : ['Heading 2'], tags : ['h2'] },
h3 : { visible : false && !( $.browser.mozilla ), className : 'h3', command : 'formatBlock', arguments : ['Heading 3'], tags : ['h3'] },
separator07 : { visible : false, separator : true },
cut : { visible : false },
copy : { visible : false },
paste : { visible : false },
separator08 : { separator : true && !( $.browser.msie ) },
increaseFontSize : { visible : true ,
exec : function(){
/*
Browser font size 1 -> Safari: 10 px (Actual font size: 8 px)
Browser font size 2 -> Safari: 13 px (Actual font size: 10 px)
Browser font size 3 -> Safari: 16 px (Actual font size: 12 px)
Browser font size 4 -> Safari: 18 px (Actual font size: 14 px)
Browser font size 5 -> Safari: 24 px (Actual font size: 18 px)
Browser font size 6 -> Safari: 32 px (Actual font size: 24 px)
Browser font size 7 -> Safari: 48 px (Actual font size: 36 px)
*/
if($.browser.mozilla){
this.editorDoc.execCommand('increasefontsize',false,[]);
}else{
var sf = {
10:1,13:2,16:3,18:4,24:5,32:6,48:7
}
var font_size = parseInt(this.editorDoc.queryCommandValue('FontSize'));
if(font_size>7)font_size=sf[font_size];
if(font_size&&font_size<7){
this.editorDoc.execCommand('FontSize',false,font_size+1);
}
}
}
},
decreaseFontSize : { visible : true && !( $.browser.msie ), tags : ['small'] },
separator09 : { separator : true },
html : {
visible : false,
exec : function()
{
if ( this.viewHTML )
{
this.setContent( $(this.original).val() );
$(this.original).hide();
}
else
{
this.saveContent();
$(this.original).show();
}
this.viewHTML = !( this.viewHTML );
}
},
removeFormat : {
visible : true,
exec : function()
{
this.editorDoc.execCommand('removeFormat', false, []);
this.editorDoc.execCommand('unlink', false, []);
}
}
}
});
$.extend(Wysiwyg.prototype,
{
original : null,
options : {},
element : null,
editor : null,
init : function( element, options )
{
var self = this;
this.editor = element;
this.options = options || {};
$.data(element, 'wysiwyg', this);
var newX = element.width || element.clientWidth;
var newY = element.height || element.clientHeight;
if ( element.nodeName.toLowerCase() == 'textarea' )
{
this.original = element;
if ( newX == 0 && element.cols )
newX = ( element.cols * 8 ) + 21;
if ( newY == 0 && element.rows )
newY = ( element.rows * 16 ) + 16;
var editor = this.editor = $('<iframe></iframe>').css({
minHeight : ( newY - 6 ).toString() + 'px',
width : ( newX - 8 ).toString() + 'px'
}).attr('id', $(element).attr('id') + 'IFrame');
if ( $.browser.msie )
{
this.editor
.css('height', ( newY ).toString() + 'px');
/**
var editor = $('<span></span>').css({
width : ( newX - 6 ).toString() + 'px',
height : ( newY - 8 ).toString() + 'px'
}).attr('id', $(element).attr('id') + 'IFrame');
editor.outerHTML = this.editor.outerHTML;
*/
}
}
var panel = this.panel = $('<ul></ul>').addClass('panel');
this.appendControls();
this.element = $('<div></div>').css({
width : ( newX > 0 ) ? ( newX ).toString() + 'px' : '100%'
}).addClass('wysiwyg')
.append(panel)
.append( $('<div><!-- --></div>').css({ clear : 'both' }) )
.append(editor);
$(element)
// .css('display', 'none')
.hide()
.before(this.element);
this.viewHTML = false;
this.initialHeight = newY - 8;
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=52
*/
this.initialContent = $(element).val();
this.initFrame();
if ( this.initialContent.length == 0 )
this.setContent('');
if ( this.options.autoSave )
$('form').submit(function() { self.saveContent(); });
$('form').bind('reset', function()
{
self.setContent( self.initialContent );
self.saveContent();
});
},
initFrame : function()
{
var self = this;
var style = '';
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=14
*/
if ( this.options.css && this.options.css.constructor == String )
style = '<link rel="stylesheet" type="text/css" media="screen" href="' + this.options.css + '" />';
this.editorDoc = $(this.editor).document();
this.editorDoc_designMode = false;
try {
this.editorDoc.designMode = 'on';
this.editorDoc_designMode = true;
} catch ( e ) {
// Will fail on Gecko if the editor is placed in an hidden container element
// The design mode will be set ones the editor is focused
$(this.editorDoc).focus(function()
{
self.designMode();
});
}
this.editorDoc.open();
this.editorDoc.write(
this.options.html
.replace(/INITIAL_CONTENT/, this.initialContent)
.replace(/STYLE_SHEET/, style)
);
this.editorDoc.close();
this.editorDoc.contentEditable = 'true';
if ( $.browser.msie )
{
/**
* Remove the horrible border it has on IE.
*/
setTimeout(function() { $(self.editorDoc.body).css('border', 'none'); }, 0);
}
$(this.editorDoc).click(function( event )
{
self.checkTargets( event.target ? event.target : event.srcElement);
});
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=20
*/
$(this.original).focus(function()
{
$(self.editorDoc.body).focus();
});
if ( this.options.autoSave )
{
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=11
*/
$(this.editorDoc).keydown(function() { self.saveContent(); })
.keyup(function() { self.saveContent(); })
.mousedown(function() { self.saveContent(); });
}
if ( this.options.css )
{
setTimeout(function()
{
if ( self.options.css.constructor == String )
{
/**
* $(self.editorDoc)
* .find('head')
* .append(
* $('<link rel="stylesheet" type="text/css" media="screen" />')
* .attr('href', self.options.css)
* );
*/
}
else
$(self.editorDoc).find('body').css(self.options.css);
}, 0);
}
$(this.editorDoc).keydown(function( event )
{
if ( $.browser.msie && self.options.brIE && event.keyCode == 13 )
{
var rng = self.getRange();
rng.pasteHTML('<br />');
rng.collapse(false);
rng.select();
return false;
}
});
},
designMode : function()
{
if ( !( this.editorDoc_designMode ) )
{
try {
this.editorDoc.designMode = 'on';
this.editorDoc_designMode = true;
} catch ( e ) {}
}
},
getSelection : function()
{
return ( window.getSelection ) ? window.getSelection() : document.selection;
},
getRange : function()
{
var selection = this.getSelection();
if ( !( selection ) )
return null;
return ( selection.rangeCount > 0 ) ? selection.getRangeAt(0) : selection.createRange();
},
getContent : function()
{
return $( $(this.editor).document() ).find('body').html();
},
setContent : function( newContent )
{
$( $(this.editor).document() ).find('body').html(newContent);
},
saveContent : function()
{
if ( this.original )
{
var content = this.getContent();
if ( this.options.rmUnwantedBr )
content = ( content.substr(-4) == '<br>' ) ? content.substr(0, content.length - 4) : content;
$(this.original).val(content);
}
},
appendMenu : function( cmd, args, className, fn )
{
var self = this;
var args = args || [];
$('<li></li>').append(
$('<a><!-- --></a>').addClass(className || cmd)
).mousedown(function() {
if ( fn ) fn.apply(self); else self.editorDoc.execCommand(cmd, false, args);
if ( self.options.autoSave ) self.saveContent();
}).appendTo( this.panel );
},
appendMenuSeparator : function()
{
$('<li class="separator"></li>').appendTo( this.panel );
},
appendControls : function()
{
for ( var name in this.options.controls )
{
var control = this.options.controls[name];
if ( control.separator )
{
if ( control.visible !== false )
this.appendMenuSeparator();
}
else if ( control.visible )
{
this.appendMenu(
control.command || name, control.arguments || [],
control.className || control.command || name || 'empty', control.exec
);
}
}
},
checkTargets : function( element )
{
for ( var name in this.options.controls )
{
var control = this.options.controls[name];
var className = control.className || control.command || name || 'empty';
$('.' + className, this.panel).removeClass('active');
if ( control.tags )
{
var elm = element;
do {
if ( elm.nodeType != 1 )
break;
if ( $.inArray(elm.tagName.toLowerCase(), control.tags) != -1 )
$('.' + className, this.panel).addClass('active');
} while ( elm = elm.parentNode );
}
if ( control.css )
{
var elm = $(element);
do {
if ( elm[0].nodeType != 1 )
break;
for ( var cssProperty in control.css )
if ( elm.css(cssProperty).toString().toLowerCase() == control.css[cssProperty] )
$('.' + className, this.panel).addClass('active');
} while ( elm = elm.parent() );
}
}
},
getElementByAttributeValue : function( tagName, attributeName, attributeValue )
{
var elements = this.editorDoc.getElementsByTagName(tagName);
for ( var i = 0; i < elements.length; i++ )
{
var value = elements[i].getAttribute(attributeName);
if ( $.browser.msie )
{
/** IE add full path, so I check by the last chars. */
value = value.substr(value.length - attributeValue.length);
}
if ( value == attributeValue )
return elements[i];
}
return false;
}
});
})(jQuery);
做些小改动
(function( $ )
{
$.fn.document = function()
{
var element = this[0];
if ( element.nodeName.toLowerCase() == 'iframe' )
return element.contentWindow.document;
/*
return ( $.browser.msie )
? document.frames[element.id].document
: element.contentWindow.document // contentDocument;
*/
else
return $(this);
};
$.fn.documentSelection = function()
{
var element = this[0];
if ( element.contentWindow.document.selection )
return element.contentWindow.document.selection.createRange().text;
else
return element.contentWindow.getSelection().toString();
};
$.fn.wysiwyg = function( options )
{
if ( arguments.length > 0 && arguments[0].constructor == String )
{
var action = arguments[0].toString();
var params = [];
for ( var i = 1; i < arguments.length; i++ )
params[i - 1] = arguments[i];
if ( action in Wysiwyg )
{ var r;
this.each(function()
{
$.data(this, 'wysiwyg')
.designMode();
r=Wysiwyg[action].apply(this, params);
});
if(r!==undefined)return r;
}
return this;
}
var controls = {};
/**
* If the user set custom controls, we catch it, and merge with the
* defaults controls later.
*/
if ( options && options.controls )
{
var controls = options.controls;
delete options.controls;
}
var options = $.extend({
html : '<'+'?xml version="1.0" encoding="UTF-8"?'+'><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">STYLE_SHEET</head><body>INITIAL_CONTENT</body></html>',
css : {},
debug : false,
autoSave : true, // http://code.google.com/p/jwysiwyg/issues/detail?id=11
rmUnwantedBr : true, // http://code.google.com/p/jwysiwyg/issues/detail?id=15
brIE : true,
controls : {},
messages : {}
}, options);
options.messages = $.extend(true, options.messages, Wysiwyg.MSGS_EN);
options.controls = $.extend(true, options.controls, Wysiwyg.TOOLBAR);
for ( var control in controls )
{
if ( control in options.controls )
$.extend(options.controls[control], controls[control]);
else
options.controls[control] = controls[control];
}
// not break the chain
return this.each(function()
{
Wysiwyg(this, options);
});
};
function Wysiwyg( element, options )
{
return this instanceof Wysiwyg
? this.init(element, options)
: new Wysiwyg(element, options);
}
$.extend(Wysiwyg, {
insertImage : function( szURL, attributes )
{
var self = $.data(this, 'wysiwyg');
if ( self.constructor == Wysiwyg && szURL && szURL.length > 0 )
{
if ( attributes )
{
self.editorDoc.execCommand('insertImage', false, '#jwysiwyg#');
var img = self.getElementByAttributeValue('img', 'src', '#jwysiwyg#');
if ( img )
{
img.src = szURL;
for ( var attribute in attributes )
{
img.setAttribute(attribute, attributes[attribute]);
}
}
}
else
{
self.editorDoc.execCommand('insertImage', false, szURL);
}
}
},
createLink : function( szURL )
{
var self = $.data(this, 'wysiwyg');
if ( self.constructor == Wysiwyg && szURL && szURL.length > 0 )
{
var selection = $(self.editor).documentSelection();
if ( selection.length > 0 )
{
self.editorDoc.execCommand('unlink', false, []);
self.editorDoc.execCommand('createLink', false, szURL);
}
else if ( self.options.messages.nonSelection )
alert(self.options.messages.nonSelection);
}
},
getContent : function (newContent){
var self = $.data(this, 'wysiwyg');
return self.getContent()
},
setContent : function( newContent )
{
var self = $.data(this, 'wysiwyg');
self.setContent( newContent );
self.saveContent();
},
clear : function()
{
var self = $.data(this, 'wysiwyg');
self.setContent('');
self.saveContent();
},
MSGS_EN : {
nonSelection : 'select the text you wish to link'
},
TOOLBAR : {
bold : { visible : true, tags : ['b', 'strong'], css : { fontWeight : 'bold' } },
italic : { visible : true, tags : ['i', 'em'], css : { fontStyle : 'italic' } },
strikeThrough : { visible : true, tags : ['s', 'strike'], css : { textDecoration : 'line-through' } },
underline : { visible : true, tags : ['u'], css : { textDecoration : 'underline' } },
separator00 : { visible : false, separator : true },
justifyLeft : { visible : true, css : { textAlign : 'left' } },
justifyCenter : { visible : true, tags : ['center'], css : { textAlign : 'center' } },
justifyRight : { visible : true, css : { textAlign : 'right' } },
justifyFull : { visible : false, css : { textAlign : 'justify' } },
separator01 : { visible : false, separator : true },
indent : { visible : false },
outdent : { visible : false },
separator02 : { visible : false, separator : true },
subscript : { visible : false, tags : ['sub'] },
superscript : { visible : false, tags : ['sup'] },
separator03 : { visible : false, separator : true },
undo : { visible : false },
redo : { visible : false },
separator04 : { visible : false, separator : true },
insertOrderedList : { visible : false, tags : ['ol'] },
insertUnorderedList : { visible : false, tags : ['ul'] },
insertHorizontalRule : { visible : false, tags : ['hr'] },
separator05 : { separator : true },
createLink : {
visible : true,
exec : function()
{
var selection = $(this.editor).documentSelection();
if ( selection.length > 0 )
{
if ( $.browser.msie )
this.editorDoc.execCommand('createLink', true, null);
else
{
var szURL = prompt('URL', 'http://');
if ( szURL && szURL.length > 0 )
{
this.editorDoc.execCommand('unlink', false, []);
this.editorDoc.execCommand('createLink', false, szURL);
}
}
}
else if ( this.options.messages.nonSelection )
alert(this.options.messages.nonSelection);
},
tags : ['a']
},
insertImage : {
visible : true,
exec : function()
{
if ( $.browser.msie )
this.editorDoc.execCommand('insertImage', true, null);
else
{
var szURL = prompt('URL', 'http://');
if ( szURL && szURL.length > 0 )
this.editorDoc.execCommand('insertImage', false, szURL);
}
},
tags : ['img']
},
separator06 : { separator : true ,visible : false},
h1mozilla : { visible : false && $.browser.mozilla, className : 'h1', command : 'heading', arguments : ['h1'], tags : ['h1'] },
h2mozilla : { visible : false && $.browser.mozilla, className : 'h2', command : 'heading', arguments : ['h2'], tags : ['h2'] },
h3mozilla : { visible : false && $.browser.mozilla, className : 'h3', command : 'heading', arguments : ['h3'], tags : ['h3'] },
h1 : { visible : false && !( $.browser.mozilla ), className : 'h1', command : 'formatBlock', arguments : ['Heading 1'], tags : ['h1'] },
h2 : { visible : false && !( $.browser.mozilla ), className : 'h2', command : 'formatBlock', arguments : ['Heading 2'], tags : ['h2'] },
h3 : { visible : false && !( $.browser.mozilla ), className : 'h3', command : 'formatBlock', arguments : ['Heading 3'], tags : ['h3'] },
separator07 : { visible : false, separator : true },
cut : { visible : false },
copy : { visible : false },
paste : { visible : false },
separator08 : { separator : true && !( $.browser.msie ) },
increaseFontSize : { visible : true ,
exec : function(){
/*
Browser font size 1 -> Safari: 10 px (Actual font size: 8 px)
Browser font size 2 -> Safari: 13 px (Actual font size: 10 px)
Browser font size 3 -> Safari: 16 px (Actual font size: 12 px)
Browser font size 4 -> Safari: 18 px (Actual font size: 14 px)
Browser font size 5 -> Safari: 24 px (Actual font size: 18 px)
Browser font size 6 -> Safari: 32 px (Actual font size: 24 px)
Browser font size 7 -> Safari: 48 px (Actual font size: 36 px)
*/
if($.browser.mozilla){
this.editorDoc.execCommand('increasefontsize',false,[]);
}else{
var sf = {
10:1,13:2,16:3,18:4,24:5,32:6,48:7
}
var font_size = parseInt(this.editorDoc.queryCommandValue('FontSize'));
if(font_size>7)font_size=sf[font_size];
if(font_size&&font_size<7){
this.editorDoc.execCommand('FontSize',false,font_size+1);
}
}
}
},
decreaseFontSize : { visible : true && !( $.browser.msie ), tags : ['small'] },
separator09 : { separator : true },
html : {
visible : false,
exec : function()
{
if ( this.viewHTML )
{
this.setContent( $(this.original).val() );
$(this.original).hide();
}
else
{
this.saveContent();
$(this.original).show();
}
this.viewHTML = !( this.viewHTML );
}
},
removeFormat : {
visible : true,
exec : function()
{
this.editorDoc.execCommand('removeFormat', false, []);
this.editorDoc.execCommand('unlink', false, []);
}
}
}
});
$.extend(Wysiwyg.prototype,
{
original : null,
options : {},
element : null,
editor : null,
init : function( element, options )
{
var self = this;
this.editor = element;
this.options = options || {};
$.data(element, 'wysiwyg', this);
var newX = element.width || element.clientWidth;
var newY = element.height || element.clientHeight;
if ( element.nodeName.toLowerCase() == 'textarea' )
{
this.original = element;
if ( newX == 0 && element.cols )
newX = ( element.cols * 8 ) + 21;
if ( newY == 0 && element.rows )
newY = ( element.rows * 16 ) + 16;
var editor = this.editor = $('<iframe></iframe>').css({
minHeight : ( newY - 6 ).toString() + 'px',
width : ( newX - 8 ).toString() + 'px'
}).attr('id', $(element).attr('id') + 'IFrame');
if ( $.browser.msie )
{
this.editor
.css('height', ( newY ).toString() + 'px');
/**
var editor = $('<span></span>').css({
width : ( newX - 6 ).toString() + 'px',
height : ( newY - 8 ).toString() + 'px'
}).attr('id', $(element).attr('id') + 'IFrame');
editor.outerHTML = this.editor.outerHTML;
*/
}
}
var panel = this.panel = $('<ul></ul>').addClass('panel');
this.appendControls();
this.element = $('<div></div>').css({
width : ( newX > 0 ) ? ( newX ).toString() + 'px' : '100%'
}).addClass('wysiwyg')
.append(panel)
.append( $('<div><!-- --></div>').css({ clear : 'both' }) )
.append(editor);
$(element)
// .css('display', 'none')
.hide()
.before(this.element);
this.viewHTML = false;
this.initialHeight = newY - 8;
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=52
*/
this.initialContent = $(element).val();
this.initFrame();
if ( this.initialContent.length == 0 )
this.setContent('');
if ( this.options.autoSave )
$('form').submit(function() { self.saveContent(); });
$('form').bind('reset', function()
{
self.setContent( self.initialContent );
self.saveContent();
});
},
initFrame : function()
{
var self = this;
var style = '';
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=14
*/
if ( this.options.css && this.options.css.constructor == String )
style = '<link rel="stylesheet" type="text/css" media="screen" href="' + this.options.css + '" />';
this.editorDoc = $(this.editor).document();
this.editorDoc_designMode = false;
try {
this.editorDoc.designMode = 'on';
this.editorDoc_designMode = true;
} catch ( e ) {
// Will fail on Gecko if the editor is placed in an hidden container element
// The design mode will be set ones the editor is focused
$(this.editorDoc).focus(function()
{
self.designMode();
});
}
this.editorDoc.open();
this.editorDoc.write(
this.options.html
.replace(/INITIAL_CONTENT/, this.initialContent)
.replace(/STYLE_SHEET/, style)
);
this.editorDoc.close();
this.editorDoc.contentEditable = 'true';
if ( $.browser.msie )
{
/**
* Remove the horrible border it has on IE.
*/
setTimeout(function() { $(self.editorDoc.body).css('border', 'none'); }, 0);
}
$(this.editorDoc).click(function( event )
{
self.checkTargets( event.target ? event.target : event.srcElement);
});
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=20
*/
$(this.original).focus(function()
{
$(self.editorDoc.body).focus();
});
if ( this.options.autoSave )
{
/**
* @link http://code.google.com/p/jwysiwyg/issues/detail?id=11
*/
$(this.editorDoc).keydown(function() { self.saveContent(); })
.keyup(function() { self.saveContent(); })
.mousedown(function() { self.saveContent(); });
}
if ( this.options.css )
{
setTimeout(function()
{
if ( self.options.css.constructor == String )
{
/**
* $(self.editorDoc)
* .find('head')
* .append(
* $('<link rel="stylesheet" type="text/css" media="screen" />')
* .attr('href', self.options.css)
* );
*/
}
else
$(self.editorDoc).find('body').css(self.options.css);
}, 0);
}
$(this.editorDoc).keydown(function( event )
{
if ( $.browser.msie && self.options.brIE && event.keyCode == 13 )
{
var rng = self.getRange();
rng.pasteHTML('<br />');
rng.collapse(false);
rng.select();
return false;
}
});
},
designMode : function()
{
if ( !( this.editorDoc_designMode ) )
{
try {
this.editorDoc.designMode = 'on';
this.editorDoc_designMode = true;
} catch ( e ) {}
}
},
getSelection : function()
{
return ( window.getSelection ) ? window.getSelection() : document.selection;
},
getRange : function()
{
var selection = this.getSelection();
if ( !( selection ) )
return null;
return ( selection.rangeCount > 0 ) ? selection.getRangeAt(0) : selection.createRange();
},
getContent : function()
{
return $( $(this.editor).document() ).find('body').html();
},
setContent : function( newContent )
{
$( $(this.editor).document() ).find('body').html(newContent);
},
saveContent : function()
{
if ( this.original )
{
var content = this.getContent();
if ( this.options.rmUnwantedBr )
content = ( content.substr(-4) == '<br>' ) ? content.substr(0, content.length - 4) : content;
$(this.original).val(content);
}
},
appendMenu : function( cmd, args, className, fn )
{
var self = this;
var args = args || [];
$('<li></li>').append(
$('<a><!-- --></a>').addClass(className || cmd)
).mousedown(function() {
if ( fn ) fn.apply(self); else self.editorDoc.execCommand(cmd, false, args);
if ( self.options.autoSave ) self.saveContent();
}).appendTo( this.panel );
},
appendMenuSeparator : function()
{
$('<li class="separator"></li>').appendTo( this.panel );
},
appendControls : function()
{
for ( var name in this.options.controls )
{
var control = this.options.controls[name];
if ( control.separator )
{
if ( control.visible !== false )
this.appendMenuSeparator();
}
else if ( control.visible )
{
this.appendMenu(
control.command || name, control.arguments || [],
control.className || control.command || name || 'empty', control.exec
);
}
}
},
checkTargets : function( element )
{
for ( var name in this.options.controls )
{
var control = this.options.controls[name];
var className = control.className || control.command || name || 'empty';
$('.' + className, this.panel).removeClass('active');
if ( control.tags )
{
var elm = element;
do {
if ( elm.nodeType != 1 )
break;
if ( $.inArray(elm.tagName.toLowerCase(), control.tags) != -1 )
$('.' + className, this.panel).addClass('active');
} while ( elm = elm.parentNode );
}
if ( control.css )
{
var elm = $(element);
do {
if ( elm[0].nodeType != 1 )
break;
for ( var cssProperty in control.css )
if ( elm.css(cssProperty).toString().toLowerCase() == control.css[cssProperty] )
$('.' + className, this.panel).addClass('active');
} while ( elm = elm.parent() );
}
}
},
getElementByAttributeValue : function( tagName, attributeName, attributeValue )
{
var elements = this.editorDoc.getElementsByTagName(tagName);
for ( var i = 0; i < elements.length; i++ )
{
var value = elements[i].getAttribute(attributeName);
if ( $.browser.msie )
{
/** IE add full path, so I check by the last chars. */
value = value.substr(value.length - attributeValue.length);
}
if ( value == attributeValue )
return elements[i];
}
return false;
}
});
})(jQuery);
发表评论
-
gz后仅5.5K的Rich Editor
2009-12-24 14:31 2033http://kissy.googlecode.com/sv ... -
windows监控目录改动
2009-07-30 16:30 3300先安装 http://sourceforge.net/proj ... -
每天写一点web框架 5
2009-07-29 23:31 1542继续 http://blog.html.it/layoutg ... -
每天写一点web框架 4
2009-07-28 10:02 1320昨天有事出差,先补上一篇 先 easy_install we ... -
每天写一点web框架 3
2009-07-26 11:22 1296http://code.google.com/p/zpyweb ... -
每天写一点web框架 2
2009-07-25 21:37 1241今天把url route弄好了 http://code.goo ... -
每天写一点web框架 1
2009-07-24 17:32 1444打算开始写一个web框架了 有空就写一点吧 今天写的是模 ... -
linux 命令 zcat , pgrep
2009-07-15 01:43 4805http://www.ibm.com/developerwor ... -
Tokyo Dystopia 全文搜索
2009-07-13 10:33 2242http://d.hatena.ne.jp/perezvon/ ... -
随笔...
2009-05-21 01:00 12311. 交换机的东西我一点不懂 今晚学了一点. 100M 电 ... -
linux下安装dns本地缓存
2009-04-12 12:04 4295linux的版本是gentoo 写爬虫不用dns缓存很容易就 ... -
事前审查系统设计思路整理
2009-03-18 18:17 1491整理一下思路 先定义一个函数 function 发表函数( ... -
顺手写的一个tab样式
2009-03-02 16:39 2219<!DOCTYPE HTML PUBLIC &quo ... -
备忘:MySQL InnoDB Error "the table is full"
2009-02-23 13:16 3609http://blog.imminentweb.com/te ... -
LucidDB 备忘
2009-02-21 00:04 3341http://en.wikipedia.org/wiki ... -
js高亮关键词代码备忘
2009-02-17 11:42 2543当然是抄的啊:) 管理后台用这个很方便 <!DOCTY ... -
google reader 的 prompt 函数
2009-01-27 11:40 1671IE7对prompt做了限制,MS的产品部门真是好奇怪... ... -
jquery 1.3 event模型(消息<->订阅者)
2009-01-21 17:18 13281.3中对event进行改版,现在$(xxx).click等等 ... -
js抄袭笔记 -- 飞出
2009-01-20 15:39 1349这个博客http://james.padolsey.com ... -
js抄袭笔记 -- 完美黑屏
2009-01-20 15:23 1548好处: 1.考虑了resize 2.考虑了页面宽度不足一屏幕 ...
相关推荐
所见即所得的jQuery富文本编辑器插件-wysiwyg.js
在线编辑内容的时候,那些基于 JavaScript 的编辑器帮了我们大忙,这些所见即所得(WYSIWYG)编辑器,给我们提供了类似 Office?的操作体验。如今,任何网站内容管理系统(CMS)和博客系统都需要一个这样的编辑器。...
利用wysiwyg.js开发的一款十分强大的、jQuery富文本编辑器插件,经过优化后的富文本框,打开速度非常快,无报错,不影响其他任何功能。
利用wysiwyg.js开发的一款十分强大的、jQuery富文本编辑器插件,经过优化后的富文本框,打开速度非常快,无报错,不影响其他任何功能。
要求 (建议v.3 +,v.3.2 +) FontAwesome( / ) src/jquery.richtext.min.js src/richtext.min.css初始化编辑器只需在jQuery('textarea')或jQuery('input')字段上调用.richText() jQuery('textarea')也允许使用...
PSEditor是一个开源jQuery插件,它提供了一个WYSIWYG HTML编辑器,该编辑器可以基于CLEditor轻松添加到任何网站中。 有关演示,请参见: 有关下载,请参见: 必需的 :1.10.1+ :1.9.2+ :1.4.4+ jquery....
emojionearea.js是一款可集成EmojiOne表情符号的所见即所得的jQuery文本编辑器插件。emojionearea.js允许你将任何的HTML元素转换为WYSIWYG文本编辑器,并且它能够在编辑器中使用Emojione图标。
script type =" text/javascript " src =" ../scripts/jquery.min.js " > </ script > < script type =" text/javascript " src =" ../scripts/jquery.popline.min.js " > </ script > 或...
wysiwyg.js是一款十分强大的、所见即所得的jQuery富文本编辑器插件。wysiwyg.js富文本编辑器体积小,支持选择、键盘、占位等众多事件。而且该富文本编辑器的兼容性十分好,甚至兼容IE6。
matlab更改代码字体角度WYSIWYG.JS组件 使用的角度所见即所得编辑器组件。 它还用于代码高亮处理。 先决条件-依赖关系 jQuery(wysiwygjs库可选) fontawesome(wysiwygjs libary必需) pyramidjs(此组件使用的代码...
Htmle 另一个jQuery HTML WYSIWYG插件如下图所示,Htmle具有一组最常用的编辑功能。 可以自定义Htmle,以仅显示所需的控件。 它没有繁重的设计主题,因此您可以轻松更改其css以适合您网站的主题。先决条件真棒字体:...
jQuery Te Rails jQuery TE是一个jQuery插件。 它是一个轻量级的(19.5 KB)并且非常有用HTML编辑器。 它与所见即所得模型一起使用。 jQuery TE是根据MIT许可提供的。 请查看所有积分都jQuery文本编辑器团队的Fatih ...
bootstrap3-wysiwyg是一款简单实用的基于Bootstrap3所见即所得的jQuery文本编辑器插件。该文本编辑器使用简单,支持多国语言,适用于需要简单文本编辑的场合。
Z-Blog是一套基于ASP平台的开放、高效、健壮、实用、美观的Blog发布程序。拥有以下优秀特性:生成静态文件、完全符合网页标准、高度可制定化模板...在common.js里集成了最新版的jquery. 12.移除了引用功能和相关的菜单
Adding LESS files as well as Javascript client-side template files such as Mustache. (now available) Please note that support is provided via email as mentioned in the documentation page.
Mindmup Wysiwyg Editor Toopay Markdown Editor 1.1.4 X-editable 1.4.6 Select2 3.4.2 Bootstrap Tags 2.2.5 jQuery Mobile 1.3.2 (Custom Build) jqGrid 4.5.2 Dropzone.js 3.0 Nestable lists plugin ...
Froala Editor 基于HTML5的精美WYSIWYG HTML编辑器,是最强大的JavaScript富文本编辑器之一 Froala Editor Froala WYSIWYG HTML Editor 是有...开始使用 Froala WYSIWYG HTML 编辑器需要 jQuery 1.11.0 或更高版本和名
emojionearea.js是一款可集成EmojiOne表情符号的所见即所得的jQuery文本编辑器插件。emojionearea.js允许你将任何的HTML元素转换为WYSIWYG文本编辑器,并且它能够在编辑器中使用Emojione图标。