you are here: codestackercodes [RSS]

seletores do jquery

http://docs.jQuery.com/DOM/Traversing/Selectors

$('h1') // elementos h1

$('#meuID') // elementos com id "meuID"

$('.minhaClasse') // elementos definidos com a classe "minhaClasse"

$('[width]') // elementos que possuem o atributo width definido

$('[width=500]') // elementos que possuem o atributo width definido como 500

$('img[width=300]') // imagens que possuem largura = 300

$('img[src$=png]') // imagens com final png

$('a[href^=http://localhost]') // links que comecem com http://localhost

$('a[href$=pdf]') // links com final pdf

$('a[href*=www]') // links que contém www

$(':empty') // elementos vazio

$('div:empty') // elementos div vazios

$(':has(p)') // todos elementos que tenham um parágrafo

$('div:has(a)'); // elementos div que possuem link

$("p:contains('dinei')") // parágrafos que contém a palavra "dinei"

$("p:eq(0)") // seleciona o primeiro elemento p

i18n in labels

rails 2.3.4 doen't have i18n support in labels

http://lawrencesong.net/2009/04/i18n-label-in-rails-monkey-patch/

module ActionView 
  module Helpers 
    class InstanceTag 
      def to_label_tag_with_i18n(text = nil, options = {}) 
        text ||= object.class.human_attribute_name(method_name) if object.class.respond_to?(:human_attribute_name) 
 
        to_label_tag_without_i18n(text, options) 
      end 
 
      alias_method_chain :to_label_tag, :i18n 
    end 
  end 
end

paperclip refresh all images

run this task

rake paperclip:refresh class=MyClass

use default_scope to set up default find conditions such as order

class MyModel < ActiveRecord::Base
  default_scope :order => 'created_at desc'
end

Detectar se o browser estar offline ou online

Como detectar que seu browser estar offline ou online utilizando de jQuery?
Esse código foi montado e capturado na internet. Por tanto náo é meu.
Agora não sei de quem são os créditos.

Com ele temos como mostrar para o usuário que sua conexão esta offline.

<script type="text/javascript">
		jQuery.networkDetection = function(url,interval){
			
			var url = url;
			var interval = interval;
			online = false;
			this.StartPolling = function(){
				this.StopPolling();
				this.timer = setInterval(poll, interval);
			};
			
			this.StopPolling = function(){
				clearInterval(this.timer);
			};
			
			this.setPollInterval= function(i) {
				interval = i;
			};
			
			this.getOnlineStatus = function(){
				return online;
			};
			
			function poll() {
				jQuery.ajax({
					type: "POST",
					url: url,
					dataType: "text",
					error: function(){
						online = false; 
						jQuery(document).trigger('status.networkDetection',[false]);
					},
					success: function(){
						online = true; 
						jQuery(document).trigger('status.networkDetection',[true]);
					}
				});
			};
			
			
		};
					
		jQuery(document).ready(function(){
			
			network = new jQuery.networkDetection("/poll", 5000);
			network.StartPolling();
			
			jQuery(document).bind("status.networkDetection", function(e, status){	
				// subscribers can be namespaced with multiple classes

				subscribers = jQuery('.subscriber.networkDetection');
				// publish notify.networkDetection to subscribers

				subscribers.trigger("notify.networkDetection", [status])
				/*
				other logic based on network connectivity could go here
				use google gears offline storage etc
				maybe trigger some other events
				*/
			});
			
			/* 
			Listen for notify.networkDetection events. This could equally be listening
			directly to status.networkDetection events
			*/
			jQuery('#notifier').bind("notify.networkDetection",function(e, online){
				// the following simply demonstrates

				notifier = jQuery(this);
				if(online){
					if (!notifier.hasClass("online")){
						notifier.hide();
						jQuery(this).addClass("online").removeClass("offline").text("Você esta online");
					}
				}else{
					if (!notifier.hasClass("offline")){
						notifier.show();
						jQuery(this).addClass("offline").removeClass("online").text("Sua conexão esta falhando");
					}
				};
			});
			
		});



</script>

<style type="text/css">
	
	* {
		font-family:verdana, arial, helvetica, sans-serif;
		font-weight:bold;
	}
	
	#notifier{
		border:1px solid #CCCCCC;
		color:#333333;
		margin-left:36%;
		padding:20px;
		position:absolute;
		text-align:center;
		width:300px;
	}
	
	#notifier.online{
		color:#fff;
		background:#3c3;
		border-color:#3c3;
	}
	
	#notifier.offline{
		color:#fff;
		background:#f66;
		border-color:#f66;
	}
	
	
