mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-12 11:55:09 +00:00
HTML composition, take 2
Monotone-Parent: dbd490c81ea6cac4c12b2e17661e2fef43219e68 Monotone-Revision: 0801dc9f1e4fdc49ea44fc0450fb025c2639ed26 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-06-25T19:18:02 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
(function()
|
||||
{
|
||||
var doc = CKEDITOR.document;
|
||||
|
||||
var listId = 'cke' + CKEDITOR.tools.getNextNumber();
|
||||
|
||||
// Constructs the HTML view of the specified templates data.
|
||||
function renderTemplatesList( editor, templatesDefinitions )
|
||||
{
|
||||
var listDiv = doc.getById( listId );
|
||||
|
||||
// clear loading wait text.
|
||||
listDiv.setHtml( '' );
|
||||
|
||||
for ( var i = 0 ; i < templatesDefinitions.length ; i++ )
|
||||
{
|
||||
var definition = CKEDITOR.getTemplates( templatesDefinitions[ i ] ),
|
||||
imagesPath = definition.imagesPath,
|
||||
templates = definition.templates;
|
||||
|
||||
for ( var j = 0 ; j < templates.length ; j++ )
|
||||
{
|
||||
var template = templates[ j ];
|
||||
listDiv.append( createTemplateItem( editor, template, imagesPath ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createTemplateItem( editor, template, imagesPath )
|
||||
{
|
||||
var div = doc.createElement( 'div' );
|
||||
div.setAttribute( 'class', 'cke_tpl_item' );
|
||||
|
||||
// Build the inner HTML of our new item DIV.
|
||||
var html = '<table style="width:350px;" class="cke_tpl_preview"><tr>';
|
||||
|
||||
if( template.image && imagesPath )
|
||||
html += '<td class="cke_tpl_preview_img"><img src="' + CKEDITOR.getUrl( imagesPath + template.image ) + '"></td>';
|
||||
|
||||
html += '<td style="white-space:normal;"><span class="cke_tpl_title">' + template.title + '</span><br/>';
|
||||
|
||||
if( template.description )
|
||||
html += '<span>' + template.description + '</span>';
|
||||
|
||||
html += '</td></tr></table>';
|
||||
|
||||
div.setHtml( html );
|
||||
|
||||
div.on( 'mouseover', function()
|
||||
{
|
||||
div.addClass( 'cke_tpl_hover' );
|
||||
});
|
||||
|
||||
div.on( 'mouseout', function()
|
||||
{
|
||||
div.removeClass( 'cke_tpl_hover' );
|
||||
});
|
||||
|
||||
div.on( 'click', function()
|
||||
{
|
||||
insertTemplate( editor, template.html );
|
||||
});
|
||||
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the specified template content
|
||||
* to document.
|
||||
* @param {Number} index
|
||||
*/
|
||||
function insertTemplate( editor, html )
|
||||
{
|
||||
var dialog = CKEDITOR.dialog.getCurrent(),
|
||||
isInsert = dialog.getValueOf( 'selectTpl', 'chkInsertOpt' );
|
||||
|
||||
if( isInsert )
|
||||
{
|
||||
editor.setData( html );
|
||||
}
|
||||
else
|
||||
{
|
||||
editor.insertHtml( html );
|
||||
}
|
||||
|
||||
dialog.hide();
|
||||
}
|
||||
|
||||
CKEDITOR.dialog.add( 'templates', function( editor )
|
||||
{
|
||||
// Load skin at first.
|
||||
CKEDITOR.skins.load( editor, 'templates' );
|
||||
|
||||
/**
|
||||
* Load templates once.
|
||||
*/
|
||||
var isLoaded = false;
|
||||
|
||||
return {
|
||||
title :editor.lang.templates.title,
|
||||
|
||||
minWidth : CKEDITOR.env.ie ? 440 : 400,
|
||||
minHeight : 340,
|
||||
|
||||
contents :
|
||||
[
|
||||
{
|
||||
id :'selectTpl',
|
||||
label : editor.lang.templates.title,
|
||||
elements :
|
||||
[
|
||||
{
|
||||
type : 'vbox',
|
||||
padding : 5,
|
||||
children :
|
||||
[
|
||||
{
|
||||
type : 'html',
|
||||
html :
|
||||
'<span>' +
|
||||
editor.lang.templates.selectPromptMsg +
|
||||
'</span>'
|
||||
},
|
||||
{
|
||||
type : 'html',
|
||||
html :
|
||||
'<div id="' + listId + '" class="cke_tpl_list">' +
|
||||
'<div class="cke_tpl_loading"><span></span></div>' +
|
||||
'</div>'
|
||||
},
|
||||
{
|
||||
id : 'chkInsertOpt',
|
||||
type : 'checkbox',
|
||||
label : editor.lang.templates.insertOption,
|
||||
'default' : editor.config.templates_replaceContent
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
buttons : [ CKEDITOR.dialog.cancelButton ],
|
||||
|
||||
onShow : function()
|
||||
{
|
||||
CKEDITOR.loadTemplates( editor.config.templates_files, function()
|
||||
{
|
||||
var templates = editor.config.templates.split( ',' );
|
||||
|
||||
if ( templates.length )
|
||||
renderTemplatesList( editor, templates );
|
||||
else
|
||||
{
|
||||
var listCtEl = doc.getById( listId );
|
||||
listCtEl.setHtml(
|
||||
'<div class="cke_tpl_empty">' +
|
||||
'<span>' + editor.lang.templates.emptyListMsg + '</span>' +
|
||||
'</div>' );
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
(function()
|
||||
{
|
||||
CKEDITOR.plugins.add( 'templates',
|
||||
{
|
||||
requires : [ 'dialog' ],
|
||||
|
||||
init : function( editor )
|
||||
{
|
||||
CKEDITOR.dialog.add( 'templates', CKEDITOR.getUrl( this.path + 'dialogs/templates.js' ) );
|
||||
|
||||
editor.addCommand( 'templates', new CKEDITOR.dialogCommand( 'templates' ) );
|
||||
|
||||
editor.ui.addButton( 'Templates',
|
||||
{
|
||||
label : editor.lang.templates.button,
|
||||
command : 'templates'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var templates = {},
|
||||
loadedTemplatesFiles = {};
|
||||
|
||||
CKEDITOR.addTemplates = function( name, definition )
|
||||
{
|
||||
templates[ name ] = definition;
|
||||
};
|
||||
|
||||
CKEDITOR.getTemplates = function( name )
|
||||
{
|
||||
return templates[ name ];
|
||||
};
|
||||
|
||||
CKEDITOR.loadTemplates = function( templateFiles, callback )
|
||||
{
|
||||
// Holds the templates files to be loaded.
|
||||
var toLoad = [];
|
||||
|
||||
// Look for pending template files to get loaded.
|
||||
for ( var i = 0 ; i < templateFiles.length ; i++ )
|
||||
{
|
||||
if ( !loadedTemplatesFiles[ templateFiles[ i ] ] )
|
||||
{
|
||||
toLoad.push( templateFiles[ i ] );
|
||||
loadedTemplatesFiles[ templateFiles[ i ] ] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( toLoad.length > 0 )
|
||||
CKEDITOR.scriptLoader.load( toLoad, callback );
|
||||
else
|
||||
setTimeout( callback, 0 );
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The templates definition set to use. It accepts a list of names separated by
|
||||
* comma. It must match definitions loaded with the templates_files setting.
|
||||
* @type String
|
||||
* @default 'default'
|
||||
*/
|
||||
CKEDITOR.config.templates = 'default';
|
||||
|
||||
/**
|
||||
* The list of templates definition files to load.
|
||||
* @type (String) Array
|
||||
* @default [ 'plugins/templates/templates/default.js' ]
|
||||
*/
|
||||
CKEDITOR.config.templates_files =
|
||||
[
|
||||
CKEDITOR.getUrl(
|
||||
'plugins/templates/templates/default.js' )
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether replace the current document content OR insert current
|
||||
* editing position.
|
||||
* @type Boolean
|
||||
* @default true
|
||||
*/
|
||||
CKEDITOR.config.templates_replaceContent = true;
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
// Register a templates definition set named "default".
|
||||
CKEDITOR.addTemplates( 'default',
|
||||
{
|
||||
// The name of sub folder which hold the shortcut preview images of the
|
||||
// templates.
|
||||
imagesPath : CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'templates' ) + 'templates/images/' ),
|
||||
|
||||
// The templates definitions.
|
||||
templates :
|
||||
[
|
||||
{
|
||||
title: 'Image and Title',
|
||||
image: 'template1.gif',
|
||||
description: 'One main image with a title and text that surround the image.',
|
||||
html:
|
||||
'<h3>' +
|
||||
'<img style="margin-right: 10px" height="100" alt="" width="100" align="left"/>' +
|
||||
'Type the title here'+
|
||||
'</h3>' +
|
||||
'<p>' +
|
||||
'Type the text here' +
|
||||
'</p>'
|
||||
},
|
||||
{
|
||||
title: 'Strange Template',
|
||||
image: 'template2.gif',
|
||||
description: 'A template that defines two colums, each one with a title, and some text.',
|
||||
html:
|
||||
'<table cellspacing="0" cellpadding="0" width="100%" border="0">' +
|
||||
'<tr>' +
|
||||
'<td width="50%">' +
|
||||
'<h3>Title 1</h3>' +
|
||||
'</td>' +
|
||||
'<td></td>' +
|
||||
'<td width="50%">' +
|
||||
'<h3>Title 2</h3>' +
|
||||
'</td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td>' +
|
||||
'Text 1' +
|
||||
'</td>' +
|
||||
'<td></td>' +
|
||||
'<td>' +
|
||||
'Text 2' +
|
||||
'</td>' +
|
||||
'</tr>' +
|
||||
'</table>' +
|
||||
'<p>' +
|
||||
'More text goes here.' +
|
||||
'</p>'
|
||||
},
|
||||
{
|
||||
title: 'Text and Table',
|
||||
image: 'template3.gif',
|
||||
description: 'A title with some text and a table.',
|
||||
html:
|
||||
'<div style="width: 80%">' +
|
||||
'<h3>' +
|
||||
'Title goes here' +
|
||||
'</h3>' +
|
||||
'<table style="float: right" cellspacing="0" cellpadding="0" width="150" border="1">' +
|
||||
'<caption style="border:solid 1px black">' +
|
||||
'<strong>Table title</strong>' +
|
||||
'</caption>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'</tr>' +
|
||||
'<tr>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'<td> </td>' +
|
||||
'</tr>' +
|
||||
'</table>' +
|
||||
'<p>' +
|
||||
'Type the text here' +
|
||||
'</p>' +
|
||||
'</div>'
|
||||
}
|
||||
]
|
||||
});
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 375 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 333 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 422 B |
Reference in New Issue
Block a user