Simple Block Based Editor for Opencart

Estimated reading time: 469 words, 3-4 minutes Font: 1,511 Views

Challenges with Third-Party Editors

OpenCart has always used third-party editors. Perhaps due to their complexity, updates can be quite challenging. If there are new updates to the third-party library, it can affect the operation of OpenCart, which is why I wanted to replace this editor.

Exploring a Simpler Solution

A block-based editor is simpler, so I tried Editor.js. It is quite a good editor to use, but the third-party still cannot meet the update needs of OpenCart. Additionally, the third-party loads many unnecessary features, which increases loading time. Therefore, I spent a week writing a simple block-based editor.

Reducing Dependency on Third-Party Libraries

Since this is for internal admin use, security is not a priority. The main goal is to remove third-party code, as OpenCart relies too much on third parties. Besides the editor, there are also jQuery, Bootstrap, and Twig. I hope OpenCart can avoid relying too much on third-party libraries in the future. However, removing jQuery also took a week, but fortunately, with the help of artificial intelligence, I was finally able to remove it all and use native ECMAScript (JavaScript).

Features of the New Editor

Block based Editor Opencart in Desktop
Screenshot on Opencart Block Based Editor

This simple editor outputs standard and clean HTML code, and general document styles can be modified. It can be used in full screen. The original OpenCart hid the textarea, but I changed it to be visible for user convenience. All HTML tags are displayed at the top of the blocks, allowing users to know which HTML tags are being used.

Draft Storage Functionality

This simple editor also includes draft storage; when users click to create HTML code, it will be saved in local storage. Initially, I wanted to save automatically at intervals, but that would burden the user’s device memory. When users reopen the editor, it will prompt them with saved drafts, allowing them to click to restore or clear the draft.

Customizable Blocks for Flexibility

All blocks in this editor can be removed or added, and they can be moved up and down. The editor is divided into three blocks: General, Image, and Table. Each block has different options; for example, the General block can convert to other HTML tags, h tags, or list tags. The Image block allows users to upload images and remove or change captions. The Table block can remove or add new rows and columns.

Block Based Editor View in Mobile
Screenshot of Block Based Editor in Mobile

Simplicity and Maintenance Focus

This editor uses native ECMAScript and CSS, with no third-party code. Since this editor is used internally in OpenCart, it does not need powerful or complex features. The main goal is to make maintenance and updates easier. Here, everyone can take a look at the effects of this editor.

Found this article helpful? Why not share it on social media and help someone else too?
Twitter (Open in new window) FaceBook (Open in new window)
Posted in categories of HTML5 This page was last modified on
Return to all HTML5 articles

Join the conversation and leave a comment with your perspective.

By creating an account, you agree to our Terms of Service and Private Policy.

Comment Policy