| @@ -1,220 +1,220 @@ | ||
| 1 | -const $ = window.jQuery || jQuery; | |
| 2 | - | |
| 3 | -const serializeJSON = function serializeJSON( path ) { | |
| 4 | - const isInput = $( this ).is( 'input' ) || $( this ).is( 'select' ) || $( this ).is( 'textarea' ); | |
| 5 | - let unIndexed = isInput ? $( this ).serializeArray() : $( this ).find( 'input, select, textarea' ).serializeArray(), | |
| 6 | - indexed = {}, | |
| 7 | - validate = /(\[([a-zA-Z0-9_-]+)?\]?)/g, | |
| 8 | - arrayKeys = {}, | |
| 9 | - end = false; | |
| 10 | - $.each( unIndexed, function() { | |
| 11 | - const that = this, | |
| 12 | - match = this.name.match( /^([0-9a-zA-Z_-]+)/ ); | |
| 13 | - if ( ! match ) { | |
| 14 | - return; | |
| 15 | - } | |
| 16 | - let keys = this.name.match( validate ), | |
| 17 | - objPath = "indexed['" + match[ 0 ] + "']"; | |
| 18 | - | |
| 19 | - if ( keys ) { | |
| 20 | - if ( typeof indexed[ match[ 0 ] ] != 'object' ) { | |
| 21 | - indexed[ match[ 0 ] ] = {}; | |
| 22 | - } | |
| 23 | - | |
| 24 | - $.each( keys, function( i, prop ) { | |
| 25 | - prop = prop.replace( /\]|\[/g, '' ); | |
| 26 | - let rawPath = objPath.replace( /'|\[|\]/g, '' ), | |
| 27 | - objExp = '', | |
| 28 | - preObjPath = objPath; | |
| 29 | - | |
| 30 | - if ( prop == '' ) { | |
| 31 | - if ( arrayKeys[ rawPath ] == undefined ) { | |
| 32 | - arrayKeys[ rawPath ] = 0; | |
| 33 | - } else { | |
| 34 | - arrayKeys[ rawPath ]++; | |
| 35 | - } | |
| 36 | - objPath += "['" + arrayKeys[ rawPath ] + "']"; | |
| 37 | - } else { | |
| 38 | - if ( ! isNaN( prop ) ) { | |
| 39 | - arrayKeys[ rawPath ] = prop; | |
| 40 | - } | |
| 41 | - objPath += "['" + prop + "']"; | |
| 42 | - } | |
| 43 | - try { | |
| 44 | - if ( i == keys.length - 1 ) { | |
| 45 | - objExp = objPath + '=that.value;'; | |
| 46 | - end = true; | |
| 47 | - } else { | |
| 48 | - objExp = objPath + '={}'; | |
| 49 | - end = false; | |
| 50 | - } | |
| 51 | - | |
| 52 | - const evalString = '' + | |
| 53 | - 'if( typeof ' + objPath + " == 'undefined'){" + objExp + ';' + | |
| 54 | - '}else{' + | |
| 55 | - 'if(end){' + | |
| 56 | - 'if(typeof ' + preObjPath + "!='object'){" + preObjPath + '={};}' + | |
| 57 | - objExp + | |
| 58 | - '}' + | |
| 59 | - '}'; | |
| 60 | - eval( evalString ); | |
| 61 | - } catch ( e ) { | |
| 62 | - console.log( 'Error:' + e + '\n' + objExp ); | |
| 63 | - } | |
| 64 | - } ); | |
| 65 | - } else { | |
| 66 | - indexed[ match[ 0 ] ] = this.value; | |
| 67 | - } | |
| 68 | - } ); | |
| 69 | - if ( path ) { | |
| 70 | - path = "['" + path.replace( '.', "']['" ) + "']"; | |
| 71 | - const c = 'try{indexed = indexed' + path + '}catch(ex){console.log(c, ex);}'; | |
| 72 | - eval( c ); | |
| 73 | - } | |
| 74 | - return indexed; | |
| 75 | -}; | |
| 76 | - | |
| 77 | -const LP_Tooltip = ( options ) => { | |
| 78 | - options = $.extend( {}, { offset: [ 0, 0 ] }, options || {} ); | |
| 79 | - | |
| 80 | - return $.each( this, function() { | |
| 81 | - const $el = $( this ), | |
| 82 | - content = $el.data( 'content' ); | |
| 83 | - | |
| 84 | - if ( ! content || ( $el.data( 'LP_Tooltip' ) !== undefined ) ) { | |
| 85 | - return; | |
| 86 | - } | |
| 87 | - | |
| 88 | - let $tooltip = null; | |
| 89 | - | |
| 90 | - $el.on( 'mouseenter', function( e ) { | |
| 91 | - $tooltip = $( '<div class="learn-press-tooltip-bubble"/>' ).html( content ).appendTo( $( 'body' ) ).hide(); | |
| 92 | - const position = $el.offset(); | |
| 93 | - | |
| 94 | - if ( Array.isArray( options.offset ) ) { | |
| 95 | - const top = options.offset[ 1 ], | |
| 96 | - left = options.offset[ 0 ]; | |
| 97 | - | |
| 98 | - if ( $.isNumeric( left ) ) { | |
| 99 | - position.left += left; | |
| 100 | - } else { | |
| 101 | - | |
| 102 | - } | |
| 103 | - if ( $.isNumeric( top ) ) { | |
| 104 | - position.top += top; | |
| 105 | - } else { | |
| 106 | - | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - $tooltip.css( { | |
| 111 | - top: position.top, | |
| 112 | - left: position.left, | |
| 113 | - } ); | |
| 114 | - | |
| 115 | - $tooltip.fadeIn(); | |
| 116 | - } ); | |
| 117 | - | |
| 118 | - $el.on( 'mouseleave', function( e ) { | |
| 119 | - $tooltip && $tooltip.remove(); | |
| 120 | - } ); | |
| 121 | - | |
| 122 | - $el.data( 'tooltip', true ); | |
| 123 | - } ); | |
| 124 | -}; | |
| 125 | - | |
| 126 | -const hasEvent = function hasEvent( name ) { | |
| 127 | - const events = $( this ).data( 'events' ); | |
| 128 | - if ( typeof events.LP == 'undefined' ) { | |
| 129 | - return false; | |
| 130 | - } | |
| 131 | - for ( i = 0; i < events.LP.length; i++ ) { | |
| 132 | - if ( events.LP[ i ].namespace == name ) { | |
| 133 | - return true; | |
| 134 | - } | |
| 135 | - } | |
| 136 | - return false; | |
| 137 | -}; | |
| 138 | - | |
| 139 | -const dataToJSON = function dataToJSON() { | |
| 140 | - const json = {}; | |
| 141 | - $.each( this[ 0 ].attributes, function() { | |
| 142 | - const m = this.name.match( /^data-(.*)/ ); | |
| 143 | - if ( m ) { | |
| 144 | - json[ m[ 1 ] ] = this.value; | |
| 145 | - } | |
| 146 | - } ); | |
| 147 | - return json; | |
| 148 | -}; | |
| 149 | - | |
| 150 | -const rows = function rows() { | |
| 151 | - const h = $( this ).height(); | |
| 152 | - const lh = $( this ).css( 'line-height' ).replace( 'px', '' ); | |
| 153 | - $( this ).attr( { height: h, 'line-height': lh } ); | |
| 154 | - | |
| 155 | - return Math.floor( h / parseInt( lh ) ); | |
| 156 | -}; | |
| 157 | - | |
| 158 | -const checkLines = function checkLines( p ) { | |
| 159 | - return this.each( function() { | |
| 160 | - const $e = $( this ), | |
| 161 | - rows = $e.rows(); | |
| 162 | - | |
| 163 | - p.call( this, rows ); | |
| 164 | - } ); | |
| 165 | -}; | |
| 166 | - | |
| 167 | -const findNext = function findNext( selector ) { | |
| 168 | - const $selector = $( selector ), | |
| 169 | - $root = this.first(), | |
| 170 | - index = $selector.index( $root ), | |
| 171 | - $next = $selector.eq( index + 1 ); | |
| 172 | - return $next.length ? $next : false; | |
| 173 | -}; | |
| 174 | - | |
| 175 | -const findPrev = function findPrev( selector ) { | |
| 176 | - const $selector = $( selector ), | |
| 177 | - $root = this.first(), | |
| 178 | - index = $selector.index( $root ), | |
| 179 | - $prev = $selector.eq( index - 1 ); | |
| 180 | - return $prev.length ? $prev : false; | |
| 181 | -}; | |
| 182 | - | |
| 183 | -const progress = function progress( v ) { | |
| 184 | - return this.each( function() { | |
| 185 | - const t = parseInt( v / 100 * 360 ), | |
| 186 | - timer = null, | |
| 187 | - $this = $( this ); | |
| 188 | - | |
| 189 | - if ( t < 180 ) { | |
| 190 | - $this.find( '.progress-circle' ).removeClass( 'gt-50' ); | |
| 191 | - } else { | |
| 192 | - $this.find( '.progress-circle' ).addClass( 'gt-50' ); | |
| 193 | - } | |
| 194 | - $this.find( '.fill' ).css( { | |
| 195 | - transform: 'rotate(' + t + 'deg)', | |
| 196 | - } ); | |
| 197 | - } ); | |
| 198 | -}; | |
| 199 | - | |
| 200 | -$.fn.serializeJSON = serializeJSON; | |
| 201 | -$.fn.LP_Tooltip = LP_Tooltip; | |
| 202 | -$.fn.hasEvent = hasEvent; | |
| 203 | -$.fn.dataToJSON = dataToJSON; | |
| 204 | -$.fn.rows = rows; | |
| 205 | -$.fn.checkLines = checkLines; | |
| 206 | -$.fn.findNext = findNext; | |
| 207 | -$.fn.findPrev = findPrev; | |
| 208 | -$.fn.progress = progress; | |
| 209 | - | |
| 210 | -export default { | |
| 211 | - serializeJSON, | |
| 212 | - LP_Tooltip, | |
| 213 | - hasEvent, | |
| 214 | - dataToJSON, | |
| 215 | - rows, | |
| 216 | - checkLines, | |
| 217 | - findNext, | |
| 218 | - findPrev, | |
| 219 | - progress, | |
| 220 | -}; | |
| 1 | +const $ = window.jQuery || jQuery; | |
| 2 | + | |
| 3 | +const serializeJSON = function serializeJSON( path ) { | |
| 4 | + const isInput = $( this ).is( 'input' ) || $( this ).is( 'select' ) || $( this ).is( 'textarea' ); | |
| 5 | + let unIndexed = isInput ? $( this ).serializeArray() : $( this ).find( 'input, select, textarea' ).serializeArray(), | |
| 6 | + indexed = {}, | |
| 7 | + validate = /(\[([a-zA-Z0-9_-]+)?\]?)/g, | |
| 8 | + arrayKeys = {}, | |
| 9 | + end = false; | |
| 10 | + $.each( unIndexed, function() { | |
| 11 | + const that = this, | |
| 12 | + match = this.name.match( /^([0-9a-zA-Z_-]+)/ ); | |
| 13 | + if ( ! match ) { | |
| 14 | + return; | |
| 15 | + } | |
| 16 | + let keys = this.name.match( validate ), | |
| 17 | + objPath = "indexed['" + match[ 0 ] + "']"; | |
| 18 | + | |
| 19 | + if ( keys ) { | |
| 20 | + if ( typeof indexed[ match[ 0 ] ] != 'object' ) { | |
| 21 | + indexed[ match[ 0 ] ] = {}; | |
| 22 | + } | |
| 23 | + | |
| 24 | + $.each( keys, function( i, prop ) { | |
| 25 | + prop = prop.replace( /\]|\[/g, '' ); | |
| 26 | + let rawPath = objPath.replace( /'|\[|\]/g, '' ), | |
| 27 | + objExp = '', | |
| 28 | + preObjPath = objPath; | |
| 29 | + | |
| 30 | + if ( prop == '' ) { | |
| 31 | + if ( arrayKeys[ rawPath ] == undefined ) { | |
| 32 | + arrayKeys[ rawPath ] = 0; | |
| 33 | + } else { | |
| 34 | + arrayKeys[ rawPath ]++; | |
| 35 | + } | |
| 36 | + objPath += "['" + arrayKeys[ rawPath ] + "']"; | |
| 37 | + } else { | |
| 38 | + if ( ! isNaN( prop ) ) { | |
| 39 | + arrayKeys[ rawPath ] = prop; | |
| 40 | + } | |
| 41 | + objPath += "['" + prop + "']"; | |
| 42 | + } | |
| 43 | + try { | |
| 44 | + if ( i == keys.length - 1 ) { | |
| 45 | + objExp = objPath + '=that.value;'; | |
| 46 | + end = true; | |
| 47 | + } else { | |
| 48 | + objExp = objPath + '={}'; | |
| 49 | + end = false; | |
| 50 | + } | |
| 51 | + | |
| 52 | + const evalString = '' + | |
| 53 | + 'if( typeof ' + objPath + " == 'undefined'){" + objExp + ';' + | |
| 54 | + '}else{' + | |
| 55 | + 'if(end){' + | |
| 56 | + 'if(typeof ' + preObjPath + "!='object'){" + preObjPath + '={};}' + | |
| 57 | + objExp + | |
| 58 | + '}' + | |
| 59 | + '}'; | |
| 60 | + eval( evalString ); | |
| 61 | + } catch ( e ) { | |
| 62 | + console.log( 'Error:' + e + '\n' + objExp ); | |
| 63 | + } | |
| 64 | + } ); | |
| 65 | + } else { | |
| 66 | + indexed[ match[ 0 ] ] = this.value; | |
| 67 | + } | |
| 68 | + } ); | |
| 69 | + if ( path ) { | |
| 70 | + path = "['" + path.replace( '.', "']['" ) + "']"; | |
| 71 | + const c = 'try{indexed = indexed' + path + '}catch(ex){console.log(c, ex);}'; | |
| 72 | + eval( c ); | |
| 73 | + } | |
| 74 | + return indexed; | |
| 75 | +}; | |
| 76 | + | |
| 77 | +const LP_Tooltip = ( options ) => { | |
| 78 | + options = $.extend( {}, { offset: [ 0, 0 ] }, options || {} ); | |
| 79 | + | |
| 80 | + return $.each( this, function() { | |
| 81 | + const $el = $( this ), | |
| 82 | + content = $el.data( 'content' ); | |
| 83 | + | |
| 84 | + if ( ! content || ( $el.data( 'LP_Tooltip' ) !== undefined ) ) { | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + | |
| 88 | + let $tooltip = null; | |
| 89 | + | |
| 90 | + $el.on( 'mouseenter', function( e ) { | |
| 91 | + $tooltip = $( '<div class="learn-press-tooltip-bubble"/>' ).html( content ).appendTo( $( 'body' ) ).hide(); | |
| 92 | + const position = $el.offset(); | |
| 93 | + | |
| 94 | + if ( Array.isArray( options.offset ) ) { | |
| 95 | + const top = options.offset[ 1 ], | |
| 96 | + left = options.offset[ 0 ]; | |
| 97 | + | |
| 98 | + if ( $.isNumeric( left ) ) { | |
| 99 | + position.left += left; | |
| 100 | + } else { | |
| 101 | + | |
| 102 | + } | |
| 103 | + if ( $.isNumeric( top ) ) { | |
| 104 | + position.top += top; | |
| 105 | + } else { | |
| 106 | + | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + $tooltip.css( { | |
| 111 | + top: position.top, | |
| 112 | + left: position.left, | |
| 113 | + } ); | |
| 114 | + | |
| 115 | + $tooltip.fadeIn(); | |
| 116 | + } ); | |
| 117 | + | |
| 118 | + $el.on( 'mouseleave', function( e ) { | |
| 119 | + $tooltip && $tooltip.remove(); | |
| 120 | + } ); | |
| 121 | + | |
| 122 | + $el.data( 'tooltip', true ); | |
| 123 | + } ); | |
| 124 | +}; | |
| 125 | + | |
| 126 | +const hasEvent = function hasEvent( name ) { | |
| 127 | + const events = $( this ).data( 'events' ); | |
| 128 | + if ( typeof events.LP == 'undefined' ) { | |
| 129 | + return false; | |
| 130 | + } | |
| 131 | + for ( i = 0; i < events.LP.length; i++ ) { | |
| 132 | + if ( events.LP[ i ].namespace == name ) { | |
| 133 | + return true; | |
| 134 | + } | |
| 135 | + } | |
| 136 | + return false; | |
| 137 | +}; | |
| 138 | + | |
| 139 | +const dataToJSON = function dataToJSON() { | |
| 140 | + const json = {}; | |
| 141 | + $.each( this[ 0 ].attributes, function() { | |
| 142 | + const m = this.name.match( /^data-(.*)/ ); | |
| 143 | + if ( m ) { | |
| 144 | + json[ m[ 1 ] ] = this.value; | |
| 145 | + } | |
| 146 | + } ); | |
| 147 | + return json; | |
| 148 | +}; | |
| 149 | + | |
| 150 | +const rows = function rows() { | |
| 151 | + const h = $( this ).height(); | |
| 152 | + const lh = $( this ).css( 'line-height' ).replace( 'px', '' ); | |
| 153 | + $( this ).attr( { height: h, 'line-height': lh } ); | |
| 154 | + | |
| 155 | + return Math.floor( h / parseInt( lh ) ); | |
| 156 | +}; | |
| 157 | + | |
| 158 | +const checkLines = function checkLines( p ) { | |
| 159 | + return this.each( function() { | |
| 160 | + const $e = $( this ), | |
| 161 | + rows = $e.rows(); | |
| 162 | + | |
| 163 | + p.call( this, rows ); | |
| 164 | + } ); | |
| 165 | +}; | |
| 166 | + | |
| 167 | +const findNext = function findNext( selector ) { | |
| 168 | + const $selector = $( selector ), | |
| 169 | + $root = this.first(), | |
| 170 | + index = $selector.index( $root ), | |
| 171 | + $next = $selector.eq( index + 1 ); | |
| 172 | + return $next.length ? $next : false; | |
| 173 | +}; | |
| 174 | + | |
| 175 | +const findPrev = function findPrev( selector ) { | |
| 176 | + const $selector = $( selector ), | |
| 177 | + $root = this.first(), | |
| 178 | + index = $selector.index( $root ), | |
| 179 | + $prev = $selector.eq( index - 1 ); | |
| 180 | + return $prev.length ? $prev : false; | |
| 181 | +}; | |
| 182 | + | |
| 183 | +const progress = function progress( v ) { | |
| 184 | + return this.each( function() { | |
| 185 | + const t = parseInt( v / 100 * 360 ), | |
| 186 | + timer = null, | |
| 187 | + $this = $( this ); | |
| 188 | + | |
| 189 | + if ( t < 180 ) { | |
| 190 | + $this.find( '.progress-circle' ).removeClass( 'gt-50' ); | |
| 191 | + } else { | |
| 192 | + $this.find( '.progress-circle' ).addClass( 'gt-50' ); | |
| 193 | + } | |
| 194 | + $this.find( '.fill' ).css( { | |
| 195 | + transform: 'rotate(' + t + 'deg)', | |
| 196 | + } ); | |
| 197 | + } ); | |
| 198 | +}; | |
| 199 | + | |
| 200 | +$.fn.serializeJSON = serializeJSON; | |
| 201 | +$.fn.LP_Tooltip = LP_Tooltip; | |
| 202 | +$.fn.hasEvent = hasEvent; | |
| 203 | +$.fn.dataToJSON = dataToJSON; | |
| 204 | +$.fn.rows = rows; | |
| 205 | +$.fn.checkLines = checkLines; | |
| 206 | +$.fn.findNext = findNext; | |
| 207 | +$.fn.findPrev = findPrev; | |
| 208 | +$.fn.progress = progress; | |
| 209 | + | |
| 210 | +export default { | |
| 211 | + serializeJSON, | |
| 212 | + LP_Tooltip, | |
| 213 | + hasEvent, | |
| 214 | + dataToJSON, | |
| 215 | + rows, | |
| 216 | + checkLines, | |
| 217 | + findNext, | |
| 218 | + findPrev, | |
| 219 | + progress, | |
| 220 | +}; | |