Skip to content
Browse files

several checkins from a tydget-like results widget.

  • Loading branch information...
1 parent 103261c commit de4c7d6a67e284f6a33fe5dd76bb5da142704cba Natalie Po committed Mar 24, 2010
Showing with 1,751 additions and 0 deletions.
  1. +23 −0 first.js
  2. +15 −0 index.html
  3. +45 −0 lovelace_sample.html
  4. +1,312 −0 results.json
  5. +356 −0 typepad_parsing.js
View
23 first.js
@@ -0,0 +1,23 @@
+<script type="text/javascript" >
+$(function() {
+ $(".more").click(function() {
+ var element = $(this);
+ var msg = element.attr("id");
+ $("#morebutton").html('<img src="ajax-loader.gif" />');
+
+ $.ajax({
+ type: "GET",
+ url: "http://api.typepad.com/assets.js?q=ada%20lovelace&max-results=2&callback=ada_callback",
+ data: "",
+ cache: false,
+ success: function(html){
+
+ $("#more_updates").append(html);
+ $(".more").remove();
+
+ }
+ });
+ return false;
+ });
+});
+</script>
View
15 index.html
@@ -0,0 +1,15 @@
+<html>
+<head>
+ <title>ada test</title>
+ <meta name="http-equiv" content="Content-type: text/html; charset=UTF-8"/>
+</head>
+
+
+<body>
+ <h2>Happy Ada Lovelace Day!</h2>
+ <div id="ada"></div>
+ <script type="text/javascript" src="http://www.nataliepo.com/ada/typepad_parsing.js"></script>
+ <script type="text/javascript" src="http://api.typepad.com/assets.js?q=ada%20lovelace&max-results=10&callback=ada_callback"></script>
+</body>
+</html>
+
View
45 lovelace_sample.html
@@ -0,0 +1,45 @@
+
+ <div id="ada">
+ <div id="tydget-inner-body" class="tydget-inner-body">
+ <div class="tydget-event">
+ <div class="tydget-avatar-wrapper">
+ <div class="tydget-avatar-itself">
+ <a href="http://profile.typepad.com/david"><img class="tydget-thumbnail" src="http://up7.typepad.com/6a00d8341e3ac753ef0120a644b895970c-50si"></a>
+ </div>
+ </div>
+ <div class="tydget-event-detail">
+ <h3 class="tydget-title-string">
+ <a href="http://hello.typepad.com/hello/2010/03/celebrate-ada-lovelace-day-by-coding-something-meaningful.html">Celebrate Ada Lovelace Day by Coding Something Meaningful</a>
+ </h3>
+ <p class="tydget-body-string">
+ ThinkTank hasn't been around long enough to have accumulated any cruft – either in the source code, or in the community's politics. If you join now you have the opportunity to make a major impact on early decisions that will...
+ </p>
+ <p class="tydget-credit">
+ by <a href="http://profile.typepad.com/david">David Jacobs</a>
+ </p>
+ </div>
+ </div>
+ <div class="tydget-event">
+ <div class="tydget-avatar-wrapper">
+ <div class="tydget-avatar-itself">
+ <a href="http://profile.typepad.com/wildwoman"><img class="tydget-thumbnail" src="http://up5.typepad.com/6a00d834790a6569e200e5500104168833-50si"></a>
+ </div>
+ </div>
+ <div class="tydget-event-detail">
+ <h3 class="tydget-title-string">
+ <a href="http://plotblog.typepad.com/plotblog/2010/03/helen-aspall-for-ada-lovelace-day.html">Helen Aspall for Ada Lovelace Day</a>
+ </h3>
+ <p class="tydget-body-string">
+ Ada Lovelace day is here again, and this time we nominate someone who is making inroads into connecting with the digitally disenfranchised, Helen Aspall.
+ </p>
+ <p class="tydget-credit">
+ by <a href="http://profile.typepad.com/wildwoman">Plot agents</a>
+ </p>
+ </div>
+ </div>
+ </div>
+ <div class="tydget-footer-outer">
+ <a class="tydget-footer-inner" href="http://www.typepad.com">Powered by TypePad</a>
+ </div>
+ </div>
+
View
1,312 results.json
1,312 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
356 typepad_parsing.js
@@ -0,0 +1,356 @@
+function ada_callback(json_response) {
+
+ var tydget = document.getElementById("ada");
+
+ // just return nothing for now.
+ if (!tydget) {
+ return;
+ }
+
+ // set up the outer div wrappers.
+ innerHTML =
+'<div id="ada"> \n';
+// innerHTML += build_header(json_response);
+ innerHTML += build_inner_body(json_response);
+ innerHTML += build_footer(json_response);
+ innerHTML +=
+'</div>';
+
+ tydget.innerHTML = innerHTML;
+
+ return;
+}
+
+/***************
+ * build_ methods are the powerhouses generating the html,
+ * create_ methods make smaller event snippet
+ ***************/
+function build_header (json_response) {
+ var innerHTML = "";
+
+ // janky workaround since events feed doesnt store url or name
+ var url = get_site_url(json_response.entries[0].object.permalinkUrl);
+ var name = get_site_name(json_response.entries[0].object.permalinkUrl);
+
+ innerHTML =
+' <div class="tydget-header-div"> \n' +
+' <div class="tydget-header-precursor"> \n' +
+' recently on \n' +
+' </div>\n' +
+' <a class="tydget-header-title" href="' + url + '">' + name + '</a> \n' +
+' </div> \n';
+
+ return innerHTML;
+}
+
+function build_inner_body (json_response) {
+ var innerHTML = '<div id="tydget-inner-body" class="tydget-inner-body">';
+
+ for (var i = 0; i < json_response.entries.length; i++) {
+
+ var author = json_response.entries[i].author;
+ if (author) {
+ //alert("[" + i + "] author name = " + author.preferredUsername);
+
+ // Skip null objects in the stream. this is a known bug in the
+ // events api that deleted obj stay in there.
+ innerHTML += '<div class="tydget-event">\n';
+ innerHTML += create_event_snippet(json_response.entries[i], author);
+ innerHTML += '</div>';
+ }
+ }
+
+ // close out the event div.
+ innerHTML += '\n</div>';
+
+ return innerHTML;
+
+}
+
+function build_footer (obj) {
+ var innerHTML = "";
+
+ innerHTML +=
+'<p class="morelink"><a href="#">Get More Posts...</a></p>';
+
+ innerHTML +=
+' <div class="tydget-footer-outer">\n' +
+' <a class="tydget-footer-inner" href="http://www.typepad.com">Powered by TypePad</a>\n' +
+' </div>\n';
+
+ return innerHTML;
+}
+
+function create_event_snippet (obj, author) {
+ var innerHTML = "";
+
+ innerHTML += create_event_avatar(obj, author);
+// innerHTML += create_event_thumbnail(obj);
+ innerHTML += create_event_detail(obj, author);
+// innerHTML += create_event_footer(obj, author);
+
+ return innerHTML;
+}
+
+
+function create_event_thumbnail(obj) {
+ var innerHTML =
+' <div class="tydget-thumbnail-itself">\n' +
+' <a href="' + obj.permalinkUrl + '">\n' +
+' <img src="' + get_resized_image(obj, 50) + '" />\n'+
+' </a>\n' +
+' </div>\n';
+
+ return innerHTML;
+
+}
+
+function create_event_avatar (obj, author) {
+
+ var innerHTML =
+' <div class="tydget-avatar-wrapper">\n' +
+' <div class="tydget-avatar-itself">\n' +
+' <a href="' + author.profilePageUrl + '">\n' +
+' <img class="tydget-thumbnail" src="' + get_resized_avatar(author, 50) + '">\n' +
+' </a>\n' +
+' </div>\n' +
+' </div>';
+
+ return innerHTML;
+}
+
+function create_event_detail (obj, author) {
+ var innerHTML = "";
+
+ innerHTML +=
+' <div class="tydget-event-detail">\n' +
+//' <a class="tydget-author_link" href="' + author.profilePageUrl + '">' + get_author_name(author) + '</a>\n' +
+' <h3 class="tydget-title-string"><a href="' + obj.permalinkUrl + '">' + obj.title + '</a></h3>\n' +
+' <p class="tydget-body-string">' + obj.excerpt + '</p>\n' +
+' <p class="tydget-credit">by <a href="' + author.profilePageUrl + '">' + get_author_name(author) + '</a></p>\n' +
+' </div>\n';
+
+ return innerHTML;
+}
+
+function create_event_footer (obj, author) {
+ var innerHTML = "";
+
+ innerHTML +=
+' <div class="tydget-event_footer_div">\n' +
+' <div class="tydget-comment-div">\n' +
+' <a class="tydget-comment-link" href="' + obj.permalinkUrl + '#comments">' + obj.commentCount + '</a>\n' +
+' </div>\n' +
+' <div class="tydget-fav-div">\n' +
+' <a class="tydget-fav-link" href="' + obj.permalinkUrl + '#comments">' + obj.favoriteCount + '</a>\n' +
+' </div>\n' +
+' </div>\n';
+
+ return innerHTML;
+}
+
+
+
+/***************
+ * utility fns to help parse the api or formulate something for tydget
+ ***************/
+/* These are all hosted in Boone/library/utilites.js */
+
+/***************
+ * utility fns to help parse the api or formulate something for tydget
+ ***************/
+
+
+function get_author_name (author_obj) {
+ if (author_obj.displayName) {
+ return author_obj.displayName;
+ }
+
+ return "A Member";
+}
+
+
+ function get_post_wording (obj) {
+
+ var str = "";
+ if (obj.videoLink) {
+ str = "a video";
+ }
+ else if (obj.imageLink) {
+ str = "an image";
+ }
+ else if (obj.targetUrl) {
+ str = "a link";
+ }
+ else if (obj.audioLink) {
+ str = "a soundclip";
+ }
+
+ if (str && (((obj.title && !obj.audioLink) || obj.content))) {
+ str += " called";
+ }
+
+ return str;
+}
+
+
+function get_action_verb (obj) {
+ if (obj.videoLink || obj.targetURL || obj.audioLink) {
+ return "shared";
+ }
+
+ return "wrote";
+}
+
+
+function get_resized_image (obj, size) {
+ var default_image = 'http://up3.typepad.com/6a00d83451c82369e20120a4e574c1970b-50si';
+
+
+ for (var i = 0; i < obj.embeddedImageLinks.length; i++) {
+ return obj.embeddedImageLinks[i].url;
+ }
+
+
+ return default_image;
+}
+
+function get_resized_avatar (user, size) {
+ // use the lilypad as a default in case all else fails
+ var default_avatar = 'http://up3.typepad.com/6a00d83451c82369e20120a4e574c1970b-50si';
+
+
+ for (var i = 0; i < user.links.length; i++) {
+ if (user.links[i].rel == "avatar") {
+ if (user.links[i].width < 125) {
+ return user.links[i].href;
+ }
+ }
+ }
+
+ return default_avatar;
+}
+
+
+function get_site_name (url) {
+// return "the community";
+ if (!url) {
+// alert("[get_site_name] name is bad");
+ return "Community";
+ }
+
+ var url_parts = new Array();
+ url_parts = url.split("/");
+
+ // the first two should represent the http.
+ // the next should represent everything up to the slash.
+
+ // If it's a (something).typepad.com, just show the something.
+ var name = url_parts[2];
+ var snippet_parts = new Array();
+ snippet_parts = name.split(".");
+ if (snippet_parts[1] == "typepad") {
+ name = snippet_parts[0];
+ }
+ else if ((snippet_parts[1] == "com") ||
+ (snippet_parts[1] == "info") ||
+ (snippet_parts[1] == "org")) {
+ // this is the case where there's no subdomain, so just use the domain.
+ name = snippet_parts[0];
+ }
+ else {
+ // otherwise, if it's a www.NAME.com, so use the inner.
+ name = snippet_parts[1];
+ }
+
+ if (name == "mmmeow") {
+ return name;
+ }
+ else if (name == "womensbookclub") {
+ return "NY Women's Book Club";
+ }
+
+ name = capitalize_string(name);
+
+ return "The " + name + " Community";
+}
+
+
+function get_site_url (url) {
+
+ if (!url) {
+ // alert("[get_site_url] url is bad");
+ return "http://www.typepad.com";
+ }
+
+ var url_parts = new Array();
+ url_parts = url.split("/");
+
+ // the first two should represent the http.
+ // the next should represent everything up to the slash.
+ return "http://" + url_parts[2];
+}
+
+
+function chop_str (str, size) {
+ if (str.length <= size) {
+ return str;
+ }
+
+ var str_parts = new Array();
+ str_parts = str.split(" ");
+
+ // now we have an array of words.
+ var i = 0;
+
+ var curr = "";
+ var next = str_parts[i];
+ while (next.length < size) {
+ curr += str_parts[i] + ' ';
+ i++;
+ next += str_parts[i] + ' ';
+ }
+
+ // chop the last space
+ curr = curr.substring(0, (curr.length - 1));
+ return curr + "...";
+}
+
+
+function capitalize_string (name) {
+
+ // make sure name is capitalized.
+ var first_letter = name.substr(0, 1);
+ var rest = name.substr(1, name.length);
+ first_letter = first_letter.toUpperCase();
+ return first_letter + rest;
+}
+
+
+function get_full_action_wording(obj, author) {
+
+ var post_type = get_post_wording(obj);
+ var action = get_action_verb(obj);
+
+ var string_length = 300;
+
+ var title = "";
+ // create the title.
+ // Audio link titles have funky strings.
+ if (obj.title && (!obj.audioLink)) {
+ title = chop_str(obj.title, (string_length - action.length - post_type.length - author.displayName.length)); //.substring(0, 75);
+ }
+ else if (obj.content) {
+ title = chop_str(obj.content, (string_length - action.length - post_type.length - author.displayName.length));
+ }
+
+/* var html_string = " " + action + " " + post_type;
+ if (title) {
+ html_string += " '" + title + "'";
+ }
+*/
+
+ return title;
+}
+
+

0 comments on commit de4c7d6

Please sign in to comment.
Something went wrong with that request. Please try again.