Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[livejournal] r22638: LJSUP-12123: Font-size select dialog

Committer: anazarov
LJSUP-12123: Font-size select dialog
U   trunk/htdocs/js/ck/config.js
U   trunk/htdocs/js/ck/plugins/livejournal/plugin.js
Modified: trunk/htdocs/js/ck/config.js
===================================================================
--- trunk/htdocs/js/ck/config.js	2012-08-14 13:20:30 UTC (rev 22637)
+++ trunk/htdocs/js/ck/config.js	2012-08-14 14:18:42 UTC (rev 22638)
@@ -89,7 +89,7 @@
 
 	if (Site.page.ljpost) {
 		toolbar = [
-			'Bold', 'Italic', 'Underline', 'Strike', 'ljFontSize', 'LJColor',
+			'Bold', 'Italic', 'Underline', 'Strike', 'LJFont', 'LJColor',
 
 			'-',
 

Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js
===================================================================
--- trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2012-08-14 13:20:30 UTC (rev 22637)
+++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2012-08-14 14:18:42 UTC (rev 22638)
@@ -577,6 +577,121 @@
 
 			// LJ Buttons
 
+			// LJ Font
+			(function () {
+				var button = 'LJFont',
+					config = editor.config,
+					hooked = false,
+					styles = {},
+					defaultFont = 'normal',  // This value probably should not be hardcoded
+					currentFont = defaultFont,
+					sizes = config.fontSize_sizes,
+					style = config.fontSize_style,
+					selectedItem = 'b-fontsize-select-item-active',
+					i, part, vars, name, $items = jQuery();
+
+				sizes = sizes.split(';');
+
+				for (i = 0; i < sizes.length; i++) {
+					part = sizes[i];
+
+					if (part) {
+						part = part.split( '/' );
+
+						vars = {};
+						name = sizes[i] = part[0].toLowerCase();
+
+						vars['size'] = part[1] || name;
+
+						styles[name] = new CKEDITOR.style(style, vars);
+						styles[name]._.definition.name = name;
+					} else {
+						sizes.splice(i--, 1);
+					}
+				}
+
+				function setValue(value) {
+					currentFont = value;
+
+					$items
+						.removeClass(selectedItem)
+						.filter('.b-fontsize-select-item-' + currentFont)
+						.addClass(selectedItem);
+				}
+
+				editor.addCommand(button, {
+					exec: function(editor) {
+						editor.rteButton(button, 'font');
+
+						if (!hooked) {
+							$items = jQuery('.b-fontsize-select-item');
+							LiveJournal.register_hook('font_response', function (font) {
+								editor.focus();
+								editor.fire('saveSnapshot');
+
+								var style = styles[font],
+									s, selection, selected;
+
+								if (currentFont === font) {
+									style.remove(editor.document);
+								} else {
+									selection = editor.getSelection();
+									selected = parseFloat(style._.definition.styles['font-size']);
+
+									for (s in styles) {
+										styles[s].remove(editor.document);
+									}
+
+									style.apply(editor.document);
+								}
+
+								editor.fire('saveSnapshot');
+							});
+							hooked = true;
+
+							var command = editor.getCommand(button);
+							command.setState(CKEDITOR.TRISTATE_ON);
+
+							setValue(currentFont);
+						}
+					}
+				});
+
+				editor.ui.addButton(button, {
+					label: CKLang[button] || 'BUTTON',
+					command: button
+				});
+
+				editor.on('selectionChange', function (ev) {
+					var elementPath = ev.data.path,
+						elements = elementPath.elements,
+						command = editor.getCommand(button),
+						i, element, value;
+
+					// For each element into the elements path.
+					for (i = 0; i < elements.length; i++) {
+						element = elements[i];
+
+						// Check if the element is removable by any of
+						// the styles.
+						for (value in styles) {
+							if (styles[value].checkElementRemovable(element, true)) {
+								if (value !== currentFont) {
+									setValue(value);
+									command.setState(CKEDITOR.TRISTATE_ON);
+								}
+
+								return;
+							}
+						}
+					}
+
+					setValue(defaultFont);
+					command.setState(CKEDITOR.TRISTATE_OFF);
+					return;
+				});
+			}());
+
 			// LJ User
 			(function () {
 				var url = top.Site.siteroot + '/tools/endpoints/ljuser.bml',

Tags: anazarov, js, livejournal, nfokz
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments