Commits

Anonymous committed 852cf33

Streamlined JS code.

Comments (0)

Files changed (1)

markupmirror/static/markupmirror/markupmirror.js

     "jQuery": jQuery
 };
 
-(function($) {
-    $(function() {
+/* document ready and jQuery closure */
+(function($) { $(function() {
 
-        var MarkupMirrorEditor = function( element, options ) {
-                    var _this = this,
-                        _public = {
 
-                            /* to configure the wrapper */
-                            configure: function( obj ) {
-                                for( key in obj ) {
-                                    _private.options[ key ] = obj[ key ];
-                                }
 
-                                return _this;
-                            },
+var MarkupMirrorEditor = function( element, options ) {
+    var _this = this,
+        _public = {
 
-                            get: function( key ) {
-                                return _private.options[ key ] || undefined;
-                            },
-
-                            /* add the Codemirror to a new element */
-                            add: function( el, options ) {
-                                    if( !el || el.length === 0 ) {
-                                        return _this;
-                                    }
-
-                                    var editor;
-
-                                     $.each( el,
-                                            function() {
-                                                if( this.nodeName.toLowerCase() === 'textarea' ) {
-                                                    if( options === undefined ) {
-                                                        if( _private.getOption( '_init' ) === true && _private.getOption( 'inherit' ) === true ) {
-                                                            editor = CodeMirror.fromTextArea( this, _private.getOption( 'initOptions' ) );
-                                                            _public.configure( { 'editor': editor } );
-                                                        } else {
-                                                            editor = CodeMirror.fromTextArea( this );
-                                                            _public.configure( { 'editor': editor } );
-                                                        }
-                                                    } else {
-
-                                                        /* so we are able to overwrite just a few of the options */
-                                                        if(  _private.getOption( '_init' ) === true && _private.getOption( 'extend' ) ) {
-                                                            options = $.extend( _private.getOption( 'initOptions' ), options );
-                                                        }
-
-                                                        editor = CodeMirror.fromTextArea( this, options );
-                                                        _public.configure( { 'editor': editor } );
-                                                    }
-
-                                                    if( typeof( _private.getOption( 'onInit' ) ) === 'function' ) {
-                                                         _private.getOption( 'onInit' )( this );
-                                                    }
-                                                }
-                                            });
-
-                                    return _this;
-                                 }
-                        },
-
-                        /* this will not be exposed to the public */
-                        _private = {
-                            getOption: function( index ) {
-                                return _private.options[ index ] || undefined;
-                            },
-
-                            /* store configuration options here */
-                            options: {
-                                /* initial options passed in */
-                                initOptions: undefined,
-
-                                /* new added elements inherit from the inital options */
-                                inherit: true,
-
-                                /* extends the original options object by passing a new element in */
-                                extend: true,
-
-                                /* initial init was done */
-                                _init: false,
-
-                                /* callback */
-                                onInit: undefined,
-
-                                /* the original codemirror editor object */
-                                editor: undefined
-                            }
-                        };
-
-                    /* initialise the plugin here */
-                    _public.configure( { _init: true,
-                                         initOptions: options } );
-
-                    /* add init element */
-                    _public.add( element, options );
-
-                    return _this = _public;
-                };
-
-
-        var $textarea = $('.item-markupmirror'),
-            CM = new MarkupMirrorEditor( undefined, $textarea.data('mmSettings') )
-                        .configure({'onInit': createIframe})
-                        .configure({'onChange': updateIframe})
-                        .add( $textarea );
-
-                /* when init a textarea with codemirror we also create an iframe */
-                function createIframe( el ) {
-                    var $el = $(el),
-                        $iframe = $('<iframe />').attr('src', $el.data('mmSettings')['base_url']);
-
-                    $el.on('change', updateIframe);
-
-                    $iframe
-                    .insertAfter( $el );
+            /* to configure the wrapper */
+            configure: function( obj ) {
+                var key;
+                for( key in obj ) {
+                    _private.options[ key ] = obj[ key ];
                 }
 
-                /* when changing the textarea we replace the iframe content with the new coming from the server */
-                function updateIframe( e ) {
-                    console.log('update');
+                return _this;
+            },
+
+            get: function( key ) {
+                return _private.options[ key ] || undefined;
+            },
+
+            /* add the Codemirror to a new element */
+            add: function( el, options ) {
+                if( !el || el.length === 0 ) {
+                    return _this;
                 }
 
-            console.log( CM.get('editor') );
+                var editor;
+                $.each( el, function() {
+                    if( this.nodeName.toLowerCase() === 'textarea' ) {
+                        if( options === undefined ) {
+                            if( _private.getOption( '_init' ) === true &&
+                                _private.getOption( 'inherit' ) === true ) {
+                                editor = CodeMirror.fromTextArea(
+                                    this,
+                                    _private.getOption( 'initOptions' ) );
+                                _public.configure( { 'editor': editor } );
+                            } else {
+                                editor = CodeMirror.fromTextArea( this );
+                                _public.configure( { 'editor': editor } );
+                            }
+                        } else {
 
-    });
-})(markupmirror.jQuery);
+                            /* so we are able to overwrite just a few of the
+                             * options */
+                            if( _private.getOption( '_init' ) === true &&
+                                _private.getOption( 'extend' ) ) {
+                                options = $.extend(
+                                    _private.getOption( 'initOptions' ),
+                                    options );
+                            }
+
+                            editor = CodeMirror.fromTextArea( this, options );
+                            _public.configure( { 'editor': editor } );
+                        }
+
+                        if( typeof(
+                            _private.getOption( 'onInit' ) ) === 'function' ) {
+                            _private.getOption( 'onInit' )( this );
+                        }
+                    }
+                });
+
+                return _this;
+            }
+        },
+
+        /* this will not be exposed to the public */
+        _private = {
+            getOption: function( index ) {
+                return _private.options[ index ] || undefined;
+            },
+
+            /* store configuration options here */
+            options: {
+                /* initial options passed in */
+                initOptions: undefined,
+
+                /* new added elements inherit from the inital
+                 * options */
+                inherit: true,
+
+                /* extends the original options object by passing a
+                 * new element in */
+                extend: true,
+
+                /* initial init was done */
+                _init: false,
+
+                /* callback */
+                onInit: undefined,
+
+                /* the original codemirror editor object */
+                editor: undefined
+            }
+        };
+
+    /* initialise the plugin here */
+    _public.configure( { _init: true,
+                         initOptions: options } );
+
+    /* add init element */
+    _public.add( element, options );
+
+    return _this = _public;
+};
+
+
+/* initialize plugin for all textareas, class item-markupmirror */
+var $textarea = $('.item-markupmirror'),
+    CM = new MarkupMirrorEditor( undefined,
+                                 $textarea.data('mmSettings') )
+        .configure({'onInit': createIframe})
+        .configure({'onChange': updateIframe})
+        .add( $textarea );
+
+
+/* when init a textarea with codemirror we also create an iframe */
+function createIframe( el ) {
+    var $el = $(el),
+        $iframe = $('<iframe />').attr(
+            'src', $el.data('mmSettings')['base_url']);
+
+    $el.on('change', updateIframe);
+    $iframe.insertAfter( $el );
+}
+
+
+/* when changing the textarea we replace the iframe content with the
+ * new coming from the server */
+function updateIframe( e ) {
+    console.log('update');
+}
+
+console.log( CM.get('editor') );
+
+
+
+/* end document ready and jQuery closure */
+}); })(markupmirror.jQuery);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.