Sprites, also floodlight search support
authorDan Fuhry <dan@enanocms.org>
Fri, 12 Nov 2010 18:12:41 -0500
changeset 5 28ef73d2e7e8
parent 4 f8d8b3ef32e0
child 6 7398bdc17604
Sprites, also floodlight search support
guieditor/editor.js
guieditor/icons/sprite.png
guieditor/icons/sprite.sh
--- a/guieditor/editor.js	Wed Nov 10 13:55:24 2010 -0500
+++ b/guieditor/editor.js	Fri Nov 12 18:12:41 2010 -0500
@@ -16,6 +16,8 @@
 	toolbar += head.run();
 	
 	var buttons = ['heading', '|', 'bold*', 'italic*', 'underline*', '|', 'intlink', 'extlink', 'image*', 'table*', '|', 'ulist*', 'olist*', '|', 'signature'];
+	// if new images are to be added, run sprite.sh under icons/ and update this array
+	var spritelist = ['add', 'bold', 'extlink', 'image', 'intlink', 'italic', 'olist', 'signature', 'table', 'ulist', 'underline', 'separator'];
 	
 	// Button: Bold
 	var i;
@@ -25,7 +27,7 @@
 		if ( buttons[i] == '|' )
 		{
 			label.assign_vars({
-					TITLE: '<img alt="|" src="' + scriptPath + '/plugins/guieditor/icons/separator.png" />'
+					TITLE: gen_sprite_html(cdnPath + '/plugins/guieditor/icons/sprite.png', 8, 16, 0, (spritelist.length - 1) * 16),
 				});
 			toolbar += label.run();
 		}
@@ -53,7 +55,8 @@
 			}
 			button.assign_vars({
 					TITLE: $lang.get('guied_btn_' + buttons[i]),
-					IMAGE: cdnPath + '/plugins/guieditor/icons/' + buttons[i] + '.png',
+					// FIXME: indexOf is error prone here
+					SPRITE: gen_sprite_html(cdnPath + '/plugins/guieditor/icons/sprite.png', 16, 16, 0, spritelist.indexOf(buttons[i]) * 16),
 					FLAGS: 'href="#" onclick="guied_act(\'' + buttons[i] + '\'); return false;"'
 				});
 			toolbar += button.run();
@@ -76,6 +79,7 @@
 function guied_act(action)
 {
 	var textarea = document.getElementById('ajaxEditArea');
+	var af_class = typeof(autofill_schemas.floodlight) == 'object' ? 'guied_floodlight' : 'page';
 	switch(action)
 	{
 		case 'bold':
@@ -99,7 +103,7 @@
 									' + $lang.get('guied_intlink_lbl_page') + ' \
 									</td> \
 									<td valign="top"> \
-										<input type="text" id="guied_intlink_page" class="autofill page" style="width: 100%;" /><br /> \
+										<input type="text" id="guied_intlink_page" class="autofill ' + af_class + '" style="width: 100%;" /><br /> \
 										<small>' + $lang.get('guied_intlink_af_hint') + '</small> \
 									</td> \
 								</tr> \
@@ -573,3 +577,31 @@
 	}
 	
 };
+
+// This is only used if floodlight is available
+autofill_schemas.guied_floodlight = {
+  init: function(element, fillclass, params)
+  {
+    params = params || {};
+    $(element).autocomplete(makeUrlNS('Special', 'Autofill', 'type=floodlight') + '&userinput=', {
+        minChars: 3,
+        formatItem: function(row, _, __)
+        {
+          var type = ( typeof(row.type) == 'string' ) ? row.type : '';
+          var html = '<big>' + row.title + '</big> <small>' + type + '</small>';
+          html += '<br /><small>' + $lang.get('floodlight_lbl_score') + row.score + '% | ' + row.size + '</small>';
+          row[0] = row[0].replace(/^go:/, '');
+          return html;
+        },
+        tableHeader: '<tr><th>' + $lang.get('floodlight_table_heading') + '</th></tr>',
+        showWhenNoResults: true,
+        onItemSelect: function(li)
+        {
+        	$(element).val(li.selectValue.replace(/^go:/, ''));
+        },
+        width: 180,
+        noResultsHTML: '<tr><td class="row1" style="font-size: smaller;">' + $lang.get('floodlight_msg_no_results') + '</td></tr>',
+    });
+  }
+};
+
Binary file guieditor/icons/sprite.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/guieditor/icons/sprite.sh	Fri Nov 12 18:12:41 2010 -0500
@@ -0,0 +1,22 @@
+#!/bin/bash
+# separator is special (only 8px wide) so ensure it goes last
+images=(`ls *.png | grep -v sprite | grep -v separator` separator.png)
+
+echo "Creating sprite.png. Update spritelist in ../editor.js with:"
+echo -ne "\t["
+for img in ${images[@]}; do
+	echo -n "'${img%.png}'"
+	if [ $img != "separator.png" ]; then
+		echo -n ", "
+	fi
+done
+echo "]"
+
+montage=`which montage`
+if [ -z "$montage" ]; then
+	echo "Could not find montage, please install imagemagick"
+	exit 1
+fi
+
+montage -background transparent -tile ${#images[@]}x1 -geometry +0+0 ${images[@]} sprite.png
+