Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 480601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:54:34+00:00 2026-05-13T00:54:34+00:00

Following problem: I would like to build a little clipboard with jQuery. I have

  • 0

Following problem:

I would like to build a little clipboard with jQuery. I have tried several times to store an object in the data of a javascript object with $(object).data(‘id’,objectToStore). Objects can be stored there that works fine. The problem is if I try to insert the stored data I only get a reference to that object. So when I am editing one copy also the others are changed. I need a way to copy the html code into a global variable and then to insert the code individually from the stored one. Hope u guys understand my problem! Thx!

Here the code:

Object

 /**
  * Objectdefinition
  */
 Clipboard = {

    //PROPERTIES
        itemcount: 0,           
        maxItems:10,            

        //Templates
        tplClipboard:"<div id='GUI_clipboard'><a href='' title='clear&nbsp;clipboard' id='GUI_clipboardClose' class='gritter-close'></a><ul></ul></div>",
        tplItem:"<li><a href='' class='[[type]] clipboardItem' id='[[id]]'><span class='hidden'>[[text]]</span></a></li>",
        tplItemHover:"<div class='GUI_clipboard_itemhover' style='width:[[offsetW]]px;height:[[offsetH]]px'><a href='' title='delete&nbsp;container' class='GUI_containerDelete'><span class='hidden'>Delete</span></a></div>",

        //Clipboarditem
        item:{
            id:null,
            type:null,
            content:'',
            offsetWidth:0,
            offsetHeight:0
        },

    //FUNCTIONS
        addItem:function(id,type,text,content,offsetH,offsetW){
            if(this.itemcount>=this.maxItems){
                return $.gritter.add({
                    title:'Clipboard',
                    text:'You cannot store more than '+ this.maxItems +' Elements!',
                    image:'warning',
                });
            }


            var item = {};
                item.id=id,
                item.type=type,
                item.content=content,
                item.offsetHeight=offsetH,
                item.offsetWidth= offsetW;


            this.verify();


            if (!this.checkRed(id)) {


                this.itemcount++;


                var tmp = this.tplItem;


                tmp = this.str_replace(['[[type]]', '[[id]]', '[[text]]'], [type, id, text], tmp);

                $('#GUI_clipboard ul').append(tmp);
                var $item = $('a#'+id);
                var number = this.itemcount;
                $item.hide().fadeIn('slow',function(){

                    Clipboard.redraw();
                });


                this.saveItem(item);


                var config = {
                    over:function(){Clipboard.hoveringItem($('a',this))},
                    out:function(){Clipboard.unhoveringItem($('a',this))},
                    timeout:1
                };
                $item.parent().hoverIntent(config);


                $item.draggable({
                    connectToSortable:'.column',                        
                    helper:'clone',                                     
                    revert:'invalid',                                   
                    cursor:'move',                                      //Cursor
                    start:function(){
                        $('body').unbind('mouseover',Content.showContainerMenu);
                        $('body').unbind('mouseout',Content.hideContainerMenu);
                        $('#GUI_clipboard li').trigger('mouseout');
                    },
                    stop:function(){
                        $('body').bind('mouseover',Content.showContainerMenu);
                        $('body').bind('mouseout',Content.hideContainerMenu);
                    }
                });
            }else{

                $('#'+id,'#GUI_clipboard').effect("bounce", { times:3 }, 300);
            }
        },


        saveItem:function(item){            
            $(this).data(item.id,item);
        },


        removeItem: function(id){
            $('#GUI_clipbaord').data(id,null);
            $('a[id='+id+']','#GUI_clipboard').parent().slideUp('slow',function(){$(this).remove()});
            this.itemcount--;

            if(this.itemcount==0)this.remove();
        },


        verify:function(){
            if($('#GUI_clipboard').length == 0){
                $('body').append(this.tplClipboard);                     

                $('#GUI_clipboard')                         
                    .css({
                        top:$(window).height()/2+'px'                       
                    })
                    .animate({                                          
                        left:0
                    }).children('.gritter-close').capture({cssClass:'GUI_clipboardClose'});     
            }
        },


        checkRed:function(id){
            if($('a[id='+id+']').length==0)return false;
            else return true;
        },


        remove:function(){
            $('#GUI_clipboard').animate({                                               
                left:'-60px'
            },function(){
                $(this).remove();
            });
            this.itemcount=0;
        },


        hoveringItem:function(el){

            var item = $(this).data($(el).attr('id')),
                content=item.content,
                oH=item.offsetHeight,
                oW=item.offsetWidth,


            tmp = this.tplItemHover;                
            tmp = this.str_replace(['[[offsetW]]', '[[offsetH]]'], [oW,oH], tmp);


            $(el).after(tmp);
            var $element = $('.GUI_clipboard_itemhover').append(content).prepend("<div class='GUI_clipboardArrow'></div>");


            $element.position({ my: 'left center', at: 'right center', of: $(el),offset:'14 0',collision:'none fit'});
            $('.GUI_clipboardArrow',$element).position({ my: 'left center', at: 'right center', of: $(el),offset:'-2 0',collision:'none fit'});


            $('#'+item.id,'#GUI_clipboard').removeClass('borderContainer editable');


            $('a.GUI_containerDelete',$element).click(function(){
                Clipboard.removeItem($element.children('.container').attr('id'));
                $element.fadeOut().remove();
            }).capture({cssClass:'GUI_clipboardItemClose'});

        },


        unhoveringItem:function(el){
            //Preview entfernen
            $(el).next().remove();
        },


        redraw:function(){
            if(this.itemcount>1){
                $('#GUI_clipboard').animate({
                     top: '-=20px'                      
                });
            }
        },


        str_replace: function(search, replace, subject, count) {

            var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
                f = [].concat(search),
                r = [].concat(replace),
                s = subject,
                ra = r instanceof Array, sa = s instanceof Array;
            s = [].concat(s);
            if (count) {
                this.window[count] = 0;
                }

            for (i=0, sl=s.length; i < sl; i++) {
                if (s[i] === '') {
                    continue;
                }
                for (j=0, fl=f.length; j < fl; j++) {
                    temp = s[i]+'';
                    repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
                    s[i] = (temp).split(f[j]).join(repl);
                    if (count && s[i] !== temp) {
                        this.window[count] += (temp.length-s[i].length)/f[j].length;}
                }
            }
            return sa ? s : s[0];

        }
 }

