includes/clientside/tinymce/plugins/insertdatetime/editor_plugin_src.js
changeset 1 fe660c52c48f
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 /**
       
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 /* Import plugin specific language pack */
       
     9 tinyMCE.importPluginLanguagePack('insertdatetime');
       
    10 
       
    11 var TinyMCE_InsertDateTimePlugin = {
       
    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 
       
    22 	/**
       
    23 	 * Returns the HTML contents of the insertdate, inserttime controls.
       
    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 
       
    30 			case "inserttime":
       
    31 				return tinyMCE.getButtonHTML(cn, 'lang_inserttime_desc', '{$pluginurl}/images/inserttime.gif', 'mceInsertTime');
       
    32 		}
       
    33 
       
    34 		return "";
       
    35 	},
       
    36 
       
    37 	/**
       
    38 	 * Executes the mceInsertDate command.
       
    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 
       
    45 			if (value.length < len) {
       
    46 				for (var i=0; i<(len-value.length); i++)
       
    47 					value = "0" + value;
       
    48 			}
       
    49 
       
    50 			return value;
       
    51 		}
       
    52 
       
    53 		function getDateTime(d, fmt) {
       
    54 			fmt = fmt.replace("%D", "%m/%d/%y");
       
    55 			fmt = fmt.replace("%r", "%I:%M:%S %p");
       
    56 			fmt = fmt.replace("%Y", "" + d.getFullYear());
       
    57 			fmt = fmt.replace("%y", "" + d.getYear());
       
    58 			fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
       
    59 			fmt = fmt.replace("%d", addZeros(d.getDate(), 2));
       
    60 			fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
       
    61 			fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
       
    62 			fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
       
    63 			fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
       
    64 			fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
       
    65 			fmt = fmt.replace("%B", "" + tinyMCE.getLang("lang_inserttime_months_long")[d.getMonth()]);
       
    66 			fmt = fmt.replace("%b", "" + tinyMCE.getLang("lang_inserttime_months_short")[d.getMonth()]);
       
    67 			fmt = fmt.replace("%A", "" + tinyMCE.getLang("lang_inserttime_day_long")[d.getDay()]);
       
    68 			fmt = fmt.replace("%a", "" + tinyMCE.getLang("lang_inserttime_day_short")[d.getDay()]);
       
    69 			fmt = fmt.replace("%%", "%");
       
    70 
       
    71 			return fmt;
       
    72 		}
       
    73 
       
    74 		// Handle commands
       
    75 		switch (command) {
       
    76 			case "mceInsertDate":
       
    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);