CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Parking Elements  (Read 2388 times)

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Parking Elements
« on: 26 Oct 2020, 12:49:58 pm »
Hi,

I have my drag and drop js going but now i would like to be able to park the boxes off to the side and make them inactive until dragged and dropped back into the live area.   I am not looking for code solution here just a direction.

I dont know what you call that feature first of all, is it called element parking?
 
I am thinking that all i would need to do is just drag n drop them into an div that is display none or maybe display them in a way inside that div that its a list rather than the element itself.  Am i thinking somewhat in the right direction here? 
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #1 on: 26 Oct 2020, 05:57:23 pm »
Looks like i am on to something here... i was just farten around and it worked the first time i tried it, i was amazed lol

As you can see its parked....  but in full content but i can address that later (i just want the name of the element ie Video Activity, not the whole content.)

js

Code: [Select]
<script>
function parkit(boxvalue)
{
     
  $("#"+boxvalue).appendTo("#parking");

}//close function parkit

</script>


html - there are several feedwappers so i needed to also give it an id to isolate it
Code: [Select]

     <div id="parking">
       Parking:
       <br>
       <br>
       
       </div>



 <div class="feedwrapper" id="videobox" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?> <a href="javascript:void(0);" class="dark" onClick="parkit('videobox');"><i class="fas fa-parking"></i></a></h3>
    <div class="feed_data">
     Joe uploaded a new video
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
    </div>
    <h5 class="setright padhalveem textlite"><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h5>
  </div>  <!-- feedwrapper -->
 

Oh ok you dont allow attachments... ok here is the google drive image

https://drive.google.com/file/d/1uIshYNXyhOnd6c4MSyF-u_kT7c8I6WM6/view?usp=sharing

Now i need a unpark icon :)

Seems i can use the same concept to move the element to a pre-recorded position. For example if the user wants a certain block in a certain place all the time, i can store that location position and then just append the element to that position using ajax to get it from the db.  mmmmmmm interesting

So since i cant find a unpark icon that is free (fontawesome charges for theirs) i just decided to change the color to red... and then to remove the content and just keep the title i added a id to the html and then did a display:none on that feed data

new html
Code: [Select]

 <div class="feedwrapper" id="videobox" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?> <a href="javascript:void(0);" class="dark" onClick="parkit('videobox');"><i class="fas fa-parking"></i></a></h3>
    <div class="feed_data" id="video_feed_data">
     Joe uploaded a new video
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
    </div>
    <h5 class="setright padhalveem textlite"><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h5>
  </div>  <!-- feedwrapper -->


and then the new js

Code: [Select]

<script>
function parkit(boxvalue)
{
     
  $("#"+boxvalue).appendTo("#parking");
 
  document.getElementById(boxvalue).className="parkred";
 
  document.getElementById('video_feed_data').style="display:none";

}//close function parkit

</script>

//and parkred is just the css color red


new image
https://drive.google.com/file/d/1-VpGB6fQ6pHN_a58GN1zXWcHOpXh8CaR/view?usp=sharing

« Last Edit: 26 Oct 2020, 07:13:12 pm by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1052
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Parking Elements
« Reply #2 on: 27 Oct 2020, 09:24:17 am »
So many problems. You've got H5 on something that clearly isn't the start of a new section of content, without a H4 for it to even be a subsection of. You've got anchor with the void() crap and the outdated outmoded onclick junk slopped into the markup, you're actually kind-of ID heavy since I'm not sure these even warrant that, you've hardcoded it to make it harder to have multiple sections to "park", you've got that goofball $ thing indicating a pointless wrapper or jQuery bullshit is involved, presentational class garbage.

Not sure what you're trying to accomplish, but this is bad...

First off, let's clean up the markup
Code: [Select]
<section class="parkable" draggable>
<h3>
<?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?>
</h3>
<div class="hideWhenParked">
Joe uploaded a new video<br>
Steve shared a youtube video<br>
Karen is checking out videos
</div>
<footer>
<?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?>
</footer>
<!-- .parkable --></section>

getting rid of the excess ID's that we probably won't need anymore.

Then for the JavaScript, let's make it so that you can have any section with a h3 have the scripting only button added to it where it belongs, IN THE SCRIPTING!

Code: [Select]
(function(d) {

var
parking = d.getElementById('parking'),
parkHeaders = d.querySelectorAll('.parkable h3');

for (var h3 of parkHeaders) {
var
button = h3.appendChild(d.createElement('button')),
i = button.appendChild(d.createElement('i'));
button.type = 'button'; // remember, default is "submit"
button.onclick = park;
i.className = "fas fa-parking";
}

function park(event) {
parking.appendChild(event.currentTarget.parentNode.parentNode);
}

})(document);

Then a little CSS to do the little things that really aren't any of JavaScript's business.

Code: [Select]
#parking .hideWhenParked {
display:none;
}

#parking h3 > button {
color:red;
}


Though I'd be tempted to plug some actual text into that "parking" icon so people have some clue what it means... perhaps in a span to act as a tooltip? Or just put a title on it?
« Last Edit: 27 Oct 2020, 07:19:01 pm by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #3 on: 27 Oct 2020, 02:43:08 pm »
Yes i added the title attribute after i posted that code.    I just sent you a PM, have a look and let me know if i should proceed as suggested.   I wanted you to see it live before i rip it apart, as it works as i wanted currently. 

I use the onClick and the like because i dont know how to do the click event functions in js, with all the brackets and the nasty message (? is not a function grrrrr) it confuses me and i can never get js to work without blowing up on me...

I know that i use older code but the benefit is that i know what it does and i know what the data looks like, well some of it.  So i can fix it if needed.   Im willing to try new things but i just need to push myself to understand it.

Thanks

UPDATE:  I also just fixed the scrolling so that the title stays static, i moved the overflow to the innerdiv instead of the outer div...
« Last Edit: 27 Oct 2020, 05:37:56 pm by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1052
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Parking Elements
« Reply #4 on: 27 Oct 2020, 07:18:30 pm »
I just sent you a PM, have a look and let me know if i should proceed as suggested.
Absolutely as you won't have to repeat yourself all over the markup or hardcode the functions to do ID lookups on each and every blasted one.

I use the onClick and the like because i dont know how to do the click event functions in js

Well let's fix that.

with all the brackets and the nasty message (? is not a function grrrrr)

The what now?!?

Adding handlers from the JS is pretty simple. If you have the element in question in a variable, let's call it "button" because it's a ... button.

button.addEventListener('click', buttonClickHandler, false);

Anything out can onevent you can addEventlistener(event.

You can also from the javaScript use Element.onevent, but beware that 1) it erases any existing callbacks, and 2) it passes an event object to the callback, as opposed to being an independent function as per doing it in the markup.

Because you can chain multiple events on an object, you should use addEventListener. The only time I'd suggest using element.onevent is if you literally just made the DOM element with document.createElement.

The big difference in doing it from the JavaScript is that the handler function gets the Event object.
https://developer.mozilla.org/en-US/docs/Web/API/Event

The event object has two properties that make it really nice to work with.

Event.target : the element that initiated the event

Event.currentTarget : the element the event is attached to.

That might seem confusing, but lemme put it this way:

Code: [Select]
<button type="button" id="test">Some Text <i class="fas fa-whatever"></i></button>
Remember, the default type of button is submit. If we set button, it doesn't trigger any events so we don't need to preventDefault. This is why for scripting hooks you should use <button>, not <a>nchor!

Code: [Select]
document.getElementById("test").addEventListener('click', testClick, false);

function testClick(event) {
  console.log('target',  event.target);
  console.log('currentTarget', event.currentTarget);
} // testClick

If you click on the "some text" both event.target and event.currentTarget will be the button element, however if you click on the favicon event.target will be the i.fas, whilst event.currentTarget will still be the button.

Being that you can get the initiator or the base element means you can DOM-walk your way to parent nodes to do things.

