~ overflow ~

Tag: jQuery

Bad Coders United

by z3n on Jan.31, 2010, under lol

Problem:

So I have this joint work where I do the frontend and another company does the backend and CRM integration of the system, I basically wrote a frontend and examples of all XMLs that backend should send to the system in order to have it working. After a week things were ready and i sent it to the backend team, and look how good they manipulate arrays:

$listai = str_replace(‘Ar’,” , $listai);
$listai = str_replace(‘Array’,” , $listai);
$listai = str_replace(‘ray’,” , $listai);

another example…

function datadma($dataz){
$dia = substr($dataz, -2);
$mess = substr($dataz, -5,2);
$ano = substr($dataz, -10,4);
return $dataz= $dia.”/”.$mess.”/”.$ano;
}

Oh man, wait, they DON’T KNOW what is an array!

How is that possible? Array is one of the first things a decent programmer is supposed to learn.

And the best, how is it possible for a company to build up a CRM system without the use of a single array? That’s like a coding challenge, specially when manipulating multiple fields and so on. And that’s not the only issue, after stating, in front of the client, that they weren’t able to work with jQuery + Ajax using XML (which they previously stated that could be worked without problems) they asked me to teach them … for free!!!!

ahahahah

Solution:

just sharing the story, there’s no solution for this :)

Leave a Comment :, , more...

Reset jwysiwyg

by z3n on Jan.15, 2010, under Coding, Games and Gaming

Problem:

jquery’s extension jwysiwyg can’t be reseted on fly, calling the function again will just append another editor.

Solution:

You will need to do a workaround by adding the jwysiwyg object inside a container then resetting it using this little function:

  1. function _reset_jwysiwyg(h,x,j){ // html, first id, second id
  2.    h=str_replace("\\","",h); // this requires php.js to work, can be removed if you don't add slashes on your vars
  3.    $("#cf"+x+""+j).html("<textarea id='#f"+x+""+j+"' class='jwysiwyg' name='jwysiwyg' cols=94 rows=30>"+h+"</textarea>");
  4.    $(".jwysiwyg").wysiwyg({
  5.        html: h
  6.       // you may want to add other control options here
  7.   });
  8. }

this will work for this setup:
<span id=’c12′><textarea id=’f12′ class=’jwysiwyg’ name=’jwysiwyg’ cols=94 rows=30></textarea></span>

on this example it will be called as:

_reset_jwysiwyg(“”,1,2);

Note

this function is a snippet from my code, you might not want the identifiers just the div name, that makes it less complicated.

Leave a Comment :, , , , , more...

jQuery + XML + IE = xmlDOM issue … or no??

by z3n on Aug.29, 2009, under Coding, Notes

Problem:

In the middle of the developing of a very complex script i figured out that IE was simply ignoring the xml documents i sent to it by ajax. Searching the web i’ve found this $.xmlDOM jQuery extension that is supposed to fix the IE issue with xmls. Although the extesion was clear and other people claims it work, it didn’t worked for me, how lucky is that?

Solution:

This took a while to solve, and i will skip all the boring process. Turns out that i didn’t needed the $.xmlDOM extension at all, the issue was on the xml. I’m developing this script in a language that has accents, i need to use `&aacute;` like html entities in order to avoid malfuncioning with data transport, so this little ampersand was breaking IE.

How nice is that?

Leave a Comment :, , , , more...

jQuery hoverpulse different image ratio fix

by z3n on Aug.18, 2009, under Coding

The jQuery’s extension hoverpulse created allows you to have images that resize themselfs on a mouse hover, very usefull when you need to have larger thumbs without showing the full image like other extensions does.

However hoverpulse has a issue when it comes to resize non square images, it simply stretches them, so I wrote this little custom version of hoverpulse in order to have this gap filled:

Links:

Modified Source

jQuery

HoverPulse Plugin

2 Comments :, , , more...

little jQuery to loop through checkboxes

by z3n on Aug.18, 2009, under Coding

This is a little function to loop throught a specific form or id with checkboxes, it will check if the checkbox is checked and then you can `do something`.

  1. function (what)
  2. {
  3. jQuery.each(jQuery("#"+what+" :checkbox"),function(){    
  4.  if (jQuery(this).is(':checked')) {
  5.                         // do something
  6.  }
  7. });
  8. }
1 Comment :, , , more...

Keep it simple, stupid jQuery experience

by z3n on Aug.14, 2009, under Coding, Notes

As much as I like jQuery I must admit that it’s far away from simplifying things. Although it might be a great idea using it on 100% jQuery scripts, it’s a real bad idea using it to refurbish an old script.

