@ -1,6 +1,6 @@
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* AdminLTE Site Search. js
* AdminLTE Navbar Search. js
* License MIT
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
@ -12,19 +12,18 @@ import $ from 'jquery'
* === === === === === === === === === === === === === === === === === =
* /
const NAME = ' Site Search'
const DATA _KEY = 'lte. site -search'
const NAME = ' Navbar Search'
const DATA _KEY = 'lte. navbar -search'
const JQUERY _NO _CONFLICT = $ . fn [ NAME ]
const SELECTOR _TOGGLE _BUTTON = '[data-widget="site-search"]'
const SELECTOR _SEARCH _BLOCK = '.site-search-block'
const SELECTOR _SEARCH _BACKDROP = '.site-search-backdrop'
const SELECTOR _SEARCH _INPUT = '.site-search-block .form-control'
const SELECTOR _TOGGLE _BUTTON = '[data-widget="navbar-search"]'
const SELECTOR _SEARCH _BLOCK = '.navbar-search-block'
const SELECTOR _SEARCH _INPUT = '.navbar-search-block .form-control'
const CLASS _NAME _OPEN = ' site -search-open'
const CLASS _NAME _OPEN = ' navbar -search-open'
const Default = {
transitionSpeed: 300
resetOnClose: true
}
/ * *
@ -32,25 +31,25 @@ const Default = {
* === === === === === === === === === === === === === === === === === =
* /
class Site Search {
class Navbar Search {
constructor ( _element , _options ) {
this . element = _element
this . options = $ . extend ( { } , Default , _options )
this . _ element = _element
this . _config = $ . extend ( { } , Default , _options )
}
// Public
open ( ) {
$ ( SELECTOR _SEARCH _BLOCK ) . slideDown ( this . options . transitionSpeed )
$ ( SELECTOR _SEARCH _BACKDROP ) . show ( 0 )
$ ( SELECTOR _SEARCH _BLOCK ) . css ( 'display' , 'flex' ) . hide ( ) . fadeIn ( ) . addClass ( CLASS _NAME _OPEN )
$ ( SELECTOR _SEARCH _INPUT ) . focus ( )
$ ( SELECTOR _SEARCH _BLOCK ) . addClass ( CLASS _NAME _OPEN )
}
close ( ) {
$ ( SELECTOR _SEARCH _BLOCK ) . slideUp ( this . options . transitionSpeed )
$ ( SELECTOR _SEARCH _BACKDROP ) . hide ( 0 )
$ ( SELECTOR _SEARCH _BLOCK ) . removeClass ( CLASS _NAME _OPEN )
$ ( SELECTOR _SEARCH _BLOCK ) . fadeOut ( ) . removeClass ( CLASS _NAME _OPEN )
if ( this . _config . resetOnClose ) {
$ ( SELECTOR _SEARCH _INPUT ) . val ( '' )
}
}
toggle ( ) {
@ -68,11 +67,11 @@ class SiteSearch {
let data = $ ( this ) . data ( DATA _KEY )
if ( ! data ) {
data = new Site Search( this , options )
data = new Navbar Search( this , options )
$ ( this ) . data ( DATA _KEY , data )
}
if ( ! /toggle|close /. test ( options ) ) {
if ( ! /toggle|close |open /. test ( options ) ) {
throw new Error ( ` Undefined method ${ options } ` )
}
@ -90,16 +89,11 @@ $(document).on('click', SELECTOR_TOGGLE_BUTTON, event => {
let button = $ ( event . currentTarget )
if ( button . data ( 'widget' ) !== ' site -search') {
if ( button . data ( 'widget' ) !== ' navbar -search') {
button = button . closest ( SELECTOR _TOGGLE _BUTTON )
}
SiteSearch . _jQueryInterface . call ( button , 'toggle' )
} )
$ ( document ) . on ( 'click' , SELECTOR _SEARCH _BACKDROP , event => {
const backdrop = $ ( event . currentTarget )
SiteSearch . _jQueryInterface . call ( backdrop , 'close' )
NavbarSearch . _jQueryInterface . call ( button , 'toggle' )
} )
/ * *
@ -107,11 +101,11 @@ $(document).on('click', SELECTOR_SEARCH_BACKDROP, event => {
* === === === === === === === === === === === === === === === === === =
* /
$ . fn [ NAME ] = Site Search. _jQueryInterface
$ . fn [ NAME ] . Constructor = Site Search
$ . fn [ NAME ] = Navbar Search. _jQueryInterface
$ . fn [ NAME ] . Constructor = Navbar Search
$ . fn [ NAME ] . noConflict = function ( ) {
$ . fn [ NAME ] = JQUERY _NO _CONFLICT
return Site Search. _jQueryInterface
return Navbar Search. _jQueryInterface
}
export default Site Search
export default Navbar Search