Undo Redo Function
Jun 8, 2004
<!--
I'm working on an undo-redo function. Couldnt really find anything useful in the internet.
So I have a try. Guess it could be quite useful for a lot of people out there.
Wonder if the concept is any good?
Please critizise hard!
Try it out if you dare!
Any feedback is welcome!
All suggestions are appreciated!
Yours
Axinya
-->
<html>
<head>
<style type="text/css">
<!--
#wisiwig {
overflow: auto;
position: relative;
height: 300px;
width: 600px;
margin-top: 5px;
padding: 5px;
border: thin groove #999999;
}
-->
</style>
<script language="JavaScript">
<!--
var b_ackup = new Array(); //Store data in Array
var undo_pos= 0;//Position of undo
var flag = false;// shall we start new undo thread and delete obsolete items?
var w_isiwig;//editor interface
function init(){
w_isiwig = document.getElementById("wisiwig");
w_isiwig.contentEditable = true;
w_isiwig.onkeyup = HandleKeys;
b_ackup[0] = w_isiwig.innerHTML;
}
function HandleKeys(evt) {//events to write to backup
//
if (event) {
switch (event.keyCode) {
case 32:
BACKUP();
break;
case 8:
BACKUP();
break;
case 13:
BACKUP();
break;
case 46:
BACKUP();
break;
default:
return;
}
}
}
function BACKUP(){
if (flag){// action if undo was clicked
var removed= b_ackup.splice(flag,b_ackup.length - flag);
for (var i = 0; i < removed.length; i++) {
delete removed[i];//delete obsolete array items
}
b_ackup[b_ackup.length] = w_isiwig.innerHTML;
undo_pos = b_ackup.length - 1;
flag = false;
w_isiwig.focus();
}
else{//write to backup array
b_ackup[b_ackup.length] = w_isiwig.innerHTML;
undo_pos = b_ackup.length - 1;
flag = false;
w_isiwig.focus();
}
}
function undo(){
if (b_ackup.length){//
if(undo_pos==0){w_isiwig.focus();return;}// beginning of backup items
if(flag == false){BACKUP();}// save last state of document
w_isiwig.innerHTML=b_ackup[undo_pos -1];
undo_pos=undo_pos - 1;
flag = undo_pos +1;
look();
w_isiwig.focus();
}
}
function redo(){
if(undo_pos == b_ackup.length -1){w_isiwig.focus();return;}
//end of backup array
w_isiwig.innerHTML=b_ackup[undo_pos +1];
undo_pos=undo_pos + 1;
flag = undo_pos +1;
look();
w_isiwig.focus();
}
function look(){// monitor our Array data
var e='flag:'+flag+'
undo_pos:'+undo_pos+'
'
e+='b_ackup.length:'+b_ackup.length+'
'
for (i=0; i<b_ackup.length; i++){
e+= 'Backup item '+i+':'+b_ackup[i]+'
'
}
document.getElementById('bup_a').value=e;
}
</script>
<title>undo-redo</title>
</head>
<body id = "body" onload= "init();">
<p><b>undo/redo</b> <br>
development version: for <b>IE</b> only<br>
Backup written by <b>'onkeyup'</b> event(space,back,return,del), or
<b>'add to backup'</b> button. </p>
<div id="menu">
<a href="#" onclick='BACKUP();return false'>[add to backup]</a>
<a href="#" onclick='setTimeout("undo()",10)'>[undo]</a>
<a href="#" onclick='setTimeout("redo()",10)'>[redo]</a>
<a href="#" onclick='look()'>[view backup-data]</a> </div>
<div id="wisiwig">Type text: </div>
Backup Array Data: <br>
<div id="bup">
<textarea id="bup_a" name="bup_a" cols="80" rows="6"></textarea>
</div>
</body>
</html>
View 8 Replies
ADVERTISEMENT
Sep 6, 2010
I find most rich internet text editors, developers put in the product many many features but fail to make a decent undo redo mechanism, I pressed crtl+z they deleted my whole paragraph. Unlike googledocs's one, it knows exactly what to undo.
If anyone can let me know what the logic of google docs/Ms word machanism is, maybe I can give it shot building one.
View 1 Replies
View Related
Jul 23, 2005
I`m writing a javascript regex tester (IE 6 only) and would like to include
an undo button for a text input field.
I want it to handle individual keystrokes, pasting and drop, and also
text added by clicking various buttons.
I have tried a LOT of handler combinations and fancy conditionals to
make it work perfectly, and I`m ALMOST there.
View 3 Replies
View Related
Jul 23, 2005
I am using IE 6.0. On a page, I have placed a contenteditable div
which I want to use as a Rich Text Area. I am using the execCommand method of
the document to control bold, italics, underlining, and undo for this div.
I have placed an input element on the page to. All but the undo, are
restricted to working only on the div. How can I restrict the undo to
working on only the div?
Below is the complete page so you can see what I am talking about.
Just paste it into an htm file and traverse to it via your browser.
Type something in the div and the input and then try the buttons. Code:
View 3 Replies
View Related
Sep 29, 2010
is it possible to do a CTRL-z (undo) in a onclick event ?
View 3 Replies
View Related
Jun 12, 2009
I am working on a UI that, when you click on a menu option, a div opens and show three divs inside. These divs all have different
heights. The heights are based on the divs content.The problem I'm having is... how do I measure what the divs height should be? IE, how do I grab the height for a div BEFORE it has had any style applied to it.
View 1 Replies
View Related
Dec 8, 2009
I have some javascript the works in conjunction with a flash video player. When a user selects a video in the Flash video list and new video is called and begins to play. Also, when that video is selected a function called "doOnMediaLoad()" is called and inside of that function I have put a call to another function that I wrote in the same script.function that is called when user selects flash player video list.
function doOnMediaLoad(e) {
vcomments_changed(e.id); //call to my function
}
[code]....
View 2 Replies
View Related
Dec 9, 2009
I have some javascript the works in conjunction with a flash video player. When a user selects a video in the Flash video list and new video is called and begins to play. Also, when that video is selected a function called "doOnMediaLoad()" is called and inside of that function I have put a call to another function that I wrote in the same script.
[Code]...
View 4 Replies
View Related
Jul 1, 2010
I'm using the Google AJAX APIs, but some reason google.load works when run through normal javascript, but if I call the method from my jquery ready function it doesn't work. Code and output is below
page.html
<script type="text/javascript">
loadGoogleStuff();
function loaded() {
console.debug("in loaded function");
}
[Code]...
window.loadFirebugConsole is not a function If I comment out line 3 in code.js, the console debug runs okay, so the ready function is running okay. Even though there's a reference to Firebug, the same error occurs in Safari too. Nothing on the page loads.
View 1 Replies
View Related
Apr 1, 2010
I'm using jQuery 1.4 to hide a div (#cartPop) when the "close" link inside of it (#cartPop a) is clicked. Since I'm using animate() to fade the div out (opacity), I also have to use hide() to get rid of the div once it has faded out (otherwise the invisible div, which is on a higher z-index, blocks the elements on a lower z-index).
Code:
The problem is that the hide() function calls immediately without waiting for the animate() function to run. Even if I append a delay() function before hide() like so:
Code:
...it still doesn't wait.
View 3 Replies
View Related
Apr 4, 2010
I'm wanting a table cell click event to remove and replace the table it was clicked on, however I'm finding that as it's deleting the original table object the actual running event code is being replaced and the function is bailing.how I can call the delete/refresh function from outside the event's function scope?
View 1 Replies
View Related
Feb 12, 2010
how I can accomplish wrappingrelevantparts of a script into a function then call that function within a success area on another page.
This is what I have so far: Script.js page - This page is longer but this is the relevant part that I would like to wrap:
$(".product img").draggable({
containment: 'document',
opacity: 0.6,
revert: 'invalid',
[code]....
View 3 Replies
View Related
Jun 23, 2010
I have just started learning JQuery and have a doubt in the below code. $.get('myhtmlpage.html', myCallBack);The doubt is should the 1st parameter of the get function be a HTML file or can it be a unction name?
View 1 Replies
View Related
Feb 15, 2012
I want to call java function in javascript.In which we pass one parameter to function and its returns String value which I want to display in alert message.
View 2 Replies
View Related
Jun 11, 2011
I have a real perplexing issue. In two separate "projects" I had code that displayed checkboxes - when clicked, they would fetch information from a db and display it in the div below. I had code that displayed a jquery date-picker - when clicked, it would fetch information from a db and display it in the div below. My issue comes with this:
[Code]...
View 1 Replies
View Related
Mar 24, 2006
I have a function I call to see if people leave form fields empty. I have been asked by a client to check to make sure of the person's date of birth as well. They gave me the script, however, I am unsure how to do implement it. How do I add this to my existing checks? Code:
View 2 Replies
View Related
Jul 12, 2011
I am facing a problem in passing replace() function as an argument in user defined java function.
intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '' to '\'
I am posting my javascript function here:
<a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\/g,"\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a>
function OpenDocPreview(url, docname) {
alert('message from search base : ' + url + ' ' + docname);
}
View 1 Replies
View Related
Oct 1, 2010
I am trying to minimize the amount of script that I use on my website. I have sections of each page; each section has the same basic layout. The divs and images that I want to make appear and disappear all have nearly identical ids, the only difference is the number at the end of the id.Is there a way to get one script to automatically detect which id number has been clicked and then show all elements with the same number at the end of the id? I would also like it to hide the elements in the hide function below (basically they are the elements that do not share the same id number).I currently have everything working the way I want it to using multiple functions like the one below but I woul
$("#2thumbNail2 , #ledBar").click(function () {
$("#type201 , #type203 , #type204").hide();
$("#image201 , #image203 , #image204").fadeOut("slow");
[code]....
View 1 Replies
View Related
Jun 18, 2010
I have 2 javascript files: 1 containing generic functions for my site used sitewide and another for a particular web page containing just the javascript for that page. The page is also calling the jQuery javascript file.
What I want to do is have a javascript function in my main javascript file which uses features of jQuery such as show, hide etc. and then I want to call this javascript function from the other page specific javascript file.
[Code]...
This does not work and so was wondering if anyone can point me in the right direction as to how to achieve this or something similar.
View 1 Replies
View Related
Aug 29, 2011
I am having a strange problem with a javascript function that does not return the value but returns the code inside the function. My best guess is that I am incorrectly calling the function hasLandedOn()and jquery is interpeting it. Why is this happening? I highlighted the parts in red.-Tom ReeseThe following is returned NOT the variable imageName.
function hasLandedOn(){
var selectorLoc = $("#selector").offset();
var imageName = "";
[code]....
View 2 Replies
View Related
Oct 10, 2009
how can i write a function that accepts a callback function?[URL].. i want myFunction to load some data via(an unordored list actually) load method end then somehow to return the wrapped elements for the callback function, exactly like load() does.
View 6 Replies
View Related
May 23, 2009
I have done some searching on the discussions here and have found info on waiting for fadeins, etc. to finish and then calling another function. However, I am needing something a little different. I am needing for function 1 to process and then call over to function 2 once it's finished. Here is my code:
[Code]...
View 1 Replies
View Related
Jan 6, 2012
I have a lot of similar instances of the following code on my page:
$('#btnEditParty').click(function () {
$.ajax({
type: "POST",
url: "WardAdmin.aspx/GetParty",
[Code]....
I'd like to create a generic function to save repeating a lot of code and then just pass in the relevant values.
I'm fine with that, the only thing I'm not sure about is if/how I can pass in a function name to be called on success/fail.
This post is where I was doing something similar to save repeated code: [URL]
In a similar way is there a way of passing in a function name to be called on success?
View 1 Replies
View Related
Jun 25, 2009
The javascript function addRowToTable() is called by a button, and replies a set of elements (select, input, checkbox) of the form. In this function, the creation of select calls another function CliK(sel.id)The problem is that this function tells me error "object required" as if the select Id was not "type" or the checkbox id was not "key" here I go wrong?
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
[code]....
View 4 Replies
View Related
Jan 28, 2011
I'm trying to make a time script for an app I'm making (this is not an HTML document; it's a .js file to be used with Titanium) however I'm having trouble getting the function to display and update.
function updateClock()
{
setInterval ( 'kiTime()', 1000 );
}
function kiTime ()
{
//Get current date and time
[Code]...
If I use kiTime() under the text field I will get the current time (or at least the time the app was opened), however if I call updateClock() it's blank.
View 4 Replies
View Related
Jul 12, 2011
I am facing a problem in passing replace() function as an argument in user defined java function
intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '' to '\'
I am posting my javascript function here:
<a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\/g,"\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a>
function OpenDocPreview(url, docname) {
alert('message from search base : ' + url + ' ' + docname);
}
View 4 Replies
View Related