diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index a93e9853fc..b892670d21 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -1698,12 +1698,9 @@ otherFields[creatorField] = value; var lastName = otherFields.lastName; - //Handle \n\r delimited entries - if (lastName.search('\r') > -1 || lastName.search('\n') > -1) { - lastName = lastName.replace('\r\n','\n'); - lastName = lastName.replace('\r','\n'); - var rawNameArray = lastName.split('\n'); - + //Handle \n\r and \n delimited entries + var rawNameArray = lastName.split(/\r\n?|\n/); + if (rawNameArray.length > 1) { //Save tab direction and add creator flags since they are reset in the //process of adding multiple authors var tabDirectionBuffer = this._tabDirection; @@ -1713,16 +1710,7 @@ this._addCreatorRow = false; //Filter out bad names - var nameArray = new Array(); - var counter = 0; - var tempName = ''; - for each(tempName in rawNameArray) { - if (tempName.length > 0) { - //Put further error checking of tempName here - nameArray[counter] = tempName; - counter++; - } - } + var nameArray = [tempName for each(tempName in rawNameArray) if(tempName)]; //If not adding names at the end of the creator list, make new creator //entries and then shift down existing creators. @@ -1742,25 +1730,25 @@ } //Add the creators in lastNameArray one at a time - var tempFields=otherFields; for each(tempName in nameArray) { - // Check for comma to determine creator name format - tempFields.fieldMode = (tempName.indexOf('\t') == -1) ? 1 : 0; - if (tempFields.fieldMode == 0) { - tempFields.lastName=tempName.split('\t')[0]; - tempFields.firstName=tempName.split('\t')[1]; + // Check for tab to determine creator name format + otherFields.fieldMode = (tempName.indexOf('\t') == -1) ? 1 : 0; + if (otherFields.fieldMode == 0) { + otherFields.lastName=tempName.split('\t')[0]; + otherFields.firstName=tempName.split('\t')[1]; } else { - tempFields.lastName=tempName; + otherFields.lastName=tempName; + otherFields.firstName=''; } - this.modifyCreator(creatorIndex,tempFields); + this.modifyCreator(creatorIndex,otherFields); creatorIndex++; } this._tabDirection = tabDirectionBuffer; this._addCreatorRow = (creatorsToShift==0) ? addCreatorRowBuffer : false; if (this._tabDirection == 1) { this._lastTabIndex = parseInt(tabIndexBuffer,10) + 2*(nameArray.length-1); - if (tempFields.fieldMode == 0) { + if (otherFields.fieldMode == 0) { this._lastTabIndex++; } } diff --git a/chrome/content/zotero/bindings/tagsbox.xml b/chrome/content/zotero/bindings/tagsbox.xml index 2ca4cd030c..50ef77e363 100644 --- a/chrome/content/zotero/bindings/tagsbox.xml +++ b/chrome/content/zotero/bindings/tagsbox.xml @@ -427,10 +427,10 @@ // Tag id encoded as 'tag-1234' var id = row.getAttribute('id').split('-')[1]; - var newlinePresent = (value.search('\r') > -1 || value.search('\n') > -1); + var tagArray = value.split(/\r\n?|\n/); if (saveChanges) { - if (id && newlinePresent != true) { + if (id && (tagArray.length < 2)) { if (value) { var origTagIndex = this.item.getTagIndex(id); var changed = tagsbox.replace(id, value); @@ -453,16 +453,13 @@ } } } + } // New tag else { //Check for newlines or carriage returns used as delimiters //in a series of tags added at once. Add each tag //separately. - if (newlinePresent) { - value = value.replace('\r\n','\n'); - value = value.replace('\r','\n'); - var nameArray = value.split('\n'); - + if (tagArray.length > 1) { var extremeTag = false; var nextTag = false; if (this._tabDirection == -1) { @@ -479,7 +476,7 @@ } } - id = this.item.addTags(nameArray); + id = this.item.addTags(tagArray); if (extremeTag) { if (this._tabDirection == 1) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index fd06240484..e09fdfcc58 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1,7 +1,7 @@ /* ***** BEGIN LICENSE BLOCK ***** - Copyright ¬© 2009 Center for History and New Media + Copyright © 2009 Center for History and New Media George Mason University, Fairfax, Virginia, USA http://zotero.org @@ -2703,7 +2703,7 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { // Strip "storage:" var path = row.path.substr(8); // setRelativeDescriptor() silently uses the parent directory on Windows - // if the filename contains certain characters, so strip them ‚Äî + // if the filename contains certain characters, so strip them — // but don't skip characters outside of XML range, since they may be // correct in the opaque relative descriptor string // @@ -3541,21 +3541,19 @@ Zotero.Item.prototype.addTag = function(name, type) { Zotero.Item.prototype.addTags = function (tags, type) { Zotero.DB.beginTransaction(); try { - var tagIDarray = []; - var counter = 0; + var tagIDArray = []; var tempID = false; for (var i = 0; i < tags.length; i++) { tempID = this.addTag(tags[i], type); if (tempID) { - tagIDarray[counter] = tempID; - counter++; + tagIDArray.push(tempID); } } - tagIDarray = (tagIDarray.length>0) ? tagIDarray : false; + tagIDArray = (tagIDArray.length>0) ? tagIDArray : false; Zotero.DB.commitTransaction(); - return tagIDarray; + return tagIDArray; } catch (e) { Zotero.DB.rollbackTransaction(); @@ -3637,20 +3635,19 @@ Zotero.Item.prototype.getTagIDs = function() { return Zotero.DB.columnQuery(sql, this.id); } -//Return the index of tagID in the list of the item's tags -//sorted in alphabetical order. +/** +* Return the index of tagID in the list of the item's tags sorted in alphabetical order. +*/ Zotero.Item.prototype.getTagIndex = function(tagID) { var tags = this.getTags(); - var tagIndex=-1; for (var i=0;i