Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 04:41 AM   PM User | #1
cmulletman
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
cmulletman is an unknown quantity at this point
Question Complex JS Assigment

Hi there everyone!

I have a couple things I need help with and I'm very new to javascript as I'm taking a class on this right now. We have an extra credit assignment that I'd really like to have. It's meant to be fairly vague and open for interpretation. Here's what it says:

Quote:
== Write a jQuery plugin that serves as a DOMElement factory with supporting HTML/CSS
You have a web application that adds orders to carts. Items in the cart can be displayed on a dedicated cart page, in a modal/dialog with cart contents, and in an expandable menu from a fixed footer (open to interpretation). These item lists should be detailed, somewhat informative, and summarized (respectively and based on context, so the 'expandable menu' should be minimal while the dedicated 'cart page' should have the most detail). The jQuery plugin should use the same method(s) to add items to each instance of the cart contents without the use of parameters that identify the context of the list that the item is being added to. HTML/CSS can be minimal and only needs to support displaying the items in a rudimentary (but functional) way.

== Write a small Javascript application that does not expose any logic to the end user
While there is no such thing as "secure Javascript", adding objects to the global namespace is typically a Bad Idea. However, sometimes scope presents problems interfacing with objects outside of that scope. Create a Javascript object/context that does not expose itself globally but is still able to be interacted with by other objects out of scope (open to interpretation) while maintaining application integrity.

== Create a simple HTML page that saves state
Sometimes a page requires a lot of application logic that changes the contents or functionality of the page drastically from its initial state. In this instance, instead of needing to reproduce steps to achieve the same results on subsequent pageloads, the page should effectively save its state so that reloading the page will not have an adverse effect on its contents or functionality. Page contents are arbitrary and left up to you.

We only have to do 2 out of the three options. Ideally I'd like to combine at least 2 of them into one document and make it an awesome assignment. If there's a way to combine all 3 that'd be even more awesome. Can you guys point to resources that ideally already have most of this created so I just have to merge it together and maybe make some of my own little markup? Or would it take very long for someone here to do 2 of these for me really quick? If the latter is an option, I'm willing to pay a little bit of money for your time.

Thanks!
cmulletman is offline   Reply With Quote
Old 10-11-2012, 04:54 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
so, can we help you cheat and if that requires some effort you'll throw some change at us?

love the optimism...
xelawho is offline   Reply With Quote
Old 10-11-2012, 04:55 AM   PM User | #3
cmulletman
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
cmulletman is an unknown quantity at this point
Honestly yes, but I do actually learn faster and more efficiently if I look at other people's code. So it does actually help me out in the long run as far as actually learning it goes.
cmulletman is offline   Reply With Quote
Old 10-11-2012, 05:54 AM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Quote:
Originally Posted by cmulletman View Post
I do actually learn faster and more efficiently if I look at other people's code.
Believe me, you don't. The way you learn to write code is by writing code.
xelawho is offline   Reply With Quote
Old 10-11-2012, 08:57 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,195
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
The second and third ones there aren't really all that complex or hard.

For the second one, you just use the standard self-invoking anonymous function and you allow HTML elements to interact with it by specifying (for example) dummy class names, where the class name(s) tell your JS code what to do.

The third one is truly simple: cookies. And you could implement it with the same self-invoking anonymous function used in the second answer, so it's easy to combine those two.

In fact, you can easily fulfill both those by, for example. using a class name on various form fields or other user choices to indicate a value that needs to be stored in the cookie and then restored on page load.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-12-2012, 01:52 AM   PM User | #6
cmulletman
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
cmulletman is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
The second and third ones there aren't really all that complex or hard.

For the second one, you just use the standard self-invoking anonymous function and you allow HTML elements to interact with it by specifying (for example) dummy class names, where the class name(s) tell your JS code what to do.

The third one is truly simple: cookies. And you could implement it with the same self-invoking anonymous function used in the second answer, so it's easy to combine those two.

In fact, you can easily fulfill both those by, for example. using a class name on various form fields or other user choices to indicate a value that needs to be stored in the cookie and then restored on page load.
Thank you for this help and not berating me over asking for help. Do you have any specific resources that you think might be helpful for me to do this?
cmulletman is offline   Reply With Quote
Old 10-12-2012, 08:15 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by cmulletman View Post
Thank you for this help and not berating me over asking for help. Do you have any specific resources that you think might be helpful for me to do this?
I have that idea that people here were offended by your offer of money to do your homework for you. That is, cheat. You should know that it is not really in your best interests that others do your all or most homework for you.

The assignment you post seems to me too advanced and inappropriate for someone who claims to be "very new to Javascript".

Resources - what is wrong with your course tutorial meterials?
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 10-12-2012, 05:33 PM   PM User | #8
cmulletman
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
cmulletman is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
I have that idea that people here were offended by your offer of money to do your homework for you. That is, cheat. You should know that it is not really in your best interests that others do your all or most homework for you.

The assignment you post seems to me too advanced and inappropriate for someone who claims to be "very new to Javascript".

Resources - what is wrong with your course tutorial meterials?
I understand that, but I also asked for resources first and foremost. I was only offering money if someone wanted to do it for me. Yes, I'd love to have resources and do it all myself and actually learn it, but I'm don't always put off the opportunity to see someone else's code and learn from how they do something. Like I said before, this is an extra credit assignment so it's meant to be harder to achieve. We also have people in the class that are a bit more advanced in Javascript than I am so it'll be easier for them to do it. This is a general web development class that hasn't yet provided specific resources for something like this so my class resources aren't much help in this sense.
cmulletman is offline   Reply With Quote
Old 10-12-2012, 08:54 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,195
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here is a VERY stripped down version of some code you could use. You can find setCookie and getCookie scripts all over the web, for example, so I leave them to you.

Code:
<html>
<body>
<form action="someOtherPage.php" method="POST">
   What is your name? <input class="SAVE" name="username" />
   <br/>
   What is your age? <input class="SAVE" name="age" />
   <br/>
   <input class="SAVETRIGGER" type="button" value="Save my entries" />
</form>

<script type="text/javascript">
(
  function( )
  {
      var toSave = document.getElementsByClassName("SAVE");
      for ( var t = 0; t < toSave.length; ++t )
      {
          var field = toSave[t];
          field.value = getCookie(  field.name );
      }

      var triggers = document.getElementsByClassName("SAVETRIGGER");
      for ( var t = 0; t < triggers.length; ++t )
      {
          triggers[t].onclick = saveData;
      }

      function saveData( )
      {
          for ( var t = 0; t < toSave.length; ++t )
          {
              var field = toSave[t];
              setCookie( field.value, field.name );
          }
      
      }

      function setCookie( name, value ) { ...you write.. }
      function getCookie( name ) { ...you write... }
  }
)( );
</script>
</body>
</html>
That is truly bare bones, but it does demonstrate the features requested in the second and third requirements. You need to flesh it out a *LOT* more. I would suggest, for example, that you provide at least two and better more HTML pages showing auto-remembering of values across pages, etc., etc. Or maybe auto-remembering that takes into account the URL of the pages, even better.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-12-2012, 08:55 PM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,195
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
p.s.: getElementsByClassName() is not available on older MSIE, but I can't see how that would matter for an assignment.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:38 PM.


Advertisement
Log in to turn off these ads.