Project

General

Profile

Feature #22265 » rtehtmlarea_feature_13796.patch

Administrator Admin, 2010-03-11 05:31

View differences:

typo3/sysext/rtehtmlarea/htmlarea/plugins/RemoveFormat/locallang.xml (copie de travail)
<label index="Cleaning options">Type of formatting to remove</label>
<label index="Formatting:">HTML Formatting:</label>
<label index="MS Word Formatting:">MS Word Formatting:</label>
<label index="Spaces">Non-breaking spaces:</label>
<label index="Images:">Images:</label>
<label index="All HTML:">All HTML tags:</label>
<label index="Select the type of formatting you wish to remove.">Select the type of formatting to remove.</label>
typo3/sysext/rtehtmlarea/htmlarea/plugins/RemoveFormat/popups/removeformat.html (copie de travail)
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!--
/***************************************************************
* Copyright notice
*
* (c) 2005-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
* Remove Format Plugin for TYPO3 htmlArea RTE
*
* TYPO3 SVN ID: $Id$
*/
-->
<head>
<title>Remove formatting</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<script type="text/javascript">
/*<![CDATA[*/
<!--
var dialog = window.opener.HTMLArea.Dialog.RemoveFormat;
function Init() {
dialog.initialize();
var editor = dialog.plugin.editor;
if (!editor._selectionEmpty(editor._getSelection())) document.getElementById('clean_selection').checked = true;
}
function onOK() {
var param = {};
if (document.getElementById('clean_selection').checked) {
param["cleaning_area"] = "selection";
} else {
param["cleaning_area"] = "all";
}
var fields = ["formatting", "ms_formatting", "images", "html_all"];
oneChecked = false;
for (var i=0; i<fields.length; i++) {
var id = fields[i];
var el = document.getElementById(id);
if (el.checked) {
param[id] = true;
oneChecked = true;
}
}
if (oneChecked) {
dialog.performAction(param);
dialog.close();
} else {
alert(dialog.plugin.localize("Select the type of formatting you wish to remove."));
}
return false;
};
function onCancel() {
dialog.close();
return false;
}
// -->
/*]]>*/
</script>
</head>
<body class="popupwin htmlarea-remove-format" onload="Init();">
<div id="content">
<div class="title">Remove formatting</div>
<form action="" method="get">
<fieldset>
<legend>Cleaning Area</legend>
<div>
<label for="clean_selection">Selection</label> <input type="radio" name="cleaning_area" id="clean_selection" value="selection" />
<label for="clean_page">All</label> <input type="radio" name="cleaning_area" id="clean_page" value="page" checked="checked" />
</div>
</fieldset>
<fieldset>
<legend>Cleaning options</legend>
<div>
<label class="fl" for="formatting">Formatting:</label>
<input type="checkbox" id="formatting" value="" />
</div>
<div>
<label class="fl" for="ms_formatting">MS Word Formatting:</label>
<input type="checkbox" id="ms_formatting" value="" checked="checked" />
</div>
<div>
<label class="fl" for="images">Images:</label>
<input type="checkbox" id="images" value="" />
</div>
<div>
<label class="fl" for="html_all">All HTML:</label>
<input type="checkbox" id="html_all" value="" />
</div>
</fieldset>
<div class="buttons">
<button type="button" name="ok" onclick="return onOK();">OK</button>
<button type="button" name="cancel" onclick="return onCancel();">Cancel</button>
</div>
</form>
</div>
</body>
</html>
typo3/sysext/rtehtmlarea/htmlarea/plugins/RemoveFormat/remove-format.js (copie de travail)
* TYPO3 SVN ID: $Id$
*/
RemoveFormat = HTMLArea.Plugin.extend({
constructor : function(editor, pluginName) {
constructor: function(editor, pluginName) {
this.base(editor, pluginName);
},
/*
* This function gets called by the class constructor
*/
configurePlugin : function(editor) {
configurePlugin: function(editor) {
/*
* Registering plugin "About" information
*/
var pluginInformation = {
version : "1.7",
developer : "Stanislas Rolland",
developerUrl : "http://www.sjbr.ca/",
copyrightOwner : "Stanislas Rolland",
sponsor : "SJBR",
sponsorUrl : "http://www.sjbr.ca/",
license : "GPL"
version : '2.0',
developer : 'Stanislas Rolland',
developerUrl : 'http://www.sjbr.ca/',
copyrightOwner : 'Stanislas Rolland',
sponsor : 'SJBR',
sponsorUrl : 'http://www.sjbr.ca/',
license : 'GPL'
};
this.registerPluginInformation(pluginInformation);
/*
* Registering the button
*/
var buttonId = "RemoveFormat";
var buttonId = 'RemoveFormat';
var buttonConfiguration = {
id : buttonId,
tooltip : this.localize(buttonId+"Tooltip"),
action : "onButtonPress",
tooltip : this.localize(buttonId + 'Tooltip'),
action : 'onButtonPress',
dialog : true
};
this.registerButton(buttonConfiguration);
this.popupWidth = 370;
this.popupHeight = 260;
return true;
},
/*
* This function gets called when the button was pressed.
*
......
*
* @return boolean false if action is completed
*/
onButtonPress : function (editor, id, target) {
onButtonPress: function (editor, id, target) {
// Could be a button or its hotkey
var buttonId = this.translateHotKey(id);
buttonId = buttonId ? buttonId : id;
this.dialog = this.openDialog("RemoveFormat", this.makeUrlFromPopupName("removeformat"), "applyRequest", null, {width:this.popupWidth, height:this.popupHeight});
// Open dialogue window
this.openDialogue(
buttonId,
'Remove formatting',
this.getWindowDimensions(
{
width: 260,
height:260
},
buttonId
)
);
return false;
},
/*
* Open the dialogue window
*
* @param string buttonId: the button id
* @param string title: the window title
* @param object dimensions: the opening dimensions of the window
*
* @return void
*/
openDialogue: function (buttonId, title, dimensions) {
this.dialog = new Ext.Window({
title: this.localize(title),
cls: 'htmlarea-window',
border: false,
width: dimensions.width,
height: 'auto',
// As of ExtJS 3.1, JS error with IE when the window is resizable
resizable: !Ext.isIE,
iconCls: buttonId,
listeners: {
close: {
fn: this.onClose,
scope: this
}
},
items: [{
xtype: 'fieldset',
title: this.localize('Cleaning Area'),
defaultType: 'radio',
labelWidth: 150,
defaults: {
labelSeparator: ''
},
items: [{
itemId: 'selection',
fieldLabel: this.localize('Selection'),
name: 'htmlarea-removeFormat-area'
},{
itemId: 'allContent',
fieldLabel: this.localize('All'),
checked: true,
name: 'htmlarea-removeFormat-area'
}
]
},{
xtype: 'fieldset',
defaultType: 'checkbox',
title: this.localize('Cleaning options'),
labelWidth: 150,
defaults: {
labelSeparator: ''
},
items: [{
itemId: 'formatting',
fieldLabel: this.localize('Formatting:')
},{
itemId: 'msWordFormatting',
fieldLabel: this.localize('MS Word Formatting:'),
checked: true
},{
itemId: 'spaces',
fieldLabel: this.localize('Spaces')
},{
itemId: 'images',
fieldLabel: this.localize('Images:')
},{
itemId: 'allHtml',
fieldLabel: this.localize('All HTML:')
}
]
}
],
buttons: [
this.buildButtonConfig('OK', this.onOK),
this.buildButtonConfig('Cancel', this.onCancel)
]
});
this.show();
},
/*
* Handler when the OK button is pressed
*/
onOK: function () {
var fields = [
'selection',
'allContent',
'formatting',
'msWordFormatting',
'spaces',
'images',
'allHtml'
];
var params = {};
Ext.each(fields, function (field) {
params[field] = this.dialog.find('itemId', field)[0].getValue();
}, this);
if (params['allHtml'] || params['formatting'] || params['spaces'] || params['images'] || params['msWordFormatting']) {
this.applyRequest(params);
} else {
Ext.MessageBox.alert('', this.localize('Select the type of formatting you wish to remove.'));
}
return false;
},
/*
* Perform the cleaning request
* .
* @param object params: the values of the form fields
*
* @return void
*/
applyRequest : function(param) {
applyRequest: function(params) {
var editor = this.editor;
editor.focusEditor();
if (param) {
if (param["cleaning_area"] == "all") {
var html = editor._doc.body.innerHTML;
} else {
var html = editor.getSelectedHTML();
}
if (html) {
if (param["html_all"]== true) {
html = html.replace(/<[\!]*?[^<>]*?>/g, "");
}
if (param["formatting"] == true) {
// remove font, b, strong, i, em, u, strike, span and other tags
var regF1 = new RegExp("<\/?(abbr|acronym|b[^a-zA-Z]|big|cite|code|em[^a-zA-Z]|font|i[^a-zA-Z]|q|s[^a-zA-Z]|samp|small|span|strike|strong|sub|sup|u[^a-zA-Z]|var)[^>]*>", "gi");
html = html.replace(regF1, "");
// keep tags, strip attributes
var regF2 = new RegExp(" style=\"[^>\"]*\"", "gi");
var regF3 = new RegExp(" (class|align|cellpadding|cellspacing|frame|bgcolor)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
html = html.replace(regF2, "").replace(regF3, "");
}
if (param["images"] == true) {
// remove any IMG tag
html = html.replace(/<\/?img[^>]*>/gi, ""); //remove img tags
}
if (param["ms_formatting"] == true) {
// make one line
var regMS1 = new RegExp("(\r\n|\n|\r)", "g");
html = html.replace(regMS1, " ");
//clean up tags
var regMS2 = new RegExp("<(b[^r]|strong|i|em|p|li|ul) [^>]*>", "gi");
html = html.replace(regMS2, "<$1>");
// keep tags, strip attributes
var regMS3 = new RegExp(" style=\"[^>\"]*\"", "gi");
var regMS4 = new RegExp(" (class|align)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
html = html.replace(regMS3, "").replace(regMS4, "");
// mozilla doesn't like <em> tags
html = html.replace(/<em>/gi, "<i>").replace(/<\/em>/gi, "</i>");
// kill unwanted tags: span, div, ?xml:, st1:, [a-z]:, meta, link
html = html.replace(/<\/?span[^>]*>/gi, "").
replace(/<\/?div[^>]*>/gi, "").
replace(/<\?xml:[^>]*>/gi, "").
replace(/<\/?st1:[^>]*>/gi, "").
replace(/<\/?[a-z]:[^>]*>/g, "").
replace(/<\/?meta[^>]*>/g, "").
replace(/<\/?link[^>]*>/g, "");
// remove unwanted tags and their contents: style, title
html = html.replace(/<style[^>]*>.*<\/style[^>]*>/gi, "").
replace(/<title[^>]*>.*<\/title[^>]*>/gi, "");
// remove comments
html = html.replace(/<!--[^>]*>/gi, "");
editor.focus();
this.restoreSelection();
if (params['allContent']) {
var html = editor.getInnerHTML();
} else {
var html = editor.getSelectedHTML();
}
if (html) {
if (params['allHtml']) {
html = html.replace(/<[\!]*?[^<>]*?>/g, "");
}
if (params['formatting']) {
// remove font, b, strong, i, em, u, strike, span and other tags
var regF1 = new RegExp("<\/?(abbr|acronym|b[^a-zA-Z]|big|cite|code|em[^a-zA-Z]|font|i[^a-zA-Z]|q|s[^a-zA-Z]|samp|small|span|strike|strong|sub|sup|u[^a-zA-Z]|var)[^>]*>", "gi");
html = html.replace(regF1, "");
// keep tags, strip attributes
var regF2 = new RegExp(" style=\"[^>\"]*\"", "gi");
var regF3 = new RegExp(" (class|align|cellpadding|cellspacing|frame|bgcolor)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
html = html.replace(regF2, "").replace(regF3, "");
}
if (params['spaces']) {
// Replace non-breaking spaces by normal spaces
html = html.replace(/&nbsp;/g, " ");
}
if (params['images']) {
// remove any IMG tag
html = html.replace(/<\/?img[^>]*>/gi, "");
}
if (params['msWordFormatting']) {
// make one line
var regMS1 = new RegExp("(\r\n|\n|\r)", "g");
html = html.replace(regMS1, " ");
//clean up tags
var regMS2 = new RegExp("<(b[^r]|strong|i|em|p|li|ul) [^>]*>", "gi");
html = html.replace(regMS2, "<$1>");
// keep tags, strip attributes
var regMS3 = new RegExp(" style=\"[^>\"]*\"", "gi");
var regMS4 = new RegExp(" (class|align)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
html = html.replace(regMS3, "").replace(regMS4, "");
// mozilla doesn't like <em> tags
html = html.replace(/<em>/gi, "<i>").replace(/<\/em>/gi, "</i>");
// kill unwanted tags: span, div, ?xml:, st1:, [a-z]:, meta, link
html = html.replace(/<\/?span[^>]*>/gi, "").
replace(/<\/?div[^>]*>/gi, "").
replace(/<\?xml:[^>]*>/gi, "").
replace(/<\/?st1:[^>]*>/gi, "").
replace(/<\/?[a-z]:[^>]*>/g, "").
replace(/<\/?meta[^>]*>/g, "").
replace(/<\/?link[^>]*>/g, "");
// remove unwanted tags and their contents: style, title
html = html.replace(/<style[^>]*>.*<\/style[^>]*>/gi, "").
replace(/<title[^>]*>.*<\/title[^>]*>/gi, "");
// remove comments
html = html.replace(/<!--[^>]*>/gi, "");
// remove double tags
oldlen = html.length + 1;
var reg6 = new RegExp("<([a-z][a-z]*)> *<\/\1>", "gi");
var reg7 = new RegExp("<([a-z][a-z]*)> *<\/?([a-z][^>]*)> *<\/\1>", "gi");
var reg8 = new RegExp("<([a-z][a-z]*)><\1>", "gi");
var reg9 = new RegExp("<\/([a-z][a-z]*)><\/\1>", "gi");
var reg10 = new RegExp("[\x20]+", "gi");
while(oldlen > html.length) {
oldlen = html.length;
// join us now and free the tags
html = html.replace(reg6, " ").replace(reg7, "<$2>");
// remove double tags
oldlen = html.length + 1;
var reg6 = new RegExp("<([a-z][a-z]*)> *<\/\1>", "gi");
var reg7 = new RegExp("<([a-z][a-z]*)> *<\/?([a-z][^>]*)> *<\/\1>", "gi");
var reg8 = new RegExp("<([a-z][a-z]*)><\1>", "gi");
var reg9 = new RegExp("<\/([a-z][a-z]*)><\/\1>", "gi");
var reg10 = new RegExp("[\x20]+", "gi");
while(oldlen > html.length) {
oldlen = html.length;
// join us now and free the tags
html = html.replace(reg6, " ").replace(reg7, "<$2>");
// remove double tags
html = html.replace(reg8, "<$1>").replace(reg9, "<\/$1>");
// remove double spaces
html = html.replace(reg10, " ");
}
html = html.replace(reg8, "<$1>").replace(reg9, "<\/$1>");
// remove double spaces
html = html.replace(reg10, " ");
}
if (param["cleaning_area"] == "all") {
editor.setHTML(html);
} else {
editor.insertHTML(html);
}
}
} else {
return false;
if (params['allContent']) {
editor.setHTML(html);
} else {
editor.insertHTML(html);
}
}
}
});
(1-1/2)