Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts

    insertAfter, insert Before

    Hi all i have yet another problem:

    Code:
    function contextMenuWork(action, el, pos) {
    			switch (action) {
    				case "delete":
    					{
    						$(el).remove();
    						break;
    					}
    				case "insert":
    					{
    						$("#copiedElement").html($(el).outerHTML());
    						break;
    					}
    				case "pasteAfter":
    					{
    						var copiedElement = $("#copiedElement").html();
    						copiedElement.insertAfter($(el));
    						break;
    					}	
    				case "edit":
    					{
    						var copiedElement = $("#copiedElement").html();
    						copiedElement.insertBefore($(el));
    						break;
    					}
    			}
    	   }
    Firebug says copiedElement.insertBefore is not a function but i cant understand why. any help much appreciated.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    var copiedElement = $("#copiedElement").html();
    copiedElement.insertBefore($(el));
    I think the problem lies there. Your variable copiedElement is not a reference to an object. Is it?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    i've gotten this far..

    Code:
    function contextMenuWork(action, el, pos) {
    			switch (action) {
    				case "delete":
    					{
    						$(el).remove();
    						break;
    					}
    				case "insert":
    					{
    						var copy = $(el).outerHTML();
    						$("#copiedElement").html(copy);
    						var child = $("#copiedElement").children()[0];
    						$(child).attr("id", "tester");
    						break;
    					}
    				case "pasteAfter":
    					{
    						$("#copiedElement").children()[0].insertAfter($(el));
    						break;
    					}	
    				case "edit":
    					{
    						$("#copiedElement").children()[0].insertBefore($(el));
    						break;
    					}
    			}
    	   }
    but now getting error:

    uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: https://web111.secure-secure.co.uk/s...age.php#insert :: contextMenuWork :: line 64" data: no]

    Line 0
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    line 64 being $("#copiedElement").children()[0].insertBefore($(el));
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #5
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    I have managed to get it to work...
    But i was wondering if you could yet again help me. This is the code:

    Code:
    $(document).ready(function() {
    		$("p, ul, li").contextMenu({ 
    			menu: 'myMenu' 
    		}, 
    			function(action, el, pos) { 
    				contextMenuWork(action, el, pos); 
    		});
    		$(".openmenu").contextMenu({ 
    			menu: 'myMenu', leftButton: true 
    		}, 
    			function(action, el, pos) { 
    				contextMenuWork(action, el.parent("tr"), pos); 
    			}
    		);
    	});
    		
    	function contextMenuWork(action, el, pos) {
    		switch (action) {
    			case "delete":
    			  {
    				  $(el).remove();
    				  break;
    			  }
    			case "insert":
    			  {
    				  var copy = $(el).outerHTML();
    				  $("#copiedElement").html(copy);
    				  var child = $("#copiedElement").children()[0];
    				  $(child).attr("id", "tester");
    				  $("#copiedElement").attr("rel", $(child).attr("id"));
    				  break;
    			  }
    			case "pasteAfter":
    			  {
    				  var copyID = $("#copiedElement").attr("rel");
    				  $("#"+copyID).insertAfter($(el));
    				  break;
    			  }	
    			case "edit":
    			  {
    				  var copyID = $("#copiedElement").attr("rel");
    				  $("#"+copyID).insertBefore($(el));
    				  break;
    			  }
    		}
       }
    what it does is cuts and pastes selected content. But once to content is pasted, you cant copy that element ( i think due to because its not in the "DOM" (sorry i dont know the technical jargon) ) previously stated here:

    Code:
    $("p, ul, li").contextMenu({ 
    	menu: 'myMenu' 
    },
    How do i add the pasted elements into the "DOM". Please correct my terminology if im using it in the wrong context. Many thanks.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •