Changing qTip2 width

It took me a while to find this out. If you need to change the default max width of qTip2, here is how. First set up a new style class. .my_width_setting_class { max-width: 1200px; min-width: 0px; } Then in the qtip style attribute, insert our newly created css class. style: { classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow my_width_setting_class' } That will then override the default settings in jquery.qtip.css. ref: http://craigsworks.com/projects/qtip2/tutorials/styling/#dimensions ...

May 22, 2012 · 1 min · birdchan

Adding shadow to wp-codebox

Too bad wp-codebox contains two divs namely wp_codebox_msgheader and wp_codebox, we cannot simply give the box-shadow to one single div. After playing with this a bit, here is my parameters. The css file is located at /your-wp-root/wp-content/plugins/wp-codebox/css/codebox.css. .wp_codebox_msgheader { box-shadow: 6px 14px 11px #808083; } .wp_codebox { box-shadow: 7px 10px 10px #888; } The overlapped area seems smooth with this setting. I also added bottom margin to the codebox, see if you like it. ...

May 19, 2012 · 1 min · birdchan

Check the existence of an element in jquery

When dealing with dynamic creation of DOM objects, sometimes you need to check if a certain element exists. Below is how you check: if ($('#my_element').length > 0){ // it exists! } If you need to check whether a dropdown has any options, here is how if ($('#my_dropdown option').length > 0){ // contains options }

May 16, 2012 · 1 min · birdchan

MySQL converting Text to Varchar

One incentive of converting a text column to a varchar column is that, you can index that column for quicker query. Before converting, you want to make sure you won’t be truncating anything. Run the following to make sure SELECT MAX( LENGTH( target_column ) ) FROM target_table As long as the returned length is less than your varchar length, you are good to go.

April 14, 2012 · 1 min · birdchan

PHPExcel: the right way to open files

Just let PHPExcel figure out the file type by using PHPExcel_IOFactory::identify() $filename = 'your_file.xls'; require_once 'PHPExcel/Classes/PHPExcel.php'; // Create new PHPExcel object $filetype = PHPExcel_IOFactory::identify($filename); $objReader = PHPExcel_IOFactory::createReader($filetype); $objReader->setReadDataOnly(true); // set this if you don't need to write $objPHPExcel = $objReader->load($filename); // go through each sheet foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { ... }

March 27, 2012 · 1 min · birdchan

Packing form elements using json

Sometimes I don’t really want to pass form elements one by one in my ajax call, I just want to pack them all in one giant obj and send it over to the backend script. After looking for a while, I found the solution. See sample code below. json_str = JSON.stringify($('#my_form').serializeArray()); $.ajax({ url: 'do_something.php', type: 'POST', dataType: 'json', data: { form_data: json_str }, success: function(data) { // do something with data }, error: function(request, error) { alert('error: '+error+'nreadyState: '+request.readyState+'nstatus: '+request.status); alert('responseText: '+request.responseText); } }); Yea, serializeArray() will convert a form object to a javascript array. Notice this method can only apply to form objects. Then the stringify method will convert the array to a json string. ...

March 23, 2012 · 1 min · birdchan

PHPExcel

PHPExcel is a PHP library to handle both read/write from/to an excel file. Below is a short tutorial to cover reading data from an excel file. $filename = 'your_file.xls'; require_once 'PHPExcel/Classes/PHPExcel.php'; // Create new PHPExcel object $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($filename); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $sheet_name = $worksheet->getTitle(); foreach ($worksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if empty foreach ($cellIterator as $cell) { if (!is_null($cell)) { $cell_coord = $cell->getCoordinate(); $cell_val = $cell->getCalculatedValue(); if (preg_match('/^([a-zA-Z]+)([0-9]+)$/', $cell_coord, $matches)){ $col = $matches[1]; $row = (int) $matches[2]; do_something_with_this_cell($sheet_name, $col, $row, $cell_val); } } } } } For do_something_with_this_cell($sheet_name, $col, $row, $cell_val), you can either store the value into DB for later analysis, or look up a mapping array and determine what that cell carries. ...

March 23, 2012 · 2 min · birdchan

Use PHP to remove non ascii characters

Yea, sometimes it’s acceptable and you will need to do this. $s = "Don't you love this ☂?"; $s = preg_replace('/[^(x20-x7F)]*/','', $s); The string becomes Don't you love this ? Thanks Ryan for figuring this out!

March 1, 2012 · 1 min · birdchan

jeditable textile having no OK nor cancel button

Say in implementation the jeditable textile you don’t want any OK nor Cancel buttons, kinda like making your textarea an Excel cell, how to do that? The key is to use onblur, then comment out submit and cancel. Now when you press ESC, it’s a cancel. Clicking somewhere else is an OK, or submit. $('.editable_textile').editable('save.php', { indicator : '', loadurl : 'load.php', type : 'textarea', onblur : 'submit', //submit : 'OK', //cancel : 'Cancel', callback: function(value, settings) { var retval = value.replace(/\n/gi, " \n"); $(this).html(retval); }, }); See more examples at http://unrealideas.net/examples/05_onblur.php ...

February 29, 2012 · 1 min · birdchan

Mysteriously off-by-1 pixel even using width=100% ???

This took me a while to debug, one div and one fieldset both are set to 100%, but in close examination they are off by a few pixels. Below is a stripped down example. This is the menu bar, with some buttons Some text So, I was like, perhaps some of these jquery-ui classes gave margin values, so I manually set the margins to all zeros. I also then set all the border sizes to zeroes. ...

February 28, 2012 · 1 min · birdchan