Tuesday, June 10, 2014

Changes 6/10/14

jQuery:

  • Began process of converting shaking mlg elements to canvas after this successful test
  • Didn't get very far though

Thursday, June 5, 2014

Changes 6/5/14

jQuery:

  • Reworked the mlg element creation, as there was repeated code between the hitmarker creation and mlgElement creation.  I moved the shared code into a placeImage function, which takes an object which holds parameters.
  • Changed the shaker from shaking the body to shaking only the mlgElements.
  • Moved the mlg toggle button's onclick into the code, defining it with a jQuery event.
  • Added a github repo for the website.

Wednesday, June 4, 2014

Changes June 4, 2014

jQuery:

  • Continued trying to figure out why the mlg toggle button press doesn't always fire, but I couldn't really figure it out.  I think it might have to do with lag in the browser due to the shaking and element fading.

Tuesday, June 3, 2014

Changes 6/3/14

jQuery:

  • Fixed a bug where I had put setInterval(generateMLGElement(), 500);, which did not generate elements after the interval.  I'm not really sure why, but changing it to setInterval(function() {generateMLGElement()}, 500); fixed the problem.
  • I also began investigating a problem where the button press does not always stop or start the shakes and element fades.  As far as I can tell the onclick method of the button does not always fire when the button has been pressed.
  • Figured out that jQuery does use css selectors, and the reason it wasn't working for me was I had used the selector button.mlg to try to select a button I had never set to the mlg class.  By adding the class in html, everything worked fine.

Wednesday, May 28, 2014

Changes 5/28/14

jQuery:

  • I'm still trying to make elements shake.  I almost have it, but I have this weird problem when trying to programatically animate an element.
  • I'm using the code $(selector).animate({next_dir : sign + '=15px'}); to animate, where selector is something passed into the surrounding code, and next_dir and sign change depending on the number of iterations.
  • This code does not work for some reason, and there is something wrong with next_dir.  It's super weird because passing the function as $(selector).animate({"left" : sign + '=15px'}); works correctly but setting next_dir = "left" and passing $(selector).animate({next_dir : sign + '=15px'}); does not work, saying that there is an invalid property id.

Saturday, May 24, 2014

Changes 5/24/14 (Bonus!)

jQuery:

  • Script visible at http://students.gctaa.net/~ahirschberg/, actual script here.  Note that these may change.
  • Got my script working; image elements fade in and out at random locations.
  • Now the elements actually get removed correctly, instead of sitting invisible and slowing down the browser
  • I implemented an id delegation system which I had originally written for the movable window project I was working on.  I then improved it by allowing for ids to be deassigned and "recycled".  I ran into some interesting problems.
  • For example, look at code snippet 1. Substituting $(this).attr("id") for ele_id in the timeoutManager.addElement(...); line should be the same thing, right?  The .attr("id") method just pulls the id out of the element being created, which had its id set to ele_id.  There SHOULD be no difference between them.  However, these two are NOT necessarily the same.  Javascript is super weird, and when I was testing I entered into the console a for loop which would call generateMLGElement() many times with no delay, and I found that the function itself would fully execute, but queue the .load() statements, which would be executed later (So if you ran generateMLGElement() 4 times extremely rapidly, it would execute all the code in the body excluding the stuff in .load() 4 times, then execute the stuff within .load() for each element after all that was completed).  This caused the ele_id to always be set to the id of the greatest element created for every single element.  So if the four elements were created, the ele_id accessed by every .load() function would be 4, regardless of what the id was supposed to be.  I worked around this by pulling the id out of the element itself rather than relying on the element id.
  • If you couldn't quite understand what I was talking about, try modifying mlg.js so that the timeoutManager is sent ele_id rather than than .attr("id") in its addElement method (the one shown in the code snippet).  If you enter into the console a for loop such as for (var i = 0; i <=5; i++) {generateMLGElement();}, you will see that the elements with ids 0 through 4 will not be removed but instead remain on the page (faded, but still there), because the id 5 will have been removed and registered for every element.

 Code:

  1. function generateMLGElement() {
      ...
      ele_id = ID_PREFIX + idManager.assign()
      element = 
        $('<img class="mlg" src="'+ imagesrc +'" ' + 'id="' + ele_id + '">').load(function() {
          ... 
          timeoutManager.addElement($(this).attr("id"), 2000);
        }) 
      ...
    }

Friday, May 23, 2014

Changes 5/23/14

Nothing:

  • Didn't really do anything because of the workplace readiness picture and having to leave early.
  • jQuery: Realized that I need to set element ids in order to fade and remove elements a specific time after they are created, since remove is not queueable after a delay().