Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | /** |
| 2 | * PrimeFaces Ultima Layout |
||
| 3 | */ |
||
| 4 | PrimeFaces.widget.Ultima = PrimeFaces.widget.BaseWidget.extend({ |
||
| 5 | |||
| 6 | init: function(cfg) { |
||
| 7 | this._super(cfg); |
||
| 8 | this.wrapper = $(document.body).children('.layout-wrapper'); |
||
| 9 | this.topbar = $('body > .layout-wrapper > .topbar'); |
||
| 10 | this.menu = this.jq; |
||
| 11 | this.menuWrapper = this.menu.closest('.layout-menu'); |
||
| 12 | this.menulinks = this.menu.find('a'); |
||
| 13 | this.expandedMenuitems = this.expandedMenuitems || []; |
||
| 14 | this.profileButton = $('#profile-options'); |
||
| 15 | this.profileMenu = $('#profile-menu'); |
||
| 16 | this.topbarItems = this.topbar.find('.topbar-items'); |
||
| 17 | this.topbarLinks = this.topbarItems.find('> li > a'); |
||
| 18 | this.menuButton = $('#menu-button'); |
||
| 19 | this.topbarMenuButton = $('#topbar-menu-button'); |
||
| 20 | this.menuActive = false; |
||
| 21 | this.topbarLinkClick = false; |
||
| 22 | this.topbarMenuClick = false; |
||
| 23 | this.isMobileDev = this.isMobileDevice(); |
||
| 24 | |||
| 25 | this._bindEvents(); |
||
| 26 | |||
| 27 | if(!this.wrapper.hasClass('menu-layout-horizontal')) { |
||
| 28 | this.restoreMenuState(); |
||
| 29 | } |
||
| 30 | |||
| 31 | this.menuWrapper.children('.nano').nanoScroller({flash:true}); |
||
| 32 | }, |
||
| 33 | |||
| 34 | _bindEvents: function() { |
||
| 35 | var $this = this; |
||
| 36 | |||
| 37 | this.menuButton.off('click.menuButton').on('click.menuButton', function(e) { |
||
| 38 | $this.menuButton.toggleClass('menu-button-rotate'); |
||
| 39 | $this.topbarItems.removeClass('topbar-items-visible'); |
||
| 40 | |||
| 41 | //overlay |
||
| 42 | if($this.wrapper.hasClass('menu-layout-overlay')) { |
||
| 43 | $this.wrapper.toggleClass('layout-menu-overlay-active'); |
||
| 44 | |||
| 45 | if($this.wrapper.hasClass('layout-menu-overlay-active')) { |
||
| 46 | $this.enableModal(); |
||
| 47 | $this.enableSwipe(); |
||
| 48 | } |
||
| 49 | else { |
||
| 50 | $this.disableModal(); |
||
| 51 | $this.disableSwipe(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | //static |
||
| 55 | else { |
||
| 56 | if($this.isDesktop()) { |
||
| 57 | $this.wrapper.toggleClass('layout-menu-static-inactive') |
||
| 58 | } |
||
| 59 | else { |
||
| 60 | if($this.wrapper.hasClass('layout-menu-static-active')) { |
||
| 61 | $this.wrapper.removeClass('layout-menu-static-active'); |
||
| 62 | $this.disableModal(); |
||
| 63 | $this.disableSwipe(); |
||
| 64 | } |
||
| 65 | else { |
||
| 66 | $this.wrapper.addClass('layout-menu-static-active'); |
||
| 67 | $this.wrapper.removeClass('layout-menu-static-inactive'); |
||
| 68 | $this.enableModal(); |
||
| 69 | $this.enableSwipe(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | e.preventDefault(); |
||
| 75 | }); |
||
| 76 | |||
| 77 | this.topbarMenuButton.off('click.topbarButton').on('click.topbarButton', function(e) { |
||
| 78 | $this.topbarMenuClick = true; |
||
| 79 | $this.topbarItems.find('ul').removeClass('fadeInDown fadeOutUp'); |
||
| 80 | |||
| 81 | if($this.wrapper.hasClass('layout-menu-overlay-active')||$this.wrapper.hasClass('layout-menu-static-active')) { |
||
| 82 | $this.menuButton.removeClass('menu-button-rotate'); |
||
| 83 | $this.wrapper.removeClass('layout-menu-overlay-active layout-menu-static-active'); |
||
| 84 | $this.disableModal(); |
||
| 85 | } |
||
| 86 | |||
| 87 | if($this.topbarItems.hasClass('topbar-items-visible')) { |
||
| 88 | $this.topbarItems.addClass('fadeOutUp'); |
||
| 89 | |||
| 90 | setTimeout(function() { |
||
| 91 | $this.topbarItems.removeClass('fadeOutUp topbar-items-visible'); |
||
| 92 | },500); |
||
| 93 | } |
||
| 94 | else { |
||
| 95 | $this.topbarItems.addClass('topbar-items-visible fadeInDown'); |
||
| 96 | } |
||
| 97 | |||
| 98 | e.preventDefault(); |
||
| 99 | }); |
||
| 100 | |||
| 101 | this.menulinks.off('click').on('click', function(e) { |
||
| 102 | var link = $(this), |
||
| 103 | item = link.parent(), |
||
| 104 | submenu = item.children('ul'), |
||
| 105 | horizontal = $this.isHorizontal() && $this.isDesktop(); |
||
| 106 | |||
| 107 | if(horizontal) { |
||
| 108 | $this.horizontalMenuClick = true; |
||
| 109 | } |
||
| 110 | |||
| 111 | if(item.hasClass('active-menuitem')) { |
||
| 112 | if(submenu.length) { |
||
| 113 | $this.removeMenuitem(item.attr('id')); |
||
| 114 | item.removeClass('active-menuitem'); |
||
| 115 | |||
| 116 | if(horizontal) { |
||
| 117 | if(item.parent().is($this.jq)) { |
||
| 118 | $this.menuActive = false; |
||
| 119 | } |
||
| 120 | |||
| 121 | submenu.hide(); |
||
| 122 | } |
||
| 123 | else { |
||
| 124 | submenu.slideUp(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 | else { |
||
| 129 | $this.addMenuitem(item.attr('id')); |
||
| 130 | |||
| 131 | if(horizontal) { |
||
| 132 | $this.deactivateItems(item.siblings()); |
||
| 133 | item.addClass('active-menuitem'); |
||
| 134 | $this.menuActive = true; |
||
| 135 | submenu.show(); |
||
| 136 | } |
||
| 137 | else { |
||
| 138 | $this.deactivateItems(item.siblings(), true); |
||
| 139 | $this.activate(item); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | if(!horizontal) { |
||
| 144 | setTimeout(function() { |
||
| 145 | $(".nano").nanoScroller(); |
||
| 146 | }, 500); |
||
| 147 | } |
||
| 148 | |||
| 149 | if(submenu.length) { |
||
| 150 | e.preventDefault(); |
||
| 151 | } |
||
| 152 | }); |
||
| 153 | |||
| 154 | this.menu.find('> li').on('mouseenter', function(e) { |
||
| 155 | if($this.isHorizontal() && $this.isDesktop()) { |
||
| 156 | var item = $(this); |
||
| 157 | |||
| 158 | if(!item.hasClass('active-menuitem')) { |
||
| 159 | $this.menu.find('.active-menuitem').removeClass('active-menuitem'); |
||
| 160 | $this.menu.find('ul:visible').hide(); |
||
| 161 | $this.menu.find('.ink').remove(); |
||
| 162 | |||
| 163 | if($this.menuActive) { |
||
| 164 | item.addClass('active-menuitem'); |
||
| 165 | item.children('ul').show(); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | }); |
||
| 170 | |||
| 171 | this.profileButton.off('click.profileButton').on('click.profileButton', function(e) { |
||
| 172 | var profile = $this.profileMenu.prev('.profile'), |
||
| 173 | expanded = profile.hasClass('profile-expanded'); |
||
| 174 | |||
| 175 | $this.profileMenu.slideToggle(); |
||
| 176 | $this.profileMenu.prev('.profile').toggleClass('profile-expanded'); |
||
| 177 | $this.setInlineProfileState(!expanded); |
||
| 178 | |||
| 179 | setTimeout(function() { |
||
| 180 | $(".nano").nanoScroller(); |
||
| 181 | }, 500); |
||
| 182 | |||
| 183 | e.preventDefault(); |
||
| 184 | }); |
||
| 185 | |||
| 186 | this.topbarLinks.off('click.topbarLink').on('click.topbarLink', function(e) { |
||
| 187 | var link = $(this), |
||
| 188 | item = link.parent(), |
||
| 189 | submenu = link.next(); |
||
| 190 | |||
| 191 | $this.topbarLinkClick = true; |
||
| 192 | |||
| 193 | item.siblings('.active-top-menu').removeClass('active-top-menu'); |
||
| 194 | if($this.wrapper.hasClass('layout-menu-overlay-active')) { |
||
| 195 | $this.menuButton.removeClass('menu-button-rotate'); |
||
| 196 | $this.wrapper.removeClass('layout-menu-overlay-active'); |
||
| 197 | $this.disableModal(); |
||
| 198 | } |
||
| 199 | |||
| 200 | if($this.isDesktop()) { |
||
| 201 | if(submenu.length) { |
||
| 202 | if(item.hasClass('active-top-menu')) { |
||
| 203 | submenu.addClass('fadeOutUp'); |
||
| 204 | |||
| 205 | setTimeout(function() { |
||
| 206 | item.removeClass('active-top-menu'), |
||
| 207 | submenu.removeClass('fadeOutUp'); |
||
| 208 | },500); |
||
| 209 | } |
||
| 210 | else { |
||
| 211 | item.addClass('active-top-menu'); |
||
| 212 | submenu.addClass('fadeInDown'); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | else { |
||
| 217 | item.children('ul').removeClass('fadeInDown fadeOutUp'); |
||
| 218 | item.toggleClass('active-top-menu'); |
||
| 219 | } |
||
| 220 | |||
| 221 | e.preventDefault(); |
||
| 222 | }); |
||
| 223 | |||
| 224 | $this.topbarItems.children('.search-item').on('click', function(e) { |
||
| 225 | $this.topbarLinkClick = true; |
||
| 226 | }); |
||
| 227 | |||
| 228 | $(document.body).off('click').on('click', function() { |
||
| 229 | if($this.isHorizontal() && !$this.horizontalMenuClick && $this.isDesktop()) { |
||
| 230 | $this.menu.find('.active-menuitem').removeClass('active-menuitem'); |
||
| 231 | $this.menu.find('ul:visible').hide(); |
||
| 232 | $this.menuActive = false; |
||
| 233 | } |
||
| 234 | |||
| 235 | if(!$this.topbarMenuClick && !$this.topbarLinkClick) { |
||
| 236 | $this.topbarItems.find('.active-top-menu').removeClass('active-top-menu'); |
||
| 237 | } |
||
| 238 | |||
| 239 | if(!$this.topbarMenuClick && !$this.topbarLinkClick) { |
||
| 240 | $this.topbarItems.removeClass('topbar-items-visible'); |
||
| 241 | } |
||
| 242 | |||
| 243 | $this.horizontalMenuClick = false; |
||
| 244 | $this.topbarLinkClick = false; |
||
| 245 | $this.topbarMenuClick = false; |
||
| 246 | }); |
||
| 247 | }, |
||
| 248 | |||
| 249 | activate: function(item) { |
||
| 250 | var submenu = item.children('ul'); |
||
| 251 | item.addClass('active-menuitem'); |
||
| 252 | |||
| 253 | if(submenu.length) { |
||
| 254 | submenu.slideDown(); |
||
| 255 | } |
||
| 256 | }, |
||
| 257 | |||
| 258 | deactivate: function(item) { |
||
| 259 | var submenu = item.children('ul'); |
||
| 260 | item.removeClass('active-menuitem'); |
||
| 261 | |||
| 262 | if(submenu.length) { |
||
| 263 | submenu.hide(); |
||
| 264 | } |
||
| 265 | }, |
||
| 266 | |||
| 267 | deactivateItems: function(items, animate) { |
||
| 268 | var $this = this; |
||
| 269 | |||
| 270 | for(var i = 0; i < items.length; i++) { |
||
| 271 | var item = items.eq(i), |
||
| 272 | submenu = item.children('ul'); |
||
| 273 | |||
| 274 | if(submenu.length) { |
||
| 275 | if(item.hasClass('active-menuitem')) { |
||
| 276 | var activeSubItems = item.find('.active-menuitem'); |
||
| 277 | item.removeClass('active-menuitem'); |
||
| 278 | item.find('.ink').remove(); |
||
| 279 | |||
| 280 | if(animate) { |
||
| 281 | submenu.slideUp('normal', function() { |
||
| 282 | $(this).parent().find('.active-menuitem').each(function() { |
||
| 283 | $this.deactivate($(this)); |
||
| 284 | }); |
||
| 285 | }); |
||
| 286 | } |
||
| 287 | else { |
||
| 288 | submenu.hide(); |
||
| 289 | item.find('.active-menuitem').each(function() { |
||
| 290 | $this.deactivate($(this)); |
||
| 291 | }); |
||
| 292 | } |
||
| 293 | |||
| 294 | $this.removeMenuitem(item.attr('id')); |
||
| 295 | activeSubItems.each(function() { |
||
| 296 | $this.removeMenuitem($(this).attr('id')); |
||
| 297 | }); |
||
| 298 | } |
||
| 299 | else { |
||
| 300 | item.find('.active-menuitem').each(function() { |
||
| 301 | var subItem = $(this); |
||
| 302 | $this.deactivate(subItem); |
||
| 303 | $this.removeMenuitem(subItem.attr('id')); |
||
| 304 | }); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | else if(item.hasClass('active-menuitem')) { |
||
| 308 | $this.deactivate(item); |
||
| 309 | $this.removeMenuitem(item.attr('id')); |
||
| 310 | } |
||
| 311 | } |
||
| 312 | }, |
||
| 313 | |||
| 314 | removeMenuitem: function (id) { |
||
| 315 | this.expandedMenuitems = $.grep(this.expandedMenuitems, function (value) { |
||
| 316 | return value !== id; |
||
| 317 | }); |
||
| 318 | this.saveMenuState(); |
||
| 319 | }, |
||
| 320 | |||
| 321 | addMenuitem: function (id) { |
||
| 322 | if ($.inArray(id, this.expandedMenuitems) === -1) { |
||
| 323 | this.expandedMenuitems.push(id); |
||
| 324 | } |
||
| 325 | this.saveMenuState(); |
||
| 326 | }, |
||
| 327 | |||
| 328 | saveMenuState: function() { |
||
| 329 | $.cookie('ultima_expandeditems', this.expandedMenuitems.join(','), {path: '/'}); |
||
| 330 | }, |
||
| 331 | |||
| 332 | clearMenuState: function() { |
||
| 333 | $.removeCookie('ultima_expandeditems', {path: '/'}); |
||
| 334 | }, |
||
| 335 | |||
| 336 | setInlineProfileState: function(expanded) { |
||
| 337 | if(expanded) |
||
| 338 | $.cookie('ultima_inlineprofile_expanded', "1", {path: '/'}); |
||
| 339 | else |
||
| 340 | $.removeCookie('ultima_inlineprofile_expanded', {path: '/'}); |
||
| 341 | }, |
||
| 342 | |||
| 343 | restoreMenuState: function() { |
||
| 344 | var menucookie = $.cookie('ultima_expandeditems'); |
||
| 345 | if (menucookie) { |
||
| 346 | this.expandedMenuitems = menucookie.split(','); |
||
| 347 | for (var i = 0; i < this.expandedMenuitems.length; i++) { |
||
| 348 | var id = this.expandedMenuitems[i]; |
||
| 349 | if (id) { |
||
| 350 | var menuitem = $("#" + this.expandedMenuitems[i].replace(/:/g, "\\:")); |
||
| 351 | menuitem.addClass('active-menuitem'); |
||
| 352 | |||
| 353 | var submenu = menuitem.children('ul'); |
||
| 354 | if(submenu.length) { |
||
| 355 | submenu.show(); |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | var inlineProfileCookie = $.cookie('ultima_inlineprofile_expanded'); |
||
| 362 | if (inlineProfileCookie) { |
||
| 363 | this.profileMenu.show().prev('.profile').addClass('profile-expanded'); |
||
| 364 | } |
||
| 365 | }, |
||
| 366 | |||
| 367 | enableModal: function() { |
||
| 368 | this.modal = this.wrapper.append('<div class="layout-mask"></div>').children('.layout-mask'); |
||
| 369 | }, |
||
| 370 | |||
| 371 | disableModal: function() { |
||
| 372 | this.modal.remove(); |
||
| 373 | }, |
||
| 374 | |||
| 375 | enableSwipe: function() { |
||
| 376 | if(this.isMobileDev) { |
||
| 377 | var $this = this; |
||
| 378 | this.menuWrapper.swipe({ |
||
| 379 | swipeLeft: function() { |
||
| 380 | $this.menuButton.click(); |
||
| 381 | } |
||
| 382 | }); |
||
| 383 | } |
||
| 384 | }, |
||
| 385 | |||
| 386 | disableSwipe: function() { |
||
| 387 | if(this.isMobileDev) { |
||
| 388 | this.menuWrapper.swipe('destroy'); |
||
| 389 | } |
||
| 390 | }, |
||
| 391 | |||
| 392 | isHorizontal: function() { |
||
| 393 | return this.wrapper.hasClass('menu-layout-horizontal'); |
||
| 394 | }, |
||
| 395 | |||
| 396 | isTablet: function() { |
||
| 397 | var width = window.innerWidth; |
||
| 398 | return width <= 1024 && width > 640; |
||
| 399 | }, |
||
| 400 | |||
| 401 | isDesktop: function() { |
||
| 402 | return window.innerWidth > 1024; |
||
| 403 | }, |
||
| 404 | |||
| 405 | isMobile: function() { |
||
| 406 | return window.innerWidth <= 640; |
||
| 407 | }, |
||
| 408 | |||
| 409 | isMobileDevice: function() { |
||
| 410 | return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(window.navigator.userAgent.toLowerCase()); |
||
| 411 | } |
||
| 412 | |||
| 413 | }); |
||
| 414 | |||
| 415 | /*! |
||
| 416 | * jQuery Cookie Plugin v1.4.1 |
||
| 417 | * https://github.com/carhartl/jquery-cookie |
||
| 418 | * |
||
| 419 | * Copyright 2006, 2014 Klaus Hartl |
||
| 420 | * Released under the MIT license |
||
| 421 | */ |
||
| 422 | (function (factory) { |
||
| 423 | if (typeof define === 'function' && define.amd) { |
||
| 424 | // AMD (Register as an anonymous module) |
||
| 425 | define(['jquery'], factory); |
||
| 426 | } else if (typeof exports === 'object') { |
||
| 427 | // Node/CommonJS |
||
| 428 | module.exports = factory(require('jquery')); |
||
| 429 | } else { |
||
| 430 | // Browser globals |
||
| 431 | factory(jQuery); |
||
| 432 | } |
||
| 433 | }(function ($) { |
||
| 434 | |||
| 435 | var pluses = /\+/g; |
||
| 436 | |||
| 437 | function encode(s) { |
||
| 438 | return config.raw ? s : encodeURIComponent(s); |
||
| 439 | } |
||
| 440 | |||
| 441 | function decode(s) { |
||
| 442 | return config.raw ? s : decodeURIComponent(s); |
||
| 443 | } |
||
| 444 | |||
| 445 | function stringifyCookieValue(value) { |
||
| 446 | return encode(config.json ? JSON.stringify(value) : String(value)); |
||
| 447 | } |
||
| 448 | |||
| 449 | function parseCookieValue(s) { |
||
| 450 | if (s.indexOf('"') === 0) { |
||
| 451 | // This is a quoted cookie as according to RFC2068, unescape... |
||
| 452 | s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); |
||
| 453 | } |
||
| 454 | |||
| 455 | try { |
||
| 456 | // Replace server-side written pluses with spaces. |
||
| 457 | // If we can't decode the cookie, ignore it, it's unusable. |
||
| 458 | // If we can't parse the cookie, ignore it, it's unusable. |
||
| 459 | s = decodeURIComponent(s.replace(pluses, ' ')); |
||
| 460 | return config.json ? JSON.parse(s) : s; |
||
| 461 | } catch(e) {} |
||
| 462 | } |
||
| 463 | |||
| 464 | function read(s, converter) { |
||
| 465 | var value = config.raw ? s : parseCookieValue(s); |
||
| 466 | return $.isFunction(converter) ? converter(value) : value; |
||
| 467 | } |
||
| 468 | |||
| 469 | var config = $.cookie = function (key, value, options) { |
||
| 470 | |||
| 471 | // Write |
||
| 472 | |||
| 473 | if (arguments.length > 1 && !$.isFunction(value)) { |
||
| 474 | options = $.extend({}, config.defaults, options); |
||
| 475 | |||
| 476 | if (typeof options.expires === 'number') { |
||
| 477 | var days = options.expires, t = options.expires = new Date(); |
||
| 478 | t.setMilliseconds(t.getMilliseconds() + days * 864e+5); |
||
| 479 | } |
||
| 480 | |||
| 481 | return (document.cookie = [ |
||
| 482 | encode(key), '=', stringifyCookieValue(value), |
||
| 483 | options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE |
||
| 484 | options.path ? '; path=' + options.path : '', |
||
| 485 | options.domain ? '; domain=' + options.domain : '', |
||
| 486 | options.secure ? '; secure' : '' |
||
| 487 | ].join('')); |
||
| 488 | } |
||
| 489 | |||
| 490 | // Read |
||
| 491 | |||
| 492 | var result = key ? undefined : {}, |
||
| 493 | // To prevent the for loop in the first place assign an empty array |
||
| 494 | // in case there are no cookies at all. Also prevents odd result when |
||
| 495 | // calling $.cookie(). |
||
| 496 | cookies = document.cookie ? document.cookie.split('; ') : [], |
||
| 497 | i = 0, |
||
| 498 | l = cookies.length; |
||
| 499 | |||
| 500 | for (; i < l; i++) { |
||
| 501 | var parts = cookies[i].split('='), |
||
| 502 | name = decode(parts.shift()), |
||
| 503 | cookie = parts.join('='); |
||
| 504 | |||
| 505 | if (key === name) { |
||
| 506 | // If second argument (value) is a function it's a converter... |
||
| 507 | result = read(cookie, value); |
||
| 508 | break; |
||
| 509 | } |
||
| 510 | |||
| 511 | // Prevent storing a cookie that we couldn't decode. |
||
| 512 | if (!key && (cookie = read(cookie)) !== undefined) { |
||
| 513 | result[name] = cookie; |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | return result; |
||
| 518 | }; |
||
| 519 | |||
| 520 | config.defaults = {}; |
||
| 521 | |||
| 522 | $.removeCookie = function (key, options) { |
||
| 523 | // Must not alter options, thus extending a fresh object... |
||
| 524 | $.cookie(key, '', $.extend({}, options, { expires: -1 })); |
||
| 525 | return !$.cookie(key); |
||
| 526 | }; |
||
| 527 | |||
| 528 | })); |
||
| 529 | |||
| 530 | /* Issue #924 is fixed for 5.3+ and 6.0. (compatibility with 5.3) */ |
||
| 531 | if(window['PrimeFaces'] && window['PrimeFaces'].widget.Dialog) { |
||
| 532 | PrimeFaces.widget.Dialog = PrimeFaces.widget.Dialog.extend({ |
||
| 533 | |||
| 534 | enableModality: function() { |
||
| 535 | this._super(); |
||
| 536 | $(document.body).children(this.jqId + '_modal').addClass('ui-dialog-mask'); |
||
| 537 | }, |
||
| 538 | |||
| 539 | syncWindowResize: function() {} |
||
| 540 | }); |
||
| 541 | } |
||
| 542 | |||
| 543 | /* JS extensions to support material animations */ |
||
| 544 | if(PrimeFaces.widget.InputSwitch) { |
||
| 545 | PrimeFaces.widget.InputSwitch = PrimeFaces.widget.InputSwitch.extend({ |
||
| 546 | |||
| 547 | init: function(cfg) { |
||
| 548 | this._super(cfg); |
||
| 549 | |||
| 550 | if(this.input.prop('checked')) { |
||
| 551 | this.jq.addClass('ui-inputswitch-checked'); |
||
| 552 | } |
||
| 553 | }, |
||
| 554 | |||
| 555 | toggle: function() { |
||
| 556 | var $this = this; |
||
| 557 | |||
| 558 | if(this.input.prop('checked')) |
||
| 559 | this.uncheck(); |
||
| 560 | else |
||
| 561 | this.check(); |
||
| 562 | |||
| 563 | setTimeout(function() { |
||
| 564 | $this.jq.toggleClass('ui-inputswitch-checked'); |
||
| 565 | }, 100); |
||
| 566 | } |
||
| 567 | }); |
||
| 568 | } |
||
| 569 | |||
| 570 | if(PrimeFaces.widget.SelectBooleanButton) { |
||
| 571 | PrimeFaces.widget.SelectBooleanButton.prototype.check = function() { |
||
| 572 | if(!this.disabled) { |
||
| 573 | this.input.prop('checked', true); |
||
| 574 | this.jq.addClass('ui-state-active').children('.ui-button-text').contents()[0].textContent = this.cfg.onLabel; |
||
| 575 | |||
| 576 | if(this.icon.length > 0) { |
||
| 577 | this.icon.removeClass(this.cfg.offIcon).addClass(this.cfg.onIcon); |
||
| 578 | } |
||
| 579 | |||
| 580 | this.input.trigger('change'); |
||
| 581 | } |
||
| 582 | } |
||
| 583 | |||
| 584 | PrimeFaces.widget.SelectBooleanButton.prototype.uncheck = function() { |
||
| 585 | if(!this.disabled) { |
||
| 586 | this.input.prop('checked', false); |
||
| 587 | this.jq.removeClass('ui-state-active').children('.ui-button-text').contents()[0].textContent = this.cfg.offLabel; |
||
| 588 | |||
| 589 | if(this.icon.length > 0) { |
||
| 590 | this.icon.removeClass(this.cfg.onIcon).addClass(this.cfg.offIcon); |
||
| 591 | } |
||
| 592 | |||
| 593 | this.input.trigger('change'); |
||
| 594 | } |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | PrimeFaces.skinInput = function(input) { |
||
| 599 | setTimeout(function() { |
||
| 600 | if(input.val() != '') { |
||
| 601 | var parent = input.parent(); |
||
| 602 | input.addClass('ui-state-filled'); |
||
| 603 | |||
| 604 | if(parent.is("span:not('.md-inputfield')")) { |
||
| 605 | parent.addClass('md-inputwrapper-filled'); |
||
| 606 | } |
||
| 607 | } |
||
| 608 | }, 1); |
||
| 609 | |||
| 610 | input.on('mouseenter', function() { |
||
| 611 | $(this).addClass('ui-state-hover'); |
||
| 612 | }) |
||
| 613 | .on('mouseleave', function() { |
||
| 614 | $(this).removeClass('ui-state-hover'); |
||
| 615 | }) |
||
| 616 | .on('focus', function() { |
||
| 617 | var parent = input.parent(); |
||
| 618 | $(this).addClass('ui-state-focus'); |
||
| 619 | |||
| 620 | if(parent.is("span:not('.md-inputfield')")) { |
||
| 621 | parent.addClass('md-inputwrapper-focus'); |
||
| 622 | } |
||
| 623 | }) |
||
| 624 | .on('blur', function() { |
||
| 625 | $(this).removeClass('ui-state-focus'); |
||
| 626 | |||
| 627 | if(input.hasClass('hasDatepicker')) { |
||
| 628 | setTimeout(function() { |
||
| 629 | PrimeFaces.onInputBlur(input); |
||
| 630 | },150); |
||
| 631 | } |
||
| 632 | else { |
||
| 633 | PrimeFaces.onInputBlur(input); |
||
| 634 | } |
||
| 635 | }); |
||
| 636 | |||
| 637 | //aria |
||
| 638 | input.attr('role', 'textbox') |
||
| 639 | .attr('aria-disabled', input.is(':disabled')) |
||
| 640 | .attr('aria-readonly', input.prop('readonly')); |
||
| 641 | |||
| 642 | if(input.is('textarea')) { |
||
| 643 | input.attr('aria-multiline', true); |
||
| 644 | } |
||
| 645 | |||
| 646 | return this; |
||
| 647 | }; |
||
| 648 | |||
| 649 | PrimeFaces.onInputBlur = function(input) { |
||
| 650 | var parent = input.parent(), |
||
| 651 | hasInputFieldClass = parent.is("span:not('.md-inputfield')"); |
||
| 652 | |||
| 653 | if(parent.hasClass('md-inputwrapper-focus')) { |
||
| 654 | parent.removeClass('md-inputwrapper-focus'); |
||
| 655 | } |
||
| 656 | |||
| 657 | if(input.val() != '') { |
||
| 658 | input.addClass('ui-state-filled'); |
||
| 659 | if(hasInputFieldClass) { |
||
| 660 | parent.addClass('md-inputwrapper-filled'); |
||
| 661 | } |
||
| 662 | } |
||
| 663 | else { |
||
| 664 | input.removeClass('ui-state-filled'); |
||
| 665 | parent.removeClass('md-inputwrapper-filled'); |
||
| 666 | } |
||
| 667 | }; |
||
| 668 | |||
| 669 | if(PrimeFaces.widget.AutoComplete) { |
||
| 670 | PrimeFaces.widget.AutoComplete.prototype.setupMultipleMode = function() { |
||
| 671 | var $this = this; |
||
| 672 | this.multiItemContainer = this.jq.children('ul'); |
||
| 673 | this.inputContainer = this.multiItemContainer.children('.ui-autocomplete-input-token'); |
||
| 674 | |||
| 675 | this.multiItemContainer.hover(function() { |
||
| 676 | $(this).addClass('ui-state-hover'); |
||
| 677 | }, |
||
| 678 | function() { |
||
| 679 | $(this).removeClass('ui-state-hover'); |
||
| 680 | } |
||
| 681 | ).click(function() { |
||
| 682 | $this.input.focus(); |
||
| 683 | }); |
||
| 684 | |||
| 685 | //delegate events to container |
||
| 686 | this.input.focus(function() { |
||
| 687 | $this.multiItemContainer.addClass('ui-state-focus'); |
||
| 688 | $this.jq.addClass('md-inputwrapper-focus'); |
||
| 689 | }).blur(function(e) { |
||
| 690 | $this.multiItemContainer.removeClass('ui-state-focus'); |
||
| 691 | $this.jq.removeClass('md-inputwrapper-focus').addClass('md-inputwrapper-filled'); |
||
| 692 | |||
| 693 | setTimeout(function() { |
||
| 694 | if($this.hinput.children().length == 0 && !$this.multiItemContainer.hasClass('ui-state-focus')) { |
||
| 695 | $this.jq.removeClass('md-inputwrapper-filled'); |
||
| 696 | } |
||
| 697 | }, 150); |
||
| 698 | }); |
||
| 699 | |||
| 700 | var closeSelector = '> li.ui-autocomplete-token > .ui-autocomplete-token-icon'; |
||
| 701 | this.multiItemContainer.off('click', closeSelector).on('click', closeSelector, null, function(event) { |
||
| 702 | if($this.multiItemContainer.children('li.ui-autocomplete-token').length === $this.cfg.selectLimit) { |
||
| 703 | if(PrimeFaces.isIE(8)) { |
||
| 704 | $this.input.val(''); |
||
| 705 | } |
||
| 706 | $this.input.css('display', 'inline'); |
||
| 707 | $this.enableDropdown(); |
||
| 708 | } |
||
| 709 | $this.removeItem(event, $(this).parent()); |
||
| 710 | }); |
||
| 711 | }; |
||
| 712 | }; |
||
| 713 | |||
| 714 | if(PrimeFaces.widget.Calendar) { |
||
| 715 | PrimeFaces.widget.Calendar.prototype.bindDateSelectListener = function() { |
||
| 716 | var _self = this; |
||
| 717 | |||
| 718 | this.cfg.onSelect = function() { |
||
| 719 | if(_self.cfg.popup) { |
||
| 720 | _self.fireDateSelectEvent(); |
||
| 721 | } |
||
| 722 | else { |
||
| 723 | var newDate = $.datepicker.formatDate(_self.cfg.dateFormat, _self.getDate()); |
||
| 724 | |||
| 725 | _self.input.val(newDate); |
||
| 726 | _self.fireDateSelectEvent(); |
||
| 727 | } |
||
| 728 | |||
| 729 | if(_self.input.val() != '') { |
||
| 730 | var parent = _self.input.parent(); |
||
| 731 | parent.addClass('md-inputwrapper-filled'); |
||
| 732 | _self.input.addClass('ui-state-filled'); |
||
| 733 | } |
||
| 734 | }; |
||
| 735 | }; |
||
| 736 | } |