View Full Version : mousedown timed

07-31-2006, 10:47 PM
can someone edit this script to make it so the user has to hold down their mouse for 3 seconds before it allows you to do the edit.

Event.observe(window, 'load', init, false);

function init(){

function makeEditable(id){
Event.observe(id, 'mousedown', function(){edit($(id))}, false);
Event.observe(id, 'mouseover', function(){showAsEditable($(id))}, false);
Event.observe(id, 'mouseout', function(){showAsEditable($(id), true)}, false);

function edit(obj){

var textarea = '<div id="'+obj.id+'_editor"><textarea id="'+obj.id+'_edit" name="'+obj.id+'" rows="4" cols="60">'+obj.innerHTML+'</textarea>';
var button = '<div class="save"><input id="'+obj.id+'_cancel" type="button" value="CANCEL" /><input id="'+obj.id+'_save" type="button" value="SAVE" /></div></div>';

new Insertion.After(obj, textarea+button);

Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);


function showAsEditable(obj, clear){
if (!clear){
Element.addClassName(obj, 'editable');
Element.removeClassName(obj, 'editable');

function saveChanges(obj){

var new_content = escape($F(obj.id+'_edit'));

obj.innerHTML = "Saving...";
cleanUp(obj, true);

var success = function(t){editComplete(t, obj);}
var failure = function(t){editFailed(t, obj);}

var url = 'edit.php';
var pars = 'id='+obj.id+'&content='+new_content;
var myAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});


function cleanUp(obj, keepEditable){
if (!keepEditable) showAsEditable(obj, true);

function editComplete(t, obj){
obj.innerHTML = t.responseText;
showAsEditable(obj, true);

function editFailed(t, obj){
obj.innerHTML = 'Sorry, the update failed.';

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum