Nice Exhibit Ted!

I've added it to the Exhibit In-The-Wild wiki section.

Regards,

Larry




________________________________
From: Ted <[email protected]>
To: SIMILE Widgets <[email protected]>
Sent: Thursday, January 8, 2009 3:03:18 PM
Subject: Re: Custom sort terms


Thanks David.  Changing the code you pointed out allowed me to
generate the sort order I wanted.

Here it is:
http://libdev.law.columbia.edu/neweres/sorted.html

A nice feature would be if you could specify a sort order in an
external file, like with plural label terms, and then read that in to
this function for customized sorting.  I would be willing to work on
this, but I'm not sure where to begin.

Thanks again.


var processNonNumericLevel = function(items, index, values, valueType)
{
        var keys = [];
        var compareKeys;
        var retrieveItems;
        var order = orders[index];

        if (valueType == "item") {
            values.visit(function(itemID) {
                var label = database.getObject(itemID, "label");
                label = label != null ? label : itemID;
                keys.push({ itemID: itemID, display: label });
            });

            compareKeys = function(key1, key2) {
                var c = key1.display.localeCompare(key2.display);
                return c != 0 ? c : key1.itemID.localeCompare
(key2.itemID);
            };

            retrieveItems = order.forward ? function(key) {
                return database.getSubjects(key.itemID,
order.property, null, items);
            } : function(key) {
                return database.getObjects(key.itemID, order.property,
null, items);
            };
        }else if (order.property == "type" && order.forward) {
            var map = {
               "US Legal Databases" : 0,
               "Periodical and Treatise Indexes" : 1,
           "Foreign Law Databases": 2,
           "International Law Databases": 3,
               //... add everything here ...
            };
            values.visit(function(typeID) {
                keys.push({ display: typeID, index: typeID in map ? map
[typeID] : -1 });
            });
            compareKeys = function(key1, key2) {
                var c = key1.index - key2.index;
                return c != 0 ? c : key1.display.localeCompare
(key2.display);
            };
            retrieveItems = function(key) {
                return database.getSubjects(key.display, "type", null,
items);
            };
        }else { //text
            values.visit(function(value) {
                keys.push({ display: value });
            });

            compareKeys = function(key1, key2) {
                return key1.display.localeCompare(key2.display);
            };
            retrieveItems = order.forward ? function(key) {
                return database.getSubjects(key.display,
order.property, null, items);
            } : function(key) {
                return database.getObjects(key.display,
order.property, null, items);
            };
        }

        keys.sort(function(key1, key2) {
            return (order.ascending ? 1 : -1) * compareKeys(key1,
key2);
        });

        for (var k = 0; k < keys.length; k++) {
            var key = keys[k];
            key.items = retrieveItems(key);
            if (!settings.showDuplicates) {
                items.removeSet(key.items);
            }
        }

        return keys;
    };

HTML
<div ex:role="view"

                     ex:showAll="true"
                     ex:orders=".type, .name"
                     ex:showToolbox="false"
                     class="exhibit-body" >
    </div>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SIMILE Widgets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simile-widgets?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to