Oh, and I had a typo in the code, I'll fix that. It says button.onclick = park; when it should be =parkIt;

In production, I'd have the click handler function simply detect if #parking is a parent. If so, move it back to #gridContainer.
« Last Edit: 27 Oct 2020, 07:21:22 pm by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #5 on: 27 Oct 2020, 09:07:04 pm »
That is awesome, thank you so much for that tutorial... ill start redoing it tonight since i cant seem to sleep.  Also when i moved the overflow to the inside div to keep my title static, i lost my resize:both on the original div...   I am hoping that when i get this all redone it will come back at some point.   Oh i see, its because overlow is required to use resize... darn.... oh wait i can just use overflow: hidden :)   Cool its  back... :)

I also just learned how to change the background color of the whole drag area as i drag and then change it back when i let it go.  Now the user knows where the drag boundaries are for the two dif sections, the top bar and the other big block.  I just did the top bar for now, when i decide on a color ill do the big block too.

I did it by learning how to get the parentNode of anything im working on..

Code: [Select]
var p = parkitem.parentNode;

parkitem is the div i am moving and p will be its parent which is the div i want to change the background color on when i grab the parkitem....

Thats perty dang cool...  so maybe today i dont hate js as much lol

Anyway to explain that message ? is not a function.....   i always get a similar message when dealing with events and listeners for some reason...  it always seems to come back and tell me that whatever i am doing is not a function, and im like "yes it is you stupid POC i preceded it with the word function"  lol  anyway next time it happens ill share it to see what im doing wrong.
« Last Edit: 27 Oct 2020, 10:24:13 pm by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #6 on: 28 Oct 2020, 12:27:43 am »
Now just in case i have to go back to this for some reason i wanted you to see what i have so far....  Im sure you prob saw most of it when you visited the site but this is the most current version.   Yes it has a silly patch because i knew what the problem was but did not know how to fix it so i just stuck some gum in the hole lol .... 

This is the parking js which i pieced together from stuff i found online, its not my code other than a few mods to it.

Code: [Select]
/* for parking only   */
 
 const dropParkitems = document.querySelectorAll('.parking, .parkbar_contentA, .parkbar_contentB, .parkbar_contentC'); // all the divs inside the container
 const dropParkarea  = document.querySelectorAll('.parkContainer'); //the container area
 
 
/* cant use parentNode because 3 items are in lower div than */
/* the parking div and i dont know how to do parentNode.parentNode */
       
 var father = document.getElementById('parkContainer');
 var pking = document.getElementById('parking');

 let draggedParkItem = '';  // bug in old code, using null:  will show null on the screen
 
 for(let k=0; k < dropParkitems.length; k++)
 {
   
     const parkitem = dropParkitems[k];
     
     
     parkitem.addEventListener('dragstart', function()
     {
         
         /* here we set the background alittle darker on grab to give the user */
         /* a heads up on where the drag area is */
         
        father.style.background="#bbb9b9";
       
        /* i stuck gum in the bug hole here */
        /* to fix bug when A B or C are grabbed   */
        /* the parking box changes bgcolor as well as the background behind it */
        /* it should be just the background behind it that changes */
        /* when parking box is moved its fine, its only when other boxs are grabbed */
        /* so we force the bg color back on anything but parking box */
       
        if(this.id != "parking")
        {
           
          pking.style.background="#d2cbcb";
         
        }
         
        draggedParkItem = parkitem;
       
        setTimeout(function()
        {
         parkitem.style.display = 'none';
           
        }, 0);
     });
     
     parkitem.addEventListener('dragend', function()
     {
       
        setTimeout(function()
        {
           
          draggedParkItem.style.display = 'block';
          draggedParkItem = null;
           
        }, 0);
     });
     
     /* the above code is for grabbing and moving object */
     
     
     
     
     /*  the below code is for placing and letting go of object */
     
     for(let p=0; p < dropParkarea.length; p++)
     {
         
         const parklist = dropParkarea[p];
         
         
         parklist.addEventListener('dragover', function(e)
         {
             e.preventDefault();
         });
         
         parklist.addEventListener('dragenter', function(e)
         {
             e.preventDefault();
         });
         
         parklist.addEventListener('drop', function(e)
         {
            this.append(draggedParkItem);
           
            /* we have to set the background back to normal after release */
            father.style.background="#d2cbcb";
           
         });
         
      }//close for let p
     
 }//close for let k
 


