forked from ExLibrisGroup/primo-explore-devenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.js
29 lines (28 loc) · 7.01 KB
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* ngTweet - Angular directives for better Twitter integration.
*
* @license
* The MIT License (MIT)
*
* Copyright (c) 2015 Aru Sahni, http://arusahni.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
!function(){"use strict";angular.module("ngtweet",[]).value("ngTweetLogVerbose",!0).value("twitterWidgetURL","https://platform.twitter.com/widgets.js")}(),function(){"use strict";function e(e,t){var n=function(){},i=function(e){return t===!0?e:n};return{log:i(e.log),debug:i(e.debug),info:i(e.info),warn:e.warn,error:e.error}}e.$inject=["$log","ngTweetLogVerbose"],angular.module("ngtweet").factory("ngTweetLogger",e)}(),function(){"use strict";function e(e,t){function n(e,t){this.timelineType=e,this.message=t}function i(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!0;if(e.length!==t.length)return!0;for(var n=0,i=e.length;n<i;n++)if(e[n]!==t[n])return!0;return!1}function r(e){function t(e){return 1===e.length?'"'+e+'"':'("'+e.join('" AND "')+'")'}return e.map(t).join(" OR ")}function o(e){var t={sourceType:e.sourceType};if(!l.hasOwnProperty(e.sourceType))throw new n(e.sourceType,"unknown type");for(var i=l[e.sourceType],o=!1,u=0,a=i.length;u<a;u++){for(var c=i[u],d={},g=0,s=c.length;g<s;g++)angular.isDefined(e[c[g]])&&(d[c[g]]=e[c[g]]);if(Object.keys(d).length===s){angular.merge(t,d),o=!0;break}}if(!o)throw new n(e.sourceType,"args: "+r(i));return t}function u(n,r,u){e.debug("Linking",n,r,u),n.id&&!angular.isString(n.id)&&e.warn("twitterTimelineId should probably be a string due to loss of precision.");try{n.twitterTimelineOptions=JSON.parse(u.twitterTimelineOptions)}catch(a){n.$watch(function(){return n.$parent.$eval(u.twitterTimelineOptions)},function(e,t){n.twitterTimelineOptions=e})}angular.isUndefined(n.twitterTimelineOptions)&&(n.twitterTimelineOptions={}),n.sourceType?n.$watchGroup(c,function(u,a){if(i(a,u)&&angular.element(r[0]).empty(),u.every(function(e){return!e}))return void e.debug("Falsey args received. Not rendering the timeline.");var c;try{c=o(n)}catch(l){return void e.error('Could not create new timeline: bad args for type "'+l.timelineType+'". Reason: '+l.message)}t.createTimelineNew(c,r[0],n.twitterTimelineOptions).then(function(t){e.debug("New Timeline Success!")})["catch"](function(t){e.error("Could not create new timeline: ",t,r)})}):angular.isDefined(n.id)||angular.isString(n.screenName)?n.$watch("id",function(i,o){null!==n.id&&(void 0!==o&&i!==o&&angular.element(r[0]).empty(),t.createTimeline(n.id,n.screenName,r[0],n.twitterTimelineOptions).then(function(t){e.debug("Timeline Success!!!")})["catch"](function(t){e.error("Could not create timeline: ",t,r)}))}):t.load(r[0])}var a={id:"=?twitterTimelineId",screenName:"=?twitterTimelineScreenName",sourceType:"@?twitterTimelineType",userId:"=?twitterTimelineUserId",ownerScreenName:"=?twitterTimelineOwnerScreenName",slug:"=?twitterTimelineSlug",url:"=?twitterTimelineUrl"},c=Object.keys(a).reduce(function(e,t){return"="===a[t][0]&&e.push(t),e},[]),l={profile:[["screenName"],["userId"]],likes:[["screenName"],["userId"]],collection:[["id"]],widget:[["id"]],list:[["id"],["ownerScreenName","slug"]],url:[["url"]]};return{restrict:"E",replace:!0,transclude:!0,scope:a,template:'<div class="ngtweet-wrapper" ng-transclude></div>',link:u}}e.$inject=["ngTweetLogger","TwitterWidgetFactory"],angular.module("ngtweet").directive("twitterTimeline",e)}(),function(){"use strict";function e(e,t){return{restrict:"E",replace:!0,transclude:!0,scope:{twitterWidgetId:"=",twitterWidgetOnRendered:"&",twitterWidgetOptions:"@"},template:'<div class="ngtweet-wrapper" ng-transclude></div>',link:function(n,i,r){n.$watch("twitterWidgetId",function(o,u){e.debug("Linking",i,r);var a=n.$eval(r.twitterWidgetOptions);void 0!==u&&o!==u&&angular.element(i[0]).empty(),angular.isUndefined(n.twitterWidgetId)?t.load(i[0]):(angular.isString(n.twitterWidgetId)||e.warn("twitterWidgetId should probably be a string due to loss of precision."),t.createTweet(n.twitterWidgetId,i[0],a).then(function(t){e.debug("Created tweet widget: ",n.twitterWidgetId,i),n.twitterWidgetOnRendered()})["catch"](function(t){e.error("Could not create widget: ",t,i)}))})}}}e.$inject=["ngTweetLogger","TwitterWidgetFactory"],angular.module("ngtweet").directive("twitterWidget",e)}(),function(){"use strict";function e(e,t,n,i,r,o){function u(){o.twttr=function(e,t,n){var r,u=e.getElementsByTagName(t)[0],a=o.twttr||{};if(!e.getElementById(n))return r=e.createElement(t),r.id=n,r.src=i,u.parentNode.insertBefore(r,u),a._e=[],a.ready=function(e){a._e.push(e)},a}(e[0],"script","twitter-wjs")}function a(){return o.twttr&&o.twttr.init}function c(){return angular.isUndefined(f)?(f=r.defer(),a()?f.resolve(o.twttr):(u(),o.twttr.ready(function(e){n.debug("Twitter script ready"),e.events.bind("rendered",l),f.resolve(e)}),f.promise)):f.promise}function l(e){n.debug("Tweet rendered",e.target.parentElement.attributes)}function d(e,t,i){return c().then(function(o){return n.debug("Creating Tweet",o,e,t,i),r.when(o.widgets.createTweet(e,t,i))})}function g(e,t,i,o){return c().then(function(u){return n.debug("Creating Timeline",e,t,o,i),angular.isString(t)&&t.length>0&&(o.screenName=t),r.when(u.widgets.createTimeline(e,i,o))})}function s(e,t,i){return c().then(function(o){return n.debug("Creating new Timeline",e,i,t),r.when(o.widgets.createTimeline(e,t,i))})}function w(e){c().then(function(t){n.debug("Wrapping",t,e),t.widgets.load(e)})["catch"](function(t){n.error("Could not wrap element: ",t,e)})}var f;return{createTweet:d,createTimeline:g,createTimelineNew:s,initialize:c,load:w}}e.$inject=["$document","$http","ngTweetLogger","twitterWidgetURL","$q","$window"],angular.module("ngtweet").factory("TwitterWidgetFactory",e)}(),function(){"use strict";function e(e,t){return{restrict:"A",replace:!1,scope:!1,link:function(n,i,r){e.debug("Initializing"),t.initialize()}}}e.$inject=["ngTweetLogger","TwitterWidgetFactory"],angular.module("ngtweet").directive("twitterWidgetInitialize",e)}(),function(){"use strict";function e(e){e.decorator("ngTweetLogVerbose",["$delegate",function(e){return!1}])}e.$inject=["$provide"],angular.module("ngtweet").config(e)}();
*/