From: <abe...@us...> - 2012-09-23 02:19:34
|
Revision: 5689 http://astlinux.svn.sourceforge.net/astlinux/?rev=5689&view=rev Author: abelbeck Date: 2012-09-23 02:19:24 +0000 (Sun, 23 Sep 2012) Log Message: ----------- web interface, Edit tab, if unsaved edits exist a dialog will warn the user before leaving Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/common/murmurhash3_gc.js Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2012-09-21 03:04:04 UTC (rev 5688) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2012-09-23 02:19:24 UTC (rev 5689) @@ -341,6 +341,24 @@ } putHtml("</center>"); ?> + <script language="JavaScript" type="text/javascript" src="../common/murmurhash3_gc.js"></script> + <script language="JavaScript" type="text/javascript"> + //<![CDATA[ + var old_textHash; + + function setOKexit() { + var cur_textHash = murmurhash3_32_gc(document.getElementById("ed").value, 6802145); + if (cur_textHash != old_textHash) { + return 'Unsaved changes will be lost. Really leave?'; + } + } + + function setOKhandler() { + old_textHash = murmurhash3_32_gc(document.getElementById("ed").value, 6802145); + window.onbeforeunload = setOKexit; + } + //]]> + </script> <center> <table class="layoutNOpad"><tr><td><center> <form method="post" action="<?php echo $myself;?>"> @@ -494,7 +512,7 @@ </td></tr></table> <table width="100%" class="stdtable"> <tr><td width="240" style="text-align: center;"> - <input type="submit" class="formbtn" value="Save Changes" name="submit_save" /> + <input type="submit" class="formbtn" value="Save Changes" name="submit_save" onclick="setOKhandler();" /> <input type="hidden" value="<?php echo $openfile;?>" name="openfile" /> </td><td class="dialogText" style="text-align: center;"> <input type="submit" class="formbtn" value="Reload/Restart" name="submit_reload" /> @@ -518,7 +536,7 @@ $rows = '30'; } putHtml('<table class="stdtable"><tr><td>'); - echo '<textarea name="edit_text" rows="'.$rows.'" cols="'.$cols.'" wrap="off" class="editText">'; + echo '<textarea id="ed" name="edit_text" rows="'.$rows.'" cols="'.$cols.'" wrap="off" class="editText">'; if ($openfile !== '') { if (($ph = @fopen($openfile, "rb")) !== FALSE) { while (! feof($ph)) { @@ -533,8 +551,13 @@ putHtml('</textarea>'); putHtml('</td></tr></table>'); putHtml('</form>'); - putHtml("</center></td></tr></table>"); - putHtml("</center>"); + putHtml('</center></td></tr></table>'); + putHtml('</center>'); + putHtml('<script language="JavaScript" type="text/javascript">'); + putHtml('//<![CDATA['); + putHtml('setOKhandler();'); + putHtml('//]]>'); + putHtml('</script>'); } // End of HTTP GET require_once '../common/footer.php'; Added: branches/1.0/package/webinterface/altweb/common/murmurhash3_gc.js =================================================================== --- branches/1.0/package/webinterface/altweb/common/murmurhash3_gc.js (rev 0) +++ branches/1.0/package/webinterface/altweb/common/murmurhash3_gc.js 2012-09-23 02:19:24 UTC (rev 5689) @@ -0,0 +1,64 @@ +/** + * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011) + * + * @author <a href="mailto:gar...@gm...">Gary Court</a> + * @see http://github.com/garycourt/murmurhash-js + * @author <a href="mailto:aap...@gm...">Austin Appleby</a> + * @see http://sites.google.com/site/murmurhash/ + * + * @param {string} key ASCII only + * @param {number} seed Positive integer only + * @return {number} 32-bit positive integer hash + */ + +function murmurhash3_32_gc(key, seed) { + var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i; + + remainder = key.length & 3; // key.length % 4 + bytes = key.length - remainder; + h1 = seed; + c1 = 0xcc9e2d51; + c2 = 0x1b873593; + i = 0; + + while (i < bytes) { + k1 = + ((key.charCodeAt(i) & 0xff)) | + ((key.charCodeAt(++i) & 0xff) << 8) | + ((key.charCodeAt(++i) & 0xff) << 16) | + ((key.charCodeAt(++i) & 0xff) << 24); + ++i; + + k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); + h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff; + h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16)); + } + + k1 = 0; + + switch (remainder) { + case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16; + case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8; + case 1: k1 ^= (key.charCodeAt(i) & 0xff); + + k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff; + h1 ^= k1; + } + + h1 ^= key.length; + + h1 ^= h1 >>> 16; + h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff; + h1 ^= h1 >>> 13; + h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff; + h1 ^= h1 >>> 16; + + return h1 >>> 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |