dom-functions.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638
  1. /*· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
  2. · ·
  3. · ·
  4. · Q V I T T E R ·
  5. · ·
  6. · ·
  7. · <o) ·
  8. · /_//// ·
  9. · (____/ ·
  10. · (o< ·
  11. · o> \\\\_\ ·
  12. · \\) \____) ·
  13. · ·
  14. · ·
  15. · @licstart The following is the entire license notice for the ·
  16. · JavaScript code in this page. ·
  17. · ·
  18. · Copyright (C) 2015 Hannes Mannerheim and other contributors ·
  19. · ·
  20. · ·
  21. · This program is free software: you can redistribute it and/or modify ·
  22. · it under the terms of the GNU Affero General Public License as ·
  23. · published by the Free Software Foundation, either version 3 of the ·
  24. · License, or (at your option) any later version. ·
  25. · ·
  26. · This program is distributed in the hope that it will be useful, ·
  27. · but WITHOUT ANY WARRANTY; without even the implied warranty of ·
  28. · MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ·
  29. · GNU Affero General Public License for more details. ·
  30. · ·
  31. · You should have received a copy of the GNU Affero General Public License ·
  32. · along with this program. If not, see <http://www.gnu.org/licenses/>. ·
  33. · ·
  34. · @licend The above is the entire license notice ·
  35. · for the JavaScript code in this page. ·
  36. · ·
  37. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  38. /* ·
  39. ·
  40. · Build a menu
  41. ·
  42. · Menus currently support four row types: divider, functions, links and profile-prefs-toggles
  43. · Function rows run the function in the function attribute when clicked.
  44. · Profile-prefs-toggle rows toggles the preference in the attribute when clicked.
  45. ·
  46. · @param streamObject: stream object returned by pathToStreamRouter()
  47. ·
  48. · · · · · · · · · */
  49. function getMenu(menuArray) {
  50. if(typeof getMenu == 'undefined' || getMenu === false) {
  51. return false;
  52. }
  53. var menuHTML = buildMenuTop();
  54. $.each(menuArray,function(){
  55. if(this.type == 'divider') {
  56. menuHTML = menuHTML + buildMenuDivider();
  57. }
  58. else if(this.type == 'function') {
  59. menuHTML = menuHTML + buildMenuRowFullwidth(this.label, {
  60. class: 'row-type-' + this.type,
  61. 'data-menu-row-type': this.type,
  62. 'data-function-name': this.functionName,
  63. 'data-function-arguments': JSON.stringify(this.functionArguments)
  64. });
  65. }
  66. else if(this.type == 'link') {
  67. menuHTML = menuHTML + buildMenuRowFullwidth(this.label, {
  68. class: 'row-type-' + this.type,
  69. 'href': this.href
  70. });
  71. }
  72. else if(this.type == 'profile-prefs-toggle') {
  73. // only prefs in the qvitter namespace is supported
  74. if(this.namespace == 'qvitter') {
  75. // enabled?
  76. var prefEnabledOrDisabled = 'disabled';
  77. if(isQvitterProfilePrefEnabled(this.topic)) {
  78. prefEnabledOrDisabled = 'enabled';
  79. }
  80. // sometimes we want another label when the toggle is enabled
  81. var labelToUse = this.label;
  82. if(isQvitterProfilePrefEnabled(this.topic) && typeof this.enabledLabel != 'undefined') {
  83. labelToUse = this.enabledLabel;
  84. }
  85. // the tick can be disabled
  86. var disableTickClass = '';
  87. if(typeof this.tickDisabled != 'undefined' && this.tickDisabled === true) {
  88. var disableTickClass = ' tick-disabled';
  89. }
  90. // get row html
  91. menuHTML = menuHTML + buildMenuRowFullwidth(labelToUse, {
  92. id: this.topic,
  93. class: 'row-type-' + this.type + ' ' + prefEnabledOrDisabled + disableTickClass,
  94. 'data-menu-row-type': this.type,
  95. 'data-profile-prefs-topic': this.topic,
  96. 'data-profile-prefs-namespace': this.namespace,
  97. 'data-profile-prefs-label': replaceHtmlSpecialChars(this.label),
  98. 'data-profile-prefs-enabled-label': replaceHtmlSpecialChars(this.enabledLabel),
  99. 'data-profile-pref-state': prefEnabledOrDisabled,
  100. 'data-profile-pref-callback': this.callback
  101. });
  102. }
  103. }
  104. });
  105. return menuHTML + buildMenuBottom();
  106. }
  107. /* ·
  108. ·
  109. · Menu from streamObject
  110. ·
  111. · · · · · · · · · */
  112. function streamObjectGetMenu(streamObject) {
  113. if(typeof streamObject == 'undefined') {
  114. return false;
  115. }
  116. if(streamObject.menu === false) {
  117. return false;
  118. }
  119. return getMenu(streamObject.menu);
  120. }
  121. /* ·
  122. ·
  123. · Menu components
  124. ·
  125. · · · · · · · · · */
  126. function buildMenuTop() {
  127. return '<ul class="dropdown-menu">\
  128. <li class="dropdown-caret right">\
  129. <span class="caret-outer"></span>\
  130. <span class="caret-inner"></span>\
  131. </li>';
  132. }
  133. function buildMenuBottom() {
  134. return '</ul>';
  135. }
  136. function buildMenuDivider() {
  137. return '<li class="fullwidth dropdown-divider"></li>';
  138. }
  139. function buildMenuRowFullwidth(label, attributes) {
  140. var attributesHTML = '';
  141. $.each(attributes,function(k,v){
  142. attributesHTML = attributesHTML + ' ' + k + '=\'' + v + '\'';
  143. });
  144. return '<li class="fullwidth"><a' + attributesHTML + '>' + replaceHtmlSpecialChars(label) + '</a></li>';
  145. }
  146. function alignMenuToParent(menu, parent, offsetLeft) {
  147. if(typeof offsetLeft == 'undefined') {
  148. var offsetLeft = 0;
  149. }
  150. var menuLeft = parent.innerWidth()/2 - menu.width() + 15 + offsetLeft;
  151. var menuTop = parent.height()+5;
  152. menu.css('left', menuLeft + 'px');
  153. menu.css('top', menuTop + 'px');
  154. menu.css('display','block'); // show menu
  155. }
  156. /* ·
  157. ·
  158. · Show error message
  159. ·
  160. · @param message: error message
  161. ·
  162. · · · · · · · · · */
  163. function showErrorMessage(message, after) {
  164. if(typeof after == 'undefined') {
  165. var after = $('#user-container,#login-register-container');
  166. }
  167. after.after('<div class="error-message">' + message + '<span class="discard-error-message"></span></div>');
  168. }
  169. /* ·
  170. ·
  171. · Show favs and requeets in queet element
  172. ·
  173. · @param q: queet jQuery object
  174. · @param data: object with users that has faved and requeeted
  175. ·
  176. · · · · · · · · · */
  177. function showFavsAndRequeetsInQueet(q,data) {
  178. // set the non-expanded fav- and rq-count
  179. q.children('.queet').find('.action-fav-num').html(data.favs.length);
  180. q.children('.queet').find('.action-fav-num').attr('data-fav-num',data.favs.length);
  181. q.children('.queet').find('.action-rq-num').html(data.repeats.length);
  182. q.children('.queet').find('.action-rq-num').attr('data-rq-num',data.repeats.length);
  183. // don't proceed if queet is not expanded
  184. if(!q.hasClass('expanded') || q.hasClass('collapsing')) {
  185. return;
  186. }
  187. // don't proceed and remove expanded stats if all favs and repeats are removed
  188. if(data.favs.length < 1 && data.repeats.length < 1) {
  189. q.children('.queet').find('.stats').remove();
  190. return;
  191. }
  192. // remove any existing stats container and add a new empty one
  193. if(q.children('.queet').find('ul.stats').length > 0) {
  194. q.children('.queet').find('ul.stats').remove();
  195. }
  196. q.children('.queet').find('.queet-stats-container').prepend('<ul class="stats"><li class="avatar-row"></li></ul><div class="clearfix"></div>');
  197. // set the expanded fav-count number
  198. if(data.favs.length > 0) {
  199. if(data.favs.length == 1) {
  200. var favLabel = window.sL.favoriteNoun;
  201. }
  202. else if(data.favs.length > 1) {
  203. var favLabel = window.sL.favoritesNoun;
  204. }
  205. if(q.children('.queet').find('.fav-count').length>0) {
  206. q.children('.queet').find('.fav-count').children('strong').html(data.favs.length);
  207. }
  208. else {
  209. q.children('.queet').find('li.avatar-row').before('<li class="fav-count"><a>' + favLabel + ' </a><strong>' + data.favs.length + '</strong></li>');
  210. }
  211. }
  212. // add repeats
  213. if(data.repeats.length > 0) {
  214. if(data.repeats.length == 1) {
  215. var repeatsLabel = window.sL.requeetNoun;
  216. }
  217. else if(data.repeats.length > 1) {
  218. var repeatsLabel = window.sL.requeetsNoun;
  219. }
  220. if(q.children('.queet').find('.rq-count').length>0) {
  221. q.children('.queet').find('.rq-count').children('strong').html(data.repeats.length);
  222. }
  223. else {
  224. q.children('.queet').find('li.avatar-row').before('<li class="rq-count"><a>' + repeatsLabel + ' </a><strong>' + data.repeats.length + '</strong></li>');
  225. }
  226. }
  227. // merge favs and repeats objects by user_id (removes duplicate users)
  228. var favsAndRepeats = {};
  229. $.each(data.repeats,function(){
  230. favsAndRepeats[this.user_id] = this;
  231. });
  232. $.each(data.favs,function(){
  233. favsAndRepeats[this.user_id] = this;
  234. });
  235. // make an object with time the key
  236. var favsAndRepeatsByTime = {};
  237. $.each(favsAndRepeats,function(){
  238. favsAndRepeatsByTime[this.time] = this;
  239. });
  240. // create an array with times and sort it
  241. var timeSorted = [];
  242. $.each(favsAndRepeats,function(){
  243. timeSorted.push(this.time);
  244. });
  245. timeSorted.sort();
  246. // display avatars in chronological order, max 7
  247. var avatarnum = 1;
  248. $.each(timeSorted,function(){
  249. q.children('.queet').find('.avatar-row').append('<a title="' + favsAndRepeatsByTime[this].fullname + '" data-user-id="' + favsAndRepeatsByTime[this].user_id + '" href="' + favsAndRepeatsByTime[this].profileurl + '"><img alt="' + favsAndRepeatsByTime[this].fullname + '" src="' + favsAndRepeatsByTime[this].avatarurl + '" class="avatar size24" id="av-' + favsAndRepeatsByTime[this].user_id + '"></a>');
  250. if(avatarnum > 15) {
  251. return false;
  252. }
  253. avatarnum++;
  254. });
  255. }
  256. /* ·
  257. ·
  258. · Build a follow/block button
  259. ·
  260. · @param obj: an object with a user array
  261. ·
  262. · · · · · · · · · */
  263. function buildFollowBlockbutton(obj) {
  264. // following?
  265. var followingClass = '';
  266. if(obj.following) {
  267. followingClass = ' following';
  268. }
  269. // blocking?
  270. var blockingClass = '';
  271. if(obj.statusnet_blocking) {
  272. blockingClass = ' blocking';
  273. }
  274. var followButton = '';
  275. if(typeof window.loggedIn.screen_name != 'undefined' // if logged in
  276. && window.loggedIn.id != obj.id) { // not if this is me
  277. if(!(obj.statusnet_profile_url.indexOf('/twitter.com/')>-1 && obj.following === false)) { // only unfollow twitter users
  278. if(obj.blocks_you) {
  279. var followButton = '<div class="user-actions">\
  280. <div class="blocks-you" data-tooltip="' + window.sL.tooltipBlocksYou.replace('{username}','@' + obj.screen_name) + '"></div>\
  281. </div>';
  282. }
  283. else {
  284. var followButton = '<div class="user-actions">\
  285. <button data-follow-user-id="' + obj.id + '" data-follow-user="' + obj.statusnet_profile_url + '" type="button" class="qvitter-follow-button' + followingClass + blockingClass + '">\
  286. <span class="button-text follow-text"><i class="follow"></i>' + window.sL.userFollow + '</span>\
  287. <span class="button-text following-text">' + window.sL.userFollowing + '</span>\
  288. <span class="button-text unfollow-text">' + window.sL.userUnfollow + '</span>\
  289. <span class="button-text blocking-text">' + window.sL.buttonBlocked + '</span>\
  290. <span class="button-text unblock-text">' + window.sL.buttonUnblock + '</span>\
  291. </button>\
  292. </div>';
  293. }
  294. }
  295. }
  296. return followButton;
  297. }
  298. /* ·
  299. ·
  300. · Build profile card HTML
  301. ·
  302. · @param data: an object with a user array
  303. ·
  304. · · · · · · · · · */
  305. function buildProfileCard(data) {
  306. data = cleanUpUserObject(data);
  307. // use avatar if no cover photo
  308. var coverPhotoHtml = '';
  309. if(data.cover_photo !== false) {
  310. coverPhotoHtml = 'background-image:url(\'' + data.cover_photo + '\')';
  311. }
  312. // follows me?
  313. var follows_you = '';
  314. if(data.follows_you === true && window.loggedIn.id != data.id) {
  315. var follows_you = '<span class="follows-you">' + window.sL.followsYou + '</span>';
  316. }
  317. // me?
  318. var is_me = '';
  319. if(window.loggedIn !== false && window.loggedIn.id == data.id) {
  320. var is_me = ' is-me';
  321. }
  322. // logged in?
  323. var logged_in = '';
  324. if(window.loggedIn !== false) {
  325. var logged_in = ' logged-in';
  326. }
  327. // silenced?
  328. var is_silenced = '';
  329. if(data.is_silenced === true) {
  330. is_silenced = ' silenced';
  331. }
  332. // sandboxed?
  333. var is_sandboxed = '';
  334. if(data.is_sandboxed === true) {
  335. is_sandboxed = ' sandboxed';
  336. }
  337. // muted?
  338. var is_muted = '';
  339. if(isUserMuted(data.id)) {
  340. is_muted = ' user-muted';
  341. }
  342. var followButton = '';
  343. // follow from external instance if logged out and the user is local
  344. if(window.loggedIn === false && data.is_local == true) {
  345. followButton = '<div class="user-actions"><button type="button" class="external-follow-button"><span class="button-text follow-text"><i class="follow"></i>' + window.sL.userExternalFollow + '</span></button></div>';
  346. }
  347. // edit profile button if it's me
  348. else if(window.loggedIn !== false && window.loggedIn.id == data.id) {
  349. followButton = '<div class="user-actions"><button type="button" class="edit-profile-button"><span class="button-text edit-profile-text">' + window.sL.editMyProfile + '</span></button></div>';
  350. }
  351. // follow button for logged in users
  352. else if(window.loggedIn !== false) {
  353. followButton = buildFollowBlockbutton(data);
  354. }
  355. // is webpage empty?
  356. var emptyWebpage = '';
  357. if(data.url.length<1) {
  358. emptyWebpage = ' empty';
  359. }
  360. // full card html
  361. var profileCardHtml = '\
  362. <div class="profile-card' + is_me + logged_in + is_muted + '">\
  363. <script class="profile-json" type="application/json">' + JSON.stringify(data) + '</script>\
  364. <div class="profile-header-inner' + is_silenced + is_sandboxed + '" style="' + coverPhotoHtml + '" data-user-id="' + data.id + '" data-screen-name="' + data.screen_name + '">\
  365. <div class="profile-header-inner-overlay"></div>\
  366. <a class="profile-picture" href="' + data.profile_image_url_original + '">\
  367. <img class="avatar profile-size" src="' + data.profile_image_url_profile_size + '" data-user-id="' + data.id + '" />\
  368. </a>\
  369. <div class="profile-card-inner">\
  370. <h1 class="fullname" data-user-id="' + data.id + '">' + data.name + '</h1>\
  371. <span class="silenced-flag" data-tooltip="' + window.sL.silencedStreamDescription + '">' + window.sL.silenced + '</span>\
  372. <span class="sandboxed-flag" data-tooltip="' + window.sL.sandboxedStreamDescription + '">' + window.sL.sandboxed + '</span>\
  373. <h2 class="username">\
  374. <span class="screen-name" data-user-id="' + data.id + '">@' + data.screen_name + '</span>\
  375. ' + follows_you + '\
  376. </h2>\
  377. <div class="bio-container"><p>' + data.description + '</p></div>\
  378. <p class="location-and-url">\
  379. <span class="location">' + data.location + '</span>\
  380. <span class="url' + emptyWebpage + '">\
  381. <span class="divider"> · </span>\
  382. <a href="' + data.url + '">' + data.url.replace('http://','').replace('https://','') + '</a>\
  383. </span>\
  384. </p>\
  385. </div>\
  386. </div>\
  387. <div class="profile-banner-footer">\
  388. <ul class="stats">\
  389. <li class="tweet-num"><a href="' + data.statusnet_profile_url + '" class="tweet-stats">' + window.sL.notices + '<strong>' + data.statuses_count + '</strong></a></li>\
  390. <li class="following-num"><a href="' + data.statusnet_profile_url + '/subscriptions" class="following-stats">' + window.sL.following + '<strong>' + data.friends_count + '</strong></a></li>\
  391. <li class="follower-num"><a href="' + data.statusnet_profile_url + '/subscribers" class="follower-stats">' + window.sL.followers + '<strong>' + data.followers_count + '</strong></a></li>\
  392. <li class="groups-num"><a href="' + data.statusnet_profile_url + '/groups" class="groups-stats">' + window.sL.groups + '<strong>' + data.groups_count + '</strong></a></li>\
  393. </ul>\
  394. ' + followButton + '\
  395. <div class="user-menu-cog' + is_silenced + is_sandboxed + logged_in + '" data-tooltip="' + window.sL.userOptions + '" data-user-id="' + data.id + '" data-screen-name="' + data.screen_name + '"></div>\
  396. <div class="clearfix"></div>\
  397. </div>\
  398. </div>\
  399. ';
  400. return { userArray: data, profileCardHtml: profileCardHtml };
  401. }
  402. /* ·
  403. ·
  404. · Build external profile card HTML
  405. ·
  406. · @param data: an object containing data.external user array,
  407. · and maybe (hopefully) also a data.local user array
  408. ·
  409. · · · · · · · · · */
  410. function buildExternalProfileCard(data) {
  411. // follows me?
  412. var follows_you = '';
  413. if(data.local !== null && data.local.follows_you === true && window.loggedIn.id != data.local.id) {
  414. var follows_you = '<span class="follows-you">' + window.sL.followsYou + '</span>';
  415. }
  416. // follow button
  417. var followButton = '';
  418. if(window.loggedIn !== false && typeof data.local != 'undefined' && data.local !== null) {
  419. var followButton = buildFollowBlockbutton(data.local);
  420. }
  421. // me?
  422. var is_me = '';
  423. if(window.loggedIn !== false && window.loggedIn.id == data.local.id) {
  424. var is_me = ' is-me';
  425. }
  426. // logged in?
  427. var logged_in = '';
  428. if(window.loggedIn !== false) {
  429. var logged_in = ' logged-in';
  430. }
  431. // silenced?
  432. var is_silenced = '';
  433. if(data.local.is_silenced === true) {
  434. is_silenced = ' silenced';
  435. }
  436. // sandboxed?
  437. var is_sandboxed = '';
  438. if(data.local.is_sandboxed === true) {
  439. is_sandboxed = ' sandboxed';
  440. }
  441. // muted?
  442. var is_muted = '';
  443. if(isUserMuted(data.local.id)) {
  444. is_muted = ' user-muted';
  445. }
  446. // local id/screen_name
  447. var localUserId = data.local.id;
  448. var localUserScreenName = data.local.screen_name;
  449. // empty strings and zeros instead of null
  450. data = cleanUpUserObject(data.external);
  451. // old statusnet-versions might not have full avatar urls in their api response
  452. if(typeof data.profile_image_url_original == 'undefined'
  453. || data.profile_image_url_original === null
  454. || data.profile_image_url_original.length == 0) {
  455. data.profile_image_url_original = data.profile_image_url;
  456. }
  457. if(typeof data.profile_image_url_profile_size == 'undefined'
  458. || data.profile_image_url_profile_size === null
  459. || data.profile_image_url_profile_size.length == 0) {
  460. data.profile_image_url_profile_size = data.profile_image_url;
  461. }
  462. // we might have a cover photo
  463. if(typeof data.cover_photo != 'undefined' && data.cover_photo !== false) {
  464. var cover_photo = data.cover_photo;
  465. }
  466. else {
  467. var cover_photo = data.profile_image_url_original;
  468. }
  469. // is webpage empty?
  470. var emptyWebpage = '';
  471. if(data.url.length<1) {
  472. emptyWebpage = ' empty';
  473. }
  474. var serverUrl = guessInstanceUrlWithoutProtocolFromProfileUrlAndNickname(data.statusnet_profile_url, data.screen_name);
  475. data.screenNameWithServer = '@' + data.screen_name + '@' + serverUrl;
  476. var profileCardHtml = '\
  477. <div class="profile-card' + is_me + logged_in + is_muted + '">\
  478. <div class="profile-header-inner' + is_silenced + is_sandboxed + '" style="background-image:url(\'' + cover_photo + '\')" data-user-id="' + localUserId + '" data-screen-name="' + localUserScreenName + '">\
  479. <div class="profile-header-inner-overlay"></div>\
  480. <a class="profile-picture"><img src="' + data.profile_image_url_profile_size + '" /></a>\
  481. <div class="profile-card-inner">\
  482. <a target="_blank" href="' + data.statusnet_profile_url + '">\
  483. <h1 class="fullname">' + data.name + '</h1>\
  484. <span class="silenced-flag" data-tooltip="' + window.sL.silencedStreamDescription + '">' + window.sL.silenced + '</span>\
  485. <span class="sandboxed-flag" data-tooltip="' + window.sL.sandboxedStreamDescription + '">' + window.sL.sandboxed + '</span>\
  486. <h2 class="username">\
  487. <span class="screen-name">' + data.screenNameWithServer + '</span>\
  488. <span class="ostatus-link" data-tooltip="' + window.sL.goToTheUsersRemoteProfile + '">' + window.sL.goToTheUsersRemoteProfile + '</span>\
  489. ' + follows_you + '\
  490. </h2>\
  491. </a>\
  492. <div class="bio-container"><p>' + data.description + '</p></div>\
  493. <p class="location-and-url">\
  494. <span class="location">' + data.location + '</span>\
  495. <span class="url' + emptyWebpage + '">\
  496. <span class="divider"> · </span>\
  497. <a target="_blank" href="' + data.url + '">' + data.url.replace('http://','').replace('https://','') + '</a>\
  498. </span>\
  499. </p>\
  500. </div>\
  501. </div>\
  502. <div class="profile-banner-footer">\
  503. <ul class="stats">\
  504. <li class="tweet-num"><a class="tweet-stats" target="_blank" href="' + data.statusnet_profile_url + '">' + window.sL.notices + '<strong>' + data.statuses_count + '</strong></a></li>\
  505. <li class="following-num"><a class="following-stats" target="_blank" href="' + data.statusnet_profile_url + '/subscriptions">' + window.sL.following + '<strong>' + data.friends_count + '</strong></a></li>\
  506. <li class="follower-num"><a class="follower-stats" target="_blank" href="' + data.statusnet_profile_url + '/subscribers">' + window.sL.followers + '<strong>' + data.followers_count + '</strong></a></li>\
  507. </ul>\
  508. ' + followButton + '\
  509. <div class="user-menu-cog' + is_silenced + is_sandboxed + logged_in + '" data-tooltip="' + window.sL.userOptions + '" data-user-id="' + localUserId + '" data-screen-name="' + localUserScreenName + '"></div>\
  510. <div class="clearfix"></div>\
  511. </div>\
  512. </div>\
  513. <div class="clearfix"></div>';
  514. return { userArray: data, profileCardHtml: profileCardHtml };
  515. }
  516. /* ·
  517. ·
  518. · Adds a profile card before feed element
  519. ·
  520. · @param data: an object with a user array
  521. ·
  522. · · · · · · · · · */
  523. function addProfileCardToDOM(data) {
  524. // change design
  525. changeDesign({backgroundimage:data.userArray.background_image, backgroundcolor:data.userArray.backgroundcolor, linkcolor:data.userArray.linkcolor});
  526. // remove any old profile card and show profile card
  527. $('#feed').siblings('.profile-card').remove();
  528. $('#feed').before(data.profileCardHtml);
  529. }
  530. /* ·
  531. ·
  532. · Adds a group profile card before feed element
  533. ·
  534. · @param data: an object with one or more queet objects
  535. ·
  536. · · · · · · · · · */
  537. function groupProfileCard(groupAlias) {
  538. getFromAPI('statusnet/groups/show/' + groupAlias + '.json', function(data){ if(data){
  539. data.nickname = data.nickname || '';
  540. data.fullname = data.fullname || '';
  541. data.stream_logo = data.stream_logo || window.defaultAvatarStreamSize;
  542. data.homepage_logo = data.homepage_logo || window.defaultAvatarProfileSize;
  543. data.original_logo = data.original_logo || window.defaultAvatarProfileSize;
  544. data.description = data.description || '';
  545. data.homepage = data.homepage || '';
  546. data.url = data.url || '';
  547. data.member_count = data.member_count || 0;
  548. data.admin_count = data.admin_count || 0;
  549. // show user actions if logged in
  550. var memberClass = '';
  551. if(data.member) {
  552. memberClass = 'member';
  553. }
  554. var memberButton = '';
  555. if(typeof window.loggedIn.screen_name != 'undefined') {
  556. var memberButton = '<div class="user-actions"><button data-group-id="' + data.id + '" type="button" class="member-button ' + memberClass + '"><span class="button-text join-text"><i class="join"></i>' + window.sL.joinGroup + '</span><span class="button-text ismember-text">' + window.sL.isMemberOfGroup + '</span><span class="button-text leave-text">' + window.sL.leaveGroup + '</span></button></div>';
  557. }
  558. // follow from external instance if logged out
  559. if(typeof window.loggedIn.screen_name == 'undefined') {
  560. var memberButton = '<div class="user-actions"><button type="button" class="external-member-button"><span class="button-text join-text"><i class="join"></i>' + window.sL.joinExternalGroup + '</span></button></div>';
  561. }
  562. // change design
  563. changeDesign({backgroundimage:false, backgroundcolor:false, linkcolor:false});
  564. // add card to DOM
  565. $('#feed').siblings('.profile-card').remove(); // remove any old profile card
  566. $('#feed').before(' <div class="profile-card group">\
  567. <div class="profile-header-inner" style="background-image:url(' + data.original_logo + ')">\
  568. <div class="profile-header-inner-overlay"></div>\
  569. <a class="profile-picture" href="' + data.original_logo + '">\
  570. <img src="' + data.homepage_logo + '" />\
  571. </a>\
  572. <div class="profile-card-inner">\
  573. <a href="' + window.siteInstanceURL + 'group/' + data.nickname + '">\
  574. <h1 class="fullname">\
  575. ' + data.fullname + '\
  576. <span></span>\
  577. </h1>\
  578. <h2 class="username">\
  579. <span class="screen-name">!' + data.nickname + '</span>\
  580. </h2>\
  581. </a>\
  582. <div class="bio-container">\
  583. <p>' + data.description + '</p>\
  584. </div>\
  585. <p class="location-and-url">\
  586. <span class="url">\
  587. <a href="' + data.homepage + '">' + data.homepage.replace('http://','').replace('https://','') + '</a>\
  588. </span>\
  589. </p>\
  590. </div>\
  591. </div>\
  592. <div class="profile-banner-footer">\
  593. <ul class="stats">\
  594. <li>\
  595. <a href="' + window.siteInstanceURL + 'group/' + data.nickname + '/members" class="member-stats">\
  596. ' + window.sL.memberCount + '\
  597. <strong>' + data.member_count + '</strong>\
  598. </a>\
  599. </li>\
  600. <li>\
  601. <a href="' + window.siteInstanceURL + 'group/' + data.nickname + '/admins" class="admin-stats">\
  602. ' + window.sL.adminCount + '\
  603. <strong>' + data.admin_count + '</strong>\
  604. </a>\
  605. </li>\
  606. </ul>\
  607. ' + memberButton + '\
  608. <div class="clearfix"></div>\
  609. </div>\
  610. </div>');
  611. }});
  612. }
  613. /* ·
  614. ·
  615. · Change stream
  616. ·
  617. · @param streamObject: object returned by pathToStreamRouter()
  618. · @param setLocation: whether we should update the browsers location bar when we set the new stream
  619. · @param fallbackId: if we fail to get the stream, it can be due to a bad/changed user/group nickname,
  620. · in that case this parameter can contain a user/group id that we can use to retrieve the correct nickname
  621. · @param actionOnSuccess: callback function on success
  622. ·
  623. · · · · · · · · · */
  624. function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess) {
  625. if(!streamObject || !streamObject.stream) {
  626. console.log('invalid streamObject, no stream to set!');
  627. return;
  628. }
  629. // update the cache for the old stream
  630. rememberStreamStateInLocalStorage();
  631. // remove any old error messages
  632. $('.error-message').remove();
  633. // halt interval that checks for new queets
  634. window.clearInterval(checkForNewQueetsInterval);
  635. // scroll to top
  636. $(window).scrollTop(0);
  637. $('body').addClass('androidFix').scrollTop(0).removeClass('androidFix');
  638. // blur any selected links
  639. $('a').blur();
  640. // unset metadata for the old stream saved in attributes
  641. $('#feed-body').removeAttr('data-search-page-number');
  642. $('#feed-body').removeAttr('data-end-reached');
  643. // hide new queets bar and reload stream button
  644. $('#new-queets-bar-container').addClass('hidden');
  645. $('.reload-stream').hide();
  646. // remove old menu cog
  647. $('#stream-menu-cog').remove();
  648. display_spinner('#feed-header-inner');
  649. // are we just reloading?
  650. var weAreReloading = false;
  651. if(typeof window.currentStreamObject != 'undefined' && window.currentStreamObject.stream == streamObject.stream) {
  652. weAreReloading = true;
  653. }
  654. // show hidden items when we reload
  655. if(weAreReloading) {
  656. $('#feed-body').children('.stream-item').removeClass('hidden');
  657. }
  658. // remember the most recent stream object
  659. window.currentStreamObject = streamObject;
  660. // set the new streams header and description
  661. if(streamObject.streamSubHeader) {
  662. $('#stream-header').html(streamObject.streamSubHeader);
  663. }
  664. else {
  665. $('#stream-header').html(streamObject.streamHeader);
  666. }
  667. if(streamObject.streamDescription !== false) {
  668. $('#feed-header-description').html(streamObject.streamDescription);
  669. }
  670. else {
  671. $('#feed-header-description').empty();
  672. }
  673. // add menu cog if this stream has a menu
  674. if(streamObject.menu && window.loggedIn) {
  675. $('#feed-header-inner h2').append('<div id="stream-menu-cog" data-tooltip="' + window.sL.timelineOptions + '"></div>');
  676. }
  677. // subtle animation to show somethings happening
  678. $('#feed-header-inner h2').css('opacity','0.2');
  679. $('#feed-header-inner h2').animate({opacity:'1'},1000);
  680. // if we're just reloading, we dont need to:
  681. // (1) check if we have a cached version of this stream
  682. // (2) remove the stream if we don't
  683. // (3) change design
  684. if(weAreReloading === false) {
  685. // (1) check if we have a cached version of the stream
  686. var haveOldStreamState = localStorageObjectCache_GET('streamState',window.currentStreamObject.path);
  687. // discard and remove any cached data that is not in this (new) format
  688. if(typeof haveOldStreamState.card == 'undefined'
  689. || typeof haveOldStreamState.feed == 'undefined') {
  690. localStorageObjectCache_STORE('streamState',window.currentStreamObject.path, false);
  691. haveOldStreamState = false;
  692. }
  693. // show cached version immediately
  694. if(haveOldStreamState) {
  695. $('.profile-card,.hover-card,.hover-card-caret').remove();
  696. $('#feed').before(haveOldStreamState.card);
  697. var oldStreamState = $('<div/>').html(haveOldStreamState.feed);
  698. // if the cached items has data-quitter-id-in-stream attributes, sort them before adding them
  699. if(oldStreamState.children('.stream-item[data-quitter-id-in-stream]').length>0) {
  700. oldStreamState.sortDivsByAttrDesc('data-quitter-id-in-stream');
  701. }
  702. // hide any removed notices that we know of
  703. if(typeof window.knownDeletedNotices != 'undefined') {
  704. $.each(window.knownDeletedNotices,function(delededURI,v){
  705. oldStreamState.children('.stream-item[data-uri="' + delededURI + '"]').addClass('deleted always-hidden');
  706. });
  707. }
  708. // hide all notices from blocked users (not for user lists)
  709. if(window.currentStreamObject.type != 'users' && typeof window.allBlocking != 'undefined') {
  710. markAllNoticesFromBlockedUsersAsBlockedInJQueryObject(oldStreamState);
  711. }
  712. // mark all notices and profile cards from muted users as muted
  713. markAllNoticesFromMutedUsersAsMutedInJQueryObject(oldStreamState);
  714. markAllProfileCardsFromMutedUsersAsMutedInDOM();
  715. // hide dublicate repeats, only show the first/oldest instance of a notice
  716. oldStreamState = hideAllButOldestInstanceOfStreamItem(oldStreamState);
  717. // show full notice text for all cached notices, if we have it in cache
  718. $.each(oldStreamState.children('.stream-item'),function(){
  719. getFullUnshortenedHtmlForQueet($(this),true);
  720. });
  721. // if this is notidfications we have seen obviously seen them before
  722. oldStreamState.children('.stream-item').removeClass('not-seen');
  723. $('#feed-body').html(oldStreamState.html());
  724. // set location bar from stream
  725. if(setLocation) {
  726. setUrlFromStream(streamObject);
  727. setLocation = false; // don't set location twice if we've already set it here
  728. }
  729. // update all queets times
  730. updateAllQueetsTimes();
  731. // also mark this stream as the current stream immediately, if a saved copy exists
  732. addStreamToHistoryMenuAndMarkAsCurrent(streamObject);
  733. // make sure page-container and feed is visible
  734. $('#page-container').css('opacity','1');
  735. $('#feed').css('opacity','1');
  736. // run callbacks for this stream
  737. if(streamObject.callbacks !== false) {
  738. $.each(streamObject.callbacks, function(){
  739. if(typeof window[this] == 'function') {
  740. window[this]();
  741. }
  742. });
  743. }
  744. // maybe do something
  745. if(typeof actionOnSuccess == 'function') {
  746. actionOnSuccess();
  747. // don't invoke actionOnSuccess later if we already invoked it here
  748. actionOnSuccess = false;
  749. }
  750. }
  751. // (2) if we don't have a cached version we remove and hide the old stream and wait for the new one to load
  752. else {
  753. $('.profile-card,.hover-card,.hover-card-caret').remove();
  754. $('#feed').css('opacity',0);
  755. $('#feed-body').html('');
  756. remove_spinner(); display_spinner(); // display spinner in page header instead feed header
  757. }
  758. // (3) change design immediately to either cached design or logged in user's
  759. if(typeof window.oldStreamsDesigns[window.currentStreamObject.nickname] != 'undefined') {
  760. changeDesign(window.oldStreamsDesigns[window.currentStreamObject.nickname]);
  761. }
  762. else {
  763. changeDesign({backgroundimage:window.loggedIn.background_image, backgroundcolor:window.loggedIn.backgroundcolor, linkcolor:window.loggedIn.linkcolor});
  764. }
  765. }
  766. // get stream
  767. getFromAPI(streamObject.stream, function(queet_data, userArray, error, url){
  768. // while waiting for this data user might have changed stream, so only proceed if current stream still is this one
  769. if(window.currentStreamObject.stream != streamObject.stream) {
  770. console.log('stream has changed, aborting');
  771. return;
  772. }
  773. // if we have a fallbackId and a userArray, and the userArray's id is not equal to
  774. // the fallackId, this is the wrong stream! we need to re-invoke setNewCurrentStream()
  775. // with the correct and up-to-date nickname (maybe best not to send a fallbackId here not
  776. // to risk getting into an infinite loop caused by bad data)
  777. // also, we do the same thing if getting the stream fails, but we have a fallback id
  778. if((userArray && fallbackId && userArray.id != fallbackId)
  779. || (queet_data === false && fallbackId)) {
  780. if(streamObject.name == 'profile') {
  781. getNicknameByUserIdFromAPI(fallbackId,function(nickname) {
  782. if(nickname) {
  783. setNewCurrentStream(pathToStreamRouter(nickname),true,false,actionOnSuccess);
  784. }
  785. else {
  786. // redirect to front page if everything fails
  787. setNewCurrentStream(pathToStreamRouter('/'),true,false,actionOnSuccess);
  788. }
  789. });
  790. }
  791. else if(streamObject.name == 'group notice stream') {
  792. getNicknameByGroupIdFromAPI(fallbackId,function(nickname) {
  793. if(nickname) {
  794. setNewCurrentStream(pathToStreamRouter('group/' + nickname),true,false,actionOnSuccess);
  795. }
  796. else {
  797. // redirect to front page if everything fails
  798. setNewCurrentStream(pathToStreamRouter('/'),true,false,actionOnSuccess);
  799. }
  800. });
  801. }
  802. }
  803. // getting stream failed, and we don't have a fallback id
  804. else if(queet_data === false) {
  805. // e.g. maybe fade in user-container here, ("success" was a badly chosen name...)
  806. if(typeof actionOnSuccess == 'function') {
  807. actionOnSuccess();
  808. }
  809. if(error.status == 401) {
  810. showErrorMessage(window.sL.ERRORmustBeLoggedIn);
  811. }
  812. else if(error.status == 404) {
  813. if(streamObject.name == 'profile'
  814. || streamObject.name == 'friends timeline'
  815. || streamObject.name == 'mentions'
  816. || streamObject.name == 'favorites'
  817. || streamObject.name == 'subscribers'
  818. || streamObject.name == 'subscriptions'
  819. || streamObject.name == 'user group list') {
  820. showErrorMessage(window.sL.ERRORcouldNotFindUserWithNickname.replace('{nickname}',replaceHtmlSpecialChars(streamObject.nickname)));
  821. }
  822. else if(streamObject.name == 'group notice stream'
  823. || streamObject.name == 'group member list'
  824. || streamObject.name == 'group admin list') {
  825. showErrorMessage(window.sL.ERRORcouldNotFindGroupWithNickname.replace('{nickname}',replaceHtmlSpecialChars(streamObject.nickname)));
  826. }
  827. else if(streamObject.name == 'list notice stream'
  828. || streamObject.name == 'list members'
  829. || streamObject.name == 'list subscribers') {
  830. showErrorMessage(window.sL.ERRORcouldNotFindList);
  831. }
  832. else {
  833. showErrorMessage(window.sL.ERRORcouldNotFindPage + '<br><br>url: ' + url);
  834. }
  835. emptyRememberAndHideFeed();
  836. }
  837. else if(error.status == 410 && streamObject.name == 'notice') {
  838. showErrorMessage(window.sL.ERRORnoticeRemoved);
  839. emptyRememberAndHideFeed();
  840. }
  841. else if(error.status == 0
  842. || (error.status == 200 && error.responseText == 'An error occurred.')
  843. ) {
  844. showErrorMessage(window.sL.ERRORnoContactWithServer + ' (' + replaceHtmlSpecialChars(error.statusText) + ')');
  845. // don't hide feed for these errors
  846. }
  847. else if (typeof error.responseJSON != 'undefined' && typeof error.responseJSON.error != 'undefined' && error.responseJSON.error.length > 0) {
  848. showErrorMessage(error.responseJSON.error);
  849. emptyRememberAndHideFeed();
  850. }
  851. else {
  852. showErrorMessage(window.sL.ERRORsomethingWentWrong + '<br><br>\
  853. url: ' + url + '<br><br>\
  854. jQuery ajax() error:<pre><code>' + replaceHtmlSpecialChars(JSON.stringify(error, null, ' ')) + '</code></pre>\
  855. ');
  856. }
  857. // make sure page-container is visible
  858. $('#page-container').css('opacity','1');
  859. }
  860. // everything seems fine, show the new stream
  861. else if(queet_data) {
  862. // set location bar from stream
  863. if(setLocation) {
  864. setUrlFromStream(streamObject);
  865. }
  866. // profile card from user array
  867. if(userArray) {
  868. addProfileCardToDOM(buildProfileCard(userArray));
  869. }
  870. // remove any trailing profile cards
  871. else {
  872. $('.profile-card').remove();
  873. }
  874. // show group profile card if this is a group stream
  875. if(streamObject.name == 'group notice stream'
  876. || streamObject.name == 'group member list'
  877. || streamObject.name == 'group admin list') {
  878. groupProfileCard(streamObject.nickname);
  879. }
  880. // say hello to the api if this is notifications stream, to
  881. // get correct unread notifcation count
  882. if(window.currentStreamObject.name == 'notifications') {
  883. helloAPI();
  884. }
  885. // start checking for new queets again
  886. window.clearInterval(checkForNewQueetsInterval);
  887. checkForNewQueetsInterval=window.setInterval(function(){checkForNewQueets()},window.timeBetweenPolling);
  888. // add this stream to the history menu
  889. addStreamToHistoryMenuAndMarkAsCurrent(streamObject);
  890. remove_spinner();
  891. // some streams, e.g. /statuses/show/1234.json is not enclosed in an array, make sure it is
  892. if(!$.isArray(queet_data)) {
  893. queet_data = [queet_data];
  894. }
  895. // empty feed-body if this is a
  896. // (1) notice page
  897. // (2) if we got an empty result
  898. // (3) it's not a stream of notices or notifications
  899. if(window.currentStreamObject.name == 'notice'
  900. || queet_data.length==0
  901. || (window.currentStreamObject.type != 'notices' && window.currentStreamObject.type != 'notifications')) {
  902. $('#feed-body').html('');
  903. }
  904. // if the last item in the stream doesn't exists in the feed-body, we can't
  905. // just prepend the new items, since it will create a gap in the middle of the
  906. // feed. in that case we just empty the body and start from scratch
  907. else if($('#feed-body').children('.stream-item[data-quitter-id-in-stream="' + queet_data.slice(-1)[0].id + '"]').length == 0) {
  908. $('#feed-body').html('');
  909. }
  910. // if the stream is slow to load, the user might have expanded a notice, or scrolled down
  911. // and started reading. in that case we add the new items _hidden_
  912. if($('#feed-body').children('.stream-item.expanded').length>0 || $(window).scrollTop() > 50) {
  913. addToFeed(queet_data, false,'hidden');
  914. maybeShowTheNewQueetsBar();
  915. }
  916. else {
  917. addToFeed(queet_data, false,'visible');
  918. }
  919. // make sure page-container is visible
  920. $('#page-container').css('opacity','1');
  921. $('#feed').css('opacity','1');
  922. // run callbacks for this stream
  923. if(streamObject.callbacks !== false) {
  924. $.each(streamObject.callbacks, function(){
  925. if(typeof window[this] == 'function') {
  926. window[this]();
  927. }
  928. });
  929. }
  930. $('.reload-stream').show();
  931. $('body').removeClass('loading-older');$('body').removeClass('loading-newer');
  932. // maybe do something
  933. if(typeof actionOnSuccess == 'function') {
  934. actionOnSuccess();
  935. }
  936. }
  937. });
  938. }
  939. /* ·
  940. ·
  941. · Empties the feed body, remembers the new empty state in localstorage and hide the feed and any profile card
  942. · and mark this stream as current
  943. ·
  944. · · · · · · · · · */
  945. function emptyRememberAndHideFeed() {
  946. $('#feed').css('opacity','0');
  947. $('#feed-body').empty();
  948. $('.profile-card').remove();
  949. rememberStreamStateInLocalStorage();
  950. }
  951. /* ·
  952. ·
  953. · Add this stream to history menu if it doesn't exist in stream selection menus (if we're logged in)
  954. · and mark this stream as current
  955. ·
  956. · @param streamObject: stream object returned by pathToStreamRouter()
  957. ·
  958. · · · · · · · · · */
  959. function addStreamToHistoryMenuAndMarkAsCurrent(streamObject) {
  960. if(streamObject.parentPath) {
  961. var urlToMarkAsCurrent = window.siteInstanceURL + streamObject.parentPath;
  962. }
  963. else {
  964. var urlToMarkAsCurrent = window.siteInstanceURL + streamObject.path;
  965. }
  966. if($('.stream-selection[href="' + urlToMarkAsCurrent + '"]').length==0
  967. && typeof window.loggedIn.screen_name != 'undefined') {
  968. $('#history-container').prepend('<a class="stream-selection" href="' + urlToMarkAsCurrent + '">' + streamObject.streamHeader + '<i class="chev-right" data-tooltip="' + window.sL.tooltipBookmarkStream + '"></i></a>');
  969. updateHistoryLocalStorage();
  970. // max 10 in history container
  971. var historyNum = $('#history-container').children('.stream-selection').length;
  972. if(historyNum > 10) {
  973. $('#history-container').children('.stream-selection').slice(-(historyNum-10)).remove();
  974. }
  975. }
  976. $('.stream-selection').removeClass('current');
  977. $('.stream-selection[href="' + urlToMarkAsCurrent + '"]').addClass('current');
  978. }
  979. /* ·
  980. ·
  981. · Expand/de-expand queet
  982. ·
  983. · @param q: the stream item to expand
  984. · @param doScrolling: if we should scroll back to position or not
  985. ·
  986. · · · · · · · · · */
  987. function expand_queet(q,doScrolling) {
  988. // don't do anything if this is a queet being posted
  989. if(q.hasClass('temp-post')) {
  990. return;
  991. }
  992. // don't expand if this is a popup
  993. if(q.closest('.modal-container').length>0) {
  994. return;
  995. }
  996. doScrolling = typeof doScrolling !== 'undefined' ? doScrolling : true;
  997. var qid = q.attr('data-quitter-id');
  998. // de-expand if expanded
  999. if(q.hasClass('expanded') && !q.hasClass('collapsing')) {
  1000. var sel = getSelection().toString();
  1001. if(!sel
  1002. && !q.find('.queet-button').children('button').hasClass('enabled')
  1003. && !q.find('.queet-button').children('button').hasClass('too-long')) { // don't collapse if text is selected, or if queet has an active queet button, or if queet text is too long
  1004. // remove some things right away
  1005. q.find('.inline-reply-caret').remove();
  1006. // "unplay" gif image on collapse if there's only one attachment (switch to thumb)
  1007. var gifToUnPlay = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button').children('.attachment-thumb[data-mime-type="image/gif"]');
  1008. if(gifToUnPlay.length > 0) {
  1009. gifToUnPlay.attr('src',gifToUnPlay.attr('data-thumb-url'));
  1010. gifToUnPlay.parent('.thumb-container').css('background-image','url(\'' + gifToUnPlay.attr('data-thumb-url') + '\')');
  1011. }
  1012. // show thumbs (if hidden) and remove any iframe video immediately
  1013. q.children('.queet').find('.queet-thumbs').removeClass('hide-thumbs');
  1014. q.children('.queet').find('iframe').remove();
  1015. q.addClass('collapsing');
  1016. if(q.hasClass('conversation')) {
  1017. q.removeClass('expanded');
  1018. q.removeClass('collapsing');
  1019. q.find('.view-more-container-top').remove();
  1020. q.find('.view-more-container-bottom').remove();
  1021. q.find('.stream-item.conversation').remove();
  1022. q.find('.inline-reply-queetbox').remove();
  1023. q.find('.expanded-content').remove();
  1024. }
  1025. else {
  1026. rememberMyScrollPos(q.children('.queet'),qid,0);
  1027. // give stream item a height
  1028. q.css('height',q.height() + 'px');
  1029. q.children('.queet').find('.expanded-content').css('height',q.find('.expanded-content').height() + 'px');
  1030. q.children('.queet').find('.queet-thumbs.thumb-num-1').css('max-height',q.find('.queet-thumbs.thumb-num-1').height() + 'px');
  1031. q.children('.queet').find('.queet-thumbs.thumb-num-1 .thumb-container').css('max-height',q.find('.queet-thumbs.thumb-num-1').height() + 'px');
  1032. q.children('div').not('.queet').children('a').css('opacity','0.5');
  1033. q.children('div').not('.queet').children().children().css('opacity','0.5');
  1034. var collapseTime = 100 + q.find('.stream-item.conversation:not(.hidden-conversation)').length*50;
  1035. // set transition time (needs to be delayed, otherwise webkit animates the height-setting above)
  1036. setTimeout(function() {
  1037. q.children('.queet').css('-moz-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1038. q.children('.queet').css('-o-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1039. q.children('.queet').css('-webkit-transition-duration',Math.round( collapseTime * 1000 * 10) / 10 + 's');
  1040. q.children('.queet').css('transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1041. q.children('.queet').find('.expanded-content, .queet-thumbs.thumb-num-1, .queet-thumbs.thumb-num-1 .thumb-container').css('-moz-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1042. q.children('.queet').find('.expanded-content, .queet-thumbs.thumb-num-1, .queet-thumbs.thumb-num-1 .thumb-container').css('-o-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1043. q.children('.queet').find('.expanded-content, .queet-thumbs.thumb-num-1, .queet-thumbs.thumb-num-1 .thumb-container').css('-webkit-transition-duration',Math.round( collapseTime * 1000 * 10) / 10 + 's');
  1044. q.children('.queet').find('.expanded-content, .queet-thumbs.thumb-num-1, .queet-thumbs.thumb-num-1 .thumb-container').css('transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1045. q.css('-moz-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1046. q.css('-o-transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1047. q.css('-webkit-transition-duration',Math.round( collapseTime * 1000 * 10) / 10 + 's');
  1048. q.css('transition-duration',Math.round( collapseTime / 1000 * 10) / 10 + 's');
  1049. // set new heights and margins to animate to
  1050. var animateToHeight = q.children('.queet').outerHeight() - q.find('.inline-reply-queetbox').outerHeight() - q.children('.queet').find('.expanded-content').outerHeight() - Math.max(0,q.children('.queet').find('.queet-thumbs.thumb-num-1').outerHeight()-250) - 2;
  1051. if(animateToHeight < 73) { // no less than this
  1052. animateToHeight = 73;
  1053. }
  1054. q.css('height',animateToHeight + 'px');
  1055. q.children('.queet').css('margin-top', '-' + (q.children('.queet').offset().top - q.offset().top) + 'px');
  1056. q.children('.queet').find('.expanded-content').css('height','0');
  1057. q.children('.queet').find('.queet-thumbs.thumb-num-1, .queet-thumbs.thumb-num-1 .thumb-container').css('max-height','250px');
  1058. if(doScrolling) {
  1059. setTimeout(function() {
  1060. backToMyScrollPos(q,qid,500,function(){
  1061. cleanUpAfterCollapseQueet(q);
  1062. });
  1063. }, collapseTime);
  1064. }
  1065. else {
  1066. setTimeout(function() {
  1067. cleanUpAfterCollapseQueet(q);
  1068. }, collapseTime);
  1069. }
  1070. }, 50);
  1071. }
  1072. }
  1073. }
  1074. else if(!q.hasClass('collapsing')) {
  1075. // not for acitivity or notifications
  1076. if(!q.hasClass('activity') && !q.hasClass('repeat') && !q.hasClass('like') && !q.hasClass('follow')) {
  1077. q.addClass('expanded');
  1078. q.prev().addClass('next-expanded');
  1079. // get full html, if shortened
  1080. getFullUnshortenedHtmlForQueet(q);
  1081. // add expanded container
  1082. var longdate = parseTwitterLongDate(q.find('.created-at').attr('data-created-at'));
  1083. var qurl = q.find('.created-at').find('a').attr('href');
  1084. var metadata = '<span class="longdate" title="' + longdate + '">' + longdate + ' · ' + unescape(q.attr('data-source')) + '</span> · <a href="' + qurl + '" class="permalink-link">' + window.sL.details + '</a>';
  1085. // show expanded content
  1086. q.find('.stream-item-footer').before('<div class="expanded-content"><div class="queet-stats-container"></div><div class="client-and-actions"><span class="metadata">' + metadata + '</span></div></div>');
  1087. // "play" gif image on expand if there's only one attachment (switch to full gif from thumb)
  1088. var gifToPlay = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button').children('.attachment-thumb[data-mime-type="image/gif"]');
  1089. if(gifToPlay.length > 0) {
  1090. gifToPlay.attr('src',gifToPlay.attr('data-full-image-url'));
  1091. gifToPlay.parent('.thumb-container').css('background-image','url(\'' + gifToPlay.attr('data-full-image-url') + '\')');
  1092. }
  1093. // if there's only one thumb and it's a youtube video, show it inline
  1094. if(q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.host-youtube-com').length == 1) {
  1095. var youtubeURL = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.host-youtube-com').children('.attachment-thumb').attr('data-full-image-url');
  1096. if(q.children('.queet').find('.expanded-content').children('.media').children('iframe[src="' + youTubeEmbedLinkFromURL(youtubeURL) + '"]').length < 1) { // not if already showed
  1097. q.children('.queet').find('.queet-thumbs').addClass('hide-thumbs');
  1098. // show video
  1099. q.children('.queet').find('.expanded-content').prepend('<div class="media"><iframe width="510" height="315" src="' + youTubeEmbedLinkFromURL(youtubeURL) + '" frameborder="0" allowfullscreen></iframe></div>');
  1100. }
  1101. }
  1102. // if there's only one thumb and it's a vimeo video, show it inline
  1103. else if(q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.host-vimeo-com').length == 1) {
  1104. var vimeoURL = q.children('.queet').find('.queet-thumbs.thumb-num-1').children('.thumb-container.play-button.host-vimeo-com').children('.attachment-thumb').attr('data-full-image-url');
  1105. var embedURL = vimeoEmbedLinkFromURL(vimeoURL);
  1106. if(q.children('.queet').find('.expanded-content').children('.media').children('iframe[src="' + embedURL + '"]').length < 1) { // not if already showed
  1107. q.children('.queet').find('.queet-thumbs').addClass('hide-thumbs');
  1108. // show video
  1109. q.children('.queet').find('.expanded-content').prepend('<iframe src="' + embedURL + '" width="510" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
  1110. }
  1111. }
  1112. // show certain attachments in expanded content
  1113. if(q.children('.queet').children('script.attachment-json').length > 0
  1114. && q.children('.queet').children('script.attachment-json').text() != 'undefined') {
  1115. try {
  1116. var attachmentsParsed = JSON.parse(q.children('.queet').children('script.attachment-json').text());
  1117. }
  1118. catch(e) {
  1119. var attachmentsParsed = false;
  1120. console.log('could not parse attachment json when expanding the notice: ' + e);
  1121. console.log("attachment-json: " + q.children('.queet').children('script.attachment-json').text());
  1122. }
  1123. if(attachmentsParsed !== false) {
  1124. $.each(attachmentsParsed, function() {
  1125. var attachment_mimetype = this.mimetype;
  1126. var attachment_title = this.url;
  1127. // filename extension
  1128. var attachment_title_extension = attachment_title.substr((~-attachment_title.lastIndexOf(".") >>> 0) + 2);
  1129. // attachments in the content link to /attachment/etc url and not direct to image/video, link is in title
  1130. if(typeof attachment_title != 'undefined') {
  1131. // videos
  1132. if($.inArray(attachment_mimetype, ['video/mp4', 'video/ogg', 'video/quicktime', 'video/webm']) >=0) {
  1133. if(q.children('.queet').find('.expanded-content').children('.media').children('video').children('source[href="' + attachment_title + '"]').length < 1) { // not if already showed
  1134. // local attachment with a thumbnail
  1135. var attachment_poster = '';
  1136. if(typeof this.thumb_url != 'undefined') {
  1137. attachment_poster = ' poster="' + this.thumb_url + '"';
  1138. }
  1139. if(q.children('.queet').find('.expanded-content').children('.media').length > 0) {
  1140. q.children('.queet').find('.media').last().after('<div class="media"><video class="u-video" controls="controls"' + attachment_poster + '><source type="' + attachment_mimetype + '" src="' + attachment_title + '" /></video></div>');
  1141. }
  1142. else {
  1143. q.children('.queet').find('.expanded-content').prepend('<div class="media"><video class="u-video" controls="controls"' + attachment_poster + '><source type="' + attachment_mimetype + '" src="' + attachment_title + '" /></video></div>');
  1144. }
  1145. }
  1146. }
  1147. else {
  1148. // other plugins, e.g. gotabulo, can check for other attachment file formats to expand
  1149. window.currentlyExpanding = {
  1150. "attachment_title":attachment_title,
  1151. "attachment_mimetype":attachment_mimetype,
  1152. "attachment_title_extension":attachment_title_extension,
  1153. "streamItem":q,
  1154. "thisAttachmentLink":$(this)
  1155. };
  1156. $(document).trigger('qvitterExpandOtherAttachments');
  1157. }
  1158. }
  1159. });
  1160. }
  1161. }
  1162. // get and show favs and repeats
  1163. getFavsAndRequeetsForQueet(q, qid);
  1164. // show conversation and reply form (but not if already in conversation)
  1165. if(!q.hasClass('conversation')) {
  1166. // show conversation
  1167. getConversation(q, qid);
  1168. // show inline reply form if logged in
  1169. if(typeof window.loggedIn.screen_name != 'undefined') {
  1170. q.children('.queet').append(replyFormHtml(q,qid));
  1171. maybePrefillQueetBoxWithCachedText(q.children('.queet').find('.queet-box'));
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. function cleanUpAfterCollapseQueet(streamItem) {
  1178. var queet = streamItem.children('.queet');
  1179. streamItem.css('height','auto');
  1180. queet.css('margin-top','0');
  1181. streamItem.removeClass('expanded');
  1182. streamItem.prev().removeClass('next-expanded');
  1183. streamItem.removeClass('collapsing');
  1184. streamItem.find('.expanded-content').remove();
  1185. streamItem.find('.view-more-container-top').remove();
  1186. streamItem.find('.view-more-container-bottom').remove();
  1187. streamItem.find('.inline-reply-queetbox').remove();
  1188. streamItem.children('.stream-item.conversation').remove();
  1189. streamItem.find('.show-full-conversation').remove();
  1190. streamItem.removeAttr('style');
  1191. queet.removeAttr('style');
  1192. queet.find('.queet-thumbs.thumb-num-1').removeAttr('style');
  1193. queet.find('.queet-thumbs.thumb-num-1 .thumb-container').css('max-height','');
  1194. }
  1195. /* ·
  1196. ·
  1197. · Get a popup queet box
  1198. ·
  1199. · @return the html for the queet box
  1200. ·
  1201. · · · · · · · · · */
  1202. function queetBoxPopUpHtml() {
  1203. // if we have cached text in localstorage
  1204. var data = localStorageObjectCache_GET('queetBoxInput','pop-up-queet-box');
  1205. if(data) {
  1206. var cachedText = encodeURIComponent(data);
  1207. }
  1208. var startText = encodeURIComponent(window.sL.compose);
  1209. return '<div class="inline-reply-queetbox"><div id="pop-up-queet-box" class="queet-box queet-box-syntax" data-start-text="' + startText + '" data-cached-text="' + cachedText + '">' + decodeURIComponent(startText) + '</div><div class="syntax-middle"></div><div class="syntax-two" contenteditable="true"></div><div class="mentions-suggestions"></div><div class="queet-toolbar toolbar-reply"><div class="queet-box-extras"><button data-tooltip="' + window.sL.tooltipAttachImage + '" class="upload-image"></button><button data-tooltip="' + window.sL.tooltipShortenUrls + '" class="shorten disabled">URL</button></div><div class="queet-button"><span class="queet-counter"></span><button>' + window.sL.queetVerb + '</button></div></div></div>';
  1210. }
  1211. /* ·
  1212. ·
  1213. · Get a reply form
  1214. ·
  1215. · @param q: the stream item to open reply form in
  1216. · @param qid: queet id
  1217. · @return the html for the reply form
  1218. ·
  1219. · · · · · · · · · */
  1220. function replyFormHtml(streamItem,qid) {
  1221. var q = streamItem.children('.queet');
  1222. // if we have cached text in localstorage
  1223. var data = localStorageObjectCache_GET('queetBoxInput','queet-box-' + qid);
  1224. if(data) {
  1225. var cachedText = encodeURIComponent(data);
  1226. }
  1227. // object with ostatus-uri as key to avoid duplicates
  1228. var screenNamesToAdd = {};
  1229. // add the screen name to the one we're replying to first (if it's not me)
  1230. if(!thisIsALinkToMyProfile(streamItem.attr('data-user-profile-url')) && typeof streamItem.attr('data-user-ostatus-uri') != 'undefined') {
  1231. screenNamesToAdd[streamItem.attr('data-user-ostatus-uri')] = streamItem.attr('data-user-screen-name');
  1232. }
  1233. // old style notice (probably cached, this can be removed later)
  1234. else if (typeof streamItem.attr('data-user-ostatus-uri') == 'undefined') {
  1235. screenNamesToAdd[q.find('.account-group').attr('href')] = q.find('.screen-name').text().replace('@','');
  1236. }
  1237. // add the rest of the attentions (not me)
  1238. if(q.children('script.attentions-json').length > 0
  1239. && q.children('script.attentions-json').text() != 'undefined') {
  1240. try {
  1241. var attentionsParsed = JSON.parse(q.children('script.attentions-json').text());
  1242. }
  1243. catch(e) {
  1244. var attentionsParsed = false;
  1245. console.log('could not parse attentions json: ' + e);
  1246. console.log("attentions-json: " + q.children('script.attentions-json').text());
  1247. }
  1248. if(attentionsParsed !== false) {
  1249. $.each(attentionsParsed, function() {
  1250. if(!thisIsALinkToMyProfile(this.profileurl)
  1251. && typeof screenNamesToAdd[this.ostatus_uri] == 'undefined') {
  1252. screenNamesToAdd[this.ostatus_uri] = this.screen_name;
  1253. }
  1254. });
  1255. }
  1256. }
  1257. // build reply/rant strings
  1258. var repliesText = '';
  1259. if(Object.keys(screenNamesToAdd).length < 1
  1260. && q.find('strong.name').attr('data-user-id') == window.loggedIn.id) {
  1261. if(streamItem.attr('data-in-reply-to-status-id') == 'null' || streamItem.attr('data-in-reply-to-status-id') == 'false' || streamItem.attr('data-in-reply-to-status-id') == 'undefined' || streamItem.attr('data-in-reply-to-status-id') == '') {
  1262. var startText = window.sL.startRant + ' ';
  1263. }
  1264. else {
  1265. var startText = window.sL.continueRant + ' ';
  1266. }
  1267. }
  1268. else {
  1269. var startText = window.sL.replyTo + ' ';
  1270. var repliesArray = [];
  1271. $.each(screenNamesToAdd, function(url,screenName){
  1272. repliesArray.push(screenName);
  1273. });
  1274. if(repliesArray.length>0) {
  1275. startText = '<a>@' + repliesArray.join('</a>&nbsp;<a>@') + '</a>&nbsp;<br>';
  1276. repliesText = '@' + repliesArray.join(' @') + '&nbsp;';
  1277. }
  1278. }
  1279. startText = encodeURIComponent(startText);
  1280. repliesText = encodeURIComponent(repliesText);
  1281. return '<div class="inline-reply-queetbox"><span class="inline-reply-caret"><span class="caret-inner"></span></span><img class="reply-avatar" src="' + $('#user-avatar').attr('src') + '" /><div class="queet-box queet-box-syntax" id="queet-box-' + qid + '" data-start-text="' + startText + '" data-replies-text="' + repliesText + '" data-cached-text="' + cachedText + '">' + decodeURIComponent(startText) + '</div><div class="syntax-middle"></div><div class="syntax-two" contenteditable="true"></div><div class="mentions-suggestions"></div><div class="queet-toolbar toolbar-reply"><div class="queet-box-extras"><button data-tooltip="' + window.sL.tooltipAttachImage + '" class="upload-image"></button><button data-tooltip="' + window.sL.tooltipShortenUrls + '" class="shorten disabled">URL</button></div><div class="queet-button"><span class="queet-counter"></span><button>' + window.sL.queetVerb + '</button></div></div></div>';
  1282. }
  1283. /* ·
  1284. ·
  1285. · Popup for replies, deletes, etc
  1286. ·
  1287. · @param popupId: popups id
  1288. · @param heading: popops header
  1289. · @param bodyHtml: popups body html
  1290. · @param footerHtml: popups footer html
  1291. ·
  1292. · · · · · · · · · · · · · */
  1293. function popUpAction(popupId, heading, bodyHtml, footerHtml, popUpWidth){
  1294. $('.modal-container').remove(); // remove any open popups
  1295. var allFooterHtml = '';
  1296. if(footerHtml) {
  1297. allFooterHtml = '<div class="modal-footer">' + footerHtml + '</div>';
  1298. }
  1299. $('body').prepend('<div id="' + popupId + '" class="modal-container"><div class="modal-draggable"><div class="modal-content"><button class="modal-close" type="button"><span class="icon"></span></button><div class="modal-header"><h3 class="modal-title">' + heading + '</h3></div><div class="modal-body">' + bodyHtml + '</div>' + allFooterHtml + '</div></div></div>');
  1300. var thisPopUp = $('#' + popupId).children('.modal-draggable');
  1301. if(typeof popUpWidth != 'undefined') {
  1302. thisPopUp.width(popUpWidth);
  1303. }
  1304. centerPopUp(thisPopUp);
  1305. }
  1306. function centerPopUp(thisPopUp) {
  1307. thisPopUp.css('margin-top','');
  1308. thisPopUp.css('margin-left','');
  1309. var this_modal_height = thisPopUp.height();
  1310. var this_modal_width = thisPopUp.width();
  1311. var popupPos = thisPopUp.offset().top - $(window).scrollTop();
  1312. if((popupPos-(this_modal_height/2))<5) {
  1313. var marginTop = 5-popupPos;
  1314. }
  1315. else {
  1316. var marginTop = 0-this_modal_height/2;
  1317. }
  1318. thisPopUp.css('margin-top', marginTop + 'px');
  1319. thisPopUp.css('margin-left', '-' + (this_modal_width/2) + 'px');
  1320. thisPopUp.draggable({ handle: ".modal-header" });
  1321. }
  1322. /* ·
  1323. ·
  1324. · Get and show conversation
  1325. ·
  1326. · This function has grown into a monster, needs fixing
  1327. ·
  1328. · · · · · · · · · · · · · */
  1329. function getConversation(q, qid) {
  1330. // check if we have a conversation for this notice cached in localstorage
  1331. var cacheData = localStorageObjectCache_GET('conversation',q.attr('data-conversation-id'));
  1332. if(cacheData) {
  1333. showConversation(q, qid, cacheData, 8);
  1334. }
  1335. // always get most recent conversation from server
  1336. getFromAPI('statusnet/conversation/' + q.attr('data-conversation-id') + '.json?count=100', function(data){ if(data) {
  1337. // cache in localstorage
  1338. localStorageObjectCache_STORE('conversation',q.attr('data-conversation-id'), data);
  1339. showConversation(q, qid,data, 0);
  1340. }});
  1341. }
  1342. function showConversation(q, qid, data, offsetScroll) {
  1343. if(data && !q.hasClass('collapsing')){
  1344. if(data.length>1) {
  1345. var before_or_after = 'before';
  1346. $.each(data.reverse(), function (key,obj) {
  1347. // switch to append after original queet
  1348. if(obj.id == qid) {
  1349. before_or_after = 'after';
  1350. }
  1351. // don't add clicked queet to DOM, but all else
  1352. // note: first we add the full conversation, but hidden
  1353. if(obj.id != qid) {
  1354. var queetTime = parseTwitterDate(obj.created_at);
  1355. var queetHtml = buildQueetHtml(obj, obj.id, 'hidden-conversation', false, true);
  1356. if(q.hasClass('expanded')) { // add queet to conversation only if still expanded
  1357. // don't add if already exist in conversation
  1358. if(q.children('.stream-item.conversation[data-quitter-id="' + obj.id + '"]').length > 0) {
  1359. // the data in the existing notice is updated automatically in searchForUpdatedNoticeData invoked from getFromAPI
  1360. }
  1361. else if(before_or_after == 'before') {
  1362. q.children('.queet').before(queetHtml);
  1363. }
  1364. else {
  1365. if(q.children('.queet').nextAll('.conversation').length < 1) {
  1366. q.children('.queet').after(queetHtml);
  1367. }
  1368. else {
  1369. q.children('.queet').nextAll('.conversation').last().after(queetHtml);
  1370. }
  1371. }
  1372. }
  1373. }
  1374. convertAttachmentMoreHref();
  1375. });
  1376. }
  1377. else {
  1378. remove_spinner();
  1379. }
  1380. // loop trough this stream items conversation and show the "strict" line of replies
  1381. rememberMyScrollPos(q.children('.queet'),qid,offsetScroll);
  1382. findInReplyToStatusAndShow(q,qid,q.attr('data-in-reply-to-status-id'),true,false);
  1383. backToMyScrollPos(q.children('.queet'),qid,false);
  1384. findAndMarkLastVisibleInConversation(q);
  1385. }
  1386. else {
  1387. remove_spinner();
  1388. }
  1389. }
  1390. /* ·
  1391. ·
  1392. · Add last&first visible class, since that's not possible to select in pure css
  1393. ·
  1394. · · · · · · · · · · · · · */
  1395. function findAndMarkLastVisibleInConversation(streamItem) {
  1396. streamItem.children().removeClass('last-visible');
  1397. streamItem.children().removeClass('first-visible-after-parent');
  1398. streamItem.children().not('.hidden-conversation').not('.always-hidden').last().addClass('last-visible');
  1399. streamItem.children('.queet').nextAll().not('.hidden-conversation').not('.always-hidden').first().addClass('first-visible-after-parent');
  1400. streamItem.children().removeClass('first-visible');
  1401. streamItem.children().not('.hidden-conversation').not('.always-hidden').first().addClass('first-visible');
  1402. }
  1403. /* ·
  1404. ·
  1405. · Recursive walker functions to view only reyplies to replies, not full conversation
  1406. ·
  1407. · · · · · · · · · · · · · */
  1408. function findInReplyToStatusAndShow(q, qid,reply,only_first,onlyINreplyto) {
  1409. var reply_found = q.find('.stream-item[data-quitter-id="' + reply + '"]');
  1410. var reply_found_reply_to = q.find('.stream-item[data-quitter-id="' + reply_found.attr('data-in-reply-to-status-id') + '"]');
  1411. if(reply_found.length>0) {
  1412. reply_found.removeClass('hidden-conversation');
  1413. reply_found.css('opacity','1');
  1414. if(only_first && reply_found_reply_to.length>0) {
  1415. if(q.children('.view-more-container-top').length < 1) {
  1416. if(q.children('.queet').prevAll('.hidden-conversation:not(.always-hidden)').length>0) {
  1417. q.prepend('<div class="view-more-container-top" data-trace-from="' + reply + '"><a>' + window.sL.viewMoreInConvBefore + '</a></div>');
  1418. }
  1419. }
  1420. findReplyToStatusAndShow(q, qid,qid,true);
  1421. }
  1422. else {
  1423. findInReplyToStatusAndShow(q, qid,reply_found.attr('data-in-reply-to-status-id'),false,onlyINreplyto);
  1424. }
  1425. }
  1426. else if(!onlyINreplyto) {
  1427. findReplyToStatusAndShow(q, qid,qid,true);
  1428. }
  1429. else {
  1430. checkForHiddenConversationQueets(q, qid);
  1431. }
  1432. }
  1433. // recursive function to find the replies to a status
  1434. function findReplyToStatusAndShow(q, qid,this_id,only_first) {
  1435. var replies_found = q.find('.stream-item[data-in-reply-to-status-id="' + this_id + '"]');
  1436. $.each(replies_found, function(k,reply_found){
  1437. var reply_founds_reply = q.find('.stream-item[data-in-reply-to-status-id="' + $(reply_found).attr('data-quitter-id') + '"]');
  1438. $(reply_found).removeClass('hidden-conversation');
  1439. $(reply_found).css('opacity','1');
  1440. if(!only_first) {
  1441. findReplyToStatusAndShow(q, qid,$(this).attr('data-quitter-id'),false);
  1442. }
  1443. if(only_first && reply_founds_reply.length>0) {
  1444. if(q.children('.view-more-container-bottom').length < 1) {
  1445. if(q.children('.queet').nextAll('.hidden-conversation:not(.always-hidden)').length>0) {
  1446. q.append('<div class="view-more-container-bottom" data-replies-after="' + qid + '"><a>' + window.sL.viewMoreInConvAfter + '</a></div>');
  1447. }
  1448. }
  1449. }
  1450. });
  1451. checkForHiddenConversationQueets(q, qid);
  1452. }
  1453. // helper function for the above recursive functions
  1454. function checkForHiddenConversationQueets(q, qid) {
  1455. // here we check if there are any remaining hidden queets in conversation, if there are, we put a "show full conversation"-link
  1456. if(q.find('.hidden-conversation:not(.always-hidden)').length>0) {
  1457. if(q.children('.queet').find('.show-full-conversation').length == 0) {
  1458. q.children('.queet').find('.stream-item-footer').append('<span class="show-full-conversation" data-stream-item-id="' + qid + '">' + window.sL.expandFullConversation + '</span>');
  1459. }
  1460. }
  1461. else {
  1462. q.children('.queet').find('.show-full-conversation').remove();
  1463. }
  1464. }
  1465. /* ·
  1466. ·
  1467. · Build stream items and add them to feed
  1468. ·
  1469. · Also a function that has grown out of control... Needs total makeover
  1470. ·
  1471. · · · · · · · · · · · · · */
  1472. function addToFeed(feed, after, extraClasses) {
  1473. // some streams, e.g. /statuses/show/1234.json is not enclosed in an array, make sure it is
  1474. if(!$.isArray(feed)) {
  1475. feed = [feed];
  1476. }
  1477. var addedToTopOfFeedBodyNum = 0;
  1478. $.each(feed.reverse(), function (key,obj) {
  1479. var extraClassesThisRun = extraClasses;
  1480. // if this is the notifications feed
  1481. if(window.currentStreamObject.name == 'notifications') {
  1482. // don't show any notices with object_type "activity"
  1483. if(typeof obj.notice != 'undefined' && obj.notice !== null && obj.notice.is_post_verb === false) {
  1484. return true;
  1485. }
  1486. // only if this notification isn't already in stream
  1487. if($('#feed-body > .stream-item[data-quitter-id-in-stream="' + obj.id + '"]').length == 0) {
  1488. obj.from_profile.description = obj.from_profile.description || '';
  1489. var notificationTime = parseTwitterDate(obj.created_at);
  1490. if(obj.is_seen == '0') {
  1491. extraClassesThisRun += ' not-seen';
  1492. }
  1493. if(isUserMuted(obj.from_profile.id)) {
  1494. extraClassesThisRun += ' user-muted';
  1495. }
  1496. // external
  1497. var ostatusHtml = '';
  1498. if(obj.from_profile.is_local === false) {
  1499. ostatusHtml = '<a target="_blank" data-tooltip="' + window.sL.goToOriginalNotice + '" class="ostatus-link" href="' + obj.from_profile.statusnet_profile_url + '"></a>';
  1500. }
  1501. if(obj.ntype == 'like') {
  1502. var noticeTime = parseTwitterDate(obj.notice.created_at);
  1503. var notificationHtml = '<div data-user-id="' + obj.from_profile.id + '" data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification like">\
  1504. <div class="queet">\
  1505. <div class="dogear"></div>\
  1506. ' + ostatusHtml + '\
  1507. <div class="queet-content">\
  1508. <div class="stream-item-header">\
  1509. <a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '" data-user-id="' + obj.from_profile.id + '">\
  1510. <img class="avatar standard-size" src="' + obj.from_profile.profile_image_url + '" data-user-id="' + obj.from_profile.id + '" />\
  1511. <strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">\
  1512. ' + obj.from_profile.name + '\
  1513. </strong>\
  1514. </a> \
  1515. ' + window.sL.xFavedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" data-tooltip="' + parseTwitterLongDate(obj.created_at) + '"> <a>' + notificationTime + '</a></small>\
  1516. </div>\
  1517. <div class="small-grey-notice">\
  1518. <a data-created-at="' + obj.notice.created_at + '" data-tooltip="' + parseTwitterLongDate(obj.notice.created_at) + '" href="' + window.siteInstanceURL + 'notice/' + obj.notice.id + '">\
  1519. ' + noticeTime + '\
  1520. </a>: \
  1521. ' + $.trim(obj.notice.statusnet_html) + '\
  1522. </div>\
  1523. </div>\
  1524. </div>\
  1525. </div>';
  1526. }
  1527. else if(obj.ntype == 'repeat') {
  1528. var noticeTime = parseTwitterDate(obj.notice.created_at);
  1529. var notificationHtml = '<div data-user-id="' + obj.from_profile.id + '" data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification repeat">\
  1530. <div class="queet">\
  1531. <div class="dogear"></div>\
  1532. ' + ostatusHtml + '\
  1533. <div class="queet-content">\
  1534. <div class="stream-item-header">\
  1535. <a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '" data-user-id="' + obj.from_profile.id + '">\
  1536. <img class="avatar standard-size" src="' + obj.from_profile.profile_image_url + '" data-user-id="' + obj.from_profile.id + '" />\
  1537. <strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">\
  1538. ' + obj.from_profile.name + '\
  1539. </strong>\
  1540. </a> \
  1541. ' + window.sL.xRepeatedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" data-tooltip="' + parseTwitterLongDate(obj.created_at) + '"> <a>' + notificationTime + '</a></small>\
  1542. </div>\
  1543. <div class="small-grey-notice">\
  1544. <a data-created-at="' + obj.notice.created_at + '" data-tooltip="' + parseTwitterLongDate(obj.notice.created_at) + '" href="' + window.siteInstanceURL + 'notice/' + obj.notice.id + '">\
  1545. ' + noticeTime + '\
  1546. </a>: \
  1547. ' + $.trim(obj.notice.statusnet_html) + '\
  1548. </div>\
  1549. </div>\
  1550. </div>\
  1551. </div>';
  1552. }
  1553. else if(obj.ntype == 'mention') {
  1554. var notificationHtml = buildQueetHtml(obj.notice, obj.id, extraClassesThisRun + ' notification mention');
  1555. }
  1556. else if(obj.ntype == 'reply') {
  1557. var notificationHtml = buildQueetHtml(obj.notice, obj.id, extraClassesThisRun + ' notification reply');
  1558. }
  1559. else if(obj.ntype == 'follow') {
  1560. var notificationHtml = '<div data-user-id="' + obj.from_profile.id + '" data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification follow">\
  1561. <div class="queet">\
  1562. <div class="queet-content">\
  1563. ' + ostatusHtml + '\
  1564. <div class="stream-item-header">\
  1565. <a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '" data-user-id="' + obj.from_profile.id + '">\
  1566. <img class="avatar standard-size" src="' + obj.from_profile.profile_image_url + '" data-user-id="' + obj.from_profile.id + '" />\
  1567. <strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">\
  1568. ' + obj.from_profile.name + '\
  1569. </strong>\
  1570. </a> \
  1571. ' + window.sL.xStartedFollowingYou + '<small class="created-at" data-created-at="' + obj.created_at + '" title="' + obj.created_at + '"> <a>' + notificationTime + '</a></small>\
  1572. </div>\
  1573. </div>\
  1574. </div>\
  1575. </div>';
  1576. }
  1577. if(after) {
  1578. $('#' + after).after(notificationHtml);
  1579. }
  1580. else {
  1581. $('#feed-body').prepend(notificationHtml);
  1582. addedToTopOfFeedBodyNum++;
  1583. }
  1584. }
  1585. }
  1586. // if this is a user feed
  1587. else if(window.currentStreamObject.type == 'users') {
  1588. // only if not user is already in stream
  1589. if($('#stream-item-' + obj.id).length == 0) {
  1590. var userHtml = buildUserStreamItemHtml(obj);
  1591. if(after) {
  1592. $('#' + after).after(userHtml);
  1593. }
  1594. else {
  1595. $('#feed-body').prepend(userHtml);
  1596. addedToTopOfFeedBodyNum++;
  1597. }
  1598. }
  1599. }
  1600. // if this is a list of groups
  1601. else if(window.currentStreamObject.type == 'groups') {
  1602. // only if not group is already in stream
  1603. if($('#stream-item-' + obj.id).length == 0) {
  1604. obj.description = obj.description || '';
  1605. obj.stream_logo = obj.stream_logo || window.defaultAvatarStreamSize;
  1606. // rtl or not
  1607. var rtlOrNot = '';
  1608. if($('body').hasClass('rtl')) {
  1609. rtlOrNot = 'rtl';
  1610. }
  1611. // show group actions if logged in
  1612. var memberClass = '';
  1613. if(obj.member) {
  1614. memberClass = 'member';
  1615. }
  1616. var memberButton = '';
  1617. if(typeof window.loggedIn.screen_name != 'undefined') {
  1618. var memberButton = '<div class="user-actions"><button data-group-id="' + obj.id + '" type="button" class="member-button ' + memberClass + '"><span class="button-text join-text"><i class="join"></i>' + window.sL.joinGroup + '</span><span class="button-text ismember-text">' + window.sL.isMemberOfGroup + '</span><span class="button-text leave-text">' + window.sL.leaveGroup + '</span></button></div>';
  1619. }
  1620. var groupAvatar = obj.stream_logo;
  1621. if(obj.homepage_logo != null) {
  1622. groupAvatar = obj.homepage_logo;
  1623. }
  1624. var groupHtml = '<div id="stream-item-' + obj.id + '" class="stream-item user"><div class="queet ' + rtlOrNot + '">' + memberButton + '<div class="queet-content"><div class="stream-item-header"><a class="account-group" href="' + obj.url + '"><img class="avatar" src="' + groupAvatar + '" /><strong class="name" data-group-id="' + obj.id + '">' + obj.fullname + '</strong> <span class="screen-name">!' + obj.nickname + '</span></a></div><div class="queet-text">' + obj.description + '</div></div></div></div>';
  1625. if(after) {
  1626. $('#' + after).after(groupHtml);
  1627. }
  1628. else {
  1629. $('#feed-body').prepend(groupHtml);
  1630. addedToTopOfFeedBodyNum++;
  1631. }
  1632. }
  1633. }
  1634. // if this is a retweet
  1635. // (note the difference between "the repeat-notice" and "the repeated notice")
  1636. // but the unrepeat delete activity notices have retweeted_status added to them, so check this is not a delete notice
  1637. else if(typeof obj.retweeted_status != 'undefined'
  1638. && (typeof obj.qvitter_delete_notice == 'undefined' || obj.qvitter_delete_notice === false)) {
  1639. // if repeat-notice doesn't already exist in feed
  1640. if($('#stream-item-' + obj.id).length == 0) {
  1641. // if the this or the repeated notice already exist in feed, we add this, but hidden
  1642. if($('.stream-item[data-quitter-id="' + obj.retweeted_status.id + '"]').length > 0) {
  1643. extraClassesThisRun += ' hidden-repeat';
  1644. }
  1645. var queetHtml = buildQueetHtml(obj.retweeted_status, obj.id, extraClassesThisRun, obj);
  1646. if(after) {
  1647. $('#' + after).after(queetHtml);
  1648. }
  1649. else {
  1650. $('#feed-body').prepend(queetHtml);
  1651. addedToTopOfFeedBodyNum++;
  1652. }
  1653. }
  1654. }
  1655. // ordinary tweet
  1656. else {
  1657. // only if not already exist
  1658. if($('#stream-item-' + obj.id).length == 0) {
  1659. // sometimes the notice already exist but in the form of a repeat, because of
  1660. // a repeat reaching our server before the actual notice, or because of date settings
  1661. // on different servers, anyhow, hide this notice if a repeat of it already exist in
  1662. // the stream, using the hidden-repeat class (a little confusing maybe)
  1663. if($('.stream-item[data-quitter-id="' + obj.id + '"]').length > 0) {
  1664. extraClassesThisRun += ' hidden-repeat';
  1665. }
  1666. // remove any matching temp post
  1667. if(typeof obj.user != 'undefined'
  1668. && obj.user.id == window.loggedIn.id
  1669. && $('#feed-body > .temp-post').length > 0
  1670. && after === false) {
  1671. $('#feed-body > .temp-post').each(function (){
  1672. if($(this).children('.queet').find('.queet-text').text() == obj.text) {
  1673. $(this).remove();
  1674. extraClassesThisRun = 'visible';
  1675. }
  1676. });
  1677. }
  1678. var queetHtml = buildQueetHtml(obj, obj.id, extraClassesThisRun);
  1679. if(after) {
  1680. $('#' + after).after(queetHtml);
  1681. }
  1682. else {
  1683. $('#feed-body').prepend(queetHtml);
  1684. addedToTopOfFeedBodyNum++;
  1685. // if this is a single notice, we expand it
  1686. if(window.currentStreamObject.name == 'notice') {
  1687. expand_queet($('#stream-item-' + obj.id));
  1688. }
  1689. }
  1690. }
  1691. }
  1692. });
  1693. convertAttachmentMoreHref();
  1694. // if we've added stuff to the top of feed-body, we update our stream cache
  1695. if(addedToTopOfFeedBodyNum>0) {
  1696. rememberStreamStateInLocalStorage();
  1697. }
  1698. $('.stream-selection').removeAttr('data-current-user-stream-name'); // don't remeber user feeds
  1699. }
  1700. /* ·
  1701. ·
  1702. · Build HTML for a user stream item from an object
  1703. ·
  1704. · @param obj: a user object
  1705. ·
  1706. · · · · · · · · · · · · · */
  1707. function buildUserStreamItemHtml(obj) {
  1708. obj.description = obj.description || '';
  1709. // external
  1710. var ostatusHtml = '';
  1711. if(obj.is_local === false) {
  1712. ostatusHtml = '<a target="_blank" title="' + window.sL.goToTheUsersRemoteProfile + '" class="ostatus-link" href="' + obj.statusnet_profile_url + '"></a>';
  1713. }
  1714. // rtl or not
  1715. var rtlOrNot = '';
  1716. if($('body').hasClass('rtl')) {
  1717. rtlOrNot = 'rtl';
  1718. }
  1719. // following?
  1720. var followingClass = '';
  1721. if(obj.following) {
  1722. followingClass = ' following';
  1723. }
  1724. // blocking?
  1725. var blockingClass = '';
  1726. if(obj.statusnet_blocking) {
  1727. blockingClass = ' blocking';
  1728. }
  1729. // silenced?
  1730. var silencedClass = '';
  1731. if(obj.is_silenced === true) {
  1732. silencedClass = ' silenced';
  1733. }
  1734. // sandboxed?
  1735. var sandboxedClass = '';
  1736. if(obj.is_sandboxed === true) {
  1737. sandboxedClass = ' sandboxed';
  1738. }
  1739. // logged in?
  1740. var loggedInClass = '';
  1741. if(window.loggedIn !== false) {
  1742. loggedInClass = ' logged-in';
  1743. }
  1744. // muted?
  1745. var mutedClass = '';
  1746. if(isUserMuted(obj.id)) {
  1747. mutedClass = ' user-muted';
  1748. }
  1749. var followButton = '';
  1750. if(typeof window.loggedIn.screen_name != 'undefined' // if logged in
  1751. && window.loggedIn.id != obj.id) { // not if this is me
  1752. if(!(obj.statusnet_profile_url.indexOf('/twitter.com/')>-1 && obj.following === false)) { // only unfollow twitter users
  1753. var followButton = buildFollowBlockbutton(obj);
  1754. }
  1755. }
  1756. return '<div id="stream-item-' + obj.id + '" class="stream-item user' + silencedClass + sandboxedClass + mutedClass + '" data-user-id="' + obj.id + '">\
  1757. <div class="queet ' + rtlOrNot + '">\
  1758. ' + followButton + '\
  1759. <div class="user-menu-cog' + silencedClass + sandboxedClass + loggedInClass + '" data-tooltip="' + window.sL.userOptions + '" data-user-id="' + obj.id + '" data-screen-name="' + obj.screen_name + '"></div>\
  1760. <div class="queet-content">\
  1761. <div class="stream-item-header">\
  1762. <a class="account-group" href="' + obj.statusnet_profile_url + '" data-user-id="' + obj.id + '">\
  1763. <img class="avatar profile-size" src="' + obj.profile_image_url_profile_size + '" data-user-id="' + obj.id + '" />\
  1764. <strong class="name" data-user-id="' + obj.id + '">' + obj.name + '</strong>\
  1765. <span class="silenced-flag" data-tooltip="' + window.sL.silencedStreamDescription + '">' + window.sL.silenced + '</span> \
  1766. <span class="sandboxed-flag" data-tooltip="' + window.sL.sandboxedStreamDescription + '">' + window.sL.sandboxed + '</span> \
  1767. <span class="screen-name" data-user-id="' + obj.id + '">@' + obj.screen_name + '</span>\
  1768. </a>\
  1769. ' + ostatusHtml + '\
  1770. </div>\
  1771. <div class="queet-text">' + obj.description + '</div>\
  1772. </div>\
  1773. </div>\
  1774. </div>';
  1775. }
  1776. /* ·
  1777. ·
  1778. · Build HTML for a queet from an object
  1779. ·
  1780. · @param obj: a queet object
  1781. · @param requeeted_by: if this is a requeet
  1782. ·
  1783. · · · · · · · · · · · · · */
  1784. function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversation) {
  1785. // if we've blocked this user, but it has slipped through anyway
  1786. var blockingTooltip = '';
  1787. if(typeof window.allBlocking != 'undefined') {
  1788. $.each(window.allBlocking,function(){
  1789. if(this == obj.user.id){
  1790. extraClasses += ' profile-blocked-by-me';
  1791. blockingTooltip = ' data-tooltip="' + window.sL.thisIsANoticeFromABlockedUser + '"';
  1792. return false; // break
  1793. }
  1794. });
  1795. }
  1796. // muted? (if class is not already added)
  1797. if(isUserMuted(obj.user.id) && extraClasses.indexOf(' user-muted') == -1) {
  1798. extraClasses += ' user-muted';
  1799. blockingTooltip = ' data-tooltip="' + window.sL.thisIsANoticeFromAMutedUser + '"';
  1800. }
  1801. // silenced?
  1802. if(obj.user.is_silenced === true) {
  1803. extraClasses += ' silenced';
  1804. }
  1805. // sandboxed?
  1806. if(obj.user.is_sandboxed === true) {
  1807. extraClasses += ' sandboxed';
  1808. }
  1809. // deleted?
  1810. if(typeof window.knownDeletedNotices[obj.uri] != 'undefined') {
  1811. extraClasses += ' deleted always-hidden';
  1812. }
  1813. // unrepeated?
  1814. if(typeof requeeted_by != 'undefined'
  1815. && requeeted_by !== false
  1816. && typeof window.knownDeletedNotices[requeeted_by.uri] != 'undefined') {
  1817. extraClasses += ' unrepeated always-hidden';
  1818. }
  1819. // activity? (hidden with css)
  1820. if(obj.source == 'activity' || obj.is_post_verb === false) {
  1821. extraClasses += ' activity always-hidden';
  1822. // because we had an xss issue with activities, the obj.statusnet_html of qvitter-deleted-activity-notices can contain unwanted html, so we escape, they are hidden anyway
  1823. obj.statusnet_html = replaceHtmlSpecialChars(obj.statusnet_html);
  1824. }
  1825. // if we have the full html for a truncated notice cached in localstorage, we use that
  1826. var cacheData = localStorageObjectCache_GET('fullQueetHtml',obj.id);
  1827. if(cacheData) {
  1828. obj.statusnet_html = cacheData;
  1829. }
  1830. // we don't want to print 'null' in in_reply_to_screen_name-attribute, someone might have that username!
  1831. var in_reply_to_screen_name = '';
  1832. if(obj.in_reply_to_screen_name != null) {
  1833. in_reply_to_screen_name = obj.in_reply_to_screen_name;
  1834. }
  1835. // conversations has some slightly different id's
  1836. var idPrepend = '';
  1837. if(typeof isConversation != 'undefined' && isConversation === true) {
  1838. var idPrepend = 'conversation-';
  1839. extraClasses += ' conversation'
  1840. }
  1841. // is this mine?
  1842. var isThisMine = 'not-mine';
  1843. if(obj.user.id == window.loggedIn.id) {
  1844. var isThisMine = 'is-mine';
  1845. }
  1846. // requeeted by me?
  1847. var requeetedByMe = '';
  1848. if(obj.repeated_id) {
  1849. requeetedByMe = ' data-requeeted-by-me-id="' + obj.repeated_id + '" ';
  1850. }
  1851. // requeet html
  1852. if(obj.repeated) {
  1853. var requeetHtml = '<li class="action-rt-container"><a class="with-icn done"><span class="icon sm-rt" title="' + window.sL.requeetedVerb + '"></span></a></li>';
  1854. extraClasses += ' requeeted';
  1855. }
  1856. else {
  1857. var requeetHtml = '<li class="action-rt-container"><a class="with-icn"><span class="icon sm-rt ' + isThisMine + '" title="' + window.sL.requeetVerb + '"></span></a></li>';
  1858. }
  1859. // favorite html
  1860. if(obj.favorited) {
  1861. var favoriteHtml = '<a class="with-icn done"><span class="icon sm-fav" title="' + window.sL.favoritedVerb + '"></span></a>';
  1862. extraClasses += ' favorited';
  1863. }
  1864. else {
  1865. var favoriteHtml = '<a class="with-icn"><span class="icon sm-fav" title="' + window.sL.favoriteVerb + '"></span></a>';
  1866. }
  1867. // actions only for logged in users
  1868. var queetActions = '';
  1869. if(typeof window.loggedIn.screen_name != 'undefined') {
  1870. queetActions = '<ul class="queet-actions"><li class="action-reply-container"><a class="with-icn"><span class="icon sm-reply" title="' + window.sL.replyVerb + '"></span></a></li>' + requeetHtml + '<li class="action-rq-num" data-rq-num="' + obj.repeat_num + '">' + obj.repeat_num + '</li><li class="action-fav-container">' + favoriteHtml + '</li><li class="action-fav-num" data-fav-num="' + obj.fave_num + '">' + obj.fave_num + '</li><li class="action-ellipsis-container"><a class="with-icn"><span class="icon sm-ellipsis" title="' + window.sL.ellipsisMore + '"></span></a></li></ul>';
  1871. }
  1872. // reply-to html
  1873. var reply_to_html = '';
  1874. if(obj.in_reply_to_screen_name !== null
  1875. && obj.in_reply_to_profileurl !== null
  1876. && obj.in_reply_to_profileurl != obj.user.statusnet_profile_url) {
  1877. var replyToProfileurl = obj.in_reply_to_profileurl;
  1878. var replyToScreenName = obj.in_reply_to_screen_name;
  1879. }
  1880. // if we don't have a reply-to, we might have attentions, in that case use the first one as reply
  1881. else if(typeof obj.attentions != 'undefined' && typeof obj.attentions[0] != 'undefined') {
  1882. var replyToProfileurl = obj.attentions[0].profileurl;
  1883. var replyToScreenName = obj.attentions[0].screen_name;
  1884. }
  1885. if(typeof replyToProfileurl != 'undefined' && typeof replyToScreenName != 'undefined') {
  1886. // if the reply-to nickname doesn't exist in the notice, we add a class to the reply-to nickname in the header, to make the reply more visible
  1887. var mentionedInline = '';
  1888. if(obj.statusnet_html.indexOf('>' + replyToScreenName + '<') === -1) {
  1889. var mentionedInline = 'not-mentioned-inline';
  1890. }
  1891. reply_to_html = '<span class="reply-to"><a class="h-card mention ' + mentionedInline + '" href="' + replyToProfileurl + '">@' + replyToScreenName + '</a></span> ';
  1892. }
  1893. // in-groups html
  1894. var in_groups_html = '';
  1895. if(typeof obj.statusnet_in_groups != 'undefined' && obj.statusnet_in_groups !== false && typeof obj.statusnet_in_groups === 'object') {
  1896. $.each(obj.statusnet_in_groups,function(){
  1897. in_groups_html = in_groups_html + ' <span class="in-groups"><a class="h-card group" href="' + this.url + '">!' + this.nickname + '</a></span>';
  1898. });
  1899. }
  1900. // requeets get's a context element and a identifying class
  1901. // uri used is the repeate-notice's uri for repeats, not the repetED notice's uri (necessary if someone deletes a repeat)
  1902. var URItoUse = obj.uri;
  1903. var requeetHtml = '';
  1904. if(typeof requeeted_by != 'undefined' && requeeted_by !== false) {
  1905. var requeetedByHtml = '<a data-user-id="' + requeeted_by.user.id + '" href="' + requeeted_by.user.statusnet_profile_url + '"> <b>' + requeeted_by.user.name + '</b></a>';
  1906. requeetHtml = '<div class="context" id="requeet-' + requeeted_by.id + '"><span class="with-icn"><i class="badge-requeeted" data-tooltip="' + parseTwitterDate(requeeted_by.created_at) + '"></i><span class="requeet-text"> ' + window.sL.requeetedBy.replace('{requeeted-by}',requeetedByHtml) + '</span></span></div>';
  1907. var URItoUse = requeeted_by.uri;
  1908. extraClasses += ' is-requeet';
  1909. }
  1910. // the URI for delete activity notices are the same as the notice that is to be deleted
  1911. // so we make the URI for the (hidden) actitity notice unique, otherwise we might remove
  1912. // the activity notice from DOM when we remove the deleted notice
  1913. if(typeof obj.qvitter_delete_notice != 'undefined' && obj.qvitter_delete_notice == true) {
  1914. URItoUse += '-activity-notice';
  1915. }
  1916. // attachment html and attachment url's to hide
  1917. var attachmentBuild = buildAttachmentHTML(obj.attachments);
  1918. var statusnetHTML = $('<div/>').html(obj.statusnet_html);
  1919. $.each(statusnetHTML.find('a'),function(k,aElement){
  1920. $.each(attachmentBuild.urlsToHide,function(k,urlToHide){
  1921. var urlToHideWithoutProtocol = removeProtocolFromUrl(urlToHide);
  1922. if(urlToHideWithoutProtocol == removeProtocolFromUrl($(aElement).attr('href'))
  1923. || urlToHideWithoutProtocol == removeProtocolFromUrl($(aElement).text())) {
  1924. $(aElement).addClass('hidden-embedded-link-in-queet-text')
  1925. }
  1926. });
  1927. });
  1928. // if statusnetHTML is contains <p>:s, unwrap those (diaspora..)
  1929. statusnetHTML.children('p').each(function(){
  1930. $(this).contents().unwrap();
  1931. });
  1932. // bookmarks created by the bookmark plugin get's a tooltip
  1933. statusnetHTML.find('.xfolkentry').each(function(){
  1934. $(this).attr('data-tooltip',window.sL.thisIsABookmark);
  1935. });
  1936. // find a place in the queet-text for the quoted notices
  1937. statusnetHTML = placeQuotedNoticesInQueetText(attachmentBuild.quotedNotices, statusnetHTML);
  1938. statusnetHTML = statusnetHTML.html();
  1939. // remove trailing <br>s from queet text
  1940. while (statusnetHTML.slice(-4) == '<br>') {
  1941. statusnetHTML = statusnetHTML.slice(0,-4);
  1942. }
  1943. // external
  1944. var ostatusHtml = '';
  1945. if(obj.user.is_local === false) {
  1946. ostatusHtml = '<a target="_blank" data-tooltip="' + window.sL.goToOriginalNotice + '" class="ostatus-link" href="' + obj.external_url + '"></a>';
  1947. var qSource = '<a href="' + obj.external_url + '">' + getHost(obj.external_url) + '</a>';
  1948. }
  1949. else {
  1950. var qSource = obj.source;
  1951. }
  1952. var queetTime = parseTwitterDate(obj.created_at);
  1953. var queetHtml = '<div \
  1954. id="' + idPrepend + 'stream-item-' + idInStream + '" \
  1955. data-uri="' + URItoUse + '" \
  1956. class="stream-item notice ' + extraClasses + '" \
  1957. data-source="' + escape(qSource) + '" \
  1958. data-quitter-id="' + obj.id + '" \
  1959. data-conversation-id="' + obj.statusnet_conversation_id + '" \
  1960. data-quitter-id-in-stream="' + idInStream + '" \
  1961. data-in-reply-to-screen-name="' + in_reply_to_screen_name + '" \
  1962. data-in-reply-to-profile-url="' + obj.in_reply_to_profileurl + '" \
  1963. data-in-reply-to-profile-ostatus-uri="' + obj.in_reply_to_ostatus_uri + '" \
  1964. data-in-reply-to-status-id="' + obj.in_reply_to_status_id + '"\
  1965. data-user-id="' + obj.user.id + '"\
  1966. data-user-screen-name="' + obj.user.screen_name + '"\
  1967. data-user-ostatus-uri="' + obj.user.ostatus_uri + '"\
  1968. data-user-profile-url="' + obj.user.statusnet_profile_url + '"\
  1969. ' + requeetedByMe + '>\
  1970. <div class="queet" id="' + idPrepend + 'q-' + idInStream + '"' + blockingTooltip + '>\
  1971. <script class="attachment-json" type="application/json">' + JSON.stringify(obj.attachments) + '</script>\
  1972. <script class="attentions-json" type="application/json">' + JSON.stringify(obj.attentions) + '</script>\
  1973. ' + requeetHtml + '\
  1974. ' + ostatusHtml + '\
  1975. <div class="queet-content">\
  1976. <div class="stream-item-header">\
  1977. <a class="account-group" href="' + obj.user.statusnet_profile_url + '" data-user-id="' + obj.user.id + '">\
  1978. <img class="avatar profile-size" src="' + obj.user.profile_image_url_profile_size + '" data-user-id="' + obj.user.id + '" />\
  1979. <strong class="name" data-user-id="' + obj.user.id + '">' + obj.user.name + '</strong>\
  1980. <span class="silenced-flag" data-tooltip="' + window.sL.silencedStreamDescription + '">' + window.sL.silenced + '</span> \
  1981. <span class="sandboxed-flag" data-tooltip="' + window.sL.sandboxedStreamDescription + '">' + window.sL.sandboxed + '</span> \
  1982. <span class="screen-name" data-user-id="' + obj.user.id + '">@' + obj.user.screen_name + '</span>' +
  1983. '</a>' +
  1984. '<i class="addressees">' + reply_to_html + in_groups_html + '</i>' +
  1985. '<small class="created-at" data-created-at="' + obj.created_at + '">\
  1986. <a data-tooltip="' + parseTwitterLongDate(obj.created_at) + '" href="' + window.siteInstanceURL + 'notice/' + obj.id + '">' + queetTime + '</a>\
  1987. </small>\
  1988. </div>\
  1989. <div class="queet-text">' + $.trim(statusnetHTML) + '</div>\
  1990. ' + attachmentBuild.html + '\
  1991. <div class="stream-item-footer">\
  1992. ' + queetActions + '\
  1993. </div>\
  1994. </div>\
  1995. </div>\
  1996. </div>';
  1997. // detect rtl
  1998. queetHtml = detectRTL(queetHtml);
  1999. return queetHtml;
  2000. }
  2001. /* ·
  2002. ·
  2003. · Place or update quoted notices in the queet text
  2004. ·
  2005. · @param quotedNotices: object returned by buildAttachmentHTML()
  2006. · @param queetText: jQuery object for queet text
  2007. ·
  2008. · · · · · · · · · */
  2009. function placeQuotedNoticesInQueetText(quotedNotices,queetText) {
  2010. $.each(quotedNotices,function(k,qoutedNotice){
  2011. if(typeof qoutedNotice.url != 'undefined') {
  2012. var quoteLinkFound = queetText.find('a[href*="' + removeProtocolFromUrl(qoutedNotice.url) + '"]:not(.quote-link-container)');
  2013. // if we can't found it in a href, we might find it in data-quote-url attribute!
  2014. if(quoteLinkFound.length==0) {
  2015. quoteLinkFound = queetText.find('a[data-quote-url*="' + removeProtocolFromUrl(qoutedNotice.url) + '"]:not(.quote-link-container)');
  2016. }
  2017. if(quoteLinkFound.length>0) {
  2018. $.each(quoteLinkFound,function(){
  2019. // restore old style links (this can be removed later)
  2020. if($(this).children('.quoted-notice-header, .oembed-item-header').length>0) {
  2021. $(this).html($(this).attr('href'));
  2022. $(this).removeAttr('style');
  2023. $(this).removeClass('quoted-notice');
  2024. $(this).removeClass('oembed-item');
  2025. }
  2026. // place a container if we don't have it
  2027. if(!$(this).next().is('.quote-link-container')) {
  2028. $(this).after('<a class="quote-link-container"></a>');
  2029. }
  2030. // update the link and the (maybe newly added) quote container after the link
  2031. if($(this).next().is('.quote-link-container')) {
  2032. $(this).addClass('hidden-quote-link-in-queet-text');
  2033. $(this).attr('data-quote-url',qoutedNotice.url);
  2034. $(this).next().attr('data-quote-url',qoutedNotice.url);
  2035. $(this).next().addClass(qoutedNotice.class);
  2036. $(this).next().attr('href',qoutedNotice.href);
  2037. $(this).next().html(qoutedNotice.html);
  2038. // remove unnecessary line breaks, i.e. remove br between two quoted notices
  2039. if($(this).prev().is('br')) {
  2040. $(this).prev().remove();
  2041. }
  2042. if(!$(this).next().next().is('br')) {
  2043. $(this).next().after('<br>');
  2044. }
  2045. }
  2046. });
  2047. }
  2048. }
  2049. });
  2050. return queetText;
  2051. }
  2052. /* ·
  2053. ·
  2054. · Build HTML for the attachments to a queet
  2055. ·
  2056. · @param attachments: attachment object returned by the api
  2057. ·
  2058. · · · · · · · · · · · · · */
  2059. function buildAttachmentHTML(attachments){
  2060. var attachmentHTML = '';
  2061. var oembedHTML = '';
  2062. var quotedNotices = [];
  2063. var attachmentNum = 0;
  2064. var oembedNum = 0;
  2065. var urlsToHide = [];
  2066. if(typeof attachments != "undefined") {
  2067. $.each(attachments, function(){
  2068. // quoted notices
  2069. if(typeof this.quoted_notice != 'undefined') {
  2070. var quotedContent = this.quoted_notice.content;
  2071. // quoted notice's attachments' thumb urls
  2072. var quotedAttachmentsHTML = '';
  2073. var quotedAttachmentsHTMLbefore = '';
  2074. var quotedAttachmentsHTMLafter = '';
  2075. if(typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) {
  2076. quotedAttachmentsHTML += '<div class="quoted-notice-attachments quoted-notice-attachments-num-' + this.quoted_notice.attachments.length + '">'
  2077. $.each(this.quoted_notice.attachments,function(k,qAttach){
  2078. quotedAttachmentsHTML += '<div class="quoted-notice-img-container" style="background-image:url(\'' + qAttach.thumb_url + '\')"><img class="quoted-notice-img" src="' + qAttach.thumb_url + '" /></div>';
  2079. // remove attachment string from content
  2080. quotedContent = quotedContent.split(window.siteInstanceURL + 'attachment/' + qAttach.attachment_id).join('');
  2081. });
  2082. quotedAttachmentsHTML += '</div>';
  2083. // if there is only one attachment, it goes before, otherwise after
  2084. if(this.quoted_notice.attachments.length == 1) {
  2085. quotedAttachmentsHTMLbefore = quotedAttachmentsHTML;
  2086. }
  2087. else {
  2088. quotedAttachmentsHTMLafter = quotedAttachmentsHTML;
  2089. }
  2090. }
  2091. var quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\
  2092. <div class="quoted-notice-header">\
  2093. <span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\
  2094. <span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\
  2095. </div>\
  2096. <div class="quoted-notice-body">' + $.trim(quotedContent) + '</div>\
  2097. ' + quotedAttachmentsHTMLafter;
  2098. quotedNotices.push({
  2099. url: this.url,
  2100. html: quotedNoticeHTML,
  2101. href: window.siteInstanceURL + 'notice/' + this.quoted_notice.id,
  2102. class:'quoted-notice'
  2103. });
  2104. }
  2105. // if we have Twitter oembed data, we add is as quotes
  2106. else if(typeof this.oembed != 'undefined'
  2107. && this.oembed !== false
  2108. && this.oembed.provider == 'Twitter') {
  2109. var twitterHTML = '<div class="oembed-item-header">\
  2110. <span class="oembed-item-title">' + this.oembed.author_name + '</span>\
  2111. <span class="oembed-username">' + this.oembed.title + '</span>\
  2112. </div>\
  2113. <div class="oembed-item-body">' + this.oembed.oembedHTML + '</div>\
  2114. <div class="oembed-item-footer">\
  2115. <span class="oembed-item-provider">' + this.oembed.provider + '</span>\
  2116. </div>';
  2117. quotedNotices.push({
  2118. url: this.url,
  2119. html: twitterHTML,
  2120. href: this.url,
  2121. class:'oembed-item'
  2122. });
  2123. }
  2124. // if we have other oembed data (but not for photos and youtube, we handle those later)
  2125. else if(typeof this.oembed != 'undefined'
  2126. && this.oembed !== false
  2127. && this.oembed.title !== null
  2128. && this.oembed.provider != 'YouTube'
  2129. && this.oembed.provider != 'Vimeo'
  2130. && this.oembed.type != 'photo') {
  2131. var oembedImage = '';
  2132. // only local images
  2133. if(typeof this.thumb_url != 'undefined'
  2134. && this.thumb_url !== null
  2135. && isLocalURL(this.thumb_url)) {
  2136. oembedImage = '<div class="oembed-img-container" style="background-image:url(\'' + this.thumb_url + '\')"><img class="oembed-img" src="' + this.thumb_url + '" /></div>';
  2137. }
  2138. var oembedBody = '';
  2139. // don't add body if html it's too similar (80%) to the title (wordpress does this..)
  2140. if(this.oembed.oembedHTML !== null
  2141. && this.oembed.oembedHTML.length > 0) {
  2142. if(this.oembed.oembedHTML.length > 200) {
  2143. this.oembed.oembedHTML = this.oembed.oembedHTML.substring(0,200) + '…';
  2144. }
  2145. if(stringSimilarity(this.oembed.oembedHTML,this.oembed.title.substring(0,200)) < 80) {
  2146. oembedBody = this.oembed.oembedHTML;
  2147. }
  2148. }
  2149. if(this.oembed.provider === null) {
  2150. var oembedProvider = this.url;
  2151. var oembedProviderURL = '';
  2152. }
  2153. else {
  2154. var oembedProvider = this.oembed.provider;
  2155. var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url);
  2156. // remove trailing /
  2157. if(oembedProviderURL.slice(-1) == '/') {
  2158. oembedProviderURL = oembedProviderURL.slice(0,-1);
  2159. }
  2160. }
  2161. // If the oembed data is generated by Qvitter, we know a better way of showing the title
  2162. var oembedTitle = this.oembed.title;
  2163. var oembedTitleHTML = '<span class="oembed-item-title">' + oembedTitle + '</span>';
  2164. if(oembedTitle.slice(-10) == ' (Qvitter)') {
  2165. var oembedTimePosted = parseTwitterLongDate(oembedTitle.slice(0,-10));
  2166. var oembedGNUsocialUsername = this.oembed.author_name.substring(this.oembed.author_name.lastIndexOf('(')+1,this.oembed.author_name.lastIndexOf(')'));
  2167. var oembedGNUsocialFullname = this.oembed.author_name.slice(0,-(oembedGNUsocialUsername.length+3));
  2168. oembedTitleHTML = '<span class="oembed-item-title">' + oembedGNUsocialFullname + '</span>\
  2169. <span class="oembed-username">@' + oembedGNUsocialUsername + '</span>';
  2170. }
  2171. oembedHTML += '<a href="' + this.url + '" class="oembed-item">\
  2172. ' + oembedImage + '\
  2173. <div class="oembed-item-header">\
  2174. ' + oembedTitleHTML + '\
  2175. </div>\
  2176. <div class="oembed-item-body">' + oembedBody + '</div>\
  2177. <div class="oembed-item-footer">\
  2178. <span class="oembed-item-provider">' + oembedProvider + '</span>\
  2179. <span class="oembed-item-provider-url">' + oembedProviderURL + '</span>\
  2180. </div>\
  2181. </a>';
  2182. oembedNum++;
  2183. }
  2184. // if there's a local thumb_url we assume this is a image or video
  2185. else if(typeof this.thumb_url != 'undefined'
  2186. && this.thumb_url !== null
  2187. && isLocalURL(this.thumb_url)) {
  2188. var bigThumbW = 1000;
  2189. var bigThumbH = 3000;
  2190. if(bigThumbW > window.siteMaxThumbnailSize) {
  2191. bigThumbW = window.siteMaxThumbnailSize;
  2192. }
  2193. if(bigThumbH > window.siteMaxThumbnailSize) {
  2194. bigThumbH = window.siteMaxThumbnailSize;
  2195. }
  2196. // very long landscape images should not have background-size:cover
  2197. var noCoverClass='';
  2198. if(this.width/this.height > 2) {
  2199. noCoverClass=' no-cover';
  2200. }
  2201. // play button for videos and animated gifs
  2202. var playButtonClass = '';
  2203. if(typeof this.animated != 'undefined' && this.animated === true
  2204. || (this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1)
  2205. || this.url.indexOf('://vimeo.com') > -1) {
  2206. playButtonClass = ' play-button';
  2207. }
  2208. // gif-class
  2209. var animatedGifClass = '';
  2210. if(typeof this.animated != 'undefined' && this.animated === true) {
  2211. var animatedGifClass = ' animated-gif';
  2212. }
  2213. // animated gifs always get default small non-animated thumbnail
  2214. if(this.animated === true) {
  2215. var img_url = this.thumb_url;
  2216. }
  2217. // if no dimensions are set, go with default thumb
  2218. else if(this.width === null && this.height === null) {
  2219. var img_url = this.thumb_url;
  2220. }
  2221. // large images get large thumbnail
  2222. else if(this.width > 1000) {
  2223. var img_url = this.large_thumb_url;
  2224. }
  2225. // no thumbnails for small local images
  2226. else if (this.url.indexOf(window.siteInstanceURL) === 0) {
  2227. var img_url = this.url;
  2228. }
  2229. // small thumbnail for small remote images
  2230. else {
  2231. var img_url = this.thumb_url;
  2232. }
  2233. var urlToHide = window.siteInstanceURL + 'attachment/' + this.id;
  2234. attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + animatedGifClass + ' ' + CSSclassNameByHostFromURL(this.url) + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>';
  2235. urlsToHide.push(urlToHide); // hide this attachment url from the queet text
  2236. attachmentNum++;
  2237. }
  2238. else if (this.mimetype == 'image/svg+xml') {
  2239. var urlToHide = window.siteInstanceURL + 'attachment/' + this.id;
  2240. attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>';
  2241. urlsToHide.push(urlToHide); // hide this attachment url from the queet text
  2242. attachmentNum++;
  2243. }
  2244. });
  2245. }
  2246. return { html: '<div class="oembed-data oembed-num-' + oembedNum + '">' + oembedHTML + '</div><div class="queet-thumbs thumb-num-' + attachmentNum + '">' + attachmentHTML + '</div>',
  2247. urlsToHide: urlsToHide,
  2248. quotedNotices: quotedNotices
  2249. };
  2250. }