Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Don't require placeholder to be an image #34

Open
jonom opened this issue May 8, 2016 · 4 comments
Open

Feature request: Don't require placeholder to be an image #34

jonom opened this issue May 8, 2016 · 4 comments

Comments

@jonom
Copy link
Contributor

jonom commented May 8, 2016

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.

@sheadawson
Copy link
Owner

sheadawson commented May 8, 2016

@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.

@jonom
Copy link
Contributor Author

jonom commented May 8, 2016

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!

@sheadawson
Copy link
Owner

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
#34 (comment)

Shea Dawson
Web Developer
LiveSource

mobile +64 20 4028 5647
skype squatchnz
email shea@livesource.co.nz
*web *www.livesource.co.nz

@jonom
Copy link
Contributor Author

jonom commented May 8, 2016

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants