January 29th, 2012 — 6:39am
Creating a node with PHP in Drupal 7 is easy. This can be used to insert one node from a custom form or to insert a batch of nodes from an array of data.
Just follow these instructions to populate a node with PHP.
// start with a blank object
$node = new stdClass();
$node->type = 'node-type';
// adds defaults for node type
node_object_prepare($node);
$node->title = 'Any title';
// set language to default 'und'
$node->language = LANGUAGE_NONE;
// sets node author (can use $node->name instead)
$node->uid = 1;
// set the body field
$node->body[$node->language][0]['value'] = 'text';
$node->body[$node->language][0]['format'] = 'filtered_html';
// most other fields can be added this way
$node->field_name[$node->language][0]['value'] = 'value';
// updates author and publish date
node_submit($node);
node_save($node);
1 comment » | Programming
August 18th, 2011 — 7:38am
Let’s say you have several select dropdowns on the same form. You want three different answers for the same question or a similar one. But you don’t want the user to select the same option more than once. This simple jQuery setup with help you out.
There are two parts to the code. One to find which option has been selected and disable it in the other options lists.
//this function determines which option has been selected and disables it in the other boxes
$('#select-group select').blur(function() {
$('#select-group option:selected').each(function() {
var v = $(this).val();
if (v != '') {
$(this).parents('.selector').siblings('.selector')
.find('option[value="'+v+'"]').attr('disabled','disabled');
}
});
});
And one to make sure the ones deselected are available again.
//re-enables those deselected
$('#select-group select').focus(function() {
$(this).find('option:selected').each(function() {
var v = $(this).val();
if (v != '') {
$(this).parents('.selector').siblings('.selector')
.find('option[value="'+v+'"]').removeAttr('disabled');
}
});
});
You can download the selection-removal to get all the code.
1 comment » | Programming
August 13th, 2011 — 10:07pm
One of the latest crazes in web design is the parallax effect, or a 3D effect created by layering. You can find a really amazing, complicated design at NikeBetterWorld. Recently I created the effect on a much simpler scale for a small wakeboarder’s website.
I used jQuery to get the job done. The function works as follows:
//spd tells the object how quickly to move with the window scroll. 1 is normal speed.
opts.spd = opts.spd || 1;
This is the function to calculate the new position for the object based on the position of the window scroll.
function calcMove() {
//get the scroll position from top, document height, window height, and object height
var offset = $(document).scrollTop();
var docSize = $(document).height();
var windowSize = $(window).height();
var boxSize = $(obj).height();
//calculate the percent down the document
var room = offset/(windowSize - docSize);
//calculate the how fast the object should move and where it should be in relation to actual position
var move = ((docSize * room) * opts.spd) + opts.startPos;
return move;
}
Then you need a bit of javascript to place the objects and give them speed.
//this sets the height of the document (how far the entire scroll will go)
$('div#node-1').parents('#content').height(16200);
//the top setting is where the object starts and the spd is how fast it moves
$('div#node-1, div#node-1-title').css('top',65).parallax({spd:.15});
The best bet to get this working the way you want is to start from the top and move down. Testing objects as you move down the page to get them just where you want.
Attached is the html file with the javascript you need to use this simple parallax function.
Parallax doc
5 comments » | Design, Programming
June 2nd, 2011 — 1:17pm
For the Nice to Speed You site I re-created the templates for the new designs. Again created with Jessica (www.interactivexperience.nl). This is a fast paced video dating site.
You can see the new design here: www.nicetospeedyou.com
Comments Off | Programming
May 2nd, 2011 — 1:08pm
Many moons ago I completely the layout for this site. Designs completed by Jessica www.interactivexperience.nl. It’s a simple site created with Drupal 6.
You can see the site here:
www.waterwoning-depionier.nl
Comments Off | Programming