Skip to content

Instantly share code, notes, and snippets.

@bsmirnov
Last active August 29, 2015 14:19
Show Gist options
  • Save bsmirnov/0b32ca045d35046b49bc to your computer and use it in GitHub Desktop.
Save bsmirnov/0b32ca045d35046b49bc to your computer and use it in GitHub Desktop.
Content Lock

#Issue Symptoms:

When on node add/edit page. When uploading images only one works and we get javascript error relating to jQuery function:

	(anonymous function) (content_lock_init.js, line 30)```

#Issue Analysis:

It seems the issue is related to how we are handling header/footer js and alternate versions of jQuery mapped to $ and jQuery. Because the jQuery plugins are mapped to $ and jQuery variable separately by Drupal and BH versions of jquery and javascript using the wrong($/jQuery) one will return undefined for some functions.

Content lock module has 2 javascript files which are inconsistently referring to jQuery in behaviors. 
Additionally the files we load for header and footer get initiated in hook_init therefore this happends on every request weather or not the actually page loads. Because of when doing file upload on node edit form, they get wired during ajax request and issue appears even though we are on admin page because while we avoid loading the BH js files on admin pages, ajax request avoid this exception. 

#Fix:

The fix adds the files to theme folder overriding the default ones and making sure that behaviors wired properly and correct reference to jQuery is used by the module.  
Additionaly the part where we add BH js files and remap Jquery is moved to page hook_preprocess_html instead of hook_init this way it hopefully only runs on full page loads and not ajax requests. 

#Issues/Further concerns:

This types of issues are unpredictable and hard to anticipate as loading 2 versions of jQuery is not recommended and if we are not careful the mapping gets out of sync. It seems that we will continue to discover issues once in a while as long as we loading the header/footer js the way we do. 

#Testing:

- Test addding new node 
- Test adding all fields  on node edit
- Test editing node and updating/adding all fields

#Tested:
- Switching Wisywig modes. - Works
- Adding fields
	- Topshot
	- Images
	- C-Info
	- C-Headline
	- Multiple Item Images
	- Inserting images via insert. 
	
# Results 

- No problems.
- No JS errors.

# Files affected by fix
- bnh_includes.module
- content_lock_init.js new file in theme
- onUserExit.js new file in theme
- template.php modified in theme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment