Sha256: 9a6ebeffd8f75c891f3582276abb6f920be3fd518702e7165447a23d9bcec915

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

/*!
 * Aloha Editor
 * Author & Copyright (c) 2010 Gentics Software GmbH
 * aloha-sales@gentics.com
 * Licensed unter the terms of http://www.aloha-editor.com/license.html
 */
define(
['aloha/jquery', 'aloha/registry'],
function( jQuery, Registry ) {
	

	/**
	 * Create an contentHandler from the given definition. Acts as a factory method
	 * for contentHandler.
	 *
	 * @param {Object} definition
	 */
	return new ( Registry.extend({

		createHandler: function( definition ) {
			
			if ( typeof definition.handleContent != 'function' ) {
				throw 'ContentHandler has no function handleContent().';
			}

			var AbstractContentHandler = Class.extend({
				handleContent: function( content ) {
					// Implement in subclass!
				}
			}, definition);
			
			return new AbstractContentHandler();
		},
		
		handleContent: function ( content, options ) {
			var handler,
				handlers = this.getEntries();
			
			if ( typeof options.contenthandler === 'undefined') {
				options.contenthandler = [];
				for ( handler in handlers ) {
					if ( handlers.hasOwnProperty(handler) ) {
						options.contenthandler.push(handler);
					}
				}
			}

			for ( handler in handlers ) {
				if ( handlers.hasOwnProperty(handler) ) {
					if (jQuery.inArray( handler, options.contenthandler ) < 0 ) {
						continue;
					}
					
					if ( typeof handlers[handler].handleContent === 'function') {
						content = handlers[handler].handleContent( content, options );
					} else {
						console.error( 'A valid content handler needs the method handleContent.' );
					}
				}
			}

			return content;
		}
	}))();
});

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
locomotive-aloha-rails-0.20.1.5 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
aloha-rails-0.0.2 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
locomotive-aloha-rails-0.20.1.4 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
locomotive-aloha-rails-0.20.1.3 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
locomotive-aloha-rails-0.20.1.2 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
locomotive-aloha-rails-0.20.1.1 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
aloha-rails-0.0.1 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js
locomotive-aloha-rails-0.20.1 vendor/assets/javascripts/aloha/lib/aloha/contenthandlermanager.js