and then the other js document calls
Code: [Select]
function parkit(boxvalue, boxname)
{
     
  $("#"+boxvalue).appendTo("#parked_content");
 
  document.getElementById(boxname+'_feed_data').style="display:none";
  document.getElementById(boxname+'_bottom_text').style="display:none";
  document.getElementById(boxvalue).setAttribute('draggable', false);
 
  document.getElementById(boxname+'_unparked').style="display:none";
  document.getElementById(boxname+'_parked').style="display:inline-block";
 
  document.getElementById(boxname+'_faMouse').style="display:none";

}//close function parkit
 

function unParkit(boxvalue, boxname)
{
   
  if(boxname == "news")
  {
      $("#"+boxvalue).appendTo("#newsgridcontainer");
     
  }else{
     
        $("#"+boxvalue).appendTo("#gridcontainer");
     
       }
 
  document.getElementById(boxname+'_feed_data').style="display:block";
  document.getElementById(boxname+'_bottom_text').style="display:block";
  document.getElementById(boxvalue).setAttribute('draggable', true);
 
  document.getElementById(boxname+'_unparked').style="display:inline-block";
  document.getElementById(boxname+'_parked').style="display:none";
 
  document.getElementById(boxname+'_faMouse').style="display: inline-block";
   
}//close function unParkit




This is the parking html

Code: [Select]
<!-- parking container only -->
 
 <div class="parkContainer" id="parkContainer">
  <div class="parking" id="parking" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('FEED_PARKING_HEADER_TEXT')); ?> <span class="dark" title="Hold-N-Drag"><i class="fas fa-mouse"></i></span></h3>
    <div id="parked_content"></div>
  </div> <!-- parking -->
  <!-- just empty divs so we can move among them in the grid -->
  <div class="parkbar_contentA" draggable="true"><h3>Plugin A <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
  <div class="parkbar_contentB" draggable="true"><h3>Plugin B <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
  <div class="parkbar_contentC" draggable="true"><h3>Plugin C <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
 </div> <!-- parkContainer -->
 <br>



And the html for one of the div blocks that can be parked
Code: [Select]
<div class="feedwrapper" id="videobox" draggable="true">
    <h3><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?>
    <span id="video_unparked">
    <a href="javascript:void(0);" title="<?= htmlspecialchars(getLangValue('FEED_PARK_WORD_TEXT')); ?>" class="dark" onClick="parkit('videobox','video');"><i class="fas fa-parking"></i></a>
    </span>
    <span id="video_parked">
    <a href="javascript:void(0);" title="<?= htmlspecialchars(getLangValue('FEED_UNPARK_WORD_TEXT')); ?>" class="parkred" onClick="unParkit('videobox','video');"><i class="fas fa-parking"></i></a>
    </span>
    <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span>
    </h3>
    <div class="feed_data" id="video_feed_data">
     Joe uploaded a new video
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
    </div>
    <h5 class="setright padhalve_em textlite" id="video_bottom_text"><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h5>
  </div>  <!-- feedwrapper -->

and the parking css

Code: [Select]

/*
  ***************************
  *  P A R K I N G   
  ***************************
 */
 
.parkContainer {
    width: 98.5%;
    display: grid;
    max-height: 11em;
    grid-template-columns: 23% 23% 23% 23%;
    grid-gap: 1em;
    overflow: hidden;
    margin-left: 1em;
    margin-right: 1em;
}

.parkContainer > div {
    padding: 1em;
    border: 0.063em solid #000000;
}


