mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-04-13 19:26:21 +00:00
first commit
This commit is contained in:
152
lib/ckeditor4/plugins/stylesheetparser/plugin.js
Executable file
152
lib/ckeditor4/plugins/stylesheetparser/plugin.js
Executable file
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
|
||||
* For licensing, see LICENSE.md or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview stylesheetParser plugin.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
// We want to extract only the elements with classes defined in the stylesheets:
|
||||
function parseClasses( aRules, skipSelectors, validSelectors ) {
|
||||
// aRules are just the different rules in the style sheets
|
||||
// We want to merge them and them split them by commas, so we end up with only
|
||||
// the selectors
|
||||
var s = aRules.join( ' ' );
|
||||
// Remove selectors splitting the elements, leave only the class selector (.)
|
||||
s = s.replace( /(,|>|\+|~)/g, ' ' );
|
||||
// Remove attribute selectors: table[border="0"]
|
||||
s = s.replace( /\[[^\]]*/g, '' );
|
||||
// Remove Ids: div#main
|
||||
s = s.replace( /#[^\s]*/g, '' );
|
||||
// Remove pseudo-selectors and pseudo-elements: :hover :nth-child(2n+1) ::before
|
||||
s = s.replace( /\:{1,2}[^\s]*/g, '' );
|
||||
|
||||
s = s.replace( /\s+/g, ' ' );
|
||||
|
||||
var aSelectors = s.split( ' ' ),
|
||||
aClasses = [];
|
||||
|
||||
for ( var i = 0; i < aSelectors.length; i++ ) {
|
||||
var selector = aSelectors[ i ];
|
||||
|
||||
if ( validSelectors.test( selector ) && !skipSelectors.test( selector ) ) {
|
||||
// If we still don't know about this one, add it
|
||||
if ( CKEDITOR.tools.indexOf( aClasses, selector ) == -1 )
|
||||
aClasses.push( selector );
|
||||
}
|
||||
}
|
||||
|
||||
return aClasses;
|
||||
}
|
||||
|
||||
function LoadStylesCSS( theDoc, skipSelectors, validSelectors ) {
|
||||
var styles = [],
|
||||
// It will hold all the rules of the applied stylesheets (except those internal to CKEditor)
|
||||
aRules = [],
|
||||
i;
|
||||
|
||||
for ( i = 0; i < theDoc.styleSheets.length; i++ ) {
|
||||
var sheet = theDoc.styleSheets[ i ],
|
||||
node = sheet.ownerNode || sheet.owningElement;
|
||||
|
||||
// Skip the internal stylesheets
|
||||
if ( node.getAttribute( 'data-cke-temp' ) )
|
||||
continue;
|
||||
|
||||
// Exclude stylesheets injected by extensions
|
||||
if ( sheet.href && sheet.href.substr( 0, 9 ) == 'chrome://' )
|
||||
continue;
|
||||
|
||||
// Bulletproof with x-domain content stylesheet.
|
||||
try {
|
||||
var sheetRules = sheet.cssRules || sheet.rules;
|
||||
for ( var j = 0; j < sheetRules.length; j++ )
|
||||
aRules.push( sheetRules[ j ].selectorText );
|
||||
} catch ( e ) {}
|
||||
}
|
||||
|
||||
var aClasses = parseClasses( aRules, skipSelectors, validSelectors );
|
||||
|
||||
// Add each style to our "Styles" collection.
|
||||
for ( i = 0; i < aClasses.length; i++ ) {
|
||||
var oElement = aClasses[ i ].split( '.' ),
|
||||
element = oElement[ 0 ].toLowerCase(),
|
||||
sClassName = oElement[ 1 ];
|
||||
|
||||
styles.push({
|
||||
name: element + '.' + sClassName,
|
||||
element: element,
|
||||
attributes: { 'class': sClassName }
|
||||
});
|
||||
}
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
// Register a plugin named "stylesheetparser".
|
||||
CKEDITOR.plugins.add( 'stylesheetparser', {
|
||||
init: function( editor ) {
|
||||
// Stylesheet parser is incompatible with filter (#10136).
|
||||
editor.filter.disable();
|
||||
|
||||
var cachedDefinitions;
|
||||
|
||||
editor.once( 'stylesSet', function( evt ) {
|
||||
// Cancel event and fire it again when styles are ready.
|
||||
evt.cancel();
|
||||
|
||||
// Overwrite editor#getStylesSet asap (contentDom is the first moment
|
||||
// when editor.document is ready), but before stylescombo reads styles set (priority 5).
|
||||
editor.once( 'contentDom', function() {
|
||||
editor.getStylesSet( function( definitions ) {
|
||||
// Rules that must be skipped
|
||||
var skipSelectors = editor.config.stylesheetParser_skipSelectors || ( /(^body\.|^\.)/i ),
|
||||
// Rules that are valid
|
||||
validSelectors = editor.config.stylesheetParser_validSelectors || ( /\w+\.\w+/ );
|
||||
|
||||
cachedDefinitions = definitions.concat( LoadStylesCSS( editor.document.$, skipSelectors, validSelectors ) );
|
||||
|
||||
editor.getStylesSet = function( callback ) {
|
||||
if ( cachedDefinitions )
|
||||
return callback( cachedDefinitions );
|
||||
};
|
||||
|
||||
editor.fire( 'stylesSet', { styles: cachedDefinitions } );
|
||||
} );
|
||||
} );
|
||||
}, null, null, 1 );
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression that defines whether a CSS rule will be
|
||||
* skipped by the Stylesheet Parser plugin. A CSS rule matching
|
||||
* the regular expression will be ignored and will not be available
|
||||
* in the Styles drop-down list.
|
||||
*
|
||||
* // Ignore rules for body and caption elements, classes starting with "high", and any class defined for no specific element.
|
||||
* config.stylesheetParser_skipSelectors = /(^body\.|^caption\.|\.high|^\.)/i;
|
||||
*
|
||||
* @since 3.6
|
||||
* @cfg {RegExp} [stylesheetParser_skipSelectors=/(^body\.|^\.)/i]
|
||||
* @member CKEDITOR.config
|
||||
* @see CKEDITOR.config#stylesheetParser_validSelectors
|
||||
*/
|
||||
|
||||
/**
|
||||
* A regular expression that defines which CSS rules will be used
|
||||
* by the Stylesheet Parser plugin. A CSS rule matching the regular
|
||||
* expression will be available in the Styles drop-down list.
|
||||
*
|
||||
* // Only add rules for p and span elements.
|
||||
* config.stylesheetParser_validSelectors = /\^(p|span)\.\w+/;
|
||||
*
|
||||
* @since 3.6
|
||||
* @cfg {RegExp} [stylesheetParser_validSelectors=/\w+\.\w+/]
|
||||
* @member CKEDITOR.config
|
||||
* @see CKEDITOR.config#stylesheetParser_skipSelectors
|
||||
*/
|
||||
70
lib/ckeditor4/plugins/stylesheetparser/samples/assets/sample.css
Executable file
70
lib/ckeditor4/plugins/stylesheetparser/samples/assets/sample.css
Executable file
@@ -0,0 +1,70 @@
|
||||
body
|
||||
{
|
||||
font-family: Arial, Verdana, sans-serif;
|
||||
font-size: 12px;
|
||||
color: #222;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* preserved spaces for rtl list item bullets. (#6249)*/
|
||||
ol,ul,dl
|
||||
{
|
||||
padding-right:40px;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4
|
||||
{
|
||||
font-family: Georgia, Times, serif;
|
||||
}
|
||||
|
||||
h1.lightBlue
|
||||
{
|
||||
color: #00A6C7;
|
||||
font-size: 1.8em;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
h3.green
|
||||
{
|
||||
color: #739E39;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
span.markYellow { background-color: yellow; }
|
||||
span.markGreen { background-color: lime; }
|
||||
|
||||
img.left
|
||||
{
|
||||
padding: 5px;
|
||||
margin-right: 5px;
|
||||
float:left;
|
||||
border:2px solid #DDD;
|
||||
}
|
||||
|
||||
img.right
|
||||
{
|
||||
padding: 5px;
|
||||
margin-right: 5px;
|
||||
float:right;
|
||||
border:2px solid #DDD;
|
||||
}
|
||||
|
||||
a.green
|
||||
{
|
||||
color:#739E39;
|
||||
}
|
||||
|
||||
table.grey
|
||||
{
|
||||
background-color : #F5F5F5;
|
||||
}
|
||||
|
||||
table.grey th
|
||||
{
|
||||
background-color : #DDD;
|
||||
}
|
||||
|
||||
ul.square
|
||||
{
|
||||
list-style-type : square;
|
||||
}
|
||||
82
lib/ckeditor4/plugins/stylesheetparser/samples/stylesheetparser.html
Executable file
82
lib/ckeditor4/plugins/stylesheetparser/samples/stylesheetparser.html
Executable file
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.md or http://ckeditor.com/license
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Using Stylesheet Parser Plugin — CKEditor Sample</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="../../../ckeditor.js"></script>
|
||||
<script src="../../../samples/sample.js"></script>
|
||||
<link rel="stylesheet" href="../../../samples/sample.css">
|
||||
<meta name="ckeditor-sample-required-plugins" content="stylescombo">
|
||||
<meta name="ckeditor-sample-name" content="Stylesheet Parser plugin">
|
||||
<meta name="ckeditor-sample-description" content="Using the Stylesheet Parser plugin to fill the Styles drop-down list based on the CSS classes available in the document stylesheet.">
|
||||
<meta name="ckeditor-sample-group" content="Plugins">
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="samples">
|
||||
<a href="../../../samples/index.html">CKEditor Samples</a> » Using the Stylesheet Parser Plugin
|
||||
</h1>
|
||||
<div class="description">
|
||||
<p>
|
||||
This sample shows how to configure CKEditor instances to use the
|
||||
<strong>Stylesheet Parser</strong> (<code>stylesheetparser</code>) plugin that fills
|
||||
the <strong>Styles</strong> drop-down list based on the CSS rules available in the document stylesheet.
|
||||
</p>
|
||||
<p>
|
||||
To add a CKEditor instance using the <code>stylesheetparser</code> plugin, insert
|
||||
the following JavaScript call into your code:
|
||||
</p>
|
||||
<pre class="samples">
|
||||
CKEDITOR.replace( '<em>textarea_id</em>', {
|
||||
<strong>extraPlugins: 'stylesheetparser'</strong>
|
||||
});</pre>
|
||||
<p>
|
||||
Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of
|
||||
the <code><textarea></code> element to be replaced with CKEditor.
|
||||
</p>
|
||||
</div>
|
||||
<form action="../../../samples/sample_posteddata.php" method="post">
|
||||
<p>
|
||||
<label for="editor1">
|
||||
CKEditor using the <code>stylesheetparser</code> plugin with its default configuration:
|
||||
</label>
|
||||
<textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>
|
||||
<script>
|
||||
|
||||
// This call can be placed at any point after the
|
||||
// <textarea>, or inside a <head><script> in a
|
||||
// window.onload event handler.
|
||||
|
||||
// Replace the <textarea id="editor"> with an CKEditor
|
||||
// instance, using default configurations.
|
||||
CKEDITOR.replace( 'editor1' , {
|
||||
extraPlugins: 'stylesheetparser',
|
||||
|
||||
// Stylesheet for the contents.
|
||||
contentsCss: 'assets/sample.css',
|
||||
|
||||
// Do not load the default Styles configuration.
|
||||
stylesSet: []
|
||||
});
|
||||
|
||||
</script>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Submit">
|
||||
</p>
|
||||
</form>
|
||||
<div id="footer">
|
||||
<hr>
|
||||
<p>
|
||||
CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
|
||||
</p>
|
||||
<p id="copy">
|
||||
Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
|
||||
Knabben. All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user