Upgrade Guide - mercadolibre/chico GitHub Wiki
We wrote this guide to help you to upgrade from Chico UI 0.13.x to Chico UI 1.0.0.
Our APIs have been redesigned, following these goals:
- Reuse our code: Mobile + Desktop!
- Extend our components (using prototypal inheritance).
- Add performance improvements.
- Be Modular.
- Core (ch)
- ch.Positioner
- ch.Content
- ch.Viewport
- ch.Calendar
- ch.Countdown
- ch.Datepicker
- ch.Expandable
- ch.Popover
- ch.Carousel
- ch.Tabs
- ch.Menu
- ch.Form
- ch.Validation
- CSS
- Removed
ch.cacheobject. - Removed
ch.debug()method. - Removed
ch.versionproperty. - Removed
ch.instancescollection. - Removed
ch.blinkmethod. - Removed
ch.keyboard; usech.shortcuts. - Removed
ch.Widgetclass; usech.Component. - Removed
ch.Controlsclass. - Removed
ch.Floatsclass; usech.Popover. - Removed
ch.events; use the followings properties:ch.onchangelayout,ch.onkeybackspace,ch.onkeydownarrow,ch.onkeyenter,ch.onkeyesc,ch.onkeyinput,ch.onkeyleftarrow,ch.onkeyrightarrow,ch.onkeytab,ch.onkeyuparrow,ch.onpointerdown,ch.onpointerenter,ch.onpointerleave,ch.onpointermove,ch.onpointertap,ch.onpointerup,ch.onresize,ch.onscroll
- Removed
ch.support.fixed. - Added
ch.support.fx. - Added
ch.support.touch.
- Removed
ch.util.hasOwn()method. - Removed
ch.util.inDom()method. - Removed
ch.util.indexproperty. - Removed
ch.util.isSelector()method. - Removed
ch.util.isTag()method. - Removed
ch.util.use()method. - Added
ch.util.getOffset(el)method. - Added
ch.util.getOuterDimensions(el)method. - Added
ch.util.getScroll(el)method.
### Options
- Removed
repositionoption. - Removed
elementoption; usetarget. - Removed
contextoption; usereference. - Removed
pointsoption; usesideandalign. - Removed
offsetoption; useoffsetXandoffsetY. - Added
positionedoption.
- Added
refresh()method (standalone version). - Removed
position('refresh')from Popovers; userefreshPosition().
ch.Positioner({
'element': '#element',
'context': '#context',
'points': 'lt rt',
'offset': '10 0'
});new ch.Positioner({
'target': $('#element'),
'reference': $('#reference'),
'offsetX': 10,
'offsetY': 0,
'side': 'center',
'align': 'center',
'positioned': 'fixed'
});We updated the content(options) ability to content(content, [options]).
- Added
contentparameter.-
AJAX.
component.content('http://www.some-url.com');
-
Plain text.
component.content('Some plain text.');
-
HTML Element.
var paragraph = document.createElement('p'); paragraph.innerHTML = 'Some text'; component.content(paragraph);
-
Query Selector.
component.content('#element');
component.content($('#element'));
-
- Added
options(optional) parameter.// Use only with AJAX content component.content('http://www.some-url.com', { 'method': 'POST', 'params': 'x-request=true', 'cache': false, 'async': true, 'waiting': '<div class="ch-loading-big"></div>' });
- Removed
contentLoadevent; usecontentdone. - Removed
contentErrorevent; usecontenterror. - Added
contentwaitingevent.
The viewport has been redesigned to ease viewport management.
### Properties
- Removed
elementproperty; use$el. - Added
orientationproperty.
- Removed
getOffset()method; usecalculateOffset(). - Removed
getSize()method; usecalculateDimensions(). - Removed
getPosition()method; useoffsetTop,offsetBottom,offsetRightoroffsetLeftoptions. - Added
calculateOrientation()method. - Added
inViewport()method. - Added
isVisible()method. - Added
refresh()method. - Added
ch.EventEmittermethods:on(),once(),off(),emit(),listener().
- Added
ch.onresizeevent. - Added
ch.onscrollevent.
- Removed
onSelectoption; suscribe to theselectevent.calendar.on('select', function () {...});
- Removed
onNextMonthoption; suscribe to thenextmonthevent.calendar.on('nextmonth', function () {...});
- Removed
onPrevMonthoption; suscribe to theprevmonthevent.calendar.on('prevmonth', function () {...});
- Removed
onNextYearoption; suscribe to thenextyearevent.calendar.on('nextyear', function () {...});
- Removed
onPrevYearoption; suscribe to theprevyearevent.calendar.on('prevyear', function () {...});
- Removed
typeproperty; usename. - Removed
elementproperty; use$container.
- Removed
reset()method. - Removed
today()method; usegetToday(). - Removed
to()method; usesetTo(). - Removed
from()method; usesetFrom(). - Removed
next()method; usenextMonth()ornextYear()methods. - Removed
prev()method; useprevMonth()orprevYear()methods. - Removed
trigger()method; useemit(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method.
- Added
nextmonthevent. - Added
nextyearevent. - Added
prevmonthevent. - Added
prevyearevent.
- Removed
typeproperty; usename. - Removed
elementproperty; use$trigger. - Added
$containerproperty.
- Removed
trigger()method; useemit(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method.
- Added
exceedevent.
### Options
-
Removed
onSelectoption; suscribe to theselectevent.datepicker.on('select', function () {...});
-
Removed
pointsoption; usesideandalign. -
Removed
closableoption; usehiddenby. -
Added
positionedoption. -
Added
offsetXoption. -
Added
offsetYoption.$('#element').datepicker({ 'closable': 'click', 'points': 'lt lt' });
$('#element').datepicker({ 'hiddenby': 'pointers-only', 'side': 'bottom', 'align': 'center' });
- Removed
typeproperty; usename. - Removed
elementproperty; use$field. - Added
$triggerproperty.
- Removed
trigger()method; useemit(). - Removed
prev()method; useprevMonth()orprevYear(). - Removed
next()method; usenextMonth()ornextYear(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method.
- Added
showevent. - Added
hideevent. - Added
resetevent. - Added
nextmonthevent. - Added
nextyearevent. - Added
prevmonthevent. - Added
prevyearevent.
### Options
- Removed
openoption. - Removed
onShowoption; suscribe to theshowevent.expandable.on('show', function () {...});
- Removed
onHideoption; suscribe to thehideevent. - Added
toggleoption. - Added
contentoption. - Added
containeroption.
$('#element').expandable({
'open': true
});$('#element').expandable().show();$('#element').expandable({
'toggle': true,
'content': 'Some content!',
'container': $('#container')
});- Removed
elementproperty; use$trigger. - Removed
typeproperty; usename. - Added
$containerproperty.
- Removed
isActive()method; useisShown(). - Removed
trigger()method; useemit(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method. - Added
content()method.
- Removed
contentLoadevent; usecontentdone. - Removed
contentErrorevent; usecontenterror. - Added
contentloadingevent.
Previously known as ch.Floats. It includes ch.Layer, ch.Modal, ch.Tooltip, ch.Transition, ch.Zoom and add the new component ch.Bubble (used for validation errors).
The Floats were redesigned as Popover to be the basic unit of a dialog window. It can be instantiated as a generic component too. Components that inherits from Popover, just adds specific functionality. For example, a Modal window shows and hides an underlay.
Popover also has the ability to be instantiated without the need of an existent element. It means you no longer need to create an element in memory (usually implemented with an <a> tag) to create a component:
$('<a>').modal();$.modal();- Removed
repositionoption. - Removed
onShowoption; suscribe to theshowevent.$('#element').layer().on('show', function () {});
- Removed
onHideoption; suscribe to thehideevent.$('#element').layer().on('hide', function () {});
- Removed
onContentLoadoption; suscribe to thecontentdoneevent.$('#element').layer().on('contentdone', function () {});
- Removed
onContentErroroption; suscribe to thecontenterrorevent.$('#element').layer().on('contenterror', function () {});
- Removed
classesoption; useaddClass. - Removed
pointsoption; usesideandalign. - Removed
offsetoption; useoffsetXandoffsetY. - Removed
eventoption; useshownby. The possible values are:shownby: 'pointertap'instead ofevent: 'click'(default),shownby: 'pointerenter'instead ofevent: 'hover'orshownby: 'none' - Removed
closableoption; usehiddenby. - Removed
closeButtonoption; the Close button appears with'hiddenby': 'button-only'or'hiddenby': 'all'options. - Updated
fx:Booleanoption; usefx:Boolean || String. - Updated
width:Number || Stringoption; usewidth:String. - Updated
height:Number || Stringoption; useheight:String. - Added
positionedoption. - Added
waitingoption.
$('#element').layer({
'classes': 'test',
'points': 'lt lb',
'offset': '0 10',
'event': 'click',
'closable': 'button',
'closeButton': true,
'fx': true,
'width': 100,
'height': 50
});$('#element').layer({
'addClass': 'test',
'side': 'bottom',
'align': 'left',
'offsetX': 0,
'offsetY': 10,
'shownby': 'pointerenter',
'hiddenby': 'button',
'fx': 'fadeIn',
'width': '100px',
'height': '50px',
'positioned': 'absolute',
'waiting': '<div class="ch-loading ch-loading-centered"></div>'
});- Removed
elementproperty; use$trigger. - Removed
typeproperty; usename. - Added
$containerproperty.
- Removed
closable()method. - Removed
trigger()method; useemit(). - Removed
isActive()method; useisShown(). - Removed
position()method; userefreshPosition(). By using when the component is hidden, it will refresh the position. Using when the component is shown, it will reconfigure the position. - Updated
width(Number || String)parameters; usewidth(String). - Updated
height(Number || String)parameters; useheight(String). - Added
init()method. - Added
enable()method. - Added
destroy()method. - Added
disable()method. - Added
getListeners()method. - Added
require()method. - Added
constructor()method.
- Removed
contentLoadevent; usecontentdone. - Removed
contentErrorevent; usecontenterror. - Added
contentwaitingevent.
The Dropdown was redesigned to share most of its code (and its public API) with components with similar behavior. That's why now it's part of ch.Popover.
- Removed
openoption. - Removed
iconoption. - Removed
repositionoption; reposition manually using the methodinViewport()in ch.Viewport and use this CSS for upwards Dropdown:.ch-dropdown[data-side="top"] { border-radius: 5px 5px 5px 0px; } .ch-dropdown-trigger-on[data-side="top"], .ch-dropdown-trigger-on[data-side="top"]:hover { border-radius: 0 0 3px 3px; }
- Removed
onShowoption; suscribe to theshowevent.$('#element').dropdown().on('show', function () {});
- Removed
onHideoption; suscribe to thehideevent.$('#element').dropdown().on('hide', function () {});
- Removed
pointsoption; usesideandalign. - Updated
fx:Booleanoption; usefx:Boolean || String. - Added
addClassoption. - Added
offsetXandoffsetY. - Added
shownbyoption. The possible values are:shownby: 'pointertap'(default),shownby: 'pointerenter'orshownby: 'none' - Added
hiddenbyoption. - Added
skinoption. This replaces the old way of instantiate a Dropdown skin, where you added the CSS classch-dropdown-skinto the main HTML element. - Added
shortcutsoption. - Added
widthoption. - Added
heightoption. - Added
positionedoption. - Added
waitingoption.
$('#element').dropdown({
'open': false,
'icon': true,
'reposition': true,
'points': 'lt lb',
'fx': false
});$('#element').dropdown({
'side': 'bottom',
'align': 'left',
'fx': 'fadeIn',
'offsetX': 0,
'offsetY': 10,
'shownby': 'pointerenter',
'hiddenby': 'pointerleave',
'skin': true,
'shortcuts': true,
'width': '100px',
'height': '50px',
'positioned': 'absolute',
'waiting': '<div class="ch-loading ch-loading-centered"></div>'
});- Removed
elementproperty; use$trigger. - Removed
typeproperty; usename. - Added
$containerproperty.
- Removed
trigger()method; useemit(). - Removed
isActive()method; useisShown(). - Removed
position()method; userefreshPosition(). - Added
init()method. - Added
enable()method. - Added
destroy()method. - Added
disable()method. - Added
getListeners()method. - Added
require()method. - Added
constructor()method. - Added
widthmethod. - Added
heightmethod. - Added
contentmethod.
- Added
contentdoneevent. - Added
contenterrorevent. - Added
contentwaitingevent.
- Removed
pageoption. - Removed
widthoption; it's an adaptive component, so set a width in CSS for the element that wraps the Carousel in your layout. - Removed
onNextoption; suscribe to thenextevent.$('#element').carousel().on('next', function () {});
- Removed
onPrevoption; suscribe to theprevevent.$('#element').carousel().on('prev', function () {});
- Removed
onRedrawoption; suscribe to theredrawevent.$('#element').carousel().on('redraw', function () {});
- Removed
onSelectoption; suscribe to theselectevent.$('#element').carousel().on('select', function () {});
- Removed
onItemsAddedoption; suscribe to theitemsaddevent.$('#element').carousel().on('itemsadd', function () {});
- Removed
asyncDataandasyncRenderoptions; useasyncoption anditemsaddevent:$('#element').carousel({ 'async': 10 }).on('itemsadd', function ($items) { // Inject content into the added <li> elements $.each($items, function (i, e) { $(e).html('Content into one of newly inserted <li> elements.'); }); });
- Removed
maxItemsoption; uselimitPerPage. - Updated
arrows:Stringoption; usearrows:Boolean. Now, when there is no arrows, you should handle the mask margin with CSS:.my-own-carousel .ch-carousel-mask { margin: 0; }
$('#element').carousel({
'width': 300,
'page': 2,
'asyncData': ['First', 'Second', 'Third'],
'asyncRender': function (a) { return a + 'element'; },
'maxItems': 2,
'arrows': 'over'
});$('#element').carousel({
'async': 3, // Use 'itemsadd' events to inject content into the new <li> elements
'limitPerPage': 2,
'arrows': false
});- Removed
typeproperty; usename. - Removed
elementproperty.
- Removed
arrows()method. - Removed
page()method. - Removed
itemsPerPage()method. - Removed
play()andpause()methods; use the extension ch.carousel.autoSliding.js from the /extension folder in repository. - Removed
redraw()method; userefresh(). - Removed
trigger()method; useemit(). - Added
init()method. - Added
enable()method. - Added
destroy()method. - Added
disable()method. - Added
getListeners()method. - Added
require()method. - Added
constructor()method.
- Removed
redrawevent; userefresh. - Removed
itemsAddedevent; useitemsadd.
### Options
- Removed
onSelectoption; suscribe to theselectevent.tabs.on('select', function () {...});
- Removed
onContentLoadoption; suscribe to thecontentdoneevent.tabs.on('contentdone', function () {...});
- Removed
onContentErroroption; suscribe to thecontenterrorevent.tabs.on('contenterror', function () {...});
- Removed
selectedoption.
- Removed
elementproperty; use$container. - Removed
childrencollection; usetabpanels. - Removed
typeproperty; usename. - Added
$panelproperty. - Added
$triggersproperty.
- Removed
isActive()method; useisShown(). - Removed
trigger()method; useemit(). - Removed
select()method; useshow(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method. - Added
content()method. - Added
getShown()method.
- Removed
contentLoadevent; usecontentdone. - Removed
contentErrorevent; usecontenterror. - Added
contentloadingevent. - Added
selectevent.
### Options
- Removed
onSelectoption; suscribe to theselectevent.menu.on('select', function () {...});
- Removed
selectedoption.
- Removed
elementproperty; use$container. - Removed
typeproperty; usename. - Added
foldcollection.
- Removed
trigger()method; useemit(). - Removed
select()method; useshow(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method. - Added
content()method. - Added
hide()method.
The ch.Form API has been redesigned to easy manipulation. Now, you have more control on the submit event and you decide what you want to do.
- Removed
beforeSubmitoption. - Removed
afterSubmitoption. - Removed
afterValidateoption. - Removed
beforeValidateoption; suscribe to thebeforevalidateevent.form.on('beforevalidate', function () {...});
- Removed
onValidateoption; suscribe to thesuccessevent.validation.on('success', function () {...});
- Removed
onErroroption; suscribe to theerrorevent.validation.on('error', function () {...});
- Removed
onClearoption; suscribe to theclearevent.validation.on('clear', function () {...});
- Removed
onResetoption; suscribe to theresetevent.validation.on('reset', function () {...});
- Removed
messagesproperty. - Removed
elementproperty; use$container. - Removed
typeproperty; usename. - Removed
childrencollection; usevalidations. - Added
errorscollection.
- Removed
submit()method. - Removed
trigger()method; useemit(). - Removed
isValidated()method; usehasError(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method. - Added
enable()method. - Added
disable()method.
-
Removed
beforeSubmit,afterSubmitandsubmitevents. Use native event:form.on('beforeSubmit', function () {...}); form.on('submit', function () {...}); form.on('afterSubmit', function () {...});
$('.myForm').on('submit', function (event) { // Some code here! if (!form.hasError()) { event.preventDefault(); // Some code here! } });
-
Removed
afterValidateevent. -
Removed
validateevent; usesuccess.form.on('success', function (event) { event.preventDefault(); // Some code here! });
-
Removed
beforeValidateevent; usebeforevalidate. -
Updated
errorevent; it now receives a collection with errors:form.on('error', function (errors) {...});
The ch.Validation API has been redesigned to easy manipulation. You can use validations interfaces: ch.Custom, ch.Required, ch.String, ch.Email, ch.Url, ch.MaxLength, ch.MinLength, ch.Number, ch.Max and ch.Min.
- Removed
ch.Price
- Removed
classesoption. - Removed
beforeValidateoption. - Removed
afterValidateoption. - Removed
beforeValidateoption; suscribe to thebeforevalidateevent.validation.on('beforevalidate', function () {...});
- Removed
onValidateoption; suscribe to thesuccessevent.validation.on('success', function () {...});
- Removed
onErroroption; suscribe to theerrorevent.validation.on('error', function () {...});
- Removed
onClearoption; suscribe to theclearevent.validation.on('clear', function () {...});
- Removed
contentoption; usemessage.$('#element').required({ 'message': 'Some message!' })
- Removed
conditionoption; useconditions. - Removed
contextoption; usereference. - Removed
pointsoption; usesideandalign. - Removed
offsetoption; useoffsetXandoffsetY.
$('#element').validation({
'condition': {
'name': 'required'
},
'context': '#context',
'points': 'lt rt',
'offset': '10 0'
});$('#element').validation({
'conditions': [
{
'name': 'required'
},
{
'name': 'custom-name',
'fn': function (value) { return value === "custom";},
'message': 'This is a custom validation.'
}
],
'reference': $('#reference'),
'offsetX': 10,
'offsetY': 0,
'side': 'left',
'align': 'top'
});- Removed
validatorproperty. - Removed
elementproperty; use$trigger. - Removed
helperproperty; usebubble. - Removed
floatproperty; usebubble. - Removed
typeproperty; usename. - Added
errorproperty. - Added
conditionsproperty.
- Removed
toggleEnable()method. - Removed
isActive()method; useisShown(). - Removed
float.position()method; usebubble.refreshPosition(). - Removed
trigger()method; useemit(). - Added
getListeners()method. - Added
require()method. - Added
destroy()method.
- Removed
beforeValidateevent. - Removed
validatedevent; usesuccess.validation.on('success', function () {...});
- Removed
afterValidateevent.
The ch.Custom API has been redesigned to create and manipulate multiple custom validations instance with the same trigger.
Now, you should give a name to your custom validations.
$('#element').custom(function (value) {
return value === 'Something';
}, 'This is a custom Validation!');$('#element').custom('some-name', function (value) {
return value === 'Something';
}, 'This is a custom Validation!');- Removed
url. - Removed
content. - Removed
suggestions. - Removed
jsonpCallback. - Removed
pointsoption; usesideandalign.
var ac = $('.example').autoComplete({
'url': 'http://www.chico-ui.com.ar/suggest?q=',
'jsonpCallback': 'autoComplete'
});
function autoComplete(data) {
ac.suggest(data);
}var ac = $('.example').autoComplete();
ac.on('type', function (userInput) {
$.ajax({
'url': 'http://www.chico-ui.com.ar/suggest?q=' + userInput + '&callback=ac.suggest',
'dataType': 'jsonp',
'cache': false,
'global': true,
'context': window,
'jsonp': 'ac.suggest',
'crossDomain': true
});
});Example with the MercadoLibre API
var mercadolibre = $('.autoComplete3').autoComplete();
var parseMLAPIResults = function (results) {
var data = [];
results[2].suggested_queries.forEach(function (e, i) {
data.push(e.q);
});
mercadolibre.suggest(data);
}
mercadolibre.on('type', function (userInput) {
$.ajax({
'url': 'http://suggestgz.mlapps.com/sites/MLA/autosuggest?q='+ userInput +'&v=1&callback=parseMLAPIResults',
'dataType': 'jsonp',
'cache': false,
'global': true,
'context': window,
'jsonp': 'parseMLAPIResults',
'crossDomain': true
});
});- Added
type
To expand the messages boxes variety, now you have to include the icon by yourself and the CSS class name ch-box-icon to the container:
<div class="ch-box-error">Oops, something wrong happened</div><div class="ch-box-icon ch-box-error"><i class="ch-icon-remove-sign"></i>Oops, something wrong happened</div>
