GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, February 22, 2011

Drupal Page Callback

If you want a link to direct for a page, do it with that menu callback hook function. You access the page without no menu navigation link.

<?php

/**
 * Implements hook_menu()
 */
 
function luna_menu(){

    $items = array();
   
    $items['luna/main'] = array(
        'title' => 'Main Menu',
        'page callback' => 'description',
        'access callback' => TRUE,
    );
   
    $items['luna/po/%'] = array(       
        'page callback' => 'four',
        'page arguments' => array(2), // start from 0/1/2/3/etc
        'type' => MENU_CALLBACK,      // no link in nav menu
        'access arguments' => array('access arguments page'),
    );
   
    return $items;
}

function description(){
    return 'Get the other for this one: <a href="po/4">About Us</a>';
}

function four(){
    return 'Hello. We are currently active in the what we do for the next year. We build a custom enterprise software for oil company.';
}
Share/Bookmark

Monday, February 21, 2011

jQuery Plugin Authoring

In this moment, the code below show to you on how to build your own plugin that namespacing. Without namespacing, the code is like below:

<script src="jquery-1.5.js"></script>

<div id="satu">
Indonesia
</div>

<script>
function($){
     $.fn.fore = function(options){
         var settings = {
             'color': 'blue'
         };
         if(options){
             $.extend(settings, options);
         }
         $(this).css('color',settings.color);
         return $(this);
     };

     $.fn.back = function(options){
         var settings = {
             'color': 'lime'
         };
         $(options){
             $.extend(settings, options);
         }
         $(this).css('background',settings.color);
         return $(this);
    };
})(jQuery);

$('#satu').fore().back();

</script>

But with the namespace, the code will be like this:
<script src="jquery-1.5.js"></script>

<div id="satu">
Indonesia
</div>

<script>
function($){
    var methods = {
        // this is the same function in the above 
        // this is the first function in the above           
        'fore': function(options){
            var settings = {
                'color': 'blue'
            };
            if(options){
                $.extend(settings, options);
            }
            $(this).css('color',settings.color);
            return $(this);
        },

        // this is the second function of the above
        'back': function(options){
            var settings = {
                'color': 'lime'
            };
            if (options){
                $.extend(settings, options);
            }
            $(this).css('background',settings.color);
                return $(this);
            }
        };

// this is the main function of namespacing
$.fn.coloring = function(method){
    if ( methods[method] ) {
        return methods[ method ].apply( this, 
                  Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
        return methods.init.apply( this, arguments );
    } else {
        $.error( 'Method ' +  method + ' does not exist on ' 
                 + ' jQuery.tooltip' );
    }   

}
 
})(jQuery);

$('#satu').coloring('fore').coloring('back');

</script>
Share/Bookmark

Sunday, February 20, 2011

Drupal Database Access

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [name] => lady gaga
            [age] => 25
            [city] => new york
        )

    [1] => stdClass Object
        (
            [id] => 2
            [name] => luna maya
            [age] => 27
            [city] => denpasar
        )

)
The above is the result of this function
function get_data(){
 $output = '';
 $select = db_select('data_siswa','c')->fields('c')->execute()->fetchAll(); 
 return print_r($select); 
}
 
To get the data as a table, use this one:
function introo(){
 $output = '<table>';
 $output .= '<tr><th>Name</th><th>Age</th><th>City</th></tr>';
 
 $select = db_select('data_siswa','c')->fields('c')
                                    ->execute()->fetchAll();
      foreach($select as $key){
  $output .= '<tr><td>'.$key->name ."</td><td>";
                $output .=  $key->age. "</td><td>". $key->city ."</td></tr>";
 }
 
 $output .= "</table>";
 
 return $output; 
} 

Share/Bookmark

Saturday, February 19, 2011

Plugin Authoring

<script src="jquery-1.5.js"></script>

<h1 id="satu">We hope we can do more!</h1>

<script>

(function($){

    // coloring the text
     $.fn.coloring = function(options){

          var settings = {
               'color' : 'blue'
          };

          if(options){
               $.extend(settings, options);
          }

          $(this).css('color',settings.color);

          return $(this);
     }


      // backgrouning the text
     $.fn.backgrouning = function(options){

          var settings = {
               'background': '#fc5',
          };

          if(options){
               $.extend(settings, options);
          }

          $(this).css('background-color', settings.background);

          return $(this);
     };


    // sizing the text
     $.fn.sizing = function(options){

          var settings = {
               'size': 30,
          };

          if(options){
               $.extend(settings, options);
          }

          $(this).css('font-size', settings.size);

          return $(this);
     };

})(jQuery);

$('#satu').coloring().backgrouning().sizing()

</script>

Share/Bookmark

Friday, February 18, 2011

Message In Drupal

It's easy to make message in drupal. If your form function is data_form($form, &$form_state), so your submit function is data_form_submit($form, &$form_state). What's the point? The point is that you add "_submit" on the for function for your submit function. Look this  code

// form function
function data_form( $form, &$form_state){
    // implement codes
}

// form submit function
function data_form_submit( $form, &$form_state){
    drupal_set_message( t('Your data has been saved successfully') );
}
Share/Bookmark

Thursday, February 17, 2011

Font End Design

<div id="satu">
<h2>Technical Specification</h2>
<div id="list">

<div class="item">
<h3>The Current Priorities</h3>
<ul><li>Skripsi</li>
<li>Web Portfolio</li>
</ul>
</div>

<div class="item">
<h3>The Next Priorities</h3>
<ul><li>Jobs in hacker centric place</li>
<li>Get to the next stage of hacking skills</li>
<li>Get the certificates of Hacking</li>
</ul>
</div>

<div class="item">
<h3>In Americas</h3>
<ul><li>Jobs in NVidia</li>
<li>Building part-time technology business</li>
</ul>
</div>

<div class="item">
<h3>The Next Ahead</h3>
<ul><li>Big Business</li>
<li>Nta Fund</li>
</ul>
</div>


<style>
html, body, div, h1, h2, h3 { margin: 0px; }
ol, ul { list-style: square; padding: 0 0 0 15px; }
html { background: #eee; color: #333;}
#satu { margin: 20px; padding: 20px; -moz-box-shadow: 0 0 1px #aaa; background: white; -moz-border-radius: 4px; font: 12px sans-serif; }

#satu h2 { border-bottom: 1px solid #aaa; padding: 0 0 10 0px; margin: 0 0 20px; }
.item { float: left; width: 50%; margin: 0 0 15px; }
.item li { margin: 0 0 5px; }

</style>

<div style="clear: both; "></div>
</div>
</div>
Share/Bookmark

Extending jQuery With Options

<script src="jquery.js"></script>

<div id="one">Winning Eleven</div>
<div id="two">Winning Eleven</div>
<div id="three">Winning Eleven</div>

<script>

(function($){
    $.fn.bigBlue = function(options){
        // set the kinds of options
        var settings = {
            'color' : 'blue',
            'size' : '50'
        }
        // use the template
        if(options){
            $.extend(settings, options);
        }
        // code goes here
        $(this).css({'color':settings.color,
                     'font-size':   settings.size});

        return $(this);
    };
})(jQuery);

$('#one').bigBlue();    // use default options
$('#two').bigBlue({'color':'lime'});
$('#three').bigBlue({'color':'pink','size':100});

</script>

Share/Bookmark