Skip to content

Instantly share code, notes, and snippets.

@mynameispj
mynameispj / orientationChange.js
Last active September 3, 2020 19:39
jQuery event that fires when the orientation (portrait, landscape) of a mobile device changes
window.addEventListener("orientationchange", function() {
alert(window.orientation);
//do whatever you want on orientation change here
}, false);
@mynameispj
mynameispj / controller.rb
Created March 23, 2013 21:38
In Rails, redirect a logged in user from the home page to another page
def home
if current_user.present?
redirect_to projects_url
end
end
@mynameispj
mynameispj / dropdown.html
Last active December 22, 2019 16:05
Simple jQuery dropdown boxes that disappear when you click outside of them
<a class="drop-down-toggle">Click me to reveal drop down box below...</a>
<div class="drop-down-wrapper">
Hello, I will be revealed!
</div>
@mynameispj
mynameispj / Compass px to em
Created March 10, 2013 22:29 — forked from ijy/Compass px to em
Modified for SASS syntax...
@function em($target, $context: $base-font-size)
@if $target == 0
@return 0
@return $target / $context + 0em
$base-font-size: 16px
@mynameispj
mynameispj / height.js
Created February 9, 2013 23:31
jQuery: get the height of an element and set that height as an inline style on said element
$(window).load(function(){
var height = jQuery('#your-element').outerHeight(true);
$('#your-element').css('height',mainContainerVXDHeight);
})
@mynameispj
mynameispj / props.txt
Created February 8, 2013 22:05
Simple sticky elements with no jQuery plugin
http://daigo.org/2011/09/quick-and-dirty-sticky-elements-when-scrolling-using-jquery/
@mynameispj
mynameispj / htmlspecialchars.js
Created February 3, 2013 20:35
HTML Special Characters in jQuery
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
@mynameispj
mynameispj / page.tpl.php
Created December 8, 2012 22:48
Drupal Omega: Print region outside of section
//Your region won't be rendered if it doesn't have a zone. There is a work-around for your use-case. All the //regions that are not being printed get placed in $page['#excluded']. You can use hook_page_alter() to move a //region from there to the part of the $page array that gets forwarded to the templates.
//source: http://drupal.org/node/1200272
$page['my_new_region'] = $page['#excluded']['my_new_region'];
@mynameispj
mynameispj / getFilePath.php
Created October 31, 2012 22:43
Drupal 7 - Get Filepath for File or Image
$findTheFileURL = file_create_url($node->field_csv_file['und'][0]['uri']);
@mynameispj
mynameispj / elementContainsOtherElement.js
Created October 17, 2012 20:50
jQuery - check if element has another element
$('#div').has('.other-div').length;
//returns 1 if it does, returns 0 if it doesn't