I have j/s in my theme (am I infamous yet? ;) which is modifying the DOM by adding elements via api.decorateCooked(…. It inserts a variety HTML head elements.
I also have the DiscoTOC Theme component installed.
However, adding the usual <div data-theme-toc="true"> </div> that DiscoTOC notices and expands, doesn’t generate a table-of-contents including my dynamically inserted elements.
I’m figuring this might be as simple as execution order… if DiscoTOC looks before my j/s adds more elements . . .
What determines the ordering of execution if multiple bits of theme j/s code are calling api.cooked(?
I’m inserting within the post, yes. That’s why I suspect execution order.
Some bit of code determines the execution order… that’s the leverage point for me to get my component before TOC. eg, if it’s alpha by component name (ie, as displayed in the Component list in Admin area) then I can try namin my component accordingly, etc
That said, you can set initializer order for advanced use cases. I can put DiscoTOC in a named initializer so you can run your code before DiscoTOC, but I need to know what you’re trying to do first to give you a clear answer.
Your modifications here are based on an HTTP/AJAX request, correct?
Yes AJAX, but using a synchronous call. (I’ve always loved the oxymoron of synchronous AJAX :^)
I’m feeling like my next step is create a proper component—atm, it’s just some j/s pasted into my Theme’s Header. Then I can try fiddling with a judiciously chosen ID. “_foo” or “0-foo” might be all I need.
تشير الردود من الآخرين أعلاه إلى أن اسم المكون لا يؤثر على ترتيب التنفيذ. لقد أعدت تسميتها للتو إلى aa-mycomponent و x-last-DiscoTOC ولم ينجح ذلك. [DiscoTOC لا يتضمن العناوين المضافة إلى DOM ديناميكيًا - نعم، داخل نص المنشور]
همممم… ربما الخطأ أكثر من مجرد ترتيب. لقد قمت للتو بفحص… والأشياء الموجودة في DOM والتي كنت أعتقد أنها عناوين HTML… هي في الواقع علامات DIV مع class="d-toc-ignore"
حان الوقت لأتعمق أكثر. أين ذهبت العناوين الخاصة بي؟
حسنًا، أعتقد أنه يمكنك إثبات ذلك بأي من الطريقتين من خلال تجربة مثال بسيط جدًا.
قم بإنشاء مكونين بسيطين، مع تجاوز أو ربط نفس الشيء، ربما قالب بسيط مع اختلاف طفيف، قم بتسمية أحدهما باسم يبدأ لاحقًا في الأبجدية، لاحظ أيهما ينتهي بتجاوز السمة.
من الواضح جدًا أنه مرتب حسب الاسم في الكود هنا في النموذج:
لا يؤثر الاسم على ترتيب التنفيذ. @merefield يؤثر السطر الذي ربطته على كيفية عرضها في واجهة المستخدم الإدارية، ولكنه لا يُستخدم للتنفيذ الفعلي.
هذا هو السطر ذي الصلة لترتيب التنفيذ:
لذلك يتم تنفيذها بترتيب تصاعدي لـ “id” في قاعدة البيانات.
الضمان الوحيد الذي يمكن نقله عبر مثيلات Discourse هو أن كود theme يتم تنفيذه دائمًا قبل كود theme component.
كما ذكر @Johani أعلاه، إذا كنت بحاجة إلى تشغيل الكود بعد تحميل مكون آخر، فإن أفضل رهان هو على الأرجح استخدام تهيئة Ember، والتي تدعم الترتيب. للأسف، لن يكون ذلك ممكنًا على الفور في هذه الحالة، نظرًا لأنه لا يبدو أن DiscoTOC يستخدم تهيئات Ember. سيؤدي تحديث DiscoTOC لاستخدام JavaScript متعدد الملفات (وبالتالي تهيئات Ember) بالتأكيد إلى الترحيب بـ pr-welcome.