Skip to content

Commit

Permalink
Merge pull request zmanring-zz#46 from rocketraman/issue-45
Browse files Browse the repository at this point in the history
Issue 45
  • Loading branch information
Zach Manring committed Jan 17, 2014
2 parents b637989 + f10b882 commit 8ee28ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 56 deletions.
91 changes: 36 additions & 55 deletions assets/javascripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,8 @@
return defer.promise;
};

Delicious.fetchLinks = (function() {
return function fetchLinks() {
var defer = $q.defer(),
hash = localStorage.getItem('chrome-ext-delicious'),
options = {
method: 'GET',
url: 'https://api.del.icio.us/v1/posts/all?results=10000',
headers: {
'Authorization': 'Basic ' + hash
},
transformResponse: _parseLinksResponse
};

$http(options).then(function(resp) {
localStorage.setItem('chrome-ext-delicious-links', JSON.stringify(resp.data));
defer.resolve(resp.data);
});

return defer.promise;
};

function _parseLinksResponse(data) {
Delicious.parseLinks = (function() {
return function parseLinksResponse(data) {
var json = xml.xmlToJSON(data);

function _parseLink(rawLink) {
Expand All @@ -254,7 +234,8 @@
link['domain'] = link['href'].replace(/^(.*\/\/[^\/?#]*).*$/, '$1');
link['private'] = (link.shared === 'no') ? true : false;

link.tags = link.tag.split(' ');
var split = (localStorage.getItem('chrome-ext-delicious-parse-single-space')) === 'true' ? / [ ]?/ : " ";
link.tags = link.tag.split(split);
delete link.tag;

return link;
Expand All @@ -270,6 +251,28 @@
}
}());

Delicious.fetchLinks = (function() {
return function fetchLinks() {
var defer = $q.defer(),
hash = localStorage.getItem('chrome-ext-delicious'),
options = {
method: 'GET',
url: 'https://api.del.icio.us/v1/posts/all?results=10000',
headers: {
'Authorization': 'Basic ' + hash
},
transformResponse: Delicious.parseLinks
};

$http(options).then(function(resp) {
localStorage.setItem('chrome-ext-delicious-links', JSON.stringify(resp.data));
defer.resolve(resp.data);
});

return defer.promise;
};
}());

Delicious.getDeliciousLinkDataByUrl = (function () {
return function getDeliciousLinkDataByUrl(url) {
var defer = $q.defer(),
Expand All @@ -280,7 +283,7 @@
headers: {
'Authorization': 'Basic ' + hash
},
transformResponse: _parseLinksResponse
transformResponse: Delicious.parseLinks
};

$http(options).then(function(resp) {
Expand All @@ -289,37 +292,6 @@

return defer.promise;
};

function _parseLinksResponse(data) {
var json = xml.xmlToJSON(data);

function _parseLink(rawLink) {
var link = {};

// Remove '@' symbols from keys
for (var key in rawLink) {
var k = key.split('@')[1];
link[k] = rawLink[key];
}

// domain root
link['domain'] = link['href'].replace(/^(.*\/\/[^\/?#]*).*$/, '$1');
link['private'] = (link.shared === 'no') ? true : false;

link.tags = link.tag.split(' ');
delete link.tag;

return link;
}

if ( ! json.posts) {
return [];
} else if (angular.isArray(json.posts.post)) {
return json.posts.post.map(_parseLink);
} else {
return [_parseLink(json.posts.post)];
}
}
}());

Delicious.getUpdate = (function() {
Expand Down Expand Up @@ -834,6 +806,15 @@
$scope.$watch('filterTime', function(value) {
localStorage.setItem('chrome-ext-delicious-filter-time', value);
});

// api options
$scope.parseSingleSpace = (localStorage.getItem('chrome-ext-delicious-parse-single-space')) === 'true' ? true : false;

$scope.$watch('parseSingleSpace', function(value) {
localStorage.setItem('chrome-ext-delicious-parse-single-space', value);
// need to reload links when this setting is changed
localStorage.removeItem('chrome-ext-delicious-links');
});
});


Expand Down
12 changes: 11 additions & 1 deletion updated.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>@Delicious 2.9.5</h1>

<section class="animated fadeIn">

<h4 class="latest">Note: When using Delicious.com and this extension, multiple tags could return as one tag. This is due to how the API returns these tags. Sometimes they're returned as double-spaced delimited, sometimes tags are single space delimited. This extension uses double-spaced delimiting for the ability to have multi-word tags. So as long as you save tags through this extension it will work in both locations. -Zach</h4>
<h4 class="latest">Note: When using Delicious.com and this extension, multiple tags could return as one tag. This is due to how the API returns these tags. Sometimes they're returned as double-spaced delimited, sometimes tags are single space delimited. This extension uses double-spaced delimiting for the ability to have multi-word tags. So as long as you save tags through this extension it will work in both locations. If none of your delicious tags contain any spaces, then you can check the "My tags have no spaces" option, and all tags will be delimited correctly. -Zach</h4>

<p class="twitter">Get New Feature updates on Twitter - <a href="https://twitter.com/@deliciousext">@DeliciousExt</a></p>

Expand All @@ -22,6 +22,9 @@ <h4 class="latest">Note: When using Delicious.com and this extension, multiple t
<h2>New Features</h2>
<ul>
<li class="latest">
Added option to single-space delimit tags when user's tags contain no spaces. Thanks @Rocketraman
</li>
<li>
Added ability for selected text to auto-fill extended description field when using context menu - Thanks for the idea @Tomasz
</li>
<li>
Expand Down Expand Up @@ -66,6 +69,13 @@ <h2>Changelog</h2>
<p>Found an issue or want to see a feature implemented? <a href="https://chrome.google.com/webstore/support/pplcoloalmjgljnbpkhcojpjnjbggppe?hl=en&gl=US#bug" target="_blank">Send Feedback</a></p>

<article class="latest">
<h4>Version 2.9.6 (in development)</h4>
<ul>
<li>Feature - handle single space delimited tags via user option.</li>
</ul>
</article>

<article>
<h4>Version 2.9.5</h4>
<ul>
<li>Fixed - increased limitation of bookmarks from 1000 to 10000 - Thanks @Matteo</li>
Expand Down
5 changes: 5 additions & 0 deletions views/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ <h1>Options</h1>

</fieldset>

<fieldset>
<legend>API Settings (Advanced)</legend>
<input type="checkbox" id="parse-single-space" ng-model="parseSingleSpace" ng-checked="parseSingleSpace" />
<label for="parse-single-space">Parse single space between tags as a delimiter (my tags don't have spaces)</label>
</fieldset>
</main>
</section>

0 comments on commit 8ee28ee

Please sign in to comment.