Initial commit

This commit is contained in:
László Károlyi 2014-10-26 22:18:13 +01:00
commit 033604d2ed
12 changed files with 2928 additions and 0 deletions

15
README.md Normal file
View File

@ -0,0 +1,15 @@
Used tools:
-----------
* Sublime Text 3 with my repo: https://github.com/karolyi/st3-config
* csslint
* jshint
* htmllint
* jQuery UI Widget Factory: http://jqueryui.com/widget/
Since a grid system is not provided, no grid system is used by default. All the positioned elements are pixel positioned.
---
The data is loaded from the `data/cart.json` file at load time, and pushing the "Buy Now" button alerts the JSON format which would be posted to the REST API.

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
assets/trash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

356
css/style.css Normal file
View File

@ -0,0 +1,356 @@
html {
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #FFFFFF),
color-stop(1, #DADADA)
);
background-image: -o-linear-gradient(bottom, #FFFFFF 0%, #DADADA 100%);
background-image: -moz-linear-gradient(bottom, #FFFFFF 0%, #DADADA 100%);
background-image: -webkit-linear-gradient(bottom, #FFFFFF 0%, #DADADA 100%);
background-image: -ms-linear-gradient(bottom, #FFFFFF 0%, #DADADA 100%);
background-image: linear-gradient(to bottom, #FFFFFF 0%, #DADADA 100%);
}
body {
margin: 0;
padding: 0;
}
#content {
font-family: 'Droid Serif', serif;
margin: 0 auto;
width: 580px;
}
#logo {
background-image: url(../assets/logo.png);
font-size: 0;
height: 48px;
margin: 130px 0 0 21px;
width: 100px;
}
#content h1 {
font-size: 31px;
font-weight: 700;
letter-spacing: -2px;
margin: 67px 0 0 21px;
}
#content p {
font-size: 14px;
margin: 12px 0 0 22px;
}
#cart form input {
display: inline-block;
font-size: 14px;
height: 22px;
text-align: center;
width: 31px;
}
#headings {
border-bottom: 2px solid;
float: left;
margin: 60px 0 0;
width: 510px;
}
#headings .header {
float: left;
font-size: 18px;
font-weight: 700;
padding: 0 0 0 19px;
}
#headings .header.product {
width: 238px;
}
#headings .header.price {
text-align: right;
width: 60px;
}
#headings .header.quantity {
text-align: center;
width: 70px;
}
#headings .header.cost {
text-align: right;
width: 50px;
}
#items {
float: left;
margin: 27px 0 0;
width: 550px;
}
#items .item {
clear: left;
float: left;
font-size: 18px;
padding: 13px 10px 9px 0;
}
#items .item: hover {
background-color: #ddd;
}
#items .item .product,
#items .item .price,
#items .item .quantity,
#items .item .cost,
#items .item .remove {
float: left;
margin-left: 20px;
}
#cart-totals {
color: #666;
float: left;
margin: 27px 0 0;
width: 498px;
}
#items .item .product {
display: block;
width: 235px;
}
#items .item .price {
text-align: right;
width: 63px;
}
#items .item .quantity {
margin-top: -4px;
padding: 0;
width: 79px;
}
#items .item .quantity input {
border: 1px #999 solid;
float: left;
height: 28px;
padding-right: 4px;
text-align: right;
width: 34px;
}
#items .item .quantity .qty-ctrl {
float: left;
font-size: 0;
margin-left: 4px;
width: 17px;
}
#items .item .quantity .qty-ctrl .qty-up {
background-color: #999;
border: 0;
color: #FFF;
height: 15px;
margin-bottom: 2px;
padding: 0;
width: 16px;
}
#items .item .quantity .qty-ctrl .qty-up span {
font-size: 11px;
position: relative;
top: -1px;
}
#items .item .quantity .qty-ctrl .qty-down {
background-color: #999;
border: 0;
color: #FFF;
height: 15px;
padding: 0;
width: 16px;
}
#items .item .quantity .qty-ctrl .qty-down span {
clear: left;
font-size: 11px;
position: relative;
top: -1px;
}
#items .item .cost {
width: 53px;
}
#items .item .remove {
background-color: transparent;
background-image: url(../assets/trash.png);
background-position: 1px 1px;
background-repeat: no-repeat;
border: 0;
height: 24px;
margin-left: 10px;
padding: 0;
width: 18px;
}
#cart-totals > div {
clear: both;
float: left;
width: 498px;
}
#cart-totals .heading {
float: left;
padding: 0 0 7px 22px;
width: 380px;
}
#cart-totals .amount {
float: left;
text-align: right;
width: 80px;
}
#cart-totals #total {
color: #000;
font-weight: 700;
padding: 20px 0 0;
}
#buynow {
clear: both;
float: left;
margin: 47px 0 178px;
width: 479px;
}
#buy-btn {
background-color: #000065;
border: 0 none;
color: #fff;
float: right;
font-size: 23px;
font-weight: 700;
height: 50px;
padding: 10px 0 10px 5px;
text-align: left;
text-decoration: none;
width: 130px;
border-radius: 10px;
}
#buy-btn: disabled {
background-color: #ccc;
color: #333;
}
#footer {
background-color: #666;
border-top: 1px solid #000;
clear: both;
color: #fff;
font-size: 11px;
margin: 10px 0 0;
padding: 14px 0;
text-align: center;
width: 100%;
}
@media all and max-width 699px and min-width 520px{
#logo {
margin: 70px 0 0;
}
}
@media all and max-width 520px and min-width 320px{
#logo {
margin: 50px 0 0;
}
#content h1 {
margin: 25px 0 0 21px;
}
#headings {
margin: 30px 0 0;
width: 100%;
}
#headings .header {
font-size: 14px;
}
#items {
width: 110%;
}
#items .item {
font-size: 12px;
padding: 0 0 13px 19px;
}
#headings .header.product {
width: 39%;
}
#headings .header.price,
#items .item.price {
width: 10%;
}
#items .item.product,
#items .item.product {
width: 34%;
}
#items .item.cost {
width: 8%;
}
#cart-totals,
#cart-totals > div,
#buynow {
width: 100%;
}
#cart-totals .heading {
width: 50%;
}
#cart-totals .amount {
width: 40%;
}
#headings .header.quantity,
#items .item.quantity,
#headings .header.cost {
width: 15%;
}
}
@media all and max-width 320px and min-width 120px{
#headings .header.product {
width: 32%;
}
#headings .header.quantity,
#items .item.quantity {
width: 16%;
}
#items .item.cost {
width: 5%;
}
#items .item.remove a {
font-size: 12px;
}
#items > div {
height: 46px;
}
}

19
data/cart.json Normal file
View File

@ -0,0 +1,19 @@
{
"basket": [
{
"product": "Cotton T-Shirt, Medium",
"price": 1.99,
"quantity": 1
},
{
"product": "Baseball Cap, One Size",
"price": 2.99,
"quantity": 2
},
{
"product": "Swim Shorts, Medium",
"price": 3.99,
"quantity": 1
}
]
}

65
index.html Normal file
View File

@ -0,0 +1,65 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Your Basket</title>
<script src="lib/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="lib/jquery-ui.js" type="text/javascript"></script>
<script src="lib/modernizr-latest.js" type="text/javascript"></script>
<script src="js/itemWidget.js" type="text/javascript"></script>
<script src="js/cartWidget.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Droid+Serif:400,700,700italic,400italic' rel='stylesheet' type='text/css'/>
<script type="text/javascript">
$(function () {
$('#cart').cartWidget({
inputFile: 'data/cart.json'
});
});
</script>
</head>
<body>
<div id="content">
<div id="logo">AKQA</div>
<h1>Your Basket</h1>
<p>Items you have added to your basket are shown below.<br/>Adjust the quantities or remove items before continuing your purchase.</p>
<div id="cart">
<form id="cart-form" action="#">
<div id="headings">
<div class="header product">Product</div>
<div class="header price">Price</div>
<div class="header quantity">Qty</div>
<div class="header cost">Cost</div>
</div>
<div id="items">
</div>
<div id="cart-totals">
<div id="subtotal">
<div class="heading">Sub total</div>
<div class="amount">&pound;<span></span></div>
</div>
<div id="vat">
<div class="heading">VAT @ 20%</div>
<div class="amount">&pound;<span></span></div>
</div>
<div id="total">
<div class="heading">Total Cost</div>
<div class="amount">&pound;<span></span></div>
</div>
</div>
<div id="buynow">
<button id="buy-btn" type="button" disabled="disabled">Buy Now &raquo;</button>
</div>
</form>
</div>
</div>
<div id="footer"><strong>&copy; 2013 AKQA Ltd.</strong> Registered in England: 2964394</div>
</body>
</html>

