Edit

Login redirect

<?php

function HOOK_user_login_submit( $form, &$form_state ){
    $form_state["redirect"] = "";
}

function HOOK_form_user_login_alter( &$form, $form_state ){
    $form["#submit"][] = "HOOK_user_login_submit";
}

?>

Make Drupal Module Most Important

So other modules don't supersede your module, run this code once.
<?php
db_query("UPDATE {system} SET weight = 100 WHERE name = 'MODULE_NAME'");
?>

Image Desaturation Effect

.box img{
 filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'>
  <filter id=\'grayscale\'>
   <feColorMatrix type=\'saturate\' values=\'0.5\'/>
  </filter>
 </svg>#grayscale");
 filter: gray alpha(opacity=50);
 -webkit-filter: grayscale(50%);
 -webkit-transform: translateZ(0);
}
.box img:hover{
 filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'>
  <filter id=\'grayscale\'>
   <feColorMatrix type=\'saturate\' values=\'1\'/>
  </filter>
 </svg>#grayscale");
 -webkit-fil

Slideshow

HTML

<div id="photos_rotator">
 <ul>
  <li>
   <a href="/node/15">
    <span class="title">003</span>
   </a>
   <div class="rotator_full"><img src="003_0.jpg" alt=""/></div>
  </li>
  <li>
   <a href="/node/14">
    <span class="title">002</span>
   </a>
   <div class="rotator_full"><img src="002_0.jpg" alt=""/></div>
  </li>
  <li>
   <a href="/node/13">
    <span class="title">001</span>
   </a>
   <div class="rotator_f

Webcam Image Refresher

HTML

<img src="http://orgnsm.org/camoff.jpg" alt="Webcam" id="webcamImage"/></div>

JavaScript

function refreshCam(id, file) {
	var today = new Date();
	var h = today.getHours();
	var m = today.getMinutes();
	var s = today.getSeconds();
	document.getElementById(id).src = file + "?time="+h+m+s;
	setTimeout('refreshCam("webcamImage","'+file+'")',10000);
}

window.onload = function(){

    if( document.getElementById("webcamImage") )
        refreshCam( "webcamImage","http://orgnsm.org/webcam.jpg" );

}

AJAX Remote Read, Local Write

w/JavaScript

//the callback function run after loading JSONp below
function test_results_loaded(data){

 //post data to a service via ajax
 var xhr = new XMLHttpRequest();
 xhr.open("POST", "https://orgnsm@orgnsm.org:lkAGWUE01H@orgnsm.testrail.com//index.php?/api/v2/add_result/1", true);
 xhr.setRequestHeader('Content-Type', 'application/json;');
 xhr.setRequestHeader('Accept', 'application/json;');

 // send the collected data as JSON
 xhr.send(JSON.stringify({"status_id":"1"}));

 xhr.onloadend = function () { alert("Wrote test data"); };

}



window.onload = function()

DOM Inject and Add Event

w/JavaScript

window.onload = function(){

 //create new button
 var btn = document.createElement("a");
 btn.setAttribute("id", "addedbutton");
 var btntxt = document.createTextNode("Run Me");
 btn.appendChild(btntxt);

 //inject new button
 document.getElementById("sidebar").appendChild(btn);

 //add event to new button
 document.getElementById('addedbutton').onclick = function(){
  alert("Success");
 }

}

w/JQuery

$(document).ready(function(){

 var test = $("<a href='#'>Run Me</a>").click(function(){
  alert("Success");
  

Pagination Logic

Installation URL: 
http://stage.orgnsm.org/code/pagination.php
<?php

$items = array(
    0 => array( "item 1", "2013-09-13", "1" ),
    1 => array( "item 2", "2013-09-14", "2" ),
    2 => array( "item 3", "2013-09-15", "3" ),
);


######## CALCULATIONS #########

# set per-page var
if (isset($_GET["perpage"])) $perpage = $_GET["perpage"];
else $perpage = 10;

# calc numb of pages
$pages = ceil(count($items) / $perpage);

# which page are we on?
if( isset($_GET["page"]) && round($_GET["page"]) <= $pages && round($_GET["page"]) > 0 )
	$page = round($_GET["page"]);
else $page = 1;

# calc start and end item
$startItem = (($page - 1) * $p

Device-Responsive Layout

Installation URL: 
http://code.orgnsm.org/viewport.html

HTML

<meta name="viewport" content="width=device-width, initial-scale=1.0;"/>

CSS


@media (max-width: 480px){
}
@media (max-width: 767px){
    #container{
        padding: 0 25px;
    }
    nav ul li a{
        font-size: 100%;
        padding: 15px 0;
        border-radius: 30px;
    }
    nav ul li a svg{
        width: 60px;
        height: 60px;
    }
}
@media (min-width: 768px) and (max-width: 979px){
    #container{
        padding: 0 35px;
    }
    nav ul li a{
        font-size: 120%;
        padding: 20px 0;
        border-r

Dynamic Form Submission

Installation URL: 
http://stage.orgnsm.org/code/form.html

The JavaScript

jQuery(function($){

    $("#contact").submit(function(){
        //grab form values before blowing it out of the DOM in the next line
        values=$(this).serialize();
        $("#contact").html( "<p>Sending message...</p>\n" );
        //send the values to the PHP handler
        $.ajax({
            type: "POST",
            url: $("#contact").attr('action'),
            data: values,
            success: function(re){
                $("#contact").html(re);
            }
        });
        return false;
    });

});

PHP

Pages