Thursday, December 23, 2010

CSS staff you have to know

I'm sure most of you have worked with CSS. I'm sure many of you know that, but some do not, so here are some nice practices that can help you.
1. div>h1 { color: red;}
- means all h1 that are child to div will get that CSS, but not sub child.
examples:
<div>
<h1>this is red</h1>
</div>

<div>
<p>
<h1>this is not red</h1>
</p>
</div>

2. p+h1 {color:red}
- means make red h1 in case if it is going just after p on the same level
examples:
<div>
<p></p>
<h1>this is red text</h1>

</div>

<div>
<p></p>
<h2></h2>
<h1>this is not red text</h1>
</div>


3. p~h1 {color:red} (similar to +)
- means make red h1 in case if it is on the same level with p
examples:
<div>
<p></p>
<h1>this is red text</h1>
</div>

<div>
<p></p>
<h2></h2>
<h1>this is also red text</h1>
</div>


4. p:first-child {color:red}
- means make red p in case if it is first child
examples:
<body>
<p>This is red text</p>
<p>This is not read</p>
</body>

Monday, December 06, 2010

Expand and Collapse views in xPages

Found very nice solution

Collapse all
 var viewPanel = getComponent(compositeData.viewPanelName);  
 var model:com.ibm.xsp.model.domino.DominoViewDataModel = viewPanel.getDataModel();  
 var container:com.ibm.xsp.model.domino.DominoViewDataContainer = model.getDominoViewDataContainer();  
 container.collapseAll();  

Expand all
 var viewPanel = getComponent(compositeData.viewPanelName);  
 var model:com.ibm.xsp.model.domino.DominoViewDataModel = viewPanel.getDataModel();  
 var container:com.ibm.xsp.model.domino.DominoViewDataContainer = model.getDominoViewDataContainer();  
 container.expandAll();  

That's much better then save values in sessionScope/RequestScope and use property expandLevel in viewPanel.

Tuesday, November 16, 2010

JS staff: Use Object instead of Switch.

Well, many of us use switch to solve own tasks, but there is another way I would like to show. We can use Object approach to solve our problem and it looks more intelligent from my point of view.

Let me show couple examples

1. Example with switch
function FoodType(food) {
var getfoodtype;

switch(food) {
case 'apple': getfoodtype = 'fruit'; break;
case 'cucumbers': getfoodtype = 'vegetable'; break;
case 'watermelon': getfoodtype = 'strawberry'; break;
default: getfoodtype = 'not recognized';
}

return getfoodtype;

}

var getfoodtype, case, and break, we can avoid them.

2. Example with Object
FoodType {
apple: fruit,
cucumbers: vegetable,
watermelon: strawberry,

GetFoodType: function(type) {

return(this[type] || 'not recognized');
}

}

Ofc there could be cases where Object approach does not work and we have to use switch, but it is alternative, so keep in mind this.