Posts Tagged ‘element’

Can I hide broken images?

Monday, August 23rd, 2010

Hi guys, I am trying to create a sidebar for which I can specify the image in the back-end of my wordpress cms using custom fields, now I have gotten it to work, with just one little bug, if the user enters a invalid URL, the image link will display as broken and will not display, is there a way that I can hide the broken image icon perhaps?

I have a background image set for the parent DIV element so that if there is no image to display, the parent’s background will.

here is the PHP code:

//here I get the 'side_image' custom field, which will contain the URL to the side image
if (have_posts()) :
         while (have_posts()) : the_post();
             $side = get_post_meta($post->ID, 'side_image', true);
         endwhile;
 endif;

HTML:

<!--here is the HTML markup-->
<div id="inner_content_right">
    <img src="<?php echo $side; ?>" />
</div>

CSS:

#inner_content_right {
    background: url(images/Layout_3_other_06_backup.jpg) no-repeat;
    width: 259px;
    height: 691px;
    float: right;
    position: relative;
    bottom: 28px;
}

Thanx in advance!

Apply border to all elements

Monday, August 23rd, 2010
How do I apply a thin border to ever element in my document?

I want to be able to see the border on every element so I can better understand where one ends and the next begins.

I tried this but it only applies to the body

Code:

body {
  border: 4px solid black;
}


Debbie

IE 8 Quirks vs Standards retrieving offsetHeight/offsetWidth

Monday, August 23rd, 2010

I am in the process of converting my application to use XHTML strict mode (it didn’t have a DOCTYPE before). However, I noticed a significant degradation when getting offsetHeight/offsetWidth. This is very noticeable on pages with large number of DOM elements, let’s say a table with 1 column by 800 rows, the cells only have a piece of text. Visiting each descendant element in that table to obtain their offset dimension is way slower than when IE renders the page in Quirks mode.
Why is that the case? and does anybody know tips to help IE calculate those offsetValues?

[CSS21] Issue 142: the term “ancestor box”

Sunday, August 22nd, 2010
This is proposed text for issue 142[1]. Section 10.1 uses the term
"ancestor box," by which it means the "box of an ancestor element." But
apparently the term causes confusion. That is probably because in some
cases and in some implementations the boxes form a tree. (CSS doesn't
say that the boxes form a tree, only that each box is associated with an
element and the elements form a tree.)

So here is a rewrite to avoid the term. The following all occur in
section 10.1:

  - Replace the first occurrence of "ancestor box" by "ancestor
    element".

  - Replace the occurrence of "ancestor boxes" (in the example) by
    "ancestor elements".

  - Replace the phrase "the nearest positioned ancestor box" (at the
    end of the example) by "the padding edge of the nearest positioned
    ancestor".

[1] http://wiki.csswg.org/spec/css2.1#issue-142

Bert

libxml2 HTML parsing

Sunday, August 22nd, 2010

I’m parsing HTML with libxml2, using XPath to find elements. Once I found the element I’m looking for, how can I get the HTML as a string from that element (keeping in mind that this element will have many child elements). Given a document:

<html>
    <header>
        <title>Some document</title>
    </header

    <body>
        <p id="faq">
            Some kind of text <a href="http://www.nowhere.com/">here</a>.
        </p>
    </body>
</html>

Say I retrieved the body element with XPath and then get the HTML for that, I’d like to end up with a string containing:

<body>
    <p id="faq">
        Some kind of text <a href="http://www.nowhere.com/">here</a>.
    </p>
</body>

How can I do this?

jQuery – do something after an element is loaded via ajax, but not in the ajax function

Sunday, August 22nd, 2010

I’m trying to watch for an element to load on the page from an ajax call. I don’t have access to the jquery that’s making the ajax call. So, when some new html is loaded onto the page, I’d like to apply some changes to it.

I’m currently trying to use the .load() function:

$( '.autosuggest_keyword' ).load(
    function()
    {
        $( this ).val( 'load test' );
    }
);

Which isn’t doing anything. I even tried making that a live binding, which doesn’t really make sense, but I thought I’d give it a try.

The selector is correct.

Any ideas?

How do you Unit Test a Zend_Form that includes the CSRF form element?

Sunday, August 22nd, 2010

I’m using the CSRF hidden hash element with Zend_Form and trying to Unit Test the login but don’t know how to write a Unit Test to include that element. Looked in the docs and read as many tutorials as I could find. I even delicioused them all, but no one mentions this.

Algorithm for number of transitions between pair of set (graph) partitions

Sunday, August 22nd, 2010

Say I have a set (or graph) which is partitioned into groups. I am interested to find the number of transitions between two partitions, where a transition involves taking an element out of one partition and moving it into another (or singleton partition by itself)

For example there is one transition between partitions

1 2 | 3 and 1 | 2 | 3

but between 1 2 3 4 and 1 2 | 3 | 4

The minimum number of transitions is 2 I believe.

So my question is are there algorithms that given a pair of partitions and a set, can return the number of transitions states between them?

There is a further complication that this set actually represents a graph and I would like every partition (and transition partition) to be connected (i.e. 1 2 | 3 would be invalid if there exists no in/direct connection between 1 and 2 unblocked by 3′s single partition) but unless you are truly enlightened about this topic you can much probably ignore that.

Thanks

As a note I do have a method I thought of myself which is basically to find all neighbours of a partition A (i.e. all partitions which can be found within one transition) and do the same for partition B and if these is some overlap between these two sets of neighbours then they are one transition away. However this method gets very expensive very quickly.

Circular queue problem

Sunday, August 22nd, 2010

I’m learning queues from a book. I’ve got into a problem while learning circular queue. The author from which I’m learning uses the following piece of code to explain how an element is inserted in a circular queue.

#define MAX 100
char *p[MAX];
int spos = 0; // spos: holds the index of the **next free** storage location

int rpos = 0;// rpos: holds the index of the next item to retrieve

void qstore(char *q)
{
  /* The queue is full if either spos is one less than rpos
      or if spos is at the end of the queue array and rpos
      is at the beginning.
  */
  if(spos+1= =rpos || (spos+1==MAX && !rpos)) <-- /***Problem is here**. Is it even
                                                    correct?*/
  {
     printf(''List Fulln");
     return;
  }
  p[spos] = q;
  spos++;

  if(spos==MAX)
  spos = 0; /* loop back */
}

He further states that: The queue is full when the store index is one less than the retrieve index; otherwise, there is room in the queue for another event.

SO, acc. to the author, if spos (which holds the index of the next free storage location) is equal to 4 and rpos=5, then the queue is full. Isn’t this incorrect? Because spos=3 means that the memory location at p[3] is empty.


So I decided to change the program.

#define MAX 100
char *p[MAX];
int spos = 0; // spos: holds the index of the **last allocated** storage location

int rpos = 0;// rpos: holds the index of the next item to retrieve

void qstore(char *q)
{
  /* The condition for queue full is same as the previous program*/

 /* The queue is full if either spos is one less than rpos
      or if spos is at the end of the queue array and rpos
      is at the beginning.
  */

if((spos+1==rpos) || (spos+1==MAX && rpos==0)) // Also changed syntax of test condition.
 {
   printf("Queue Fulln");
 } 

spos++

if((spos+1==MAX) && (rpos!=0))
 {
   spos=0;
 }
else
{
  spos++;
}

 p[spos]=q;

}

Is my code correct?

screen scrape help

Sunday, August 22nd, 2010
I’m trying to create a mac widget and i mistakenly thought i could use php to do what i want. I’m trying to figure out how to scrape a certain element with an id and display it using only javascript. something like…

Code:

function screenscrape(url, elementid) {

//code to find that element id from the provided url and display it

}


any help would be much appreciated!