added Modifier option.

changed form to use a submit button.
This commit is contained in:
Victor Nguyen 2013-02-22 01:23:12 +11:00
parent e26d51c0b1
commit b55543d1a3
5 changed files with 67 additions and 26 deletions

View file

@ -1,5 +1,8 @@
#minified { padding-top:0; margin-left:20px; } #form-specs { margin:0; padding:20px 30px 25px; background:#f5f5f5; border:1px solid #e5e5e5; border-radius:6px; }
#minified { padding-top:0; margin:0 30px 0 20px; }
#modifier { margin-left:20px; }
#modifier .help-inline { font-size:0.9em; }
#results { display:none; } #results { display:none; }
#image { width:70%; margin:0 auto; display:block; } #image { width:70%; margin:0 auto; display:block; }

View file

@ -7,31 +7,38 @@
select: (function () { select: (function () {
// cache elems // cache elems
var $dropdown = $('#dropdown'), var model = null, // set in _setSelectedModel()
$dropdown = $('#dropdown'),
$trigger = $dropdown.children('.btn'), $trigger = $dropdown.children('.btn'),
$options = $dropdown.find('.dropdown-menu a'), $options = $dropdown.find('.dropdown-menu a'),
$minified = $('#minified input'); $modifier = $('#modifier input'),
$minified = $('#minified input'),
$submit = $('#submit');
// bind dropdown handler // bind event handlers
$options.click( _handleSelect ); $options.click( _handleSelect );
$submit.click( _handleSubmit );
// create popover for modifier field
$modifier.popover();
function _handleSelect (e) { function _handleSelect (e) {
e.preventDefault(); e.preventDefault();
_setSelectedModel(this);
_reset(model.name);
}
var model = { function _handleSubmit(e) {
slug: $(this).attr('href').replace(/#/,''), e.preventDefault();
name: $(this).text(),
img: $(this).attr('data-img')
};
console.log('selected', model.slug, _isMinified()); var model = _getSelectedModel();
_setLoading(model.name); _setLoading(model.name);
CREPE.results.hide(); CREPE.results.hide();
CREPE CREPE
.data.fetch( model.slug, _isMinified() ) .data.fetch( model.slug, _getModifier(), _isMinified() )
.then(function(response) { .then(function(response) {
CREPE.results.init(model, response); CREPE.results.init(model, response);
_reset(model.name); _reset(model.name);
@ -42,10 +49,28 @@
$trigger.button('loading'); $trigger.button('loading');
} }
function _setSelectedModel(option) {
var $option = $(option);
model = {
slug: $option.attr('href').replace(/#/,''),
name: $option.text(),
img: $option.attr('data-img')
};
console.log('selected', model.slug);
}
function _getSelectedModel() {
return model;
}
function _isMinified() { function _isMinified() {
return $minified.is(':checked'); return $minified.is(':checked');
} }
function _getModifier() {
return $modifier.val();
}
function _reset (label) { function _reset (label) {
var defaultLabel = 'Select a model', var defaultLabel = 'Select a model',
spacing = '   '; spacing = '   ';
@ -56,14 +81,14 @@
} }
return { return {
getSelectedModel: _getSelectedModel
}; };
}()), }()),
data: { data: {
fetch: function(slug, isMinified){ fetch: function(slug, modifier, isMinified){
return $.get('/specs/' + slug, { minified: isMinified }); return $.get('/specs/' + slug, { minified:isMinified, modifier:modifier });
} }
}, },

View file

@ -11,6 +11,7 @@ exports.fetch = function(req, res){
var model = req.params.model, var model = req.params.model,
isMinified = req.query.minified == 'true' ? true : false; isMinified = req.query.minified == 'true' ? true : false;
modifier = req.query.modifier;
console.log('Model requested: ', model, req.params, req.query, isMinified); console.log('Model requested: ', model, req.params, req.query, isMinified);
@ -50,7 +51,15 @@ exports.fetch = function(req, res){
// res.send('There are ' + $styles.length + ' body style(s) for the ' + model); // res.send('There are ' + $styles.length + ' body style(s) for the ' + model);
var carName = $body.find('h1').text().replace(' Specifications',''); var carName = $body.find('h1').text().replace(' Specifications','');
res.render('specs', { title:carName, styles:specs, pretty:!isMinified }); res.render(
'specs',
{
title: carName,
styles: specs,
modifier: modifier,
pretty: !isMinified
}
);
function _parseBodyStyleHtml(i,bodyStyle) { function _parseBodyStyleHtml(i,bodyStyle) {
var style = { var style = {

View file

@ -5,6 +5,7 @@ block content
div.hero-unit div.hero-unit
h1= title h1= title
p Welcome to #{title}. That that was redudant tag line. p Welcome to #{title}. That that was redudant tag line.
form#form-specs.form-inline
div#dropdown.btn-group div#dropdown.btn-group
a.btn.btn-large.dropdown-toggle(data-toggle='dropdown', data-loading-text='Fetching specs...', data-complete-text='', href='#') Select a model    a.btn.btn-large.dropdown-toggle(data-toggle='dropdown', data-loading-text='Fetching specs...', data-complete-text='', href='#') Select a model   
span.caret span.caret
@ -12,9 +13,12 @@ block content
each model in models each model in models
li li
a(href='##{model.slug}', data-img='#{model.img}') #{model.name} a(href='##{model.slug}', data-img='#{model.img}') #{model.name}
label#minified.checkbox.inline label#modifier Modifier:
input.input-small(type='text', placeholder='none', value='two-col', data-toggle='popover', data-placement='bottom', data-trigger='focus', data-html='true', data-title='Modifier CSS Class', data-content='Applied to <code>div.specifications-set</code> to enable custom styling per vehicle.')
label#minified.checkbox
input(type='checkbox', checked) input(type='checkbox', checked)
| Minified | Minified output
button#submit.btn.btn-primary.btn-large Get Specs
div#results.row-fluid div#results.row-fluid
div.span4 div.span4
h3 Model Name h3 Model Name

View file

@ -24,7 +24,7 @@ div#specs
//- TAB CONTENT //- TAB CONTENT
each style, i in styles each style, i in styles
- var visible = (i === 0) ? 'display:block' : '' - var visible = (i === 0) ? 'display:block' : ''
div.specifications-set.two-col(id='#{style.slug}', style='#{visible}') div(class='specifications-set #{modifier}', id='#{style.slug}', style='#{visible}')
//- CATEGORY TABS //- CATEGORY TABS
ul.table-tabs.clearfix ul.table-tabs.clearfix