Today I’ve spent over 2 hours implement jQuery on a old script I have, and I felt into so many issues that it didn’t worth at all.

My script was simple, I had a huge variable list that could be edited by a form, script loops through the variables building a form with input fields for each variable. I will not get into specific details because it’s boring, but I needed to allow the user to add a new variable inside an array, so i thought that jQuery would help a lot since i only would need to dynamic add a new input field as needed then post everything back to script to save the file.

First I spent an hour figuring out that jQuery was ruining the text by converting the whole thing into UTF-8, loosing all the accents, eventually I found out about contentType encoding ajax variable:

contentType:"application/json; charset=utf-8"
which could be changed to the charset i wanted.

It was useless, jQuery still posting into the wrong charset, there’s some other tweks on this, but they are also useless.

I was able to fix the accent issue with this php statement:

mb_convert_encoding(urldecode($variable),”ISO-8859-1″,”auto”);

This is much more obscure though, but I was familiar with it since i coded in japanese charsets which are a pain to convert.

After having this cleared, and searching a lot of useless blogs and postings, turns out that jQuery was using the hard coded form names to post the data, which could be overlapped by an dynamic added field, I did a script to change the name of the hard coded inputs, something like this:

$(“#field_id”).attr(’name’,’new_name’);

Theorically, it worked, but when I did:

$(“#form”).serialize();

jQuery used the dynamic fields with the ordinary hard coded ignoring the attr changes.

Now I had to add a handler to dynamic convert and read all the inputs and do my own serialize in order to TRY to make it work…and that’s because i didn’t tested it on IE yet.

So that’s when I quit using jQuery for this script and do something plain and simple, which took me about 20 minutes and 0 searches.

It looks like that if I had used DOM elements for the whole form, all elements generated by jQuery itself, not hard coded, i would have less trouble with the form, although, the charset issues still.

Super Fun Sources:

Stack overflow posting

Stack overflow posting 2

jQuery Ajax Documentation (completly useless since contentType explanation has 2 lines)

Leave a Comment :, , , , , more...

Simple AJAX/xmlhttp query issue

by z3n on May.20, 2009, under Coding, Tips & Hints

Problem:

You like jQuery, however, doing simple tasks get impossible since jQuery is too massive, even packed it’s over 50kb. The alternate, script.taculo.us, is even bigger!

Solution:

Doing a simple ajax or xmlhttp request, is nothing out of this world, actually, it’s pretty easy, you just need to watch it if you do more than one on the same page, or when a error happen you might want to have a handler.

Based on quirks mode example i wrote this little function, it’s able to do a rudimentar queue and return plain text from a remote server, it’s also compatible with IE.

var x=null;var p=0; // p is the processing control, while the request is running it will be true, if another request shows up it will fall into a timer loop until the first one ends
  1. _lD=function(url){
  2.    if(p==1){
  3.     setTimeout("_lD('"+url+"')",250);
  4.    }else{
  5.       p=1;
  6.       x=null;
  7.       if(window.XMLHttpRequest){
  8.          x=new XMLHttpRequest();
  9.       }else if(window.ActiveXObject){
  10.          x=new ActiveXObject("Microsoft.XMLHTTP");
  11.       }
  12.       if(x!=null){
  13.          x.onreadystatechange=function(){
  14.          var r="";
  15.          if(x.readyState==4){
  16.              if(x.status==200){
  17.                   r=x.responseText;
  18.  
  19.                   // manipulate your result here
  20.  
  21.                   p=0;
  22.                }
  23.             }
  24.          }
  25.          x.open("GET",url,true);
  26.          x.send(null);
  27.       }
  28.    }
  29. }

Packed, this function is less than 500 bytes, much better than the 58kb of jQuery, heheh

Leave a Comment :, , , , , , more...

Google Maps API blank screen when loaded dinamically

by z3n on Feb.19, 2009, under Coding

Problem:

this:

$.getScript(“http://maps.google.com/maps?file=googleapi&v=2&key=<?=_gkey?>”,function(){something});

will execute the callback and then go to a blank a screen.

Solution:

Apparently, googlemaps api has it’s own onLoad feature which screws up with dynamic js loading, so what you have to do is add the callback on the query:

function gmaps_dloader(){$.getScript(“http://maps.google.com/maps?file=googleapi&v=2&key=<?=_gkey?>&callback=happy_function“);}

function happy_function(){alert(“HOY!!!”);}

if you need callbacks so much you may also add the jQuery’s, both will be executed.

2 Comments :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!