I have always successfully sorted my arrays like this (when I did not want the standard lexicographic ordering): Now, someone told me this was wrong, and that I would need to return a-b instead. Is that true, and if yes why? I have tested my comparison function, and it works! Also, why would my solution be so…
Tag: javascript
Mobile Safari sometimes does not trigger the click event
This is a dynamic JavaScript application I am working on. I have many <a> anchor elements that have a class. When that class is clicked, something should happen. This works fine in Firefox, Chrome, IE, but in some cases the click event is not triggered on mobile Safari (iPad and iPhone). These elements …
JavaScript How to Dynamically Move Div by Clicking and Dragging
Okay it would seem like it should be simple. I need to take an already existing div and move it according to mouse position within the window. I have searched everywhere and it has led me to over-complicated ways of doing the same thing and involves the use of j-query. I need to strictly use javascript for wh…
Check url content type with javascript
In order to conserve server resources I’m looking for a way to retrieve the content type of a given url using javascript. It should not download the complete content from the url only the headers. Is this possible with the restrictions javascript has. Answer Make an Ajax call with a head request.
Multi Level Inheritance in Javascript
I am trying to mock inheritance in Javascript using prototype. I have a function named Model and a type of model => Item. How can I access names array from init() function above? Answer Inheritance in Javascript is tricky! Read this post for a great explanation of traditional object oriented inheritance in…
Lazy Loading HTML5 picture element
I have been searching (unsuccessfully) for a reliable method to lazy load images while using the HTML5 spec for <picture>. Most solutions/plugins out there currently rely on using data- attributes. I could be wrong, but it doesn’t seem this method will work in conjunction w/ <picture>. IR…
jquery – css “transform:scale” affects ‘.offset()’ of jquery
I’m Trying To do Validation in jQuery. It’ll produce error after blur event occurs by checking whether the given input is empty. Based on that, it’ll create a <div class=”errdiv”> next to that input which will have the specific error. I use .offset to get the position of th…
How to programmatically invoke the native datepicker on a mobile device
I want to programmatically kick off the native datepicker on my web page (that is run on iOS and Android). I know that I can use <input type=”date” but that would require user input. How do I kick it off programmatically? Answer You don’t. You can’t tell (/force) the phone to show t…
What is the AutobahnJS realm for?
Just wondering what the mysterious realm field in AutobahnJS is. From the docs, creating a connection is as follows: I don’t set a realm server-side so what is this realm parameter for? Furthermore, it is a required field which must mean it is necessary for the connection to work. Can someone enlighten …
Use HTML5 to resize an image before upload
I have found a few different posts and even questions on stackoverflow answering this question. I am basically implementing this same thing as this post. So here is my issue. When I upload the photo, I also need to submit the rest of the form. Here is my html: Previously, I did not need to resize the image, s…