Open jonom opened 8 years ago
@jonom I completely agree. When I was reviewing and tweaking #32 I had a go... and failed. The trouble happens around here https://github.com/sheadawson/silverstripe-shortcodable/blob/master/javascript/editor_plugin.js#L61. Here we are using a regex string.repalce callback on the editor content to update shortcode tags to img tags. If we want to change that to shortcode tags to div tags with html contents loaded from a url, we have to use an ajax request to get the html... But because the ajax request is asynchronous, the callback function returns before the ajax request completes.
This is what my attempt looked like.
http://codepen.io/sheadawson/pen/ONdzRZ
I think actually using images is not as lame as I initially thought. The example you mention displaying a phone number from SiteConfig can be achieved by setting the phone number as the text in the placeholder image. See this example https://gist.github.com/sheadawson/12c5e5a2b42272bd90f703941450d677#file-imagegallery-php-L64 I also like how it keeps things simple and clean in the editor. Implementation is fast and reasonably flexible.
That said, if you or anyone else can think of a way to make this work, that would be awesome.
Ah, that makes sense. Could you do it as a two-part thing maybe where _replaceShortcodesWithPlaceholders()
is only expected to initiate the conversion process, and the content is only updated gradually as request(s) come back?
Within _replaceShortcodesWithPlaceholders()
, for each shortcode that needs updating you could add a temporary unique identifier to the shortcode markup, and initiate an ajax request to fetch the placeholder. The done
method for that request could then do a find-and-replace on the content, identifying the single shortcode it needs to replace by it's temporary ID.
Don't know if it's actually feasible or not :)
Thanks for the tip on adding text to the placeholder image - didn't realise you could do that!
Cheers for the suggestion. That could potentially work. I'll have to park it for now until I have more time. I think I need to just block out a week or two to invest in modules dev. Wouldn't that be awesome :D
On 9 May 2016 at 10:25, Jono Menz notifications@github.com wrote:
Ah, that makes sense. Could you do it as a two-part thing maybe where _replaceShortcodesWithPlaceholders() is only expected to initiate the conversion process, and the content is only updated gradually as request(s) come back?
Within _replaceShortcodesWithPlaceholders(), for each shortcode that needs updating you could add a temporary unique identifier to the shortcode markup, and initiate an ajax request to fetch the placeholder. The done http://api.jquery.com/deferred.done/ method for that request could then do a find-and-replace on the content, identifying the single shortcode it needs to replace by it's temporary ID.
Don't know if it's actually feasible or not :)
Thanks for the tip on adding text to the placeholder image - didn't realise you could do that!
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/sheadawson/silverstripe-shortcodable/issues/34#issuecomment-217749960
Shea Dawson Web Developer LiveSource
mobile +64 20 4028 5647 skype squatchnz email shea@livesource.co.nz web www.livesource.co.nz
I think I need to just block out a week or two to invest in modules dev. Wouldn't that be awesome
Ha, sure would!
The new ability to add a placeholder is great! Think it would be even better if it didn't have to be an image.
Currently
getShortcodePlaceHolder()
must return the URL to an image, but if it could return arbitrary HTML instead it would be much more flexible. I'm not sure how easy it would be to support this in TinyMCE but if there was a wrapper element involved maybe it could be accomplished?For simple shortcodes like reusable text tokens (e.g. displaying a phone number from SiteConfig) this would let you show the actual content, perhaps with a slightly different treatment to show it's a shortcode.