.parkbar_contentA,
.parkbar_contentB,
.parkbar_contentC {
    max-height: 6em;
    background-color: #d2cbcb; /* off white-cream */
}


#parking {
    max-width: 17em;
    padding-left: 1em;
    border: .063em solid #000000;
    padding-bottom: 1em;
    margin-left: 1em;
}


#newsbox {
    display: block;
    width: 100%;
}


#chatbox,
#blogbox,
#gallerybox,
#forumbox,
#memberbox,
#videobox  {
     display: block;
     width: 24.5em;
}


.parkred i {
    color: #6b0007;  /* red */
    padding-left: 0.25em;
}

#parked_content {
    display: block;
    max-width: 13em;
    max-height: 6em;
    background-color: #b1b1b2;
    color: #000000;
    padding: 0.50em;
    overflow-y: auto;
    overflow-x: hidden;
    resize: none;
}


OK now to rip it all apart and start over lmao hee hee   thanks for your tips  ill get to work now...
« Last Edit: 28 Oct 2020, 03:55:55 am by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #7 on: 28 Oct 2020, 05:03:47 am »
Ok so i set up one element (the video box) using your suggestion.  I didnt just copy paste the code i typed it all in because i wanted to try to understand it as i went.   

So i see the result now...   Correct me if i am wrong (like i have to say that to you LMAO)   but by the time i give it a background and border  and do the other css and scrollbars and the code to unpark it and all the other stuff,  wont i be at about the same amount of code as i was before?     

I dont mind doing it this way if its better and saves some resources as i  want this to be lean and mean.   But it wont really save me any coding will it... its just a better way to doing it right?

LOL so funny, i made a comment about parentNode parentNode before and you used it on this suggestion, i just took a stab in the dark that it was possible, i really didnt know for sure...  now i do.. :)


OK looking pretty good now,  i had to use true on draggable or it would not enable it.  Also i could not use footer because i have footer assigned already so i used h4.    I am also surprised that the php worked inside the js like that, it was just a stab in the dark for the lang key.

here is the new html for the one video element  using your suggested code and some of mine i had to put back.

Code: [Select]
<div class="feedwrapper" id="videobox" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h3>
  <section class="parkable">
   <div class="hideWhenParked">
     Joe uploaded a new video
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
   </div>
  </section> <!-- parkable -->
   <h4 class="setright padhalve_em textlite"><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h4>
 </div>



here is the js for that
Code: [Select]
(function(d) {
 
   var parking = d.getElementById('videobox');
   var parkHeaders = d.querySelectorAll('.feedwrapper h3');
 
   for(var h3 of parkHeaders)
   {
       /* p icon button */
       var button = h3.appendChild(d.createElement('button'));
       var p = button.appendChild(d.createElement('p'));
       button.type='button';// remember, default is the submit
       button.onclick = park;
       p.className = "fas fa-parking";
       p.title = "<?= htmlspecialchars(getLangValue('FEED_PARK_WORD_TEXT')); ?>";
       
       
       /* mouse icon */
       /* we really dont need this to be a button */
       /* because clicking anywhere on the block will drag it */
       /* its just for asthetics */
       
        var mouse_image = h3.appendChild(d.createElement('p'));
        mouse_image.className = "fas fa-mouse";
        mouse_image.title = "<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>";
       
   }//end for loop
   
   
   function park(event)
   {
       
     parking.appendChild(event.currentTarget.parentNode.parentNode); 
       
   }//close function park
 
 })(document);   
   


No i suspect when i get this code it its own js file that the php lang key wont work anymore.  If not ill have to leave the code at the base of the index file, i dont like it but well it is what it is...

and here is the css

Code: [Select]
#parking .hideWhenParked {
    display: none;
}

#parking h3 > button {
    color: #6b0007;  /* red */
    border: 0;
}

.feedwrapper h3 button {
    background-color: #dbdee5;  /* off white */
    border: 0;
}
 
