Make WordPress Core

Changeset 2536


Ignore:
Timestamp:
04/16/2005 04:31:38 PM (20 years ago)
Author:
matt
Message:

Initial auto-save checkin code from DarkCryst. No bug reports on it yet! Several known issues, including deleting cookies, moving the restore button, and other behavior probs.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-footer.php

    r1664 r2536  
    1010<?php do_action('admin_footer', ''); ?>
    1111
     12<?php if ( isset( $editing ) ) : ?>
     13<script type="text/javascript">
     14WhenLoaded();
     15</script>
     16<?php endif; ?>
     17
    1218</body>
    1319</html>
  • trunk/wp-admin/admin-header.php

    r2406 r2536  
    7979<?php endif; ?>
    8080
     81<?php if ( isset( $editing ) ) : ?>
     82var elem;
     83var eID = 'content';
     84var cID = 'twWPAutoSave';
     85
     86function 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
     97function eraseCookie(name){
     98    createCookie(name,"",-1);
     99}
     100
     101function 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
     123function 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
     135function WhenLoaded(){
     136var 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
     151function restoreData(){
     152    elem.value = readCookie(cID);
     153}
     154<?php endif; ?>
    81155//]]>
    82156</script>
  • trunk/wp-admin/post.php

    r2524 r2536  
    2525    // Fix submenu highlighting for pages.
    2626if (false !== strpos($_SERVER['HTTP_REFERER'], 'edit-pages.php')) $submenu_file = 'page-new.php';
     27
     28$editing = true;
    2729
    2830switch($action) {
Note: See TracChangeset for help on using the changeset viewer.