Jump to content

MrFish

Members
  • Posts

    492
  • Joined

  • Last visited

Everything posted by MrFish

  1. Oh sorry I should clarify. When I said "limit" that was a packet limit. You could also say a limit I'm putting on my script (personally). I don't want to send multiple packets for one set of information. I want to fill every packet to it's max size (or really close) before I send it to reduce the time it takes overall (since http has that lengthy handshake process).
  2. I'm trying to compress data as much as possible before sending data in Javascript. I'd like to send a CSV list of numbers and possibly a character or two thrown in there and get as many in as possible before reaching the 1,500 byte limit (1 HTTP packet-- so the internet says). I'm really not sure where to look or if it's possible. I don't need someone to do it for me but I'm looking for at least a point in the right direction. Thanks in advance!
  3. I have to use google maps frequently so I made something simple to suit my purposes but it's a good base and should be easy to change styles for whatever you need. Thought I'd go ahead and post this. Enjoy! Sample Code: <?php // Irrelevant to GoogleJSMap $Community = new Controller("community", 1, null, true); // Supply API Key $Map = new GoogleJSMap("ABQIAAAAQbKvZ2Jzb7p-l2D0EJ2NhRQJg3pYlbY33RHuh3LyS3s0-mZYuRT0eR665Q5h9HAbVnVyM05l0GLp2Q"); // Irrelevant to GoogleJSMap $str = $Community->get("address") . "+" . $Community->get("city") . "+" . $Community->get("state") . "+" . $Community->get("zip"); // Address array has 4 possible assoc keys // // address - required // name - optional // text - optional // image - optional // // The name, text, and image produce something a bit ugly. Should be easy for // you to style if you need to. $address = array("address" => $str); // Add as many locations as you want. Code automatically centers over them $Map->addLocation($address); // Print JS echo $Map->getJS(); // Print map canvas. Width: 700px | Height: 525px echo $Map->getCanvas(700, 525); ?> Object Code: <?php//Written by Micah Williamson class GoogleJSMap{ private $key; private $canvasId; private $centerLat; private $centerLong; private $locations; function __construct($key) { $this->key = $key; $this->canvasId = md5(rand(0,999999999999999)); $this->centerLat = 0; $this->centerLong = 0; } //Modifiers function addLocation($arr) { $this->locations[] = $arr; } //Helpers function getCanvas($width, $height) { return "<div onload='window.initialize()' id='{$this->canvasId}' style='width:{$width}px; height:{$height}px;'></div>"; } function getJS() { $out = " <script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script> <script type='text/javascript'> function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng({$this->centerLat}, {$this->centerLong}); var myOptions = { zoom: 4, center: latlng, scrollwheel: false, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById(\"{$this->canvasId}\"), myOptions); contentString = 'test'; infowindow = new google.maps.InfoWindow ({ content: contentString }); bounds = new google.maps.LatLngBounds(); "; $i = 0; foreach($this->locations as $location) { $address = $location["address"]; $image = $location["image"]; $text = $location["text"]; $name = $location["name"]; $this->locations[$i]["id"] = $randId = md5(rand(0,999999999999999)); $i++; $out .= " var address = '$address'; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker ({ map: map, title: '$name', id: '$randId', position: results[0].geometry.location }); latLong = new google.maps.LatLng(results[0].geometry.location.Pa, results[0].geometry.location.Qa); bounds.extend(latLong); google.maps.event.addListener(marker, 'mouseover', function() { infowindow.content = document.getElementById(marker.id).innerHTML; infowindow.open(map,marker); }); } }); map.fitBounds(bounds); "; } $out .= " } // End initialize window.onload = function(){initialize();} </script>"; $out .= "<div style='display: none;'>"; foreach($this->locations as $location) { $address = $location["address"]; $image = $location["image"]; $text = $location["text"]; $name = $location["name"]; $randId = $location["id"]; if($image != null) $image = "<br/><br/><img style='max-width: 200px; max-height: 100px;' src='$image'/>"; if($text != null) $text = "<br/><br/>$text"; $out .= "<div id='$randId'> <b>$name</b><br/> Address: $address $image $text </div>"; } $out .= "</div>"; return $out; }}?>
  4. MrFish

    Php Eval Troubles

    I did end up doing that in the end but I thought it would be quicker for the script to use eval then do yet another str_replace.
  5. Thanks for the replies. I should have posted my solution sooner but here is what I found works- <form onsubmit="return validateForm(this);">...</form> It will run the function fully if you do something like this instead. Still not sure why the original didn't.
  6. MrFish

    Php Eval Troubles

    I'm trying to use php eval on this string but I can't get it to work. I'm trying to locate anything within (( ... )) in a string and replace it with (($data[' ... '])) but running eval on that only returns the same text. Here is my test code: $string = preg_replace_callback("/\(\(([^)]+)\)\)/", 'insertDummy', $string); echo $string; //TEST WORKS $test = "(({\$data['address']}))"; echo $test; eval("\$test = \"$test\";"); echo $test; //BACK TO CODE eval("\$string = \"$string\";"); echo $string; Here is the string before I run preg_replace_callback <div class="horizontal_results" id="horizontal_results"> <div class="horizontal_results_top"></div> <div class="horizontal_results_content"> <div class="horizontal_results_col01"> <img src="((photo))" alt="" width="150" height="113" class="left" style="margin-left: 5px;"> </div> <div class="horizontal_results_right"> <h4>((address))</h4> <div class="horizontal_results_col02"> <h5> [[<strong>Priced:</strong> ((price))<br>]] [[<strong>Beds:</strong> ((beds))]][[<strong> Baths:</strong> ((baths))]]<br> [[<strong>SQ FT:</strong> ((squareFeet))<br>]] [[<strong>Garages:</strong> ((garages))]] </h5> </div> <div class="horizontal_results_col03"> <h5> [[<strong>Status: </strong>((status))<br>]] [[<strong>Agent: </strong>((agentId))<br>]] [[<strong>PH: </strong>((phone))<br>]] [[<a href="mailto:((email))">Email Agent</a></h5>]] </div> </div><!-- end of horizontal_results_right --> </div> <!-- end horizontal_results_content --> <div id="horizontal_results_edge"><a href="living_invdetail.php?item=((id))">View Detail</a></div> </div> Here is the code for the first preg_replace_callback (insertDummy) function insertDummy($matches){ $clean = $matches[1]; return "(({\$data['" . $matches[1] . "']}))";} Here is the string after this preg_replace_callback is used <div class="horizontal_results" id="horizontal_results"> <div class="horizontal_results_top"></div> <div class="horizontal_results_content"> <div class="horizontal_results_col01"> <img src="(({$data['photo']}))" alt="" width="150" height="113" class="left" style="margin-left: 5px;"> </div> <div class="horizontal_results_right"> <h4>(({$data['address']}))</h4> <div class="horizontal_results_col02"> <h5> [[<strong>Priced:</strong> (({$data['price']}))<br>]] [[<strong>Beds:</strong> (({$data['beds']}))]][[<strong> Baths:</strong> (({$data['baths']}))]]<br> [[<strong>SQ FT:</strong> (({$data['squareFeet']}))<br>]] [[<strong>Garages:</strong> (({$data['garages']}))]] </h5> </div> <div class="horizontal_results_col03"> <h5> [[<strong>Status: </strong>(({$data['status']}))<br>]] [[<strong>Agent: </strong>(({$data['agentId']}))<br>]] [[<strong>PH: </strong>(({$data['phone']}))<br>]] [[<a href="mailto:(({$data['email']}))">Email Agent</a></h5>]] </div> </div><!-- end of horizontal_results_right --> </div> <!-- end horizontal_results_content --> <div id="horizontal_results_edge"><a href="living_invdetail.php?item=(({$data['id']}))">View Detail</a></div> </div> And after eval is used:(disregard double square brackets. they are for later use) <div class="horizontal_results" id="horizontal_results"> <div class="horizontal_results_top"></div> <div class="horizontal_results_content"> <div class="horizontal_results_col01"> <img src="(({$data['photo']}))" alt="" width="150" height="113" class="left" style="margin-left: 5px;"> </div> <div class="horizontal_results_right"> <h4>(({$data['address']}))</h4> <div class="horizontal_results_col02"> <h5> [[<strong>Priced:</strong> (({$data['price']}))<br>]] [[<strong>Beds:</strong> (({$data['beds']}))]][[<strong> Baths:</strong> (({$data['baths']}))]]<br> [[<strong>SQ FT:</strong> (({$data['squareFeet']}))<br>]] [[<strong>Garages:</strong> (({$data['garages']}))]] </h5> </div> <div class="horizontal_results_col03"> <h5> [[<strong>Status: </strong>(({$data['status']}))<br>]] [[<strong>Agent: </strong>(({$data['agentId']}))<br>]] [[<strong>PH: </strong>(({$data['phone']}))<br>]] [[<a href="mailto:(({$data['email']}))">Email Agent</a></h5>]] </div> </div><!-- end of horizontal_results_right --> </div> <!-- end horizontal_results_content --> <div id="horizontal_results_edge"><a href="living_invdetail.php?item=(({$data['id']}))">View Detail</a></div> </div> As you can see. Nothing changed. Here is what the test does: Insert: $test = "(({\$data['address']}))"; Before: (({$data['address']})) After: ((asdf))
  7. I'm trying to notify the user submiting a form if they didn't enter the passwords correctly. The trouble is that the onsubmit function only gets half way through (tracked by alerts) before it just submits anyway. frm = document.getElementById("registerForm"); frm.onsubmit = function(e) { e = e || window.event; elements = frm.elements; password1 = elements["password1"]; password2 = elements["password2"]; if(password1.value != password2.value) { alert("The Passwords Entered Did Not Match"); e.preventDefault(); } else return true; } It get's just after this line password1 = elements["password1"]; and submits the form without completing. What can I do to make it run all the way through?
  8. You don't need any java programming knowledge for this but it's written in java so I'll post it here.I have a 2 dimensional array of point objects. Each contains a row and column variable and a list of properties for that point. Points share property lists and can be grouped by their "PointPropertyList" id. So seen above is a group of points (green points surrounded by grey) surrounded by a second group (blue points). I want to draw a polygon around these points so I need to find the edges. I can easily find the edges by just checking to see if it has a neighboring point of the same group on each side. If it doesn't then it must be an edge.The issue I have is that after finding the edges and adding it to an array of other edge points- it is unordered. So I need to order the points so I can use Graphics2D to draw a polygon around them.tl;dr:Given an array of edge pointsHow can I determine the correct order of points from an unordered array of points?How can I determine if the shape is concave or convex? 0,0,0,0,0,0,0,0,0,00,1,1,0,0,0,0,0,0,00,0,1,1,0,0,0,0,0,00,0,1,1,0,0,0,0,0,00,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,0
  9. I think NetBeans is a popular one but I haven't tried it. Because it's very popular it should have a lot of support.
  10. Right I was making a joke. I knew there was a reason but I was stumped. I don't really believe in computer anomalies :)Thanks for the debugging advice.
  11. These properties will only work for webkit browsers (chrome and safari). If it's for ipad and ipad uses webkit then I guess that's not a problem. But just want to point that out first.CSS can only have single states and cannot be used for smooth transitioning from one property to another alone. You will need to use javascript to do that.
  12. Where is your script for the drop down. The probable cause is that you have a mouseover and mouseout event that shows and hides the drop down menu. So when you mouseout of the menu item the event triggers and hides the drop down menu. So you need to catch it by adding a mouseover event to the sub menu.
  13. Ah that makes so much sense! Thank you for your help justsomeguy. Now my faith in cause and effect is restored. I was beginning to think JS had supernatural properties. haha
  14. I typed <input type='text' onclick="alert()"/> in the live editor and got an alert when I clicked on the input.
  15. Well I was able to get it to work using onkeyup as an attribute.But the js still have a onclick event in the code (it just doesn't trigger). I don't need it at this point but you can look at it here- http://micahwilliamson.com/work/treatolife...b/?page=profileuser: testpass: test
  16. I've decided to use onkeyup inside the tag as an attribute. This works even if the original problem isn't fix.It's still a mystery but not necessary to solve at this point (so you can go for it but I don't want to waste your time). Would still be nice to know though.
  17. I'm actually using chrome. Changed it to myInput. Still not working :\
  18. EDIT: If you login it's in the far right tab of the profile pageYou can look at it here: http://micahwilliamson.com/work/treatolife...b/?page=profileUsername: testPassword: testThe entire JS that I'm using for this page is this- <script type='text/javascript'> $(document).ready(function() { input = document.getElementById("nameInput"); input.onclick = function() { alert(1); } //This one works fine $(".tab").click(function() { window.moveTabTo($(this)); }); window.moveTabTo = function(obj) { target = obj.attr('target'); html = $("#" + target).html(); $(".tab.active").removeClass("active"); obj.addClass("active"); $("#blackBox .inner").html(html); }; window.moveTabTo($(".tab:first")); off = $("#chatboxes").offset(); l = off.left; t = off.top; w = 45 $("#blueball").css("top", t-6).css("left", l+w+6); $("#chatboxes").click(function() { $(this).children("img").attr('src', 'images/chatboxes.png'); $("#blueball").css('visibility', 'hidden'); $.get("actions/tryread.php", function(d) { }); }); }); </script> This is not in the header.The form html is this- <form action='actions/trysendmessage.php' method='post'> <table id="messager"> <tr> <td>To:</td> <td> <input id="nameInput" type="text" name="to" style="width: 80%; background-color: #fff; color: #555; border-radius: 15px; -moz-border-radius: 15px;"/> </td> <td></td> </tr> <tr> <td>Message:</td> <td> <textarea name='body' style='width: 80%; background-color: #fff; color: #555; border-radius: 15px; -moz-border-radius: 15px; height: 150px;'></textarea> </td> <td> <img src='images/paperairplane.jpg'/> </td> </tr> </table> </form>
  19. There are no errors in the console. And when I alert the input variable before I try writing the function and it shows that the DOM is loaded.The input isn't dynamically generated so there is nothing stopping me from adding onkeypress="" in the tag itself so I think that's what I'll have to do. But this is very strange.
  20. I works fine in the console but it won't work when I have it on the page. That's the strange behavior
  21. input = document.getElementById("nameInput"); alert(input); input.onClick = function() { alert(1); } input.onclick = function() { alert(1); } input.click = function() { alert(1); } $("#nameInput").click(function() { alert(1); }); document.getElementById("nameInput").onclick = function(){alert(1);} //This one works fine $(".tab").click(function() { window.moveTabTo($(this)); }); I've tried all of the suggestions and the JQuery version. Right after there is a click event for something else and that works. If someone wants to see the page I can pm you a login and password because this is for a users profile.
  22. I need to write something for onkeypress but I'm using alert to test it because I noticed the onkeypress never shot off. Now no events will run for this input. There are some other functions in the $(document).ready and they all work fine. After typing in that line "document.getElementById("nameInput").onclick = function(){alert();}" in the console the onclick event works for the input. But for some reason it doesn't work when the page loads.
  23. I am scratching my head over this. It's very simple but I can't get an on event to work with an input. Am I missing something?html <input type="text" id="nameInput" name='to' style='width: 80%; background-color: #fff; color: #555; border-radius: 15px; -moz-border-radius: 15px;'> Js $(document).ready(function(){ input = document.getElementById("nameInput"); input.onclick = function() { alert(); }}); Nothing. If put this in: alert(input); right before I set the on function I get [Object HTMLInputElement].There are no errors in my web console. I can check the input variable and see that it is set as well as the function.Then I type in the terminal: document.getElementById("nameInput").onclick = function(){alert();} and it works...What am I missing? It's so simple but it's driving me crazy.
  24. I was able to get something from another forum on this that worked. postData = {};...postData[key] = value;...$.post(url, postData, function(){}); Though- thanks for your reply, thescientist. I will remember to try that if I need to construct a JSON object like this again.
  25. I don't know why I didn't think of this before but I could just parse the whole string server side.I'm still a bit curious how I would do it like I originally planned.
×
×
  • Create New...