.parkable {
    display: block;
    max-height: 12em;
    padding: 0.40em;
    border: 0.02em solid #000000;
    word-break: break-word;
    overflow-y: auto;
    overflow-x: hidden; /* hide bottom scroll bar */
}
 


i think you saved me alittle coding as this does not include the unpark process, its close i think...
« Last Edit: 28 Oct 2020, 06:27:40 am by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #8 on: 28 Oct 2020, 06:32:45 am »
I dont know what this error means but im trying to get it fixed \

Quote
index.php:657 Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.

im guessing that means that the child and the parent share the same space so we dont need to get the child just the parent

line 657
Code: [Select]
parking.appendChild(event.currentTarget.parentNode.parentNode);

im going to take a guess and say that we dont need the second parentNode anymore since i had to add a div wrapper

ok so maybe neigther of the parentNodes is needed... so i change it to this code

Code: [Select]

$("#videobox").appendTo("#parked_content"); 

it works and no error... the content parked still has some div body elements to it in the parking space, but i can hide those with css i think..   
« Last Edit: 28 Oct 2020, 06:52:02 am by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #9 on: 28 Oct 2020, 09:11:23 am »
Ok time to ask for help again... i am wayyy over my head here..
 the parking works fine, but i am working on the unparking and i cant seen to get the button element from the parked_content div so i can call the button_onclick=unParkit

your login is still good if you want to have a look at what i have so far..

here is the code i have so far...  all i get is NodeLIst[]

Code: [Select]

<script>
 (function(d) {

   var unParking = d.querySelectorAll('.parked_content.feedwrapper.h3.button'); 
   var parkHeaders = d.querySelectorAll('.feedwrapper h3');
 
   for(var h3 of parkHeaders)
   {
       /* p icon button */
       var button = h3.appendChild(d.createElement('button'));
       var p = button.appendChild(d.createElement('p'));
       button.type='button';// remember, default is the submit
       button.onclick = parkit;
       p.className = "fas fa-parking";
       p.title = "<?= htmlspecialchars(getLangValue('FEED_PARK_WORD_TEXT')); ?>";
       p.id="videobox_pIcon"; 
     
       
       
       /* mouse icon */
       /* we really dont need this to be a button */
       /* because clicking anywhere on the block will drag it */
       /* its just for asthetics */
       
        var mouse_image = h3.appendChild(d.createElement('p'));
        mouse_image.className = "fas fa-mouse";
        mouse_image.title = "<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>";
        mouse_image.id = "videobox_mouse";
       
       
       
        console.log(unParking);
       
   }//end for loop
   
     /* i am trying to get the button element so i can use the parked_button.onclick = unParkit  */
     /* but all i get is NodeList[]  and i have no idea what all that data in the list means */
   
    for(let redbutton of Object.keys(unParking))
    {
       
      var parked_button = unParking(button);
     
      //console.log(parked_button);
   
     //button.onclick = unParkit;
   
    }//close for loop
   
   
   
   
   function parkit(event)
   {
      $("#videobox").appendTo("#parked_content");
     
      document.getElementById('videobox_mouse').style="display:none";
      document.getElementById('videobox_pIcon').style="color: #6b0007";
      document.getElementById('videobox_pIcon').title="<?= htmlspecialchars(getLangValue('FEED_UNPARK_WORD_TEXT')); ?>";
       
   }//close function park
   
   
   function unParkit(boxid)
   {
   
     if(boxid == "newsbox")
     {
         
       $("#"+boxid).appendTo("#newsgridcontainer");
     
     }else{
     
            $("#"+boxid).appendTo("#gridcontainer");
     
          }   
   
   }//close function inParkit
   
 
 })(document);
   
</script>


and html for the parking container

