Public snipts »
styledev's
snipts
showing 1-15 of 15 snipts
-
∞ // Create Dropdown from Select (CSS)
select.select{display:none;} dl.dropselector{margin:0 10px 0 0;} .dropselector dd,.dropselector dt,.dropselector ul{margin:0px;padding:0px;} .dropselector dd{position:relative;} .dropselector a,.dropselector a:visited{color:#816c5b;outline:none;text-decoration:none;} .dropselector a:hover{color:#5d4617;} .dropselector dt a:hover{border:1px solid #d0c9af;color:#5d4617;} .dropselector dt a{background:#e4dfcb url(arrow.png) no-repeat scroll right center;border:1px solid #d4ca9a;display:block;height:14px;padding-right:20px;padding:10px;width:auto;} .dropselector dt a span{cursor:pointer;display:block;} .dropselector dd ul{background:#e4dfcb none repeat scroll 0 0;border:1px solid #d4ca9a;color:#C5C0B0;display:none;left:0px;list-style:none;padding:5px 0px;position:absolute;min-width:170px;top:2px;width:100%;} .dropselector span.value{display:none;} .dropselector dd ul li a{padding:5px;display:block;} .dropselector dd ul li.current a{background-color:#d0c9af;color:#5d4617;} .dropselector dd ul li a:hover{background-color:#d0c9af;} .dropselector img.flag{border:none;margin-left:10px;vertical-align:middle;} .flagvisibility{display:none;}
-
∞ Create Dropdown from Select (JS)
function createDropSelect(){ var count = 0; $('.select').each(function(){ var select = $(this), selected = select.find("option[selected]"), options = $("option", select); $(".attr_values").append('<dl class="dropselector '+ count +' right"></dl>'); $(".dropselector."+count).append('<dt><a href="#" class="call">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>') $(".dropselector."+count).append('<dd><ul class="call"></ul></dd>') options.each(function(){ if( $(this).text() == selected.text()){ $(".dropselector."+count+" dd ul").append('<li class="current"><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>'); }else{ $(".dropselector."+count+" dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>'); } }); count++; }) } createDropSelect(); $(".dropselector dt a").click(function() { $(this).parent().parent().children('dd').children('ul').toggle(); }); $(".dropselector dd ul li a").click(function() { var text = $(this).html(); $(this).parents('.dropselector').children('dt').children('a').html(text); $(this).parents('.dropselector').children('dd').children('ul').toggle(); var source = $(".select"); source.val($(this).find("span.value").html()) }); $(document).bind('click', function(e) { var $clicked = $(e.target); if (! $clicked.parents().hasClass("dropselector")) $(".dropselector dd ul").hide(); });
-
∞ Grab Vimeo Thumbnail
<?php $url = 'http://vimeo.com/api/clip/6518700/php'; $contents = @file_get_contents($url); $thumb = @unserialize(trim($contents)); echo "<img src=".$thumb[0][thumbnail_small].">"; ?> With Viper's Video Plugin for Wordpress <?php $cont = explode('/',get_the_content(null, 0, '')); $videoID = substr($cont[3], 0, -1); $url = "http://vimeo.com/api/clip/".$videoID."/php"; $contents = @file_get_contents($url); $thumb = @unserialize(trim($contents)); echo "<img src=".$thumb[0][thumbnail_small].">"; ?>
-
∞ Remove Firefox Image Link Outline
a { outline-width: 0; }
-
∞ Uninstall Gem
Uninstall a Gem: $> sudo gem uninstall "gem_name" Or if installed improperly: $> sudo gem uninstall "gem_name" --install-dir=~/.gem/ruby/1.8/
-
∞ Convert RoR Project to HAML
haml --rails path/to/app
-
∞ Find Conditions
Before: Post.find(:first, :conditions => ['status = ? and active = ?', 1, 1]) After: Post.find(:first, :conditions => { :status => 1, :active => 1 })
-
∞ Link Helper
def make_links( str ) regex = Regexp.new '(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)' str.gsub( regex, '<a href="\1">\1</a>' ) end
-
∞ Case Statement
- case parameter - when "this" do this - when "or_this" do this
-
∞ Set the layout file for a controller
layout 'layouts/filename'
-
∞ HABTM Multi-Select
= select(:model, :join_id, JoinModel.all.collect { |i| [ i.name, i.id ]}, { :include_blank => false }, { :onChange => "" })
-
∞ Ordinalized Time Helper
def ordinalized_time(time = Time.now) time.strftime("%b #{time.day.ordinalize}, %Y") end
-
∞ Odd / Even
cycle('odd', 'even')
-
∞ Complex Forms
In the Layout file: = javascript_include_tag :defaults In the Item controller add to the new method: 1.times { @item.tickets.build } In the Ticket model: validates_numericality_of :number, :message => "must not be comprised of letters/symbols!" attr_accessor :should_destroy def should_destroy? should_destroy.to_i == 1 end In the Application.js file: function mark_for_destroy(element) { $(element).next('.should_destroy').value = 1; $(element).up('.ticket').hide(); } Create _ticket.html.haml in the Item view: %div{ :class => 'ticket' } - fields_for "item[ticket_attributes][]", ticket do |f| %p = f.label :number, 'Ticket #' = f.text_field :number, :index => nil = f.label :quarter_id, 'Quarter' = f.collection_select :quarter_id, Quarter.find(:all), :id, :name, {}, {:index => nil} - if ticket.new_record? = link_to_function "[x]", "$(this).up('.ticket').remove()" - else = link_to_function "[x]", "" = f.hidden_field :id, :index => nil = f.hidden_field :should_destroy, :index => nil In the Item helper: def add_ticket_link(name) link_to_function name do |page| page.insert_html :bottom, :tickets, :partial => 'ticket', :object => Ticket.new end end In the Item view: (preferably in a _fields.html.haml partial) %p %div{ :id => 'tickets' } = render :partial => 'ticket', :collection => @item.tickets = add_ticket_link "Add a Ticket" In the Item model: after_update :save_tickets validates_associated :tickets def ticket_attributes=(ticket_attributes) ticket_attributes.each do |attributes| if attributes[:id].blank? tickets.build(attributes) else ticket = tickets.detect { |t| t.id == attributes[:id].to_i } ticket.attributes = attributes end end end def save_tickets tickets.each do |t| if t.should_destroy? t.destroy else t.save(false) end end end protected def after_validation # Create an empty array to hold the field names fields = [] # Iterate through the errors errors.each do |field,message| # Unless you have alreayd processed the field add the errors (This is necessary to remove duplicates for the 'has many' fields) unless fields.include?(field) # If the field of an error is really an association, then the 'validates_associated' found an error if self.class.reflect_on_all_associations.collect(&:name).index(field.to_sym) # Iterate through the objects in the association looking for the invalid ones self.send(field).each do |association| if association and !association.valid? # add the error messages of the associated object to my error messages association.errors.each_full do |msg| self.errors.add_to_base "#{association.class.name}: #{msg}" end end errors.delete field end fields << field end end end end Create the following config/initializers/error_patches.rb class ActiveRecord::Errors def delete(attribute) @errors.delete attribute.to_s end end
-
∞ HTML2HAML
find . -name '*erb' | \ xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' find . -name '*erb' | \ xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \ bash



CSS Pocket Reference: Visual Presentation for the Web