Git Product home page Git Product logo

Comments (4)

aniket-magadum avatar aniket-magadum commented on August 20, 2024

Is anyone working on this?

from octobertricks.com.

tobias-kuendig avatar tobias-kuendig commented on August 20, 2024

I am not.

This could be impemented as a first version using the Responsiv.Uploader plugin. This won't allow screenshots in the content itself but they could be displayed above or below the content.

from octobertricks.com.

LarryBarker avatar LarryBarker commented on August 20, 2024

Would be great to figure out copy/paste behavior right in the editor, like github. I'll do some looking into it!

UPDATE So a quick search revealed how to capture images from the clipboard with Javascript. There's also talk on Ghost forums about how to handle this.

  1. What format would be best? blob vs base64?
  2. Setup events to capture the clipboard content
  3. Need to check that it is actually an image?
  4. Use AJAX to send the data to the backend (POST /tricks/upload/policies)
  5. Place to store the images?
  6. Handler to inject the MD for displaying the stored image

from octobertricks.com.

SamBrishes avatar SamBrishes commented on August 20, 2024

Hello there.

I know, this topic is a bit older... but... anyways...

EasyMDE already provides the possibility to upload images since version 2.8.0 (released in 2019). However, I created a quick prototype how it could work and came along with the following solution (The component method, shown below, still misses some validation stuff like filesize, mimetype and so on).

The EasyMDE related JavaScript code (I updated EasyMDE to the latest version)

var easyMDE = new EasyMDE({
    showIcons: ['strikethrough', 'code', 'upload-image'],
    hideIcons: [],
    element: document.querySelector('#trick_content'),
    toolbar: [
        "bold", "italic", "strikethrough", "heading", "|", 
        "code", "quote", "unordered-list", "ordered-list","|", 
        "link", "image", "upload-image","|", 
        "preview", "side-by-side", "fullscreen","|", 
        "guide"
    ],
    uploadImage: true,
    imageUploadFunction: (file, resolve, reject) => {
        jQuery(this).request('onUploadImage', {
            data: {
                'image': file
            },
            files: true,
            success: function (data) {
                if (typeof data === 'object' && (data.status || '') === 'success') {
                    resolve(data.path);
                } else {
                    reject('An unknown error occured');
                }
            },
            error: function () {
                let message = (this.responseJSON || {}).result || 'An unknown error occured';
                reject(message);
            }
        });
    },
    renderingConfig: {
        singleLineBreaks: false,
        codeSyntaxHighlighting: true,
    },
});

The required method on the TrickForm component:

public function onUploadImage()
{
    if (!Input::hasFile('image')) {
        throw new AjaxException('The passed form is invalid.');
    }

    try {
        $file = new File();
        $file->fromPost(request()->file('image'));
        $file->save();
        return ['status' => 'success', 'path' => $file->getPath()];
    } catch (\Exception $e) {
        throw new AjaxException($e->getMessage());
    }
}

Anyways, one issue stays: What happens when the user aborts the Trick creation, after uploading x pictures? I've two solution for this scenario.

  1. Each file is referenced via the system_files db. Theoretically, we could clean unused images by checking the field or attachment_id / attachment_type columns and remove them respectively. This can either happen manually via the backend or using a cronjob.

  2. Alternatively, we "skip" the upload path on the EasyMDE function and handle them after the user submits the Trick itself. This should be possible with some JavaScript magic and a simple replacement on the backend side. However, this COULD be a horrible user experience when the user uploads huge or many images (which both could be restricted, of course).

Anyways. Would do you think?

~Sam.

from octobertricks.com.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.