Tuesday 10 July 2012

attachment opening as zip IE

IE opens the xls,doc and ppt files as a zip file. After extracted also, no files will be there. To avoid this add the below lines in Apache conf. If needed add for other file extensions also.

AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx

Monday 9 July 2012

Apache redirect,alias and SSL

1. Redirect /files http://localhost/info.php
if you put the above in the htaccess and hit http://localhost/files. It will be redirected to http://localhost/info.php.

2. Error log in htaccess
php_value log_errors On
php_value error_log php_error_log.txt
The above two lines enable the log and write it to php_error_log.txt

3. Alias example: lets say you have the some files in downloads dir of c drive. But when you hit http://localhost/files, it has to fetch from c:/downloads. The below config achieves that
Alias /files "C:/downloads/"
<Directory "C:/downloads">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

4. If you want to force a particular url to be secure, try below config
<Directory "C:/Program Files/Apache Group/Apache2/htdocs">
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "www.drupalssl.com"
ErrorDocument 403 https://www.drupalssl.com
</Directory>

Note: After making changes restart apache and clear the browse cache. The redirect directive takes precedence over alias directive.
Reference:
http://www.apache-ssl.org/docs.html#SSLRequireSSL
http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html
http://httpd.apache.org/docs/2.0/mod/mod_alias.html
http://www.thewebhostinghero.com/tutorials/apache-alias.html

Force files not to open in browser Apache

Sometimes you may not want to allow the user the to open the file in the browser and provide them option to open or save.Following links will be helpful.
http://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/
       AddType application/octet-stream .pdf
http://www.stuvel.eu/pdfdownload
       SetEnvIf Request_URI "\.pdf$" requested_pdf=pdf
       Header add Content-Disposition "attachment" env=requested_pdf
http://www.thingy-ma-jig.co.uk/comment/5305
      <FilesMatch "\.(?i:pdf)$">
            ForceType application/octet-stream
            Header set Content-Disposition attachment

      </FilesMatch>


Don't forget to enable the mod_header module in apache. If not enabled, will get 500 internal server error.
The first method works only in certain browsers. After doing the changes, always restart the apache and clear the browser cache.

Jquery Autocomplete

Jquery Doc:
http://jqueryui.com/demos/autocomplete/
http://docs.jquery.com/UI/Autocomplete

To perform some action when the item is selected using select event.
http://stackoverflow.com/questions/7733315/jquery-autocomplete-event-select

Normally, autocomplete searches the char or text entered in the entire string. If you want to change this behaviour and match with only the beginning of the string, refer below
http://jsbin.com/avoyu5/edit#javascript,html
http://www.jensbits.com/2011/04/28/jquery-ui-autocomplete-search-from-beginning-of-string/
http://stackoverflow.com/questions/2382497/jquery-autocomplete-plug-in-search-configuration
if you have any issues in using tag, use tag.label or tag.value
http://forum.jquery.com/topic/select-only-items-that-start-with-jquery-ui-autocomplete

Custom Formatting
http://stackoverflow.com/questions/2435964/jqueryui-how-can-i-custom-format-the-autocomplete-plug-in-results

Clear form field after select
http://stackoverflow.com/questions/2561903/clear-form-field-after-select-for-jquery-ui-autocomplete

Thursday 5 July 2012

click event not working for anchor tags added dynamically

Lets say you are inserting new elements to the DOM and trying to add the onclick event to it, it wont work with just .click function. For that below is the solution.
$('#add').live('click', function(e) {
e.preventDefault();
alert('hello');
});
Reference:http://stackoverflow.com/questions/2264246/jquery-click-event-of-a-tag-added-at-run-time-doesnt-get-fired

Form not submitting on pressing enter

Some browsers have this problem, just add the below piece of code
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
  //call submit function and do whatever you want to
}
Reference:http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed