-5

Sometimes while I explore a website I came across a javascript function that can serve my future needs so I use the firebug console or google chrome and by inspecting the element on which the function is invoked i get an incomprehensible code

so whats the trick please to get the function attached to this link on the picture?

below there is an example in image that shows what i mean

Community
  • 1
  • 1
  • 2
    What you see in the image is just the event handler for a `click` event. Instead of just trying to copy out the effect your are looking for, you should google to see if you can find a similar snippet or library that does what you want. – nils May 13 '15 at 11:36
  • 1
    Plupload ist opensource so this should be no problem for you http://www.plupload.com/ . `preventDefault()` is a jQuery-method –  May 13 '15 at 11:38
  • nils : thanks for giving help , i'm not trying to copy rather i'm trying to understand the invoked function for the change event to see how they handle the upload, that's because i learned the javascript fundamentals then advanced javascript but still unable to manipulate libraries i don't know how to achive this level – heavenclick hatim May 13 '15 at 12:14
  • Daniel Ruf : thank's for the proposition , it seems a good library – heavenclick hatim May 13 '15 at 12:28

1 Answers1

0

It looks like the code was minimized by some tool. This creates a more compact form of Javascript so a library, for example, becomes smaller in size which reduces download times and makes the library harder to read. The code is still Javascript but is indeed harder to read.

So to clarify: you are looking at the correct function which handles the click but it has most likely been made harder to read by a tool.

When I look at the sample image you included it looks like the third line

t && !t.disabled && t.click(), e.preventDefault();

Could have looked like this before it was minimized:

if(t && !t.disabled)
{
    t.click();
    e.preventDefault();
}

I doubt there is a full fledged tool which could completely un-minify this code. Especially because variable names are almost always minified. For example a variable name "persons" could be shortened to just "p". A un-minify tool can not know this, of course.

Also take a look at this question: Tool to Unminify / Decompress JavaScript

Community
  • 1
  • 1
Mathyn
  • 2,436
  • 2
  • 21
  • 33
  • really thanks for clarifying these points .i learned javascript essantials then advanced js but still can't take a library and manipulate it to suits my need that's because i can't understand some parts of the libraries code. what do i need to achieve this level please – heavenclick hatim May 13 '15 at 12:21
  • 1
    You don't manipulate libraries but work with their methods. You can uncompress JavaScript code with tools like http://jsbeautifier.org/ The code is from a polyfill, take a look here https://github.com/moxiecode/moxie/blob/be5d0e4f610136882b77bd9c96905cc47cfd554e/src/javascript/runtime/html5/file/FileInput.js#L71 –  May 13 '15 at 12:31
  • Are you trying to use an existing library like jQuery? Or do you want to look at the code of a library to understand how they programmed certain features? – Mathyn May 13 '15 at 12:40
  • no i don't have lot of problems using jquery, i get stuck each time i try to understand a feature on certain libraries, because sometimes what the library offers does not suits my needs so i need to manipulate the core of the library but i feel overwheelmed. what's the roadmap to master it? – heavenclick hatim May 13 '15 at 13:50
  • If you want to edit an existing library how you go about this depends entirely on the library you use. Some libraries are open source meaning you can download the un-minified code which often also contains inline documentation to a certain degree. I would try this first. If the library is not open source you can contact the author of the library and ask him/her for help. If neither work I'm not sure how best to proceed. Trying to edit the minimized code (even if you use a beautifier) will be rather hard and bug prone. – Mathyn May 13 '15 at 14:17