SlideShare a Scribd company logo
.




.




             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

More Related Content

Similar to Write a Google Closure Editor Plugin

Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013
Mauricio (Salaboy) Salatino
 
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
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
Emil Varga
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike 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 Guice
Adrian 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 Grilo
Juan 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
 
Geb presentation
Geb presentationGeb presentation
Geb presentation
Ivar Østhus
 
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 Script
Dipali 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 Google
Mathias Seguy
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu
 
Gojko Adzic Cucumber
Gojko Adzic CucumberGojko Adzic Cucumber
Gojko Adzic Cucumber
Skills Matter
 
Voluminous_Weibo
Voluminous_WeiboVoluminous_Weibo
Voluminous_Weibo
xiaojueqq12345
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
James Casey
 

Similar to 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
 

More from yinhm .

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

More from 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
 

Recently uploaded

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

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