2 * @brief contains functions for bootstrap modal handling
4 $(document).ready(function(){
5 // Clear bs modal on close
6 // We need this to prevent that the modal displays old content
7 $('body, footer').on('hidden.bs.modal', '.modal', function () {
8 $(this).removeData('bs.modal');
9 $("#modal-title").empty();
10 $('#modal-body').empty();
11 // remove the file browser from jot (else we would have problems
13 $(".fbrowser").remove();
16 // Clear bs modal on close
17 // We need this to prevent that the modal displays old content
18 $('body').on('hidden.bs.modal', '#jot-modal', function () {
19 // restore cached jot at its hidden position ("#jot-content")
20 $("#jot-content").append(jotcache);
25 // Add Colorbox for viewing Network page images
26 //var cBoxClasses = new Array();
27 $("body").on("click", ".wall-item-body a img", function(){
28 var aElem = $(this).parent();
29 var imgHref = aElem.attr("href");
31 // We need to make sure we only put a Colorbox on links to Friendica images
32 // We'll try to do this by looking for links of the form
33 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
34 // that that will be unique enough
35 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
37 // Add a unique class to all the images of a certain post, to allow scrolling through
38 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
39 $(this).addClass(cBoxClass);
41 // if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
42 // cBoxClasses.push(cBoxClass);
47 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
48 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
54 $("body").on("click", "#nav-login", function(e){
56 Dialog.show(this.href, this.dataset.originalTitle || this.title);
60 $("body").on("click", "#jot-modal .jot-nav li a", function(e){
65 // bookmarklet page needs an jot modal which appears automatically
66 if(window.location.pathname.indexOf("/bookmarklet") >=0 && $("#jot-modal").length){
70 // Open filebrowser for elements with the class "image-select"
71 // The following part handles the filebrowser for field_fileinput.tpl
72 $("body").on("click", ".image-select", function(){
73 // set a extra attribute to mark the clicked button
74 this.setAttribute("image-input", "select");
75 Dialog.doImageBrowser("input");
78 // Insert filebrowser images into the input field (field_fileinput.tpl)
79 $("body").on("fbrowser.image.input", function(e, filename, embedcode, id, img) {
80 // select the clicked button by it's attribute
81 var elm = $("[image-input='select']");
82 // select the input field which belongs to this button
83 var input = elm.parent(".input-group").children("input");
84 // remove the special indicator attribut from the button
85 elm.removeAttr("image-input");
86 // inserte the link from the image into the input field
92 // overwrite Dialog.show from main js to load the filebrowser into a bs modal
93 Dialog.show = function(url, title="") {
94 var modal = $('#modal').modal();
95 modal.find("#modal-header h4").html(title);
98 .load(url, function (responseText, textStatus) {
99 if ( textStatus === 'success' ||
100 textStatus === 'notmodified')
104 $(function() {Dialog._load(url);});
109 // overwrite the function _get_url from main.js
110 Dialog._get_url = function(type, name, id) {
112 if (id !== undefined) hash = hash + "-" + id;
113 return "fbrowser/"+type+"/?mode=none#"+hash;
116 // does load the filebrowser into the jot modal
117 Dialog.showJot = function() {
121 var url = Dialog._get_url(type, name);
122 if(($(".modal-body #jot-fbrowser-wrapper .fbrowser").length) < 1 ) {
123 // load new content to fbrowser window
124 $("#jot-fbrowser-wrapper").load(url,function(responseText, textStatus){
125 if ( textStatus === 'success' ||
126 textStatus === 'notmodified')
128 $(function() {Dialog._load(url);});
134 // init the filebrowser after page load
135 Dialog._load = function(url) {
136 // get nickname & filebrowser type from the modal content
137 var nickname = $("#fb-nickname").attr("value");
138 var type = $("#fb-type").attr("value");
140 // try to fetch the hash form the url
141 var match = url.match(/fbrowser\/[a-z]+\/\?mode=none(.*)/);
142 if (match===null) return; //not fbrowser
145 // initialize the filebrowser
146 var jsbrowser = function() {
147 FileBrowser.init(nickname, type, hash);
149 loadScript("view/theme/frio/js/filebrowser.js", jsbrowser);
153 * @brief Add first element with the class "heading" as modal title
155 * Note: this should be really done in the template
156 * and is the solution where we havent done it until this
157 * moment or where it isn't possible because of design
159 function loadModalTitle() {
160 // clear the text of the title
161 //$("#modal-title").empty();
163 // hide the first element with the class "heading" of the modal body
164 $("#modal-body .heading").first().hide();
166 // get the text of the first element with "heading" class
167 var title = $("#modal-body .heading").first().text();
169 // and append it to modal title
171 $("#modal-title").append(title);
175 // This function loads html content from a friendica page
177 function addToModal(url) {
178 var char = qOrAmp(url);
180 url = url + char + 'mode=none';
181 var modal = $('#modal').modal();
185 .load(url, function (responseText, textStatus) {
186 if ( textStatus === 'success' ||
187 textStatus === 'notmodified')
191 //Get first element with the class "heading"
192 //and use it as title
198 // function to load the html from the edit post page into
200 function editpost(url) {
201 // next to normel posts the post can be an event post. The event posts don't
202 // use the normal Jot modal. For event posts we will use a normal modal
203 // But first we have to test if the url links to an event. So we will split up
204 // the url in its parts
205 var splitURL = parseUrl(url);
206 // Test if in the url path containing "events/event". If the path containing this
207 // expression then we will call the addToModal function and exit this function at
209 if (splitURL.path.indexOf('events/event') > -1) {
210 addToModal(splitURL.path);
214 var modal = $('#jot-modal').modal();
215 url = url + " #profile-jot-form";
217 //var rand_num = random_digits(12);
218 $(".jot-nav #jot-perms-lnk").parent("li").hide();
220 // For editpost we load the modal html form the edit page. So we would have two jot forms in
221 // the page html. To avoid js conflicts we store the original jot in the variable jotcache.
222 // After closing the modal original jot should be restored at its orginal position in the html structure.
223 jotcache = $("#jot-content > #profile-jot-form");
225 // remove the original Jot as long as the edit Jot is open
228 // add the class "edit" to the modal to have some kind of identifier to
229 // have the possibility to e.g. put special event-listener
230 $("#jot-modal").addClass("edit-jot");
235 .find('#jot-modal-body')
236 .load(url, function (responseText, textStatus) {
237 if ( textStatus === 'success' ||
238 textStatus === 'notmodified')
240 // get the item type and hide the input for title and category if it isn't needed
241 var type = $(responseText).find("#profile-jot-form input[name='type']").val();
242 if(type === "wall-comment" || type === "remote-comment")
244 // hide title and category input fields because we don't
245 $("#profile-jot-form #jot-title-wrap").hide();
246 $("#profile-jot-form #jot-category-wrap").hide();
250 $("#jot-popup").show();
255 // remove content from the jot modal
256 function jotreset() {
257 // Clear bs modal on close
258 // We need this to prevent that the modal displays old content
259 $('body').on('hidden.bs.modal', '#jot-modal.edit-jot', function () {
260 $(this).removeData('bs.modal');
261 $(".jot-nav #jot-perms-lnk").parent("li").show();
262 $("#profile-jot-form #jot-title-wrap").show();
263 $("#profile-jot-form #jot-category-wrap").show();
265 // the following was commented out because it is needed anymore
266 // because we changed the behavior at an other place
267 // var rand_num = random_digits(12);
268 // $('#jot-title, #jot-category, #profile-jot-text').val("");
269 // $( "#profile-jot-form input[name='type']" ).val("wall");
270 // $( "#profile-jot-form input[name='post_id']" ).val("");
271 // $( "#profile-jot-form input[name='post_id_random']" ).val(rand_num);
273 // remove the "edit-jot" class so we can the standard behavior on close
274 $("#jot-modal.edit-jot").removeClass("edit-jot");
275 $("#jot-modal-body").empty();
279 // Give the active "jot-nav" list element the class "active"
280 function toggleJotNav (elm) {
281 // select all li of jot-nav and remove the active class
282 $(elm).closest(".jot-nav").children("li").removeClass("active");
283 // add the active class to the parent of the link which was selected
284 $(elm).parent("li").addClass("active");