// Date.now()
if (!Date.now) {
Date.now = function() { return new Date().getTime(); }
};
// console.log()
if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };
console.log( "Setting up console log..." );
// string.trim()
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
// string.ltrim()
if(typeof String.prototype.ltrim !== 'function') {
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
}
// string.rtrim()
if(typeof String.prototype.rtrim !== 'function') {
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
}
== Query Touch Device ==
File ''sample.php'':
...
....
Some Touch Control...
...
File ''utils.js'':
//------------------------------------------------------------------------
// Test whether client device supports touch.
//
// Hide the element with ID as ‘touch-only’ if the web page is viewed
// on a device that doesn’t have a touch screen. This should work on
// all desktop and mobile devices including iOS, Android, Opera,
// Chrome, IE, Safari and Windows Phone.
//
// if (!is_touch_device()) {
// document.getElementById('touch-only').style.display='none';
// }
//
// Credits: http://ctrlq.org/code/19616-detect-touch-screen-javascript
//-----------------------------------------------------------------------
function isTouchDevice()
{
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0)
);
}
== Audio Support ==
Preload audio clips and play them. Add the following to a webpage:
...
...
Bootstraps buttons to play audio clips
Play audio clip using browser's built-in player:
Audio
A preloaded audio clip, ready to play
An autoplay clip
Source:
* [[http://html5doctor.com/native-audio-in-the-browser|HTML5 Doctor: Native Audio in the Browser]]
* [[http://html5doctor.com/html5-audio-the-state-of-play|HTML5 Doctor: Audio, the State of Play]]
* [[http://happyworm.com/jquery/jplayer|JPlayer (Open Source)]]