r2809 - changed the format option to a callback function, allowing it to be more freeform.
Author: scottjehl
Date: Thu Jun 18 12:44:28 2009
New Revision: 2809
Modified:
branches/labs/selectmenu/index.html
branches/labs/selectmenu/ui.selectmenu.js
Log:
changed the format option to a callback function, allowing it to be more
freeform.
Modified: branches/labs/selectmenu/index.html
==============================================================================
--- branches/labs/selectmenu/index.html (original)
+++ branches/labs/selectmenu/index.html Thu Jun 18 12:44:28 2009
@@ -80,14 +80,29 @@
});
- //format options
- var addressFormatting = [
- {find:/^([^\-]+) \- /g, rep: '<span
class="ui-selectmenu-item-header">$1</span>'},
- {find:/([^\|><]+) \| /g, rep: '<span
class="ui-selectmenu-item-content">$1</span>'},
- {find:/([^\|><\(\)]+) (\()/g, rep: '<span
class="ui-selectmenu-item-content">$1</span>$2'},
- {find:/([^\|><\(\)]+)$/g, rep: '<span
class="ui-selectmenu-item-content">$1</span>'},
- {find:/(\([^\|><]+\))$/g, rep: '<span
class="ui-selectmenu-item-footer">$1</span>'}
- ];
+
+
+ //a custom format option callback
+ var addressFormatting = function(text){
+ var newText = text;
+ //array of find replaces
+ var findreps = [
+ {find:/^([^\-]+) \- /g, rep: '<span
class="ui-selectmenu-item-header">$1</span>'},
+ {find:/([^\|><]+) \| /g, rep: '<span
class="ui-selectmenu-item-content">$1</span>'},
+ {find:/([^\|><\(\)]+) (\()/g, rep: '<span
class="ui-selectmenu-item-content">$1</span>$2'},
+ {find:/([^\|><\(\)]+)$/g, rep: '<span
class="ui-selectmenu-item-content">$1</span>'},
+ {find:/(\([^\|><]+\))$/g, rep: '<span
class="ui-selectmenu-item-footer">$1</span>'}
+ ];
+
+ for(var i in findreps){
+ newText = newText.replace(findreps[i].find, findreps[i].rep);
+ }
+ return newText;
+ }
+
+
+
+
</script>
Modified: branches/labs/selectmenu/ui.selectmenu.js
==============================================================================
--- branches/labs/selectmenu/ui.selectmenu.js (original)
+++ branches/labs/selectmenu/ui.selectmenu.js Thu Jun 18 12:44:28 2009
@@ -386,14 +386,7 @@
else { this.open(event); }
},
_formatText: function(text){
- var o = this.options;
- var newText = text;
- if(o.format){
- for(var i in o.format){
- newText = newText.replace(o.format[i].find, o.format[i].rep);
- }
- }
- return newText;
+ return this.options.format ? this.options.format(text) : text;
},
_selectedIndex: function(){
return this.element[0].selectedIndex;