Category Archives: jQuery

How-to for jQuery

Setting Up Eclipse PDT with UniServer for PHP Development (Part 1 of 2)

General Observations

Not the most convenient or intuitive IDE in the world, Eclipse is still a convenient IDE to use if you are not into spending big money on other developers … but, would like some very useful tools for development. If set up correctly, Eclipse PDT can help develop PHP projects with very useful debug options.

Some of the problems with Eclipse PDT include:

  • Setup can be a pain, it is definitely not load and go
  • Extra effort my be needed if you are not using Zend Server
  • You define your projects, but, deleting projects is a nuisance to do

I should mention, I am not an Eclipse expert. Definitely, it was a massive effort to hunt and peck my way through the installation. This article is to help me remember the process the next time I need to go through the process. It has a bit of rambling side information for those of you that find this articles and are curious why I have elected to do some of the setup that I do to use Eclipse. I hope it helps you too.

Preparation to use Eclipse PDT

To use Eclipse PDT, you must have the ability to run PHP. This implies the availability of a Server environment. Preparation suggests you install an AMP environment. In the case of this article, I have a WAMP environment.

I am developing on a WAMP environment; Windows, Apache, MySql & PHP. To maintain the database, I like using phpMyAdmin. To meet my needs for Apache and mySQL, I have tried using Zend Server.

Zend Server is an interesting, having lots of bells and whistles, but, I find that it is a pain to install phpMyAdmin on Zend Server hosted on Windows. Zend Server has a “simple” button press “deployment” of phpMyAdmin on their Zend Server, but, it fails in Windows. Notes around the internet indicate it works in Unix and Linux but, phpMyAdmin does not deploy conveniently on Windows at this time … true.

Even more inconvenient, uninstall of Zend Server does not do a complete uninstall. Zend Server installs IBM DB2 Server, but, does not remove it in the uninstall. This incomplete uninstall leaves the IBM DB server blocking access to port 3306 for other WAMP package installs. If you want to use port 3306, for the database servers with some other WAMP package like Uniserver, Wampserver, UmAmp … you will need to be aware and uninstall the DB2 server separately. Failure to uninstall IBM DB2 results in the failure of other WAMP packages to install completely. In the future, I may try Zend Server again using a Linux environment, but, not on Windows … until they solve their Windows compatibility problem with phpMyAdmin.

On Windows, I find the Uniform Server (UniServer) extremely convenient to install. I have used UniServer for about 10 years and never have had problems with Uniserver. The installation is quick, simple, and always works. UniServer includes mySQL, PHP and phpMyAdmin and meets my development needs nicely. Load and go in a Windows development environment.

If you are looking to use Eclipse, I assume you have an AMP package installed. If you have a AMP package installed, you can skip to Installing Eclipse PDT. If you are using Windows and need a WAMP package, the following two short sections will help.

Find Uniform Server

Uniform Server can be found at http://www.uniformserver.com/. Go on over to the UniServer site and click Download to retrieve the latest version of UniServer.

Installation of UniServer

To install UniServer:

  • Choose a where you would like to install UniServer. Some would choose the “Windows File” directory, but, I prefer to place it elsewhere. Your development files will be placed in a subdirectory below this and I do not like my development files stored below the Windows/Program Files subdirectory.
  • run the unZip for the uniserver package into the chosen . A will be created, but, standard Windows install with registry is not used by the UniServer package. (The name of the server_subdirectory changes with version, so I will call that )
  • Create a shortcut on your desktop to /UniController.exe. This will be your access to the UniServer control panel.

You are now ready to move on to the hard part … installing and configuring Eclipse PDT.

Head on over to the next article to find details of the Eclipse PDT installation and configuration.

Drupal 7; How to assign custom CSS and JS by node

If you need to have custom CSS or JS for a node, it is easy to set up.   This can be setup via the template.php file.   To customize available CSS or JS via template.php, modify the THEME_preprocess_node.  For example, if you have a special node type called “directory” in a theme called “boulder,” add the following code to your boulder_preprocess_node function.



  function boulder_preprocess_node(&$variables) {
    if ($variables['view_mode'] == 'full') {
      $node =& $variables['node'];
      if ($node->type == 'directory') {
        $path = drupal_get_path('theme', 'boulder');
        drupal_add_css($path . '/CSS/directory.css');
        drupal_add_js($path . '/js/directory.js', 
            array('type' => 'file', 'scope' => 'header'));
      }
    }
  }

I love this. It’s quick, easy and very useful.

Having a Problem With SilverStripe FlexSlider? Fix It!

SilverStripe

Note: You may have problems with your first installation of SilverStripe FlexSlider, there is a trick.

Have faith, the SilverStripe FlexSlider does work. The installation appears straight forward. Loading of images can be a bit clumsy, but is functional. The use of shortcode is easy, and insertion into the template files is simple. The details on loading and use of SilverStripe’s implementation of FlexSlider is at http://www.netefx.de/Silverstripe-flexslider.php.

