Skip to content

Instantly share code, notes, and snippets.

@mediamichael
mediamichael / RTL Bootstrap flip via JS
Last active March 3, 2020 17:07
RTL and LTR direction change for Bootstrap using JavaScript i18N
// Eldar: https://stackoverflow.com/questions/19730598/right-to-left-support-for-twitter-bootstrap-3
// Edited for custom implementation
var layout = {};
layout.setDirection = function (direction) {
layout.rtl = (direction === 'rtl');
document.getElementsByTagName("html")[0].style.direction = direction;
var styleSheets = document.styleSheets;
var modifyRule = function (rule) {
@mediamichael
mediamichael / .block
Created November 8, 2017 08:21 — forked from mbostock/.block
Force Layout with Mouseover Labels
license: gpl-3.0
@mediamichael
mediamichael / no_drag.css
Last active January 2, 2016 10:29
Disable Dragging and Selecting CSS
.img{
user-drag: none;
-webkit-user-drag: none;
-webkit-touch-callout: none;
-moz-user-select: none;
-khtml-user-select: none;
user-select: none;
}
/* click through it */
.elem {
@mediamichael
mediamichael / iframeAppendCSS
Last active December 24, 2015 07:59
Get iframe by ID and append a CSS style to affect an element inside the iframe.
var iframe1 = document.getElementById('myiframeID');
iframe1.onload = function (){
if(this.contentDocument) iframe1.doc = iframe1.contentDocument;
else if(iframe.contentWindow) iframe1.doc = iframe1.contentWindow.document;
var css = '.myelement{float:right;}',
header = iframe1.doc.getElementsByTagName('head')[0],
style = document.createElement('style');
@mediamichael
mediamichael / isMobile
Created September 17, 2013 22:31
Detect if device is Android, iPhone, iPad, or iPod.
var isMobile;
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf( "android") > -1;
if ( isAndroid || is_uiwebview || is_safari_or_uiwebview ) {
isMobile = true;
//do something
}
@mediamichael
mediamichael / dynamic_object_name
Created September 17, 2013 22:27
Create an object from a dynamic variable name and assign a global class.
var rnd = Math.floor(Math.random()*10000000000);
var myVar = "myString" + "_" + rnd;
window[ myVar + "_optionalID"] = new classname();
@mediamichael
mediamichael / isYouTube
Created September 17, 2013 22:21
Confirm if string is a YouTube URL, strip the youtube ID, and convert the url to a specific format and security.
var youTubeID;
var videoURL = "http://youtube.com/v/youtubeid"
if ( isYoutubeFile( videoURL ) == true ) {
//do something
}
function isYoutubeFile(vidURL) {
//console.log( "javascript: isYoutubeFile: vidURL: " +vidURL );
var videoURL;
@mediamichael
mediamichael / script_loader
Created September 17, 2013 19:16
Script and CSS style loader to manage the load order and detect when complete.
var numLoaded=0;
var minimumToLoad=1;
function loadScript( file, type, title ) {
//console.log( "javascript: " + "loadScript: " + file );
if ( type == 'js' ){
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = file;
if (script.readyState){
@mediamichael
mediamichael / console.log
Created September 17, 2013 18:53
IE console.log fallback support
var alertFallback = true;
if ( typeof console === "undefined" || typeof console.log === "undefined" ) {
console = {};
if (alertFallback) {
console.log = function(msg) {
alert(msg);
};
} else {
console.log = function() {};
}
@mediamichael
mediamichael / ie_browser_detect
Created September 17, 2013 19:04
IE browser detect, including ie version, and ie document mode.
var ua = navigator.userAgent;
var isIE = ua.indexOf("MSIE") != -1;
var ieVersion;
var mode = document.documentMode ||
((/back/i).test(document.compatMode || "") ? 5 : ieVersion) ||
((/MSIE\s*(\d+\.?\d*)/i).test(navigator.userAgent || "") ? parseFloat(RegExp.$1, 10) : null);
function getIEVersion(dataString) {
var index = dataString.indexOf("MSIE");
if (index == -1) return;
return parseFloat(dataString.substring(index+5));