SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
.




.




             Write a Google Closure
                  Editor Plugin
                            @yinhm

                         December 19, 2010




    .                                 .
    @yinhm         Google Closure Plugin     1/27
.




             Before we start
.




             • Closure is a JavaScript library
             • Developed by google, released under Apache license
             • The JavaScript library behind Google’s web apps




    .                                              .
    @yinhm                      Google Closure Plugin               2/27
.




             Hello world: Step 1
.




             goog.require('goog.dom');

             function sayHi() {
               var newHeader = goog.dom.createDom('h1',
                            {'style': 'background-color:#EEE'},
                 'Hello world!');
               goog.dom.appendChild(document.body, newHeader);
             }



    .                                           .
    @yinhm                   Google Closure Plugin                3/27
.




             Hello world: Step 2
.




             <html>
               <head>
                <script src="closure-library/closure/goog/base.js">
                 </script>
                 <script src="hello.js"></script>
               </head>
               <body onload="sayHi()">
               </body>
             </html>


    .                                           .
    @yinhm                   Google Closure Plugin              4/27
.




             Hello world: How does it work?
.




             • bootstrap file base.js
             • import module: goog.require(’goog.dom’)




    .                                             .
    @yinhm                     Google Closure Plugin     5/27
.




             Modules
.




             • DOM, Dojo query(third party)
             • UI: Autocomplete, dialog, date picker, Tab...
             • AJAX: xhrio, iframeio...
             • Rich-text editor




    .                                                .
    @yinhm                        Google Closure Plugin        6/27
.




             object-oriented programming
.




             • Class-based programming(as opposed to prototype-based)
             • Namespace
             • Inheritance




    .                                            .
    @yinhm                    Google Closure Plugin                     7/27
.




             Example of a Class
.



             /** no JSDoc **/
             goog.provide('example.Animal'}

             example.Animal = function(first_name) {
               this.name_ = name;
             };

             example.Animal.prototype.first_name = '';

             example.Animal.prototype.getName = function() {
               return this.name_;
             };
    .                                           .
    @yinhm                   Google Closure Plugin             8/27
.




             Static methods
.




             defined on Class constructor function but not it’s prototype

             example.Animal.equil = function(a1, a2) {
               return a1.name == a2.name;
             };




    .                                               .
    @yinhm                       Google Closure Plugin                     9/27
.




             Inheritance
.


             goog.privode('example.Bird');

             goog.require('example.Animal');

             example.Bird = function() {
               // call to the superclass’s constructor function
               goog.base(this, 'bird');
             };
             goog.inherits(example.Bird, example.Animal); // prototyp

             example.Bird.prototype.fly = function() {
               return true;
             };
    .                                           .
    @yinhm                   Google Closure Plugin              10/27
.




             Inheritance of ui.Dialog
.




    .                                     .
    @yinhm             Google Closure Plugin   11/27
.




             goog.Disposable
.




             • dispose
             • disposeInternal




    .                                               .
    @yinhm                       Google Closure Plugin   12/27
.




             goog.events.EventTarget
.




             • addEventListener
             • removeEventListener
             • dispatchEvent




    .                                             .
    @yinhm                     Google Closure Plugin   13/27
.




             goog.ui.Component
.


             Life Cycle Stage (or Purpose)
               • constructor Component instance creation
               • createDom() Component DOM structure building
               • decorateInternal() (optional)
               • enterDocument() Post DOM-building initialization (such
                  as attaching event listeners)
               • exitDocument() Post DOM-removal cleanup (such as
                  detaching event listeners)
               • dispose() Component disposal
               • canDecorate() Indicates whether the component can use
                  a pre-existing element
    .                                              .
    @yinhm                      Google Closure Plugin                     14/27
.




             A UI Component Example
.




             An Introduction to Components




    .                                             .
    @yinhm                     Google Closure Plugin   15/27
.




             Rich Text Editor
.




             • Known as Trog Editor
             • Used in previous verion of Google Docs
             • Used in Gmail
             • Google not releasing all plugins(yet), eg: Image




    .                                             .
    @yinhm                     Google Closure Plugin              16/27
.




             Rich Text Editor: high-level
