| 1 |
( function( $ ) { |
| 2 |
window.FIB = { |
| 3 |
|
| 4 |
getSelectedText: function getSelectedText() { |
| 5 |
let html = ''; |
| 6 |
if ( typeof window.getSelection !== 'undefined' ) { |
| 7 |
const sel = window.getSelection(); |
| 8 |
if ( sel.rangeCount ) { |
| 9 |
const container = document.createElement( 'div' ); |
| 10 |
for ( let i = 0, len = sel.rangeCount; i < len; ++i ) { |
| 11 |
container.appendChild( sel.getRangeAt( i ).cloneContents() ); |
| 12 |
} |
| 13 |
html = container.innerHTML; |
| 14 |
} |
| 15 |
} else if ( typeof document.selection !== 'undefined' ) { |
| 16 |
if ( document.selection.type === 'Text' ) { |
| 17 |
html = document.selection.createRange().htmlText; |
| 18 |
} |
| 19 |
} |
| 20 |
return html; |
| 21 |
}, |
| 22 |
|
| 23 |
createTextNode( content ) { |
| 24 |
return document.createTextNode( content ); |
| 25 |
}, |
| 26 |
|
| 27 |
isContainHtml: function isContainHtml( content ) { |
| 28 |
const $el = $( content ), |
| 29 |
sel = 'b.fib-blank'; |
| 30 |
return $el.is( sel ) || $el.find( sel ).length || $el.parent().is( sel ); |
| 31 |
}, |
| 32 |
|
| 33 |
getSelectionRange: function getSelectionRange() { |
| 34 |
let t = ''; |
| 35 |
if ( window.getSelection ) { |
| 36 |
t = window.getSelection(); |
| 37 |
} else if ( document.getSelection ) { |
| 38 |
t = document.getSelection(); |
| 39 |
} else if ( document.selection ) { |
| 40 |
t = document.selection.createRange().text; |
| 41 |
} |
| 42 |
return t; |
| 43 |
}, |
| 44 |
|
| 45 |
outerHTML( $dom ) { |
| 46 |
return $( '<div>' ).append( $( $dom ).clone() ).html(); |
| 47 |
}, |
| 48 |
|
| 49 |
doUpgrade( callback ) { |
| 50 |
$.ajax( { |
| 51 |
url: '', |
| 52 |
data: { |
| 53 |
'lp-ajax': 'fib-upgrade', |
| 54 |
}, |
| 55 |
success( res ) { |
| 56 |
console.log( res ); |
| 57 |
callback && callback.call( res ); |
| 58 |
}, |
| 59 |
} ); |
| 60 |
}, |
| 61 |
}; |
| 62 |
|
| 63 |
$( document ).ready( function() { |
| 64 |
$( '#do-upgrade-fib' ).on( 'click', function() { |
| 65 |
const $button = $( this ).prop( 'disabled', true ).addClass( 'ajaxloading' ); |
| 66 |
FIB.doUpgrade( function() { |
| 67 |
$button.prop( 'disabled', false ).removeClass( 'ajaxloading' ); |
| 68 |
} ); |
| 69 |
} ); |
| 70 |
} ); |
| 71 |
}( jQuery ) ); |
| 72 |
|