مساحة عمل بحجم ثابت
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إن أبسط طريقة لوضع Blockly في صفحة ويب هي إدخالها في
علامة 'div' فارغة.
1. الحصول على الشفرة
احصل على الرمز بأي طريقة
تناسب تطبيقك بشكل أفضل.
2. تحديد المنطقة
إضافة علامة div فارغة في مكان ما ضمن نص الصفحة وتعيين حجمها:
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
3- إدخال مساحة العمل
تحديد بنية صندوق الأدوات:
const toolbox = {
"kind": "flyoutToolbox",
"contents": [
{
"kind": "block",
"type": "controls_if"
},
{
"kind": "block",
"type": "controls_repeat_ext"
},
{
"kind": "block",
"type": "logic_compare"
},
{
"kind": "block",
"type": "math_number"
},
{
"kind": "block",
"type": "math_arithmetic"
},
{
"kind": "block",
"type": "text"
},
{
"kind": "block",
"type": "text_print"
},
]
}
وأخيرًا، يمكنك استدعاء ما يلي لإدخال Blockly في قسم div المحدّد.
const workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
متغيّر workspace
غير مستخدَم حاليًا، ولكنّه سيصبح مهمًا لاحقًا لحفظ الكتل أو إنشاء رمز برمجي.
إذا تم إدراج أكثر من مثيل واحد من Blockly في الصفحة نفسها، تأكَّد
من تخزين كل مساحة عمل معروضة في متغيّر مختلف.
يمكنك الآن اختبار الصفحة في متصفّح. من المفترض أن يظهر لك محرِّر Blockly يملأ div،
مع سبعة وحدات في صندوق الأدوات.
في ما يلي عرض توضيحي مباشر.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-05-23 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-05-23 (حسب التوقيت العالمي المتفَّق عليه)"],[[["Blockly can be easily embedded into a webpage by injecting it into an empty 'div' tag."],["The process involves getting the Blockly code, defining a 'div' element for the workspace, and injecting Blockly with a specified toolbox."],["A workspace variable is returned, which will be important for interacting with the Blockly instance later."]]],["To add Blockly to a webpage, first, obtain the necessary code. Next, create an empty `div` element in the page's body and set its dimensions (e.g., `id=\"blocklyDiv\"`, `height: 480px`, `width: 600px`). Define the toolbox structure using JSON format, specifying the block types. Finally, use `Blockly.inject('blocklyDiv', {toolbox: toolbox})` to insert Blockly into the `div`, storing the result in a `workspace` variable for later use in saving blocks or code generation.\n"]]