includes/clientside/tinymce/plugins/insertdatetime/editor_plugin_src.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 /**
     1 /**
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
     2  * $Id: editor_plugin_src.js 372 2007-11-11 18:38:50Z spocke $
     3  *
     3  *
     4  * @author Moxiecode
     4  * @author Moxiecode
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     6  */
     6  */
     7 
     7 
     8 /* Import plugin specific language pack */
     8 (function() {
     9 tinyMCE.importPluginLanguagePack('insertdatetime');
     9 	tinymce.create('tinymce.plugins.InsertDateTime', {
       
    10 		init : function(ed, url) {
       
    11 			var t = this;
    10 
    12 
    11 var TinyMCE_InsertDateTimePlugin = {
    13 			t.editor = ed;
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Insert date/time',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
    14 
    22 	/**
    15 			ed.addCommand('mceInsertDate', function() {
    23 	 * Returns the HTML contents of the insertdate, inserttime controls.
    16 				var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_dateFormat", ed.getLang('insertdatetime.date_fmt')));
    24 	 */
       
    25 	getControlHTML : function(cn) {
       
    26 		switch (cn) {
       
    27 			case "insertdate":
       
    28 				return tinyMCE.getButtonHTML(cn, 'lang_insertdate_desc', '{$pluginurl}/images/insertdate.gif', 'mceInsertDate');
       
    29 
    17 
    30 			case "inserttime":
    18 				ed.execCommand('mceInsertContent', false, str);
    31 				return tinyMCE.getButtonHTML(cn, 'lang_inserttime_desc', '{$pluginurl}/images/inserttime.gif', 'mceInsertTime');
    19 			});
    32 		}
       
    33 
    20 
    34 		return "";
    21 			ed.addCommand('mceInsertTime', function() {
    35 	},
    22 				var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_timeFormat", ed.getLang('insertdatetime.time_fmt')));
    36 
    23 
    37 	/**
    24 				ed.execCommand('mceInsertContent', false, str);
    38 	 * Executes the mceInsertDate command.
    25 			});
    39 	 */
       
    40 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    41 		/* Adds zeros infront of value */
       
    42 		function addZeros(value, len) {
       
    43 			value = "" + value;
       
    44 
    26 
    45 			if (value.length < len) {
    27 			ed.addButton('insertdate', {title : 'insertdatetime.insertdate_desc', cmd : 'mceInsertDate'});
    46 				for (var i=0; i<(len-value.length); i++)
    28 			ed.addButton('inserttime', {title : 'insertdatetime.inserttime_desc', cmd : 'mceInsertTime'});
    47 					value = "0" + value;
    29 		},
    48 			}
       
    49 
    30 
    50 			return value;
    31 		getInfo : function() {
    51 		}
    32 			return {
       
    33 				longname : 'Insert date/time',
       
    34 				author : 'Moxiecode Systems AB',
       
    35 				authorurl : 'http://tinymce.moxiecode.com',
       
    36 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
       
    37 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
    38 			};
       
    39 		},
    52 
    40 
    53 		function getDateTime(d, fmt) {
    41 		// Private methods
       
    42 
       
    43 		_getDateTime : function(d, fmt) {
       
    44 			var ed = this.editor;
       
    45 
       
    46 			function addZeros(value, len) {
       
    47 				value = "" + value;
       
    48 
       
    49 				if (value.length < len) {
       
    50 					for (var i=0; i<(len-value.length); i++)
       
    51 						value = "0" + value;
       
    52 				}
       
    53 
       
    54 				return value;
       
    55 			};
       
    56 
    54 			fmt = fmt.replace("%D", "%m/%d/%y");
    57 			fmt = fmt.replace("%D", "%m/%d/%y");
    55 			fmt = fmt.replace("%r", "%I:%M:%S %p");
    58 			fmt = fmt.replace("%r", "%I:%M:%S %p");
    56 			fmt = fmt.replace("%Y", "" + d.getFullYear());
    59 			fmt = fmt.replace("%Y", "" + d.getFullYear());
    57 			fmt = fmt.replace("%y", "" + d.getYear());
    60 			fmt = fmt.replace("%y", "" + d.getYear());
    58 			fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
    61 			fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
    60 			fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
    63 			fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
    61 			fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
    64 			fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
    62 			fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
    65 			fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
    63 			fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
    66 			fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
    64 			fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
    67 			fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
    65 			fmt = fmt.replace("%B", "" + tinyMCE.getLang("lang_inserttime_months_long")[d.getMonth()]);
    68 			fmt = fmt.replace("%B", "" + ed.getLang("insertdatetime.months_long").split(',')[d.getMonth()]);
    66 			fmt = fmt.replace("%b", "" + tinyMCE.getLang("lang_inserttime_months_short")[d.getMonth()]);
    69 			fmt = fmt.replace("%b", "" + ed.getLang("insertdatetime.months_short").split(',')[d.getMonth()]);
    67 			fmt = fmt.replace("%A", "" + tinyMCE.getLang("lang_inserttime_day_long")[d.getDay()]);
    70 			fmt = fmt.replace("%A", "" + ed.getLang("insertdatetime.day_long").split(',')[d.getDay()]);
    68 			fmt = fmt.replace("%a", "" + tinyMCE.getLang("lang_inserttime_day_short")[d.getDay()]);
    71 			fmt = fmt.replace("%a", "" + ed.getLang("insertdatetime.day_short").split(',')[d.getDay()]);
    69 			fmt = fmt.replace("%%", "%");
    72 			fmt = fmt.replace("%%", "%");
    70 
    73 
    71 			return fmt;
    74 			return fmt;
    72 		}
    75 		}
       
    76 	});
    73 
    77 
    74 		// Handle commands
    78 	// Register plugin
    75 		switch (command) {
    79 	tinymce.PluginManager.add('insertdatetime', tinymce.plugins.InsertDateTime);
    76 			case "mceInsertDate":
    80 })();
    77 				tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_dateFormat", tinyMCE.getLang('lang_insertdate_def_fmt'))));
       
    78 				return true;
       
    79 
       
    80 			case "mceInsertTime":
       
    81 				tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_timeFormat", tinyMCE.getLang('lang_inserttime_def_fmt'))));
       
    82 				return true;
       
    83 		}
       
    84 
       
    85 		// Pass to next handler in chain
       
    86 		return false;
       
    87 	}
       
    88 };
       
    89 
       
    90 tinyMCE.addPlugin("insertdatetime", TinyMCE_InsertDateTimePlugin);