Вход Регистрация
Файл: public/js/3rd_party/ckeditor/plugins/stylesheetparser/plugin.js
Строк: 135
<?php

/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

/**
 * @stylesheetParser plugin.
 */

(function()
{
    
// We want to extract only the elements with classes defined in the stylesheets:
    
function parseClassesaRulesskipSelectorsvalidSelectors )
    {
        
// 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 aRules.join(' ');
        
// Remove selectors splitting the elements, leave only the class selector (.)
        
s.replace( /(,|>|+|~)/g' ' );
        
// Remove attribute selectors: table[border="0"]
        
s.replace( /[[^]]*/g'' );
        
// Remove Ids: div#main
        
s.replace( /#[^s]*/g, '' );
        // Remove pseudo-selectors and pseudo-elements: :hover :nth-child(2n+1) ::before
        
s.replace( /:{1,2}[^s]*/g'' );

        
s.replace( /s+/g' ' );

        var 
aSelectors s.split' ' ),
            
aClasses = [];

        for ( var 
0aSelectors.length i++ )
        {
            var 
selector aSelectors];

            if ( 
validSelectors.testselector ) && !skipSelectors.testselector ) )
            {
                
// If we still don't know about this one, add it
                
if ( CKEDITOR.tools.indexOfaClassesselector ) == -)
                    
aClasses.pushselector );
            }
        }

        return 
aClasses;
    }

    function 
LoadStylesCSStheDocskipSelectorsvalidSelectors )
    {
        var 
styles = [],
            
// It will hold all the rules of the applied stylesheets (except those internal to CKEditor)
            
aRules = [],
            
i;

        for ( 
0theDoc.styleSheets.lengthi++ )
        {
            var 
sheet theDoc.styleSheets],
                
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(09) == 'chrome://' )
                continue;

            var 
sheetRules sheet.cssRules || sheet.rules;
            for ( var 
0sheetRules.lengthj++ )
                
aRules.pushsheetRules].selectorText );
        }

        var 
aClasses parseClassesaRulesskipSelectorsvalidSelectors );

        
// Add each style to our "Styles" collection.
        
for ( 0aClasses.lengthi++ )
        {
            var 
oElement aClasses].split'.' ),
                
element oElement].toLowerCase(),
                
sClassName oElement];

            
styles.push( {
                
name element '.' sClassName,
                
element element,
                
attributes : {'class' sClassName}
            });
        }

        return 
styles;
    }

    
// Register a plugin named "stylesheetparser".
    
CKEDITOR.plugins.add'stylesheetparser',
    {
        
requires: [ 'styles' ],
        
onLoad : function()
        {
            var 
obj CKEDITOR.editor.prototype;
            
obj.getStylesSet CKEDITOR.tools.overrideobj.getStylesSet,  function( org )
            {
                return function( 
callback )
                {
                    var 
self this;
                    
org.callthis, function( definitions )
                    {
                        
// Rules that must be skipped
                        
var skipSelectors self.config.stylesheetParser_skipSelectors || ( /(^body.|^.)/),
                            
// Rules that are valid
                            
validSelectors self.config.stylesheetParser_validSelectors || ( /w+.w+/ );

                        
callback( ( self._.stylesDefinitions definitions.concatLoadStylesCSSself.document.$, skipSelectorsvalidSelectors ) ) ) );
                    });
                };
            });

        }
    });
})();


/**
 * 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.
 * @name CKEDITOR.config.stylesheetParser_skipSelectors
 * @type RegExp
 * @default /(^body.|^.)/i
 * @since 3.6
 * @see CKEDITOR.config.stylesheetParser_validSelectors
 * @example
 * // 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;
 */

 /**
 * 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.
 * @name CKEDITOR.config.stylesheetParser_validSelectors
 * @type RegExp
 * @default /w+.w+/
 * @since 3.6
 * @see CKEDITOR.config.stylesheetParser_skipSelectors
 * @example
 * // Only add rules for p and span elements.
 * config.stylesheetParser_validSelectors = /^(p|span).w+/;
 */
?>
Онлайн: 0
Реклама