.

             design


             • Using build-in browser features: contentEditable,
               execCommand
             • More than that: cross-browser consistency




    .                                             .
    @yinhm                     Google Closure Plugin               17/27
.




.




             Let’s build a image plugin.




    .                                                .
    @yinhm                        Google Closure Plugin   18/27
.




             init editor
.




              var editorId = 'myId';
             var editorDiv = dom.createDom(goog.dom.TagName.DIV,
                {id: editorId,
                 style: 'width: 630px; height: 300px;'});
              // Create an editable field.
              var trogField = new goog.editor.Field(editorId);
              trogField.makeEditable();




    .                                          .
    @yinhm                  Google Closure Plugin             19/27
.




             register plugin
.




              var trogField = new goog.editor.Field(editorId);
              trogField.registerPlugin(
                new goog.editor.plugins.ImageDialogPlugin(config));
              trogField.makeEditable();




    .                                          .
    @yinhm                  Google Closure Plugin             20/27
.




             Interacting
.




             • User clicks image button
             • trogField.execCommand(goog.editor.Command.BOLD)
             • trogField looks at the installed plugin
             • isEnabled? isSupportCommand?
             • plugin.execCommand
             • plugin.execCommandInternal




    .                                              .
    @yinhm                      Google Closure Plugin            21/27
.




             goog.editor.Plugin
.




             • base class for all Trog plugins
             • extends goog.events.EventTarget
             • fieldObject points to instance of goog.editor.Field
             • getFieldDomHelper() returns the goog.dom.Domhelper
               for the field
             • must implement getTrogClassId()
             • isSupportedCommand, execCommand,
               execCommandInternal



    .                                              .
    @yinhm                      Google Closure Plugin               22/27
.




             Implemen: ImageDialogPlugin
.




             • inherit from AbstractDialogPlugin
             • isSupportedCommand, execCommand,
               execCommandInternal handler by AbstractDialogPlugin
             • must implement createDialog




    .                                            .
    @yinhm                    Google Closure Plugin                  23/27
.




             Implement: ImageDialog
.




             • inherit from good.ui.editor.AbstractDialog
             • must implement createDialogControl, createOkEvent
             • creating dialog HTML, handle events




    .                                             .
    @yinhm                     Google Closure Plugin               24/27
.




             Implement: detail
.




             Open sourced: http:
             //github.com/yinhm/google-closure-editor-image/




    .                                           .
    @yinhm                   Google Closure Plugin             25/27
.




             References
.




             • http://code.google.com/closure, Google Closure




    .                                          .
    @yinhm                  Google Closure Plugin               26/27
.




             About
.




                                a
                     Created in L TEX using the beamer class, TeX Live and Emacs.


                     Published under the Creative Commons Attribution 3.0 License
                           http://creativecommons.org/licenses/by/3.0/

                                             by @yinhm
                                     http://yinhm.appspot.com


                                Document version December 19, 2010




    .                                              .
    @yinhm                      Google Closure Plugin                               27/27

Weitere ähnliche Inhalte

Ähnlich wie Write a Google Closure Editor Plugin

Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Igalia
 
Using google appengine
Using google appengineUsing google appengine
Using google appengineWei Sun
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andevMike Nakhimovich
 
Using and contributing to the next Guice
Using and contributing to the next GuiceUsing and contributing to the next Guice
Using and contributing to the next GuiceAdrian Cole
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern偉格 高
 
Writing multimedia applications with Grilo
Writing multimedia applications with GriloWriting multimedia applications with Grilo
Writing multimedia applications with GriloJuan A. Suárez Romero
 
Writing multimedia applications with Grilo (GUADEC 2013)
Writing multimedia applications with Grilo (GUADEC 2013)Writing multimedia applications with Grilo (GUADEC 2013)
Writing multimedia applications with Grilo (GUADEC 2013)Igalia
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery PluginRavi Mone
 
Extending Google Apps/Spreadsheet using Google Apps Script
Extending Google Apps/Spreadsheet using Google Apps ScriptExtending Google Apps/Spreadsheet using Google Apps Script
Extending Google Apps/Spreadsheet using Google Apps ScriptDipali Vyas
 
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Dirk Ginader
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleMathias Seguy
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
Gojko Adzic Cucumber
Gojko Adzic CucumberGojko Adzic Cucumber
Gojko Adzic CucumberSkills Matter
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 

