This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertAtCursor(myField, myValue) { | |
if(document.selection){ | |
myField.focus(); | |
sel = document.selection.createRange(); | |
sel.text = myValue; | |
} else if(myField.selectionStart || myField.selectionStart == '0') { | |
var startPos = myField.selectionStart; | |
var endPos = myField.selectionEnd; | |
myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitOnce( str, sep ){ | |
var components = str.split( sep ), | |
result = []; | |
result[0] = components.shift(); | |
result[1] = components.join( sep ); | |
return result; | |
} | |
// Example | |
var string = 'key=value&key2=value2&key3=value3'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function truncateString( string, num, useWordBoundary ){ | |
var isLong = string.length > num, | |
newString = string.replace( /(^\s)|(\s$)/gi, '' ), | |
isOneWord = newString.match(/\s/gi) === null; | |
newString = isLong ? newString.substr(0,num-1) : newString; | |
newString = ( useWordBoundary && isLong && !isOneWord ) ? newString.substr(0,newString.lastIndexOf(' ')) : newString; | |
return isLong ? newString +' ...' : newString; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myString = '<span title="title">test</span>'; | |
myString.replace(/<(?:.|\n)*?>/gm, ''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'asd123'.match(/\d+$/) // 123 | |
'asd123asd'.match(/\d+/) // 123 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addslashes(str) { | |
str=str.replace(/\\/g,'\\\\'); | |
//str=str.replace(/\'/g,'\\\''); | |
str=str.replace(/\"/g,'\\"'); | |
str=str.replace(/\0/g,'\\0'); | |
return str; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stripslashes( str ) { | |
return (str + '').replace(/\\(.?)/g, function (s, n1){ | |
switch (n1) { | |
case '\\': | |
return '\\'; | |
case '0': | |
return '\u0000'; | |
case '': | |
return ''; | |
default: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toUnicode(theString) { | |
var unicodeString = ''; | |
for (var i=0; i < theString.length; i++) { | |
var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase(); | |
while (theUnicode.length < 4) { | |
theUnicode = '0' + theUnicode; | |
} | |
theUnicode = '\\u' + theUnicode; | |
unicodeString += theUnicode; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regexS = "[\\?&]" + name + "=([^&#]*)"; | |
var regex = new RegExp(regexS); | |
var results = regex.exec(window.location.href); | |
if(results == null) | |
return ""; | |
else | |
return decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var supports = (function() { | |
var div = document.createElement('div'), | |
vendors = 'Khtml Ms O Moz Webkit'.split(' '), | |
len = vendors.length; | |
return function(prop) { | |
if ( prop in div.style ) return true; | |
prop = prop.replace(/^[a-z]/, function(val) { | |
return val.toUpperCase(); |