90
js/cartWidget.js Normal file
View File

@ -0,0 +1,90 @@
/*jshint devel:true*/
/*global $*/
'use strict';
$.widget('AKQA.cartWidget', {
options: {
inputFile: 'data/cart.json',
selectors: {
items: '#items',
subTotal: '#cart-totals #subtotal .amount span',
vat: '#cart-totals #vat .amount span',
total: '#cart-totals #total .amount span',
form: '#cart-form',
buttonBuy: '#buy-btn'
}
},
_create: function () {
var self = this;
this.subTotalWrapper = this.element.find(this.options.selectors.subTotal);
this.vatWrapper = this.element.find(this.options.selectors.vat);
this.totalWrapper = this.element.find(this.options.selectors.total);
this.itemsWrapper = this.element.find(this.options.selectors.items);
this.buttonBuy = this.element.find(this.options.selectors.buttonBuy);
this.buttonBuy.click(function (event) {
self._displaySummary(event);
});
$.when(
$.ajax(this.options.inputFile),
$.ajax('template/item.html')
).then(function (inputFileResponse, templateResponse) {
self.inputFile = inputFileResponse[0];
self.itemTemplate = templateResponse[0];
self._continueInit();
});
this.element.find(this.options.selectors.form).submit(function (event) {
event.preventDefault();
});
},
_continueInit: function () {
for (var idx = 0; idx < this.inputFile.basket.length; idx++) {
var item = this.inputFile.basket[idx];
var itemWrapper = $(this.itemTemplate);
itemWrapper.itemWidget({
index: idx,
item: item,
cartWidget: this
});
this.itemsWrapper.append(itemWrapper);
}
this._updateTotals();
},
_handlePriceFloat: function (input) {
return Math.round(input * 100) / 100;
},
_updateTotals: function () {
var result = this._getSummary();
this.subTotalWrapper.text(result.subTotal);
this.vatWrapper.text(result.vat);
this.totalWrapper.text(result.total);
this.buttonBuy.prop('disabled', result.total === 0);
},
_getSummary: function () {
var items = this.itemsWrapper.children();
var result = {
basket: [],
subTotal: 0,
vat: 0,
total: 0
};
for (var idx = 0; idx < items.length; idx++) {
var item = $(items[idx]);
var itemResult = item.itemWidget('getJson');
result.subTotal += itemResult.cost;
result.basket.push(itemResult);
}
result.subTotal = this._handlePriceFloat(result.subTotal);
result.vat = this._handlePriceFloat(result.subTotal * 0.2);
result.total = this._handlePriceFloat(result.subTotal + result.vat);
return result;
},
_displaySummary: function () {
alert(JSON.stringify(this._getSummary(), null, 2));
}
});

108
js/itemWidget.js Normal file
View File

