1 $(document).ready(function(){
2 //fade in/out based on scrollTop value
3 $(window).scroll(function () {
4 if ($(this).scrollTop() > 1000) {
5 $("#back-to-top").fadeIn();
7 $("#back-to-top").fadeOut();
11 // scroll body to 0px on click
12 $("#back-to-top").click(function () {
13 $("body,html").animate({
19 // Clear bs modal on close
20 // We need this to prevent that the modal displays old content
21 $('body').on('hidden.bs.modal', '.modal', function () {
22 $(this).removeData('bs.modal');
23 $("#modal-title").empty();
24 $('#modal-body').empty();
27 // add the class "selected" to group widges li if li > a does have the class group-selected
28 if( $("#sidebar-group-ul li a").hasClass("group-selected")) {
29 $("#sidebar-group-ul li a.group-selected").parent("li").addClass("selected");
32 // add the class "selected" to forums widges li if li > a does have the class forum-selected
33 if( $("#forumlist-sidbar-ul li a").hasClass("forum-selected")) {
34 $("#forumlist-sidbar-ul li a.forum-selected").parent("li").addClass("selected");
37 // add the class "active" to tabmenuli if li > a does have the class active
38 if( $("#tabmenu ul li a").hasClass("active")) {
39 $("#tabmenu ul li a.active").parent("li").addClass("active");
42 // give select fields an boostrap classes
43 $(".field.select, .field.custom").addClass("form-group");
44 $(".field.select > select, .field.custom > select").addClass("form-control");
47 $("ul.tabs").appendTo("#topbar-second > .container > #tabmenu");
50 // add Jot botton to the scecond navbar
51 if( $("section #jotOpen")) {
52 $("section #jotOpen").appendTo("#topbar-second > .container > #navbar-button");
53 if( $("#jot-popup").is(":hidden")) $("#topbar-second > .container > #navbar-button #jotOpen").hide();
56 // Loading remote bootstrap remote modals
57 // This is uses to load tradional friendica pages into bootstrap modals
59 $('a[rel=modal]').on('click', function(evt) {
61 var modal = $('#modal').modal();
64 .load($(this).attr("href"), function (responseText, textStatus) {
65 if ( textStatus === 'success' ||
66 textStatus === 'notmodified')
70 //Get first h3 element and use it as title
76 // Add Colorbox for viewing Network page images
77 //var cBoxClasses = new Array();
78 $(".wall-item-body a img").each(function(){
79 var aElem = $(this).parent();
80 var imgHref = aElem.attr("href");
82 // We need to make sure we only put a Colorbox on links to Friendica images
83 // We'll try to do this by looking for links of the form
84 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
85 // that that will be unique enough
86 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
88 // Add a unique class to all the images of a certain post, to allow scrolling through
89 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
90 $(this).addClass(cBoxClass);
92 // if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
93 // cBoxClasses.push(cBoxClass);
98 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
99 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
104 // overwrite Dialog.show from main js to load the filebrowser into a bs modal
105 Dialog.show = function(url) {
106 var modal = $('#modal').modal();
109 .load(url, function (responseText, textStatus) {
110 if ( textStatus === 'success' ||
111 textStatus === 'notmodified')
115 // get nickname & filebrowser type from the modal content
116 var nickname = $("#fb-nickname").attr("value");
117 var type = $("#fb-type").attr("value");
119 // try to fetch the hash form the url
120 var match = url.match(/fbrowser\/[a-z]+\/\?mode=modal(.*)/);
123 // initialize the filebrowser
124 var jsbrowser = function() {
125 FileBrowser.init(nickname, type, hash);
127 loadScript("view/theme/frio/js/filebrowser.js", jsbrowser);
132 // overwrite the function _get_url from main.js
133 Dialog._get_url = function(type, name, id) {
135 if (id !== undefined) hash = hash + "-" + id;
136 return "fbrowser/"+type+"/?mode=modal#"+hash;
143 //function commentOpenUI(obj, id) {
144 // $(document).unbind( "click.commentOpen", handler );
146 // var handler = function() {
147 // if(obj.value == '{{$comment}}') {
149 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
150 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
151 // // The submit button gets tabindex + 1
152 // $("#comment-edit-text-" + id).attr('tabindex','9');
153 // $("#comment-edit-submit-" + id).attr('tabindex','10');
154 // $("#comment-edit-submit-wrapper-" + id).show();
158 // $(document).bind( "click.commentOpen", handler );
161 //function commentCloseUI(obj, id) {
162 // $(document).unbind( "click.commentClose", handler );
164 // var handler = function() {
165 // if(obj.value === '') {
166 // obj.value = '{{$comment}}';
167 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
168 // $("#comment-edit-text-" + id).removeAttr('tabindex');
169 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
170 // $("#comment-edit-submit-wrapper-" + id).hide();
174 // $(document).bind( "click.commentClose", handler );
177 function openClose(theID) {
178 var elem = document.getElementById(theID);
180 if( $(elem).is(':visible')) {
181 $(elem).slideUp(200);
184 $(elem).slideDown(200);
188 function showHide(theID) {
189 if(document.getElementById(theID).style.display == "block") {
190 document.getElementById(theID).style.display = "none"
193 document.getElementById(theID).style.display = "block"
198 function showHideComments(id) {
199 if( $('#collapsed-comments-' + id).is(':visible')) {
200 $('#collapsed-comments-' + id).slideUp();
201 $('#hide-comments-' + id).html(window.showMore);
202 $('#hide-comments-total-' + id).show();
205 $('#collapsed-comments-' + id).slideDown();
206 $('#hide-comments-' + id).html(window.showFewer);
207 $('#hide-comments-total-' + id).hide();
212 function justifyPhotos() {
213 justifiedGalleryActive = true;
214 $('#photo-album-contents').justifiedGallery({
225 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
228 function justifyPhotosAjax() {
229 justifiedGalleryActive = true;
230 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
233 function loadScript(url, callback) {
234 // Adding the script tag to the head as suggested before
235 var head = document.getElementsByTagName('head')[0];
236 var script = document.createElement('script');
237 script.type = 'text/javascript';
240 // Then bind the event to the callback function.
241 // There are several events for cross browser compatibility.
242 script.onreadystatechange = callback;
243 script.onload = callback;
246 head.appendChild(script);
250 * @brief Add first h3 element as modal title
252 * Note: this should be really done in the template
253 * and is the solution where we havent done it until this
254 * moment or where it isn't possible because of design
256 function loadModalTitle() {
257 // clear the text of the title
258 //$("#modal-title").empty();
260 // hide the first h3 child element of the modal body
261 $("#modal-body > h3").first().hide();
263 // get the text of the first h3 child element
264 var title = $("#modal-body > h3").first().text();
266 // and append it to modal title
268 $("#modal-title").append(title);
272 function editpost(url) {
273 var modal = $('#jot-modal').modal();
274 var url = url + " #profile-jot-form";
275 //var rand_num = random_digits(12);
276 $("#jot-perms-lnk").hide();
278 // rename the the original div jot-preview-content because the edit function
279 // does load the content for the modal from another source and preview won't work
280 // if this div would exist twice
281 // $("#jot-content #profile-jot-form").attr("id","#profile-jot-form-renamed");
282 // $("#jot-content #jot-preview-content").attr("id","#jot-preview-content-renamed");
284 // For editpost we load the modal html form the edit page. So we would have two jot forms in
285 // the page html. To avoid js conflicts we move the original jot to the end of the page
286 // so the editpost jot would be the first jot in html structure.
287 // After closing the modal we move the original jot back to it's orginal position in the html structure.
289 // Note: For now it seems to work but this isn't optimal because we have doubled ID names for the jot div's.
290 // We need to have a better solution for this in the future.
291 $("section #jot-content #profile-jot-form").appendTo("footer #cache-container");
296 .find('#jot-modal-body')
297 .load(url, function (responseText, textStatus) {
298 if ( textStatus === 'success' ||
299 textStatus === 'notmodified')
301 // get the item type and hide the input for title and category if it isn't needed
302 var type = $(responseText).find("#profile-jot-form input[name='type']").val();
303 if(type === "wall-comment" || type === "remote-comment")
305 $("#profile-jot-form #jot-title-wrap").hide();
306 $("#profile-jot-form #jot-category-wrap").hide();
310 $("#jot-popup").show();
315 function jotreset() {
316 // Clear bs modal on close
317 // We need this to prevent that the modal displays old content
318 $('body').on('hidden.bs.modal', '#jot-modal', function () {
319 $(this).removeData('bs.modal');
320 $("#jot-perms-lnk").show();
321 $("#profile-jot-form #jot-title-wrap").show();
322 $("#profile-jot-form #jot-category-wrap").show();
324 // the following was commented out because it is needed anymore
325 // because we changed the behavior at an other place
326 // var rand_num = random_digits(12);
327 // $('#jot-title, #jot-category, #profile-jot-text').val("");
328 // $( "#profile-jot-form input[name='type']" ).val("wall");
329 // $( "#profile-jot-form input[name='post_id']" ).val("");
330 // $( "#profile-jot-form input[name='post_id_random']" ).val(rand_num);
331 $("#jot-modal-body").empty();
333 // rename the div #jot-preview-content-renamed back to it's original
334 // name. Have a look at function editpost() for further explanation
335 //$("#jot-content #profile-jot-form-renamed").attr("id","#profile-jot-form");
336 //$("#jot-content #jot-preview-content-renamed").attr("id","#jot-preview-content");
338 // Move the original jot back to it's old place in the html structure
339 // For explaination have a look at function editpost()
340 $("footer #cache-container #profile-jot-form").appendTo("section #jot-content");
344 function random_digits(digits) {
348 for(var i = 0; i < digits; i++) {
349 var rn = Math.round(Math.random() * (9));