Ähnlich wie Write a Google Closure Editor Plugin (20)

Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013
 
Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)
 
Using google appengine
Using google appengineUsing google appengine
Using google appengine
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Using and contributing to the next Guice
Using and contributing to the next GuiceUsing and contributing to the next Guice
Using and contributing to the next Guice
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
Writing multimedia applications with Grilo
Writing multimedia applications with GriloWriting multimedia applications with Grilo
Writing multimedia applications with Grilo
 
Writing multimedia applications with Grilo (GUADEC 2013)
Writing multimedia applications with Grilo (GUADEC 2013)Writing multimedia applications with Grilo (GUADEC 2013)
Writing multimedia applications with Grilo (GUADEC 2013)
 
Geb presentation
Geb presentationGeb presentation
Geb presentation
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Extending Google Apps/Spreadsheet using Google Apps Script
Extending Google Apps/Spreadsheet using Google Apps ScriptExtending Google Apps/Spreadsheet using Google Apps Script
Extending Google Apps/Spreadsheet using Google Apps Script
 
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Gojko Adzic Cucumber
Gojko Adzic CucumberGojko Adzic Cucumber
Gojko Adzic Cucumber
 
Voluminous_Weibo
Voluminous_WeiboVoluminous_Weibo
Voluminous_Weibo
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 

Mehr von yinhm .

Dart intro
Dart introDart intro
Dart introyinhm .
 
Emacs入门
Emacs入门Emacs入门
Emacs入门yinhm .
 
git svn workflow
git svn workflowgit svn workflow
git svn workflowyinhm .
 
Ruby的类和对象模型
Ruby的类和对象模型Ruby的类和对象模型
Ruby的类和对象模型yinhm .
 

Mehr von yinhm . (6)

Dart intro
Dart introDart intro
Dart intro
 
Emacs入门
Emacs入门Emacs入门
Emacs入门
 
git svn workflow
git svn workflowgit svn workflow
git svn workflow
 
Ruby的类和对象模型
Ruby的类和对象模型Ruby的类和对象模型
Ruby的类和对象模型
 
Raemon
RaemonRaemon
Raemon
 
Heroku
HerokuHeroku
Heroku
 

