Jump to content

smoseley

Members
  • Posts

    433
  • Joined

  • Last visited

Posts posted by smoseley

  1. Oops, missed the overlap. This'll work (though a bit sloppy):

    $Result = array_filter(array_merge($Array1, $Array2), function($arr) {
        global $keys;
        $keys = is_array($keys) ? $keys : array();
        $keys[$arr['id']] = isset($keys[$arr['id']]) ? $keys[$arr['id']]+1 : 0;
        return $keys[$arr['id']] == 0;
    });
    

  2. By the way, in answer to this question:

    Should you create a separate JS file for something that will be used one time?

    I know that was probably rhetorical, but the answer can be yes.  If your script is significant in size, and the page using it can be visited multiple times per visitor, then there's a benefit to creating an external script for it.  I've done this many, many times.

     

  3. Doesn't depend on the script.  If you use a load-event handler, the script can go anywhere.  If you put it at the end of the <body>, you don't need a load-event handler.  That's pretty much that.

     

    As for "best practices", I said it "should" go in the <head> because some older browsers (much older) don't support <script> blocks in the <body>.  I was trying to illustrate that "best practices" are silly when then end-result has essentially no effect on your users.  What's "best" is what works, while still being valid code.

  4. Yes, it's a little messy messy. 

     

    It's a best practice to split separate operations onto separate lines of code, e.g.:

     

    $company_url = get_post_meta($post->ID, '_CompanyURL', true);
    if (!is_null($company_url)) {
        $company_url = esc_url($company_url); 
        //more stuff
    }
    

  5. By the way here's the answer to your last question:

     

    <?php
    // Some code
    $timeLeft = 300;
    ?>
    <script type="text/javascript">
    var timeLeft = <?=$timeLeft?>; // 5 minutes
    var timer = window.setInterval(function() {
        timeLeft--;
        var minutesLeft = Math.floor(timeLeft / 60);
        var secondsLeft = timeLeft % 60;
        console.log('Time left: ' + minutesLeft + ':' + secondsLeft);
        if (timeLeft == 0) {
            window.clearInterval(timer);
            // do some ajax thing
        }
    }, 1000);
    </script>
    

     

    But of course, your next question will be...

  6. var timeLeft = 300; // 5 minutes
    var timer = window.setInterval(function() {
        timeLeft--;
        var minutesLeft = Math.floor(timeLeft / 60);
        var secondsLeft = timeLeft % 60;
        console.log('Time left: ' + minutesLeft + ':' + secondsLeft);
        if (timeLeft == 0) {
            window.clearInterval(timer);
            // do some ajax thing
        }
    }, 1000);
    

  7. Nice try smoseley, but $this->menu_array is still undefined.

    Good point.  But it's not supposed to be defined.  He seems to want to reference $menu_array (param).  I got one, guess I missed one.

  8. 
    
    class Menu {
    private $newmenu;
    private $menu;
    public function __construct($menu_array, $index, $select = null){
    
    	//Get Text for Links from Keys of Array
    	$menu_text = array_keys($menu_array);
    
    	// produce and output the correct menu
    	$i=0;
    	if(isset($select) && $select!=null){
    		$this->newmenu="<select>"; 
    	}
    	foreach(array_values($this->menu_array) as $link_option){
    		$this->newmenu.=$this->menu;
    		$i++;
    	}
    	if(isset($select) && $select!=null){
    		$this->newmenu.="</select>"; 
    	}
    }
    
    public function generateTopMenu(){
    	$this->menu='<a href="'.$link_option.'">';
    	$this->menu.=$menu_text[$i];
    	$this->menu.='</a> ';
    }
    
    public function generateSearchMenu(){
    	$this->menu.='<option value="'.$search_text[$i].'" >'.$search_item.'</option>'."\n";
    }
    
    public function returnMenu(){
    	return $this->newmenu;
    }
    }
    

  9. I tried that and it doesn't work, although I thought it might when I tried it on my own this morning.

     

    Drummin' still in the lead...  ;)

     

    Debbie

    Ok, here's another shot at it:

     

    dt, dd {
        display: block;
        float: none;
        clear: both;
        min-height: 1em;
        margin: 0 0 2px;
        padding: 0;
    }
    dt {
        font-weight: bold;
    }
    dd {
        margin-left: 20px;
    }
    

     

    Of course, the   isn't a bad idea.  I'd probably go with that myself.

  10. Did you put that javascript code at the bottom of the page? And it needs to be wrapped in

    $(document).ready(function(){

    //your code here

    });

    If it's at the bottom of the page, it doesn't necessarily need a window.onload (document-ready) event.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.