Skip to content

Commit f148dbd

Browse files
committed
Refactored $.mobilize further to optimize form and controlgroup init. Added some notes
1 parent 6eee755 commit f148dbd

File tree

1 file changed

+28
-40
lines changed

1 file changed

+28
-40
lines changed

js/jQuery.mobile.js

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,24 @@
247247
var $el = $(this);
248248

249249
//hide no-js content
250-
$el.find('[data-role="nojs"]').addClass('ui-nojs');
250+
$el.find('[data-role="nojs"]').addClass('ui-nojs');
251+
252+
$el.find('input[type=radio],input[type=checkbox]').customCheckboxRadio();
253+
$el.find('button, input[type=submit], input[type=reset], input[type=image]').customButton();
254+
$el.find('input[type=text],input[type=number],input[type=password],textarea').customTextInput();
255+
$el.find("input, select").filter('[data-role="slider"]').slider();
256+
$el.find('select').not('[data-role="slider"]').customSelect();
257+
258+
/*temporary datepicker workaround */
259+
$el.find('input[type=date]').hide().after( $('<div />').datepicker() );
260+
$('.ui-datepicker-header').addClass('ui-body-c ui-corner-top').removeClass('ui-corner-all');
261+
$('.ui-datepicker-prev').buttonMarkup({iconPos: 'notext', icon: 'arrow-l', shadow: true, corners: true});
262+
$('.ui-datepicker-next').buttonMarkup({iconPos: 'notext', icon: 'arrow-r', shadow: true, corners: true});
263+
$('.ui-datepicker-calendar thead').remove();
264+
$('.ui-datepicker-calendar .ui-btn-text span').attr('class','');
265+
$('.ui-datepicker-calendar td').addClass('ui-btn-up-c');
266+
$('.ui-datepicker-calendar a').buttonMarkup({corners: false, shadow: false});
267+
/* //temporary datepicker workaround */
251268

252269
//pre-find data els
253270
var $dataEls = $el.find('[data-role]').andSelf().each(function() {
@@ -268,51 +285,21 @@
268285
case 'ajaxform':
269286
$this[role]();
270287
break;
288+
case 'controlgroup':
289+
// FIXME for some reason this has to come before the form control stuff (see above)
290+
$this.controlgroup({
291+
direction: $this.attr("data-type")
292+
});
293+
break;
271294
}
272295
});
273296

274297
//fix toolbars
275298
$el.fixHeaderFooter();
276299

277-
//form elements
278-
var checksradios = 'input[type=radio],input[type=checkbox]',
279-
buttonInputs = 'button, input[type=submit], input[type=reset], input[type=image]',
280-
textInputs = 'input[type=text],input[type=number],input[type=date],input[type=password],textarea',
281-
dateInputs = 'input[type=date]',
282-
sliders = '[data-role="slider"]',
283-
selects = 'select';
284-
285-
$formEls = $el.find( [checksradios, buttonInputs, textInputs, dateInputs, sliders, selects].join(',') ).not('.ui-nojs');
286-
287-
$formEls.filter(checksradios).customCheckboxRadio();
288-
//custom buttons
289-
$formEls.filter(buttonInputs).customButton();
290-
//custom text inputs
291-
$formEls.filter(textInputs).customTextInput();
292-
293-
/*temporary datepicker workaround */
294-
$formEls.filter(dateInputs).hide().after( $('<div />').datepicker() );
295-
$('.ui-datepicker-header').addClass('ui-body-c ui-corner-top').removeClass('ui-corner-all');
296-
$('.ui-datepicker-prev').buttonMarkup({iconPos: 'notext', icon: 'arrow-l', shadow: true, corners: true});
297-
$('.ui-datepicker-next').buttonMarkup({iconPos: 'notext', icon: 'arrow-r', shadow: true, corners: true});
298-
$('.ui-datepicker-calendar thead').remove();
299-
$('.ui-datepicker-calendar .ui-btn-text span').attr('class','');
300-
$('.ui-datepicker-calendar td').addClass('ui-btn-up-c');
301-
$('.ui-datepicker-calendar a').buttonMarkup({corners: false, shadow: false});
302-
/* //temporary datepicker workaround */
303-
304-
305-
//sliders
306-
$formEls.filter(sliders).slider();
307-
//selects
308-
$formEls.filter(selects).not('[data-role="slider"]').customSelect();
309-
310-
//vertical controlgroups
311-
$dataEls.filter('[data-role="controlgroup"]:not([data-type="horizontal"])').controlgroup();
312-
//horizontal controlgroups
313-
$dataEls.filter('[data-role="controlgroup"][data-type="horizontal"]').controlgroup({direction: 'horizontal'});
314-
315300
//add back buttons to headers that don't have them
301+
// FIXME make that optional?
302+
// TODO don't do that on devices that have a native back button?
316303
var backBtn = $el.find('.ui-header a.ui-back');
317304
if(!backBtn.length){
318305
backBtn = jQuery('<a href="#" class="ui-back" data-icon="arrow-l"></a>').appendTo($el.find('.ui-header'));
@@ -325,12 +312,13 @@
325312
//make all back buttons mimic the back button (pre-js, these links are usually "home" links)
326313
backBtn
327314
.click(function(){
315+
// FIXME if you navigated from some page directly to subpage (ala .../#_form-controls.html), back button will actually go to the previous page, instead of the parent page
328316
history.go(-1);
329317
return false;
330318
})
331319
.find('.ui-btn-text').text(backBtnText);
332320

333-
$el.attr('data-mobilized',true);
321+
$el.attr('data-mobilized', true);
334322
});
335323
};
336324

0 commit comments

Comments
 (0)