@ -0,0 +1,108 @@
/*global $*/
'use strict';
$.widget('AKQA.itemWidget', {
options: {
index: 0,
item: {},
cartWidget: {},
minValue: 1,
maxValue: 10,
startValue: 1,
selectors: {
productWrapper: 'label.product',
priceWrapper: '.price span',
costWrapper: '.cost span',
quantityInput: 'input',
quantityUp: 'button.qty-up',
quantityDown: 'button.qty-down',
buttonRemove: 'button.remove'
}
},
_create: function () {
var self = this;
this.valueRegex = /^[0-9]+$/;
this.productWrapper = this.element.find(this.options.selectors.productWrapper);
this.costWrapper = this.element.find(this.options.selectors.costWrapper);
this.priceWrapper = this.element.find(this.options.selectors.priceWrapper);
this.quantityInput = this.element.find(this.options.selectors.quantityInput);
this.quantityUp = this.element.find(this.options.selectors.quantityUp);
this.quantityDown = this.element.find(this.options.selectors.quantityDown);
this.buttonRemove = this.element.find(this.options.selectors.buttonRemove);
this.quantityInput.change(function (event) {
self._onChangeQuantity(event);
});
this.quantityUp.click(function (event) {
self._onClickQuantityUp(event);
});
this.quantityDown.click(function (event) {
self._onClickQuantityDown(event);
});
this.buttonRemove.click(function () {
self.element.remove();
self.options.cartWidget._updateTotals();
});
this.productWrapper.attr('for', 'qty-' + this.options.index)
.text(this.options.item.product);
this.quantityInput.attr('id', 'qty-' + this.options.index)
.val(this.options.item.quantity);
this.priceWrapper.text(this.options.item.price);
this._updateCost();
},
_sanitizeQuantityValue: function () {
var value = this.quantityInput.val();
if (!this.valueRegex.test(value)) {
this.quantityInput.val(0);
return 0;
}
return parseInt(value, 10);
},
_onChangeQuantity: function () {
var value = this._sanitizeQuantityValue();
if (value > this.options.maxValue) {
this.quantityInput.val(this.options.maxValue);
}
if (value < this.options.minValue) {
this.quantityInput.val(this.options.minValue);
}
this._updateCost();
this.options.cartWidget._updateTotals();
},
_handlePriceFloat: function (input) {
return Math.round(input * 100) / 100;
},
_onClickQuantityUp: function () {
var value = this._sanitizeQuantityValue();
this.quantityInput.val(value + 1);
this._onChangeQuantity();
},
_onClickQuantityDown: function () {
var value = this._sanitizeQuantityValue();
this.quantityInput.val(value - 1);
this._onChangeQuantity();
},
_updateCost: function () {
this.costWrapper.text(this.getCost());
},
getCost: function () {
return this._handlePriceFloat(this.options.item.price * this._sanitizeQuantityValue());
},
getJson: function () {
return {
product: this.options.item.product,
price: this.options.item.price,
quantity: this._sanitizeQuantityValue(),
cost: this.getCost()
};
}
});

4
lib/jquery-1.11.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

852
lib/jquery-ui.js vendored Executable file
View File

@ -0,0 +1,852 @@
/*! jQuery UI - v1.11.1 - 2014-10-10
* http://jqueryui.com
* Includes: core.js, widget.js
* Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([ "jquery" ], factory );
} else {
// Browser globals
factory( jQuery );
}
}(function( $ ) {
/*!
* jQuery UI Core 1.11.1
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/category/ui-core/
*/
// $.ui might exist from components with no dependencies, e.g., $.ui.position
$.ui = $.ui || {};
$.extend( $.ui, {
version: "1.11.1",
keyCode: {
BACKSPACE: 8,
COMMA: 188,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
LEFT: 37,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SPACE: 32,
TAB: 9,
UP: 38
}
});
// plugins
$.fn.extend({
scrollParent: function( includeHidden ) {
var position = this.css( "position" ),
excludeStaticParent = position === "absolute",
overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
scrollParent = this.parents().filter( function() {
var parent = $( this );
if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
return false;
}
return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
}).eq( 0 );
return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
},
uniqueId: (function() {
var uuid = 0;
return function() {
return this.each(function() {
if ( !this.id ) {
this.id = "ui-id-" + ( ++uuid );
}
});
};
})(),
removeUniqueId: function() {
return this.each(function() {
if ( /^ui-id-\d+$/.test( this.id ) ) {
$( this ).removeAttr( "id" );
}
});
}
});
// selectors
function focusable( element, isTabIndexNotNaN ) {
var map, mapName, img,
nodeName = element.nodeName.toLowerCase();
if ( "area" === nodeName ) {
map = element.parentNode;
mapName = map.name;
if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
return false;
}
img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
return !!img && visible( img );
}
return ( /input|select|textarea|button|object/.test( nodeName ) ?
!element.disabled :
"a" === nodeName ?
element.href || isTabIndexNotNaN :
isTabIndexNotNaN) &&
// the element and all of its ancestors must be visible
visible( element );
}
function visible( element ) {
return $.expr.filters.visible( element ) &&
!$( element ).parents().addBack().filter(function() {
return $.css( this, "visibility" ) === "hidden";
}).length;
}
$.extend( $.expr[ ":" ], {
data: $.expr.createPseudo ?
$.expr.createPseudo(function( dataName ) {
return function( elem ) {
return !!$.data( elem, dataName );
};
}) :
// support: jQuery <1.8
function( elem, i, match ) {
return !!$.data( elem, match[ 3 ] );
},
focusable: function( element ) {
return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
},
tabbable: function( element ) {
var tabIndex = $.attr( element, "tabindex" ),
isTabIndexNaN = isNaN( tabIndex );
return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
}
});
// support: jQuery <1.8
if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
$.each( [ "Width", "Height" ], function( i, name ) {
var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
type = name.toLowerCase(),
orig = {
innerWidth: $.fn.innerWidth,
innerHeight: $.fn.innerHeight,
outerWidth: $.fn.outerWidth,
outerHeight: $.fn.outerHeight
};
function reduce( elem, size, border, margin ) {
$.each( side, function() {
size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
if ( border ) {
size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
}
if ( margin ) {
size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
}
});
return size;
}
$.fn[ "inner" + name ] = function( size ) {
if ( size === undefined ) {
return orig[ "inner" + name ].call( this );
}
return this.each(function() {
$( this ).css( type, reduce( this, size ) + "px" );
});
};
$.fn[ "outer" + name] = function( size, margin ) {
if ( typeof size !== "number" ) {
return orig[ "outer" + name ].call( this, size );
}
return this.each(function() {
$( this).css( type, reduce( this, size, true, margin ) + "px" );
});
};
});
}
// support: jQuery <1.8
if ( !$.fn.addBack ) {
$.fn.addBack = function( selector ) {
return this.add( selector == null ?
this.prevObject : this.prevObject.filter( selector )
);
};
}
// support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
$.fn.removeData = (function( removeData ) {
return function( key ) {
if ( arguments.length ) {
return removeData.call( this, $.camelCase( key ) );
} else {
return removeData.call( this );
}
};
})( $.fn.removeData );
}
// deprecated
$.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
$.fn.extend({
focus: (function( orig ) {
return function( delay, fn ) {
return typeof delay === "number" ?
this.each(function() {
var elem = this;
setTimeout(function() {
$( elem ).focus();
if ( fn ) {
fn.call( elem );
}
}, delay );
}) :
orig.apply( this, arguments );
};
})( $.fn.focus ),
disableSelection: (function() {
var eventType = "onselectstart" in document.createElement( "div" ) ?
"selectstart" :
"mousedown";
return function() {
return this.bind( eventType + ".ui-disableSelection", function( event ) {
event.preventDefault();
});
};
})(),
enableSelection: function() {
return this.unbind( ".ui-disableSelection" );
},
zIndex: function( zIndex ) {
if ( zIndex !== undefined ) {
return this.css( "zIndex", zIndex );
}
if ( this.length ) {
var elem = $( this[ 0 ] ), position, value;
while ( elem.length && elem[ 0 ] !== document ) {
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
position = elem.css( "position" );
if ( position === "absolute" || position === "relative" || position === "fixed" ) {
// IE returns 0 when zIndex is not specified
// other browsers return a string
// we ignore the case of nested elements with an explicit value of 0
// <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
value = parseInt( elem.css( "zIndex" ), 10 );
if ( !isNaN( value ) && value !== 0 ) {
return value;
}
}
elem = elem.parent();
}
}
return 0;
}
});
// $.ui.plugin is deprecated. Use $.widget() extensions instead.
$.ui.plugin = {
add: function( module, option, set ) {
var i,
proto = $.ui[ module ].prototype;
for ( i in set ) {
proto.plugins[ i ] = proto.plugins[ i ] || [];
proto.plugins[ i ].push( [ option, set[ i ] ] );
}
},
call: function( instance, name, args, allowDisconnected ) {
var i,
set = instance.plugins[ name ];
if ( !set ) {
return;
}
if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
return;
}
for ( i = 0; i < set.length; i++ ) {
if ( instance.options[ set[ i ][ 0 ] ] ) {
set[ i ][ 1 ].apply( instance.element, args );
}
}
}
};
/*!
* jQuery UI Widget 1.11.1
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/jQuery.widget/
*/
var widget_uuid = 0,
widget_slice = Array.prototype.slice;
$.cleanData = (function( orig ) {
return function( elems ) {
var events, elem, i;
for ( i = 0; (elem = elems[i]) != null; i++ ) {
try {
// Only trigger remove when necessary to save time
events = $._data( elem, "events" );
if ( events && events.remove ) {
$( elem ).triggerHandler( "remove" );
}
// http://bugs.jquery.com/ticket/8235
} catch( e ) {}
}
orig( elems );
};
})( $.cleanData );
$.widget = function( name, base, prototype ) {
var fullName, existingConstructor, constructor, basePrototype,
// proxiedPrototype allows the provided prototype to remain unmodified
// so that it can be used as a mixin for multiple widgets (#8876)
proxiedPrototype = {},
namespace = name.split( "." )[ 0 ];
name = name.split( "." )[ 1 ];
fullName = namespace + "-" + name;
if ( !prototype ) {
prototype = base;
base = $.Widget;
}
// create selector for plugin
$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
return !!$.data( elem, fullName );
};
$[ namespace ] = $[ namespace ] || {};
existingConstructor = $[ namespace ][ name ];
constructor = $[ namespace ][ name ] = function( options, element ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new constructor( options, element );
}
// allow instantiation without initializing for simple inheritance
// must use "new" keyword (the code above always passes args)
if ( arguments.length ) {
this._createWidget( options, element );
}
};
// extend with the existing constructor to carry over any static properties
$.extend( constructor, existingConstructor, {
version: prototype.version,
// copy the object used to create the prototype in case we need to
// redefine the widget later
_proto: $.extend( {}, prototype ),
// track widgets that inherit from this widget in case this widget is
// redefined after a widget inherits from it
_childConstructors: []
});
basePrototype = new base();
// we need to make the options hash a property directly on the new instance
// otherwise we'll modify the options hash on the prototype that we're
// inheriting from
basePrototype.options = $.widget.extend( {}, basePrototype.options );
$.each( prototype, function( prop, value ) {
if ( !$.isFunction( value ) ) {
proxiedPrototype[ prop ] = value;
return;
}
proxiedPrototype[ prop ] = (function() {
var _super = function() {
return base.prototype[ prop ].apply( this, arguments );
},
_superApply = function( args ) {
return base.prototype[ prop ].apply( this, args );
};
return function() {
var __super = this._super,
__superApply = this._superApply,
returnValue;
this._super = _super;
this._superApply = _superApply;
returnValue = value.apply( this, arguments );
this._super = __super;
this._superApply = __superApply;
return returnValue;
};
})();
});
constructor.prototype = $.widget.extend( basePrototype, {
// TODO: remove support for widgetEventPrefix
// always use the name + a colon as the prefix, e.g., draggable:start
// don't prefix for widgets that aren't DOM-based
widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
}, proxiedPrototype, {
constructor: constructor,
namespace: namespace,
widgetName: name,
widgetFullName: fullName
});
// If this widget is being redefined then we need to find all widgets that
// are inheriting from it and redefine all of them so that they inherit from
// the new version of this widget. We're essentially trying to replace one
// level in the prototype chain.
if ( existingConstructor ) {
$.each( existingConstructor._childConstructors, function( i, child ) {
var childPrototype = child.prototype;
// redefine the child widget using the same prototype that was
// originally used, but inherit from the new version of the base
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
});
// remove the list of existing child constructors from the old constructor
// so the old child constructors can be garbage collected
delete existingConstructor._childConstructors;
} else {
base._childConstructors.push( constructor );
}
$.widget.bridge( name, constructor );
return constructor;
};
$.widget.extend = function( target ) {
var input = widget_slice.call( arguments, 1 ),
inputIndex = 0,
inputLength = input.length,
key,
value;
for ( ; inputIndex < inputLength; inputIndex++ ) {
for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ];
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
// Clone objects
if ( $.isPlainObject( value ) ) {
target[ key ] = $.isPlainObject( target[ key ] ) ?
$.widget.extend( {}, target[ key ], value ) :
// Don't extend strings, arrays, etc. with objects
$.widget.extend( {}, value );
// Copy everything else by reference
} else {
target[ key ] = value;
}
}
}
}
return target;
};
$.widget.bridge = function( name, object ) {
var fullName = object.prototype.widgetFullName || name;
$.fn[ name ] = function( options ) {
var isMethodCall = typeof options === "string",
args = widget_slice.call( arguments, 1 ),
returnValue = this;
// allow multiple hashes to be passed on init
options = !isMethodCall && args.length ?
$.widget.extend.apply( null, [ options ].concat(args) ) :
options;
if ( isMethodCall ) {
this.each(function() {
var methodValue,
instance = $.data( this, fullName );
if ( options === "instance" ) {
returnValue = instance;
return false;
}
if ( !instance ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" );
}
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
methodValue;
return false;
}
});
} else {
this.each(function() {
var instance = $.data( this, fullName );
if ( instance ) {
instance.option( options || {} );
if ( instance._init ) {
instance._init();
}
} else {
$.data( this, fullName, new object( options, this ) );
}
});
}
return returnValue;
};
};
$.Widget = function( /* options, element */ ) {};
$.Widget._childConstructors = [];
$.Widget.prototype = {
widgetName: "widget",
widgetEventPrefix: "",
defaultElement: "<div>",
options: {
disabled: false,
// callbacks
create: null
},
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
this.uuid = widget_uuid++;
this.eventNamespace = "." + this.widgetName + this.uuid;
this.options = $.widget.extend( {},
this.options,
this._getCreateOptions(),
options );
this.bindings = $();
this.hoverable = $();
this.focusable = $();
if ( element !== this ) {
$.data( element, this.widgetFullName, this );
this._on( true, this.element, {
remove: function( event ) {
if ( event.target === element ) {
this.destroy();
}
}
});
this.document = $( element.style ?
// element within the document
element.ownerDocument :
// element is window or document
element.document || element );
this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
}
this._create();
this._trigger( "create", null, this._getCreateEventData() );
this._init();
},
_getCreateOptions: $.noop,
_getCreateEventData: $.noop,
_create: $.noop,
_init: $.noop,
destroy: function() {
this._destroy();
// we can probably remove the unbind calls in 2.0
// all event bindings should go through this._on()
this.element
.unbind( this.eventNamespace )
.removeData( this.widgetFullName )
// support: jquery <1.6.3
// http://bugs.jquery.com/ticket/9413
.removeData( $.camelCase( this.widgetFullName ) );
this.widget()
.unbind( this.eventNamespace )
.removeAttr( "aria-disabled" )
.removeClass(
this.widgetFullName + "-disabled " +
"ui-state-disabled" );
// clean up events and states
this.bindings.unbind( this.eventNamespace );
this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" );
},
_destroy: $.noop,
widget: function() {
return this.element;
},
option: function( key, value ) {
var options = key,
parts,
curOption,
i;
if ( arguments.length === 0 ) {
// don't return a reference to the internal hash
return $.widget.extend( {}, this.options );
}
if ( typeof key === "string" ) {
// handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
options = {};
parts = key.split( "." );
key = parts.shift();
if ( parts.length ) {
curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
for ( i = 0; i < parts.length - 1; i++ ) {
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
curOption = curOption[ parts[ i ] ];
}
key = parts.pop();
if ( arguments.length === 1 ) {
return curOption[ key ] === undefined ? null : curOption[ key ];
}
curOption[ key ] = value;
} else {
if ( arguments.length === 1 ) {
return this.options[ key ] === undefined ? null : this.options[ key ];
}
options[ key ] = value;
}
}
this._setOptions( options );
return this;
},
_setOptions: function( options ) {
var key;
for ( key in options ) {
this._setOption( key, options[ key ] );
}
return this;
},
_setOption: function( key, value ) {
this.options[ key ] = value;
if ( key === "disabled" ) {
this.widget()
.toggleClass( this.widgetFullName + "-disabled", !!value );
// If the widget is becoming disabled, then nothing is interactive
if ( value ) {
this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" );
}
}
return this;
},
enable: function() {
return this._setOptions({ disabled: false });
},
disable: function() {
return this._setOptions({ disabled: true });
},
_on: function( suppressDisabledCheck, element, handlers ) {
var delegateElement,
instance = this;
// no suppressDisabledCheck flag, shuffle arguments
if ( typeof suppressDisabledCheck !== "boolean" ) {
handlers = element;
element = suppressDisabledCheck;
suppressDisabledCheck = false;
}
// no element argument, shuffle and use this.element
if ( !handlers ) {
handlers = element;
element = this.element;
delegateElement = this.widget();
} else {
element = delegateElement = $( element );
this.bindings = this.bindings.add( element );
}
$.each( handlers, function( event, handler ) {
function handlerProxy() {
// allow widgets to customize the disabled handling
// - disabled as an array instead of boolean
// - disabled class as method for disabling individual parts
if ( !suppressDisabledCheck &&
( instance.options.disabled === true ||
$( this ).hasClass( "ui-state-disabled" ) ) ) {
return;
}
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
// copy the guid so direct unbinding works
if ( typeof handler !== "string" ) {
handlerProxy.guid = handler.guid =
handler.guid || handlerProxy.guid || $.guid++;
}
var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
eventName = match[1] + instance.eventNamespace,
selector = match[2];
if ( selector ) {
delegateElement.delegate( selector, eventName, handlerProxy );
} else {
element.bind( eventName, handlerProxy );
}
});
},
_off: function( element, eventName ) {
eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
element.unbind( eventName ).undelegate( eventName );
},
_delay: function( handler, delay ) {
function handlerProxy() {
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
var instance = this;
return setTimeout( handlerProxy, delay || 0 );
},
_hoverable: function( element ) {
this.hoverable = this.hoverable.add( element );
this._on( element, {
mouseenter: function( event ) {
$( event.currentTarget ).addClass( "ui-state-hover" );
},
mouseleave: function( event ) {
$( event.currentTarget ).removeClass( "ui-state-hover" );
}
});
},
_focusable: function( element ) {
this.focusable = this.focusable.add( element );
this._on( element, {
focusin: function( event ) {
$( event.currentTarget ).addClass( "ui-state-focus" );
},
focusout: function( event ) {
$( event.currentTarget ).removeClass( "ui-state-focus" );
}
});
},
_trigger: function( type, event, data ) {
var prop, orig,
callback = this.options[ type ];
data = data || {};
event = $.Event( event );
event.type = ( type === this.widgetEventPrefix ?
type :
this.widgetEventPrefix + type ).toLowerCase();
// the original event may come from any element
// so we need to reset the target on the new event
event.target = this.element[ 0 ];
// copy original event properties over to the new event
orig = event.originalEvent;
if ( orig ) {
for ( prop in orig ) {
if ( !( prop in event ) ) {
event[ prop ] = orig[ prop ];
}
}
}
this.element.trigger( event, data );
return !( $.isFunction( callback ) &&
callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
event.isDefaultPrevented() );
}
};
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
if ( typeof options === "string" ) {
options = { effect: options };
}
var hasOptions,
effectName = !options ?
method :
options === true || typeof options === "number" ?
defaultEffect :
options.effect || defaultEffect;
options = options || {};
if ( typeof options === "number" ) {
options = { duration: options };
}
hasOptions = !$.isEmptyObject( options );
options.complete = callback;
if ( options.delay ) {
element.delay( options.delay );
}
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
element[ method ]( options );
} else if ( effectName !== method && element[ effectName ] ) {
element[ effectName ]( options.duration, options.easing, callback );
} else {
element.queue(function( next ) {
$( this )[ method ]();
if ( callback ) {
callback.call( element[ 0 ] );
}
next();
});
}
};
});
var widget = $.widget;
}));

1406
lib/modernizr-latest.js Normal file

File diff suppressed because it is too large Load Diff

13
template/item.html Normal file
View File

@ -0,0 +1,13 @@
<div class="item">
<label class="product"></label>
<div class="price">&pound;<span></span></div>
<div class="quantity">
<input type="text" value="1"/>
<div class="qty-ctrl">
<button class="qty-up"><span>+</span></button>
<button class="qty-down"><span>-</span></button>
</div>
</div>
<div class="cost">&pound;<span></span></div>
<button class="remove"><span></span></button>
</div>