Kürzlich hochgeladen

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Write a Google Closure Editor Plugin

  • 1. . . Write a Google Closure Editor Plugin @yinhm December 19, 2010 . . @yinhm Google Closure Plugin 1/27
  • 2. . Before we start . • Closure is a JavaScript library • Developed by google, released under Apache license • The JavaScript library behind Google’s web apps . . @yinhm Google Closure Plugin 2/27
  • 3. . Hello world: Step 1 . goog.require('goog.dom'); function sayHi() { var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'}, 'Hello world!'); goog.dom.appendChild(document.body, newHeader); } . . @yinhm Google Closure Plugin 3/27
  • 4. . Hello world: Step 2 . <html> <head> <script src="closure-library/closure/goog/base.js"> </script> <script src="hello.js"></script> </head> <body onload="sayHi()"> </body> </html> . . @yinhm Google Closure Plugin 4/27
  • 5. . Hello world: How does it work? . • bootstrap file base.js • import module: goog.require(’goog.dom’) . . @yinhm Google Closure Plugin 5/27
  • 6. . Modules . • DOM, Dojo query(third party) • UI: Autocomplete, dialog, date picker, Tab... • AJAX: xhrio, iframeio... • Rich-text editor . . @yinhm Google Closure Plugin 6/27
  • 7. . object-oriented programming . • Class-based programming(as opposed to prototype-based) • Namespace • Inheritance . . @yinhm Google Closure Plugin 7/27
  • 8. . Example of a Class . /** no JSDoc **/ goog.provide('example.Animal'} example.Animal = function(first_name) { this.name_ = name; }; example.Animal.prototype.first_name = ''; example.Animal.prototype.getName = function() { return this.name_; }; . . @yinhm Google Closure Plugin 8/27
  • 9. . Static methods . defined on Class constructor function but not it’s prototype example.Animal.equil = function(a1, a2) { return a1.name == a2.name; }; . . @yinhm Google Closure Plugin 9/27
  • 10. . Inheritance . goog.privode('example.Bird'); goog.require('example.Animal'); example.Bird = function() { // call to the superclass’s constructor function goog.base(this, 'bird'); }; goog.inherits(example.Bird, example.Animal); // prototyp example.Bird.prototype.fly = function() { return true; }; . . @yinhm Google Closure Plugin 10/27
  • 11. . Inheritance of ui.Dialog . . . @yinhm Google Closure Plugin 11/27
  • 12. . goog.Disposable . • dispose • disposeInternal . . @yinhm Google Closure Plugin 12/27
  • 13. . goog.events.EventTarget . • addEventListener • removeEventListener • dispatchEvent . . @yinhm Google Closure Plugin 13/27
  • 14. . goog.ui.Component . Life Cycle Stage (or Purpose) • constructor Component instance creation • createDom() Component DOM structure building • decorateInternal() (optional) • enterDocument() Post DOM-building initialization (such as attaching event listeners) • exitDocument() Post DOM-removal cleanup (such as detaching event listeners) • dispose() Component disposal • canDecorate() Indicates whether the component can use a pre-existing element . . @yinhm Google Closure Plugin 14/27
  • 15. . A UI Component Example . An Introduction to Components . . @yinhm Google Closure Plugin 15/27
  • 16. . Rich Text Editor . • Known as Trog Editor • Used in previous verion of Google Docs • Used in Gmail • Google not releasing all plugins(yet), eg: Image . . @yinhm Google Closure Plugin 16/27
  • 17. . Rich Text Editor: high-level . design • Using build-in browser features: contentEditable, execCommand • More than that: cross-browser consistency . . @yinhm Google Closure Plugin 17/27
  • 18. . . Let’s build a image plugin. . . @yinhm Google Closure Plugin 18/27
  • 19. . init editor . var editorId = 'myId'; var editorDiv = dom.createDom(goog.dom.TagName.DIV, {id: editorId, style: 'width: 630px; height: 300px;'}); // Create an editable field. var trogField = new goog.editor.Field(editorId); trogField.makeEditable(); . . @yinhm Google Closure Plugin 19/27
  • 20. . register plugin . var trogField = new goog.editor.Field(editorId); trogField.registerPlugin( new goog.editor.plugins.ImageDialogPlugin(config)); trogField.makeEditable(); . . @yinhm Google Closure Plugin 20/27
  • 21. . Interacting . • User clicks image button • trogField.execCommand(goog.editor.Command.BOLD) • trogField looks at the installed plugin • isEnabled? isSupportCommand? • plugin.execCommand • plugin.execCommandInternal . . @yinhm Google Closure Plugin 21/27
  • 22. . goog.editor.Plugin . • base class for all Trog plugins • extends goog.events.EventTarget • fieldObject points to instance of goog.editor.Field • getFieldDomHelper() returns the goog.dom.Domhelper for the field • must implement getTrogClassId() • isSupportedCommand, execCommand, execCommandInternal . . @yinhm Google Closure Plugin 22/27
  • 23. . Implemen: ImageDialogPlugin . • inherit from AbstractDialogPlugin • isSupportedCommand, execCommand, execCommandInternal handler by AbstractDialogPlugin • must implement createDialog . . @yinhm Google Closure Plugin 23/27
  • 24. . Implement: ImageDialog . • inherit from good.ui.editor.AbstractDialog • must implement createDialogControl, createOkEvent • creating dialog HTML, handle events . . @yinhm Google Closure Plugin 24/27
  • 25. . Implement: detail . Open sourced: http: //github.com/yinhm/google-closure-editor-image/ . . @yinhm Google Closure Plugin 25/27
  • 26. . References . • http://code.google.com/closure, Google Closure . . @yinhm Google Closure Plugin 26/27
  • 27. . About . a Created in L TEX using the beamer class, TeX Live and Emacs. Published under the Creative Commons Attribution 3.0 License http://creativecommons.org/licenses/by/3.0/ by @yinhm http://yinhm.appspot.com Document version December 19, 2010 . . @yinhm Google Closure Plugin 27/27