</style>


<body class="pagLogin">
	
	<div id="notifier" style="display: none;" class="subscriber networkDetection online">ONLINE</div>
	
</body>

humanized attributes

class User < ActiveRecord::Base

  HUMANIZED_ATTRIBUTES = {
    :email => "E-mail address"
  }

  def self.human_attribute_name(attr)
    HUMANIZED_ATTRIBUTES[attr.to_sym] || super
  end

end

copy to clipboard

function copyToClipBoard(id) {
    Copied = document.getElementById('id').innerText.createTextRange();
    Copied.execCommand("Copy");
}

back to top

<a href="#top" onclick="$('html, body').animate({scrollTop:0}, 'slow'); return false;">top</a>

unobstrusive popup

http://www.quirksmode.org/js/popup.html

   function popup(url) {
        newWindow = window.open(url, 'name', 'height=400,width=335,scrollbars=yes');
        if (window.focus) { newWindow.focus() }
            return false;
    }

// <a href="link.html" onclick="popup('link.html');">Link</a>

force download .htaccess

AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4

delete recursively a file (.DS_Store, thumbs.db...)

find . -name ".DS_Store" -depth -exec rm {} \;

wordpress popular posts

<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

hide/show dl list with jquery

		$(document).ready(function() {
			$('dd').toggle();
			$('dt').click(function() {$(this).next('dd').toggle('slideDown');});
		});

ie 6 and 7 selectors hack

* html #selector {property:value;} /* Only IE6 and lower will see this */
*+html #selector {property:value;} /* Only IE7 will see this */

backup all mysql database

mysqldump -u username -ppassword –all-databases > dump.sql

iPhone CSS

<link media="only screen and (max-device-width: 480px)" href="iPhone.css" type="text/css" rel="stylesheet" />

paperclip ie validation

validates_attachment_content_type :image,
  :content_type => [
    'image/jpeg',
    'image/pjpeg', # for progressive jpeg (IE mine-type for regular jpeg) 

    'image/png',
    'image/x-png', # IE mine-type for PNG

    'image/gif'
]

hover for ie 6

/* IE6 - pseudo class :hover */ 
$(document).ready(function(){ 
	if(jQuery.browser.msie && jQuery.browser.version<7){ 
		$('[class*="bla"]').hover( 
		function () { 
			$(this).addClass('hover'); 
		}, 
		function () { 
			$(this).removeClass('hover'); 
		} 
		); 
	} 
});

vertical align plugin for jquery

http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/

(function ($) {
// VERTICALLY ALIGN FUNCTION

$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);

// $('#mydiv').vAlign();

hartija css print framework

http://code.google.com/p/hartija/

body { 
width:100% !important;
margin:0 !important;
padding:0 !important;
line-height: 1.4;
word-spacing:1.1pt;
letter-spacing:0.2pt; font-family: Garamond,"Times New Roman", serif; color: #000; background: none; font-size: 12pt; }

h1,h2,h3,h4,h5,h6 { font-family: Helvetica, Arial, sans-serif; }
h1{font-size:19pt;}
h2{font-size:17pt;}
h3{font-size:15pt;}
h4,h5,h6{font-size:12pt;}

code { font: 10pt Courier, monospace; } 
blockquote { margin: 1.3em; padding: 1em;  font-size: 10pt; }
hr { background-color: #ccc; }

img { float: left; margin: 1em 1.5em 1.5em 0; }
a img { border: none; }

a:link, a:visited { background: transparent; font-weight: 700; text-decoration: underline;color:#333; }
a:link[href^="http://"]:after, a[href^="http://"]:visited:after { content: " (" attr(href) ") "; font-size: 90%; }
a[href^="http://"] {color:#000; }

table { margin: 1px; text-align:left; }
th { border-bottom: 1px solid #333;  font-weight: bold; }
td { border-bottom: 1px solid #333; }
th,td { padding: 4px 10px 4px 0; }
tfoot { font-style: italic; }
caption { background: #fff; margin-bottom:2em; text-align:left; }
thead {display: table-header-group;}
tr {page-break-inside: avoid;} 
Displaying Code 121 - 140 of 300 in total