Skip to content

Instantly share code, notes, and snippets.

// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@emayk
emayk / gist:2027378
Created March 13, 2012 07:10
JS : Snippet Query Focus on input text
$(document).ready(function() {
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
@emayk
emayk / gist:2146220
Created March 21, 2012 11:06
snippet: Jquery Dropdown_menu
function dropdown_menu() {
$("#sub-menu-id a, .subnav a");
$(" #sub-menu-id ").css({
display: "none",
opacity: "1"
}); // fix for opera browser
$("#sub-menu-id li").each(function() {
var $subNav = jQuery(this).find('ul:first');
$(this).hover(function() {
$subNav.stop().css({
@emayk
emayk / gist:2146225
Created March 21, 2012 11:06
snippet : Javascript dropdown menu
function dropdown_menu() {
$("#sub-menu-id a, .subnav a");
$(" #sub-menu-id ").css({
display: "none",
opacity: "1"
}); // fix for opera browser
$("#sub-menu-id li").each(function() {
var $subNav = jQuery(this).find('ul:first');
$(this).hover(function() {
$subNav.stop().css({
@emayk
emayk / gist:2146238
Created March 21, 2012 11:09
jQuery Toggle Multiple Elements
<!-- jQuery Code -->
$(document).ready(function() {
$('#commentbox').hide();
$('a.comment').click(function() {
var id = $(this).attr('id');
$('#commentbox' + id).toggle(500);
// alert(id);
return false;
});
@emayk
emayk / gist:2146254
Created March 21, 2012 11:11
reply:js
reply
@emayk
emayk / gist:2146259
Created March 21, 2012 11:11
jquery : div replace link
$(document).ready(function() {
$('div.chapter a[@href*=wikipedia]').each(function(index) {
var $thisLink = $(this);
$thisLink.attr({
'rel': 'external',
'id': 'wikilink-' + index,
'title': 'learn more about ' + $thisLink.text() + ' at Wikipedia'
}); });
});
@emayk
emayk / gist:2202705
Created March 26, 2012 03:40
php: header on event logout
<?php
header(‘Expires: Mon, 1 Jul 1998 01:00:00 GMT’);
header(‘Cache-Control: no-store, no-cache, must-revalidate’);
header(‘Cache-Control: post-check=0, pre-check=0′, FALSE);
header(‘Pragma: no-cache’);
header( “Last-Modified: ” . gmdate( “D, j M Y H:i:s” ) . ” GMT” );
?>
@emayk
emayk / gist:2203351
Created March 26, 2012 06:08
php : sql2xml
<?php
/**
* @param mysql_resource - $queryResult - mysql query result
* @param string - $rootElementName - root element name
* @param string - $childElementName - child element name
*/
function sqlToXml($queryResult, $rootElementName, $childElementName)
{
$xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
$xmlData .= "<" . $rootElementName . ">";
@emayk
emayk / gist:2212972
Created March 27, 2012 05:52
js : try load jquery
<script>
if(typeof jQuery=='undefined') {
function getScript(url,success) {
var script=document.createElement('script');
script.src=url;
var head=document.getElementsByTagName('head')[0],done=false;script.onload=script.onreadystatechange=function() {
if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){done=true;success();
script.onload=script.onreadystatechange=null;head.removeChild(script)}};head.appendChild(script)};getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js',function() {
if(typeof jQuery=='undefined'){}else{fancyCode()}})}else{fancyCode()}
function fancyCode(){ var code = '&lt;!DOCTYPE html>\n&lt;html>\n' + $("html").html().replace(/[<>]/g, function(m){return{'<':'&lt;','>':'&gt;'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>');