Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Turn off listview icons by default so no need to use data-icon="false" everywhere and override where necessary #4570

Closed
@stevegrove

Description

@stevegrove

INITIAL POST - https://forum.jquery.com/topic/turn-off-listview-icons-by-default-so-no-need-to-use-data-icon-false-everywhere-and-override-where-necessary

JQM 1.1.0 FINAL

I did not want icons on my listview elements except where explicitly defined - basically turning the default behaviour on its head:

  1. Add this before the jquery.mobile.js is loaded.
<script>
$(document).bind("mobileinit", function(){
  $.mobile.listview.prototype.options.icon = false;
});
</script>
  1. NEED TO EDIT THE CORE JQUERY MOBILE FUNCTION FOR THIS TO WORK:

Within $.widget( "mobile.listview", $.mobile.widget ) is the code to define the default icon which currently stands as shown below in refresh: function( create ) around line 4982

if ( a.length ) {
icon = item.jqmData("icon");

This obviously takes no notice of the "options.icon" flag set in step (1) for the list view and will show an icon for all

  • elements where "data-icon" is not defined so I changed the logic to test for explicit values set per
  • element and then fall back to the options.icon value set in the mobile init.

    if ( a.length ) {
    var override = item.jqmData("icon");
    icon = (override !== undefined) ? override : (o.icon !== undefined) ? o.icon : override;
    
    1. Wherever you want an icon just use the data-icon directive as normal e.g.
    <ul data-role="listview" data-inset="true">
    <li data-icon="star" ><a href="#">Icon</a></li>
    <li><a href="#">No Icon</a></li
    </ul>
    

    So now you can remove all those <li data-icon="false"> statements and use <li> instead. I don't think there are any regressions with this update, behaviour will be as current 1.1.0 if the listview option.icon flag is left undefined.

  • Metadata

    Metadata

    Assignees

    No one assigned

      Type

      No type

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions