Using a query parameter can often be more convenient than having to change a hardcoded value while testing a script. This allows you to pass a variable into the script without having to edit and re-save your script.
var query = window.location.search.substring(1);
var keyVal = query.split("=");
var value = keyVal[1];
if (!value) { value = 100;
} // in case no query parameter is passed in, use a default
Snippets of code and tricks that would otherwise be forgotten. Useful for me, hopefully for you too.
Thursday, January 24, 2013
Wednesday, January 9, 2013
Assigning CSS float values in javascript
I have to give credit for this information to an anonymous poster on stack overflow: http://stackoverflow.com/questions/606470/is-there-a-cross-browser-way-of-setting-style-float-in-javascript
While creating and adding styles to some DOM elements with javascript, I noticed that my IDE was unhappy with me using this syntax:
domElement.style.float = "right";
The trouble is that 'float' is a reserved keyword in javascript, and the above syntax will cause unexpected results which vary across browsers. I learned that I should be using: domElement.style.styleFloat = "right"; but this was still not working Firefox.
The cross browser solution ( Chrome, IE, Firefox ) :
domElement.style.styleFloat = "right";
domElement.style.cssFloat = "right";
Now everyone is happy.
While creating and adding styles to some DOM elements with javascript, I noticed that my IDE was unhappy with me using this syntax:
domElement.style.float = "right";
The trouble is that 'float' is a reserved keyword in javascript, and the above syntax will cause unexpected results which vary across browsers. I learned that I should be using: domElement.style.styleFloat = "right"; but this was still not working Firefox.
The cross browser solution ( Chrome, IE, Firefox ) :
domElement.style.styleFloat = "right";
domElement.style.cssFloat = "right";
Now everyone is happy.
Tuesday, December 18, 2012
Pattern Resource
A great collection of subtle patterns for web development and graphic design:
http://subtlepatterns.com/
http://subtlepatterns.com/
Wednesday, December 12, 2012
Cross Browser Opacity Classes
These come in handy pretty often:
.no_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; /* IE 8 */
filter: alpha(opacity=0); /* IE 5-7 */
-moz-opacity: 0.0; /* Netscape */
-khtml-opacity: 0.0; /* Safari 1.x */
opacity: 0.0; /* Good browsers */
}
.half_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Netscape */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */
}
.full_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; /* IE 8 */
filter: alpha(opacity=100); /* IE 5-7 */
-moz-opacity: 1.0; /* Netscape */
-khtml-opacity: 1.0; /* Safari 1.x */
opacity: 1.0; /* Good browsers */
}
.no_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; /* IE 8 */
filter: alpha(opacity=0); /* IE 5-7 */
-moz-opacity: 0.0; /* Netscape */
-khtml-opacity: 0.0; /* Safari 1.x */
opacity: 0.0; /* Good browsers */
}
.half_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Netscape */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */
}
.full_opacity {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; /* IE 8 */
filter: alpha(opacity=100); /* IE 5-7 */
-moz-opacity: 1.0; /* Netscape */
-khtml-opacity: 1.0; /* Safari 1.x */
opacity: 1.0; /* Good browsers */
}
Thursday, December 6, 2012
Installing Drupal Commons
Install xampp, or anything with Apache and MySQL
Create a database with any name for your Drupal Commons installation.
Get your download here:
https://network.acquia.com/downloads/drupal-commons
Extract these files, and move the resulting Drupal file directory structure into the web root, or any sub folder.
Configure a settings.php file from the example ( default.settings.php ) file provided.
Edit this line with your database information:
$db_url = 'mysql://username:password@localhost/databasename';
The simplest example ( only fun for a development site ) is:
$db_url = 'mysql://root@localhost/database_name';
Save settings.php
*** You will probably need to edit php.ini here to allow a maximum_execution longer than 30 seconds, this is a common fail. Try 300. Remember to restart Apache for the php.ini settings to take effect.
Use a web browser to execute the install.php file in the folder containing the installation.
Create a database with any name for your Drupal Commons installation.
Get your download here:
https://network.acquia.com/downloads/drupal-commons
Extract these files, and move the resulting Drupal file directory structure into the web root, or any sub folder.
Configure a settings.php file from the example ( default.settings.php ) file provided.
Edit this line with your database information:
$db_url = 'mysql://username:password@localhost/databasename';
The simplest example ( only fun for a development site ) is:
$db_url = 'mysql://root@localhost/database_name';
Save settings.php
*** You will probably need to edit php.ini here to allow a maximum_execution longer than 30 seconds, this is a common fail. Try 300. Remember to restart Apache for the php.ini settings to take effect.
Use a web browser to execute the install.php file in the folder containing the installation.
Wednesday, November 28, 2012
Detecting character encoding in PHP
Dealing with character encoding is never fun. It's easy to know that something has gone wrong when text is displaying as hieroglyphics, but it can be difficult to figure out why.
I found myself in this position trying to fix some Japanese text the other day and wanted to write a short example of mb_detect_encoding(); before I forget it.
<?php
// a list of possible encodings
$encodings = array('UTF-8','windows-1251','ISO-8859-1','ASCII','JIS','EUC-JP');
$string = "Example text"; // the text you wish to test
$in_encoding = mb_detect_encoding($string, $encodings, true);
echo "Encoding type: ".$in_encoding;
?>
If you find that your encoding is something other than what you desire, you should check out iconv();
I found myself in this position trying to fix some Japanese text the other day and wanted to write a short example of mb_detect_encoding(); before I forget it.
<?php
// a list of possible encodings
$encodings = array('UTF-8','windows-1251','ISO-8859-1','ASCII','JIS','EUC-JP');
$string = "Example text"; // the text you wish to test
$in_encoding = mb_detect_encoding($string, $encodings, true);
echo "Encoding type: ".$in_encoding;
?>
If you find that your encoding is something other than what you desire, you should check out iconv();
Thursday, November 8, 2012
Speed up your local Drupal development environment
A friend came across an interesting suggestion for speeding up the database interactions on my local development environment on this page:
http://drupal.org/node/469086
Basically it's just some changes to mysql's my.ini configuration file:
innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED
Then restart mysql.
The improvement will probably vary.
http://drupal.org/node/469086
Basically it's just some changes to mysql's my.ini configuration file:
innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED
Then restart mysql.
The improvement will probably vary.
Subscribe to:
Posts (Atom)