Code: [Select]
<!-- parking container only -->
 
 <div class="parkContainer" id="parkContainer">
  <div class="parking" id="parking" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('FEED_PARKING_HEADER_TEXT')); ?> <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3>
    <div class="parked_content" id="parked_content"></div>
  </div> <!-- parking -->
  <!-- just empty divs so we can move among them in the grid -->
  <div class="parkbar_contentA" draggable="true"><h3>Plugin A <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
  <div class="parkbar_contentB" draggable="true"><h3>Plugin B <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
  <div class="parkbar_contentC" draggable="true"><h3>Plugin C <span class="dark" title="<?= htmlspecialchars(getLangValue('HOLD_AND_DRAG_WORD_TEXT')); ?>"><i class="fas fa-mouse"></i></span></h3></div>
 </div> <!-- parkContainer -->
 <br>
 

and html for the video element

Code: [Select]
<div class="feedwrapper" id="videobox" draggable="true">
   <h3><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h3>
  <section class="parkable" id="parkable">
   <div class="hideWhenParked">
     Joe uploaded a new video
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
     Karen is checking out videos
     <br>
     Steve shared a youtube video
     <br>
   </div>
  </section> <!-- parkable -->
   <h4 class="setright padhalve_em textlite"><?= htmlspecialchars(getLangValue('VIDEO_ACTIVITY_WORD_TEXT')); ?></h4>
 </div>
 


how do i get the parked_content button element, it should be parked_content.feedwrapper.h3.button ?

thanks

« Last Edit: 28 Oct 2020, 09:23:26 am by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #10 on: 28 Oct 2020, 08:46:46 pm »
I am on the right track i think....  i think the button itself is the firstChild node so now that i know what node means (node is the object) i can slowly find my way to the button by reading about childNodes  :) 

I did have a big duh moment lol....  i was getting frustrated on how am i going to know what to focus on in the querySelectAll and then after some sleep it hit me, well stupid the element tab gives you all that in the console lol  i was like well duh  lol
« Last Edit: 28 Oct 2020, 08:48:29 pm by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #11 on: 28 Oct 2020, 10:02:54 pm »
I am so tempted just to go back to what i had before for some of this, especiall the unpark code.   I just cant seem go hook the button in the parked_content area and cause the event. 

I console log the event on parkit and i see the mouse results,  i know i dont have to recreate the button becaue its already there, all i have to do is just  assign  the onclick event but my brain is squirting all all directions and i just cant seem to hook it no matter what i try.   Usually if i can see the data im not bad about hooking it, but this time im very close to giving up and just using the new code on the parkit process and going back to my  old code for the unpark...    its just too complicated ...

this is about as far as i can go....   i know the unParkHeaders is correct because its the same node h3 as the park process after that im lost, i cannot get the event to fire for inParkit

Code: [Select]
  /* this is to unpark it */
   
    var unParkHeaders = d.querySelectorAll('#parked_content .feedwrapper h3'); //this is correct
   
    for(var h3 of unParkHeaders)
    {
   
       var redbutton = h3;
       redbutton.onclick = unParkit;
   
    }//end for loop
   
       
    //console.log(unParkHeaders);
   
   
   function unParkit(event)
   {
       
     console.log(event); 
       
   }

UPDATE:  so i get now that i have to assign the button value  ill try this

Code: [Select]

 var redbutton = h3.appendChild(d.getElementsByTagName('button'));


but redbutton.onclick does not work so im guessing  im still working with an array so i need to specify which one... i think i need to replace appendChild with something like getChild or something because we are not appending anymore, thats already done.  now we need to get it..

I also noticed that d is the entire document.  Isnt that storing the whole document for nothing?  I dont know...   Seems to me that saying document.getElementById('whatever')  vrs storing the whole document in a var d would be much less resources used.... but again i dont know...

OK i think im on the right track now... i was able to get the node output to show length of 1 which means it found the button...   instead of fussing with the class stuff  i decided to just look for the buttons themselves, now if i can isolate this search to just the parked_content id name then i know i have just the parked buttons which is what i want.

Code: [Select]
var unParkHeaders = d.querySelectorAll('[type=button]');
   
     console.log(unParkHeaders);


UPDATE:   so i decided to start from the beginning and take a look at some of the parkit output.   Then i decided the best thing to do was to strip down the videobox  as it would be as if i parked it and  add it to the html in side the parked_content div,   that way i had some test data to work with... that helped alot to be able to try different things and log the output..