However, there are two problem with the installation.

  1. There is a problem with one step in the instructions

    Install flexslider as explained on the page referenced above, but:

    • When the instructions tell you to add
      Object::add_extension(‘Page’, ‘FlexSliderExtension’) ;
      to mysite/_config.php, stop,
    • Run dev/build?flush=1 first,
    • Then go to mysite/_config.php and insert the line, and
    • Follow that with another dev/build?flush=1.

    If you install the add_extension() before building the database,
    you will get an installation error.

  2. Line 219 of flexslider/code/FlexSlider.php must be commented out

    The line “Requirements::javascript(THIRDPARTY_DIR . ‘/jquery/jquery.js’);” at line 219 of flexslider/code/FlexSlider.php must be commented out. This line loads jQuery.js, but, the default install of SilverStripe loads jquery.js. If jquery.js is loaded twice, jquery code becomes confused and jquery calls, such as calls to $FlexSlider() become confused and fail.

If you use the above adjustments to the documented install procedures on http://www.netefx.de/Silverstripe-flexslider.php, you should be running smoothly in no time.

 

 

HTML5 Placeholder

The new HTML5 attribute placeholder for the input tag could be wonderful if implemented correctly. Unfortunately, at the moment we have a problem on Firefox. When using placeholder on firefox, when focusing on the input field, the placeholder does not vanish. This gives the user the erroneous feel that the text is really there and attempts to “erase” it doesn’t work … it is in the background. The appearance is a bit confusing.

The following code can be used to create the “placeholder” behavior. Place a default value in an attribute called data-default, and that value will act as the placeholder.



    <script type="text/javascript">
      $(function() {
        $('input[type="text"]').focus(function() {
            if (!$(this).attr('data-default')) $(this).attr('data-default', $(this).val());
            if ($(this).val()==$(this).attr('data-default')) $(this).val('');
        });
        $('input[type="text"]').blur(function() {
            if ($(this).val()=='') $(this).val($(this).attr('data-default')); 
        });
        $( 'input[type="text"]' ).each(function( index ) {
            if ($(this).val()=='') {
			    $(this).val($(this).attr('data-default'));
			} 
        });
      }) ;
	</script>

jQuery is used, rather than simple javascript because the javascript getAttribute(‘data-function’) may not work correctly and new HTML5 data() may not work on all browsers. It is currently safest to use jQuery until HTML5 is a bit more mature.

 

Create a Google Map With Marker(s)

You may be building a website that has plugins or modules to deal with google maps, but, you may be working on a site that does not have modules or plugins available. In that event, you can use the following code to create a function that allow you to enter either longitude/latitude or address for mapping.

The following code clip will allow you to display a map with markers and associated pop-up bubble. You can add as many markers as you would like, with an equal number of pop-up information bubbles. You can place the markers by specifying an address, or a longitude and latitude.


<style type="text/css">
  .entry-content { max-width:none ; }
   #bubble { height: 50px ; -moz-border-radius: 10px; 
      -webkit-border-radius: 10px; -khtml-border-radius: 10px; 
      border-radius: 10px;  }
</style>
<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
  function map_initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      var myOptions = {
          zoom: 12,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.SATELLITE
      }
      d_map = new google.maps.Map(document.getElementById("map-me"), 
              myOptions);
      mapIt(999, 999, "Crescent City, CA", 
          "http://www.advancedwebhelp.com/blog/wp-content/uploads/2013/11/marker.png",
          "label to see on hover of marker", 
          "<'div id='bubble'>Say something in the pop-up bubble</div>", 
          "http://www.mydomain.com/link") ; 
  }
  function mapIt(lat, lng, address, image, label, bubble, alink) {
      if (lat != 999) {
          var myLatLong = new google.maps.LatLng(lat,lng) ;
          d_map.setCenter(myLatLong);
          var link = alink ;
          var contentString = '<div class="marker_content">'+ 
              '<a href="' + link + '">'  +  bubble +   
              '</a></div>';
          var infowindow = new google.maps.InfoWindow({
              content: contentString
          });
          var marker = new google.maps.Marker({
              map: d_map,
              icon: image,
              title: label,
              position: myLatLong
          });
          google.maps.event.addListener(marker, 'click', function() {
             infowindow.open(d_map,marker);
          });
      } else {
          geocoder.geocode( { 'address': address}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
              d_map.setCenter(results[0].geometry.location);
                  var link = alink ;
                  var contentString = '<div class="marker_content">' + 
                     '<a href="' + link + '">' + bubble + '</a></div><p>';
                  var infowindow = new google.maps.InfoWindow({
                      content: contentString
                  });
              var marker = new google.maps.Marker({
                      map: d_map,
                      icon: image,
                      title: label,
                      position: results[0].geometry.location
                  });
              google.maps.event.addListener(marker, 'click', function() {
                      infowindow.open(d_map,marker);
                 });
              } else { alert("Geocode was not successful 
                      for the following reason: " + status); }
          });
      }
  }
  jQuery(function() {
      map_initialize() ;        
 }) ;
</script>

Sample

If you see this, JavaScript not supported.

I should mention several things about the above code:

  1. In the declaration of the div for map-me, you can change the width and height of the map.
  2. In the declaration of var myLatLng in map_initialize(), you can change the longitude and latitude that will be used for the center of the map
  3. In the declaration of myOptions in map_initialize(), you can change the type of map, and zoom to meet your needs
  4. You may make multiple calls to mapIt() to insert markers on the map.
  5. If you do not use the latitude and longitude in mapIt, use values 999,999.
  6. In mapIt, you include the flag for the marker, so, you can make every marker can look different.
  7. In mapIt, you can pass the content used in the bubble for the marker … it can include HTML.