That was the object! As you see when I hover over an element the Object gets it from the internal store. But when I am inserting the object with following into the content area

var item = $(Clipboard).data($(ui.sender).attr('id')),
                        newItem = $.extend(true, {}, item);
                        content=newItem.content;

and then hover the clipboard to drag it and insert it again the object (html-code) from the contentarea disappears and is inserted in the preview of the clipboard.

Any ideas!

Please!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:54:34+00:00Added an answer on May 13, 2026 at 12:54 am

    Got the solution on my own! Thanks to the awesome JavaScript Tutorial from Leigh Kaszick: “The Basics of Object-Oriented JavaScript”. Check it out: http://net.tutsplus.com/tutorials/javascript-ajax/the-basics-of-object-oriented-javascript/

    Literal objects are always referenced while functional are not 😉 That’s the trick.

    Literal Object:

    var Storage = {
        id:'one',
        content:'blah'
    };
    

    functional Object:

    function Storage(id,content) = {
             this.id=id;
             this.content:content;
    }
    var myStorage = new Storage('one','blah');
    

    To solve my problem I created a new instance of the storage object each time when I pass data to the clipboard. And it works! 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following problem: i would like to create a footer. that footer
Ok, I have the following problem: I would like to scroll an overflowing ListBox
while designing my user control, i encountered the following problem: i would like to
I would like to find a better algorithm to solve the following problem: There
my problem is the following. I would like to encapsulate a NSString in a
I have a Moose class that i would like to store using Apache::Session::File. However,
I would like to build an AI for the following game: there are two
We have the following requirements for our Hudson setup: We would like to directly
I have the following example code and would like to know what kind of
I would really appreciate any help with the following problem: I need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.