As i did that it hit me... wait a second,,, and sure enough when i parked the real item it did not have a onclick = inside the html as it sat inside the parked_content area... that is why the onclick event was not working, it didnt exist...   

So now that i have added that with the code below, i feel im close enough now that i cant give up yet.. its still not unparking but at least the onclick is inside the element now..   

The problem im having is that unline the other code js has no idea what  unParkit is, it wont accept onclick="unParkit()"  or onclick="unParkit"  so now i have to work that issue out...   

Maybe what i will do is rather than try to work with unParkit inside of this function(d) maybe ill just make a separate function so that the html knows what to do as it normally would.   

Anyway here is how i created the onclick..  I figured the best time to do it is during the parkit process

Code: [Select]
  function parkit(event)
   {
      //console.log(event);
       
      $("#videobox").appendTo("#parked_content");
     
      document.getElementById('videobox_mouse').style="display:none";
      document.getElementById('videobox_pIcon').style="color: #6b0007";
      document.getElementById('videobox_pIcon').title="<?= htmlspecialchars(getLangValue('FEED_UNPARK_WORD_TEXT')); ?>";
     
      var el = d.getElementById('videobox_pIcon');
      var oc = d.createAttribute('onclick');
      oc.value = 'unParkit';
      el.setAttributeNode(oc);
     
       
   }//close function parkit


i will still need to make this dynamic so i can use any element id  but that will come later, im trying to get the videobox to work first then i can work on doing that...
« Last Edit: 29 Oct 2020, 12:36:33 am by durango_d »
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #12 on: 29 Oct 2020, 01:58:10 am »
Sorry this time it just did not work out... im going back to my old code, it worked and i knew what it was doing... I hate to quit and i really really sincerely thank you for the time you spent with me, i did learn some stuff so it was not all for nothing...   

But when i think about storing the whole document in function(d) and the fact that i have to do this

Code: [Select]
    var el = d.getElementById('videobox_pIcon');
      var oc = d.createAttribute('onclick');
      oc.value = "unParkit('videobox','video');";
      el.setAttributeNode(oc);

Verses this in html

Code: [Select]
onclick="unParkit('videobox', 'video');

4 lines of code compared to 1

and the fact that i just dont know what i am doing and i dont belong at this level of js, then its time for me to stay in the old ways...   I want to work with the new stuff but its going to take a whole lot more education on my part understanding the underbelly of js before i can ever understand the new code fully..

So again i thank you DS for you time.... i know you tried hard... but i have to move on to the next objective, this feature is taking way too long to get going and i have to put it behind me and move on to coding the profile page and other things...

Thanks for the attempt  :)   sorry it did not work out this time...

Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1052
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Parking Elements
« Reply #13 on: 29 Oct 2020, 07:42:02 am »
But when i think about storing the whole document in function(d) and the fact that i have to do this

Code: [Select]
    var el = d.getElementById('videobox_pIcon');
      var oc = d.createAttribute('onclick');
      oc.value = "unParkit('videobox','video');";
      el.setAttributeNode(oc);

I don't know where you got that, but that's not how this works. That's not how ANY of this is supposed to work.

d.getElementByID('videobox_picion).addEventListener('click', togglePark, false);

One line... NOT that you should be doing getElementById since you'd have to hard code each and every blasted link. NOT that you should have them in the markup since they're scripting only elements. etc, etc, etc.. You don't pass the bloody ID then get it, you look at the parent or the parent's parent.

I'm heading to bed, but when I get up I'll toss together a quickie to show you what I mean. Your entire methodology is bloated nonsensical outdated junk.
 
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: Parking Elements
« Reply #14 on: 29 Oct 2020, 09:13:41 am »
I know it is outdated, i got so frustrated... 

toggle() huh.... ill look it up i never heard of that before..
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

 

SMF spam blocked by CleanTalk

Advertisement