@@ -115,7 +115,9 @@ export function createOc(oc) {
115115 } ;
116116
117117 oc . addStylesToHead = ( styles ) => {
118- $ ( "<style>" + styles + "</style>" ) . appendTo ( $document . head ) ;
118+ const style = document . createElement ( "style" ) ;
119+ style . textContent = styles ;
120+ document . head . appendChild ( style ) ;
119121 } ;
120122
121123 const loadAfterReady = ( ) => {
@@ -186,29 +188,28 @@ export function createOc(oc) {
186188
187189 oc . requireSeries = asyncRequireForEach ;
188190
189- const processHtml = ( $ component, data , callback ) => {
190- const attr = $ component. attr . bind ( $ component) ;
191+ const processHtml = ( component , data , callback ) => {
192+ const setAttribute = component . setAttribute . bind ( component ) ;
191193 const dataName = data . name ;
192194 const dataVersion = data . version ;
193- attr ( "id" , data . id ) ;
194- attr ( dataRenderedAttribute , true ) ;
195- attr ( dataRenderingAttribute , false ) ;
196- attr ( "data-version" , dataVersion ) ;
197- attr ( "data-id" , data . ocId ) ;
198- $ component. html ( data . html ) ;
195+ setAttribute ( "id" , data . id ) ;
196+ setAttribute ( dataRenderedAttribute , true ) ;
197+ setAttribute ( dataRenderingAttribute , false ) ;
198+ setAttribute ( "data-version" , dataVersion ) ;
199+ setAttribute ( "data-id" , data . ocId ) ;
200+ component . innerHTML = data . html ;
199201
200202 if ( data . key ) {
201- attr ( "data-hash" , data . key ) ;
203+ setAttribute ( "data-hash" , data . key ) ;
202204 }
203205
204206 if ( dataName ) {
205- attr ( "data-name" , dataName ) ;
207+ setAttribute ( "data-name" , dataName ) ;
206208 renderedComponents [ dataName ] = { version : dataVersion } ;
207209 if ( data . baseUrl ) {
208210 renderedComponents [ dataName ] . baseUrl = data . baseUrl ;
209211 }
210- // Get raw element from jQuery object
211- data . element = $component [ 0 ] ;
212+ data . element = component ;
212213 oc . events . fire ( "oc:rendered" , data ) ;
213214 }
214215
@@ -431,39 +432,44 @@ export function createOc(oc) {
431432
432433 oc . renderNestedComponent = ( component , callback ) => {
433434 oc . ready ( ( ) => {
434- const $component = $ ( component ) ;
435- const attr = $component . attr . bind ( $component ) ;
436- const dataRendering = attr ( dataRenderingAttribute ) ;
437- const dataRendered = attr ( dataRenderedAttribute ) ;
435+ // If the component is a jQuery object, we need to get the first element
436+ component = component [ 0 ] || component ;
437+ const getAttribute = component . getAttribute . bind ( component ) ;
438+ const setAttribute = component . setAttribute . bind ( component ) ;
439+ const dataRendering = getAttribute ( dataRenderingAttribute ) ;
440+ const dataRendered = getAttribute ( dataRenderedAttribute ) ;
438441 const isRendering = dataRendering == "true" ;
439442 const isRendered = dataRendered == "true" ;
440443
441444 if ( ! isRendering && ! isRendered ) {
442445 logInfo ( MESSAGES_RETRIEVING ) ;
443- attr ( dataRenderingAttribute , true ) ;
446+ setAttribute ( dataRenderingAttribute , true ) ;
444447 if ( ! DISABLE_LOADER ) {
445- $component . html (
446- '<div class="oc-loading">' + MESSAGES_LOADING_COMPONENT + "</div>" ,
447- ) ;
448+ component . innerHTML =
449+ '<div class="oc-loading">' + MESSAGES_LOADING_COMPONENT + "</div>" ;
448450 }
449451
450452 oc . renderByHref (
451- { href : attr ( "href" ) , id : attr ( "id" ) , element : $component [ 0 ] } ,
453+ {
454+ href : getAttribute ( "href" ) ,
455+ id : getAttribute ( "id" ) ,
456+ element : component ,
457+ } ,
452458 ( err , data ) => {
453459 if ( err || ! data ) {
454- attr ( dataRenderingAttribute , false ) ;
455- attr ( dataRenderedAttribute , false ) ;
456- attr ( "data-failed" , true ) ;
457- $ component. html ( "" ) ;
460+ setAttribute ( dataRenderingAttribute , false ) ;
461+ setAttribute ( dataRenderedAttribute , false ) ;
462+ setAttribute ( "data-failed" , true ) ;
463+ component . innerHTML = "" ;
458464 oc . events . fire ( "oc:failed" , {
459465 originalError : err ,
460466 data : data ,
461- component : $component [ 0 ] ,
467+ component,
462468 } ) ;
463469 logError ( err ) ;
464470 callback ( ) ;
465471 } else {
466- processHtml ( $ component, data , callback ) ;
472+ processHtml ( component , data , callback ) ;
467473 }
468474 } ,
469475 ) ;
@@ -568,8 +574,9 @@ export function createOc(oc) {
568574 callback = callback || noop ;
569575
570576 if ( placeholder ) {
571- $ ( placeholder ) . html ( "<" + OC_TAG + ' href="' + href + '" />' ) ;
572- const newComponent = $ ( OC_TAG , placeholder ) ;
577+ placeholder = placeholder [ 0 ] || placeholder ;
578+ placeholder . innerHTML = "<" + OC_TAG + ' href="' + href + '" />' ;
579+ const newComponent = placeholder . querySelector ( OC_TAG ) ;
573580 oc . renderNestedComponent ( newComponent , ( ) => {
574581 callback ( newComponent ) ;
575582 } ) ;
0 commit comments