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