Month: June 2014

What is the difference between jquery position() and offset()?

<html>
<body>
<divid="div1"style="position:absolute; top:50px; left:50px">
<divid="div2">
</div>
</div>
</body>
</html>


Both offset and position for body will return 0 and 0.
Both offset and position for div1 will return 50 and 50.

AND NOW THE INTERESTING PART

Position for div2 will return top:0 and left:0 which would be relative to the parent in this case div1.
HOWEVER,
Offset for div2 will return top:51 and left:51 which is relative to the body and 1 is added to 50 for 1px border.

Advertisements

How to add new tab to admin list of posts and handle result list

post

 

add_action('views_edit-post','remove_edit_post_views');function remove_edit_post_views( $views ){
    $views['pre']='<a href="'.admin_url().'edit.php?pre=pre">My Special Posts</a>';return $views;}

add_action('pre_get_posts','my_special_list');function my_special_list( $q ){
  $scr = get_current_screen();if( is_admin()&&( $scr->base==='edit')&& $q->is_main_query()){// To target only a post type uncomment following line and adjust post type name// if ( $scr->post_type !== 'post' ) return;// if you change the link in function above adjust next line accordingly
    $pre = filter_input(INPUT_GET,'pre', FILTER_SANITIZE_STRING);if( $pre ==='pre'){// adjust meta query to fit your needs
      $meta_query = array('key'=>'is_special','value'=>'yes',);
      $q->set('meta_query', array($meta_query));}}}

LESS (stylesheet language)

LESS (Leaner CSS) is a dynamic stylesheet language designed by Alexis Sellier. It is influenced by Sass and has influenced the newer “SCSS” syntax of Sass, which adapted its CSS-like block formatting syntax.

Variables

LESS allows variables to be defined. LESS variables are defined with an at sign(@). Variable assignment is done with a colon (:).

During translation, the values of the variables are inserted into the output CSS document.[4]

@color: #4D926F;

#header {
color: @color;
}
h2 {
color: @color;
}

The code above in LESS would compile to the following CSS code.

#header {
color: #4D926F;
}
h2 {
color: #4D926F;
}

Mixins

Mixins allow embedding all the properties of a class into another class by including the class name as one of its properties, thus behaving as a sort of constant or variable. They can also behave like functions, and take arguments. CSS does not support Mixins. Any repeated code must be repeated in each location. Mixins allow for more efficient and clean code repetitions, as well as easier alteration of code.[4]

.rounded-corners (@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}

#header {
.rounded-corners;
}
#footer {
.rounded-corners(10px);
}

The above code in LESS would compile to the following CSS code:

#header {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#footer {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}

LESS has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.