| 81 | | <?php if ( isset( $editing ) ) : ?> |
|---|
| 82 | | var elem; |
|---|
| 83 | | var eID = 'content'; |
|---|
| 84 | | var cID = 'twWPAutoSave'; |
|---|
| 85 | | |
|---|
| 86 | | function createCookie(name,value,days){ |
|---|
| 87 | | if (days) |
|---|
| 88 | | { |
|---|
| 89 | | var date = new Date(); |
|---|
| 90 | | date.setTime(date.getTime()+(days*24*60*60*1000)); |
|---|
| 91 | | var expires = "; expires="+date.toGMTString(); |
|---|
| 92 | | } |
|---|
| 93 | | else var expires = ""; |
|---|
| 94 | | document.cookie = name + "=" + escape(value ) + expires + "; path=/"; |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| 97 | | function eraseCookie(name){ |
|---|
| 98 | | createCookie(name,"",-1); |
|---|
| 99 | | } |
|---|
| 100 | | |
|---|
| 101 | | function readCookie(name) |
|---|
| 102 | | { |
|---|
| 103 | | var dc = document.cookie; |
|---|
| 104 | | var prefix = name + "="; |
|---|
| 105 | | var begin = dc.indexOf("; " + prefix); |
|---|
| 106 | | if (begin == -1) |
|---|
| 107 | | { |
|---|
| 108 | | begin = dc.indexOf(prefix); |
|---|
| 109 | | if (begin != 0) return null; |
|---|
| 110 | | } |
|---|
| 111 | | else |
|---|
| 112 | | { |
|---|
| 113 | | begin += 2; |
|---|
| 114 | | } |
|---|
| 115 | | var end = document.cookie.indexOf(";", begin); |
|---|
| 116 | | if (end == -1) |
|---|
| 117 | | { |
|---|
| 118 | | end = dc.length; |
|---|
| 119 | | } |
|---|
| 120 | | return unescape(dc.substring(begin + prefix.length, end)); |
|---|
| 121 | | } |
|---|
| 122 | | |
|---|
| 123 | | function KeyPressEvent(event){ |
|---|
| 124 | | if (document.all) { |
|---|
| 125 | | event = window.event; |
|---|
| 126 | | } |
|---|
| 127 | | if (event.which){ |
|---|
| 128 | | key = event.which; |
|---|
| 129 | | } else { |
|---|
| 130 | | key = event.keyCode; |
|---|
| 131 | | } |
|---|
| 132 | | createCookie(cID,elem.value, 7) |
|---|
| 133 | | } |
|---|
| 134 | | |
|---|
| 135 | | function WhenLoaded(){ |
|---|
| 136 | | var postdiv; |
|---|
| 137 | | if (postdiv = document.getElementById('poststuff')){ |
|---|
| 138 | | var data = postdiv.innerHTML |
|---|
| 139 | | var index = data.indexOf('<p class="submit">') + 18; |
|---|
| 140 | | var after = data.substring(index); |
|---|
| 141 | | var before = data.substring(0, index); |
|---|
| 142 | | postdiv.innerHTML = before + '<input type="submit" id="AutoRestore" value="Restore" onclick="restoreData(); return false;" />' + after; |
|---|
| 143 | | |
|---|
| 144 | | edCanvas = document.getElementById('content'); //re-enable quicktags with correct element (original content element was overwritten). |
|---|
| 145 | | |
|---|
| 146 | | elem = document.getElementById('content'); |
|---|
| 147 | | elem.onkeyup = KeyPressEvent; |
|---|
| 148 | | } |
|---|
| 149 | | } |
|---|
| 150 | | |
|---|
| 151 | | function restoreData(){ |
|---|
| 152 | | elem.value = readCookie(cID); |
|---|
| 153 | | } |
|---|
| 154 | | <?php endif; ?> |
|---|