|
@@ -0,0 +1,93 @@
|
|
|
+/*
|
|
|
+ * Copyright 2018 UltrasonicMadness
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
+function addGSEmbedWidget(aStreamUrl, element)
|
|
|
+{
|
|
|
+ $(element).html("Loading GSEmbed...");
|
|
|
+ $.getJSON(aStreamUrl)
|
|
|
+ .done(function(data)
|
|
|
+ {
|
|
|
+ // Replace the given element with the generated widget HTML.
|
|
|
+ var gsHtml = genGSEmbedHtml(data);
|
|
|
+ $(element).addClass("gsembed_widget");
|
|
|
+ $(element).html(gsHtml);
|
|
|
+
|
|
|
+ // All links in the widget open in a new tab
|
|
|
+ $(element + " a").map(function(index, element)
|
|
|
+ {
|
|
|
+ $(this).attr("target", "_blank");
|
|
|
+ });
|
|
|
+
|
|
|
+ // Highlights moused over statuses
|
|
|
+ $(element + " li").mouseover(function()
|
|
|
+ {
|
|
|
+ $(this).addClass("gshover");
|
|
|
+ });
|
|
|
+
|
|
|
+ // and un-highlights them when the mouse leaves
|
|
|
+ $(element + " li").mouseout(function()
|
|
|
+ {
|
|
|
+ $(this).removeClass("gshover");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .fail(function(data)
|
|
|
+ {
|
|
|
+ $(element).html(data.status + " " + data.statusText);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function genGSEmbedHtml(data)
|
|
|
+{
|
|
|
+ var widgetHtml = "";
|
|
|
+
|
|
|
+ // The widget header
|
|
|
+ widgetHtml += "<div class='gse_heading'>" +
|
|
|
+ "<h4>The latest from <a href='" + data.links[0].url + "'>" +
|
|
|
+ data.title + "</a></h4>" +
|
|
|
+ "</div>";
|
|
|
+
|
|
|
+ // For each status, add an item to a <ul>.
|
|
|
+ widgetHtml += "<ul>";
|
|
|
+
|
|
|
+ for (var i = 0; i < data.items.length; i++)
|
|
|
+ {
|
|
|
+ var pubDate = new Date(data.items[i].published);
|
|
|
+
|
|
|
+ widgetHtml += "<li>";
|
|
|
+
|
|
|
+ // Adds the date which is hyperlinked to the status on GNU Social
|
|
|
+ widgetHtml += "<div class='gse_date'>" +
|
|
|
+ "<a href='" + data.items[i].url + "'>" +
|
|
|
+ pubDate.toString() + "</a></div>";
|
|
|
+
|
|
|
+ // The status itself is added below the date in a separate div
|
|
|
+ widgetHtml += "<div class='gse_postcontent'>" + data.items[i].content +
|
|
|
+ "</div>";
|
|
|
+
|
|
|
+ widgetHtml += "</li>";
|
|
|
+ }
|
|
|
+
|
|
|
+ widgetHtml += "</ul>";
|
|
|
+
|
|
|
+ // The widget footer with a link to the software page
|
|
|
+ widgetHtml += "<div class='gse_footer'>" +
|
|
|
+ "Powered by <a " +
|
|
|
+ "href='http://www.ultrasonicmadness.org/software/gsembed'>" +
|
|
|
+ "GSEmbed 0.0.1</a>" +
|
|
|
+ "</div>";
|
|
|
+
|
|
|
+ return widgetHtml;
|
|
|
+}
|