الإضافات

من ATbar Wiki
اذهب إلى: تصفح, بحث

محتويات

عن الإضافات

الإضافات هي الوسيلة الأكثر فاعلية و قابلية لإعادة الاستخدام لحزم الوظائف لغرض الاستخدام في AtKit. الإضافات يمكن تستعمل أي وظيفة من AtKit (إلق نظرة علي وثائق الإستخدام), و غالبا ما تحتوي على زر أو أكثر من ازرار شريط الأدوات, بالإضافة للترجمة و غيرها من الوظائف.

مثال عن الملحق الإضافي

فيما يلي مثال على استخدام ملحق إضافي لAtKit لتشغيل الإضافة الخاصة بالمقروئية.

(function(){

	var pluginName = "readability";
	var plugin = function(){

		// Plugin code goes here

		AtKit.addButton(
			"readability", 
			"Start Readability",
			"readability.png",
			function(dialogs, functions){
				window.readabilityToken="";
				AtKit.addScript(document.location.protocol + "//www.readability.com/bookmarklet/read.js");
			}
		);

	}

 	if(typeof window['AtKit'] == "undefined"){
 
 		window.AtKitLoaded = function(){
 			var eventAction = null;
 		
			this.subscribe = function(fn) {
				eventAction = fn;
			};
		
			this.fire = function(sender, eventArgs) {
				if (eventAction != null) {
					eventAction(sender, eventArgs);
				}
			};
		}

		window['AtKitLoaded'] = new AtKitLoaded();
		window['AtKitLoaded'].subscribe(function(){ AtKit.registerPlugin(pluginName, plugin); });
	} else {
		AtKit.registerPlugin(pluginName, plugin);
	}

})();

المكونات الأساسية للملحق المساعد

يمكن الإطلاع على النموذج المستخدم في الملحق المساعد في أسفل هذه الصفحة.القيمة المخزنة في المتغير pluginName هو اسم البرنامج المساعد في AtKit.و هذه القيمة يجب أن تكون فريدة من نوعها.

كافة التعليمات البرمجية موجودة ضمن الداله المخصصة للملحقات.

var plugin = function(){

}

بقية الكود-التعليمات البرمجية-في المتداول لتحميل الملحق إلى AtKit - من الأفضل عدم لمس هذا الكود.

تحميل الملحق

إذا كنت ترغب في استخدام الإضافات في شريط الأدوات,يجب ان تضع الكود المصدري لشريط الأدوات داخل دالة مخصصة و ترسلها إلى:AtKit.importPlugins().وقد أُعطي مثالاً أدناه.


	(function (window, AtKit) { 

		$ = AtKit.lib();
		
		var settings = {
			'baseURL': 'http://c.atbar.org/ATBar/',
			'version': '2.0.070d'
		};
		
		var onLoad = function(){
		
			// Set our logo
			AtKit.setLogo(settings.baseURL + "images/atbar.png");
			AtKit.setName("ATBar");
			// Set language to Arabic
			AtKit.setLanguage("ar");
			
			AtKit.setAbout("Version " + settings.version);
			
			// Add all the plugins to the toolbar
			AtKit.addPlugin("ftw");	
			AtKit.addPlugin("resize");
			AtKit.addPlugin("fonts");	
			AtKit.addPlugin("spell");
			AtKit.addPlugin("dictionary");
			AtKit.addPlugin("gtts");
			AtKit.addPlugin("css");

			AtKit.addResetFn('reset-saved', function(){
				AtKit.clearStorage();
			});
		
			// Run
			AtKit.render();
		};
		
		
		AtKit.importPlugins(["ftw", "resize", "fonts", "spell", "dictionary", "gtts", "css"], onLoad);
		
		
	}(window, AtKit));

في هذا المثال وضعنا كود التحميل الخاص بشريط الأدوات في داله مخصصة لـ onLoad. يتم تمرير هذا إلى importPlugins كمتغير ثاني داخل الدالة للإستدعاء لتشغيل الملحقات( يتم تحديدها كمصفوفة من المتغيرات 1)عندما يتم تحميله. عندما يتم تحميل الملحقات فإنه من الممكن إضافته بالترتيب لشريط الأدوات باستخدام الدالهaddPlugin.

لاحظ أن هذا المثال عن شريط الأدوات لايحتوي على التعليمات البرمجية للإقلاع. ارجع إلى شريط الأدوات للحصول على مثال كامل.

ملحق فارغ

(function(){

	var pluginName = "readability";
	var plugin = function(){

		// Plugin code goes here

	}

 	if(typeof window['AtKit'] == "undefined"){
 
 		window.AtKitLoaded = function(){
 			var eventAction = null;
 		
			this.subscribe = function(fn) {
				eventAction = fn;
			};
		
			this.fire = function(sender, eventArgs) {
				if (eventAction != null) {
					eventAction(sender, eventArgs);
				}
			};
		}

		window['AtKitLoaded'] = new AtKitLoaded();
		window['AtKitLoaded'].subscribe(function(){ AtKit.registerPlugin(pluginName, plugin); });
	} else {
		AtKit.registerPlugin(pluginName, plugin);
	}

})();
أدوات شخصية

المتغيرات
النطاقات
أفعال
إبحار
Languages
صندوق الأدوات