Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Posts posted by Drongo_III

  1. The code here is stripped down but it's got the issue I am talking about.

     

    Let me explain this more clearly. The div with the id '#popUp' has inside it a link and an image. My expectation from the code is that if you click the div with the ID '#popUp' the click function will fire. But I don't understand why if you click the link for 'close', the click funciton also fires. This is what doesn't make sense to me. The selector is surely the div and not the child elements within the div. OR is that the way the selector works? Am i misunderstanding something?

     

    I'm not quite following you. In your code there is only one div. If you have multiple divs like...

     

    <div id="popUp">This works</div> <div id="popDown">This works too</div>

     

    Well...that shouldn't be happening and it won't help if you don't show everything

  2. Hi

     

    That's not how I intended it to work though :/ Why would it target everything in the div? Since the selector is for '#popUp' - doesn't that mean the click function should only fire on clicking the div with that ID? I guess what I am saying is, why would the child elements active the click function when they aren't part of the selector?

     

     

     

    The way you have it set up, if you click anything in the div it will be executed, you have done nothing wrong.

  3. Hi Guys

     

    Having an issue with jquery that I've never had before.

     

    It was my expectation that with the code below (stripped down the code for this example) if you click the div with the ID '#popUp' the click function will run. What I dont understand is why when you click anything in the div (as the link or the image) the click function also runs. That's never happened before so I am really confused.

     

    Using jquery 1.8.2

     

    Can anyone point out what I've done wrong? Mighty confused and been staring at this particular website for quite some hours so probably missing something obvious :/

     

    Any help would be very welcome.

     

    Thanks,

     

    Drongo

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title></title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    
    <script type="text/javascript" src="jquery182.js"></script>
    <script type="text/javascript">
    
    
    
     $(document).ready(function(){
    
      $('#popUp').click(function(){
    
       $('#popUp').fadeOut(600, function(){  
       $('#popUp img').remove();
       $('#blackout').css('display','none');
    
       });
      });
    
    
     });
    
    
    </script>
    
    <style>
    
    #popUp{
    
     position: absolute;
     z-index: 601;
     padding: 20px; 
     margin-left: 300px;
     background-color: #000;
    
    
    
    }
    .close{
    
     position: absolute;
     z-index: 630;
     right: 20px;
     bottom: 1px;
     color: #fff;
    
    
    }
    
    </style>
    
    </head>
    <body>
    <div id="popUp">
    
     <img src="https://www.google.co.uk/images/srpr/logo3w.png"/>
     <a href="#" class="close" >Close</a>
    </div>
    </body>
    </html>
    
    
    
    

  4. Hi Guys

     

    I am making a simple lightbox style popup div. What I want is for the div to popup (containing an image) and then scale to 100%. But I want it to scale so it essentially looks like the parent div is opening from the center out. I've seen this effect on lightboxes in the past.

     

    The problem I have is that the div appears to only scale from the top left - which you can see because the container's image in the example below shows from the top left. I've tried to play about the various parameters you can set but none seem to achieve what i want.

     

    So...

     

    a.) Is it possible at all?

    b.) Is there just some css trickery I am not taking into account?

     

    Thanks, Drongo.

     

    Simplified example follows:

     

    <!DOCTYPE html>
    <html>
    <head>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    
    
    <style type="text/css">
    div {
    margin: 0px;
    width: 275px;
    height: 100px;
    background: green;
    border: 1px solid black;
    position: absolute;
    left: 200px;
    top: 200px;
    overflow: hidden;
    padding: 20px;
    display: inline-block;
    display: none;
    
    </style>
    <script>
    $(document).ready(function() {
    
    $("#clicks").click(function () {
     $('div').show("scale", {direction: 'both', scale: 'both'}, 1000);
    //alert(1);
    });
    });
    </script>
    </head>
    <body >
    <a href="#" id="clicks">Show Div</a>
    <div>
    <img src="http://www.google.co.uk/images/srpr/logo3w.png" />
    
    </div>
    </body>
    </html>
    

  5. Hi Guys

     

    Simple question but as I dont tend to work with dates much I figured I'd get some advice.

     

    I have a DB table and one of the fields is the 'date of publish' in the format 'YYYY-MM-DD' and based on whether the date is in the future or the past I need to display the row data.

     

    What I was wondering is whether a method as simple as the following is a viable method to determine whether the date from the db is in the future or not:

    1. strtotime() on date from database
    2. Get current time()
    3. use the php min function to determine if the date in the database is larger than current time - which would indicate it's in the future.

    Or is that too simplistic and stupid?

     

    The other option I am playing with is DateTime::diff but as I need to evaluate a large number of values in this way it seems a bit heavy.

     

    Any opinions on whether i am on the right track, and if so, which you'd advise?

     

    Thanks,

     

    Drongo

  6. I am trying to get a simple menu to have few item next to each other in the row, but still be centered with the page.

     

    <div ID="parent">

    <div ID="child">Menu Item 1</div><div ID="child">Menu Item 2</div><div ID="child">Menu Item 3</div>

    </div>

     

    How would I CSS that? I am having issues centering them on the page and keeping them next to each other at the same time.

    Thanks

     

    As above. Set the parent div to be

     

    margin: 0px auto;
    

     

    And it most definitely does work in IE!

  7.  

    Yes I have :)

     

    I think you misunderstood me. It's not the window.open function I have an issue with. The issue is I don't have access to the site that opens the popup window. The only bit I control is the content of the popup window. I need to change that content but the new content is bigger than the dimensions of hte popup window and the popup also has no scroll set.

     

    So I need a way to change the scrollbar property of the window from within the popup.

     

    Hope that makes more sense :)

  8. Ok, so here is my little dilemma. I have a table that acts as a spreadsheet and allows the user to click a cell and pops open an input box. And when a blur event is triggered on the input box it runs some ajax to submit the data in to the database and then closes the input box and adds that value to the cell. My problem is, if I click really really fast on multiple cells, multiple input boxes pop up and the blur event is not triggered.

     

    Is there a way to handle this type of action. I know it's nitpicky, but I can just imagine some of our engineers clicking too fast and getting this little bug.

     

    Please let me know if there is anything I can do about this.

     

    Thanks in advance!

     

     

    As there's no code I would suggest one of the following:

    1. Set a flag when an input box is opened. Then at the start of your click function do a check to see if that flag is true and if it is then don't continue running the click function. So this way you constrain the user to only having one input active at any one time. Then on blur you can reset the flag.
       
       
    2. Another option might be to set a timer so that the function cannot be run again until say 1-2 seconds has elapsed.

    Hope those suggestions help a bit!

  9. Hi Guys

     

    Strange request but stick with me. I have a site that I can't currently access that opens a popup window targeted at another site i can access. I need to change the content of that popup which is straight forward enough except for that the function that opens the popup window has the new window set to a small size with no scroll.

     

    Resizing the window is easy enough with an onload function. But I need the window to be scrollable.

     

    So if a window is opened using window.open(), but the window is not opened with a scrollbar, is it possible to subsequently add the scrollbar dynamically - i.e. through an onload function?

     

    This is purely as a temporary solution.

     

    I've googled for an hour and tried varies snippets of code but none work :/

     

    So a definitive answer as to whether this is possible would be amazing!

     

    Drongo

  10. Hi Guys

     

    Working on tricky site at the mo and what I really need is to be able to do something like:

     

    background : url('images/side_shadows.png') 0px 150px repeat-y;
    

     

    I need this because I want the background shadow to start some distance down the div on which it's applied. But this doesn't appear to work (by which i mean nothing happens and it just tiles down the y-axis as normal). Is it just a fact that this doesn't work or is there something I'm missing?

     

    Thanks

     

    Drongo

  11. Hi Guys

     

    Bit stuck on this.

     

    I have a textarea and as part of validating it I want to run a regex to ensure it matches my criteria. The problem is everytime I introduce a literal fullstop the check fails - even though it should be one of the acceptable characters.

     

    The regex is as follows:

     

    $pattern3 = '/^[a-zA-Z0-9"\'\.]{3,}$/';
    if(!preg_match($pattern3, $posts['message'])){
    
      $errorsArray[] = 'Please provide a short description of your problem.';  
    
     }
    

     

    Anyone point me in the right direction please?

  12. Well that worked perfectly :) Thank you!

     

    I will spend some time deciphering that regex too...i'll have it cracked by sometime next month ;)

     

    You're right in that I don't use it for replacing URIs with HTML anchors, but I use it to validate them. To get it to replace, all you need to do is to take out the RegExp anchors. So that it's not tied to the start and end of the string.

    Next step is to put a pair of parentheses around the whole expression, to save the result in sub group 1. Which you can then use in the replacement text.

     

    Edit: In short, replace the first caret (^) with an opening parenthesis, and the "\\z" with a closing parenthesis, and you're set.

  13. This is the Regular Expression I'm using for URIs, should be good for your purposes too:

    $RegExp = '#^(??:(?:f|ht)tps?|dchub)://)?((?:[\\w\\pL-]+\\.)+[a-z\\pL]{2,5})((?:/[\\w\\%-]*)+(??:\\.\\w{1,6})?(\\?(?:[\\w-]+=[\\w-]+)(?:&[\\w-]+(?:=[\\w-]+)?)*&?)?)?)?\\z#ui';

     

    May be that you can use the filter_var () functionality for this too, but no guarantees there. Worth checking out at least.

     

    That doesn't seem to match replace the plain text links as links. And I won't lie, I don't follow half of that!

     

    If I just wanted to rtrim the reference how can I do that? Is that possible to do?

  14. Hi Guys

     

    I'm retrieving a twitter feed as json but I have a slight issue.

     

    The feed outputs as text and so links in tweets come through as plain text, e.g.:

     

    More Tweets to discover... in the Discover tab on http://t.co/coKFdEQL. http://t.co/6OfRxQeW

     

    I've used preg_replace to reform the links into html links using the following code:

     

    $twitterFeed = file_get_contents('https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitter&count=4');
    $feedArray = json_decode($twitterFeed, true);
    
    //Pattern to correct date format
    $pattern = '/\+[0-9\s\b]+$/';
    $replacement = '';
    
    //$linkPattern = '/(http:\/\/[^\s]+)(?!\.)$/'; // This was my shot at forward reference
    
    // Pattern to match links
    $linkPattern = '/(http:\/\/[^\s]+)/';
    $linkReplace = "<a href=\"$1\">$1</a>"; // Replacement pattern to create a link
    
    foreach($feedArray as $k=>$v){
    
    $date = preg_replace($pattern, $replacement, $v['created_at']);
    $text = preg_replace($linkPattern, $linkReplace , $v['text']);
    
    echo $date . "<br/>" . $text."<br/><br/>";
    }
    

     

    The problem is that the linkPattern also captures the trailing full stop at the end of the sentence (seen in example above). So the resultant link ends up as a 404 because that full stop shouldn't be part of the link.

     

    Therefore can anyone suggest either:

     

    1) how the linkPattern can be adjusted so that it doesn't capture the trailing full stop

    2) how I can rtrim the capture reference if it's a full stop

     

    Or do I just need to do another preg_replace? :)

     

    Thanks!

  15. Hi

     

    Yes there are queries that aren;t even used on every page. It's clearly some sort of 'catch all' solution that doesn't have much regard for efficiency. I think I have my work cut out for me...there is a LOT to fix.

     

    This is going to be a far bigger performance issue than any mysql/mysqli/pconnect issue. Why are there so many calls executed every time? Is this something that should be joining across tables and combining results? Are there queries in there that don't really need to pull from the db with every page load and could be cached?

  16. Are you sure the persistent connection is actually 'working' in your case.

     

    Unless php is running as a server module on a multiprocess/multithreaded web server, all you end up with is a regular connection anyway.

     

    Not entirely sure about this as I have only just taken over from the last person. It's definitely the only connection being made but whether it's being utilised properly is another matter.

     

     

    here is your answer @ OP

     

     

    Mysql_pconnect will also open a new connection when a PHP page is called up (at any rate, it will the first time after a server reboot), but it will NOT close the connection at the end of the request - instead, it will save it in a connection pool so that a subsequent request can continue to use the same connection. It's intended for pages that do have a heavy usage - where the resources burn up by opening and closing connections every time might have a severe effect on performance. If your local supermarket had a door that was opened each time someone went in and out, there would be a lot of needless opening and closing going on - better to leave it open and let a whole lot of people in and out at the same time.

     

     

     

    Mysql_connect opens a new connection each time a PHP page is called up, and closes the connection down again at the end of the request. It's ideal for pages that don't have a heavy usage - doesn't need tuning, is straightforward internally. If you compare MySQL to a shop, this is the connection that you would use for a small shop where the door is opened each time a new customer wishes to enter.

     

    So the upshot from that would suggest that it's the way to go - given the site volume.

  17. Thanks for your reply Kevin

     

    Sorry I got the site visitors bit wrong - it's 700-800,000 per month - brain was elsewhere as i was writing :/ .

     

    I've never really seen mysql_pconect before - hence why I felt the need to get a second opinion. Do you think with those kind of visitor figures that mysql_pconnect is worth using? Or should I really just drop mysql for mysqli going forward?

     

    And the multiple query/fetch statements - where most of them aren't even used on every page - seemed plain wrong too.

     

     

     

     

    That sounds pretty bad. AFAIK, query results aren't cached with a persistent connection. I also wouldn't think that the overhead for opening/closing connections would be bad enough to necessitate a persistent connection, either. I mean, 700-800 hits a week is ~100 hits a day, or just over 4 hits an hour (4.1blahblahblah).

     

    On the surface, it sounds like a bad approach, but without being able to see the actual code, it's hard to say with 100% certainty. That said, the code should at least be modernized to use either MySQLi or PDO. The classic mysql_* functions aren't recommended any longer. There are better/safer way to handle the db.

  18. Sorry I realise this is all a bit abstract.

     

    I had hoped it would be a known issue with a known solution. The problem is even if I did re-detect the element's position, and reset it, the actual scroll event simply doesnt work when you click back.

     

    This is a toughy :/ as even the simple jquery alert in my example didn't work.

     

    Do you think I'd have more luck with straight javascript? Would an onload function get preserved perhaps? I realise the ready event is similar.

     

    hmmm

  19. Hi Guys

     

    I have recently taken up a new job. I am noticing a lot of bad practices, at least that's how they occur to me, and i was hoping to get your opinion on the following:

    1. Is it worth using mysql_pconnect ? I know php.net doesnt advise using it. The site gets a lot of visitors - typically around 700-800 hits a week - so would this justify using mysql_pconnect? And should you therefore use it on sites where you get a lot of traffic to reduce overhead? Or is it just pointless and would it be ok ot just use mysqli connect?
       
    2. A lot of the code is very procedural. One of the include files connects to the database using the method above and then there are mutliple lines lines of mysqli_query, mysql_fetch_assoc (30 plus lines of this). But none of these are surrounded by any logic so it would appear that everytime the include is called all of these statements are executed and all result sets retrieved. Would I be correct in thinking this is a tragically bad approach? OR is this something that works ok because they'ved used mysql_pconnect?

     

    Thanks...

     

    drongo

  20. Hi Guys

     

    I wonder if someone can help.

     

    Essentially it's a jquery script that makes a scrolling div track the page. So when you scroll down the page the div follows you. That works fine.

     

    The issue is that if a user clicks back, or forward on the iPad the jquery seems to simply fail and the scroll event stops working.

     

    I tried to strip the page down to test this with just a straight alert as follows:

     

    $(document).ready(function(){
    alert(1);
    });
    

     

    This code fires fine on page load and alerts 1, but if I then navigate away, and then click back, the alert doesnt fire.

     

    I am guessing this is a caching issue but I was wondering if anyone had encountered this problem and what the best solution is?

     

    Any advice welcome as iPad design is all very new to me.

     

    Drongo

  21. Hi Guys

     

    I hardly ever touch mod rewrite so I am stuck on something very simple.

     

    I am using a htaccess file and mod rewrite so that if someone targets a particular url (which is acutally a directory) they will be served a specific file in the directory but the new url will have a query string defining where they came from.

     

    So can anyone tell me why this doesn't work please?

     

    RewriteEngine On
    RewriteRule /tester http://localhost/HTACCESS/tester/tester.php?source=google
    

     

    As i said, the goal is if someone hits up my site on the directory '/tester' I want them to be servered a specific file in that directory - i.e. tester.php with a query string.

     

    What am i doing wrong? :(

     

    Oh and incidentally when i say it 'doesn't work' specifically I am just getting the directory listing for the 'tester' directory.

  22. Hi Guys

     

    I hope someone can help with this as I have been banging my head against the wall for three hours and nothing is working :/

     

    Here's what I am trying to do. I have a div that moves with the scroll bar but I want to constrain it to certain dimensions so it can't overlap the footer or header. This semi works but...

     

    There are two issues:

     

    1) If I scroll down to the bottom abruptly then the scrolling div simply zooms to the bottom and seems to completely bypass the evaluation of it's position that happens in:

     

    	
    if(elementOffset.top > maxScroll){
    scrollTopVar = maxScroll -1; //set to -1 to stop this evaluating to true on next scroll
    }
    

     

    2) Then when i do scroll down slowly, and the evaluation works, the scrolling div simply gets stuck in the position set in the code above - even though it shouldn't evaluate to true because it's actually one less than the max scroll allowed.

     

    Anyway here is the simplified code and I am sure someone better at jquery will instantly point out how easy this can be...

     

    
    
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    
    <title>Slide Div</title>
    
    <script type="text/javascript" src="jquery1.8.js"></script>
    
    
    <script>
    
                    $(document).ready(function(){
    
                                   
    
                                    var windowHeight = $(window).height();
                                    var docHeight = $(document).height();                               
    
                                    var headHeight = 85; //px value for header height - this will be dynamic
                                    var footHeight = 400; //px value for footer height - this will be dynamic
                                    var currentPos = 30;  // This is just a padding value used in the animation so animated div has breathing space from window top
                                    
                                                              
    
                                    var elementHeight = $('#scrollingDiv').height();  //Dynamically get height of scrolling div
                                    var maxScroll = docHeight - (80 + 400 + elementHeight); //sets max allowed scrolling limit.
    							var scrollingDiv = $("#scrollingDiv");	 // selector for scrolling div
                                   // alert(maxScroll);
    
    
    							$(window).scroll(function () { 
                                              
    
    								var scrollTopVar = $(window).scrollTop(); 			// defines scrolled distance -i.e. whats slipped under top nav window
    								var elementOffset = $('#scrollingDiv').offset(); 	//defines the distance to the top of the document from the scrolling element top
    
    								// First check to see if scroll bar is at top. 
    								if(scrollTopVar == 0){
    
    										currentPos = 0;
    								}									
    								else{									
    									currentPos = 30;
    								}
    
    
    								if(elementOffset.top > maxScroll){
    
    									scrollTopVar = maxScroll -1; //set to -1 to stop this evaluating to true on next scroll
    
    								}
    
    								if(elementOffset.top < maxScroll){
    
    									scrollTopVar = $(window).scrollTop(); 
    
    								}
    
    								// Then based on the evaluation above animate the div
    								scrollingDiv.stop(true).animate({"marginTop": (scrollTopVar + currentPos) + "px"}, "slow" ); 
                                           
                                    });
    
                     
    });
    
    </script>
    
    
    
    <style type="text/css">
    
    #header {width: 100%; height: 80px; border: 2px dashed red;}
    
    #scrollingDiv {width: 300px; min-height: 300px; border: 2px dashed #000; position: absolute; z-index: 100; left: 0px; top: 90px;}
    
    #content {height: 1200px; width: 100%;}
    
    #footer {height: 400px; width: 100%; border: 2px dashed green;}
    
    </style>
    
    </head>
    <body>
    
    <div id="header"></div>
    
    <div id="scrollingDiv">
    <h3>I AM THE SLIDING DIV ME</h3>
    </div>
    
    
    <div  id="content"></div>
    <div id="footer"></div>
    
    </body>
    </html>
    
    

     

×
×
  • 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.