I am trying to find the name values of all input elements of type="hidden" when in WYSIWIG mode. This has been fairly straightforward.
First, I find all image elements by the following:
Then, I loop through all elements from above and search for a '_cke_real_element_type' attribute
Then for each element found above, I use the static CKEDITOR.htmlParser.fragment.fromHtml method to create a fragment
Finally, I extract the value of the fragment's name attribute
My question is the following, is there an easier way of accomplishing this? Also, is there a CKEDITOR built-in function that would allow me to do the following:
If the built-in function does exists, does it return null (like the native node.getAttribute) if the attribute being queried does not exist.
Thanks!
P.S
I tried my best to oversimplify the code examples above. I may have made an error somewhere since I removed all of my "custom" helper functions but the overall logic is correct.
First, I find all image elements by the following:
CKEDITOR.instances['InstanceName'].document.$.getElementsByTagName('img')I could have searched by classNames of 'cke_hidden', but I know that some older browsers don't natively support getElementsByClassName and a patched function would be slower than the widely supported getElementsByTagName.
Then, I loop through all elements from above and search for a '_cke_real_element_type' attribute
element.getAttribute('_cke_real_element_type') === 'hiddenfield'
Then for each element found above, I use the static CKEDITOR.htmlParser.fragment.fromHtml method to create a fragment
fragment = CKEDITOR.htmlParser.fragment.fromHtml(decodeURIComponent( element.getAttribute('_cke_realelement')))
Finally, I extract the value of the fragment's name attribute
fragment.children[0].attributes.name
My question is the following, is there an easier way of accomplishing this? Also, is there a CKEDITOR built-in function that would allow me to do the following:
fragment.getAttribute('name')
If the built-in function does exists, does it return null (like the native node.getAttribute) if the attribute being queried does not exist.
Thanks!
P.S
I tried my best to oversimplify the code examples above. I may have made an error somewhere since I removed all of my "custom" helper functions but the overall logic is correct.
Re: Is there a fakeElement.getAttribute() method?
Sorry to say there's no neat way to achieve that, internally we use a lightweight presentation of DOM instead of real elements, you can check the documentation here.