applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / plugins / insertdatetime / editor_plugin_src.js
blobed13001541e76b0f146393d406792343d08e8185
1 /**
2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
6 */
8 /* Import plugin specific language pack */
9 tinyMCE.importPluginLanguagePack('insertdatetime');
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://tinymce.moxiecode.com/tinymce/docs/plugin_insertdatetime.html',
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
22 /**
23 * Returns the HTML contents of the insertdate, inserttime controls.
25 getControlHTML : function(cn) {
26 switch (cn) {
27 case "insertdate":
28 return tinyMCE.getButtonHTML(cn, 'lang_insertdate_desc', '{$pluginurl}/images/insertdate.gif', 'mceInsertDate');
30 case "inserttime":
31 return tinyMCE.getButtonHTML(cn, 'lang_inserttime_desc', '{$pluginurl}/images/inserttime.gif', 'mceInsertTime');
34 return "";
37 /**
38 * Executes the mceInsertDate command.
40 execCommand : function(editor_id, element, command, user_interface, value) {
41 /* Adds zeros infront of value */
42 function addZeros(value, len) {
43 value = "" + value;
45 if (value.length < len) {
46 for (var i=0; i<(len-value.length); i++)
47 value = "0" + value;
50 return value;
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("%%", "%");
71 return fmt;
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;
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;
85 // Pass to next handler in chain
86 return false;
90 tinyMCE.addPlugin("insertdatetime", TinyMCE_InsertDateTimePlugin);