From 76fd029e0cd92f74656dde2a0c2c3808f55dfead Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 4 Jun 2016 20:34:51 -0700 Subject: [PATCH] [CB-11120] Allow short/display name in config.xml This adds support for a "short" display name to be specified as an attribute of the `name` element in config.xml. This attribute is defined in the W3C Widgets spec, on which config.xml is loosely based: https://www.w3.org/TR/widgets/#the-short-attribute --- .../spec/ConfigParser/ConfigParser.spec.js | 13 +++++++++++++ cordova-common/src/ConfigParser/ConfigParser.js | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/cordova-common/spec/ConfigParser/ConfigParser.spec.js b/cordova-common/spec/ConfigParser/ConfigParser.spec.js index f3e334d64..fa4955054 100644 --- a/cordova-common/spec/ConfigParser/ConfigParser.spec.js +++ b/cordova-common/spec/ConfigParser/ConfigParser.spec.js @@ -83,7 +83,20 @@ describe('config.xml parser', function () { cfg.setName('this.is.bat.country'); expect(cfg.name()).toEqual('this.is.bat.country'); }); + + describe('short name', function() { + it('should default to the app name', function() { + expect(cfg.shortName()).toEqual('Hello Cordova'); + }); + + it('should allow setting the app short name', function() { + cfg.setShortName('Hi CDV'); + expect(cfg.name()).toEqual('Hello Cordova'); + expect(cfg.shortName()).toEqual('Hi CDV'); + }); + }); }); + describe('preference', function() { it('Test 010 : should return the value of a global preference', function() { expect(cfg.getPreference('fullscreen')).toEqual('true'); diff --git a/cordova-common/src/ConfigParser/ConfigParser.js b/cordova-common/src/ConfigParser/ConfigParser.js index e477a8984..cd718ded5 100644 --- a/cordova-common/src/ConfigParser/ConfigParser.js +++ b/cordova-common/src/ConfigParser/ConfigParser.js @@ -116,6 +116,16 @@ ConfigParser.prototype = { var el = findOrCreate(this.doc, 'name'); el.text = name; }, + shortName: function() { + return this.doc.find('name').attrib['short'] || this.name(); + }, + setShortName: function(shortname) { + var el = findOrCreate(this.doc, 'name'); + if (!el.text) { + el.text = shortname; + } + el.attrib['short'] = shortname; + }, description: function() { return getNodeTextSafe(this.doc.find('description')); },