1/*! 2 * DokuWiki Bootstrap Wrapper Plugin 3 * 4 * Home http://dokuwiki.org/plugin:bootswrapper 5 * Author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 6 * License GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 */ 8 9jQuery(document).ready(function () { 10 11 jQuery('.bs-wrap .fix-media-list-overlap').removeClass('fix-media-list-overlap'); 12 13 // Jumbotron 14 jQuery('.bs-wrap-jumbotron .page-header').removeClass('page-header'); 15 16 // Tooltips 17 jQuery('.bs-wrap-tooltip').tooltip(); 18 19 // Popovers 20 jQuery('.bs-wrap-popover').popover(); 21 22 // Images 23 jQuery('.bs-wrap-image').each(function () { 24 25 var $img_wrap = jQuery(this), 26 img_data = $img_wrap.data(); 27 28 $img_wrap.find('img').addClass(['img-', img_data.imgShape].join('')); 29 30 }); 31 32 33 // Nav 34 jQuery('.bs-wrap-nav').each(function () { 35 36 var $nav_wrap = jQuery(this), 37 nav_data = $nav_wrap.data(), 38 nav_class = ['nav']; 39 40 for (var key in nav_data) { 41 42 var value = nav_data[key]; 43 44 switch (key) { 45 case 'navType': 46 nav_class.push(['nav-', value].join('')); 47 break; 48 case 'navStacked': 49 if (value) nav_class.push('nav-stacked'); 50 break; 51 case 'navJustified': 52 if (value) nav_class.push('nav-justified'); 53 break; 54 } 55 56 } 57 58 $nav_wrap.find('ul:first').addClass(nav_class.join(' ')); 59 60 var $nav = $nav_wrap.find('.nav'); 61 62 $nav.find('div.li > *').unwrap(); 63 $nav.find('li').attr('role', 'presentation'); 64 $nav.find('.curid').parent('li').addClass('active'); 65 $nav.find('.curid').contents().unwrap(); // Unwrap for Hogfater release 66 67 // Drop-down menu 68 $nav.find('li ul') 69 .addClass('dropdown-menu') 70 .parent('li') 71 .addClass('dropdown'); 72 73 $nav.find('.dropdown div.li').replaceWith(function () { 74 return jQuery('<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" />') 75 .html(jQuery(this).contents()) 76 }); 77 78 // Sidebar (Bootstrap3 template) 79 $nav.find('li.dropdown').contents().filter(function () { 80 return this.nodeType === 3 && this.data.trim().length > 0 81 }).wrap('<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" />'); 82 83 $nav.find('.dropdown-toggle').append(' <span class="caret"/>'); 84 85 // Tab panels 86 if ($nav_wrap.find('.tab-pane').length) { 87 88 if (!$nav_wrap.find('.tab-content').length) { 89 $nav_wrap.find('.tab-pane').wrapAll(jQuery('<div class="tab-content"/>')); 90 } 91 92 $nav.find('a').attr('data-toggle', 'tab').attr('role', 'tab'); 93 94 if (nav_data.navFade) { 95 $nav_wrap.find('.tab-content .tab-pane').addClass('fade'); 96 } 97 98 $nav.find('a:first').tab('show'); 99 100 } 101 102 var $icon_links = $nav.find('li .dw-icons + a'); 103 104 if ($icon_links.length) { 105 jQuery.each($icon_links, function () { 106 var $link = jQuery(this), 107 $icon = $link.prev(); 108 $icon.prependTo($link); 109 $icon.after(' '); 110 }); 111 } 112 113 jQuery(window).on('hashchange', function () { 114 jQuery('.bs-wrap-nav .nav a[href="' + location.hash + '"]').tab('show'); 115 }); 116 117 }); 118 119 120 // Buttons 121 jQuery('.bs-wrap-button').each(function () { 122 123 var $btn_wrap = jQuery(this), 124 btn_data = $btn_wrap.data(), 125 $btn_link = $btn_wrap.find('a'), 126 btn_class = ['btn']; 127 128 // Add Fake link 129 if (!$btn_link.length) { 130 131 var btn_label = $btn_wrap.html(); 132 $btn_wrap.html(''); 133 134 $btn_link = jQuery('<a href="javascript:void(0)"/>').html(btn_label); 135 jQuery(this).append($btn_link); 136 137 } 138 139 for (key in btn_data) { 140 141 var value = btn_data[key]; 142 143 switch (key) { 144 case 'btnType': 145 case 'btnSize': 146 btn_class.push(['btn-', value].join('')); 147 break; 148 case 'btnBlock': 149 btn_class.push('btn-block'); 150 break; 151 case 'btnDisabled': 152 btn_class.push('disabled'); 153 break; 154 case 'btnCollapse': 155 $btn_link.attr('data-toggle', 'collapse'); 156 $btn_link.attr('data-target', '#' + value); 157 $btn_link.on('click', function (e) { e.preventDefault(); }); 158 break; 159 case 'btnModal': 160 $btn_link.attr('data-toggle', 'modal'); 161 $btn_link.attr('data-target', '#' + value); 162 $btn_link.on('click', function (e) { e.preventDefault(); }); 163 break; 164 case 'btnIcon': 165 var icon = ['<i class="', value, '"/> '].join(''); 166 $btn_link.prepend(icon); 167 break; 168 } 169 170 } 171 172 $btn_link.addClass(btn_class.join(' ')); 173 $btn_link.attr('role', 'button'); 174 175 if ($btn_link.hasClass('curid')) { 176 $btn_link.addClass('active'); 177 } 178 179 if ($btn_link.hasClass('urlextern')) { 180 $btn_link.removeClass('urlextern').addClass('wikilink1'); 181 } 182 183 }); 184 185 186 // List Group 187 jQuery('.bs-wrap-list-group').each(function () { 188 189 var $list_wrap = jQuery(this); 190 191 var $icon_links = $list_wrap.find('li .dw-icons + a'); 192 193 if ($icon_links.length) { 194 jQuery.each($icon_links, function () { 195 var $link = jQuery(this), 196 $icon = $link.prev(); 197 $icon.prependTo($link); 198 $icon.after(' '); 199 }); 200 } 201 202 $list_wrap.find('div.li').contents().unwrap(); 203 $list_wrap.find('ul').addClass('list-group'); 204 $list_wrap.find('ul > li').addClass('list-group-item'); 205 206 if ($list_wrap.find('a').length) { 207 208 $list_wrap.find('a').parent().each(function () { 209 210 var $list = jQuery(this); 211 212 if ($list.children().length > 1) { 213 214 $list.wrapInner('<p class="list-group-item-text"/>'); 215 216 var $link = $list.find('a'); 217 218 $link.wrapInner('<h4 class="list-group-item-heading"/>'); 219 $link.prependTo($list); 220 $list.find('p').appendTo($link); 221 222 } 223 224 }); 225 226 $list_wrap.find('a').parent().contents().unwrap(); 227 $list_wrap.find('ul a').parent().contents().unwrap(); 228 $list_wrap.addClass('list-group'); 229 $list_wrap.find('a').addClass('list-group-item'); 230 $list_wrap.find('a.curid').removeClass('curid').addClass('active'); 231 232 } 233 234 $list_wrap.removeClass('hide'); 235 236 237 }); 238 239 240 // Accordion 241 jQuery('.bs-wrap-accordion').each(function () { 242 243 var $accordion = jQuery(this), 244 accordion_id = Math.random().toString(36).substr(2, 9), 245 is_collapsed = $accordion.hasClass('bs-wrap-accordion-collapsed'); 246 247 $accordion.find('.panel').each(function () { 248 249 var $panel = jQuery(this), 250 panel_id = accordion_id + '_' + Math.random().toString(36).substr(2, 9); 251 252 $panel.find('.panel-heading').wrapInner('<a role="button" data-toggle="collapse" data-parent="#' + accordion_id + '" href="#' + panel_id + '">'); 253 $panel.find('.panel-body').wrap('<div id="' + panel_id + '" class="panel-collapse collapse" role="tabpanel">'); 254 255 }); 256 257 $accordion.attr('id', accordion_id); 258 259 if ($accordion.find('.panel-collapse').length > 1 && !is_collapsed) { 260 $accordion.find('.panel-collapse').first().addClass('in'); 261 } 262 263 }); 264 265 266 // Carousel 267 jQuery('.bs-wrap-carousel').each(function () { 268 269 var $carousel = jQuery(this), 270 carousel_id = Math.random().toString(36).substr(2, 9), 271 $images = $carousel.find('img'), 272 $slides = $carousel.find('.bs-wrap-slide'), 273 $caption = $carousel.find('.bs-wrap-caption'), 274 $indicators = $carousel.find('ol'); 275 276 $carousel.attr('id', carousel_id); 277 278 $images.removeClass('media') 279 .removeClass('medialeft') 280 .removeClass('mediaright') 281 .removeClass('mediacenter'); 282 283 $images.addClass('center-block'); 284 285 if (!$slides.length) { 286 $images.wrap('<div class="item"/>'); 287 } 288 289 if ($caption.length) { 290 $caption.removeClass('caption').addClass('carousel-caption'); 291 } 292 293 $carousel.find('.carousel-control').attr('href', '#' + carousel_id); 294 295 for (var i = 0; i < $images.length; i++) { 296 $indicators.append('<li data-target="#' + carousel_id + '" data-slide-to="' + i + '"></li>'); 297 } 298 299 $carousel.find('.item').first().addClass('active'); 300 $indicators.find('li').first().addClass('active'); 301 302 }); 303 304 305 // Panel 306 jQuery('.bs-wrap-panel').each(function () { 307 308 var $panel = jQuery(this), 309 $panel_body = $panel.find('.panel-body'), 310 $panel_heading = $panel.find('.panel-heading'), 311 $first_title = $panel_body.find('> h4:first'); 312 313 if ($first_title.length && !$panel_heading.length) { 314 315 var $panel_heading = jQuery('<div class="panel-heading"></div>'); 316 317 $first_title.addClass('panel-title'); 318 $panel_heading.append($first_title); 319 $panel.prepend($panel_heading); 320 321 } 322 323 }); 324 325 326 //Modal 327 jQuery('.bs-wrap-modal').each(function () { 328 if (jQuery(this).attr('data-show') == true) { 329 jQuery(this).modal('show'); 330 } else { 331 jQuery(this).modal('hide'); 332 } 333 }); 334 335}); 336