Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<title>Sencha Touch</title>
<link rel="stylesheet" href="sencha/097/ext-touch-debug.css" type="text/css">
<link rel="stylesheet" href="stylesheets/scratch.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
<script type="text/javascript" src="sencha/097/ext-touch-debug.js"> </script>
<script src="javascripts/data.js" type="text/javascript" charset="utf-8"></script>
var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<tpl if="this.isGirl(name)">',
'<p>Girl: {name} - {age}</p>',
'</tpl>',
// use opposite if statement to simulate 'else' processing:
'<tpl if="this.isGirl(name) == false">',
'<p>Boy: {name} - {age}</p>',
var tpl = Ext.XTemplate.from('kids-list');
tpl.isGirl = function(name){
return name == 'Sara Grace';
}
tpl.isBaby: function(age){
return age < 1;
}
@nelstrom
nelstrom / xtemplates-with-member-functions.js
Created October 20, 2010 18:34
The member function renderImage() is called using the format {images:this.renderImage}. How?
var templateFunctions = {
renderImage: function(images) {
if (Ext.isArray(images) && images[2]) {
var img = images[2];
return String.format('<img src="{0}" />', img.url, img.width, img.height);
} else {
return '';
}
},
renderPrice: function(price, values) {
landscapeProductTpl: new Ext.XTemplate(
'<div class="productlist-container">',
'<tpl for=".">',
'<span>{price:this.renderPrice} - {retailer}</span>',
'</tpl>',
'</div>',
renderPrice: function(price, values) {
var salePrice = values.salePrice;
if (salePrice) {
return '<del>' + values.priceLabel + '</del> ' + values.salePriceLabel;
@nelstrom
nelstrom / mon.js
Created November 2, 2010 17:54
What does the this.mon() function do?
demos.TouchImpl.TouchPad = Ext.extend(Ext.Component, {
id: 'touchpad',
html: 'Touch here!',
initComponent : function() {
this.addEvents('log');
demos.TouchImpl.TouchPad.superclass.initComponent.call(this);
},
afterRender: function() {
Ext.setup({
onReady: function() {
var data = [{
name: 'Joshua',
age:3
},{
name: 'Matthew',
age:2
},{
@nelstrom
nelstrom / ruby-command-R.vim
Created January 6, 2011 20:16
Ruby the ruby in the current buffer when command-R is pressed (TextMate style)
if has("autocmd")
autocmd FileType ruby nnoremap <buffer> <D-r> :!ruby %<CR>
endif
if has("autocmd")
autocmd FileType ruby :Abolish -buffer initialise initialize
endif
@nelstrom
nelstrom / only.vim
Created February 11, 2011 07:52
A command to close all Vim buffers that are not currently visible.
command! -nargs=* Only call CloseHiddenBuffers()
function! CloseHiddenBuffers()
" figure out which buffers are visible in any tab
let visible = {}
for t in range(1, tabpagenr('$'))
for b in tabpagebuflist(t)
let visible[b] = 1
endfor
endfor
" close any buffer that are loaded and not visible