Skip to content

Instantly share code, notes, and snippets.

(function($) {
var methods = {
init: function() {
var $ul = $("<ul/>").insertAfter(this);
var baseId = "_" + $(this).attr("id");
$(this).children("option").each(function(index) {
var $option = $(this);
var id = baseId + index;
var $li = $("<li/>").appendTo($ul);
@esedic
esedic / browser_caching_htaccess
Created June 7, 2014 08:07
Browser caching in .htaccess
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType etc, etc.
@esedic
esedic / view_pdf_in_browser
Created June 7, 2014 08:09
Display PDF in-page without a javascript plugin
/**
* When browser supports inline pdfs
* There is no need to append a large jquery plugin that displays them inline.
*
* You can actually use an iframe (and style it appropriately)
* or a link whenever inline PDF viewing is not supported
*
* This function is fairly simple and it's only for demo purposes
*/
function appendPdf(id, url) {
@esedic
esedic / data_in_module_position
Created June 7, 2014 08:10
Inject data into a Joomla module position
<?php
// Inject data from your component into the right module position
JFactory::getDocument()->setBuffer($data, 'modules', 'right');
// Note: Data will not be shown unless there are "real" modules present in position right
@esedic
esedic / remove_html_comments_rerplacer
Created June 7, 2014 08:11
Remove HTML comments with ReReplacer
Removes all
<!--.*?-->
Leaves conditional comments, i.e. <!--[if IE]>
<!--(?!\[).*?(?!<\])-->
@esedic
esedic / defer_javascript
Created June 7, 2014 08:13
Defer javascript - Google way
<!-- Put this before </body> tag -->
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
@esedic
esedic / add_viewport_tag_jquery
Created June 7, 2014 08:14
Add viewport tag to head with jQuery
//useful for jsfiddle
$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />');
@esedic
esedic / gist:ee6f406ba1a4aca702fa
Created June 7, 2014 08:18
Loop through array and increase values
<?php
$count = 1;
$values = array("1","2","3");
echo "<ul>";
foreach($values as $value){
echo "<li data-id=\"id-".$count."\" data-type=\"".$value['class']."\">test</li>\n";
$count++;
}
echo "</ul>";
@esedic
esedic / gist:1c4a6b8daaf7a34210a6
Created June 7, 2014 08:20
Prepend http to a URL
<?php
//Some times you need to accept some url as input but users seldom add
// http:// to it, this code will add http:// to the URL if it’s not there.
if (!preg_match("/^(http|ftp):/", $_POST['url'])) {
$_POST['url'] = 'http://'.$_POST['url'];
}
@esedic
esedic / gist:4f59cd4f8988cd9bca9f
Created June 7, 2014 08:21
Convert URLs within String into hyperlinks
<?php
// This function converts URLs and e-mail addresses within a string into clickable hyperlinks.
function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="\1">\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'\1<a href="http://\2">\2</a>', $text);
$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',