bgneal@45: /** bgneal@183: * editor_plugin_src.js bgneal@45: * bgneal@183: * Copyright 2009, Moxiecode Systems AB bgneal@183: * Released under LGPL License. bgneal@183: * bgneal@183: * License: http://tinymce.moxiecode.com/license bgneal@183: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: tinymce.create('tinymce.plugins.InsertDateTime', { bgneal@45: init : function(ed, url) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: bgneal@45: ed.addCommand('mceInsertDate', function() { bgneal@45: var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_dateFormat", ed.getLang('insertdatetime.date_fmt'))); bgneal@45: bgneal@45: ed.execCommand('mceInsertContent', false, str); bgneal@45: }); bgneal@45: bgneal@45: ed.addCommand('mceInsertTime', function() { bgneal@45: var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_timeFormat", ed.getLang('insertdatetime.time_fmt'))); bgneal@45: bgneal@45: ed.execCommand('mceInsertContent', false, str); bgneal@45: }); bgneal@45: bgneal@45: ed.addButton('insertdate', {title : 'insertdatetime.insertdate_desc', cmd : 'mceInsertDate'}); bgneal@45: ed.addButton('inserttime', {title : 'insertdatetime.inserttime_desc', cmd : 'mceInsertTime'}); bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'Insert date/time', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: _getDateTime : function(d, fmt) { bgneal@45: var ed = this.editor; bgneal@45: bgneal@45: function addZeros(value, len) { bgneal@45: value = "" + value; bgneal@45: bgneal@45: if (value.length < len) { bgneal@45: for (var i=0; i<(len-value.length); i++) bgneal@45: value = "0" + value; bgneal@45: } bgneal@45: bgneal@45: return value; bgneal@45: }; bgneal@45: bgneal@45: fmt = fmt.replace("%D", "%m/%d/%y"); bgneal@45: fmt = fmt.replace("%r", "%I:%M:%S %p"); bgneal@45: fmt = fmt.replace("%Y", "" + d.getFullYear()); bgneal@45: fmt = fmt.replace("%y", "" + d.getYear()); bgneal@45: fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2)); bgneal@45: fmt = fmt.replace("%d", addZeros(d.getDate(), 2)); bgneal@45: fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2)); bgneal@45: fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2)); bgneal@45: fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2)); bgneal@45: fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1)); bgneal@45: fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM")); bgneal@45: fmt = fmt.replace("%B", "" + ed.getLang("insertdatetime.months_long").split(',')[d.getMonth()]); bgneal@45: fmt = fmt.replace("%b", "" + ed.getLang("insertdatetime.months_short").split(',')[d.getMonth()]); bgneal@45: fmt = fmt.replace("%A", "" + ed.getLang("insertdatetime.day_long").split(',')[d.getDay()]); bgneal@45: fmt = fmt.replace("%a", "" + ed.getLang("insertdatetime.day_short").split(',')[d.getDay()]); bgneal@45: fmt = fmt.replace("%%", "%"); bgneal@45: bgneal@45: return fmt; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('insertdatetime', tinymce.plugins.InsertDateTime); bgneal@45: })();