MDL-36305 theme: Forum reply button is not removed using MyMobile
[moodle.git] / theme / mymobile / javascript / custom.js
CommitLineData
2fd7abbb 1$(document).bind("mobileinit", function(){
2//mobile init stuff 11/12/10
3//turn off ajax forms...
256c51fa 4$.mobile.defaultPageTransition = "slide";
2fd7abbb 5});
6
3c0c2bf0 7$(document).ready(function() {
2fd7abbb 8 //get some vars to start
9 var siteurl = $('.mobilesiteurl').attr("id");
10 var mytheme = $(".datatheme").attr("id");
11 var mythemeb = $(".datathemeb").attr("id");
3c0c2bf0
SH
12
13
2fd7abbb 14 //function below does generic stuff before creating all pages...
3c0c2bf0
SH
15 $('div').live('pagebeforecreate', function(event, ui) {
16 //turn off ajax on all forms for now as of beta1
17 $('form').attr("data-ajax", "false");
18 //lesson
19 $('.lessonbutton.standardbutton a').attr("data-role", "button");
20 $('#page-mod-lesson-viewPAGE div.fitemtitle label').addClass("afirst");
21
22 //tablet column removal switch
23 $('.slider').live("change",function() {
24 var slids = $(this).val();
25 M.util.set_user_preference('theme_mymobile_chosen_colpos', slids);
26 if (slids == "off") {
27 $('.ui-page-active').removeClass("has-myblocks");
28 } else {
29 $('.ui-page-active').addClass("has-myblocks");
30 }
31 });
32
33 //tabs- links set to external to fix forms
34 $('div.tabtree ul.tabrow0').attr("data-role", "controlgroup");
35 $('div.tabtree ul.tabrow12').attr("data-role", "controlgroup");
36 $('div.tabtree li a').attr("data-role", "button").attr("data-ajax", "false");
37
38 //jump to current or bottom
39 $('a.jumptocurrent').live('tap', function() {
40 var position = $(".ui-page-active .section.current").position();
41 if (!position) {
42 var position = $(".ui-page-active .mobilefooter").position();
43 }
44 $.mobile.silentScroll(position.top);
45 $(this).removeClass("ui-btn-active");
46 return false;
47 });
48
49 //scroll to top
50 $('a#uptotop').live('tap', function() {
256c51fa 51 var position = $(".ui-page-active").position();
3c0c2bf0
SH
52 $.mobile.silentScroll(position.top);
53 $(this).removeClass("ui-btn-active");
54 return false;
55 });
56
57 //remove message notifcation overlay on tap 6/21/11
58 $('a#notificationno').live('tap', function() {
59 $('#newmessageoverlay').remove();
60 return false;
61 });
62
63 //calendar and other links that need to be external
256c51fa 64 $('.maincalendar .filters a, li.activity.scorm a, div.files a, #page-user-filesPAGE li div a, .maincalendar .bottom a, .section li.url.modtype_url a, .resourcecontent .resourcemediaplugin a, #underfooter .noajax a, .block_mnet_hosts .content a, .block_private_files .content a, a.portfolio-add-link, #attempts td a').attr("data-ajax", "false");
3c0c2bf0
SH
65
66 //add blank to open in window for some
67 $('#page-mod-url-viewPAGE div.urlworkaround a, #page-mod-resource-viewPAGE div.resourceworkaround a, .mediaplugin a.mediafallbacklink, #page-mod-resource-viewPAGE .resourcemp3 a, .foldertree li a').attr("target", "_blank").attr("data-role", "button").attr("data-icon", "plus");
68
69 //// **** general stuff *** ////
70 $('form fieldset').attr("data-role", "fieldcontain");
71 $('form .fitem').attr("data-role", "fieldcontain");
72
73 //submit button for forum
74 $('#page-mod-url-viewPAGE div.urlworkaround a').attr("data-role", "button");
75
76 //survey form fix
77 $('#surveyform').attr("action", siteurl + '/mod/survey/save.php');
78
79 //nav select navigtation NEW
80 $("#navselect").live("change",function() {
81 var meb = encodeURI($(this).val());
82 $(this).val("-1");
83 if (meb != "" && meb != "-1") {
84 $.mobile.changePage(meb);
85 }
86 });
2fd7abbb 87
2fd7abbb 88 });
2fd7abbb 89
2fd7abbb 90
3c0c2bf0
SH
91 //course page only js
92 $('div.path-course-view, .path-course-view div.generalpage').live('pagebeforecreate', function(event, ui) {
93 //course listing
94 $('.section li img').addClass("ui-li-icon");
95 $('.course-content ul.section').attr("data-role", "listview").attr("data-inset", "true").attr("data-theme", mythemeb);
96 $('.sitetopic ul.section').attr("data-role", "listview").attr("data-inset", "true").attr("data-theme", mythemeb);
97 $('.topics div.left.side').addClass("ui-bar-" + mytheme);
98 $('.section.hidden div.headingwrap').attr("data-theme", mythemeb);
99 //$('.topics #section-0 div.left.side').removeClass("ui-li ui-li-divider ui-btn ui-bar-a");
100 $('.section .resource.modtype_resource a, .section .modtype_survey a').attr("data-ajax", "false");
2fd7abbb 101
3c0c2bf0
SH
102 //toggle completion checkmarks and form fixes
103 $('.togglecompletion input[type="image"]').attr("data-role", "none");
104 $('.togglecompletion input[type="image"]').click(function() {
105 $(".section .togglecompletion").attr("action", '');
106 var mylocc = siteurl + "/course/togglecompletion.php";
107 $(".section .togglecompletion").attr("action", mylocc);
108 this.form.submit();
109 return false;
110 });
111 });
2fd7abbb 112
3c0c2bf0
SH
113 //forum listing only stuff
114 $('div#page-mod-forum-viewPAGE, #page-mod-forum-view div.generalpage').live('pagebeforecreate',function(event, ui){
115 //forums listing change theme for other theme
116 $('table.forumheaderlist').attr("data-role", "controlgroup");
117 $('table.forumheaderlist thead tr').attr("data-role", "button").attr("data-theme", mythemeb);
118 $('table.forumheaderlist td.topic a').attr("data-role", "button").attr("data-icon", "arrow-r").attr("data-iconpos", "right").attr("data-theme", mythemeb);
119 });
2fd7abbb 120
3c0c2bf0
SH
121 $('div#page-mod-forum-viewPAGE').live('pageinit',function(event, ui){
122 $('.forumheaderlist td.topic').each(function(index) {
123 var ggg = $(this).nextAll("td.replies").text();
124 $(this).find('a').append('<span class="ui-li-count ui-btn-up-a ui-btn-corner-all"> ' + ggg + '</span>');
125 });
126 });
2fd7abbb 127
3c0c2bf0
SH
128 //forum discussion page only stuff
129 $('div#page-mod-forum-discussPAGE, #page-mod-forum-discuss div.generalpage, div.forumtype-single, .forumtype-single div.generalpage, div#page-mod-forum-postPAGE').live('pagebeforecreate',function(event, ui){
f54b485a 130 // Handle the '#' in the URLs.
3c0c2bf0
SH
131 $('.options div.commands a').each(function(index) {
132 var url = $(this).attr("href");
f54b485a
FM
133 if (url.indexOf("post.php") != -1 && url.indexOf("reply=") != -1) {
134 // Remove the anchor from the reply link.
135 $(this).attr('href', url.replace('#mform1', ''));
136 } else if (url.indexOf("#") != -1) {
137 // Remove "Show parent" and other links which contains a '#'.
3c0c2bf0
SH
138 $(this).remove();
139 }
140 });
2fd7abbb 141
3c0c2bf0
SH
142 //actual forum posting
143 $('.forumpost div.row.header').addClass("ui-li ui-li-divider ui-btn ui-bar-" + mytheme);
144 $('.options div.commands').attr("data-role", "controlgroup").attr("data-type", "horizontal");
145 $('.options div.commands a').attr("data-role", "button").attr("data-ajax", "false").attr("data-inline", "true");
146 $('.forumpost div.author a').attr("data-inline", "true");
147 $('.options div.commands').contents().filter(function() {
148 return this.nodeType == 3; //Node.TEXT_NODE
149 }).remove();
150 //function above removes | in div.commands
151 });
2fd7abbb 152
3c0c2bf0
SH
153 //frontpage only stuff
154 $('div#page-site-indexPAGE, div.pagelayout-coursecategory').live('pagebeforecreate',function(event, ui){
155 //course boxes on category pages and front page stuff
156 //forum posts on front page only
157 $('.forumpost div.row.header').addClass("ui-li ui-li-divider ui-btn ui-bar-" + mytheme);
158 $('div.subscribelink a').attr("data-role", "button").attr("data-inline", "true");
159 $('.unlist').attr("data-role", "controlgroup");
160 $('div.coursebox a').attr("data-role", "button").attr("data-icon", "arrow-r").attr("data-iconpos", "right").attr("data-theme", mythemeb);
161 $('.box.categorybox').attr("data-role", "controlgroup");
162 $('div.categorylist div.category a').attr("data-role", "button").attr("data-theme", mythemeb);
163 $('#shortsearchbox, #coursesearch2 #shortsearchbox').attr("data-type", "search");
2fd7abbb 164 });
2fd7abbb 165
3c0c2bf0
SH
166 $('div#page-site-indexPAGE').live('pageinit',function(event, ui){
167 $('div.categorylist div.category').each(function(index) {
168 var ggb = $(this).find("span.numberofcourse").text().replace('(','').replace(')','');
169 if (ggb != "") {
170 $(this).find('a').append('<span class="ui-li-count ui-btn-up-a ui-btn-corner-all">' + ggb + '</span>');
171 }
172 });
173 });
2fd7abbb 174
3c0c2bf0
SH
175 //chat only stuff
176 $('div#chatpage, div.path-mod-chat').live('pagebeforecreate',function(event, ui){
177 $('#input-message, #button-send').attr("data-role", "none");
178 $('#enterlink a').attr("data-role", "button").attr("data-ajax", "false").attr("data-icon", "plus");
179 $('form, input, button').attr("data-ajax", "false");
180 });
2fd7abbb 181
3c0c2bf0
SH
182 //login page only stuff
183 $('div#page-login-indexPAGE').live('pagebeforecreate',function(event, ui){
184 //signup form fix
185 $('.path-login .signupform #signup').attr("action", siteurl + '/login/signup.php');
186 $('.path-login #guestlogin').attr("action", siteurl + '/login/index.php');
187 });
2fd7abbb 188
3c0c2bf0
SH
189 //messaging only stuff
190 $('div#page-message-indexPAGE').live('pagebeforecreate',function(event, ui){
191 //below to fix form actions here and there
192 $("#usergroupform").attr("action", '');
193 //if (userform == "") {
194 var myloc = siteurl + "/message/index.php";
195 $("#usergroupform").attr("action", myloc);
196 //messaging links
197 $('.path-message td.link').attr("data-role", "controlgroup").attr("data-type", "horizontal");
198 $('.path-message td.link a').attr("data-role", "button").attr("data-inline", "true");
2fd7abbb 199 });
2fd7abbb 200
3c0c2bf0
SH
201 //database and glossary only stuff
202 $('div#page-mod-data-viewPAGE, div#page-mod-glossary-viewPAGE').live('pagebeforecreate',function(event, ui){
203 $('.defaulttemplate td a').attr("data-role", "button").attr("data-ajax", "false").attr("data-inline", "true");
204 $('#options select, .aliases select').attr("data-native-menu", "true");
205 $('#pref_search, .glossarysearchbox input[type="text"]').attr("data-type", "search");
206 $('#options').attr("action", siteurl + '/mod/data/view.php');
207 $('#page-mod-glossary-viewPAGE form').each(function(index) {
208 var glossform = $(this).attr("action");
209 if (glossform == "view.php") {
210 $(this).attr("action", siteurl + '/mod/glossary/view.php');
211 }
212 });
2fd7abbb 213 });
3c0c2bf0
SH
214
215 //mymoodle only stuff
216 $('div#page-my-indexPAGE').live('pagebeforecreate',function(event, ui){
217 //my moodle page fixes
218 //block_course_overview
219 $('.block_course_overview div.headingwrap').attr("data-role", "none");
220 $('.block_course_overview h3.main a').attr("data-theme", mytheme);
2fd7abbb 221 });
222
3c0c2bf0
SH
223 //resource only stuff to help embedded PDFs, provides link to open in new window
224 $('div#page-mod-resource-viewPAGE').live('pagebeforecreate',function(event, ui){
225 $('div.resourcepdf').each(function(index) {
226 var thisopen = $(this).find('#resourceobject').attr("data");
227 $(this).append('<a class="mobileresource" href="' +thisopen+ '" target="_blank"></a>');
228 });
229 });
2fd7abbb 230
3c0c2bf0 231 //quiz page only js
256c51fa 232 $('div#page-mod-quiz-viewPAGE, div#page-mod-quiz-attemptPAGE, div#page-mod-quiz-summaryPAGE, div#page-mod-quiz-reviewPAGE, #page-mod-quiz-attempt #content2').live('pagebeforecreate',function(event, ui){
3c0c2bf0
SH
233 //add quiz timer into quiz page
234 $('#quiz-timer').remove();
235 $('.mymobilecontent').prepend('<div id="quiz-timer" > <span id="quiz-time-left"></span></div>');
236 $('.que .info').addClass("ui-bar-" + mytheme);
237 $('.que input.submit').attr("data-role", "none");
238 $('div.submitbtns a, div.quizattemptcounts a').attr("data-role", "button").attr("data-ajax", "false");
239 $('#page-mod-quiz-attemptPAGE .questionflag input, .path-mod-quiz .questionflag input').attr("data-role", "none");
240 });
2fd7abbb 241
3c0c2bf0
SH
242 //assignment page only stuff
243 $('#page-mod-assignment-viewPAGE').live('pagebeforecreate',function(event, ui){
244 //below fixes the advanced upload edit notes button
245 $('#page-mod-assignment-viewPAGE div[rel="upload.php"]').parent().attr("action", siteurl + '/mod/assignment/upload.php');
246 });
2fd7abbb 247
3c0c2bf0
SH
248 //hotpot page only stuff
249 $('div.path-mod-hotpot').live('pagebeforecreate',function(event, ui){
250 $('.path-mod-hotpot button').attr("data-role", "none");
251 });
2fd7abbb 252
3c0c2bf0
SH
253 //collapsed topic only stuff
254 $('div#page-course-view-topcollPAGE').live('pagebeforecreate',function(event, ui){
255 $('#page-course-view-topcollPAGE ul.section').attr("data-role", "none");
256 $('.section li img').removeClass("ui-li-icon");
256c51fa 257 $.getScript('../course/format/topcoll/module.js');
3c0c2bf0
SH
258 $('#page-course-view-topcollPAGE tr.cps a').attr("data-role", "button").attr("data-icon", "arrow-r");
259 $('#page-course-view-topcollPAGE #thetopics').attr("data-role", "controlgroup");
260 $('#page-course-view-topcollPAGE td.cps_centre').each(function(index) {
261 var cpsc = $(this).text().replace('<br>','').replace(')','');
262 $(this).prev('td').find('a').append('<span class="ui-li-count ui-btn-up-a ui-btn-corner-all">' + cpsc + '</span>');
263 });
3c0c2bf0 264 });
2fd7abbb 265
3c0c2bf0
SH
266 ///// functions below does stuff after creating page for some cleaning...
267 $('div').live('pageinit',function(event, ui){
268 $('.path-calendar div.ui-radio label:first-child, .path-mod-lesson div.ui-radio label:first-child, #page-mod-wiki-createPAGE div.ui-radio label:first-child').addClass("afirst");
269 $('.forumpost div.author a').removeAttr('data-role');
270 //$('.questionflagimage2').removeClass("ui-btn-hidden");a#notificationyes
3c0c2bf0
SH
271 //image replacement
272 $(this).find(".ithumb .course-content .summary img, .ithumb .course-content .activity.label img, .ithumb .sitetopic .no-overflow img").click(function() {
273 var turl = $(this).attr("src");
274 window.open(turl);
275 });
276 });
277});