/* Import plugin specific language pack */ tinyMCE.importPluginLanguagePack('insertdatetime', 'cs,el,en,fr_ca,it,ko,sv,zh_cn,fa,fr,de,pl,pt_br'); /** * Returns the HTML contents of the insertdate, inserttime controls. */ function TinyMCE_insertdatetime_getControlHTML(control_name) { var safariPatch = '" onclick="'; if (tinyMCE.isSafari) safariPatch = ""; switch (control_name) { case "insertdate": return ''; case "inserttime": return ''; } return ""; } /** * Executes the mceInsertDate command. */ function TinyMCE_insertdatetime_execCommand(editor_id, element, command, user_interface, value) { /* Adds zeros infront of value */ function addZeros(value, len) { value = "" + value; if (value.length < len) { for (var i=0; i<(len-value.length); i++) value = "0" + value; } return value; } /* Returns the date object in the specified format */ function getDateTime(date, format) { format = tinyMCE.regexpReplace(format, "%D", "%m/%d/%y"); format = tinyMCE.regexpReplace(format, "%r", "%I:%M:%S %p"); format = tinyMCE.regexpReplace(format, "%Y", "" + date.getFullYear()); format = tinyMCE.regexpReplace(format, "%y", "" + date.getYear()); format = tinyMCE.regexpReplace(format, "%m", addZeros(date.getMonth()+1, 2)); format = tinyMCE.regexpReplace(format, "%d", addZeros(date.getDate(), 2)); format = tinyMCE.regexpReplace(format, "%H", "" + addZeros(date.getHours(), 2)); format = tinyMCE.regexpReplace(format, "%M", "" + addZeros(date.getMinutes(), 2)); format = tinyMCE.regexpReplace(format, "%S", "" + addZeros(date.getSeconds(), 2)); format = tinyMCE.regexpReplace(format, "%I", "" + (date.getHours() < 12 ? (date.getHours()+1) : 24-date.getHours())); format = tinyMCE.regexpReplace(format, "%p", "" + (date.getHours() < 12 ? "AM" : "PM")); format = tinyMCE.regexpReplace(format, "%B", "" + tinyMCE.getLang("lang_inserttime_months_long")[date.getMonth()]); format = tinyMCE.regexpReplace(format, "%b", "" + tinyMCE.getLang("lang_inserttime_months_short")[date.getMonth()]); format = tinyMCE.regexpReplace(format, "%A", "" + tinyMCE.getLang("lang_inserttime_day_long")[date.getDay()]); format = tinyMCE.regexpReplace(format, "%a", "" + tinyMCE.getLang("lang_inserttime_day_short")[date.getDay()]); format = tinyMCE.regexpReplace(format, "%%", "%"); return format; } // Handle commands switch (command) { case "mceInsertDate": tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_dateFormat", "%Y-%m-%d"))); return true; case "mceInsertTime": tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_timeFormat", "%H:%M:%S"))); return true; } // Pass to next handler in chain return false; }