Opensource, CMS, PHP, MySql, Drupal, Frameworks
Showing posts with label drupal jerry. Show all posts
Showing posts with label drupal jerry. Show all posts

Tuesday, May 28, 2013

Drupal - Own Administration Section

demo.module 

function demo_menu(){
    $items['admin/config/demo'] = array(
        'title' => 'Node demo',
        'description' => 'Adjust node demo options',
        'position' => 'right',
        'weight'=> -5,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('administer site configuration'),
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system'),
    );

    $items['admin/config/demo/settings'] = array(
        'title' => 'demo Settings',
        'description' => 'Change how demo behave',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('demo_admin_settings'),
        'access arguments' => array('administer site configuration'),
        'type' => MENU_NORMAL_ITEM,
        'file' => 'demo_posts.inc'
    );

    return $items;
}


demo_posts.inc

function demo_admin_settings($form, &$form_state){
    $types = node_type_get_types();
    foreach($types as $node_type) {
        $options[$node_type->type] = $node_type->name;
    }
    $form['demo_node_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Users may demo these content types'),
        '#options' => $options,
        '#default_value' => variable_get('demo_node_types', array('page')),
        '#description' => t('A text field will be available on these content types
        to make user-specific notes.'),
    );
   
    $form['#submit'][] = 'demo_admin_settings_submit';
    return system_settings_form($form);
}


Output:

Wednesday, February 23, 2011

drupal with jquery

Drupal.jsEnabled
This variable indicates whether or not the browser will support drupal.js and jquery.js. Returns true / false.


Drupal.attachBehaviors()
The Drupal Behaviors feature provides a standard method for attaching some particular information (called a behavior) to zero or more elements on a page.


Drupal.checkPlain()
It allow us to display HTML tags in browser.
example: 
myString = "Add a line break using the <br/> tag.";
escapedString = Drupal.checkPlain(myString);
output: Add a line break using the &lt;br/&gt; tag.

Drupal.parseJson()
This function was intended to be used for parsing AJAX data that was returned from the server in the JSON (JavaScript Object Notation) format. JSON data looks like JavaScript.
Here's an example describing a person's name:
jsonString = "{'first': 'Merriet', 'last': 'Jerry'}";
name = Drupal.parseJson(jsonString);
name.first
Output: Merriet
The string is parsed and converted to an object. We can then use that object directly in JavaScript.

Drupal.encodeURIComponent()
It correctly converts other characters while preserving the slashes.
myString = 'node/1/calc%';
Drupal.encodeURIComponent(myString);
Output: node/1/calc%25

Drupal.getSelection()
This tool is used to find out what portion of a text area (<textarea></textarea>) is selected.
For example, when you select a section of text with your mouse, this function can be used to find out the starting and ending locations of the selection.
The Drupal.getSelection() function returns an object with two attributes: start and end. These two properties are integers which represent the beginning and ending of the selection.

Drupal.t()
This function's job is to take a string and perform any translation actions on it.
var params = {
     "@siteName": "Example.Com",
     "!url": "http://example.com/"
};
var txt = Drupal.t("The URL for @siteName is !url.", params);


Drupal.formatPlural()
for (i = 0; i < 6; ++i) {
     alert( Drupal.formatPlural(i, "Johnny has 1 apple.", "Johnny has @count apples."));
}
This function takes these arguments:
  • A number (If it is 1, then the singular will be used, otherwise the plural form will be used.)
  • A singular string (in English).
  • A plural string (in English)

Drupal 7 Marketing Video




append() and appendTo() jQuery methods


An easily overlooked difference between append() and appendTo() is in the return value; both return jQuery objects. But where append() returns a jQuery object wrapping the thing(s) that have been appended to, the appendTo() call returns the elements that were appended.


//Create our content    
var appendHTML = "<p>I'm going to be added to the DOM</p>";


//Select our element, then add the html     
$("#container").append(appendHTML);


//Create our content, then select the element to append to
$(appendHTML).appentTo("#container");

Wednesday, February 16, 2011

Rotate content using jquery

Create the sticky_rotate.js


var StickyRotate = StickyRotate || {};
StickyRotate.init = function() {
var stickies = $(".sticky");
// If we don't have enough, stop immediately.
if (stickies.size() <= 1 || $('#node-form').size() > 0) {
return;
}
var highest = 100;
stickies.each(function () {
var stickyHeight = $(this).height();
if(stickyHeight > highest) {
highest = stickyHeight;
}
});
stickies.hide().css('height', highest + 'px');
StickyRotate.counter = 0;
StickyRotate.stickies = stickies;
stickies.eq(0).fadeIn('slow');
setInterval(StickyRotate.periodicRefresh, 7000);
};


StickyRotate.periodicRefresh = function () {
var stickies = StickyRotate.stickies;
var count = StickyRotate.counter;
var lastSticky = stickies.size() - 1;
var newcount;
if (count == lastSticky) {
newcount = StickyRotate.counter = 0;
}
else {
newcount = StickyRotate.counter = count + 1;
}
stickies.eq(count).fadeOut('slow', function () {
stickies.eq(newcount).fadeIn('slow');
});
};


Call the script by using 
$(document).ready(StickyRotate.init);


Ref book: Drupal 6 JavaScript and jQuery 

Tuesday, February 15, 2011

filters and input formats in drupal

Input formats are made up of a collection of filters. Shown in this figure are Drupal’s three default input formats. The direction of execution is shown by arrows.




To view a list of installed filters, either configure an existing input format or create a new one at Administrator >> Site Cofiguration >> Input formats 


Life cycle of text-filtering system






Ref book: Pro Drupal Development