Tag Archive for nested

Nested for loop

void setup() {
  size(400, 400);
  background(0);
  smooth();
  stroke(255, 50);
  //noStroke();
}

void draw() {
  
  for(int i = 0; i < width; i+=50) {
    
    for(int j = 0; j < height; j+=50) {
      fill(100, 0, 150, 100);
      ellipse(25 + i, 25 + j, 50, 50);
      fill(20, 100, 0, 50);
      rect(i, j, 50, 50);
      println("i = " + i + " j = " + j);
    }
    
  }
  
}

source

align nested div to base of parent div

div.parent {
position: relative;
}
div.nested {
position: absolute;
bottom: 0;
}

source

actionscript3 – targetting ‘root’ or ‘parent’ timelines

// send root timeline to play frame 3
MovieClip(root).gotoAndPlay(3);

// send root timeline to stop on frame "intro"
MovieClip(root).gotoAndStop("intro");

// send the current timeline's 'parent' to play frame 3
MovieClip(parent).gotoAndPlay(3);

// send the current timeline's 'parent' to stop on frame "intro"
MovieClip(parent).gotoAndStop("intro");

// when traversing a long list of nested 'parent' timelines, just string
// as many together as you need - separated by dots. for example...
MovieClip(parent.parent.parent).gotoAndPlay(3);

//or...
MovieClip(parent.parent.parent).gotoAndStop("intro");

source

JSS 0.1 – Nested CSS using Javascript

/**
* JSS
*
* Nested CSS via JavaScript
**/
var JSS = function(o, options) {
// set up the base options
this.options = {
minified: true,
apply: true
}

// set up the data hash
this.data = {};

// m()
//
// Merges properties of s into o and returns o
//
this.m = function(o, s) {
for (var p in s) {
o[p] = s[p];
}

return o;
}

// parse()
//
// Parses the object o and stores the information in this.data{}
//
this.parse = function(o, p) {
if (typeof o != 'object') {
throw new Error('CSS::parse: No valid CSS object passed.');
}

if (!p) {
p = '';
}

for (var prop in o) {
if (typeof o[prop] == 'object') {
var rule = getPrefix(p) + prop;
if (!this.data[rule]) {
this.data[rule] = [];
}

this.parse(o[prop], this.getPrefix(p) + prop);

} else {
this.data[p][this.data[p].length] = (this.options.minified) ? prop + ':' + this.minify(o[prop]) + ';' : '  ' + prop + ': ' + o[prop] + ';
';
}
}
}

// build()
//
// Builds the information stored in this.data{} into valid CSS text
//
this.build = function() {
var css = '';

for (var rule in this.data) {
if (this.data[rule] != []) {
css += (this.options.minified) ? rule + '{' : rule + ' {
';

css += this.data[rule].join('');

css += (this.options.minified) ? '}' : '}

';
}
}

return css;
}

// getPrefix()
//
// Shortcut to return the prefix for stacking
//
this.getPrefix = function(p) {
if (p) {
return p + ' ';

} else {
return '';
}
}

// minify()
//
// Minifies the string passed
//
this.minify = function(s) {
// html/css colour names that can be replaced by shorter hex codes
var colours = [
[
/black/,
'#000'
],
[
/white/,
'#fff'
],
[
/fuchsia/,
'#f0f'
],
[
/yellow/,
'#ff0'
]
];

// loop through taking out any long colour names
for (var i = colours.length - 1; i >= 0; i--){
s = s.replace(colours[i][0], colours[i][1]);
}

// if we've got any 6 char hex codes
if (s.match(/#[0-9a-f]{6}/)) {
// see if we can shrink them
var matches = s.match(/#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])/);

if ((matches[1] == matches[2]) && (matches[3] == matches[4]) && (matches[5] == matches[6])) {
s = s.replace(matches[0], '#' + matches[1] + matches[3] + matches[5]);
}
}

return s;
}

// addToPage()
//
// Applies the generated stylesheet to the page
//
this.addToPage = function(s) {
// create a style element
var style = document.createElement('style');
// set it to a text/css block
style.setAttribute('type', 'text/css');

// append the style to the body
if (style.styleSheet) {
// in IE
style.styleSheet.cssText = s;

} else {
// in the other browsers
style.appendChild(document.createTextNode(s));
}

// put it in the document
document.getElementsByTagName('head')[0].appendChild(style);
}

// set the options
this.options = this.m(this.options, options || {});

// start parsing the object
this.parse(o);

if (this.options.apply) {
// if we're supposed to apply the stylesheet, do it!
this.addToPage(this.build());

} else {
// just return the text
return this.build();
}
}

source

Build Nested Array From SQL

$refs = array();
$list = array();

$sql = "SELECT item_id, parent_id, name FROM items ORDER BY name";
$result = mysql_query($sql);
while($data = @mysql_fetch_assoc($result)) {
$thisref = &$refs[ $data['item_id'] ];

$thisref['parent_id'] = $data['parent_id'];
$thisref['name'] = $data['name'];

if ($data['parent_id'] == 0) {
$list[ $data['item_id'] ] = &$thisref;
} else {
$refs[ $data['parent_id'] ]['children'][ $data['item_id'] ] = &$thisref;
}
}

source

Toggle value of nested property

//toggle object property value
//only works if the object is in the global scope <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> 
function tog(propertyStr, value, defaultValue) {
var property = propertyStr.split('.');
/*   var propAddr = '[' + propertyStr.join('][') + ']'; */
var propAddrStr = property.shift() + '["' + property.join('"]["') + '"]';
var propValue = eval(propAddrStr);
var setPropStr = propAddrStr + '= "' + (propValue == value ? defaultValue : value ) + '"';
eval(setPropStr);
}

source